ERC-6604 Abstract token
Draft · Tokens · created 2023-03-03
A standard that lets tokens be issued off-chain as messages at no cost, and brought on-chain or reverted back into a message only when needed.
Why it is needed
Distributing tokens usually requires the issuer or recipient to execute an issuance transaction on-chain, incurring a fee each time. For services that distribute tokens to tens of thousands of people, such as airdrops, proof-of-attendance tokens, or access credentials, this cost is a significant burden. The Merkle tree approach, which shifts the cost to the recipient, is commonly used, but it is inconvenient because users must obtain and submit a Merkle proof themselves, and claim methods differ by project. There is also no common interface for wallets or apps to recognize and display potential tokens that have not yet been put on-chain. This standard aims to solve this by allowing token information to be queried and brought on-chain the same way regardless of which proof method is used.
What to implement
function reify(AbstractTokenMessage calldata message) external;: Takes a token message and instantiates the token defined within it on-chain. The same message can only be instantiated once.function status(AbstractTokenMessage calldata message) external view returns (AbstractTokenMessageStatus status);: Returns the status of whether a given message is valid, already used, or invalid.function dereify(AbstractTokenMessage calldata message) external;: An optional feature that burns a held token and reverts it into a message targeting another contract or chain.function id(AbstractTokenMessage calldata message) external view returns (uint256);: Returns the id of the token defined in the message. Implementations without an id concept, such as ERC-20, may return 0 or omit this.function amount(AbstractTokenMessage calldata message) external view returns (uint256);: Returns the quantity of the token defined in the message. Implementations without a quantity concept, such as ERC-721, may return 0 or omit this.function uri(AbstractTokenMessage calldata message) external view returns (string memory);: Returns the uri of the token defined in the message. Implementations without a uri, such as ERC-20, may return an empty string or omit this.event Reify(AbstractTokenMessage);: An event emitted when a token message is instantiated into a token.event Dereify(AbstractTokenMessage);: An event emitted when a token is de-instantiated back into a message.
In depth
Token message structure
The AbstractTokenMessage struct bundles a token together with the context needed to reify it. chainId and implementation scope which chain and which contract the message can be reified on. owner is the address that will own the token once it is reified. meta is implementation-specific context such as id, amount, and uri, and proof is an implementation-specific proof authorizing reification. nonce is a counter appended to distinguish multiple messages that are otherwise identical. The reason meta and proof are typed as bytes is covered in the Rationale: apps can query the contract instead of interpreting these fields directly, the implementation contract can decode them into a struct internally for verification, and the fields can hold any proof format, whether an array of merkle nodes or a 65 byte signature.
Message status
The AbstractTokenMessageStatus enum is defined per (contract, message) pair. invalid means the contract cannot interact with that message, valid means it can, and used means the interaction has already happened. Anyone can query this via the status function, so wallets or apps can check whether a message is usable before spending it.
Rules for reify
reify is the function that moves the token defined in a message into the contract. A contract MUST reify a valid token message. Reification must be idempotent, meaning a given message can be used to reify a token at most once. Calling reify with an already-used message MAY succeed or MAY revert. When a message is reified, a Reify event MUST be emitted.
Rules for dereify
dereify is an optional function that converts a token held in the contract back into a message targeting another contract or chain. It allows a token to be moved by dereifying it in one context and reifying it in another. If implemented, it MUST burn from the holder exactly the token defined in the message, and MUST NOT dereify a message that targets the same contract and same chain. Dereification must also be idempotent, and calling it on an already-used message may succeed or revert. A Dereify event MUST be emitted when a token is dereified into a message.
Query functions and ERC-165
id, amount, and uri are all optional functions. An implementation without a token id, like ERC-20, may return 0 for id or omit it entirely; an implementation without an amount, like ERC-721, may omit amount the same way; and an implementation without a uri, like ERC-20, may omit uri the same way. These query functions let users read the contents of their potential tokens without knowing which proof scheme the implementation uses. Every abstract token contract must support ERC-165 and include the abstract token interface ID in its supported interfaces.
Integration with existing token standards
An abstract token that is compatible with an existing standard must overload the existing transfer functions to support transferring from a message. IAbstractERC20 adds versions of transfer and transferFrom that take an AbstractTokenMessage argument, reifying the message first and then transferring. IAbstractERC721 adds the same message argument to safeTransferFrom and transferFrom, and IAbstractERC1155 adds it to safeTransferFrom and safeBatchTransferFrom in the same way. Batch transfers take an array of messages. This lets a received message be brought onchain and sent to another address in a single step.
Proposal status
This proposal has been in Draft status since March 2023. Its contents may change or stall, so check the latest status before implementing or depending on it.
Things to watch out for
- Lost messages: Because token messages are not stored onchain, losing a message can mean losing the token. An app issuing abstract tokens can hold messages on the user's behalf, but ideally users should be able to store and manage messages themselves within a wallet.
- Designing reification authorization: A message is only reified if it carries a valid proof. The proof scheme itself is out of scope for the standard, but designers must consider whether total supply needs to be auditable on and off chain, whether the scheme relies on continued access to a secret (like a signature) versus being immutable (like a merkle proof), and whether an attacker could prevent a valid message from being reified.
- (De)reification by someone other than the owner: It must be decided whether someone other than the owner can (de)reify on the owner's behalf. Allowing this has the advantage that a valid message can be spent by the owner at any time, which apps can rely on, but if the contract reverts on an already-used message, an attacker could front-run the transaction to harass the owner.
- Bridge double-spending: This standard does not specify cross-chain message delivery, so contracts on two chains have no way to know whether the same message has already been (de)reified on the other chain. A naive bridge that reifies on chain B without dereifying on chain A is exposed to a double-spend attack. An oracle mechanism is needed to prevent reification on chain B before the token on chain A has been dereified.