You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
AFAIU, it should also hashes the 'type hash' with the index and parameters.
Look at these prints taken when debugging while starknet.js encodes the enum_example:
Here we are encoding EnumA, and the data is [2, [0, 1]]. The code encodes the data to a new array containing the encoded data and passes it with the variantIndex variable (value 1).
Inside the hash function, we can see that only these three values will be hashed, with no mention of the type hash value quoted by the spec. The returned value is '0x583136381661e3eb69d103f2d6f40e6aa190005c3d5c8f0351b080c69602dcb' to the EnumA type.
This is the result of EnumB (value: '0x1fb7169b936dd880cb7ebc50e932a495a60e0084cdab94a681040cb4006e1a0'):
At the end, this will be the result of calling the getStructHash function to calculate the hash of the Example type.
'0x8eb4aeac64b707f3e843284c4258df6df1f0f7fd38dcffdd8a153a495cd351' is the type hash of Example
'0x583136381661e3eb69d103f2d6f40e6aa190005c3d5c8f0351b080c69602dcb' is the hash of EnumA
'0x1fb7169b936dd880cb7ebc50e932a495a60e0084cdab94a681040cb4006e1a0' is the hash of EnumB.
This is correct for the Example type, since the spec says that this is the default for object types (Enc[x] = hash_array(type_hash(MyObject), Enc[param1], Enc[param2], ..., Enc[paramN])), but the values of the EnumA and EnumB encoding are theoretically wrong since they were calculated without the type hash value. So, it's a wrong result after all.
What do you think guys? Please let me know if I misunderstood something.
The text was updated successfully, but these errors were encountered:
Hi. I want to talk about this line of code:
starknet.js/src/utils/typedData.ts
Line 375 in 01171b0
The code only hashes the enum index + the enum parameters but the SNIP-12 says the enum hash is:
Enc[enum] = hash_array(type_hash(enum), variant_index, Enc[chosen_variant_parameter1],..., Enc[chosen_variant_parameterN])
(ref: https://github.com/starknet-io/SNIPs/blob/main/SNIPS/snip-12.md#encoding-4).
AFAIU, it should also hashes the 'type hash' with the index and parameters.
Look at these prints taken when debugging while starknet.js encodes the enum_example:
Here we are encoding EnumA, and the data is
[2, [0, 1]]
. The code encodes the data to a new array containing the encoded data and passes it with thevariantIndex
variable (value1
).Inside the hash function, we can see that only these three values will be hashed, with no mention of the
type hash
value quoted by the spec. The returned value is'0x583136381661e3eb69d103f2d6f40e6aa190005c3d5c8f0351b080c69602dcb'
to theEnumA
type.This is the result of
EnumB
(value:'0x1fb7169b936dd880cb7ebc50e932a495a60e0084cdab94a681040cb4006e1a0'
):At the end, this will be the result of calling the
getStructHash
function to calculate the hash of theExample
type.'0x8eb4aeac64b707f3e843284c4258df6df1f0f7fd38dcffdd8a153a495cd351'
is the type hash ofExample
'0x583136381661e3eb69d103f2d6f40e6aa190005c3d5c8f0351b080c69602dcb'
is the hash ofEnumA
'0x1fb7169b936dd880cb7ebc50e932a495a60e0084cdab94a681040cb4006e1a0'
is the hash ofEnumB
.This is correct for the
Example
type, since the spec says that this is the default for object types (Enc[x] = hash_array(type_hash(MyObject), Enc[param1], Enc[param2], ..., Enc[paramN])
), but the values of theEnumA
andEnumB
encoding are theoretically wrong since they were calculated without thetype hash
value. So, it's a wrong result after all.What do you think guys? Please let me know if I misunderstood something.
The text was updated successfully, but these errors were encountered: