Skip to content

Commit

Permalink
refactor: use IERC6093 for errors
Browse files Browse the repository at this point in the history
  • Loading branch information
PacificYield committed Nov 28, 2024
1 parent fa99ca6 commit 6b6feb8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
16 changes: 12 additions & 4 deletions contracts/token/ERC20/EncryptedERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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`.
Expand Down
10 changes: 0 additions & 10 deletions contracts/token/ERC20/IEncryptedERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down

0 comments on commit 6b6feb8

Please sign in to comment.