ERC-7597 Permit signature extension for contract wallets (Signature Validation Extension for Permit)

Draft · Signatures & auth · created 2024-01-15

Extends ERC-2612 Permit, which handles token approval with a single signature, so that smart contract wallets can also use gasless approval signatures.

Why it is needed

On Ethereum, letting another app move your tokens on your behalf requires first sending an approve transaction, which costs gas. ERC-2612 Permit reduced this burden by handling approval with just a signature instead of a transaction, but because it receives the signature as three values, V, R, and S, only externally owned accounts (EOAs) signing with a private key could use it. However, as smart contract wallets, where the wallet itself is a contract, have become more common, and ERC-1271, a standard letting contracts determine signature validity themselves, has seen growing adoption, the fixed V, R, S format created a problem where such wallets could not use Permit. This standard changes the signature to be received as unformatted bytes, allowing various signature schemes and verification logic suited to each wallet type.

What to implement

In depth

A permit interface that receives the signature as bytes

Compliant contracts must implement permit(address owner, address spender, uint value, uint deadline, bytes memory signature). The core change is the signature parameter. The existing ERC-2612, which received the signature as three parameters, uint8 v, bytes32 r, and bytes32 s, is changed to a single unformatted bytes parameter. Alongside this, the two interfaces required by ERC-2612, nonces(address owner) and DOMAIN_SEPARATOR(), must still be implemented as is.

Conditions for permit to succeed

A call to permit(owner, spender, value, deadline, signature) only sets allowance[owner][spender] to value, increments nonces[owner] by 1, and emits an Approval event when all of the following conditions are met: the current block time must be no later than deadline, owner must not be the zero address, nonces[owner] before the state update must match the nonce in the signature, and the signature verification must pass. If even one condition fails, the call must revert.

Signature verification split between EOAs and contracts

Signature verification differs depending on the type of owner. If owner is an EOA, signature must be a valid secp256k1 signature in the form abi.encodePacked(r, s, v). If owner is a contract, verification is done by calling the owner contract's isValidSignature(). This lets developers verify signatures from both EOAs and smart contract wallets through a single unified interface, while allowing signature schemes and algorithms suited to each wallet type.

Compatibility with the existing V, R, S approach

This proposal is fully backward compatible with the existing ERC-2612. Existing contracts that rely on V, R, S verification continue to work unchanged. If both approaches need to be supported together, duplicate implementation can be reduced by having the permit that takes V, R, S pack them into abi.encodePacked(r, s, v) and call an internal _permit(owner, spender, value, deadline, signature).

Reference implementation

The original text presents a permit example using OpenZeppelin's SignatureChecker. After checking that the deadline has not expired and that owner and spender are not the zero address, it builds a digest from hex"1901", DOMAIN_SEPARATOR, and the Permit type hash (Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)), then checks both ECDSA signatures and ERC-1271 signatures at once using SignatureChecker.isValidSignatureNow. If it passes, allowed[owner][spender] is updated and Approval is emitted.

A proposal still in Draft stage

This ERC is in Draft status, created on January 15, 2024. Since it is at a stage where content may still change, it is advisable to check the latest original text before implementation.

Things to watch out for

Original ERC · ← ERCs