ERC-7604 ERC-1155 Permit Approval (ERC-1155 Permit Approvals)

Draft · NFTs & multi-token · created 2024-01-27

Lets an owner create an approval for a specific ID and amount of an ERC-1155 token using a single signature instead of a transaction. This standard extends ERC-20's permit approach to ERC-1155.

Why it is needed

To let another address or contract move ERC-1155 tokens on an owner's behalf, the owner must first send an approval transaction. Approval and actual use are split into two transactions, and the owner also needs ETH to pay gas. ERC-20 has a permit scheme in ERC-2612, and ERC-721 has one in ERC-4494, letting approvals be created with a single signature, but each applies only to its own token standard. ERC-1155 handles multiple token IDs and balances within a single contract, so existing permit schemes cannot be applied directly. Moreover, ERC-1155 originally has no per-amount approval, so granting approval means granting authority over the account's entire balance of that token ID. This standard closes that gap by combining ERC-5216, which defines per-amount approval, with EIP-712 signatures.

What to implement

In depth

Three Required Functions

This standard adds three functions, permit, nonces, and DOMAIN_SEPARATOR, on top of ERC-1155 and ERC-5216. permit is the entry point for signature-based approval. nonces looks up the nonce for a given owner and tokenId combination, and DOMAIN_SEPARATOR returns the EIP-712 domain separator. Unlike ERC-2612 (which handles only value) or ERC-4494 (which handles only tokenId), the key difference here is that both tokenId and value are included in the signature.

Conditions Under Which a Permit Is Valid

A call to permit(owner, spender, tokenId, value, deadline, sig) must set allowance(owner, spender, tokenId) to value, increment nonces(owner, tokenId) by 1, and emit the Approval event defined by ERC-5216, only when all of the following conditions hold. There are four conditions. The current block time must be at or before deadline, and owner must not be the zero address. The nonces[owner][tokenId] value before the state update must equal the nonce included in the signature, and sig must be a valid secp256k1, ERC-2098, or ERC-1271 signature from owner. If any condition fails, it must revert. It must also be verified that the signer is not the zero address.

The EIP-712 Signature Structure

The message to be signed is the keccak256 hash of hex"1901" and DOMAIN_SEPARATOR prepended to the abi.encode of the type hash Permit(address owner,address spender,uint256 tokenId,uint256 value,uint256 nonce,uint256 deadline) and each corresponding value. DOMAIN_SEPARATOR should be defined per EIP-712, and must be unique per contract and chain to prevent replay attacks across different domains. A common choice is the EIP712Domain hash containing name, version, chainId, and verifyingContract.

A Design With No Caller Restriction

Since msg.sender is not referenced anywhere in the spec, permit can be called by any address. A common use case is a relayer submitting the permit on the owner's behalf. In this case, the relayer effectively gets a free option to choose whether to submit the permit or withhold it, so if this is a concern, the owner can set the deadline to the near future to limit the validity period. Conversely, setting deadline to uint(-1) creates a permit that effectively never expires, and setting value to uint(-1) creates an effectively unlimited approval.

Why ERC-5216 Is Required

ERC-1155 does not natively support per-amount approval. Building a permit on top of it as is would result in an approval over the account's entire balance of that token ID. For this reason, this standard requires ERC-5216, which defines per-amount approval, allowance, and the Approval event. This makes it possible for a single permit to approve only a specific amount of a specific token ID.

Why the Signature Is Received as Bytes

ERC-2612 receives the signature split into three components, v, r, and s, but this standard receives it as a single variable-length bytes array. This is to also support formats, such as ERC-2098 signatures, that are not easily split into or reconstructed from r, s, v components (65 bytes). ERC-1271 also makes it possible to verify signatures from contract accounts. In addition, this format avoids calls into unknown code.

Registering the ERC-165 Interface

The ERC-165 interface ID for this standard is 0x7409106d. Implementing contracts must return true when supportsInterface(0x7409106d) is called. ERC-165 is already required by ERC-1155, but it is required again here so that other parties can easily check whether a contract implements this standard and interact with it accordingly.

A proposal still in Draft stage

This document is a proposal in Draft status created on January 27, 2024. The interface or detailed rules may change before final confirmation, so the latest original text should be checked when implementing or integrating.

Things to watch out for

Original ERC · ← ERCs