EIP-2566: Human Readable Parameters for Contract Function Execution


Metadata
Status: StagnantStandards Track: InterfaceCreated: 2020-03-23
Authors
Joseph Stockermans (@jstoxrocky)

Simple Summary


New Ethereum RPC method eth_sendTransactionToContractFunction that parallels eth_sendTransaction but allows for human-readable contract function execution data to be displayed to users.

Abstract


When a dapp prompts a user to execute a smart contract function via a ProviderWallet, confirmation screens displayed in the ProviderWallet layer cannot display the human readable details of the function to be called and the arguments to be passed. This is because the Ethereum RPC method used for contract function execution (eth_sendTransaction) accepts information about what function to call in a non-human readable (and non-recoverable) format. As such, when a ProviderWallet receives this non-human readable information from a dapp, they are unable to display a human readable version since they never received one and cannot recover one from the data.

This creates a poor and potentially dangerous user experience. For example, a malicious dapp could swap out the address argument in a token contract's transfer(address,uint256) function and reroute the tokens intended for someone else to themselves. This sleight-of-hand would be quiet and unlikely to be picked up by a casual user glancing over the non-human readable data. By adding a new Ethereum RPC method (eth_sendTransactionToContractFunction) that accepts the function ABI, ProviderWallets can recreate and display the human readable details of contract function execution to users.

Motivation


ProviderWallet Definition

ProviderWallets like Metamask and Geth are hybrid software that combine an Ethereum API provider with an Ethereum wallet. This allows them to sign transactions on behalf of their users and also broadcast those signed transactions to the Ethereum network. ProviderWallets are used for both convenience and for the protection they give users through human readable confirmation prompts.

Existing Solutions

Much discussion has been made in the past few years on the topic of human readable Ethereum transaction data. Aragon's Radspec addresses this issue by requiring contract developers to amend their contract functions with human readable comments. ProviderWallets can then use Aragon's Radspec software to parse these comments from the contract code and display them to the end user - substituting in argument values where necessary. Unfortunately, this approach cannot work with contracts that do not have Radspec comments (and may require integration with IPFS).

EIP 1138 also addresses this issue directly but contains serious security issues - allowing untrusted dapps to generate the human readable message displayed to users. In a similar train of thought, Geth's #2940 PR and EIPs 191, 712 all highlight the Ethereum community's desire for ProviderWallets to better inform users about what data they are actually acting upon.

Finally, the ProviderWallet Metamask already includes some built-in magic for interactions with ERC20 contracts that allows confirmation prompts to display the intended token recipient and token value. Although this is accomplished in an ad hoc fashion for ERC20-like contracts only, the motivation is the same: users deserve better information about the execution of contract functions they are relying on ProviderWallets to perform.

Background

At one point or another, a dapp will ask a user to interact with a contract. The interaction between dapps and contracts is a large part of the Ethereum ecosystem and is most commonly brokered by a ProviderWallet. When a dapp asks a user to interact with a contract, it will do so by sending the eth_sendTransaction method name to the Ethereum API exposed by a ProviderWallet along with the relevant transaction data. The data field of the transaction data contains the information necessary for the Ethereum virtual machine to identify and execute the contract's function. This field has a specific formatting that is both non-human readable and non-recoverable to its human readable state.

The accepted format for eth_sendTransaction's data field is the hexadecimal encoding of the first four bytes of the keccak256 digest of the function signature. This abbreviated hash is then concatenated with the ABI encoded arguments to the function. Since the keccak256 digest of the function signature cannot be converted back into the function signature, the data field is not only non-human readable, its non-recoverable as well. On top of this, additional insight into the concatenated argument values is further obfuscated as information about their data types are held in the function signature preimage.

Specification


This EIP proposes increasing the set of Ethereum RPC methods to include a new method - eth_sendTransactionToContractFunction. This method parallels eth_sendTransaction with the only difference being the inclusion of the contract function's abi field.

Parameters

  1. Object - The transaction object
  • from: DATA, 20 Bytes - The address the transaction is sent from.
  • to: DATA, 20 Bytes - (optional when creating new contract) The address the transaction is directed to.
  • gas: QUANTITY - (optional, default: 90000) Integer of the gas provided for the transaction execution. It will return unused gas.
  • gasPrice: QUANTITY - (optional, default: To-Be-Determined) Integer of the gasPrice used for each paid gas
  • value: QUANTITY - (optional) Integer of the value sent with this transaction
  • data: DATA - The hash of the invoked method signature and encoded parameters
  • abi: DATA - The function ABI
  • nonce: QUANTITY - (optional) Integer of a nonce. This allows to overwrite your own pending transactions that use the same nonce.

Example Parameters


Returns DATA, 32 Bytes - the transaction hash, or the zero hash if the transaction is not yet available.

Example // Request curl -X POST --data '{"jsonrpc":"2.0","method":"eth_sendTransactionToContractFunction","params":[{see above}],"id":1}'

// Result { "id":1, "jsonrpc": "2.0", "result": "0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331" }

Rationale


This EIP's proposed eth_sendTransactionToContractFunction method is intended to parallel eth_sendTransaction as much as possible since both methods result in the same behaviour when executing a contract function. The newly introduced abi field is an element of the contract's ABI that corresponds to the intended function. The data field is the same data field from eth_sendTransaction. The abi field can be combined with values parsed from the data field to recreate human readable contract function execution information.

Implementation


The data field in eth_sendTransactionToContractFunction is the same as that required for eth_sendTransaction allowing the transaction to be completed via the existing mechanisms used for eth_sendTransaction. The input argument values can be parsed from the data field and since we know their types from the abi field, the provider wallet can use this info to encode and display the values in an appropriate human readable format. Furthermore, the hashed and truncated function signature in the data field can be reconstructed using the information provided in the abi field providing an additional check to ensure that the supplied ABI matches the data field.

Backwards Compatibility


With backwards compatibility in mind, this EIP proposes augmenting the set of Ethereum RPC methods with an additional method instead of mutating the existing method. Precedent for adding a new RPC method comes from EIP 712 in which adding the method eth_signTypedData is proposed for confirmation prompt security. As an alternate approach, the eth_sendTransaction method could be changed to accept an additional abi argument, but this would break all existing code attempting to execute a contract function.

Security Considerations


Displaying the contract address, function name, and argument values can provide additional security to users, but it is not a guarantee that a function will execute as the user expects. A poorly implemented contract can still name its function transfer and accept address and uint256 arguments - but there is nothing short of contract examination that will let a user know that this contract is indeed a valid ERC20 contract. This EIP does not intend to solve the larger problem around trust in a contract's code, but instead intends to give users better tools to understand exactly what is contained within the data they are broadcasting to the Ethereum network.

Copyright


Copyright and related rights waived via CC0.