ERC-7722 Opaque tokens (Opaque Token)
Draft · Tokens · created 2024-06-09
A privacy token standard that records balances on the blockchain not as plain numbers but wrapped in hashed 'baskets,' so that an account's token holdings and transaction amounts cannot be known externally.
Why it is needed
Smart contract accounts are very useful for identity purposes because credentials or attestations can be attached to them and reused across multiple contexts. However, holding existing ERC-20 tokens with such accounts creates a problem. ERC-20 records balances on the blockchain as plaintext numbers, so anyone can look up how many tokens that account holds. When an account with a clearly exposed identity is linked to a public balance, sensitive financial information is revealed as a result. In other words, the more one tries to take advantage of reusing an identity, the greater the risk that asset details are exposed. This proposal aims to hide balances on-chain behind hashes, so that such accounts can hold tokens while preserving both privacy and integrity.
What to implement
event CreateToken(address initiatedBy, bytes32 tokenId, bytes32 totalSupplyBasket, bytes32 ref);: Must be emitted when a new token is created. Records the creator address, token ID, and total supply basket.event Issue(address initiatedBy, bytes32[] baskets, address receiver, bytes32 ref);: Must be emitted when tokens are issued. Records the baskets issued to the recipient.event ReorgHolderBaskets(address initiatedBy, bytes32[] basketsIn, bytes32[] basketsOut, bytes32 ref);: Must be emitted when a holder's baskets are reorganized. Records the baskets that disappear and the baskets newly created.event ReorgSupplyBaskets(address initiatedBy, bytes32[] basketsIn, bytes32[] basketsOut, bytes32 ref);: Must be emitted when supply baskets are reorganized.event Transfer(address initiatedBy, address receiver, bytes32[] baskets, bytes32 ref);: Must be emitted when a basket is transferred to another address.event Redeem(address initiatedBy, bytes32[] baskets, bytes32 ref);: Must be emitted when a basket is redeemed.function oracleConfig() external view returns (ORACLECONFIG memory);: Returns this token's oracle configuration (the minimum number of signatures required and the list of valid oracle addresses).function owner(bytes32 basket) external view returns (address);: Returns the owner address of the given basket.function totalSupply(bytes32 tokenId) external view returns (bytes32);: Returns the total supply of the token ID in the form of a basket hash. The actual value can be looked up off-chain by investors through the operator's off-chain storage.function operator() external view returns (address);: Returns this token's operator address. The operator is responsible for providing the primary off-chain storage.
In depth
Basket: a hash that hides the balance
Balances are recorded on-chain as a hash of the form keccak256(abi.encode(salt, tokenId, value)). salt is a random 32 bytes that increases entropy so the hash cannot be broken by brute force, tokenId is an identifier (bytes32) unique within that token contract, and value is the value of that position (uint256). It is called a basket because, just as a covered basket hides its contents, the hash hides the balance information. Since the value cannot be determined directly on-chain, balance lookups are only possible for parties with access to the off-chain data.
Two roles: operator and user
The token operator creates the token, issues positions, and controls the supply that is not yet in circulation (the supply basket). The operator uses createToken, reorgSupplyBaskets, and issue, and per the original role description also has the authority to take forced actions via the forceTransfer and forceReorg functions. The token user is an address holding tokens in circulation (owned baskets) and uses transfer, basket reorganization, and redeem. For lookups there is owner, which tells the basket's owner; oracleConfig, which tells the oracle configuration; operator, which tells the operator address; and totalSupply, which tells the total supply as a basket hash.
Off-chain storage obligations
The operator must provide off-chain storage with GET basket and PUT basket REST endpoints. Basket data (salt, tokenId, value) must be shared only on a need-to-know basis with eligible addresses that are past or current holders, and both endpoints must implement authentication. The specific authentication method is not defined by the standard. PUT stores the data when the basket hash matches it, and GET looks up a specific basket by hash or returns all baskets belonging to the requester. In case the operator's service goes down, holders are recommended to keep a copy of their own basket data in their own storage.
Reorganization and oracle verification
A reorganization (reorg) that splits or merges baskets requires that the sum of the input basket values equal the sum of the output basket values. To guarantee this, an external oracle receives the proposal via the POST reorg endpoint and signs keccak256(abi.encode(basketsIn, basketsOut)) only when the sums grouped by tokenId match on both sides and each basket hash matches its data. The minimum number of required signatures and the list of valid oracles are set via ORACLECONFIG. The oracle endpoint must be stateless, must not retain request data for later analysis, and must be usable by anyone without authentication. Because the holder proposes and the oracle verifies in a mutual-control structure, neither side can manipulate it alone, and a fraudulent oracle can be traced on-chain, so at least weak integrity is guaranteed. A zero-knowledge proof (ZKP) could be used instead, but the oracle approach was chosen for efficiency and simplicity.
Adding noise (differential privacy)
To further increase privacy, noise is added through reorganizations and empty transfers. If a received basket is sent on to someone else as is, the previous owner can learn about the recipient's subsequent receipts, so the received basket is first merged and reorganized with one's own baskets before being sent, after which the previous owner can no longer track it. Also, mixing in empty transfers of zero-value baskets to random counterparties means that while an observer can see who is transacting with whom, they cannot tell which of those transfers actually moves real value.
Deliberately forgoing ERC-20 compatibility
ERC-20 has a structure that exposes balances transparently, which is problematic when used together with reusable blockchain identities. This standard prioritizes balance confidentiality over ERC-20 compatibility and forgoes it. The choice to place the primary store of off-chain data with the operator (typically the issuer or registrar) is explained as acceptable, since the operator needs to know which investor holds which position anyway in order to manage the token's lifecycle. It may not fit every use case in the Ethereum ecosystem, but it states that it fits well for financial instruments in regulated financial industries that follow strict KYC and token operating procedures.
A Proposal in Draft Stage
This ERC is in Draft status, created on June 9, 2024. The security considerations section is also still being written in detail, so the specification may change or progress may stall going forward.
Things to watch out for
- Fraudulent oracles: The source lists Fraudulent Oracles as a security considerations item, but the details have not yet been written. The body only explains that a fraudulent oracle can be traced on-chain.
- Oracle collection of confidential data: The risk of an oracle collecting confidential data is listed as an item, but the details have not yet been written. The specification stipulates that an oracle must not retain request data for later analysis.
- Loss of confidential data: The risk of losing basket data (salt, tokenId, value) is listed as an item, but the details have not yet been written. The specification recommends that holders keep a copy of their own basket data.