EIP-7713 EIP-712 box type extension (Box type for EIP-712 messages)

No call decision · Security & privacy · EIP status Stagnant · created 2024-05-23

Defines a "box" type for embedding parameters of arbitrary type inside an EIP-712 signed message, letting wallets display the inner data transparently to users while verifying contracts remain unaware of the inner type.

Why it is needed

EIP-712 signing is a standard for wallets to show users the content of a message in human-readable form before signing. But standards like ERC-7683 pack chain-specific order data into a bytes field called orderData, and once an arbitrary type is represented as bytes, the wallet screen shows only a hex string with no way to see the actual content. Similarly, for an ERC-1271 smart contract account's signature to be safe from replay attacks, the app's EIP-712 message must be wrapped once more in an outer message that binds it to a specific account. But the outer message's type depends on the inner message's type, so for a contract to reconstruct that type on-chain, the entire type would have to be encoded as a string and carried in the signature. This is inefficient. The box type lets a verifying contract remain unaware of the inner type while still giving wallets a way to display the content transparently.

What changes

Today

After EIP-7713

Who is affected

In depth

box type declaration and encodeType

A struct member declared with type box becomes a boxed member. The actual type of this member (the unboxed type) is an arbitrary struct type that can differ per message. In encodeType, a boxed member is encoded as "box " + name. In the example, the Envelope struct is encoded as Envelope(address account,box contents). In other words, only the box placeholder appears in the outer type definition, not the actual inner type name.

Handling box values in encodeData

A boxed value is itself treated as a single unboxed value and is encoded in encodeData as its own hashStruct. That is, hashStruct(value) = keccak256(typeHash, encodeData(value)), where typeHash corresponds to the unboxed type (the inner struct type) and encodeData also operates on that inner type's value. Since only this inner hashStruct result enters the outer struct's hash computation, the outer struct need not know the details of the inner type.

Changes to the signTypedData request schema

In the message object of a signing request that includes a box member, that field must be an object with the three properties value, primaryType, and types. value is type-checked and encoded according to primaryType and types, which works the same as ordinary EIP-712 message processing except that there is no \x19 prefix. The types defined in the outer message do not apply to encoding this inner value. For example, Envelope's contents field holds a standalone object containing the Mail type and a greeting value.

JSON Schema of a boxed value

A boxed value object must have all three properties: value (object), primaryType (string), and types (an object whose each key holds an array of {name, type}). This schema is the baseline a wallet or library uses to validate that a received box field has the correct shape.

Motivation 1: The orderData problem in ERC-7683

ERC-7683 packs cross-chain order information into a bytes field called orderData. This has the advantage of allowing arbitrary, implementation-specific information such as tokens, amounts, destination chain, fees, and settlement parameters, but the moment it is represented as bytes, the type is erased. As a result, the wallet's signing screen shows only an uninterpretable hex string, and the user cannot confirm what they are actually signing. This defeats the very transparency of signed content that EIP-712 was designed to provide.

Motivation 2: Inefficiency of ERC-1271 replay prevention

For a smart contract account's ERC-1271 signature to be safe from replay attacks, the app's EIP-712 message must be wrapped in an outer message that binds it to a specific account, without hiding the message content. But the outer message's type depends on the inner message's type, so for a contract to reproduce and verify that type on-chain, the inner message's type must be encoded as a string and passed in its entirety as part of the signature. This is an inefficient approach. The box type is a way to safely encapsulate the inner type without this reconstruction process.

Incomplete status and caveats

This EIP's status is Stagnant. In the original text, the Rationale section is marked "TBD" and the Security Considerations section is marked "Needs discussion," meaning they have not yet been written. In other words, the original document itself does not contain the official rationale for why the box type was designed this way, nor a security review of issues such as signature forgery or type confusion. This must be kept in mind when considering real-world adoption.

Original EIP · ← EIPs