Add comprehensive Poseidon/Poseidon2 support for BN254 and BLS12-381#1663
Merged
jayz22 merged 6 commits intostellar:release/v25-previewfrom Jan 7, 2026
Merged
Add comprehensive Poseidon/Poseidon2 support for BN254 and BLS12-381#1663jayz22 merged 6 commits intostellar:release/v25-previewfrom
jayz22 merged 6 commits intostellar:release/v25-previewfrom
Conversation
- Add poseidon_hash<N>() matching circom implementation
- Add poseidon2_hash<N>() matching noir/barretenberg implementation
- Add Poseidon parameters (MDS, RC) for BN254 t=3, BLS12-381 t=2,3,4
- Add Poseidon2 parameters (MAT_DIAG, RC) for BN254/BLS12-381 t=2,3,4
- Add PoseidonConfig/Poseidon2Config for flexible parameter selection
- Add comprehensive test coverage validated against:
- circomlib (BN254 Poseidon)
- poseidon-bls12381-circom (BLS12-381 Poseidon)
- barretenberg (BN254 Poseidon2)
- Reference Sage scripts for parameter generation
Member
There was a problem hiding this comment.
Reviewing the top-level arrangement of the exported fns and that interface, it looks good, there's just one piece of feedback I mention inline to remove the generics that don't appear to be necessary.
Defer to @sisuresh for a review of the crypto internals.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds comprehensive Poseidon and Poseidon2 hash function support for BN254 and BLS12-381 elliptic curves, providing cryptographic primitives validated against multiple external reference implementations (circomlib, barretenberg, noir, and poseidon-bls12381-circom).
Key Changes:
- Added convenience hash methods
poseidon_hash<N>()andposeidon2_hash<N>()with configurable field types (BN254/BLS12-381) - Introduced
PoseidonConfigandPoseidon2Configstructs to encapsulate hash parameters (rate, capacity, rounds, matrices) - Changed API signatures from
Vec<U256>to fixed-size arrays[U256; N]for improved type safety - Added extensive test coverage with validation against circomlib (Poseidon BN254), poseidon-bls12381-circom (Poseidon BLS12-381), and barretenberg (Poseidon2 BN254)
Reviewed changes
Copilot reviewed 4 out of 6 changed files in this pull request and generated 7 comments.
| File | Description |
|---|---|
| soroban-sdk/src/tests/crypto_poseidon.rs | Reorganized tests into Poseidon and Poseidon2 sections; added comprehensive test cases for both BN254 and BLS12-381 with t=2, t=3, t=4 configurations; updated to use array-based API |
| soroban-sdk/src/crypto/poseidon_sponge.rs | Introduced PoseidonConfig struct; refactored sponge to use configuration-based initialization; updated absorb() to accept Vec instead of single elements; added hash() convenience function |
| soroban-sdk/src/crypto/poseidon2_sponge.rs | Introduced Poseidon2Config struct; parallel refactoring to Poseidon sponge with BLS12-381 support; added hash() convenience function with rate=3 |
| soroban-sdk/src/crypto.rs | Updated public API signatures to use fixed-size arrays and field_type parameter; added documentation linking to reference implementations; exported new Config structs |
teddav
reviewed
Jan 6, 2026
teddav
reviewed
Jan 6, 2026
teddav
reviewed
Jan 6, 2026
teddav
reviewed
Jan 6, 2026
sisuresh
approved these changes
Jan 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR provides comprehensive Poseidon and Poseidon2 hash function implementations for both BN254 and BLS12-381 curves, with extensive parameter coverage and test validation against external reference implementations.
Changes
Convenience Hash Methods
Poseidon Parameters (poseidon_params.rs)
Poseidon2 Parameters (poseidon2_params.rs)
Sponge Implementations
Test Coverage