Introduction

Hi, I'm cardene, a software engineer and technical writer focused on blockchain and AI.

I've also authored Japanese technical books on specification-driven development with LLMs and decentralized application (DApp) development.

I also build and publish a variety of tools, libraries, and open-source projects.

This article examines ERC3009, a proposal for executing the approve + transferFrom meta-transactions introduced by ERC2612 more safely.

The following material is translated, summarized, and supplemented with explanations.

I have also covered a range of other EIPs.

At the time of writing, this standard had Stagnant status (no updates for at least six months), so some details may differ between the original proposal and current practice. For an explanation of EIP statuses, see the following article.

[EIP1] The Purpose and Guidelines of EIPs

Overview

This standard proposes an interface for transferring tokens using a signed approve authorization.

Using EIP712, which enables atomic meta-transactions through signatures for ERC20 tokens, supports the following capabilities.

Executing transactions on Ethereum requires paying gas fees in ETH. With meta-transactions, users do not have to pay gas fees directly; another address can pay them instead.

  • Gas fee delegation
    • Delegate payment of gas fees to another address.
  • Gas fee payment in tokens
    • Pay for gas in an arbitrary token instead of the native token, ETH.
  • Atomic transactions
    • Transfer multiple tokens or perform other operations together in a single transaction.
    • Atomicity means that if any operation fails, all operations in that transaction fail.
  • Transaction submission delegation
    • As with delegating gas payments, users can have another address submit the transaction.
  • Batch transactions
    • Process multiple transactions together.
  • Preventing nonce reuse
    • A nonce is the number of transactions a particular address has sent.
    • When a transaction is processed successfully or unsuccessfully, the nonce increases by 1; without that increment, the same transaction could be submitted twice.
    • Multiple transactions can be executed while implementing a mechanism to prevent reuse.

For more on ERC20, see the following article.

https://chaldene.net/erc20

Motivation

The existing EIP2612 standard already enables meta-transactions. The differences between this proposal and EIP2612 are as follows.

  • EIP2612 uses sequential nonce values (unique transaction identifiers), whereas this standard uses random 32-byte nonce values.
  • EIP2612 relies on the ERC20 approve + transferFrom pattern.

For more on EIP2612, see the following article.

[ERC2612] Executing ERC20 approve and transferFrom in One Transaction

Sequential nonce values prevent concurrent execution of multiple transactions for the following reason.

  • DApps may reuse a nonce that has not yet been processed on-chain.
    • This can happen when a sudden increase in gas prices leaves transactions pending in the mempool (where transactions awaiting execution accumulate) for an extended period.

By contrast, non-sequential nonce values, as proposed by this standard, allow users to submit as many transactions as they want.

Currently, nonce values are managed per address, so account-level nonce management still matters even if the contract maintains its own nonce values. The proposal allows transactions to execute in any order because the contract-managed nonce values are not sequential.

The introduction of EIP1559 also provided a mechanism intended to mitigate sudden increases in gas prices. For more on EIP1559, see the following article.

[EIP1559] Ethereum's Gas Pricing Mechanism

The ERC20 allowance mechanism has the following problems.

  • Vulnerability to multiple withdrawal attacks

This refers to reentrancy attacks. Such a vulnerability allows the same function to be invoked repeatedly.

For more details, see the following article.

https://chaldene.net/solidity-reentrancy-attack

  • Transaction reordering

Transactions are not necessarily executed in the order in which they were created. For example, a transaction can be processed first by paying a higher gas fee. This allows others to observe transactions and act on them.

For more details, see the following article.

  • Unlimited allowance
    • Setting an extremely large value when calling ERC20 approve grants the specified address virtually unlimited permission to operate on the tokens.

The growing use of upgradeable contracts has made the above attacks more likely.

I am not sure why they have become more likely, but one possibility is that upgradeability has reduced vigilance.

Alternative token standards such as ERC777 and ERC677 were proposed to address the problems with ERC20 allowance. However, compatibility and security issues have limited adoption of these standards.

For more on ERC677, see the following article.

[ERC677] The ERC223-Based Token Receipt Notification Standard

For more on ERC777, see the following article.

[ERC777] The Standard Token Contract Interface

Specification

Events

js
event AuthorizationUsed(
    address indexed authorizer,
    bytes32 indexed nonce
);

