[BUG] Poseidon padding on empty hashes is not correct
drewstone opened this issue · comments
this is feeding evaluate
a length-0 array, then a leading 0 is added within evaluate, but then it goes to permute
with length 1 and is not padded to have length 3
To make it more semantically correct, we should pass [0u8; 32]
here: https://github.com/webb-tools/arkworks-gadgets/blob/master/arkworks-gadgets/src/merkle_tree/mod.rs#L374
Ah I've been meaning to ask: Why should that array have length 32? I removed the constraint on the array's length while trying to match up to our old implementation, but could change it back if there's a reason for 32
Yes, you are right, we should generally avoid using fixed-size arrays for representing field values since not all elliptic curve fields are the same.
@drewstone This can become a problem in substrate since we use Element([u8; 32])
https://github.com/webb-tools/protocol-substrate/blob/main/runtime/src/lib.rs#L708
I think we'll be alright here truly on the Substrate side. We are expecting a specific curve/hash there and shouldn't over-worry about generalization.