EIPs Explained

ERC-5453 · Last Call · ERC · 2022-08-12

ERC-5453: Endorsement - Permit for Any Functions

A generic "permit for any function": callers attach one or more EIP-712 signed endorsements in a trailing `extraData` argument, enabling gasless approvals, sponsored calls and multi-sig thresholds in a single transaction.

What problem does it solve?

ERC-2612 lets an ERC-20 holder approve spending with an off-chain signature, and ERC-4494 does the same for ERC-721. But each covers only one action (approval for transfer) and one signer, and the usual flow still needs a permit call followed by the real call.

Many situations need more: a second party's approval, someone else paying the gas, an M-of-N multisig, or a vote gathered from several signers. ERC-5453 defines one way to attach signed approvals to any function and check them in the same transaction.

How it works

It builds on ERC-5750, which reserves a final bytes extraData parameter on a method for extensions. To be endorsable, a method's extraData decodes to:

struct GeneralExtensionDataStruct {
    bytes32 erc5453MagicWord;   // keccak256("ERC5453-ENDORSEMENT")
    uint256 erc5453Type;        // 1 = single endorser, 2 = multiple endorsers
    uint256 nonce;
    uint256 validSince;         // inclusive
    uint256 validBy;            // inclusive
    bytes   endorsementPayload; // abi.encode(SingleEndorsementData) or (SingleEndorsementData[])
}

struct SingleEndorsementData {
    address endorserAddress;
    bytes   sig;                // 65-byte signature
}

What each endorser signs:

  1. Function hash: keccak256(abi.encodePacked(keccak256(bytes("function name(type1 p1,...)")), packedParams)), which binds the signature to a specific function and arguments.
  2. Validity digest: an EIP-712 typed hash of ValidityBound(bytes32 functionParamStructHash,uint256 validSince,uint256 validBy,uint256 nonce).

The contract recomputes the digest and accepts an endorsement if ecrecover returns endorserAddress, or if endorserAddress is a contract and its ERC-1271 isValidSignature returns the magic value. With type 2, the method may require a threshold number of valid endorsements.

validSince/validBy can be block numbers or timestamps; the implementer should document which.

Sample code

An endorsable mint, following the spec's reference EndorsableERC721 (the onlyEndorsed modifier and _computeFunctionParamHash come from the reference abstract contract AERC5453Endorsible):

pragma solidity ^0.8.9;

contract EndorsableERC721 is ERC721, AERC5453Endorsible {
    function mint(address _to, uint256 _tokenId, bytes calldata _extraData)
        external
        onlyEndorsed(
            _computeFunctionParamHash(
                "function mint(address _to,uint256 _tokenId)",
                abi.encode(_to, _tokenId)
            ),
            _extraData
        )
    {
        _mint(_to, _tokenId);
    }
}

Building extraData for a single endorser off-chain (ethers v6):

import { AbiCoder, keccak256, toUtf8Bytes } from "ethers";

const coder = AbiCoder.defaultAbiCoder();
const MAGIC = keccak256(toUtf8Bytes("ERC5453-ENDORSEMENT"));

const payload = coder.encode(["tuple(address,bytes)"], [[endorser, signature]]);
const extraData = coder.encode(
  ["tuple(bytes32,uint256,uint256,uint256,uint256,bytes)"],
  [[MAGIC, 1n, nonce, validSince, validBy, payload]],
);
await nft.mint(to, tokenId, extraData);

Things to know

  • Status: Last Call. The deadline in the spec has passed, but it had not been moved to Final.
  • Endorsements are public once broadcast. Nonces and validity windows narrow replay risk but the spec warns they do not remove it, for example across chains or similar contracts. Include the chain and contract in your EIP-712 domain.
  • The spec highlights phishing: a user can be tricked into signing an endorsement whose data happens to match a different target application.
  • Functions such as ERC-20's transfer have no extraData slot; using this standard with them requires a wrapper or upgrade.

#signature #permit #eip712 #multisig #meta-transactions

Details

Authors
Zainan Victor Zhou (@xinbenlv)
Status
Last Call
Type
Standards Track / ERC
Created
2022-08-12
Requires

Machine-readable: Markdown · JSON