ERC-3224: Described Data

Contract method to compute human-readable descriptions for signable data.


Metadata
Status: StagnantStandards Track: ERCCreated: 2021-01-23
Authors
Richard Moore (@ricmoo), Nick Johnson (@arachnid)
Requires

Abstract


Human-readable descriptions for machine executable operations, described in higher level machine readable data, so that wallets can provide meaningful feedback to the user describing the action the user is about to perform.

Motivation


When using an Ethereum Wallet (e.g. MetaMask, Clef, Hardware Wallets) users must accept and authorize signing messages or sending transactions.

Due to the complexity of Ethereum transactions, wallets are very limitd in their ability to provide insight into the contents of transactions user are approving; outside special-cased support for common transactions such as ERC20 transfers, this often amounts to asking the user to sign an opaque blob of binary data.

This EIP presents a method for dapp developers to enable a more comfortable user experience by providing wallets with a means to generate a better description about what the contract claims will happen.

It does not address malicious contracts which wish to lie, it only addresses honest contracts that want to make their user's life better. We believe that this is a reasonable security model, as transaction descriptions can be audited at the same time as contract code, allowing auditors and code reviewers to check that transaction descriptions are accurate as part of their review.

Specification


The description string and described data are generated simultaneously by evaluating the contract (i.e. the describer), passing the describer inputs to the method:


The method must be executable in a static context, (i.e. any side effects, such as logX, sstore, etc.), including through indirect calls may be ignored.

During evaluation, the ADDRESS (i.e. to), CALLER (i.e. from), VALUE, and GASPRICE must be the same as the values for the transaction being described, so that the code generating the description can rely on them. For signing described messages, VALUE should always be 0.

When executing the bytecode, best efforts should be made to ensure BLOCKHASH, NUMBER, TIMESTAMP and DIFFICULTY match the "latest" block. The COINBASE should be the zero address.

The method may revert, in which case the signing must be aborted.

New JSON-RPC Methods

Clients which manage private keys should expose additional methods for interacting with the related accounts.

If an user interface is not present or expected for any other account-based operations, the description strings should be ignored and the described data used directly.

These JSON-RPC methods will also be implemented in standard Ethereum libraries, so the JSON-RPC description is meant more of a canonical way to describe them.

Signing Described Messages


Compute the description string and described data by evaluating the call to describer, with the describerInput passed to the ABI encoded call to eipXXXDescription(bytes). The VALUE during execution must be 0.

If the wallet contains a user interface for accepting or denying signing a message, it should present the description string to the user. Optionally, a wallet may wish to additionally provide a way to examine the described data.

If accepted, the computed described data is signed according to EIP-191, with the version byte of 0x00 and the version specific data of describer address.

That is:


The returned result includes the described data, allowing dapps that use parameters computed in the contract to be available.

Sending Described Transactions


Compute the description string and described data by evaluating the call to the describer to, with the describerInput passed to the ABI encoded call to eipXXXDescription(bytes).

If the wallet contains a user interface for accepting or denying a transaction, it should present the description string along with fee and value information. Optionally, a wallet may wish to additionally provide a way to further examine the transaction.

If accepted, the transaction data is set to the computed described data, the derived transaction is signed and sent, and the description string and serialized signed transaction is returned.

Signing Described Transaction


Compute the description string and described data by evaluating the call to the describer to, with the describerInput passed to the ABI encoded call to eipXXXDescription(bytes).

If the wallet contains a user interface for accepting or denying a transaction, it should present the description string along with fee and value information. Optionally, a wallet may wish to additionally provide a way to further examine the transaction.

If accepted, the transaction data is set to the computed described data, the derived transaction is signed (and not sent) and the description string and serialized signed transaction is returned.

Description Strings

A description string must begin with a mime-type followed by a semi-colon (;). This EIP specifies only the text/plain mime-type, but future EIPs may specify additional types to enable more rich processing, such as text/markdown so that addresses can be linkable within clients or to enable multi-locale options, similar to multipart/form-data.

Rationale


Meta Description

There have been many attempts to solve this problem, many of which attempt to examine the encoded transaction data or message data directly.

In many cases, the information that would be necessary for a meaningful description is not present in the final encoded transaction data or message data.

Instead this EIP uses an indirect description of the data.

