EIPs Explained

ERC-1077 · Stagnant · ERC · 2018-05-04

ERC-1077: Gas relay for contract calls

An early meta-transaction interface for account contracts: the user signs a message, a relayer submits it and pays the ETH gas, and the contract reimburses the relayer in a token.

What problem does it solve?

Every Ethereum transaction has to be paid for in ETH. For a new user that is a real barrier: before they can touch an app they must buy ETH, even if the app's own token is all they care about.

ERC-1077 standardises a workaround. The user's funds live in an account contract (an early smart-contract wallet). The user only signs a message describing what they want to do. Anyone holding ETH, a relayer, can submit that message in a real transaction, and the account contract pays the relayer back for the gas, in ETH or in an ERC-20 token the two sides agreed on.

How it works

The account contract exposes:

Function Purpose
executeGasRelay(execData, gasPrice, gasLimit, gasToken, gasRelayer, signature) Verify the signature, run execData, pay the relayer
executeGasRelayMsg(...) Build the raw message to be signed
executeGasRelayERC191Msg(...) Same message wrapped in EIP-191 format
lastNonce() Current nonce for relayed messages

The signed message covers: the account address, the chain ID (EIP-1344), the function selector, a nonce, the call data to execute, the gas price (denominated in the chosen token), a gas limit, the gas token (zero address for ETH) and the relayer allowed to collect the refund (zero for block.coinbase).

Signature checking goes through ERC-1271, so the owner of the account can itself be a contract such as a multisig.

The contract measures gas used around the call and transfers gasSpent * gasPrice of the gas token to the relayer. If the inner call fails, the nonce is still consumed and the relayer is still paid, so relayers are not punished for a user's failed action. If funds are insufficient or the gas limit is exceeded, the whole transaction reverts.

Sample code

Building the hash the user signs, as the spec defines it (Solidity 0.8 syntax):

function gasRelayHash(
    uint256 nonce,
    bytes memory execData,
    uint256 gasPrice,
    uint256 gasLimit,
    address gasToken,
    address gasRelayer
) public view returns (bytes32) {
    return keccak256(
        abi.encodePacked(
            bytes1(0x19),          // EIP-191 prefix
            bytes1(0x00),          // EIP-191 version 0
            address(this),         // validator = this account contract
            block.chainid,
            bytes4(keccak256("executeGasRelay(uint256,bytes,uint256,uint256,address,address)")),
            nonce,
            execData,
            gasPrice,
            gasLimit,
            gasToken,
            gasRelayer
        )
    );
}

The same hash off-chain (ethers v6), signed by a device key:

import { solidityPackedKeccak256, id, dataSlice, Wallet } from "ethers";

const hash = solidityPackedKeccak256(
  ["bytes1", "bytes1", "address", "uint256", "bytes4", "uint256", "bytes", "uint256", "uint256", "address", "address"],
  ["0x19", "0x00", account, chainId,
   dataSlice(id("executeGasRelay(uint256,bytes,uint256,uint256,address,address)"), 0, 4),
   nonce, execData, gasPrice, gasLimit, gasToken, relayer],
);
const signature = new Wallet(deviceKey).signingKey.sign(hash).serialized;

Things to know

  • Status is Stagnant. It never became a widely adopted standard, and the account-contract interface itself was left out of scope.
  • Relayers take on risk: an account contract might not actually refund them. The spec tells relayers to simulate a call before submitting it and to keep their own reputation list of contracts and tokens.
  • Today the same goals are usually met with ERC-2771 (trusted forwarders), ERC-4337 (account abstraction with paymasters) or EIP-7702 for EOAs.
  • The ideas here (device keys, paying gas in tokens, apps sponsoring users) fed directly into later smart-wallet designs.

#meta-transactions #gas-abstraction #relayer #account-contract #signatures

Details

Authors
Alex Van de Sande <[email protected]>, Ricardo Guilherme Schmidt (@3esmit)
Status
Stagnant
Type
Standards Track / ERC
Created
2018-05-04
Requires
Required by

Machine-readable: Markdown · JSON