diff --git a/contracts/token/ERC20/EncryptedERC20.sol b/contracts/token/ERC20/EncryptedERC20.sol index de1e205..60ffa60 100644 --- a/contracts/token/ERC20/EncryptedERC20.sol +++ b/contracts/token/ERC20/EncryptedERC20.sol @@ -3,6 +3,7 @@ pragma solidity ^0.8.24; import "fhevm/lib/TFHE.sol"; +import { IERC20Errors } from "@openzeppelin/contracts/interfaces/draft-IERC6093.sol"; import { IEncryptedERC20 } from "./IEncryptedERC20.sol"; import { TFHEErrors } from "../../utils/TFHEErrors.sol"; @@ -14,10 +15,9 @@ import { TFHEErrors } from "../../utils/TFHEErrors.sol"; * and setting allowances, but uses encrypted data types. * The total supply is not encrypted. */ -abstract contract EncryptedERC20 is IEncryptedERC20, TFHEErrors { +abstract contract EncryptedERC20 is IEncryptedERC20, IERC20Errors, TFHEErrors { /// @notice used as a placehoder in Approval and Transfer events to comply with the official EIP20 uint256 internal constant _PLACEHOLDER = type(uint256).max; - /// @notice Total supply. uint64 internal _totalSupply; @@ -148,6 +148,14 @@ abstract contract EncryptedERC20 is IEncryptedERC20, TFHEErrors { } function _approve(address owner, address spender, euint64 amount) internal virtual { + if (owner == address(0)) { + revert ERC20InvalidApprover(owner); + } + + if (spender == address(0)) { + revert ERC20InvalidSpender(spender); + } + _allowances[owner][spender] = amount; TFHE.allowThis(amount); TFHE.allow(amount, owner); @@ -181,11 +189,11 @@ abstract contract EncryptedERC20 is IEncryptedERC20, TFHEErrors { function _transferNoEvent(address from, address to, euint64 amount, ebool isTransferable) internal virtual { if (from == address(0)) { - revert SenderAddressNull(); + revert ERC20InvalidSender(from); } if (to == address(0)) { - revert ReceiverAddressNull(); + revert ERC20InvalidReceiver(to); } /// Add to the balance of `to` and subract from the balance of `from`. diff --git a/contracts/token/ERC20/IEncryptedERC20.sol b/contracts/token/ERC20/IEncryptedERC20.sol index c15c43a..463b246 100644 --- a/contracts/token/ERC20/IEncryptedERC20.sol +++ b/contracts/token/ERC20/IEncryptedERC20.sol @@ -22,16 +22,6 @@ interface IEncryptedERC20 { */ event Transfer(address indexed from, address indexed to, uint256 errorId); - /** - * @notice Returned when receiver is address(0). - */ - error ReceiverAddressNull(); - - /** - * @notice Returned when sender is address(0). - */ - error SenderAddressNull(); - /** * @notice Sets the `encryptedAmount` as the allowance of `spender` over the caller's tokens. */