For example, the commit(bytes32) method of ENS places a commitement hash on-chain. The hash contains the blinded name and address; since the name is blinded, the encoded data (i.e. the hash) no longer contains the original values and is insufficient to access the necessary values to be included in a description.

By instead describing the commitment indirectly (with the original information intact: NAME, ADDRESS and SECRET) a meaningful description can be computed (e.g. "commit to NAME for ADDRESS (with SECRET)") and the matching data can be computed (i.e. commit(hash(name, owner, secret))).

Entangling the Contract Address

To prevent data being signed from one contract being used against another, the contract address is entanlged into both the transaction (implicitly via the to field) and in messages by the EIP-191 versions specific data.

The use of the zero address is reserved.

Alternatives

  • NatSpec and company are a class of more complex languages that attempt to describe the encoded data directly. Because of the language complexity they often end up being quite large requiring entire runtime environments with ample processing power and memory, as well as additional sandboxing to reduce security concerns. One goal of this is to reduce the complexity to something that could execute on hardware wallets and other simple wallets. These also describe the data directly, which in many cases (such as blinded data), cannot adequately describe the data at all

  • Custom Languages; due to the complexity of Ethereum transactions, any language used would require a lot of expressiveness and re-inventing the wheel. The EVM already exists (it may not be ideal), but it is there and can handle everything necessary.

  • Format Strings (e.g. Trustless Signing UI Protocol; format strings can only operate on the class of regular languages, which in many cases is insufficient to describe an Ethereum transaction. This was an issue quite often during early attempts at solving this problem.

  • The signTypedData EIP-712 has many parallels to what this EIP aims to solve

  • @TODO: More

Backwards Compatibility


All signatures for messages are generated using EIP-191 which had a previously compatible version byte of 0x00, so there should be no concerns with backwards compatibility.

Test Cases


All test cases operate against the published and verified contracts:

  • Formatter: Ropsten @ 0x7a89c0521604008c93c97aa76950198bca73d933
  • TestFormatter: Ropsten @ 0xab3045aa85cbcabb06ed3f3fe968fa5457727270

The private key used for signing messages and transactions is:


Messages

Example: login with signed message

  • sends selector login()
  • received data with selector doLogin(bytes32 timestamp)

Transactions

All transaction test cases use the ropsten network (chainId: 3) and for all unspecified properties use 0.

Example: ERC-20 transfer


Example: ERC-20 approve


Example: ENS commit


Example: WETH mint()


Reference Implementation


@TODO (consider adding it as one or more files in ../assets/eip-####/)

I will add examples in Solidity and JavaScript.

Security Considerations


Escaping Text

Wallets must be careful when displaying text provided by contracts and proper efforts must be taken to sanitize it, for example, be sure to consider:

  • HTML could be embedded to attempt to trick web-based wallets into executing code using the script tag (possibly uploading any private keys to a server)
  • In general, extreme care must be used when rendering HTML; consider the ENS names <span style="display:none">not-</span>ricmoo.eth or &thinsp;ricmoo.eth, which if rendered without care would appear as ricmoo.eth, which it is not
  • Other marks which require escaping could be included, such as quotes ("), formatting (\n (new line), \f (form feed), \t (tab), any of many non-standard whitespaces), back-slassh (\)
  • UTF-8 has had bugs in the past which could allow arbitrary code execution and crashing renderers; consider using the UTF-8 replacement character (or something) for code-points outside common planes or common sub-sets within planes
  • Homoglyphs attacks
  • Right-to-left marks may affect rendering
  • Many other things, deplnding on your environment

Distinguished Signed Data

Applications implementing this EIP to sign message data should ensure there are no collisions within the data which could result in ambiguously signed data.

@TODO: Expand on this; compare packed data to ABI encoded data?

Enumeration

If an abort occurs during signing, the response from this call should match the response from a declined signing request; otherwise this could be used for enumeration attacks, etc. A random interactive-scale delay should also be added, otherwise a < 10ms response could be interpreted as an error.

Replayablility

Transactions contain an explicit nonce, but signed messages do not.

For many purposes, such as signing in, a nonce could be injected (using block.timestamp) into the data. The log in service can verify this is a recent timestamp. The timestamp may or may not be omitted from the description string in this case, as it it largely useful internally only.

In general, when signing messages a nonce often makes sense to include to prevent the same signed data from being used in the future.

Copyright


Copyright and related rights waived via CC0.