From f561e0cc148f673d174879610cdff258045141e8 Mon Sep 17 00:00:00 2001 From: PacificYield <173040337+PacificYield@users.noreply.github.com> Date: Wed, 27 Nov 2024 15:19:40 +0100 Subject: [PATCH] refactor: use IERC6093 for errors --- contracts/token/ERC20/EncryptedERC20.sol | 15 ++++++++++++--- contracts/token/ERC20/IEncryptedERC20.sol | 10 ---------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/contracts/token/ERC20/EncryptedERC20.sol b/contracts/token/ERC20/EncryptedERC20.sol index 495ac51..22237c6 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,7 +15,7 @@ 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 Total supply. uint64 internal _totalSupply; @@ -145,6 +146,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); @@ -182,11 +191,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 16c9a2d..6841d57 100644 --- a/contracts/token/ERC20/IEncryptedERC20.sol +++ b/contracts/token/ERC20/IEncryptedERC20.sol @@ -20,16 +20,6 @@ interface IEncryptedERC20 { */ event Transfer(address indexed from, address indexed to); - /** - * @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. */