diff --git a/README.md b/README.md index d3bc1a1..1a335d4 100644 --- a/README.md +++ b/README.md @@ -26,8 +26,8 @@ pnpm add fhevm-contracts To write Solidity contracts that use `TFHE` and/or `Gateway`, it is required to set different contract addresses. -Fortunately, [the fhevm repo)](https://github.com/zama-ai/fhevm), one of this repo's dependencies, exports config files -that can be inherited to simplify the process. +Fortunately, [the fhevm repo](https://github.com/zama-ai/fhevm), one of this repo's dependencies, exports config files +that can be inherited to simplify the process. The config should be the first to be imported in the order of the inherited contracts. #### Using the mock network (for testing) @@ -63,7 +63,7 @@ contract MyERC20 is SepoliaZamaFHEVMConfig, EncryptedERC20 { ## Available contracts -As of version 0.2, these Solidity templates include governance-related and token-related contracts. +These Solidity templates include governance-related and token-related contracts. ### Token diff --git a/contracts/governance/Comp.sol b/contracts/governance/Comp.sol index 0573045..7e0a2a8 100644 --- a/contracts/governance/Comp.sol +++ b/contracts/governance/Comp.sol @@ -101,7 +101,7 @@ abstract contract Comp is IComp, EncryptedERC20, EIP712, Ownable2Step { string memory version_, uint64 totalSupply_ ) EncryptedERC20(name_, symbol_) EIP712(name_, version_) Ownable(owner_) { - _unsafeMint(owner_, TFHE.asEuint64(totalSupply_)); + _unsafeMint(owner_, totalSupply_); _totalSupply = totalSupply_; /// @dev Define the constant in the storage. diff --git a/contracts/token/ERC20/EncryptedERC20.sol b/contracts/token/ERC20/EncryptedERC20.sol index 3a1570a..f68fd5c 100644 --- a/contracts/token/ERC20/EncryptedERC20.sol +++ b/contracts/token/ERC20/EncryptedERC20.sol @@ -155,27 +155,23 @@ abstract contract EncryptedERC20 is IEncryptedERC20 { } /** - * @dev It does not incorporate any underflow check. It must be implemented + * @dev It does not incorporate any overflow check. It must be implemented * by the function calling it. */ - function _unsafeBurn(address account, euint64 amount) internal virtual { - euint64 newBalanceAccount = TFHE.sub(_balances[account], amount); - _balances[account] = newBalanceAccount; - TFHE.allowThis(newBalanceAccount); - TFHE.allow(newBalanceAccount, account); - emit Transfer(account, address(0)); + function _unsafeMint(address account, uint64 amount) internal virtual { + _unsafeMintNoEvent(account, amount); + emit Transfer(address(0), account); } /** * @dev It does not incorporate any overflow check. It must be implemented * by the function calling it. */ - function _unsafeMint(address account, euint64 amount) internal virtual { + function _unsafeMintNoEvent(address account, uint64 amount) internal virtual { euint64 newBalanceAccount = TFHE.add(_balances[account], amount); _balances[account] = newBalanceAccount; TFHE.allowThis(newBalanceAccount); TFHE.allow(newBalanceAccount, account); - emit Transfer(address(0), account); } function _transfer(address from, address to, euint64 amount, ebool isTransferable) internal virtual { @@ -187,11 +183,9 @@ abstract contract EncryptedERC20 is IEncryptedERC20 { if (from == address(0)) { revert SenderAddressNull(); } - if (to == address(0)) { revert ReceiverAddressNull(); } - /// Add to the balance of `to` and subract from the balance of `from`. euint64 transferValue = TFHE.select(isTransferable, amount, TFHE.asEuint64(0)); euint64 newBalanceTo = TFHE.add(_balances[to], transferValue); diff --git a/contracts/token/ERC20/extensions/EncryptedERC20Mintable.sol b/contracts/token/ERC20/extensions/EncryptedERC20Mintable.sol index ec9ee0a..d1f820a 100644 --- a/contracts/token/ERC20/extensions/EncryptedERC20Mintable.sol +++ b/contracts/token/ERC20/extensions/EncryptedERC20Mintable.sol @@ -33,7 +33,7 @@ abstract contract EncryptedERC20Mintable is Ownable2Step, EncryptedERC20 { * @param amount Amount of tokens to mint. */ function mint(uint64 amount) public virtual onlyOwner { - _unsafeMint(msg.sender, TFHE.asEuint64(amount)); + _unsafeMint(msg.sender, amount); /// @dev Since _totalSupply is not encrypted and _totalSupply >= balances[msg.sender], /// the next line contains an overflow check for the encrypted operation above. _totalSupply = _totalSupply + amount; diff --git a/contracts/token/ERC20/extensions/EncryptedERC20WithErrorsMintable.sol b/contracts/token/ERC20/extensions/EncryptedERC20WithErrorsMintable.sol index 316f381..6318712 100644 --- a/contracts/token/ERC20/extensions/EncryptedERC20WithErrorsMintable.sol +++ b/contracts/token/ERC20/extensions/EncryptedERC20WithErrorsMintable.sol @@ -33,7 +33,7 @@ abstract contract EncryptedERC20WithErrorsMintable is Ownable2Step, EncryptedERC * @param amount Amount of tokens to mint. */ function mint(uint64 amount) public virtual onlyOwner { - _unsafeMint(msg.sender, TFHE.asEuint64(amount)); + _unsafeMint(msg.sender, amount); /// @dev Since _totalSupply is not encrypted and _totalSupply >= balances[msg.sender], /// the next line contains an overflow check for the encrypted operation above. _totalSupply = _totalSupply + amount; diff --git a/package.json b/package.json index 5c93b35..df7daf9 100644 --- a/package.json +++ b/package.json @@ -95,5 +95,6 @@ "@openzeppelin/contracts-upgradeable": "5.0.2", "extra-bigint": "^1.1.18", "sqlite3": "^5.1.7" - } + }, + "packageManager": "pnpm@9.4.0+sha1.9217c800d4ab947a7aee520242a7b70d64fc7638" }