EIPs Explained

EIP-7713 · Stagnant · Interface · 2024-05-23

EIP-7713: Box type for EIP-712 messages

Proposes a box type for EIP-712 so a typed message can embed a struct of any type that the wallet can still display and type-check, instead of hiding it in opaque bytes.

What problem does it solve?

EIP-712 lets wallets show users exactly what they are signing, field by field. That transparency breaks down when a standard message needs to carry implementation-specific data of unknown type. The usual workaround is a bytes field, which wallets can only show as a hex blob.

The spec gives two examples:

  • ERC-7683 cross-chain orders had a bytes orderData field, so users signed opaque data.
  • Making ERC-1271 smart-account signatures replay-safe means wrapping an app's EIP-712 message inside an outer message bound to the account (the approach taken by ERC-7739, itself a Draft). The outer type depends on the inner type, which today requires shipping the inner type string inside the signature.

A box type lets the outer struct stay generic while the inner struct remains fully visible to the wallet.

How it works

  • A struct member can be declared with type box, e.g. struct Envelope { address account; box contents; }.
  • encodeType: a boxed member is written as box <name>, so the outer type is Envelope(address account,box contents) regardless of what is inside. The verifying contract can therefore be agnostic to the inner type.
  • encodeData: a boxed value is encoded as the hashStruct of the underlying (unboxed) value, using that value's own type hash. The inner type is not erased; a contract can still verify it if needed.
  • signTypedData JSON: a boxed value is an object with primaryType, types and value. Types defined in the outer message are not in scope inside the box, so each box is self-describing.

Sample code

An eth_signTypedData_v4-style request using a box (from the spec's example):

{
  "domain": { "name": "MyAccount", "version": "1", "chainId": 1 },
  "primaryType": "Envelope",
  "types": {
    "Envelope": [
      { "name": "account", "type": "address" },
      { "name": "contents", "type": "box" }
    ]
  },
  "message": {
    "account": "0x0000000000000000000000000000000000000001",
    "contents": {
      "primaryType": "Mail",
      "types": { "Mail": [{ "name": "greeting", "type": "string" }] },
      "value": { "greeting": "Hello world" }
    }
  }
}

How the hash is built (pseudocode):

ENVELOPE_TYPEHASH = keccak256("Envelope(address account,box contents)")
MAIL_TYPEHASH     = keccak256("Mail(string greeting)")

contents_hash = keccak256(MAIL_TYPEHASH + keccak256("Hello world"))  # hashStruct of the unboxed value
envelope_hash = keccak256(ENVELOPE_TYPEHASH + pad32(account) + contents_hash)

Things to know

  • Status: Stagnant. The Rationale and Security Considerations sections are still marked TBD / "needs discussion", and box is not part of EIP-712 itself, so a wallet that has not implemented this extension should be expected to reject such a request.
  • Because the outer type string is the same for every inner type, a contract that does not check the inner type hash accepts any boxed struct. Contracts that care about the content must verify it explicitly.
  • If you need replay-safe smart-account signatures now, look at ERC-7739 (Draft), which tackles the nested-message case without changing EIP-712.

#signing #eip712 #wallets #typed-data

Details

Authors
Francisco Giordano (@frangio)
Status
Stagnant
Type
Standards Track / Interface
Created
2024-05-23
Requires

Machine-readable: Markdown · JSON