Zama 백서

bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 75쪽 중 17쪽

apper holds fewer underlying tokens than shares outstanding, resulting in undercollateralization | | **Pausable** | A privileged account can suspend all token transfers | USDC, USDT | Wrap and unwrap operations revert for the duration of the pause | | **Blocklist/allowlist** | A privileged account can restrict transfers to or from specific addresses | USDC, USDT | The wrapper contract address may be blocked, preventing all wrap and unwrap operations | | **Upgradeable** | The token implementation can be replaced after deployment | USDC (proxy) | A logic upgrade may alter token behavior in ways that are incompatible with the wrapper | | **Multiple entry points** | Two contract addresses share the same underlying balance | Old Synthetix SNX/ProxyERC20 | The same underlying balance can be wrapped twice, inflating the confidential supply | | **Flash-mintable** | Tokens can be minted without collateral within a single transaction | DAI (flash mint) | Transient supply spikes may interfere with `inferredTotalSupply()` based checks | | **ERC-777 hooks** | Transfers invoke callbacks on the sender and receiver | imBTC | Callbacks introduce reentrancy vectors during wrap and unwrap operations | | **Non-standard decimals** | The token uses fewer than 18 decimals | USDC (6), WBTC (8), GUSD (2) | **Supported**: The wrapper normalizes precision automatically via `rate()` -- See the section on [decimal conversion](#check-the-conversion-rate-and-decimals) | ## Interface Support (ERC-165) | Interface | Interface ID | | ---------------------- | ------------ | | `IERC7984` | `0x4958f2a4` | | `IERC7984ERC20Wrapper` | `0x1f1c62b2` | | `IERC1363Receiver` | `0x88a7ca5c` | | `IERC165` | `0x01ffc9a7` | ```solidity wrapper.supportsInterface(type(IERC7984).interfaceId) == true; // 0x4958f2a4 wrapper.supportsInterface(type(IERC7984ERC20Wrapper).interfaceId) == true; // 0x1f1c62b2 wrapper.supportsInterface(type(IERC1363Receiver).interfaceId) == true; // 0x88a7ca5c wrapper.supportsInterface(type(IERC165).interfaceId) == true; // 0x01ffc9a7 ``` ## Upgradeability The contract uses **UUPS (Universal Upgradeable Proxy Standard)** with 2-step ownership transfer. Only the owner can upgrade the contract. Initially, the owner is set to the Protocol DAO governance (see [governance.md](/protocol/protocol-apps/governance/governance)). Ownership will then be transferred to the underlying token's owner. # Registry This document explains the **Confidential Token Wrappers Registry,** an onchain directory that maps ERC-20 tokens to their corresponding ERC-7984 confidential token wrappers. Use it to discover, validate, and integrate confidential wrappers within the FHEVM ecosystem. ## Terminology * **Token**: An ERC-20 token. * **Confidential Wrapper**: An ERC-7984 confidential token wrapper. Also called "confidential token". * **Underlying Token**: The ERC-20 token that the confidential wrapper is associated with. * **TokenWrapperPair**: A pair of a token and its confidential wrapper. * **Valid**: A valid confidential wrapper has been verified by the registry owner and can be used to wrap and unwrap tokens from the underlying token. * **Invalid**: An invalid confidential wrapper has been revoked by the registry owner and should not be used to wrap and unwrap tokens from the underlying token. * **Owner**: The owner of the registry. In the FHEVM protocol, this is the Protocol DAO governance (see [governance.md](/protocol/protocol-apps/governance/governance)). ## Contract information | Resource | Link | | ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | Deployed addresses | [Addresses directory](/protocol/protocol-apps/addresses) | | Source code | [ConfidentialTokenWrappersRegistry.sol](https://github.com/zama-ai/protocol-apps/blob/main/contracts/confidential-token-wrappers-registry/contracts/ConfidentialTokenWrappersRegistry.sol) | ## Structure {% @mermaid/diagram content="flowchart subgraph Ethereum Protocol-DAO -- owner --> Registry Registry -- registers --> Confidential-Wrapper Protocol-DAO -- owner --> Confidential-Wrapper end" %} More information on confidential wrappers can be found in the [confidential-wrapper.md](/protocol/protocol-apps/confidential-tokens/confidential-wrapper) file. ## Quick Start {% hint style="info" %} A token can only be associated with one confidential wrapper. A confidential wrapper can only be associated with one token. {% endhint %} {% hint style="warning" %} **Always check validity:** A non-zero wrapper address may be revoked by the owner. Always verify the `isValid` flag associated with the (token, wrapper) pair before use. {% endhint %} ### Find the confidential wrapper of a token ```solidity (bool isValid, address confidentialToken) = registry.getConfidentialTokenAddress(erc20TokenAddress); ``` If the token has been registered with a confidential wrapper: * `isValid` will be `true` * `confidentialToken` will be the address of the confidential wrapper. If the token has never been registered with a confidential wrapper: * `isValid` will be `false` * `confidentialToken` will be `address(0)`. If the confidential wrapper has been revoked: * `isValid` will be `false` * `confidentialToken` will be the address of the (revoked) confidential wrapper. ### Find the underlying token of a confidential wrapper ```solidity (bool isValid, address token) = registry.getTokenAddress(confidentialWrapperAddress); ``` If the confidential wrapper has been registered with a token: * `isValid` will be `true` * `token` will be the address of its underlying token. If the confidential wrapper has never been registered with a token: * `isValid` will be `false` * `token` will be `address(0)`. If the confidential wrapper has been revoked: * `isValid` will be `false` * `token` will be the address of its underlying token. ### Check if a confidential wrapper is valid ```solidity bool isValid = registry.isConfidentialTokenValid(confidentialWrapperAddress); ``` If the confidential wrapper has been revoked, * `isValid` will be `false`. If the confidential wrapper has not been revoked (it is still valid), * `isValid` will be `true`. ## Integration patterns Token and confidential wrapper pairs are stored in the registry as `TokenWrapperPair` structs. Each struct contains: * `tokenAddress`: the address of the underlying token. * `confidentialTokenAddress`: the address of the confidential wrapper. * `isValid`: `true` if the confidential wrapper is valid, `false` if it has been revoked. ### Get all valid confidential (token, wrapper) pairs ```solidity TokenWrapperPair[] memory tokenConfidentialTokenPairs = registry.getTokenConfidentialTokenPairs(); ``` It returns all confidential wrappers (including revoked ones). ### Get the total number of confidential (token, wrapper) pairs ```solidity uint256 totalTokenConfidentialTokenPairs = registry.getTokenConfidentialTokenPairsLength(); ``` ### Get the index of a token ```solidity uint256 tokenIndex = registry.getTokenIndex(tokenAddress); ``` `tokenAddress` must be a registered token. Otherwise, it will revert with `TokenNotRegistered`. ### Get a valid confidential (token, wrapper) pair by index ```solidity TokenWrapperPair memory tokenConfidentialTokenPair = registry.getTokenConfidentialTokenPair(index); ``` It returns a single confidential (token, wrapper) pair (including revoked ones). ### Get a slice of confidential (token, wrapper) pairs ```solidity TokenWrapperPair[] memory tokenConfidentialTokenPairsSlice = registry.getTokenConfidentialTokenPairsSlice(fromIndex, toIndex); ``` It returns a slice of confidential (token, wrapper) pairs (including revoked ones). `fromIndex` is included and `toIndex` is excluded. ## Data Structures ### TokenWrapperPair ```solidity struct TokenWrapperPair { address tokenAddress; // The ERC-20 token address confidentialTokenAddress; // The ERC-7984 wrapper bool isValid; // false if revoked } ``` ## Events | Event | Description | | --------------------------------------------------------------------- | ------------------------------------- | | `ConfidentialTokenRegistered(tokenAddress, confidentialTokenAddress)` | Emitted when a new pair is registered | | `ConfidentialTokenRevoked(tokenAddress, confidentialTokenAddress)` | Emitted when a wrapper is revoked | ## Errors | Error | Cause | | --------------------------------------------------------------------------------------------- | ------------------------------------------------------ | | `TokenZeroAddress()` | Attempted to register with zero token address | | `ConfidentialTokenZeroAddress()` | Attempted to register/revoke with zero wrapper address | | `TokenAddressIsConfidentialTokenAddress(tokenAddress)` | Token and confidential token addresses are the same | | `NotERC7984(confidentialTokenAddress)` | Wrapper doesn't support ERC-7984 interface | | `ConfidentialTokenDoesNotSupportERC165(confidentialTokenAddress)` | Wrapper doesn't implement ERC-165 | | `ConfidentialTokenAlreadyAssociatedWithToken(confidentialTokenAddress, existingTokenAddress)` | Wrapper already registered to another token | | `TokenAlreadyAssociatedWithConfidentialToken(tokenAddress, existingConfidentialTokenAddress)` | Token already has a registered wrapper | | `RevokedConfidentialToken(confidentialTokenAddress)` | Attempting to revoke an already-revoked wrapper | | `NoTokenAssociatedWithConfidentialToken(confidentialTokenAddress)` | Attempting to revoke unregistered wrapper | | `FromIndexGreaterOrEqualToIndex(fromIndex, toIndex)` | Invalid slice range | | `TokenNotRegistered(tokenAddress)` | Token has not been registered | ## Owner Administration {% hint style="info" %} All administrative actions are restricted to the registry owner. {% endhint %} ### Register a confidential token ```solidity registry.registerConfidentialToken( erc20TokenAddress, confidentialWrapperAddress ); ``` **Validation performed:** * Neither address can be zero * Confidential token must implement ERC-165 (`supportsInterface` function) and support the ERC-7984 interface (`0x4958f2a4`) * Token must not already have an associated wrapper * Confidential token must not already be associated with another token ### Revoke a confidential token ```solidity registry.revokeConfidentialToken(confidentialWrapperAddress); ``` **Important:** Revocation does NOT delete the mapping—it only sets `isValid = false`. This preserves historical records and prevents re-registration of malicious addresses. Revoking is currently permanent. When a wrapper is revoked: * `isValid` is set to `false` * The mapping entries remain in storage * The token cannot be registered with a new wrapper ## Upgradeability The contract uses **UUPS (Universal Upgradeable Proxy Standard)** with 2-step ownership transfer. Only the owner can upgrade the contract. # Native Confidential token This document gives high-level **guidelines** for designing a *native confidential token*: a token contract that directly implements the [ERC-7984](https://eips.ethereum.org/EIPS/eip-7984) confidential token standard, managing its own encrypted supply rather than wrapping an existing ERC-20. It is intentionally scoped to design considerations only. The code snippets below are illustrative sketches meant to make the guidelines concrete — they are not production-ready, and this document does not cover deployment or tooling. ## Terminology * **Native confidential token**: A token contract that directly implements the ERC-7984 confidential token standard. * **ERC-7984**: A confidential fungible token standard where balances and transfer amounts are encrypted. * **Owner**: The privileged account that administers the token (for example, mint authority or upgrade authority). * **Operator**: An address authorized to transfer confidential tokens on behalf of a holder for a limited period of time. * **ACL**: The Access Control List (ACL) contract used by the FHEVM to manage who is allowed to use a ciphertext. More information in the [ACL guide](https://docs.zama.org/protocol/solidity-guides/smart-contract/acl). * **Input proof**: A proof that an encrypted input is valid. More information in the [Zama SDK documentation](https://docs.zama.org/protocol/sdk/guides/encrypt-decrypt). ## Guidelines ### Precision and supply bounds ERC-7984 stores confidential amounts as `euint64`. This means the confidential supply is bounded by `type(uint64).max`, and the token's decimals must be chosen with that bound in mind. Pick a decimals value (for example, `6`) that leaves enough headroom for the intended maximum supply. ### Token shape A native confidential token composes the ERC-7984 base with the FHEVM config and your chosen access-control model. The skeleton below shows the shape — an owner-gated `mint`, a holder-driven `burn`, and encrypted amounts passed in as external ciphertexts with an input proof: ```solidity // SPDX-License-Identifier: BSD-3-Clause-Clear pragma solidity ^0.8.27; import {FHE, externalEuint64, euint64} from "@fhevm/solidity/lib/FHE.sol"; contract NativeConfidentialToken is ERC7984, ZamaMultiChainConfig, Ownable2Step { function mint( address to, externalEuint64 encryptedAmount, bytes calldata inputProof ) external onlyOwner returns (euint64) { return _mint(to, FHE.fromExternal(encryptedAmount, inputProof)); } function burn( externalEuint64 encryptedAmount, bytes calldata inputProof ) external returns (euint64) { return _burn(msg.sender, FHE.fromExternal(encryptedAmount, inputProof)); } } ``` ### Choosing a minting strategy Decide up front how the initial supply is issued. Common options: * **Zero initial supply, then mint later** — simplest option; confidential issuance is controlled by the owner after the token exists. Best when you want the simplest setup and owner-controlled issuance over time. No genesis logic is needed: rely on the owner-gated `mint` shown above. * **Public initial allocations** — recipients and amounts are set at genesis in cleartext. Best when the initial distribution does not need to be confidential. Amounts are encrypted on the way in with `FHE.asEuint64`: ```solidity for (uint256 i = 0; i < initialHolders.length; i++) { _mint(initialHolders[i], FHE.asEuint64(initialAmounts[i])); } ``` * **Confidential genesis allocations** — initial amounts are encrypted from the start. Best when confidentiality must hold from day one, but it requires extra choreography (encrypted inputs and proofs supplied at initialization rather than as plain `uint64` values). ### Confidential transfers Balances and transfer amounts are encrypted, so transfers move ciphertexts rather than cleartext values. As with ERC-7984 in general, a transfer takes the amount either as an external ciphertext plus an input proof, or as an `euint64` handle the caller already has ACL permission for. A holder transfers their own tokens directly: ```solidity // With an input proof (fresh external ciphertext)... token.confidentialTransfer(to, encryptedAmount, inputProof); // ...or with an already-permitted handle. token.confidentialTransfer(to, encryptedAmountHandle); ``` An approved [operator](#operator-approvals) transfers on a holder's behalf with `confidentialTransferFrom`. To move tokens into a contract that needs to react to the transfer, prefer the callback variant so delivery and notification happen in one transaction, without a standing operator allowance: ```solidity // Operator-driven transfer. token.confidentialTransferFrom(from, to, encryptedAmount, inputProof); // Transfer into a receiver contract, notifying it in the same transaction. token.confidentialTransferAndCall(to, encryptedAmount, inputProof, callbackData); ``` ### ACL permissions Encrypted balances and amounts are ciphertexts governed by the ACL. When designing flows, make sure the caller and the contract have the necessary ACL permissions for any ciphertext that will be reused, and that encrypted inputs are generated for the correct token contract address. Missing permissions are the most common source of failures when working with confidential values. ```solidity // Bring an external ciphertext in-contract, then grant the reuse permissions it needs. euint64 amount = FHE.fromExternal(encryptedAmount, inputProof); FHE.allowThis(amount); // allow this contract to reuse the ciphertext FHE.allow(amount, msg.sender); // allow the caller to decrypt it ``` ### Operator approvals Operators can move confidential tokens on behalf of a holder for a limited time. To limit exposure: * Keep operator approvals short-lived. * Prefer dedicated operational accounts rather than broad, shared wallets. * Revoke or replace approvals when workflows change. ```solidity // Authorize an operator until a timestamp, then transfer on the holder's behalf. token.setOperator(operator, validUntilTimestamp); bool authorized = token.isOperator(holder, operator); token.confidentialTransferFrom(from, to, encryptedAmount, inputProof); ``` ### Access control and administration Guard privileged actions (minting, and any administrative logic) behind clear ownership. Keep the set of privileged actions small and explicit, and document who holds each authority. ### Upgradeability First decide whether the token needs to be upgradeable at all. An immutable token gives holders the strongest guarantee that its rules cannot change (the ZAMA ERC20, for instance, is deliberately **not** upgradeable), while an upgradeable token trades some of that guarantee for the ability to fix bugs or evolve behavior. If you do make it upgradeable, follow the same pattern as the confidential wrapper: **UUPS (Universal Upgradeable Proxy Standard)** with 2-step ownership transfer, where only the owner can authorize an upgrade. Swap each base for its `Upgradeable` counterpart — [`ERC7984Upgradeable`](https://github.com/zama-ai/protocol-apps/tree/main/contracts/confidential-wrapper/contracts/token/ERC7984Upgradeable.sol) and [`ZamaMultiChainConfigUpgradeable`](https://github.com/zama-ai/protocol-apps/tree/main/contracts/confidential-wrapper/contracts/fhevm/ZamaMultiChainConfigUpgradeable.sol) — disable initializers in the constructor, and initialize through an `initialize` function rather than the constructor. The FHEVM config base is not optional: it points the contract at the coprocessor for the target chain (`FHE.setCoprocessor(...)`), and without it encrypted operations have no backend to run against. In an upgradeable contract it must be initialized like any other base (`__ZamaMultiChainConfig_init()`) rather than set in the constructor: ```solidity contract NativeConfidentialToken is ERC7984Upgradeable, ZamaMultiChainConfigUpgradeable, Ownable2StepUpgradeable, UUPSUpgradeable { /// @custom:oz-upgrades-unsafe-allow constructor constructor() { _disableInitializers(); } function initialize(string memory name_, string memory symbol_, address owner_) public initializer { __ERC7984_init(name_, symbol_, ""); __ZamaMultiChainConfig_init(); __Ownable_init(owner_); __Ownable2Step_init(); } function _authorizeUpgrade(address newImplementation) internal override onlyOwner {} } ``` Whoever holds ownership controls upgrades, so treat the upgrade authority as the token's most sensitive privilege — prefer a governance or multisig owner over an EOA. ## Further reading * [ERC-7984](https://eips.ethereum.org/EIPS/eip-7984) * [`ERC7984Upgradeable.sol`](https://github.com/zama-ai/protocol-apps/tree/main/contracts/confidential-wrapper/contracts/token/ERC7984Upgradeable.sol) — upgradeable ERC-7984 base used by the confidential wrapper * [`ZamaMultiChainConfigUpgradeable.sol`](https://github.com/zama-ai/protocol-apps/tree/main/contracts/confidential-wrapper/contracts/fhevm/ZamaMultiChainConfigUpgradeable.sol) — wires the contract to the FHEVM coprocessor * [Zama ACL guide](https://doc
프로젝트로 돌아가기