diff --git a/contracts/token/ERC20/EncryptedERC20.sol b/contracts/token/ERC20/EncryptedERC20.sol index c36bced..b4bc0f2 100644 --- a/contracts/token/ERC20/EncryptedERC20.sol +++ b/contracts/token/ERC20/EncryptedERC20.sol @@ -155,6 +155,17 @@ abstract contract EncryptedERC20 is IEncryptedERC20 { TFHE.allow(amount, spender); } + /** + * @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 { + _balances[msg.sender] = TFHE.add(_balances[account], amount); + TFHE.allowThis(_balances[account]); + TFHE.allow(_balances[account], account); + emit Transfer(address(0), account); + } + function _transfer(address from, address to, euint64 amount, ebool isTransferable) internal virtual { // Add to the balance of `to` and subract from the balance of `from`. euint64 transferValue = TFHE.select(isTransferable, amount, TFHE.asEuint64(0)); diff --git a/contracts/token/ERC20/extensions/EncryptedERC20Mintable.sol b/contracts/token/ERC20/extensions/EncryptedERC20Mintable.sol index 737b4ac..c9f1208 100644 --- a/contracts/token/ERC20/extensions/EncryptedERC20Mintable.sol +++ b/contracts/token/ERC20/extensions/EncryptedERC20Mintable.sol @@ -33,9 +33,7 @@ contract EncryptedERC20Mintable is Ownable2Step, EncryptedERC20 { * @param amount Amount of tokens to mint. */ function mint(uint64 amount) public onlyOwner { - _balances[msg.sender] = TFHE.add(_balances[msg.sender], amount); - TFHE.allow(_balances[msg.sender], address(this)); - TFHE.allow(_balances[msg.sender], msg.sender); + _unsafeMint(msg.sender, TFHE.asEuint64(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 20c1926..0317b54 100644 --- a/contracts/token/ERC20/extensions/EncryptedERC20WithErrorsMintable.sol +++ b/contracts/token/ERC20/extensions/EncryptedERC20WithErrorsMintable.sol @@ -33,9 +33,7 @@ contract EncryptedERC20WithErrorsMintable is Ownable2Step, EncryptedERC20WithErr * @param amount Amount of tokens to mint. */ function mint(uint64 amount) public onlyOwner { - _balances[msg.sender] = TFHE.add(_balances[msg.sender], amount); - TFHE.allow(_balances[msg.sender], address(this)); - TFHE.allow(_balances[msg.sender], msg.sender); + _unsafeMint(msg.sender, TFHE.asEuint64(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;