chore(forge): cheat eip712 struct hash#10626
Conversation
|
@Philogy @PatrickAlphaC how would u feel about this complimentary cheatcode? |
|
@0xrusowsky Where does this magic |
it is thanks to bindings that are auto-generated when running for full ctx see: #8345 (comment) |
|
@0xrusowsky I see, still seems less convenient than just being able to directly do |
yash-atreya
left a comment
There was a problem hiding this comment.
tests look good! Can be added as examples in the book as well, under the guides section perhaps?
Adds a new cheatcode to safely generate struct hashes following the EIP-712 spec, further enhancing Foundry's support.
Complementary of:
implementation details
ref #4818
the cheatcode accepts two primary arguments:
forge bind-json(recommended)internally, the cheatcode implementation leverages alloy to encode the data following the EIP-712 spec.
context
while
vm.eip712HashTypeoffers a reliable method for obtaining the type hash, developers also need to compute the hashStruct(message)to prepare data for signing or to verify signatures. Manually implementing the data encoding logic in Solidity is a significant source of errors.vm.eip712HashStructabstracts this complexity. It provides a dependable way to obtain the correct struct hash for any given EIP-712 compliant data directly within Foundry.this new cheatcode aims to provide robustness to the codebases, and peace of mind for developers, giving them guarantees that the encoding scheme that they used is correct.
example usage
using the built-in json bindings to avoid passing the full type definition:
important note
when using
vm.eip712HashType:amontinstead ofamountin the string will still produce a valid EIP-712 hash, but for the incorrect type, leading to runtime signature verification errors.forge bind-jsongenerated bindings, ensuring the hash corresponds to your actual compiled contract structs. This provides a guarantee of alignment, catching discrepancies that the string method would miss.