Skip to content

How can I properly encode and hash a message that contains a struct array in accordance to EIP712 using Viem. #1077

Answered by 0xFloop
0xFloop asked this question in Question
Discussion options

You must be logged in to vote

Full solution code here.

TLDR:
eip712 states in regards to hashing arrays/structs that "The array values are encoded as the keccak256 hash of the concatenated encodeData of their contents (i.e. the encoding of SomeType[5] is identical to that of a struct containing five members of type SomeType). The struct values are encoded recursively as hashStruct(value)"

My error came in assuming that these values would be concatenated using the abi.encode method. However, you are meant to use the abi.encodePacked method. This definitely confused me as to why data should be packed here but not in other cases, like within hashStruct for example. Anywho, thats the resolution.

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@dcapitator
Comment options

Answer selected by 0xFloop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants