Skip to content

feat: add bn254 poseidon2 constants and support t=4/8/12/16#783

Merged
yelhousni merged 5 commits intoConsensys:masterfrom
devon1209:feat/poseidon2-bn254
Feb 13, 2026
Merged

feat: add bn254 poseidon2 constants and support t=4/8/12/16#783
yelhousni merged 5 commits intoConsensys:masterfrom
devon1209:feat/poseidon2-bn254

Conversation

@devon1209
Copy link
Copy Markdown
Contributor

@devon1209 devon1209 commented Dec 30, 2025

Description

Summary of changes:

  • add bn254 Poseidon2 constants (round keys + internal diagonal) for t=4/8/12/16 and load them during parameter initialization
  • implement external matrix for t=4k using M4 + block-circulant reduction; implement internal matrix using diagM1 for t>=4
  • expand supported widths and add parameter validation tests (unskip external matrix test)

Motivation and context:

  • enables standard Poseidon2 parameter sets beyond t=2/3 on bn254, matching spec/reference constants and unlocking t=4k permutation widths

Fixes #782

Type of change

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

How has this been tested?

  • go test ./ecc/bn254/fr/poseidon2

How has this been benchmarked?

  • Not run (not requested)

Checklist:

  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • I did not modify files generated from templates
  • golangci-lint does not output errors locally
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Note

Medium Risk
Changes core cryptographic permutation parameters and linear-layer math for new widths, so any constant/matrix mismatch would silently break hash compatibility even though validation panics catch some misconfigurations.

Overview
Adds bn254 Poseidon2 precomputed constant parameter sets for widths t=4/8/12/16 (round keys plus internal matrix diagonal), and updates NewParameters to load these constants (with rf/rp validation) instead of deriving keys from a seed.

Extends the permutation to support t=4k by implementing the external linear layer via M4 chunk multiplication plus a block-circulant reduction, and the internal linear layer via the new DiagM1 diagonal; also tightens constructor validation and restricts NewPermutationWithSeed to t=2,3.

Written by Cursor Bugbot for commit d9f1a04. This will update automatically on new commits. Configure here.

@gbotrel gbotrel requested review from Tabaie and yelhousni January 15, 2026 03:00
yelhousni
yelhousni previously approved these changes Feb 4, 2026
Copy link
Copy Markdown
Collaborator

@yelhousni yelhousni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The implementation correctly follows the Poseidon2 specification and the mathematical constructions are verified. The code is clean and well-tested for the new functionality. Maybe, consider adding full permutation test vectors for the new widths. Other than that good to merge for me 👍

@devon1209
Copy link
Copy Markdown
Contributor Author

I updated the generator templates for the bn254 changes. Could you re-run the workflow?

@yelhousni yelhousni merged commit a3a3ae5 into Consensys:master Feb 13, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enhancement: Expand BN254 Poseidon2 to t=4/8/12/16 for zk‑friendly circuits in gnark

2 participants