ERC-4494 ERC-721 Signature-based approval (Permit) (Permit for ERC-721 NFTs)
Stagnant · NFTs & multi-token · created 2021-11-25
A standard that lets an NFT owner delegate usage rights for a given NFT to a specific address using only an off-chain signature (EIP-712), without an on-chain approve transaction.
Why it is needed
In existing ERC-721, letting another address (a marketplace, a lending platform, etc.) move your NFT on your behalf requires two transactions: first sending an approve transaction, then having the counterparty call transferFrom. This is a cumbersome flow in which the user has to pay gas twice and a time gap opens up between approval and actual use. ERC-20 had a way to solve this problem with ERC-2612 permit, but ERC-721 could not simply adopt it because its structure differs: it deals with individual tokenIds rather than quantities, and each token's owner can change. Without this standard, NFT owners must bear the gas cost and wait time of an on-chain approve transaction every time, and wallets or platforms have no way to offer a gasless approval flow for NFTs.
What to implement
function permit(address spender, uint256 tokenId, uint256 deadline, bytes memory sig) external;: Verifies the owner's signature and sets the spender as approved for the tokenId.function nonces(uint256 tokenId) external view returns(uint256);: Returns the current nonce value for a given tokenId. Needed when creating a permit signature.function DOMAIN_SEPARATOR() external view returns(bytes32);: Returns the domain separator used for the EIP-712 signature defined by this standard.
In depth
Conditions under which the permit function sets the approval
For a permit(spender, tokenId, deadline, sig) call to set spender as approved for tokenId and emit an Approval event, all of the following must hold: the current block timestamp must be at or before deadline, the owner of tokenId must not be the zero address, nonces[tokenId] must equal the nonce used in the signature, and sig must be a valid secp256k1 or EIP-2098 signature from the owner. This condition is valid only while the owner still holds that tokenId.
Nonce and replay protection
nonces[tokenId] must increment every time that tokenId is transferred (that is, whenever the owner changes). This differs from ERC-2612, where the nonce increments when a permit is created: once the tokenId passes to a new owner, a signature made by the previous owner can no longer be replayed.
DOMAIN_SEPARATOR and the EIP-712 message structure
The message that gets signed takes the form keccak256(0x1901 || DOMAIN_SEPARATOR || structHash), where structHash is the hash of a struct typed as Permit(address spender,uint256 tokenId,uint256 nonce,uint256 deadline). DOMAIN_SEPARATOR is defined per EIP-712 and typically includes the name, version, chainId, and contract address, preventing replay attacks against other contracts or chains.
Signature format: why bytes
ERC-2612 takes signatures split into v, r, and s, but this standard takes a single variable-length bytes value. This choice makes it easy to support not only traditional 65-byte signatures but also 64-byte EIP-2098 compact signatures, since EIP-2098 signatures cannot be cleanly split into and reconstructed from r, s, v.
EIP-165 interface registration
The interface ID for this standard is 0x5604e225, and implementing contracts must return true from a call to supportsInterface(0x5604e225). Since ERC-721 already requires EIP-165, registering this ID lets other contracts or services easily check whether a given NFT contract supports this permit standard.
Differences from existing implementations (Uniswap v3)
Some ERC-721 contracts, such as Uniswap v3, already use permit-like structures, but they differ from this standard. In existing implementations, the permit structure is keyed on owner, the nonce increments at the time the permit is created, the permit function must be called by the NFT owner (the address set as owner), and the signature is split into r, s, v. This standard is deliberately designed to differ on all four of these points.
Proposal status: Stagnant
This proposal is in Stagnant status, meaning discussion has stalled and is no longer progressing. Its content may change or it may never become a final standard.
Things to watch out for
- Caution when combining permit with transfer: When permit and a transfer function are used together in a single function, implementations must be carefully designed so that an invalid permit cannot be exploited in any way. In particular, a sloppy implementation in an automated NFT platform could lead to the theft of assets belonging to many users.
- Possibility of Front-Running: Even if the signer of a permit intends for a specific party to submit it, someone else could call and submit the permit first. From the signer's perspective, however, the final outcome (approval granted) is the same either way.
- Risk of ecrecover returning the zero address: ecrecover fails silently on an invalid signature and can return the zero address as the signer. Implementations must therefore check that ownerOf(tokenId) is not the zero address, to prevent a permit from incorrectly granting approval for an unapproved tokenId.
- Censorability of permit: Because a relayer holding a signature can withhold submission, permit is censorable. This can be mitigated by limiting validity with a deadline, or by having the owner submit directly to invalidate a previously signed permit.
- Replay risk on chain splits: If DOMAIN_SEPARATOR embeds chainId fixed at deployment time and is not recomputed per signature, a later chain split creates a risk that the same signature could be replayed on a different chain.