Thiagodeev/fix-snip-12-selector-encode #793
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR aims to fix an error in the SNIP-12
selectortype encoding.The SNIP only says that this type should be keccak-hashed (and that's exactly what Starknet.go currently does, it just takes the JSON value and hashes it), but there are some other cases when this is not correct.
Here's one edge case: instead of a user passing a method name string (like
transfer), they pass the already keccak-hashed hex string (e.g.0x2f0b3c5710379609eb5495f1ecd348cb28167711b73609fe565a72734550354). In this case, hashing the JSON value will lead to a different encoding, as we would be hashing a different value than the function name, leading to a different final message hash of the entire typedData.This is exactly what was happening in Starknet.go. The AVNU paymaster was returning a typedData with an already hashed selector string as the
selectorvalue, and we are hashing it again.Now, we will do the same as Starknet.js, which is check if the JSON value is a hex string, and skip the hashing process if true. That way we can avoid this error.
It's not SNIP-12 compliant, but we can say this is more like a SNIP-12 description problem than an implementation problem.
Starknet.js refs:
selectorstarknet-io/starknet.js#1348