// keccak256("TransferWithAuthorization(address from,address to,uint256 value,uint256 validAfter,uint256 validBefore,bytes32 nonce)")
bytes32 public constant TRANSFER_WITH_AUTHORIZATION_TYPEHASH = 0x7c7c6cdb67a18743f49ec6fa9b35f50d52ed05cbed4cc592e13b44501c1a2267;

// keccak256("ReceiveWithAuthorization(address from,address to,uint256 value,uint256 validAfter,uint256 validBefore,bytes32 nonce)")
bytes32 public constant RECEIVE_WITH_AUTHORIZATION_TYPEHASH = 0xd099cc98ef71107a616c4f0f941f04c322d8e254fe26b3c6668db87aae413de8;

/**
 * @notice Returns the state of an authorization
 * @dev Nonces are randomly generated 32-byte data unique to the authorizer's
 * address
 * @param authorizer    Authorizer's address
 * @param nonce         Nonce of the authorization
 * @return True if the nonce is used
 */
function authorizationState(
    address authorizer,
    bytes32 nonce
) external view returns (bool);

/**
 * @notice Execute a transfer with a signed authorization
 * @param from          Payer's address (Authorizer)
 * @param to            Payee's address
 * @param value         Amount to be transferred
 * @param validAfter    The time after which this is valid (unix time)
 * @param validBefore   The time before which this is valid (unix time)
 * @param nonce         Unique nonce
 * @param v             v of the signature
 * @param r             r of the signature
 * @param s             s of the signature
 */
function transferWithAuthorization(
    address from,
    address to,
    uint256 value,
    uint256 validAfter,
    uint256 validBefore,
    bytes32 nonce,
    uint8 v,
    bytes32 r,
    bytes32 s
) external;

/**
 * @notice Receive a transfer with a signed authorization from the payer
 * @dev This has an additional check to ensure that the payee's address matches
 * the caller of this function to prevent front-running attacks. (See security
 * considerations)
 * @param from          Payer's address (Authorizer)
 * @param to            Payee's address
 * @param value         Amount to be transferred
 * @param validAfter    The time after which this is valid (unix time)
 * @param validBefore   The time before which this is valid (unix time)
 * @param nonce         Unique nonce
 * @param v             v of the signature
 * @param r             r of the signature
 * @param s             s of the signature
 */
function receiveWithAuthorization(
    address from,
    address to,
    uint256 value,
    uint256 validAfter,
    uint256 validBefore,
    bytes32 nonce,
    uint8 v,
    bytes32 r,
    bytes32 s
) external;
AuthorizationUsed
js
event AuthorizationUsed(
    address indexed authorizer,
    bytes32 indexed nonce
);

An event emitted when a particular authorization is used.

  • authorizer
    • The address of the user who granted the authorization.
  • nonce
    • A unique value associated with the authorization.
TRANSFER_WITH_AUTHORIZATION_TYPEHASH
js
bytes32 public constant TRANSFER_WITH_AUTHORIZATION_TYPEHASH = 0x7c7c6cdb67a18743f49ec6fa9b35f50d52ed05cbed4cc592e13b44501c1a2267;

The type hash for the TransferWithAuthorization function. It is used to sign structured data under the EIP712 standard.

For more on EIP712, see the following article.

[EIP712] Hashing and Signing Typed Structured Data

