-
I cannot seem to figure out how to properly hash a struct (MainStruct in the example) that contains a struct array within it (SubStruct[] in the example) so that it produces the same hash as that generated by Viem's hashTypedData function. I have written out three different sol hashing options in the README that I have tried. Here is a reproduction repo. Thank you very very much for any help and let me know any more info you may need! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
@tmm any chance you can lend a hand with this? would greatly appreciate your help. |
Beta Was this translation helpful? Give feedback.
-
Full solution code here. TLDR: 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. |
Beta Was this translation helpful? Give feedback.
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.