EIPs Explained

ERC-7598 · Draft · ERC · 2024-01-15

ERC-7598: Use contract signature for signed transfer

Extends ERC-3009 signed transfers to accept a single bytes signature, so smart contract wallets (via ERC-1271) can authorize gasless token transfers just like EOAs.

What problem does it solve?

ERC-3009 "Transfer With Authorization" lets a token holder sign a transfer off-chain and have anyone submit it, so the holder never needs ETH for gas. But its functions take an ECDSA signature split into v, r, s. Only an externally owned account (EOA) can produce that. Smart contract wallets, such as multisigs and account-abstraction wallets, cannot use it at all.

ERC-7598 adds overloads that take an opaque bytes signature. The token checks it with ECDSA if from is an EOA, or by calling isValidSignature on the wallet (ERC-1271) if from is a contract.

How it works

A compliant token keeps everything from ERC-3009: the AuthorizationUsed event, the TRANSFER_WITH_AUTHORIZATION_TYPEHASH and RECEIVE_WITH_AUTHORIZATION_TYPEHASH constants, and authorizationState(authorizer, nonce). It adds:

function transferWithAuthorization(
    address from, address to, uint256 value,
    uint256 validAfter, uint256 validBefore, bytes32 nonce,
    bytes memory signature
) external;

function receiveWithAuthorization(
    address from, address to, uint256 value,
    uint256 validAfter, uint256 validBefore, bytes32 nonce,
    bytes memory signature
) external;   // also requires msg.sender == to, to stop front-running

Optionally, cancelAuthorization(authorizer, nonce, bytes signature) is added as well.

The signed payload is still the EIP-712 typed data from ERC-3009: from, to, value, validAfter, validBefore, nonce under the token's domain. Each authorization uses a random 32-byte nonce, and the token marks it used so it can only run once. For EOAs, the bytes are r ‖ s ‖ v (65 bytes), so the old v, r, s functions can simply forward to the new ones.

Sample code

Verification inside the token, using OpenZeppelin's SignatureChecker, which handles both EOAs and ERC-1271 wallets:

import {SignatureChecker} from "@openzeppelin/contracts/utils/cryptography/SignatureChecker.sol";

function transferWithAuthorization(
    address from, address to, uint256 value,
    uint256 validAfter, uint256 validBefore, bytes32 nonce,
    bytes memory signature
) external {
    require(block.timestamp > validAfter, "not yet valid");
    require(block.timestamp < validBefore, "expired");
    require(!_authorizationStates[from][nonce], "used or canceled");

    bytes32 digest = _hashTypedDataV4(keccak256(abi.encode(
        TRANSFER_WITH_AUTHORIZATION_TYPEHASH, from, to, value, validAfter, validBefore, nonce
    )));
    require(SignatureChecker.isValidSignatureNow(from, digest, signature), "invalid signature");

    _authorizationStates[from][nonce] = true;
    emit AuthorizationUsed(from, nonce);
    _transfer(from, to, value);
}

Things to know

  • Status: Draft. ERC-3009 itself is also still Draft.
  • The reference code in the spec has inconsistent variable names (owner, authorizer, typedDataHash); treat it as illustrative and use a clean implementation like the one above.
  • For contract wallets, security depends entirely on the wallet's isValidSignature. A sloppy implementation can approve transfers its owners never intended.
  • ERC-7597 applies the same idea to ERC-2612 permit.

#token #signatures #smart-wallet #gasless #erc3009

Details

Authors
Yvonne Zhang (@yvonnezhangc), Aloysius Chan (@circle-aloychan)
Status
Draft
Type
Standards Track / ERC
Created
2024-01-15
Requires

Machine-readable: Markdown · JSON