`RECEIVE_WITH_AUTHORIZATION_TYPEHASH
js
bytes32 public constant RECEIVE_WITH_AUTHORIZATION_TYPEHASH = 0xd099cc98ef71107a616c4f0f941f04c322d8e254fe26b3c6668db87aae413de8;

The type hash for the ReceiveWithAuthorization function. It is used to sign structured data under the EIP712 standard.

authorizationState
js
function authorizationState(
    address authorizer,
    bytes32 nonce
) external view returns (bool);

Checks whether the specified nonce has already been used.

  • Arguments:
    • authorizer
      • The address of the user granting authorization.
    • nonce
      • A unique value associated with the authorization.
  • Return value
    • true if the nonce has already been used; otherwise, false.
transferWithAuthorization
js
function transferWithAuthorization(
    address from,
    address to,
    uint256 value,
    uint256 validAfter,
    uint256 validBefore,
    bytes32 nonce,
    uint8 v,
    bytes32 r,
    bytes32 s
) external;

Transfers tokens using a signed authorization.

  • Arguments
    • from
      • The address of the user paying the tokens (the authorizer).
    • to
      • The address of the token recipient.
    • value
      • The amount of tokens to transfer.
    • validAfter
      • The authorization is valid after this UNIX timestamp.
    • validBefore
      • The authorization is valid before this UNIX timestamp.
    • nonce
      • A unique value.
    • v, r, s
      • Signature components.
receiveWithAuthorization
js
function receiveWithAuthorization(
    address from,
    address to,
    uint256 value,
    uint256 validAfter,
    uint256 validBefore,
    bytes32 nonce,
    uint8 v,
    bytes32 r,
    bytes32 s
) external;

Receives tokens using a signed authorization. For security reasons, the token recipient must call this function.

  • Arguments
    • from
      • The address of the user paying the tokens (the authorizer).
    • to
      • The address of the token recipient.
    • value
      • The amount of tokens to transfer.
    • validAfter
      • The authorization is valid after this UNIX timestamp.
    • validBefore
      • The authorization is valid before this UNIX timestamp.
    • nonce
      • A unique value.
    • v, r, s
      • Signature components.

Optional Features

js
event AuthorizationCanceled(
    address indexed authorizer,
    bytes32 indexed nonce
);

// keccak256("CancelAuthorization(address authorizer,bytes32 nonce)")
bytes32 public constant CANCEL_AUTHORIZATION_TYPEHASH = 0x158b0a9edf7a828aad02f63cd515c68ef2f50ba807396f6d12842833a1597429;

/**
 * @notice Attempt to cancel an authorization
 * @param authorizer    Authorizer's address
 * @param nonce         Nonce of the authorization
 * @param v             v of the signature
 * @param r             r of the signature
 * @param s             s of the signature
 */
function cancelAuthorization(
    address authorizer,
    bytes32 nonce,
    uint8 v,
    bytes32 r,
    bytes32 s
) external;
AuthorizationCanceled
js
event AuthorizationCanceled(
    address indexed authorizer,
    bytes32 indexed nonce
);

An event emitted when a particular authorization is canceled.

  • authorizer
    • The address of the user who granted the authorization.
  • nonce
    • A unique nonce associated with the authorization.
js
bytes32 public constant CANCEL_AUTHORIZATION_TYPEHASH = 0x158b0a9edf7a828aad02f63cd515c68ef2f50ba807396f6d12842833a1597429;

The type hash for the cancelAuthorization function. It is used to sign structured data under the EIP712 standard.

cancelAuthorization
solidity
function cancelAuthorization(
    address authorizer,
    bytes32 nonce,
    uint8 v,
    bytes32 r,
    bytes32 s
) external;

Cancels a signed authorization. This invalidates an authorization that has not yet been used.

  • Arguments:
    • authorizer
      • The address of the user granting authorization.
    • nonce
      • A unique nonce associated with the authorization.
    • v, r, s
      • Signature components.

Obtaining Signatures With EIP712

To obtain the signature components (v, r, s) according to EIP712, follow these steps.

  1. Generate the domain separator

    • The domain separator is data used to ensure signature uniqueness and is generated as follows.
    js
    bytes32 DomainSeparator = keccak256(abi.encode(
       keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"),
       keccak256("USD Coin"),       // name
       keccak256("2"),              // version
       1,                           // chainId
       0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48  // verifyingContract
    ));
  2. Generate the message hash

    • Hash the data for the authorization to be canceled.
    js
    bytes32 structHash = keccak256(abi.encode(
       CANCEL_AUTHORIZATION_TYPEHASH,
       authorizer,
       nonce
    ));
  3. Generate the EIP712 hash

    • Combine the domain separator and the message hash to generate the EIP712 hash.
    js
    bytes32 digest = keccak256(abi.encodePacked(
       "\x19\x01",
       DomainSeparator,
       structHash
    ));
  4. Obtain the signature components

    • Sign digest to obtain the signature components v, r, and s.
    • Use these components to cancel the authorization.

The following sections explain the process in more detail.

Domain Separator and TypeHash

The domain separator and TypeHash allow a hash to be generated for a specific message and signed with the user's private key.

Domain Separator

The domain separator is generated as follows.

js
bytes32 DomainSeparator = keccak256(abi.encode(
    keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"),
    keccak256("USD Coin"),       // name
    keccak256("2"),              // version
    1,                           // chainId
    0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48  // verifyingContract
));

TypeHash and Parameters for Each Message

The following are examples of the TypeHash and parameters for each message.

TransferWithAuthorization
js
bytes32 TypeHash = keccak256(
  "TransferWithAuthorization(address from,address to,uint256 value,uint256 validAfter,uint256 validBefore,bytes32 nonce)"
);
Params := { From, To, Value, ValidAfter, ValidBefore, Nonce };
ReceiveWithAuthorization
js
bytes32 TypeHash = keccak256(
  "ReceiveWithAuthorization(address from,address to,uint256 value,uint256 validAfter,uint256 validBefore,bytes32 nonce)"
);
Params := { From, To, Value, ValidAfter, ValidBefore, Nonce };
CancelAuthorization
js
bytes32 TypeHash = keccak256(
  "CancelAuthorization(address authorizer,bytes32 nonce)"
);
Params := { Authorizer, Nonce };

Generating the Digest

Generate a digest for each message.

js
bytes32 Digest = keccak256(
  abi.encodePacked(
    "\x19\x01",
    DomainSeparator,
    keccak256(abi.encode(TypeHash, Params...))
  )
);

The token holder signs this digest with their private key.

js
{ v, r, s } := Sign(Digest, PrivateKey);

Simplifying receiveWithAuthorization

A smart contract function can reduce its parameter count by accepting all the arguments to a receiveWithAuthorization call as a single bytes argument.

Example
js
bytes4 private constant _RECEIVE_WITH_AUTHORIZATION_SELECTOR = 0xef55bec6;

function deposit(address token, bytes calldata receiveAuthorization)
    external
    nonReentrant
{
    (address from, address to, uint256 amount) = abi.decode(
        receiveAuthorization[0:96],
        (address, address, uint256)
    );
    require(to == address(this), "Recipient is not this contract");

    (bool success, ) = token.call(
        abi.encodePacked(
            _RECEIVE_WITH_AUTHORIZATION_SELECTOR,
            receiveAuthorization
        )
    );
    require(success, "Failed to transfer tokens");

    // additional logic...
}
  • _RECEIVE_WITH_AUTHORIZATION_SELECTOR is the first four-byte selector of the receiveWithAuthorization function.
  • The deposit function decodes the receiveAuthorization bytes and extracts from, to, and amount.
  • token.call uses the encoded data to call receiveWithAuthorization.

Using a Web3 Provider

An approve signature can be obtained using the Web3 provider's eth_signTypedData{_v4}.

Example

js
const data = {
  types: {
    EIP712Domain: [
      { name: "name", type: "string" },
      { name: "version", type: "string" },
      { name: "chainId", type: "uint256" },
      { name: "verifyingContract", type: "address" },
    ],
    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" },
    ],
  },
  domain: {
    name: tokenName,
    version: tokenVersion,
    chainId: selectedChainId,
    verifyingContract: tokenAddress,
  },
  primaryType: "TransferWithAuthorization",
  message: {
    from: userAddress,
    to: recipientAddress,
    value: amountBN.toString(10),
    validAfter: 0,
    validBefore: Math.floor(Date.now() / 1000) + 3600, // Valid for an hour
    nonce: Web3.utils.randomHex(32),
  },
};

const signature = await ethereum.request({
  method: "eth_signTypedData_v4",
  params: [userAddress, JSON.stringify(data)],
});

const v = "0x" + signature.slice(130, 132);
const r = signature.slice(0, 66);
const s = "0x" + signature.slice(66, 130);

Additional Details

Why Unique Random nonce Values Matter

Problems With Sequential Nonces

Sequential nonce values are useful for ordering transactions, but they present the following problems in meta-transactions.

  • Nonce values that are too high

    • For native Ethereum transactions, transactions with a high nonce are held until transactions with lower unused nonces are executed.
    • In meta-transactions, however, a transaction with a nonce that is too high fails immediately, wasting gas.
  • Transaction reordering by miners

    • Miners can include transactions in a block in any order, so meta-transactions may fail even when they use the correct nonce.
    • For example, if a user submits transactions with nonce values 3, 4, and 5, but the miner includes them in the order 4, 5, 3, only the transaction with nonce 3 succeeds.
  • Managing nonce values across applications

    • When using different applications concurrently, determining the next nonce correctly is difficult without an off-chain tracker.
    • High gas prices can leave transactions pending in the pool for extended periods, during which the same nonce may be unintentionally reused.

For these reasons, the only way to guarantee transaction ordering is for the relayer to wait for confirmation of each transaction before submitting the next, diminishing the benefits of sequential nonce values.

Validity Period (Valid After and Valid Before)

When asking a relayer to submit a transaction, it is difficult to control exactly when it will be submitted. The validAfter and validBefore parameters allow transactions to be scheduled so that they are valid only after a specified future time or before a specified deadline. This gives users control over transaction execution timing.

Why EIP712 Matters

EIP712 makes signatures valid only for a particular token contract instance and prevents reuse across networks with different chain IDs. It achieves this by generating a Keccak-256 hash digest (the domain separator) that includes the contract address and chain ID. Include the verifyingContract and chainId fields when generating the domain separator.

Compatibility

New contracts can use EIP3009 directly to create atomic transactions, while existing contracts can continue using the conventional approve + transferFrom pattern.

Adding EIP3009 to an existing ERC20 integration requires building a forwarder contract.

  1. Extract the user and deposit amount from the approve authorization.
  2. Call receiveWithAuthorization to transfer the specified funds from the user to the forwarder contract.
  3. Set an allowance so that the parent contract can spend tokens from the forwarder.
  4. Call the parent contract's method to spend the tokens covered by the forwarder's allowance.
  5. Return ownership of the resulting tokens to the user.

Example Contracts

IDeFiToken Interface
js
interface IDeFiToken {
    function deposit(uint256 amount) external returns (uint256);
    function transfer(address account, uint256 amount) external returns (bool);
}
  • deposit
    • Deposits a specified amount of tokens and returns the number of newly issued tokens.
  • transfer
    • Transfers tokens to the specified account.
DepositForwarder Contract
js
contract DepositForwarder {
    bytes4 private constant _RECEIVE_WITH_AUTHORIZATION_SELECTOR = 0xef55bec6;

    IDeFiToken private _parent;
    IERC20 private _token;

    constructor(IDeFiToken parent, IERC20 token) public {
        _parent = parent;
        _token = token;
    }

    function deposit(bytes calldata receiveAuthorization)
        external
        nonReentrant
        returns (uint256)
    {
        (address from, address to, uint256 amount) = abi.decode(
            receiveAuthorization[0:96],
            (address, address, uint256)
        );
        require(to == address(this), "Recipient is not this contract");

        (bool success, ) = address(_token).call(
            abi.encodePacked(
                _RECEIVE_WITH_AUTHORIZATION_SELECTOR,
                receiveAuthorization
            )
        );
        require(success, "Failed to transfer to the forwarder");

        require(
            _token.approve(address(_parent), amount),
            "Failed to set the allowance"
        );

        uint256 tokensMinted = _parent.deposit(amount);
        require(
            _parent.transfer(from, tokensMinted),
            "Failed to transfer the minted tokens"
        );

        uint256 remainder = _token.balanceOf(address(this));
        if (remainder > 0) {
            require(
                _token.transfer(from, remainder),
                "Failed to refund the remainder"
            );
        }

        return tokensMinted;
    }
}
  • Constructor

    • The DepositForwarder contract receives the addresses of IDeFiToken (the parent contract) and IERC20 (the token contract).
    • This allows the forwarder to call the parent contract's methods and manage token transfers.
  • deposit function

    • Decoding authorization data
      • Decode from (sender), to (recipient), and amount from receiveAuthorization.
    • Token transfer
      • Call receiveWithAuthorization to transfer the specified tokens from the user to the forwarder contract.
    • Setting the allowance
      • Set the allowance so the parent contract can spend the forwarder contract's tokens.
    • Depositing into the parent contract
      • Call the parent contract's deposit function to deposit tokens and receive newly issued tokens.
    • Transferring issued tokens
      • Transfer the newly issued tokens to the sender.
    • Refunding the remaining balance
      • Send any remaining tokens in the forwarder to the sender.

This approach adds EIP3009 functionality to contracts that use the existing ERC20 allowance pattern.

Tests

The test code is available at the following link.

Implementation

EIP3009.sol

js
abstract contract EIP3009 is IERC20Transfer, EIP712Domain {
    // keccak256("TransferWithAuthorization(address from,address to,uint256 value,uint256 validAfter,uint256 validBefore,bytes32 nonce)")
    bytes32 public constant TRANSFER_WITH_AUTHORIZATION_TYPEHASH = 0x7c7c6cdb67a18743f49ec6fa9b35f50d52ed05cbed4cc592e13b44501c1a2267;

    // keccak256("ReceiveWithAuthorization(address from,address to,uint256 value,uint256 validAfter,uint256 validBefore,bytes32 nonce)")
    bytes32 public constant RECEIVE_WITH_AUTHORIZATION_TYPEHASH = 0xd099cc98ef71107a616c4f0f941f04c322d8e254fe26b3c6668db87aae413de8;

    mapping(address => mapping(bytes32 => bool)) internal _authorizationStates;

    event AuthorizationUsed(address indexed authorizer, bytes32 indexed nonce);

    string internal constant _INVALID_SIGNATURE_ERROR = "EIP3009: invalid signature";

    function authorizationState(address authorizer, bytes32 nonce)
        external
        view
        returns (bool)
    {
        return _authorizationStates[authorizer][nonce];
    }

    function transferWithAuthorization(
        address from,
        address to,
        uint256 value,
        uint256 validAfter,
        uint256 validBefore,
        bytes32 nonce,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external {
        require(now > validAfter, "EIP3009: authorization is not yet valid");
        require(now < validBefore, "EIP3009: authorization is expired");
        require(
            !_authorizationStates[from][nonce],
            "EIP3009: authorization is used"
        );

        bytes memory data = abi.encode(
            TRANSFER_WITH_AUTHORIZATION_TYPEHASH,
            from,
            to,
            value,
            validAfter,
            validBefore,
            nonce
        );
        require(
            EIP712.recover(DOMAIN_SEPARATOR, v, r, s, data) == from,
            "EIP3009: invalid signature"
        );

        _authorizationStates[from][nonce] = true;
        emit AuthorizationUsed(from, nonce);

        _transfer(from, to, value);
    }
}

IERC20Transfer.sol

js
abstract contract IERC20Transfer {
    function _transfer(
        address sender,
        address recipient,
        uint256 amount
    ) internal virtual;
}

EIP712Domain.sol

js
abstract contract EIP712Domain {
    bytes32 public DOMAIN_SEPARATOR;
}

EIP712.sol

js
library EIP712 {
    // keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)")
    bytes32 public constant EIP712_DOMAIN_TYPEHASH = 0x8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f;

    function makeDomainSeparator(string memory name, string memory version)
        internal
        view
        returns (bytes32)
    {
        uint256 chainId;
        assembly {
            chainId := chainid()
        }

        return
            keccak256(
                abi.encode(
                    EIP712_DOMAIN_TYPEHASH,
                    keccak256(bytes(name)),
                    keccak256(bytes(version)),
                    address(this),
                    bytes32(chainId)
                )
            );
    }

    function recover(
        bytes32 domainSeparator,
        uint8 v,
        bytes32 r,
        bytes32 s,
        bytes memory typeHashAndData
    ) internal pure returns (address) {
        bytes32 digest = keccak256(
            abi.encodePacked(
                "\x19\x01",
                domainSeparator,
                keccak256(typeHashAndData)
            )
        );
        address recovered = ecrecover(digest, v, r, s);
        require(recovered != address(0), "EIP712: invalid signature");
        return recovered;
    }
}

A complete EIP3009 implementation requires the code in the following repository, the EIP2612 code, and the EIP712 code shown above.

Security

The following sections explain the security considerations.

Security Considerations

Prefer receiveWithAuthorization

When calling from another contract, prefer receiveWithAuthorization over transferWithAuthorization for the following reasons.

  • Front-running risk
    • An attacker monitoring the transaction pool could extract the transferWithAuthorization approval and front-run the transaction, executing the transfer without calling the wrapper function.
    • As a result, the tokens become locked without being processed.
    • receiveWithAuthorization prevents this problem by additionally checking that the caller is the recipient address.
Leading Bytes of the nonce

If multiple contract functions accept approve authorizations, the same authorization must not be usable in another function. Use the leading bytes of the nonce as a specific identifier to prevent execution by the wrong function.

Submitting Multiple Transfers Concurrently

Relayers and miners determine the order in which transactions are processed. This is not a problem if the transactions are independent of one another. If transactions depend on one another, however, submit signed approve authorizations one at a time.

Rejecting the Zero Address When Using ecrecover

Reject the zero address when using ecrecover. This prevents invalid transfers and token approvals from the zero address. This check matters because the built-in ecrecover function returns the zero address when given an invalid signature.

Citation

Peter Jihoon Kim (@petejkim), Kevin Britz (@kbrizzle), David Knott (@DavidLKnott), "ERC-3009: Transfer With Authorization [DRAFT]," Ethereum Improvement Proposals, no. 3009, September 2020. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-3009.

Conclusion

This article covered ERC3009, a proposal for executing the approve + transferFrom meta-transactions introduced by ERC2612 more safely. I hope you found it useful.

If you have questions, feel free to contact me by direct message on Twitter.

Twitter @cardene777

I also share information on other platforms, so feel free to explore them.

https://chaldene.net/