From dc0b832f652049a9686cf8231787f5d054b31c2f Mon Sep 17 00:00:00 2001 From: PacificYield <173040337+PacificYield@users.noreply.github.com> Date: Mon, 2 Dec 2024 12:03:07 +0100 Subject: [PATCH] refactor: rename EncryptedERC20 to ConfidentialERC20 --- README.md | 20 +- contracts/governance/Comp.sol | 8 +- ....sol => TestConfidentialERC20Mintable.sol} | 6 +- ...estConfidentialERC20WithErrorsMintable.sol | 17 ++ .../TestEncryptedERC20WithErrorsMintable.sol | 15 -- ...cryptedERC20.sol => ConfidentialERC20.sol} | 30 +-- ...ryptedERC20.sol => IConfidentialERC20.sol} | 6 +- ...able.sol => ConfidentialERC20Mintable.sol} | 10 +- ...rs.sol => ConfidentialERC20WithErrors.sol} | 12 +- ...> ConfidentialERC20WithErrorsMintable.sol} | 10 +- docs/governance/Comp.md | 2 +- docs/token/ERC20/EncryptedERC20.md | 26 +- docs/token/ERC20/IEncryptedERC20.md | 2 +- .../extensions/EncryptedERC20Mintable.md | 4 +- .../extensions/EncryptedERC20WithErrors.md | 6 +- .../EncryptedERC20WithErrorsMintable.md | 4 +- .../ConfidentialERC20.fixture.ts} | 12 +- .../ConfidentialERC20.test.ts} | 208 ++++++++------ .../ConfidentialERC20WithErrors.fixture.ts} | 10 +- .../ConfidentialERC20WithErrors.test.ts} | 254 +++++++++++------- test/governance/Comp.test.ts | 2 +- 21 files changed, 387 insertions(+), 277 deletions(-) rename contracts/test/token/ERC20/{TestEncryptedERC20Mintable.sol => TestConfidentialERC20Mintable.sol} (50%) create mode 100644 contracts/test/token/ERC20/TestConfidentialERC20WithErrorsMintable.sol delete mode 100644 contracts/test/token/ERC20/TestEncryptedERC20WithErrorsMintable.sol rename contracts/token/ERC20/{EncryptedERC20.sol => ConfidentialERC20.sol} (90%) rename contracts/token/ERC20/{IEncryptedERC20.sol => IConfidentialERC20.sol} (94%) rename contracts/token/ERC20/extensions/{EncryptedERC20Mintable.sol => ConfidentialERC20Mintable.sol} (78%) rename contracts/token/ERC20/extensions/{EncryptedERC20WithErrors.sol => ConfidentialERC20WithErrors.sol} (91%) rename contracts/token/ERC20/extensions/{EncryptedERC20WithErrorsMintable.sol => ConfidentialERC20WithErrorsMintable.sol} (75%) rename test/{encryptedERC20/EncryptedERC20.fixture.ts => confidentialERC20/ConfidentialERC20.fixture.ts} (78%) rename test/{encryptedERC20/EncryptedERC20.test.ts => confidentialERC20/ConfidentialERC20.test.ts} (62%) rename test/{encryptedERC20/EncryptedERC20WithErrors.fixture.ts => confidentialERC20/ConfidentialERC20WithErrors.fixture.ts} (75%) rename test/{encryptedERC20/EncryptedERC20WithErrors.test.ts => confidentialERC20/ConfidentialERC20WithErrors.test.ts} (65%) diff --git a/README.md b/README.md index deb1ce3..4351e0a 100644 --- a/README.md +++ b/README.md @@ -37,10 +37,10 @@ inherited contracts. pragma solidity ^0.8.24; import { MockZamaFHEVMConfig } from "fhevm/config/ZamaFHEVMConfig.sol"; -import { EncryptedERC20 } from "fhevm-contracts/contracts/token/ERC20/EncryptedERC20.sol"; +import { ConfidentialERC20 } from "fhevm-contracts/contracts/token/ERC20/ConfidentialERC20.sol"; -contract MyERC20 is MockZamaFHEVMConfig, EncryptedERC20 { - constructor() EncryptedERC20("MyToken", "MYTOKEN") { +contract MyERC20 is MockZamaFHEVMConfig, ConfidentialERC20 { + constructor() ConfidentialERC20("MyToken", "MYTOKEN") { _unsafeMint(1000000, msg.sender); } } @@ -53,10 +53,10 @@ contract MyERC20 is MockZamaFHEVMConfig, EncryptedERC20 { pragma solidity ^0.8.24; import { SepoliaZamaFHEVMConfig } from "fhevm/config/ZamaFHEVMConfig.sol"; -import { EncryptedERC20 } from "fhevm-contracts/contracts/token/ERC20/EncryptedERC20.sol"; +import { ConfidentialERC20 } from "fhevm-contracts/contracts/token/ERC20/ConfidentialERC20.sol"; -contract MyERC20 is SepoliaZamaFHEVMConfig, EncryptedERC20 { - constructor() EncryptedERC20("MyToken", "MYTOKEN") { +contract MyERC20 is SepoliaZamaFHEVMConfig, ConfidentialERC20 { + constructor() ConfidentialERC20("MyToken", "MYTOKEN") { _unsafeMint(1000000, msg.sender); } } @@ -68,10 +68,10 @@ These Solidity templates include governance-related and token-related contracts. ### Token -- [EncryptedERC20](./contracts/token/ERC20/EncryptedERC20.sol) -- [EncryptedERC20Mintable](./contracts/token/ERC20/extensions/EncryptedERC20Mintable.sol) -- [EncryptedERC20WithErrors](./contracts/token/ERC20/extensions/EncryptedERC20WithErrors.sol) -- [EncryptedERC20WithErrorsMintable](./contracts/token/ERC20/extensions/EncryptedERC20WithErrorsMintable.sol) +- [ConfidentialERC20](./contracts/token/ERC20/ConfidentialERC20.sol) +- [ConfidentialERC20Mintable](./contracts/token/ERC20/extensions/ConfidentialERC20Mintable.sol) +- [ConfidentialERC20WithErrors](./contracts/token/ERC20/extensions/ConfidentialERC20WithErrors.sol) +- [ConfidentialERC20WithErrorsMintable](./contracts/token/ERC20/extensions/ConfidentialERC20WithErrorsMintable.sol) ### Governance diff --git a/contracts/governance/Comp.sol b/contracts/governance/Comp.sol index d0644df..3db749a 100644 --- a/contracts/governance/Comp.sol +++ b/contracts/governance/Comp.sol @@ -5,12 +5,12 @@ import "fhevm/lib/TFHE.sol"; import { Ownable2Step, Ownable } from "@openzeppelin/contracts/access/Ownable2Step.sol"; import { EIP712 } from "@openzeppelin/contracts/utils/cryptography/EIP712.sol"; import { SignatureChecker } from "@openzeppelin/contracts/utils/cryptography/SignatureChecker.sol"; -import { EncryptedERC20 } from "../token/ERC20/EncryptedERC20.sol"; +import { ConfidentialERC20 } from "../token/ERC20/ConfidentialERC20.sol"; import { IComp } from "./IComp.sol"; /** * @title Comp - * @notice This contract inherits EncryptedERC20, EIP712, and Ownable2Step. + * @notice This contract inherits ConfidentialERC20, EIP712, and Ownable2Step. * This is based on the Comp.sol contract written by Compound Labs. * see: compound-finance/compound-protocol/blob/master/contracts/Governance/Comp.sol * It is a governance token used to delegate votes, which can be used by contracts such as @@ -19,7 +19,7 @@ import { IComp } from "./IComp.sol"; * with an account's balance. * @dev The delegation of votes leaks information about the account's encrypted balance to the `delegatee`. */ -abstract contract Comp is IComp, EncryptedERC20, EIP712, Ownable2Step { +abstract contract Comp is IComp, ConfidentialERC20, EIP712, Ownable2Step { /// @notice Returned if the `blockNumber` is higher or equal to the (current) `block.number`. /// @dev It is returned in requests to access votes. error BlockNumberEqualOrHigherThanCurrentBlock(); @@ -97,7 +97,7 @@ abstract contract Comp is IComp, EncryptedERC20, EIP712, Ownable2Step { string memory symbol_, string memory version_, uint64 totalSupply_ - ) EncryptedERC20(name_, symbol_) EIP712(name_, version_) Ownable(owner_) { + ) ConfidentialERC20(name_, symbol_) EIP712(name_, version_) Ownable(owner_) { _unsafeMint(owner_, totalSupply_); _totalSupply = totalSupply_; diff --git a/contracts/test/token/ERC20/TestEncryptedERC20Mintable.sol b/contracts/test/token/ERC20/TestConfidentialERC20Mintable.sol similarity index 50% rename from contracts/test/token/ERC20/TestEncryptedERC20Mintable.sol rename to contracts/test/token/ERC20/TestConfidentialERC20Mintable.sol index 8447d7c..4fd9317 100644 --- a/contracts/test/token/ERC20/TestEncryptedERC20Mintable.sol +++ b/contracts/test/token/ERC20/TestConfidentialERC20Mintable.sol @@ -1,15 +1,15 @@ // SPDX-License-Identifier: BSD-3-Clause-Clear pragma solidity ^0.8.24; -import { EncryptedERC20Mintable } from "../../../token/ERC20/extensions/EncryptedERC20Mintable.sol"; +import { ConfidentialERC20Mintable } from "../../../token/ERC20/extensions/ConfidentialERC20Mintable.sol"; import { MockZamaFHEVMConfig } from "fhevm/config/ZamaFHEVMConfig.sol"; -contract TestEncryptedERC20Mintable is MockZamaFHEVMConfig, EncryptedERC20Mintable { +contract TestConfidentialERC20Mintable is MockZamaFHEVMConfig, ConfidentialERC20Mintable { constructor( string memory name_, string memory symbol_, address owner_ - ) EncryptedERC20Mintable(name_, symbol_, owner_) { + ) ConfidentialERC20Mintable(name_, symbol_, owner_) { // } } diff --git a/contracts/test/token/ERC20/TestConfidentialERC20WithErrorsMintable.sol b/contracts/test/token/ERC20/TestConfidentialERC20WithErrorsMintable.sol new file mode 100644 index 0000000..2fe0137 --- /dev/null +++ b/contracts/test/token/ERC20/TestConfidentialERC20WithErrorsMintable.sol @@ -0,0 +1,17 @@ +// SPDX-License-Identifier: BSD-3-Clause-Clear +pragma solidity ^0.8.24; + +import { + ConfidentialERC20WithErrorsMintable +} from "../../../token/ERC20/extensions/ConfidentialERC20WithErrorsMintable.sol"; +import { MockZamaFHEVMConfig } from "fhevm/config/ZamaFHEVMConfig.sol"; + +contract TestConfidentialERC20WithErrorsMintable is MockZamaFHEVMConfig, ConfidentialERC20WithErrorsMintable { + constructor( + string memory name_, + string memory symbol_, + address owner_ + ) ConfidentialERC20WithErrorsMintable(name_, symbol_, owner_) { + // + } +} diff --git a/contracts/test/token/ERC20/TestEncryptedERC20WithErrorsMintable.sol b/contracts/test/token/ERC20/TestEncryptedERC20WithErrorsMintable.sol deleted file mode 100644 index fd7bcb5..0000000 --- a/contracts/test/token/ERC20/TestEncryptedERC20WithErrorsMintable.sol +++ /dev/null @@ -1,15 +0,0 @@ -// SPDX-License-Identifier: BSD-3-Clause-Clear -pragma solidity ^0.8.24; - -import { EncryptedERC20WithErrorsMintable } from "../../../token/ERC20/extensions/EncryptedERC20WithErrorsMintable.sol"; -import { MockZamaFHEVMConfig } from "fhevm/config/ZamaFHEVMConfig.sol"; - -contract TestEncryptedERC20WithErrorsMintable is MockZamaFHEVMConfig, EncryptedERC20WithErrorsMintable { - constructor( - string memory name_, - string memory symbol_, - address owner_ - ) EncryptedERC20WithErrorsMintable(name_, symbol_, owner_) { - // - } -} diff --git a/contracts/token/ERC20/EncryptedERC20.sol b/contracts/token/ERC20/ConfidentialERC20.sol similarity index 90% rename from contracts/token/ERC20/EncryptedERC20.sol rename to contracts/token/ERC20/ConfidentialERC20.sol index 60ffa60..3fa6f7f 100644 --- a/contracts/token/ERC20/EncryptedERC20.sol +++ b/contracts/token/ERC20/ConfidentialERC20.sol @@ -4,18 +4,18 @@ 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 { IConfidentialERC20 } from "./IConfidentialERC20.sol"; import { TFHEErrors } from "../../utils/TFHEErrors.sol"; /** - * @title EncryptedERC20 + * @title ConfidentialERC20 * @notice This contract implements an encrypted ERC20-like token with confidential balances using * Zama's FHE (Fully Homomorphic Encryption) library. * @dev It supports standard ERC20 functions such as transferring tokens, minting, * and setting allowances, but uses encrypted data types. * The total supply is not encrypted. */ -abstract contract EncryptedERC20 is IEncryptedERC20, IERC20Errors, TFHEErrors { +abstract contract ConfidentialERC20 is IConfidentialERC20, 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. @@ -43,7 +43,7 @@ abstract contract EncryptedERC20 is IEncryptedERC20, IERC20Errors, TFHEErrors { } /** - * @notice See {IEncryptedERC20-approve}. + * @notice See {IConfidentialERC20-approve}. */ function approve(address spender, einput encryptedAmount, bytes calldata inputProof) public virtual returns (bool) { approve(spender, TFHE.asEuint64(encryptedAmount, inputProof)); @@ -51,7 +51,7 @@ abstract contract EncryptedERC20 is IEncryptedERC20, IERC20Errors, TFHEErrors { } /** - * @notice See {IEncryptedERC20-approve}. + * @notice See {IConfidentialERC20-approve}. */ function approve(address spender, euint64 amount) public virtual returns (bool) { _isSenderAllowedForAmount(amount); @@ -62,7 +62,7 @@ abstract contract EncryptedERC20 is IEncryptedERC20, IERC20Errors, TFHEErrors { } /** - * @notice See {IEncryptedERC20-transfer}. + * @notice See {IConfidentialERC20-transfer}. */ function transfer(address to, einput encryptedAmount, bytes calldata inputProof) public virtual returns (bool) { transfer(to, TFHE.asEuint64(encryptedAmount, inputProof)); @@ -70,7 +70,7 @@ abstract contract EncryptedERC20 is IEncryptedERC20, IERC20Errors, TFHEErrors { } /** - * @notice See {IEncryptedERC20-transfer}. + * @notice See {IConfidentialERC20-transfer}. */ function transfer(address to, euint64 amount) public virtual returns (bool) { _isSenderAllowedForAmount(amount); @@ -82,7 +82,7 @@ abstract contract EncryptedERC20 is IEncryptedERC20, IERC20Errors, TFHEErrors { } /** - * @notice See {IEncryptedERC20-transferFrom}. + * @notice See {IConfidentialERC20-transferFrom}. */ function transferFrom( address from, @@ -95,7 +95,7 @@ abstract contract EncryptedERC20 is IEncryptedERC20, IERC20Errors, TFHEErrors { } /** - * @notice See {IEncryptedERC20-transferFrom}. + * @notice See {IConfidentialERC20-transferFrom}. */ function transferFrom(address from, address to, euint64 amount) public virtual returns (bool) { _isSenderAllowedForAmount(amount); @@ -106,42 +106,42 @@ abstract contract EncryptedERC20 is IEncryptedERC20, IERC20Errors, TFHEErrors { } /** - * @notice See {IEncryptedERC20-allowance}. + * @notice See {IConfidentialERC20-allowance}. */ function allowance(address owner, address spender) public view virtual returns (euint64) { return _allowance(owner, spender); } /** - * @notice See {IEncryptedERC20-balanceOf}. + * @notice See {IConfidentialERC20-balanceOf}. */ function balanceOf(address account) public view virtual returns (euint64) { return _balances[account]; } /** - * @notice See {IEncryptedERC20-decimals}. + * @notice See {IConfidentialERC20-decimals}. */ function decimals() public view virtual returns (uint8) { return 6; } /** - * @notice See {IEncryptedERC20-name}. + * @notice See {IConfidentialERC20-name}. */ function name() public view virtual returns (string memory) { return _name; } /** - * @notice See {IEncryptedERC20-symbol}. + * @notice See {IConfidentialERC20-symbol}. */ function symbol() public view virtual returns (string memory) { return _symbol; } /** - * @notice See {IEncryptedERC20-totalSupply}. + * @notice See {IConfidentialERC20-totalSupply}. */ function totalSupply() public view virtual returns (uint64) { return _totalSupply; diff --git a/contracts/token/ERC20/IEncryptedERC20.sol b/contracts/token/ERC20/IConfidentialERC20.sol similarity index 94% rename from contracts/token/ERC20/IEncryptedERC20.sol rename to contracts/token/ERC20/IConfidentialERC20.sol index 463b246..28b09e9 100644 --- a/contracts/token/ERC20/IEncryptedERC20.sol +++ b/contracts/token/ERC20/IConfidentialERC20.sol @@ -4,10 +4,10 @@ pragma solidity ^0.8.24; import "fhevm/lib/TFHE.sol"; /** - * @title IEncryptedERC20 + * @title IConfidentialERC20 * @notice Interface that defines ERC20-like tokens with encrypted balances. */ -interface IEncryptedERC20 { +interface IConfidentialERC20 { /** * @notice Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. @@ -18,7 +18,7 @@ interface IEncryptedERC20 { * @notice Emitted when tokens are moved from one account (`from`) to * another (`to`). * Last argument is either a default placeholder, typically equal to max(uint256), in case of - * an EncryptedERC20 without error handling, or an errorId in case of encrypted error handling. + * an ConfidentialERC20 without error handling, or an errorId in case of encrypted error handling. */ event Transfer(address indexed from, address indexed to, uint256 errorId); diff --git a/contracts/token/ERC20/extensions/EncryptedERC20Mintable.sol b/contracts/token/ERC20/extensions/ConfidentialERC20Mintable.sol similarity index 78% rename from contracts/token/ERC20/extensions/EncryptedERC20Mintable.sol rename to contracts/token/ERC20/extensions/ConfidentialERC20Mintable.sol index d1f820a..25386b7 100644 --- a/contracts/token/ERC20/extensions/EncryptedERC20Mintable.sol +++ b/contracts/token/ERC20/extensions/ConfidentialERC20Mintable.sol @@ -4,14 +4,14 @@ pragma solidity ^0.8.24; import "fhevm/lib/TFHE.sol"; import { Ownable2Step, Ownable } from "@openzeppelin/contracts/access/Ownable2Step.sol"; -import { EncryptedERC20 } from "../EncryptedERC20.sol"; +import { ConfidentialERC20 } from "../ConfidentialERC20.sol"; /** - * @title EncryptedERC20Mintable - * @notice This contract inherits EncryptedERC20. + * @title ConfidentialERC20Mintable + * @notice This contract inherits ConfidentialERC20. * @dev It allows an owner to mint tokens. Mint amounts are public. */ -abstract contract EncryptedERC20Mintable is Ownable2Step, EncryptedERC20 { +abstract contract ConfidentialERC20Mintable is Ownable2Step, ConfidentialERC20 { /** * @notice Emitted when `amount` tokens are minted to one account (`to`). */ @@ -26,7 +26,7 @@ abstract contract EncryptedERC20Mintable is Ownable2Step, EncryptedERC20 { string memory name_, string memory symbol_, address owner_ - ) Ownable(owner_) EncryptedERC20(name_, symbol_) {} + ) Ownable(owner_) ConfidentialERC20(name_, symbol_) {} /** * @notice Mint tokens. diff --git a/contracts/token/ERC20/extensions/EncryptedERC20WithErrors.sol b/contracts/token/ERC20/extensions/ConfidentialERC20WithErrors.sol similarity index 91% rename from contracts/token/ERC20/extensions/EncryptedERC20WithErrors.sol rename to contracts/token/ERC20/extensions/ConfidentialERC20WithErrors.sol index 6902178..cfe93b1 100644 --- a/contracts/token/ERC20/extensions/EncryptedERC20WithErrors.sol +++ b/contracts/token/ERC20/extensions/ConfidentialERC20WithErrors.sol @@ -2,11 +2,11 @@ pragma solidity ^0.8.24; import "fhevm/lib/TFHE.sol"; -import { EncryptedERC20 } from "../EncryptedERC20.sol"; +import { ConfidentialERC20 } from "../ConfidentialERC20.sol"; import { EncryptedErrors } from "../../../utils/EncryptedErrors.sol"; /** - * @title EncryptedERC20WithErrors + * @title ConfidentialERC20WithErrors * @notice This contract implements an encrypted ERC20-like token with confidential balances using * Zama's FHE (Fully Homomorphic Encryption) library. * @dev It supports standard ERC20 functions such as transferring tokens, minting, @@ -14,7 +14,7 @@ import { EncryptedErrors } from "../../../utils/EncryptedErrors.sol"; * The total supply is not encrypted. * It also supports error handling for encrypted errors. */ -abstract contract EncryptedERC20WithErrors is EncryptedERC20, EncryptedErrors { +abstract contract ConfidentialERC20WithErrors is ConfidentialERC20, EncryptedErrors { /** * @notice Error codes allow tracking (in the storage) whether a transfer worked. * @dev NO_ERROR: the transfer worked as expected @@ -36,10 +36,10 @@ abstract contract EncryptedERC20WithErrors is EncryptedERC20, EncryptedErrors { constructor( string memory name_, string memory symbol_ - ) EncryptedERC20(name_, symbol_) EncryptedErrors(uint8(type(ErrorCodes).max)) {} + ) ConfidentialERC20(name_, symbol_) EncryptedErrors(uint8(type(ErrorCodes).max)) {} /** - * @notice See {IEncryptedERC20-transfer}. + * @notice See {IConfidentialERC20-transfer}. */ function transfer(address to, euint64 amount) public virtual override returns (bool) { _isSenderAllowedForAmount(amount); @@ -54,7 +54,7 @@ abstract contract EncryptedERC20WithErrors is EncryptedERC20, EncryptedErrors { } /** - * @notice See {IEncryptedERC20-transferFrom}. + * @notice See {IConfidentialERC20-transferFrom}. */ function transferFrom(address from, address to, euint64 amount) public virtual override returns (bool) { _isSenderAllowedForAmount(amount); diff --git a/contracts/token/ERC20/extensions/EncryptedERC20WithErrorsMintable.sol b/contracts/token/ERC20/extensions/ConfidentialERC20WithErrorsMintable.sol similarity index 75% rename from contracts/token/ERC20/extensions/EncryptedERC20WithErrorsMintable.sol rename to contracts/token/ERC20/extensions/ConfidentialERC20WithErrorsMintable.sol index 6318712..f28f30b 100644 --- a/contracts/token/ERC20/extensions/EncryptedERC20WithErrorsMintable.sol +++ b/contracts/token/ERC20/extensions/ConfidentialERC20WithErrorsMintable.sol @@ -4,14 +4,14 @@ pragma solidity ^0.8.24; import "fhevm/lib/TFHE.sol"; import { Ownable2Step, Ownable } from "@openzeppelin/contracts/access/Ownable2Step.sol"; -import { EncryptedERC20WithErrors } from "./EncryptedERC20WithErrors.sol"; +import { ConfidentialERC20WithErrors } from "./ConfidentialERC20WithErrors.sol"; /** - * @title EncryptedERC20WithErrorsMintable - * @notice This contract inherits EncryptedERC20WithErrors. + * @title ConfidentialERC20WithErrorsMintable + * @notice This contract inherits ConfidentialERC20WithErrors. * @dev It allows an owner to mint tokens. Mint amounts are public. */ -abstract contract EncryptedERC20WithErrorsMintable is Ownable2Step, EncryptedERC20WithErrors { +abstract contract ConfidentialERC20WithErrorsMintable is Ownable2Step, ConfidentialERC20WithErrors { /** * @notice Emitted when `amount` tokens are minted to one account (`to`). */ @@ -26,7 +26,7 @@ abstract contract EncryptedERC20WithErrorsMintable is Ownable2Step, EncryptedERC string memory name_, string memory symbol_, address owner_ - ) Ownable(owner_) EncryptedERC20WithErrors(name_, symbol_) {} + ) Ownable(owner_) ConfidentialERC20WithErrors(name_, symbol_) {} /** * @notice Mint tokens. diff --git a/docs/governance/Comp.md b/docs/governance/Comp.md index 565de5f..9ba71df 100644 --- a/docs/governance/Comp.md +++ b/docs/governance/Comp.md @@ -1,6 +1,6 @@ # Comp -This contract inherits EncryptedERC20, EIP712, and Ownable2Step. This is based on the Comp.sol contract written by +This contract inherits ConfidentialERC20, EIP712, and Ownable2Step. This is based on the Comp.sol contract written by Compound Labs. see: compound-finance/compound-protocol/blob/master/contracts/Governance/Comp.sol. It is a governance token used to delegate votes, which can be used by contracts such as GovernorAlphaZama.sol. It uses encrypted votes to delegate the voting power associated with an account's balance. diff --git a/docs/token/ERC20/EncryptedERC20.md b/docs/token/ERC20/EncryptedERC20.md index f037e58..2ec08e3 100644 --- a/docs/token/ERC20/EncryptedERC20.md +++ b/docs/token/ERC20/EncryptedERC20.md @@ -1,4 +1,4 @@ -# EncryptedERC20 +# ConfidentialERC20 This contract implements an encrypted ERC20-like token with confidential balances using Zama's FHE (Fully Homomorphic Encryption) library. @@ -73,7 +73,7 @@ constructor(string name_, string symbol_) internal function approve(address spender, einput encryptedAmount, bytes inputProof) public virtual returns (bool) ``` -See {IEncryptedERC20-approve}. +See {IConfidentialERC20-approve}. ## approve @@ -81,7 +81,7 @@ See {IEncryptedERC20-approve}. function approve(address spender, euint64 amount) public virtual returns (bool) ``` -See {IEncryptedERC20-approve}. +See {IConfidentialERC20-approve}. ## transfer @@ -89,7 +89,7 @@ See {IEncryptedERC20-approve}. function transfer(address to, einput encryptedAmount, bytes inputProof) public virtual returns (bool) ``` -See {IEncryptedERC20-transfer}. +See {IConfidentialERC20-transfer}. ## transfer @@ -97,7 +97,7 @@ See {IEncryptedERC20-transfer}. function transfer(address to, euint64 amount) public virtual returns (bool) ``` -See {IEncryptedERC20-transfer}. +See {IConfidentialERC20-transfer}. ## transferFrom @@ -105,7 +105,7 @@ See {IEncryptedERC20-transfer}. function transferFrom(address from, address to, einput encryptedAmount, bytes inputProof) public virtual returns (bool) ``` -See {IEncryptedERC20-transferFrom}. +See {IConfidentialERC20-transferFrom}. ## transferFrom @@ -113,7 +113,7 @@ See {IEncryptedERC20-transferFrom}. function transferFrom(address from, address to, euint64 amount) public virtual returns (bool) ``` -See {IEncryptedERC20-transferFrom}. +See {IConfidentialERC20-transferFrom}. ## allowance @@ -121,7 +121,7 @@ See {IEncryptedERC20-transferFrom}. function allowance(address owner, address spender) public view virtual returns (euint64) ``` -See {IEncryptedERC20-allowance}. +See {IConfidentialERC20-allowance}. ## balanceOf @@ -129,7 +129,7 @@ See {IEncryptedERC20-allowance}. function balanceOf(address account) public view virtual returns (euint64) ``` -See {IEncryptedERC20-balanceOf}. +See {IConfidentialERC20-balanceOf}. ## decimals @@ -137,7 +137,7 @@ See {IEncryptedERC20-balanceOf}. function decimals() public view virtual returns (uint8) ``` -See {IEncryptedERC20-decimals}. +See {IConfidentialERC20-decimals}. ## name @@ -145,7 +145,7 @@ See {IEncryptedERC20-decimals}. function name() public view virtual returns (string) ``` -See {IEncryptedERC20-name}. +See {IConfidentialERC20-name}. ## symbol @@ -153,7 +153,7 @@ See {IEncryptedERC20-name}. function symbol() public view virtual returns (string) ``` -See {IEncryptedERC20-symbol}. +See {IConfidentialERC20-symbol}. ## totalSupply @@ -161,7 +161,7 @@ See {IEncryptedERC20-symbol}. function totalSupply() public view virtual returns (uint64) ``` -See {IEncryptedERC20-totalSupply}. +See {IConfidentialERC20-totalSupply}. ## \_approve diff --git a/docs/token/ERC20/IEncryptedERC20.md b/docs/token/ERC20/IEncryptedERC20.md index 319c7fd..04c8f56 100644 --- a/docs/token/ERC20/IEncryptedERC20.md +++ b/docs/token/ERC20/IEncryptedERC20.md @@ -1,4 +1,4 @@ -# IEncryptedERC20 +# IConfidentialERC20 Interface that defines ERC20-like tokens with encrypted balances. diff --git a/docs/token/ERC20/extensions/EncryptedERC20Mintable.md b/docs/token/ERC20/extensions/EncryptedERC20Mintable.md index 3040e3d..33fcf96 100644 --- a/docs/token/ERC20/extensions/EncryptedERC20Mintable.md +++ b/docs/token/ERC20/extensions/EncryptedERC20Mintable.md @@ -1,6 +1,6 @@ -# EncryptedERC20Mintable +# ConfidentialERC20Mintable -This contract inherits EncryptedERC20. +This contract inherits ConfidentialERC20. _It allows an owner to mint tokens. Mint amounts are public._ diff --git a/docs/token/ERC20/extensions/EncryptedERC20WithErrors.md b/docs/token/ERC20/extensions/EncryptedERC20WithErrors.md index d9fe5e7..55a095a 100644 --- a/docs/token/ERC20/extensions/EncryptedERC20WithErrors.md +++ b/docs/token/ERC20/extensions/EncryptedERC20WithErrors.md @@ -1,4 +1,4 @@ -# EncryptedERC20WithErrors +# ConfidentialERC20WithErrors This contract implements an encrypted ERC20-like token with confidential balances using Zama's FHE (Fully Homomorphic Encryption) library. @@ -59,7 +59,7 @@ constructor(string name_, string symbol_) internal function transfer(address to, euint64 amount) public virtual returns (bool) ``` -See {IEncryptedERC20-transfer}. +See {IConfidentialERC20-transfer}. ## transferFrom @@ -67,7 +67,7 @@ See {IEncryptedERC20-transfer}. function transferFrom(address from, address to, euint64 amount) public virtual returns (bool) ``` -See {IEncryptedERC20-transferFrom}. +See {IConfidentialERC20-transferFrom}. ## getErrorCodeForTransferId diff --git a/docs/token/ERC20/extensions/EncryptedERC20WithErrorsMintable.md b/docs/token/ERC20/extensions/EncryptedERC20WithErrorsMintable.md index d131a03..d576929 100644 --- a/docs/token/ERC20/extensions/EncryptedERC20WithErrorsMintable.md +++ b/docs/token/ERC20/extensions/EncryptedERC20WithErrorsMintable.md @@ -1,6 +1,6 @@ -# EncryptedERC20WithErrorsMintable +# ConfidentialERC20WithErrorsMintable -This contract inherits EncryptedERC20WithErrors. +This contract inherits ConfidentialERC20WithErrors. _It allows an owner to mint tokens. Mint amounts are public._ diff --git a/test/encryptedERC20/EncryptedERC20.fixture.ts b/test/confidentialERC20/ConfidentialERC20.fixture.ts similarity index 78% rename from test/encryptedERC20/EncryptedERC20.fixture.ts rename to test/confidentialERC20/ConfidentialERC20.fixture.ts index 8e0782e..7eed5b2 100644 --- a/test/encryptedERC20/EncryptedERC20.fixture.ts +++ b/test/confidentialERC20/ConfidentialERC20.fixture.ts @@ -1,17 +1,17 @@ import { ethers } from "hardhat"; -import type { IEncryptedERC20, TestEncryptedERC20Mintable } from "../../types"; +import type { IConfidentialERC20, TestConfidentialERC20Mintable } from "../../types"; import { reencryptEuint64 } from "../reencrypt"; import { Signers } from "../signers"; import { FhevmInstances } from "../types"; -export async function deployEncryptedERC20Fixture( +export async function deployConfidentialERC20Fixture( signers: Signers, name: string, symbol: string, owner: string, -): Promise { - const contractFactory = await ethers.getContractFactory("TestEncryptedERC20Mintable"); +): Promise { + const contractFactory = await ethers.getContractFactory("TestConfidentialERC20Mintable"); const contract = await contractFactory .connect(signers[owner as keyof Signers]) .deploy(name, symbol, signers[owner as keyof Signers].address); @@ -24,7 +24,7 @@ export async function reencryptAllowance( instances: FhevmInstances, account: string, spender: string, - token: IEncryptedERC20, + token: IConfidentialERC20, tokenAddress: string, ): Promise { const allowanceHandle = await token.allowance(signers[account as keyof Signers], signers[spender as keyof Signers]); @@ -36,7 +36,7 @@ export async function reencryptBalance( signers: Signers, instances: FhevmInstances, account: string, - token: IEncryptedERC20, + token: IConfidentialERC20, tokenAddress: string, ): Promise { const balanceHandle = await token.balanceOf(signers[account as keyof Signers]); diff --git a/test/encryptedERC20/EncryptedERC20.test.ts b/test/confidentialERC20/ConfidentialERC20.test.ts similarity index 62% rename from test/encryptedERC20/EncryptedERC20.test.ts rename to test/confidentialERC20/ConfidentialERC20.test.ts index b1e6710..fafd924 100644 --- a/test/encryptedERC20/EncryptedERC20.test.ts +++ b/test/confidentialERC20/ConfidentialERC20.test.ts @@ -2,9 +2,9 @@ import { expect } from "chai"; import { createInstances } from "../instance"; import { getSigners, initSigners } from "../signers"; -import { deployEncryptedERC20Fixture, reencryptAllowance, reencryptBalance } from "./EncryptedERC20.fixture"; +import { deployConfidentialERC20Fixture, reencryptAllowance, reencryptBalance } from "./ConfidentialERC20.fixture"; -describe("EncryptedERC20", function () { +describe("ConfidentialERC20", function () { // @dev The placeholder is type(uint256).max --> 2**256 - 1. const PLACEHOLDER = 2n ** 256n - 1n; @@ -14,60 +14,78 @@ describe("EncryptedERC20", function () { }); beforeEach(async function () { - const contract = await deployEncryptedERC20Fixture(this.signers, "Naraggara", "NARA", "alice"); - this.encryptedERC20Address = await contract.getAddress(); - this.encryptedERC20 = contract; + const contract = await deployConfidentialERC20Fixture(this.signers, "Naraggara", "NARA", "alice"); + this.confidentialERC20Address = await contract.getAddress(); + this.confidentialERC20 = contract; this.instances = await createInstances(this.signers); }); it("post-deployment state", async function () { - expect(await this.encryptedERC20.totalSupply()).to.equal(0); - expect(await this.encryptedERC20.name()).to.equal("Naraggara"); - expect(await this.encryptedERC20.symbol()).to.equal("NARA"); - expect(await this.encryptedERC20.decimals()).to.be.eq(BigInt(6)); + expect(await this.confidentialERC20.totalSupply()).to.equal(0); + expect(await this.confidentialERC20.name()).to.equal("Naraggara"); + expect(await this.confidentialERC20.symbol()).to.equal("NARA"); + expect(await this.confidentialERC20.decimals()).to.be.eq(BigInt(6)); }); it("should mint the contract", async function () { const mintAmount = 1000; - const tx = await this.encryptedERC20.connect(this.signers.alice).mint(mintAmount); - await expect(tx).to.emit(this.encryptedERC20, "Mint").withArgs(this.signers.alice, mintAmount); + const tx = await this.confidentialERC20.connect(this.signers.alice).mint(mintAmount); + await expect(tx).to.emit(this.confidentialERC20, "Mint").withArgs(this.signers.alice, mintAmount); expect( - await reencryptBalance(this.signers, this.instances, "alice", this.encryptedERC20, this.encryptedERC20Address), + await reencryptBalance( + this.signers, + this.instances, + "alice", + this.confidentialERC20, + this.confidentialERC20Address, + ), ).to.equal(mintAmount); - expect(await this.encryptedERC20.totalSupply()).to.equal(mintAmount); + expect(await this.confidentialERC20.totalSupply()).to.equal(mintAmount); }); it("should transfer tokens between two users", async function () { const mintAmount = 10_000; const transferAmount = 1337; - let tx = await this.encryptedERC20.connect(this.signers.alice).mint(mintAmount); + let tx = await this.confidentialERC20.connect(this.signers.alice).mint(mintAmount); await tx.wait(); - const input = this.instances.alice.createEncryptedInput(this.encryptedERC20Address, this.signers.alice.address); + const input = this.instances.alice.createEncryptedInput(this.confidentialERC20Address, this.signers.alice.address); input.add64(transferAmount); const encryptedTransferAmount = await input.encrypt(); - tx = await this.encryptedERC20 + tx = await this.confidentialERC20 .connect(this.signers.alice) [ "transfer(address,bytes32,bytes)" ](this.signers.bob.address, encryptedTransferAmount.handles[0], encryptedTransferAmount.inputProof); await expect(tx) - .to.emit(this.encryptedERC20, "Transfer") + .to.emit(this.confidentialERC20, "Transfer") .withArgs(this.signers.alice, this.signers.bob, PLACEHOLDER); // Decrypt Alice's balance expect( - await reencryptBalance(this.signers, this.instances, "alice", this.encryptedERC20, this.encryptedERC20Address), + await reencryptBalance( + this.signers, + this.instances, + "alice", + this.confidentialERC20, + this.confidentialERC20Address, + ), ).to.equal(mintAmount - transferAmount); // Decrypt Bob's balance expect( - await reencryptBalance(this.signers, this.instances, "bob", this.encryptedERC20, this.encryptedERC20Address), + await reencryptBalance( + this.signers, + this.instances, + "bob", + this.confidentialERC20, + this.confidentialERC20Address, + ), ).to.equal(transferAmount); }); @@ -77,32 +95,44 @@ describe("EncryptedERC20", function () { const mintAmount = 1000; const transferAmount = 1337; - let tx = await this.encryptedERC20.connect(this.signers.alice).mint(mintAmount); + let tx = await this.confidentialERC20.connect(this.signers.alice).mint(mintAmount); await tx.wait(); - const input = this.instances.alice.createEncryptedInput(this.encryptedERC20Address, this.signers.alice.address); + const input = this.instances.alice.createEncryptedInput(this.confidentialERC20Address, this.signers.alice.address); input.add64(transferAmount); const encryptedTransferAmount = await input.encrypt(); - tx = await this.encryptedERC20["transfer(address,bytes32,bytes)"]( + tx = await this.confidentialERC20["transfer(address,bytes32,bytes)"]( this.signers.bob.address, encryptedTransferAmount.handles[0], encryptedTransferAmount.inputProof, ); - // @dev There is no error-handling in this version of EncryptedERC20. + // @dev There is no error-handling in this version of ConfidentialERC20. await expect(tx) - .to.emit(this.encryptedERC20, "Transfer") + .to.emit(this.confidentialERC20, "Transfer") .withArgs(this.signers.alice, this.signers.bob, PLACEHOLDER); // Decrypt Alice's balance expect( - await reencryptBalance(this.signers, this.instances, "alice", this.encryptedERC20, this.encryptedERC20Address), + await reencryptBalance( + this.signers, + this.instances, + "alice", + this.confidentialERC20, + this.confidentialERC20Address, + ), ).to.equal(mintAmount); // Decrypt Bob's balance expect( - await reencryptBalance(this.signers, this.instances, "bob", this.encryptedERC20, this.encryptedERC20Address), + await reencryptBalance( + this.signers, + this.instances, + "bob", + this.confidentialERC20, + this.confidentialERC20Address, + ), ).to.equal(0); }); @@ -112,24 +142,24 @@ describe("EncryptedERC20", function () { const mintAmount = 10_000; const transferAmount = 1337; - let tx = await this.encryptedERC20.connect(this.signers.alice).mint(mintAmount); + let tx = await this.confidentialERC20.connect(this.signers.alice).mint(mintAmount); await tx.wait(); const inputAlice = this.instances.alice.createEncryptedInput( - this.encryptedERC20Address, + this.confidentialERC20Address, this.signers.alice.address, ); inputAlice.add64(transferAmount); const encryptedAllowanceAmount = await inputAlice.encrypt(); - tx = await this.encryptedERC20["approve(address,bytes32,bytes)"]( + tx = await this.confidentialERC20["approve(address,bytes32,bytes)"]( this.signers.bob.address, encryptedAllowanceAmount.handles[0], encryptedAllowanceAmount.inputProof, ); await expect(tx) - .to.emit(this.encryptedERC20, "Approval") + .to.emit(this.confidentialERC20, "Approval") .withArgs(this.signers.alice, this.signers.bob, PLACEHOLDER); // @dev The allowance amount is set to be equal to the transfer amount. @@ -139,13 +169,13 @@ describe("EncryptedERC20", function () { this.instances, "alice", "bob", - this.encryptedERC20, - this.encryptedERC20Address, + this.confidentialERC20, + this.confidentialERC20Address, ), ).to.equal(transferAmount); - const bobErc20 = this.encryptedERC20.connect(this.signers.bob); - const inputBob1 = this.instances.bob.createEncryptedInput(this.encryptedERC20Address, this.signers.bob.address); + const bobErc20 = this.confidentialERC20.connect(this.signers.bob); + const inputBob1 = this.instances.bob.createEncryptedInput(this.confidentialERC20Address, this.signers.bob.address); inputBob1.add64(transferAmount + 1); // above allowance so next tx should actually not send any token const encryptedTransferAmount = await inputBob1.encrypt(); @@ -157,20 +187,32 @@ describe("EncryptedERC20", function () { ); await expect(tx2) - .to.emit(this.encryptedERC20, "Transfer") + .to.emit(this.confidentialERC20, "Transfer") .withArgs(this.signers.alice, this.signers.bob, PLACEHOLDER); // Decrypt Alice's balance expect( - await reencryptBalance(this.signers, this.instances, "alice", this.encryptedERC20, this.encryptedERC20Address), + await reencryptBalance( + this.signers, + this.instances, + "alice", + this.confidentialERC20, + this.confidentialERC20Address, + ), ).to.equal(mintAmount); // check that transfer did not happen, as expected // Decrypt Bob's balance expect( - await reencryptBalance(this.signers, this.instances, "bob", this.encryptedERC20, this.encryptedERC20Address), + await reencryptBalance( + this.signers, + this.instances, + "bob", + this.confidentialERC20, + this.confidentialERC20Address, + ), ).to.equal(0); // check that transfer did not happen, as expected - const inputBob2 = this.instances.bob.createEncryptedInput(this.encryptedERC20Address, this.signers.bob.address); + const inputBob2 = this.instances.bob.createEncryptedInput(this.confidentialERC20Address, this.signers.bob.address); inputBob2.add64(transferAmount); // below allowance so next tx should send token const encryptedTransferAmount2 = await inputBob2.encrypt(); @@ -184,12 +226,24 @@ describe("EncryptedERC20", function () { // Decrypt Alice's balance expect( - await reencryptBalance(this.signers, this.instances, "alice", this.encryptedERC20, this.encryptedERC20Address), + await reencryptBalance( + this.signers, + this.instances, + "alice", + this.confidentialERC20, + this.confidentialERC20Address, + ), ).to.equal(mintAmount - transferAmount); // check that transfer did happen this time // Decrypt Bob's balance expect( - await reencryptBalance(this.signers, this.instances, "bob", this.encryptedERC20, this.encryptedERC20Address), + await reencryptBalance( + this.signers, + this.instances, + "bob", + this.confidentialERC20, + this.confidentialERC20Address, + ), ).to.equal(transferAmount); // check that transfer did happen this time // Verify Alice's allowance is 0 @@ -199,8 +253,8 @@ describe("EncryptedERC20", function () { this.instances, "alice", "bob", - this.encryptedERC20, - this.encryptedERC20Address, + this.confidentialERC20, + this.confidentialERC20Address, ), ).to.equal(0); }); @@ -209,13 +263,13 @@ describe("EncryptedERC20", function () { const amount = 10_000; const inputAlice = this.instances.alice.createEncryptedInput( - this.encryptedERC20Address, + this.confidentialERC20Address, this.signers.alice.address, ); inputAlice.add64(amount); const encryptedAllowanceAmount = await inputAlice.encrypt(); - const tx = await this.encryptedERC20 + const tx = await this.confidentialERC20 .connect(this.signers.alice) [ "approve(address,bytes32,bytes)" @@ -223,10 +277,10 @@ describe("EncryptedERC20", function () { await tx.wait(); - const allowanceHandleAlice = await this.encryptedERC20.allowance(this.signers.alice, this.signers.bob); + const allowanceHandleAlice = await this.confidentialERC20.allowance(this.signers.alice, this.signers.bob); const { publicKey: publicKeyCarol, privateKey: privateKeyCarol } = this.instances.carol.generateKeypair(); - const eip712Carol = this.instances.carol.createEIP712(publicKeyCarol, this.encryptedERC20Address); + const eip712Carol = this.instances.carol.createEIP712(publicKeyCarol, this.confidentialERC20Address); const signatureCarol = await this.signers.carol.signTypedData( eip712Carol.domain, { Reencrypt: eip712Carol.types.Reencrypt }, @@ -239,7 +293,7 @@ describe("EncryptedERC20", function () { privateKeyCarol, publicKeyCarol, signatureCarol.replace("0x", ""), - this.encryptedERC20Address, + this.confidentialERC20Address, this.signers.carol.address, ); @@ -254,13 +308,13 @@ describe("EncryptedERC20", function () { it("should not be able to read the balance if not user after initialization", async function () { // Mint is used to initialize the balanceOf(alice) const amount = 10_000; - const tx = await this.encryptedERC20.connect(this.signers.alice).mint(amount); + const tx = await this.confidentialERC20.connect(this.signers.alice).mint(amount); await tx.wait(); - const balanceHandleAlice = await this.encryptedERC20.balanceOf(this.signers.alice); + const balanceHandleAlice = await this.confidentialERC20.balanceOf(this.signers.alice); const { publicKey: publicKeyBob, privateKey: privateKeyBob } = this.instances.bob.generateKeypair(); - const eip712Bob = this.instances.bob.createEIP712(publicKeyBob, this.encryptedERC20Address); + const eip712Bob = this.instances.bob.createEIP712(publicKeyBob, this.confidentialERC20Address); const signatureBob = await this.signers.bob.signTypedData( eip712Bob.domain, { Reencrypt: eip712Bob.types.Reencrypt }, @@ -273,7 +327,7 @@ describe("EncryptedERC20", function () { privateKeyBob, publicKeyBob, signatureBob.replace("0x", ""), - this.encryptedERC20Address, + this.confidentialERC20Address, this.signers.bob.address, ); expect.fail("Expected an error to be thrown - Bob should not be able to reencrypt Alice's balance"); @@ -288,33 +342,33 @@ describe("EncryptedERC20", function () { const NULL_ADDRESS = "0x0000000000000000000000000000000000000000"; const mintAmount = 100_000; const transferAmount = 50_000; - const tx = await this.encryptedERC20.connect(this.signers.alice).mint(mintAmount); + const tx = await this.confidentialERC20.connect(this.signers.alice).mint(mintAmount); await tx.wait(); - const input = this.instances.alice.createEncryptedInput(this.encryptedERC20Address, this.signers.alice.address); + const input = this.instances.alice.createEncryptedInput(this.confidentialERC20Address, this.signers.alice.address); input.add64(transferAmount); const encryptedTransferAmount = await input.encrypt(); await expect( - this.encryptedERC20 + this.confidentialERC20 .connect(this.signers.alice) [ "transfer(address,bytes32,bytes)" ](NULL_ADDRESS, encryptedTransferAmount.handles[0], encryptedTransferAmount.inputProof), - ).to.be.revertedWithCustomError(this.encryptedERC20, "ERC20InvalidReceiver"); + ).to.be.revertedWithCustomError(this.confidentialERC20, "ERC20InvalidReceiver"); }); it("sender who is not allowed cannot transfer using a handle from another account", async function () { const mintAmount = 100_000; const transferAmount = 50_000; - let tx = await this.encryptedERC20.connect(this.signers.alice).mint(mintAmount); + let tx = await this.confidentialERC20.connect(this.signers.alice).mint(mintAmount); await tx.wait(); - const input = this.instances.alice.createEncryptedInput(this.encryptedERC20Address, this.signers.alice.address); + const input = this.instances.alice.createEncryptedInput(this.confidentialERC20Address, this.signers.alice.address); input.add64(transferAmount); const encryptedTransferAmount = await input.encrypt(); - tx = await this.encryptedERC20 + tx = await this.confidentialERC20 .connect(this.signers.alice) [ "transfer(address,bytes32,bytes)" @@ -322,59 +376,59 @@ describe("EncryptedERC20", function () { await tx.wait(); - const balanceHandleAlice = await this.encryptedERC20.balanceOf(this.signers.alice.address); + const balanceHandleAlice = await this.confidentialERC20.balanceOf(this.signers.alice.address); await expect( - this.encryptedERC20.connect(this.signers.bob).transfer(this.signers.carol.address, balanceHandleAlice), - ).to.be.revertedWithCustomError(this.encryptedERC20, "TFHESenderNotAllowed"); + this.confidentialERC20.connect(this.signers.bob).transfer(this.signers.carol.address, balanceHandleAlice), + ).to.be.revertedWithCustomError(this.confidentialERC20, "TFHESenderNotAllowed"); }); it("sender who is not allowed cannot transferFrom using a handle from another account", async function () { const mintAmount = 100_000; const transferAmount = 50_000; - let tx = await this.encryptedERC20.connect(this.signers.alice).mint(mintAmount); + let tx = await this.confidentialERC20.connect(this.signers.alice).mint(mintAmount); await tx.wait(); - let input = this.instances.alice.createEncryptedInput(this.encryptedERC20Address, this.signers.alice.address); + let input = this.instances.alice.createEncryptedInput(this.confidentialERC20Address, this.signers.alice.address); input.add64(mintAmount); const encryptedAllowanceAmount = await input.encrypt(); - tx = await this.encryptedERC20 + tx = await this.confidentialERC20 .connect(this.signers.alice) [ "approve(address,bytes32,bytes)" ](this.signers.carol.address, encryptedAllowanceAmount.handles[0], encryptedAllowanceAmount.inputProof); - input = this.instances.carol.createEncryptedInput(this.encryptedERC20Address, this.signers.carol.address); + input = this.instances.carol.createEncryptedInput(this.confidentialERC20Address, this.signers.carol.address); input.add64(transferAmount); const encryptedTransferAmount = await input.encrypt(); - tx = await this.encryptedERC20 + tx = await this.confidentialERC20 .connect(this.signers.carol) [ "transferFrom(address,address,bytes32,bytes)" ](this.signers.alice.address, this.signers.carol.address, encryptedTransferAmount.handles[0], encryptedTransferAmount.inputProof); - const allowanceHandleAlice = await this.encryptedERC20.allowance( + const allowanceHandleAlice = await this.confidentialERC20.allowance( this.signers.alice.address, this.signers.carol.address, ); await expect( - this.encryptedERC20 + this.confidentialERC20 .connect(this.signers.bob) .transferFrom(this.signers.alice.address, this.signers.bob.address, allowanceHandleAlice), - ).to.be.revertedWithCustomError(this.encryptedERC20, "TFHESenderNotAllowed"); + ).to.be.revertedWithCustomError(this.confidentialERC20, "TFHESenderNotAllowed"); }); it("sender who is not allowed cannot approve using a handle from another account", async function () { const amount = 100_000; - const input = this.instances.alice.createEncryptedInput(this.encryptedERC20Address, this.signers.alice.address); + const input = this.instances.alice.createEncryptedInput(this.confidentialERC20Address, this.signers.alice.address); input.add64(amount); const encryptedAllowanceAmount = await input.encrypt(); - const tx = await this.encryptedERC20 + const tx = await this.confidentialERC20 .connect(this.signers.alice) [ "approve(address,bytes32,bytes)" @@ -382,19 +436,19 @@ describe("EncryptedERC20", function () { await tx.wait(); - const allowanceHandleAlice = await this.encryptedERC20.allowance( + const allowanceHandleAlice = await this.confidentialERC20.allowance( this.signers.alice.address, this.signers.carol.address, ); await expect( - this.encryptedERC20.connect(this.signers.bob).approve(this.signers.carol.address, allowanceHandleAlice), - ).to.be.revertedWithCustomError(this.encryptedERC20, "TFHESenderNotAllowed"); + this.confidentialERC20.connect(this.signers.bob).approve(this.signers.carol.address, allowanceHandleAlice), + ).to.be.revertedWithCustomError(this.confidentialERC20, "TFHESenderNotAllowed"); }); - it("EncryptedERC20Mintable - only owner can mint", async function () { - await expect(this.encryptedERC20.connect(this.signers.bob).mint(1)).to.be.revertedWithCustomError( - this.encryptedERC20, + it("ConfidentialERC20Mintable - only owner can mint", async function () { + await expect(this.confidentialERC20.connect(this.signers.bob).mint(1)).to.be.revertedWithCustomError( + this.confidentialERC20, "OwnableUnauthorizedAccount", ); }); diff --git a/test/encryptedERC20/EncryptedERC20WithErrors.fixture.ts b/test/confidentialERC20/ConfidentialERC20WithErrors.fixture.ts similarity index 75% rename from test/encryptedERC20/EncryptedERC20WithErrors.fixture.ts rename to test/confidentialERC20/ConfidentialERC20WithErrors.fixture.ts index 031c141..4b7ea16 100644 --- a/test/encryptedERC20/EncryptedERC20WithErrors.fixture.ts +++ b/test/confidentialERC20/ConfidentialERC20WithErrors.fixture.ts @@ -1,17 +1,17 @@ import { ethers } from "hardhat"; -import type { TestEncryptedERC20WithErrorsMintable } from "../../types"; +import type { TestConfidentialERC20WithErrorsMintable } from "../../types"; import { reencryptEuint8 } from "../reencrypt"; import { Signers } from "../signers"; import { FhevmInstances } from "../types"; -export async function deployEncryptedERC20WithErrorsFixture( +export async function deployConfidentialERC20WithErrorsFixture( signers: Signers, name: string, symbol: string, owner: string, -): Promise { - const contractFactory = await ethers.getContractFactory("TestEncryptedERC20WithErrorsMintable"); +): Promise { + const contractFactory = await ethers.getContractFactory("TestConfidentialERC20WithErrorsMintable"); const contract = await contractFactory .connect(signers[owner as keyof Signers]) .deploy(name, symbol, signers[owner as keyof Signers].address); @@ -24,7 +24,7 @@ export async function checkErrorCode( instances: FhevmInstances, account: string, transferId: bigint, - token: TestEncryptedERC20WithErrorsMintable, + token: TestConfidentialERC20WithErrorsMintable, tokenAddress: string, ): Promise { const errorCodeHandle = await token.getErrorCodeForTransferId(transferId); diff --git a/test/encryptedERC20/EncryptedERC20WithErrors.test.ts b/test/confidentialERC20/ConfidentialERC20WithErrors.test.ts similarity index 65% rename from test/encryptedERC20/EncryptedERC20WithErrors.test.ts rename to test/confidentialERC20/ConfidentialERC20WithErrors.test.ts index 3aa3a13..0bc710d 100644 --- a/test/encryptedERC20/EncryptedERC20WithErrors.test.ts +++ b/test/confidentialERC20/ConfidentialERC20WithErrors.test.ts @@ -2,10 +2,10 @@ import { expect } from "chai"; import { createInstances } from "../instance"; import { getSigners, initSigners } from "../signers"; -import { reencryptAllowance, reencryptBalance } from "./EncryptedERC20.fixture"; -import { checkErrorCode, deployEncryptedERC20WithErrorsFixture } from "./EncryptedERC20WithErrors.fixture"; +import { reencryptAllowance, reencryptBalance } from "./ConfidentialERC20.fixture"; +import { checkErrorCode, deployConfidentialERC20WithErrorsFixture } from "./ConfidentialERC20WithErrors.fixture"; -describe("EncryptedERC20WithErrors", function () { +describe("ConfidentialERC20WithErrors", function () { // @dev The placeholder is type(uint256).max --> 2**256 - 1. const PLACEHOLDER = 2n ** 256n - 1n; @@ -15,29 +15,35 @@ describe("EncryptedERC20WithErrors", function () { }); beforeEach(async function () { - const contract = await deployEncryptedERC20WithErrorsFixture(this.signers, "Naraggara", "NARA", "alice"); - this.encryptedERC20Address = await contract.getAddress(); - this.encryptedERC20 = contract; + const contract = await deployConfidentialERC20WithErrorsFixture(this.signers, "Naraggara", "NARA", "alice"); + this.confidentialERC20Address = await contract.getAddress(); + this.confidentialERC20 = contract; this.instances = await createInstances(this.signers); }); it("post-deployment state", async function () { - expect(await this.encryptedERC20.totalSupply()).to.equal(0); - expect(await this.encryptedERC20.name()).to.equal("Naraggara"); - expect(await this.encryptedERC20.symbol()).to.equal("NARA"); - expect(await this.encryptedERC20.decimals()).to.be.eq(BigInt(6)); + expect(await this.confidentialERC20.totalSupply()).to.equal(0); + expect(await this.confidentialERC20.name()).to.equal("Naraggara"); + expect(await this.confidentialERC20.symbol()).to.equal("NARA"); + expect(await this.confidentialERC20.decimals()).to.be.eq(BigInt(6)); }); it("should mint the contract", async function () { const mintAmount = 1000; - const tx = await this.encryptedERC20.connect(this.signers.alice).mint(mintAmount); - await expect(tx).to.emit(this.encryptedERC20, "Mint").withArgs(this.signers.alice, mintAmount); + const tx = await this.confidentialERC20.connect(this.signers.alice).mint(mintAmount); + await expect(tx).to.emit(this.confidentialERC20, "Mint").withArgs(this.signers.alice, mintAmount); expect( - await reencryptBalance(this.signers, this.instances, "alice", this.encryptedERC20, this.encryptedERC20Address), + await reencryptBalance( + this.signers, + this.instances, + "alice", + this.confidentialERC20, + this.confidentialERC20Address, + ), ).to.equal(mintAmount); - expect(await this.encryptedERC20.totalSupply()).to.equal(mintAmount); + expect(await this.confidentialERC20.totalSupply()).to.equal(mintAmount); }); it("should transfer tokens between two users", async function () { @@ -45,31 +51,43 @@ describe("EncryptedERC20WithErrors", function () { const transferAmount = 1337; const expectedTransferId = 0n; - let tx = await this.encryptedERC20.connect(this.signers.alice).mint(mintAmount); + let tx = await this.confidentialERC20.connect(this.signers.alice).mint(mintAmount); await tx.wait(); - const input = this.instances.alice.createEncryptedInput(this.encryptedERC20Address, this.signers.alice.address); + const input = this.instances.alice.createEncryptedInput(this.confidentialERC20Address, this.signers.alice.address); input.add64(transferAmount); const encryptedTransferAmount = await input.encrypt(); - tx = await this.encryptedERC20 + tx = await this.confidentialERC20 .connect(this.signers.alice) [ "transfer(address,bytes32,bytes)" ](this.signers.bob.address, encryptedTransferAmount.handles[0], encryptedTransferAmount.inputProof); await expect(tx) - .to.emit(this.encryptedERC20, "Transfer") + .to.emit(this.confidentialERC20, "Transfer") .withArgs(this.signers.alice, this.signers.bob, expectedTransferId); // Decrypt Alice's balance expect( - await reencryptBalance(this.signers, this.instances, "alice", this.encryptedERC20, this.encryptedERC20Address), + await reencryptBalance( + this.signers, + this.instances, + "alice", + this.confidentialERC20, + this.confidentialERC20Address, + ), ).to.equal(mintAmount - transferAmount); // Decrypt Bob's balance expect( - await reencryptBalance(this.signers, this.instances, "bob", this.encryptedERC20, this.encryptedERC20Address), + await reencryptBalance( + this.signers, + this.instances, + "bob", + this.confidentialERC20, + this.confidentialERC20Address, + ), ).to.equal(transferAmount); // Check the error code matches no error @@ -79,8 +97,8 @@ describe("EncryptedERC20WithErrors", function () { this.instances, "alice", expectedTransferId, - this.encryptedERC20, - this.encryptedERC20Address, + this.confidentialERC20, + this.confidentialERC20Address, ), ).to.equal("NO_ERROR"); @@ -91,8 +109,8 @@ describe("EncryptedERC20WithErrors", function () { this.instances, "bob", expectedTransferId, - this.encryptedERC20, - this.encryptedERC20Address, + this.confidentialERC20, + this.confidentialERC20Address, ), ).to.equal("NO_ERROR"); }); @@ -104,31 +122,43 @@ describe("EncryptedERC20WithErrors", function () { const transferAmount = 1337; const expectedTransferId = 0n; - let tx = await this.encryptedERC20.connect(this.signers.alice).mint(mintAmount); + let tx = await this.confidentialERC20.connect(this.signers.alice).mint(mintAmount); await tx.wait(); - const input = this.instances.alice.createEncryptedInput(this.encryptedERC20Address, this.signers.alice.address); + const input = this.instances.alice.createEncryptedInput(this.confidentialERC20Address, this.signers.alice.address); input.add64(transferAmount); const encryptedTransferAmount = await input.encrypt(); - tx = await this.encryptedERC20["transfer(address,bytes32,bytes)"]( + tx = await this.confidentialERC20["transfer(address,bytes32,bytes)"]( this.signers.bob.address, encryptedTransferAmount.handles[0], encryptedTransferAmount.inputProof, ); await expect(tx) - .to.emit(this.encryptedERC20, "Transfer") + .to.emit(this.confidentialERC20, "Transfer") .withArgs(this.signers.alice, this.signers.bob, expectedTransferId); // Decrypt Alice's balance expect( - await reencryptBalance(this.signers, this.instances, "alice", this.encryptedERC20, this.encryptedERC20Address), + await reencryptBalance( + this.signers, + this.instances, + "alice", + this.confidentialERC20, + this.confidentialERC20Address, + ), ).to.equal(mintAmount); // Decrypt Bob's balance expect( - await reencryptBalance(this.signers, this.instances, "bob", this.encryptedERC20, this.encryptedERC20Address), + await reencryptBalance( + this.signers, + this.instances, + "bob", + this.confidentialERC20, + this.confidentialERC20Address, + ), ).to.equal(0); // Check that the error code matches if balance is not sufficient @@ -138,8 +168,8 @@ describe("EncryptedERC20WithErrors", function () { this.instances, "bob", expectedTransferId, - this.encryptedERC20, - this.encryptedERC20Address, + this.confidentialERC20, + this.confidentialERC20Address, ), ).to.equal("UNSUFFICIENT_BALANCE"); }); @@ -150,24 +180,24 @@ describe("EncryptedERC20WithErrors", function () { const mintAmount = 10_000; const transferAmount = 1337; - let tx = await this.encryptedERC20.connect(this.signers.alice).mint(mintAmount); + let tx = await this.confidentialERC20.connect(this.signers.alice).mint(mintAmount); await tx.wait(); const inputAlice = this.instances.alice.createEncryptedInput( - this.encryptedERC20Address, + this.confidentialERC20Address, this.signers.alice.address, ); inputAlice.add64(transferAmount); const encryptedAllowanceAmount = await inputAlice.encrypt(); - tx = await this.encryptedERC20["approve(address,bytes32,bytes)"]( + tx = await this.confidentialERC20["approve(address,bytes32,bytes)"]( this.signers.bob.address, encryptedAllowanceAmount.handles[0], encryptedAllowanceAmount.inputProof, ); await expect(tx) - .to.emit(this.encryptedERC20, "Approval") + .to.emit(this.confidentialERC20, "Approval") .withArgs(this.signers.alice, this.signers.bob, PLACEHOLDER); // @dev The allowance amount is set to be equal to the transfer amount. @@ -177,35 +207,47 @@ describe("EncryptedERC20WithErrors", function () { this.instances, "alice", "bob", - this.encryptedERC20, - this.encryptedERC20Address, + this.confidentialERC20, + this.confidentialERC20Address, ), ).to.equal(transferAmount); const expectedTransferId1 = 0n; - const inputBob1 = this.instances.bob.createEncryptedInput(this.encryptedERC20Address, this.signers.bob.address); + const inputBob1 = this.instances.bob.createEncryptedInput(this.confidentialERC20Address, this.signers.bob.address); inputBob1.add64(transferAmount + 1); // above allowance so next tx should actually not send any token const encryptedTransferAmount = await inputBob1.encrypt(); - const tx2 = await this.encryptedERC20 + const tx2 = await this.confidentialERC20 .connect(this.signers.bob) [ "transferFrom(address,address,bytes32,bytes)" ](this.signers.alice.address, this.signers.bob.address, encryptedTransferAmount.handles[0], encryptedTransferAmount.inputProof); await expect(tx2) - .to.emit(this.encryptedERC20, "Transfer") + .to.emit(this.confidentialERC20, "Transfer") .withArgs(this.signers.alice, this.signers.bob, expectedTransferId1); // Decrypt Alice's balance expect( - await reencryptBalance(this.signers, this.instances, "alice", this.encryptedERC20, this.encryptedERC20Address), + await reencryptBalance( + this.signers, + this.instances, + "alice", + this.confidentialERC20, + this.confidentialERC20Address, + ), ).to.equal(mintAmount); // check that transfer did not happen, as expected // Decrypt Bob's balance expect( - await reencryptBalance(this.signers, this.instances, "bob", this.encryptedERC20, this.encryptedERC20Address), + await reencryptBalance( + this.signers, + this.instances, + "bob", + this.confidentialERC20, + this.confidentialERC20Address, + ), ).to.equal(0); // check that transfer did not happen, as expected // Check that the error code matches if approval is not sufficient @@ -215,35 +257,47 @@ describe("EncryptedERC20WithErrors", function () { this.instances, "bob", expectedTransferId1, - this.encryptedERC20, - this.encryptedERC20Address, + this.confidentialERC20, + this.confidentialERC20Address, ), ).to.equal("UNSUFFICIENT_APPROVAL"); const expectedTransferId2 = 1n; - const inputBob2 = this.instances.bob.createEncryptedInput(this.encryptedERC20Address, this.signers.bob.address); + const inputBob2 = this.instances.bob.createEncryptedInput(this.confidentialERC20Address, this.signers.bob.address); inputBob2.add64(transferAmount); // below allowance so next tx should send token const encryptedTransferAmount2 = await inputBob2.encrypt(); - const tx3 = await await this.encryptedERC20 + const tx3 = await await this.confidentialERC20 .connect(this.signers.bob) [ "transferFrom(address,address,bytes32,bytes)" ](this.signers.alice.address, this.signers.bob.address, encryptedTransferAmount2.handles[0], encryptedTransferAmount2.inputProof); await expect(tx3) - .to.emit(this.encryptedERC20, "Transfer") + .to.emit(this.confidentialERC20, "Transfer") .withArgs(this.signers.alice, this.signers.bob, expectedTransferId2); // Decrypt Alice's balance expect( - await reencryptBalance(this.signers, this.instances, "alice", this.encryptedERC20, this.encryptedERC20Address), + await reencryptBalance( + this.signers, + this.instances, + "alice", + this.confidentialERC20, + this.confidentialERC20Address, + ), ).to.equal(mintAmount - transferAmount); // check that transfer did happen this time // Decrypt Bob's balance expect( - await reencryptBalance(this.signers, this.instances, "bob", this.encryptedERC20, this.encryptedERC20Address), + await reencryptBalance( + this.signers, + this.instances, + "bob", + this.confidentialERC20, + this.confidentialERC20Address, + ), ).to.equal(transferAmount); // check that transfer did happen this time // Verify Alice's allowance is 0 @@ -253,8 +307,8 @@ describe("EncryptedERC20WithErrors", function () { this.instances, "alice", "bob", - this.encryptedERC20, - this.encryptedERC20Address, + this.confidentialERC20, + this.confidentialERC20Address, ), ).to.equal(0); @@ -265,8 +319,8 @@ describe("EncryptedERC20WithErrors", function () { this.instances, "bob", expectedTransferId2, - this.encryptedERC20, - this.encryptedERC20Address, + this.confidentialERC20, + this.confidentialERC20Address, ), ).to.equal("NO_ERROR"); }); @@ -275,13 +329,13 @@ describe("EncryptedERC20WithErrors", function () { const amount = 10_000; const inputAlice = this.instances.alice.createEncryptedInput( - this.encryptedERC20Address, + this.confidentialERC20Address, this.signers.alice.address, ); inputAlice.add64(amount); const encryptedAllowanceAmount = await inputAlice.encrypt(); - const tx = await this.encryptedERC20 + const tx = await this.confidentialERC20 .connect(this.signers.alice) [ "approve(address,bytes32,bytes)" @@ -289,10 +343,10 @@ describe("EncryptedERC20WithErrors", function () { await tx.wait(); - const allowanceHandleAlice = await this.encryptedERC20.allowance(this.signers.alice, this.signers.bob); + const allowanceHandleAlice = await this.confidentialERC20.allowance(this.signers.alice, this.signers.bob); const { publicKey: publicKeyCarol, privateKey: privateKeyCarol } = this.instances.carol.generateKeypair(); - const eip712Carol = this.instances.carol.createEIP712(publicKeyCarol, this.encryptedERC20Address); + const eip712Carol = this.instances.carol.createEIP712(publicKeyCarol, this.confidentialERC20Address); const signatureCarol = await this.signers.carol.signTypedData( eip712Carol.domain, { Reencrypt: eip712Carol.types.Reencrypt }, @@ -305,7 +359,7 @@ describe("EncryptedERC20WithErrors", function () { privateKeyCarol, publicKeyCarol, signatureCarol.replace("0x", ""), - this.encryptedERC20Address, + this.confidentialERC20Address, this.signers.carol.address, ); @@ -320,13 +374,13 @@ describe("EncryptedERC20WithErrors", function () { it("should not be able to read the balance if not user after initialization", async function () { // Mint is used to initialize the balanceOf(alice) const amount = 10_000; - const tx = await this.encryptedERC20.connect(this.signers.alice).mint(amount); + const tx = await this.confidentialERC20.connect(this.signers.alice).mint(amount); await tx.wait(); - const balanceHandleAlice = await this.encryptedERC20.balanceOf(this.signers.alice); + const balanceHandleAlice = await this.confidentialERC20.balanceOf(this.signers.alice); const { publicKey: publicKeyBob, privateKey: privateKeyBob } = this.instances.bob.generateKeypair(); - const eip712Bob = this.instances.bob.createEIP712(publicKeyBob, this.encryptedERC20Address); + const eip712Bob = this.instances.bob.createEIP712(publicKeyBob, this.confidentialERC20Address); const signatureBob = await this.signers.bob.signTypedData( eip712Bob.domain, { Reencrypt: eip712Bob.types.Reencrypt }, @@ -339,7 +393,7 @@ describe("EncryptedERC20WithErrors", function () { privateKeyBob, publicKeyBob, signatureBob.replace("0x", ""), - this.encryptedERC20Address, + this.confidentialERC20Address, this.signers.bob.address, ); expect.fail("Expected an error to be thrown - Bob should not be able to reencrypt Alice's balance"); @@ -354,53 +408,53 @@ describe("EncryptedERC20WithErrors", function () { const NULL_ADDRESS = "0x0000000000000000000000000000000000000000"; const mintAmount = 100_000; const transferAmount = 50_000; - const tx = await this.encryptedERC20.connect(this.signers.alice).mint(mintAmount); + const tx = await this.confidentialERC20.connect(this.signers.alice).mint(mintAmount); await tx.wait(); - const input = this.instances.alice.createEncryptedInput(this.encryptedERC20Address, this.signers.alice.address); + const input = this.instances.alice.createEncryptedInput(this.confidentialERC20Address, this.signers.alice.address); input.add64(transferAmount); const encryptedTransferAmount = await input.encrypt(); await expect( - this.encryptedERC20 + this.confidentialERC20 .connect(this.signers.alice) [ "approve(address,bytes32,bytes)" ](NULL_ADDRESS, encryptedTransferAmount.handles[0], encryptedTransferAmount.inputProof), - ).to.be.revertedWithCustomError(this.encryptedERC20, "ERC20InvalidSpender"); + ).to.be.revertedWithCustomError(this.confidentialERC20, "ERC20InvalidSpender"); }); it("receiver cannot be null address", async function () { const NULL_ADDRESS = "0x0000000000000000000000000000000000000000"; const mintAmount = 100_000; const transferAmount = 50_000; - const tx = await this.encryptedERC20.connect(this.signers.alice).mint(mintAmount); + const tx = await this.confidentialERC20.connect(this.signers.alice).mint(mintAmount); await tx.wait(); - const input = this.instances.alice.createEncryptedInput(this.encryptedERC20Address, this.signers.alice.address); + const input = this.instances.alice.createEncryptedInput(this.confidentialERC20Address, this.signers.alice.address); input.add64(transferAmount); const encryptedTransferAmount = await input.encrypt(); await expect( - this.encryptedERC20 + this.confidentialERC20 .connect(this.signers.alice) [ "transfer(address,bytes32,bytes)" ](NULL_ADDRESS, encryptedTransferAmount.handles[0], encryptedTransferAmount.inputProof), - ).to.be.revertedWithCustomError(this.encryptedERC20, "ERC20InvalidReceiver"); + ).to.be.revertedWithCustomError(this.confidentialERC20, "ERC20InvalidReceiver"); }); it("sender who is not allowed cannot transfer using a handle from another account", async function () { const mintAmount = 100_000; const transferAmount = 50_000; - let tx = await this.encryptedERC20.connect(this.signers.alice).mint(mintAmount); + let tx = await this.confidentialERC20.connect(this.signers.alice).mint(mintAmount); await tx.wait(); - const input = this.instances.alice.createEncryptedInput(this.encryptedERC20Address, this.signers.alice.address); + const input = this.instances.alice.createEncryptedInput(this.confidentialERC20Address, this.signers.alice.address); input.add64(transferAmount); const encryptedTransferAmount = await input.encrypt(); - tx = await this.encryptedERC20 + tx = await this.confidentialERC20 .connect(this.signers.alice) [ "transfer(address,bytes32,bytes)" @@ -408,50 +462,50 @@ describe("EncryptedERC20WithErrors", function () { await tx.wait(); - const balanceHandleAlice = await this.encryptedERC20.balanceOf(this.signers.alice.address); + const balanceHandleAlice = await this.confidentialERC20.balanceOf(this.signers.alice.address); await expect( - this.encryptedERC20.connect(this.signers.bob).transfer(this.signers.carol.address, balanceHandleAlice), - ).to.be.revertedWithCustomError(this.encryptedERC20, "TFHESenderNotAllowed"); + this.confidentialERC20.connect(this.signers.bob).transfer(this.signers.carol.address, balanceHandleAlice), + ).to.be.revertedWithCustomError(this.confidentialERC20, "TFHESenderNotAllowed"); }); it("sender who is not allowed cannot transferFrom using a handle from another account", async function () { const mintAmount = 100_000; const transferAmount = 50_000; - let tx = await this.encryptedERC20.connect(this.signers.alice).mint(mintAmount); + let tx = await this.confidentialERC20.connect(this.signers.alice).mint(mintAmount); await tx.wait(); - let input = this.instances.alice.createEncryptedInput(this.encryptedERC20Address, this.signers.alice.address); + let input = this.instances.alice.createEncryptedInput(this.confidentialERC20Address, this.signers.alice.address); input.add64(mintAmount); const encryptedAllowanceAmount = await input.encrypt(); - tx = await this.encryptedERC20 + tx = await this.confidentialERC20 .connect(this.signers.alice) [ "approve(address,bytes32,bytes)" ](this.signers.carol.address, encryptedAllowanceAmount.handles[0], encryptedAllowanceAmount.inputProof); - input = this.instances.carol.createEncryptedInput(this.encryptedERC20Address, this.signers.carol.address); + input = this.instances.carol.createEncryptedInput(this.confidentialERC20Address, this.signers.carol.address); input.add64(transferAmount); const encryptedTransferAmount = await input.encrypt(); - tx = await this.encryptedERC20 + tx = await this.confidentialERC20 .connect(this.signers.carol) [ "transferFrom(address,address,bytes32,bytes)" ](this.signers.alice.address, this.signers.carol.address, encryptedTransferAmount.handles[0], encryptedTransferAmount.inputProof); - const allowanceHandleAlice = await this.encryptedERC20.allowance( + const allowanceHandleAlice = await this.confidentialERC20.allowance( this.signers.alice.address, this.signers.carol.address, ); await expect( - this.encryptedERC20 + this.confidentialERC20 .connect(this.signers.bob) .transferFrom(this.signers.alice.address, this.signers.bob.address, allowanceHandleAlice), - ).to.be.revertedWithCustomError(this.encryptedERC20, "TFHESenderNotAllowed"); + ).to.be.revertedWithCustomError(this.confidentialERC20, "TFHESenderNotAllowed"); }); it("cannot reencrypt errors if the account is not a participant of the transfer", async function () { @@ -459,27 +513,27 @@ describe("EncryptedERC20WithErrors", function () { const transferAmount = 1337; const expectedTransferId = 0; - let tx = await this.encryptedERC20.connect(this.signers.alice).mint(mintAmount); + let tx = await this.confidentialERC20.connect(this.signers.alice).mint(mintAmount); await tx.wait(); - const input = this.instances.alice.createEncryptedInput(this.encryptedERC20Address, this.signers.alice.address); + const input = this.instances.alice.createEncryptedInput(this.confidentialERC20Address, this.signers.alice.address); input.add64(transferAmount); const encryptedTransferAmount = await input.encrypt(); - tx = await this.encryptedERC20 + tx = await this.confidentialERC20 .connect(this.signers.alice) [ "transfer(address,bytes32,bytes)" ](this.signers.bob.address, encryptedTransferAmount.handles[0], encryptedTransferAmount.inputProof); await expect(tx) - .to.emit(this.encryptedERC20, "Transfer") + .to.emit(this.confidentialERC20, "Transfer") .withArgs(this.signers.alice, this.signers.bob, expectedTransferId); - const errorCodeHandle = await this.encryptedERC20.getErrorCodeForTransferId(expectedTransferId); + const errorCodeHandle = await this.confidentialERC20.getErrorCodeForTransferId(expectedTransferId); const { publicKey: publicKeyCarol, privateKey: privateKeyCarol } = this.instances.carol.generateKeypair(); - const eip712Carol = this.instances.carol.createEIP712(publicKeyCarol, this.encryptedERC20Address); + const eip712Carol = this.instances.carol.createEIP712(publicKeyCarol, this.confidentialERC20Address); const signatureCarol = await this.signers.carol.signTypedData( eip712Carol.domain, { Reencrypt: eip712Carol.types.Reencrypt }, @@ -492,7 +546,7 @@ describe("EncryptedERC20WithErrors", function () { privateKeyCarol, publicKeyCarol, signatureCarol.replace("0x", ""), - this.encryptedERC20Address, + this.confidentialERC20Address, this.signers.carol.address, ); expect.fail( @@ -507,11 +561,11 @@ describe("EncryptedERC20WithErrors", function () { it("sender who is not allowed cannot approve using a handle from another account", async function () { const amount = 100_000; - const input = this.instances.alice.createEncryptedInput(this.encryptedERC20Address, this.signers.alice.address); + const input = this.instances.alice.createEncryptedInput(this.confidentialERC20Address, this.signers.alice.address); input.add64(amount); const encryptedAllowanceAmount = await input.encrypt(); - const tx = await this.encryptedERC20 + const tx = await this.confidentialERC20 .connect(this.signers.alice) [ "approve(address,bytes32,bytes)" @@ -519,19 +573,19 @@ describe("EncryptedERC20WithErrors", function () { await tx.wait(); - const allowanceHandleAlice = await this.encryptedERC20.allowance( + const allowanceHandleAlice = await this.confidentialERC20.allowance( this.signers.alice.address, this.signers.carol.address, ); await expect( - this.encryptedERC20.connect(this.signers.bob).approve(this.signers.carol.address, allowanceHandleAlice), - ).to.be.revertedWithCustomError(this.encryptedERC20, "TFHESenderNotAllowed"); + this.confidentialERC20.connect(this.signers.bob).approve(this.signers.carol.address, allowanceHandleAlice), + ).to.be.revertedWithCustomError(this.confidentialERC20, "TFHESenderNotAllowed"); }); - it("EncryptedERC20WithErrorsMintable - only owner can mint", async function () { - await expect(this.encryptedERC20.connect(this.signers.bob).mint(1)).to.be.revertedWithCustomError( - this.encryptedERC20, + it("ConfidentialERC20WithErrorsMintable - only owner can mint", async function () { + await expect(this.confidentialERC20.connect(this.signers.bob).mint(1)).to.be.revertedWithCustomError( + this.confidentialERC20, "OwnableUnauthorizedAccount", ); }); diff --git a/test/governance/Comp.test.ts b/test/governance/Comp.test.ts index 1e0ea18..13d3e67 100644 --- a/test/governance/Comp.test.ts +++ b/test/governance/Comp.test.ts @@ -2,7 +2,7 @@ import { expect } from "chai"; import { parseUnits } from "ethers"; import { ethers, network } from "hardhat"; -import { reencryptBalance } from "../encryptedERC20/EncryptedERC20.fixture"; +import { reencryptBalance } from "../confidentialERC20/ConfidentialERC20.fixture"; import { createInstances } from "../instance"; import { reencryptEuint64 } from "../reencrypt"; import { getSigners, initSigners } from "../signers";