ERC-3005 Batched meta transaction standard (Batched meta transactions)
Stagnant · Tokens · created 2020-09-25
An ERC-20 extension function that lets token holders without ether (gas) send tokens with just a signature, while allowing a relayer to bundle multiple people's meta transactions into a single on chain transaction.
Why it is needed
Meta transactions are a gasless transfer scheme that let holders send tokens with just a signature even without ether, but existing relayer implementations could only process one meta transaction at a time, or could only bundle transactions from the same sender. Without the ability to bundle multiple people's meta transactions into one on chain transaction, a relayer must submit a separate transaction for each person, which increases the gas cost burden and makes it harder to sustain a gasless service. Without this standard, the economics of running a relayer business worsen, and users who hold only tokens and no ether also lose the opportunity to send tokens gaslessly.
What to implement
function processMetaBatch(address[] memory senders, address[] memory recipients, uint256[] memory amounts, uint256[] memory relayerFees, uint256[] memory blocks, uint8[] memory sigV, bytes32[] memory sigR, bytes32[] memory sigS) public returns (bool);: Takes the data of multiple meta transactions as arrays, verifies signatures and conditions, transfers tokens only for the valid ones, and pays the total fee to the relayer.function nonceOf(address account) public view returns (uint256);: Looks up the nonce of the last meta transaction that account successfully completed on this token contract.
In depth
Meta transaction data and hash
The hash to be signed is constructed as keccak256(sender ++ recipient ++ amount ++ relayerFee ++ nonce ++ expirationDate ++ tokenContract ++ relayer). This hash is signed with the sender's private key. Including the token address and relayer address in the hash binds the meta transaction so it is valid only for that specific token contract and that specific relayer.
processMetaBatch function interface
It takes eight arrays in total: senders, recipients, amounts, relayerFees, blocks (expiration blocks), and sigV, sigR, sigS (the three signature parts). The same index across all arrays must refer to a single meta transaction's data; if the order is mismatched, signature verification will reject it. The nonce, token address, and relayer address are not sent as parameters but are derived from contract state, address(this), and msg.sender.
Validation rules
The new nonce must be exactly one greater than the sender's previous nonce. Neither the sender nor the recipient may be the 0x0 address. A meta transaction must be processed before its specified expiration block. The sender's balance must be at least the sum of the amount and the relayer fee. If any single meta transaction in the batch fails to satisfy these conditions, only that entry is skipped rather than reverting the entire transaction.
Nonce management
The contract tracks each account's nonce per token contract using the _metaNonces mapping, which can be queried via nonceOf(). The nonce is computed as the previous nonce plus one rather than taken as a function parameter, because the value is always derivable this way and to avoid a stack too deep error.
Token transfer and relayer fee
Once validation passes, the sender's nonce is incremented by one, the specified amount is sent to the recipient, and the relayer fee is sent to the relayer (msg.sender). In the reference implementation, fees are not paid out on every loop iteration but are summed and paid once at the end of the function, reducing repeated SSTORE costs.
Failure handling approach
Even if the batch contains invalid meta transactions due to signature mismatch, insufficient balance, or an expired block, the entire on chain transaction is not reverted; only that entry is skipped (continue). Relayers do not receive a fee for invalid meta transactions, so relayers are expected to validate them in advance before relaying.
A proposal still stalled
This EIP is in Stagnant status. Open questions such as whether EIP-2612's permit() nonce mapping could be reused, and whether an upper bound should be placed on the expiration block, remain unresolved in the original text and may change or see no further progress.
Things to watch out for
- Replay attack protection: The nonce prevents the same meta transaction from being processed twice on the same token contract, and including the token contract address (address(this)) in the signed hash also prevents the same meta transaction from being replayed on a different token contract.
- Front running prevention: Including the relayer address (msg.sender) in the signed hash causes signature verification to fail if a different relayer intercepts the meta transaction from the mempool and submits it instead.
- Preventing overspending via expiration block: Specifying an expiration block on a meta transaction prevents a situation where, while the relayer is slow to submit it, the user has already sent the same tokens another way, resulting in double spending.
- Duplicate submission with the same nonce: If a user submits the same nonce to multiple relayers at once, only whichever one is reflected on chain first is valid and the rest become invalid. The original text proposes that relayers share their list of pending meta transactions to filter out such conflicts in advance.
- Setting an expiration block too far in the future: A relayer could trick a user into setting the expiration block excessively far away, for example ten years out. The original text offers, as alternatives, placing a block upper bound in the contract or filtering at the relayer level, but neither is included in the reference implementation.