EIPs Explained

ERC-7758 · Review · ERC · 2020-09-28

ERC-7758: Transfer With Authorization

Move ERC-20 tokens with an off-chain signature instead of a transaction - anyone can submit it, gas can be paid by a relayer or in the token itself, and random nonces let many authorizations run in parallel. Successor of ERC-3009; implemented by USDC.

What problem does it solve?

To send an ERC-20 token you normally need ETH in the same account to pay gas. A user who was just sent 50 USDC and nothing else is stuck. Protocols also have to make users run two transactions (approve, then transferFrom) before they can take payment, and the allowance pattern invites "infinite approval" habits and multiple-withdrawal attacks.

ERC-7758 lets a token holder sign a transfer authorization off-chain. Anyone (a relayer, the recipient, a paymaster) can submit that signature to the token contract, which performs the transfer. The holder never needs ETH and never grants an allowance.

ERC-2612 permit solves part of this but keeps the allowance model and uses sequential nonces, so a user cannot have several authorizations in flight. ERC-7758 uses random 32-byte nonces, so authorizations are independent and can be created in any quantity and order.

ERC-7758 is the re-submission of ERC-3009 with the same specification, moved into the current review process. USDC has implemented it since 2020, so a very large share of stablecoin "gasless" flows already run on this interface.

How it works

The token exposes three signature-driven functions. All messages are EIP-712 typed data over the token's domain (name, version, chainId, verifyingContract).

Function Who calls it Purpose
transferWithAuthorization(from, to, value, validAfter, validBefore, nonce, v, r, s) anyone Execute a transfer signed by from
receiveWithAuthorization(...) only to Same, but the payee must be the caller, so a watcher cannot front-run and steal a deposit flow
cancelAuthorization(authorizer, nonce, v, r, s) anyone Invalidate an unused nonce (optional)
authorizationState(authorizer, nonce) view true once a nonce has been used or cancelled

Each authorization has a validity window (validAfter / validBefore, unix time) and a unique nonce. Once consumed, the contract emits AuthorizationUsed(authorizer, nonce) and refuses the same nonce again.

Sample code

Signing an authorization in the browser or backend (ethers v6):

import { Wallet, randomBytes, hexlify, Signature, parseUnits } from "ethers";

const holder = new Wallet(HOLDER_KEY);          // owns the tokens, has no ETH
const now = Math.floor(Date.now() / 1000);

const domain = {
  name: "USD Coin",
  version: "2",
  chainId: 1,
  verifyingContract: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
};
const types = {
  TransferWithAuthorization: [
    { name: "from", type: "address" },
    { name: "to", type: "address" },
    { name: "value", type: "uint256" },
    { name: "validAfter", type: "uint256" },
    { name: "validBefore", type: "uint256" },
    { name: "nonce", type: "bytes32" },
  ],
};
const message = {
  from: holder.address,
  to: MERCHANT,
  value: parseUnits("50", 6),
  validAfter: 0,
  validBefore: now + 3600,            // valid for one hour
  nonce: hexlify(randomBytes(32)),    // random, not sequential
};

const sig = Signature.from(await holder.signTypedData(domain, types, message));
// hand { message, v: sig.v, r: sig.r, s: sig.s } to the relayer

The relayer (any account with ETH) submits it:

const usdc = new Contract(domain.verifyingContract, [
  "function transferWithAuthorization(address from,address to,uint256 value,uint256 validAfter,uint256 validBefore,bytes32 nonce,uint8 v,bytes32 r,bytes32 s)",
], relayerWallet);

await usdc.transferWithAuthorization(
  message.from, message.to, message.value,
  message.validAfter, message.validBefore, message.nonce,
  sig.v, sig.r, sig.s,
);

A contract that accepts token deposits atomically, using receiveWithAuthorization so the signature can only be used by this contract:

interface IERC7758 {
    function receiveWithAuthorization(
        address from, address to, uint256 value,
        uint256 validAfter, uint256 validBefore, bytes32 nonce,
        uint8 v, bytes32 r, bytes32 s
    ) external;
}

contract Vault {
    IERC7758 public immutable token;
    mapping(address => uint256) public deposits;

    constructor(IERC7758 _token) { token = _token; }

    function deposit(
        address from, uint256 value, uint256 validAfter, uint256 validBefore,
        bytes32 nonce, uint8 v, bytes32 r, bytes32 s
    ) external {
        // `to` must be this contract; the token enforces msg.sender == to.
        token.receiveWithAuthorization(from, address(this), value, validAfter, validBefore, nonce, v, r, s);
        deposits[from] += value;
    }
}

Things to know

  • Use receiveWithAuthorization whenever a contract is the payee. With transferWithAuthorization a bot could submit the signature first; the tokens would still arrive, but the contract's own bookkeeping call would never run.
  • Nonces are random bytes32, so generate them with a CSPRNG and check authorizationState before reuse. The same nonce can be used once per authorizer.
  • Signatures are chain- and contract-specific thanks to the EIP-712 domain; check the token's name and version (USDC uses version "2").
  • Because the signer never pays gas, this pairs naturally with ERC-4337 paymasters and with EIP-7702 sponsored transactions.

#token #meta-transaction #gasless #eip-712 #usdc #erc-20

Details

Authors
Peter Jihoon Kim (@petejkim), Kevin Britz (@kbrizzle), David Knott (@DavidLKnott), Dongri Jin (@dongri)
Status
Review
Type
Standards Track / ERC
Created
2020-09-28
Requires

Machine-readable: Markdown · JSON