webb-tools / zero-knowledge-gadgets

Zero-knowledge gadgets for Webb's cross-chain blockchain applications.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[BUG] Poseidon padding on empty hashes is not correct

drewstone opened this issue · comments

https://github.com/webb-tools/arkworks-gadgets/blob/b2fc1f4a6f9a194ba5a5080df96c8783ef45f9bf/arkworks-gadgets/src/merkle_tree/mod.rs#L373

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

commented

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

commented

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.