-
Notifications
You must be signed in to change notification settings - Fork 221
feat: Expose NewDefaultPermutation in Poseidon2 packages
#761
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
| "out": [0, 0, 0, 0, 0, 0, 0, 0] | ||
| }, | ||
| { | ||
| "in": [[0, 1, 2, 3, 4, 5, 6, 7]], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The discrepancy seems to arise from differences in how the uint32 values are being encoded into field.Element objects and then serialized into byte buffers.
-
When using this encoding:
_, err = binary.Encode(buf[i*koalabear.Bytes:(i+1)*koalabear.Bytes], binary.BigEndian, in[i])
I printed the input to Permutation (the place right beforeh.Permutationin(h *Permutation) Compress), which is:
[[0] [0] [0] [0] [0] [0] [0] [0] [0] [33554430] [67108860] [100663290] [134217720] [167772150] [201326580] [234881010]], it is equal to [[0] [0] [0] [0] [0] [0] [0] [0] [0] 1xOne(), 2xOne(), 3xOne(),...]. -
When using this encoding:
elem := koalabear.Element{in[i]}
elemBytes := elem.Bytes()
copy(buf[i*koalabear.Bytes:(i+1)*koalabear.Bytes], elemBytes[:])
the input to permutation is: [[0] [0] [0] [0] [0] [0] [0] [0] [0] [1] [2] [3] [4] [5] [6] [7]].
I think the input transformation depends on how you interpret and encode the uint32 values into the field.Element representation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_, err = binary.Encode(buf[i*koalabear.Bytes:(i+1)*koalabear.Bytes], binary.BigEndian, in[i])
and
elem := koalabear.NewElement(uint64(in[i]))
elemBytes := elem.Bytes()
copy(buf[i*koalabear.Bytes:(i+1)*koalabear.Bytes], elemBytes[:])
produce equivalent results. So the main difference from the first line is how in[i] is converted to a koalabear.Element.
For use as a compression function and not a range-extended hasher
Note
Expose NewDefaultPermutation across Poseidon2 packages and switch Merkle–Damgård hashers to use it; add SetBytesCanonical property tests and koalabear Poseidon2 test vectors.
NewDefaultPermutation()returningPermutation{GetDefaultParameters()}inposeidon2.gofor multiple curves/fields and updateNewMerkleDamgardHasher()to use it.SetBytesCanonical(Bytes())remains constant infp/frelement tests across curves and in field generator templates.poseidon2/test-vectors.json) andvectors_test.govalidating width, block sizes, and output.Written by Cursor Bugbot for commit 413eea9. This will update automatically on new commits. Configure here.