ERC-2770 · Withdrawn · ERC · 2020-07-01
ERC-2770: Meta-Transactions Forwarder Contract
Proposed a standard Forwarder contract that verifies EIP-712 signed requests and relays them to target contracts, so users without ETH could interact via meta-transactions.
What problem does it solve?
To call a contract you normally need ETH for gas. That is a large hurdle for new users. Meta-transactions work around it: the user signs a request off-chain, and a relayer wraps it in a real transaction and pays the gas.
The contract being called then cannot trust msg.sender (it is the relayer), so something must check the user's signature. EIP-2770 proposes one shared, audited Forwarder contract to do that for every relayer and recipient, instead of each project reimplementing signature checks.
How it works
- The user signs a
ForwardRequestwith EIP-712 typed data:
struct ForwardRequest {
address from; // signer
address to; // target contract
uint256 value; // wei to send
uint256 gas; // gas for the inner call
uint256 nonce; // replay protection, tracked by the Forwarder
bytes data; // calldata
uint256 validUntil; // last valid block number, 0 = no expiry
}
- A relayer calls
execute(request, domainSeparator, requestTypeHash, suffixData, signature)on the Forwarder. - The Forwarder verifies the signature and nonce, then calls
towithdataandfromappended as the last 20 bytes of calldata. - The nonce is incremented whether or not the inner call succeeds, so the request cannot be replayed.
Extensible types. Projects can register extended request types with registerRequestType(typeName, typeSuffix), adding fields after the standard ones. The extra fields are passed as suffixData so wallets can still show users readable EIP-712 data.
Gas checks. The Forwarder requires gasleft() * 63/64 >= gas (+40000 if value != 0) before calling, so a relayer cannot starve the inner call (see EIP-150's 63/64 rule).
Sample code
A recipient that trusts one Forwarder and reads the real sender, following ERC-2771:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
contract Recipient {
address public immutable trustedForwarder;
mapping(address => uint256) public counter;
constructor(address forwarder) { trustedForwarder = forwarder; }
function _msgSender() internal view returns (address signer) {
if (msg.sender == trustedForwarder && msg.data.length >= 20) {
// last 20 bytes of calldata = original signer
assembly { signer := shr(96, calldataload(sub(calldatasize(), 20))) }
} else {
signer = msg.sender;
}
}
function increment() external {
counter[_msgSender()] += 1;
}
}
Things to know
- Status: Withdrawn. The stated reason: a singleton Forwarder implementation does not need to be standardized. The recipient side lives on as ERC-2771, which is Final.
- Trusting a forwarder means trusting it with every account: if it is buggy or upgradable by someone, it can act as any user towards your contract.
- If the inner call sends ETH back to the Forwarder on a request that carried no value, that ETH stays stuck in the Forwarder.
- For gasless UX today, also look at account abstraction via ERC-4337 paymasters.