-
Notifications
You must be signed in to change notification settings - Fork 2k
chore(forge): cheat eip712 struct hash #10626
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tests look good! Can be added as examples in the book as well, under the guides section perhaps?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm!
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.eip712HashType
offers 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.eip712HashStruct
abstracts 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
:amont
instead ofamount
in the string will still produce a valid EIP-712 hash, but for the incorrect type, leading to runtime signature verification errors.forge bind-json
generated 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.