Skip to content

Commit

Permalink
refactor: rename EncryptedERC20 to ConfidentialERC20
Browse files Browse the repository at this point in the history
  • Loading branch information
PacificYield committed Dec 2, 2024
1 parent b46311c commit dc0b832
Show file tree
Hide file tree
Showing 21 changed files with 387 additions and 277 deletions.
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand All @@ -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);
}
}
Expand All @@ -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

Expand Down
8 changes: 4 additions & 4 deletions contracts/governance/Comp.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
Expand Down Expand Up @@ -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_;

Expand Down
Original file line number Diff line number Diff line change
@@ -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_) {
//
}
}
Original file line number Diff line number Diff line change
@@ -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_) {
//
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -43,15 +43,15 @@ 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));
return true;
}

/**
* @notice See {IEncryptedERC20-approve}.
* @notice See {IConfidentialERC20-approve}.
*/
function approve(address spender, euint64 amount) public virtual returns (bool) {
_isSenderAllowedForAmount(amount);
Expand All @@ -62,15 +62,15 @@ 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));
return true;
}

/**
* @notice See {IEncryptedERC20-transfer}.
* @notice See {IConfidentialERC20-transfer}.
*/
function transfer(address to, euint64 amount) public virtual returns (bool) {
_isSenderAllowedForAmount(amount);
Expand All @@ -82,7 +82,7 @@ abstract contract EncryptedERC20 is IEncryptedERC20, IERC20Errors, TFHEErrors {
}

/**
* @notice See {IEncryptedERC20-transferFrom}.
* @notice See {IConfidentialERC20-transferFrom}.
*/
function transferFrom(
address from,
Expand All @@ -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);
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}.
Expand All @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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`).
*/
Expand All @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
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,
* and setting allowances, but uses encrypted data types.
* 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
Expand All @@ -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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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`).
*/
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion docs/governance/Comp.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Loading

0 comments on commit dc0b832

Please sign in to comment.