Skip to content

Cheatcode: EIP712 canonical hashing #4818

Open
@marktoda

Description

@marktoda

Component

Forge

Describe the feature you would like

Motivation

One of the hardest things to properly test in Foundry is EIP-712 encoding and hashing. Efficiently encoding EIP-712 in Solidity generally requires manual declaration of string types and abi encoding of values. In testing, there is no way to double-check that this encoding is actually consistent with the EIP-712 spec. Some catches and edge cases of EIP-712 spec are especially easy to accidentally mess up, i.e. alphabetic ordering of sub-types. This is especially important as signed messages become more widely used, i.e. for EIP-4337.

Currently the best approach for this afaik is to write typescript tests using ethers' TypedDataEncoder to verify

Feature

A cheatcode that creates canonical encodings / typehashes for EIP-712 objects.
Ideal API:

vm.hashType(MyStruct) => bytes32 typeHash
vm.hashStruct(MyStruct struct) => bytes32 hash

I'm not sure how easy the introspection will be, but this would be an invaluable feature to cover one of the last un-testable cases in Foundry

Additional context

No response

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Status

In Progress

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions