EIPs Explained

EIP-2566 · Stagnant · Interface · 2020-03-23

EIP-2566: Human Readable Parameters for Contract Function Execution

Proposes a new RPC method, eth_sendTransactionToContractFunction, that sends the function's ABI alongside the calldata so wallets can show users exactly which function and arguments they are approving.

What problem does it solve?

When a dapp asks a wallet to call a contract, it uses eth_sendTransaction with a data field: a 4-byte function selector (the first bytes of a keccak256 hash of the signature) followed by ABI-encoded arguments. That blob is not human-readable, and the selector can't be reversed into a function name, so the wallet often can't tell the user what is really being signed.

That gap is dangerous. A malicious or compromised dapp could, for example, swap the recipient in a token transfer(address,uint256) call, and a user glancing at hex data would never notice.

How it works

The proposal adds one JSON-RPC method that mirrors eth_sendTransaction and adds a single field:

  • eth_sendTransactionToContractFunction takes the usual transaction object (from, to, gas, gasPrice, value, data, nonce) plus abi, the ABI fragment for the function being called.
  • The wallet decodes the arguments in data using the types from abi, and shows the function name, parameter names and values in its confirmation screen.
  • The wallet can also recompute the selector from the ABI fragment and check that it matches the first four bytes of data, so a dapp can't attach a misleading ABI to different calldata.
  • Execution is unchanged: data is exactly what eth_sendTransaction would have sent, and the method returns the transaction hash.

A new method was chosen instead of changing eth_sendTransaction, so existing code keeps working (the same reasoning EIP-712 used when it added eth_signTypedData).

Sample code

A request as a dapp would send it through an EIP-1193 provider (TypeScript, ethers v6 for encoding):

import { Interface } from "ethers";

const fragment = {
  type: "function",
  name: "transfer",
  stateMutability: "nonpayable",
  inputs: [
    { name: "to", type: "address" },
    { name: "value", type: "uint256" },
  ],
  outputs: [{ name: "", type: "bool" }],
};

const iface = new Interface([fragment]);
const data = iface.encodeFunctionData("transfer", [recipient, 10n ** 18n]);

const txHash = await window.ethereum.request({
  method: "eth_sendTransactionToContractFunction",
  params: [{ from: account, to: tokenAddress, data, abi: JSON.stringify(fragment) }],
});

Wallet-side check that the ABI matches the calldata:

const iface = new Interface([JSON.parse(params.abi)]);
const parsed = iface.parseTransaction({ data: params.data }); // null if selector mismatch
if (!parsed) throw new Error("ABI does not match calldata");
console.log(parsed.name, parsed.args); // show to the user

Things to know

  • Status: Stagnant. The method is not part of the standard Ethereum JSON-RPC API, so don't expect wallets to support it.
  • In practice wallets solved the same problem differently: decoding calldata with ABIs fetched from verified-source databases or signature registries, and simulating transactions before signing.
  • As the spec itself notes, a readable function name is not proof of safety. A contract can name a function transfer and do anything; this only shows what is being called, not what the code does.

#json-rpc #wallet #abi #ux #security

Details

Authors
Joseph Stockermans (@jstoxrocky)
Status
Stagnant
Type
Standards Track / Interface
Created
2020-03-23

Machine-readable: Markdown · JSON