EIPs Explained

ERC-7272 · Draft · ERC · 2023-07-03

ERC-7272: Ethereum Access Token

Defines an EIP-712 signed, short-lived 'access token' that an off-chain service issues so a specific account can call a specific contract function with specific arguments, verified on-chain.

What problem does it solve?

Some on-chain actions should only be allowed after an off-chain check: KYC or compliance status, holding a verifiable credential, passing an eligibility test. The usual on-chain options are awkward. Role lists and soulbound tokens must be kept up to date by whoever runs the registry, and storing the underlying data on-chain can leak personal information.

An Ethereum Access Token (EAT) works like a JSON Web Token for smart contracts. The user asks an off-chain service for permission, the service runs whatever checks it wants, and if the user passes it signs a narrowly scoped, expiring authorization. The user then sends that signature along with the transaction, and the contract verifies it with ecrecover. No personal data goes on-chain, and the issuer can change its criteria without redeploying anything.

How it works

The issuer signs an EIP-712 typed-data payload:

AccessToken  { uint256 expiry; FunctionCall functionCall; }
FunctionCall { bytes4 functionSignature; address target; address caller; bytes parameters; }

What the token is bound to:

  • functionSignature: must match msg.sig, so it cannot be used on another function.
  • target: the contract being called.
  • caller: must match msg.sender, so nobody else can use it.
  • parameters: the rest of the calldata (everything after the EAT fields), so the arguments cannot be changed.
  • expiry: a Unix timestamp after which the token is no longer valid.

The gated function takes the signature (v, r, s) and expiry as its first arguments. The reference design splits the work in two: an AccessTokenVerifier rebuilds the EIP-712 digest, checks expiry, recovers the signer and checks it against the trusted issuers; an AccessTokenConsumer base contract provides a modifier that calls the verifier and, in the reference implementation, marks the token as used so it cannot be replayed.

Sample code

Issuing an EAT off-chain with ethers v6 (domain values are placeholders for your verifier's):

import { Wallet, AbiCoder } from "ethers";

const issuer = new Wallet(process.env.ISSUER_KEY!);

const domain = { name: "Ethereum Access Token", version: "1", chainId: 1, verifyingContract: verifierAddress };
const types = {
  AccessToken: [
    { name: "expiry", type: "uint256" },
    { name: "functionCall", type: "FunctionCall" },
  ],
  FunctionCall: [
    { name: "functionSignature", type: "bytes4" },
    { name: "target", type: "address" },
    { name: "caller", type: "address" },
    { name: "parameters", type: "bytes" },
  ],
};

const expiry = Math.floor(Date.now() / 1000) + 300; // valid for 5 minutes
const parameters = AbiCoder.defaultAbiCoder().encode(["address", "uint256"], [user, 1n]);

const sig = await issuer.signTypedData(domain, types, {
  expiry,
  functionCall: { functionSignature: mintSelector, target: gatedContract, caller: user, parameters },
});
// The user then calls gated.mint(v, r, s, expiry, user, 1)

Things to know

  • Status is Draft.
  • Security rests entirely on the off-chain issuer. If its signing key or checks are compromised, attackers can mint valid tokens.
  • Replay protection is optional in the spec (the reference implementation consumes tokens on use). Pick expiry windows carefully: too long increases misuse risk, too short hurts usability.
  • Any function can be gated except receive and fallback.
  • The spec text describes expiry as "expected to be before block.timestamp"; the intended meaning, and what the reference verifier checks, is that the token has not yet expired.
  • For signing in to off-chain apps (the reverse direction), see ERC-4361 Sign-In with Ethereum.

#access-control #signatures #eip-712 #authorization

Details

Authors
Chris Chung (@0xpApaSmURf), Raphael Roullet (@ra-phael)
Status
Draft
Type
Standards Track / ERC
Created
2023-07-03
Requires

Machine-readable: Markdown · JSON