feat(poseidon2): support BN254 widths t=4,8,12,16; fix matMulExternal indexing#1741
Conversation
… matMulExternalInPlace default;
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
|
Hey @ivokub I am making this PR to your v0.15.0 release branch as I see you've updated the gnark-crypto to 0.20.0 here, I bumped it to your latest fixed v0.20.1 release. I am adding more T parameter options that are now unlocked by the new gnark-crypto version, it'd be great if you could have a look. |
|
Thanks @beeinger - I'll have a look. |
ivokub
left a comment
There was a problem hiding this comment.
Thanks for the contribution! Looks good. I'll check what the CI reports, but otherwise it is good to merge!
Ah, I see, with gnark-crypto update we also have update code generation which affects our fuzzing small-field backend (tinyfield). Can you run |
|
Sure, on it |
|
@ivokub that should be it |
Thanks! Seems that the static check passes now, I'll wait for the complete CI run before merge |
|
Oh, I just now realized the target branch was It will probably take a bit more time before we can release v0.15 due to #1740 |
|
Yeah sure I can do the same PR to master |
… matMulExternalInPlace default; updated code generation; addressing: Consensys#1741 (comment)
Description
Adds support for BN254 Poseidon2 permutation widths t=4, 8, 12, and 16 in the circuit-side implementation, now that gnark-crypto provides precomputed constants (DiagM1 + round keys) for these widths via gnark-crypto#783.
Previously,
matMulInternalInPlacepanicked for any width beyond 2 or 3:This PR:
DiagM1to the circuitParametersstruct and propagates it from gnark-crypto for BN254DiagM1diagonal, mirroring gnark-crypto'smatMulInternalInPlacematMulExternalInPlacefor thedefault(width = 4k) branch:nil-initialized viamake([]frontend.Variable, 4)instead of zero-valuedinput[4*i+1],input[4*i+2],input[4*i+3]were all incorrectly reading frominput[4*i]Type of change
How has this been tested?
TestPoseidon2_BN254_Widths: table-driven test covering t=4, 8, 12, 16 with valid witnesses (circuit output matches gnark-crypto native permutation) and invalid witnesses (raw input as expected output is correctly rejected), across both Groth16 and PLONK backendsgo test ./std/permutation/poseidon2/How has this been benchmarked?
Checklist:
golangci-lintdoes not output errors locallyNote
Medium Risk
Touches cryptographic permutation circuit logic and relies on new precomputed constants from an updated
gnark-cryptodependency; mistakes here could silently change hashes/constraints, though the added test coverage reduces regression risk.Overview
Adds circuit-side support for Poseidon2 on BN254 with widths
t=4,8,12,16by introducingParameters.DiagM1, wiring it through parameter construction/defaults, and implementing the previously-missingmatMulInternalInPlacegeneral case fort>=4.Fixes the
matMulExternalInPlacepath for widths4k(correct zero initialization and per-lane indexing), bumpsgithub.com/consensys/gnark-cryptotov0.20.1, and adds targeted tests: BN254 width coverage for Poseidon2 plus a newVectoraliasing test to ensure in-place ops behave correctly.Written by Cursor Bugbot for commit d384984. This will update automatically on new commits. Configure here.