starknet.js
starknet.js copied to clipboard
SNIP-12 merkletree doesn't include dependent types
Describe the bug Regarding SNIP-12. When calculating the encodetype of an object that includes a merkletree, the dependent types are not transitively added
To Reproduce It can be reproduced with the following types:
{
StarknetDomain: [
{ name: "name", type: "shortstring" },
{ name: "version", type: "shortstring" },
{ name: "chainId", type: "shortstring" },
{ name: "revision", type: "shortstring" },
],
Object: [{ name: "tree", type: "merkletree", contains: "OtherObject" }],
OtherObject: [{ name: "number", type: "uint128" }]
}
Expected behavior
Object encodeType is calculated as
"Object"("tree":"merkletree")
but it should include declaration of the other object too like this:
"Object"("tree":"merkletree")"OtherObject"("number":"uint128")
This works correctly on enums but for some reason it's not done correctly with merkletrees
Screenshots
Desktop (please complete the following information): Node version: 18 Starknet.js version: v6.23.1 (latest)
Additional context
It's worth noting that SNIP-12 actually defines the encoded type to just be merkletree.
Whether this is a bug in SNIP-12 itself is debatable, but honestly starknet.js is really just faithfully following the spec here.
starknet-rs does the same.
Also this would be a breaking change. More discussions seem to be needed before attempting a fix.
It's worth noting that SNIP-12 actually defines the encoded type to just be
merkletree.
The issue is not with the merkletree itself but with the object containing the merkletree.
The encode type for the object mentions:
If the object references other objects/enum which can also reference other objects/enums, the set of referenced objects/enums is collected, sorted by name, and appended to the encoding.
Note that dependent types are included for enums but not for merkletrees, one of the two types must be implemented incorrectly
Ok, maybe your interpretation of the SNIP 12 is
If the object references other objects/enum[..], the set of referenced objects/enums is collected, sorted by name, and its encode_type is appended to the encoding
Will that definition of SNIP-12 make the defacto implementation compatible?
To clarify the SNIP, the same/similar text about referenced objects as can be found for the object and enum entries should be added for merkletree and denoted as a difference between revisions 0 and 1.