Commit 984f63e
authored
Add comprehensive Poseidon/Poseidon2 support for BN254 and BLS12-381 (#1663)
## 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
- Added poseidon_hash<N>() - matches
https://github.com/iden3/circomlib/blob/35e54ea21da3e8762557234298dbb553c175ea8d/circuits/poseidon.circom
- Added poseidon2_hash<N>() - matches
https://github.com/noir-lang/noir/blob/abfee1f54b20984172ba23482f4af160395cfba5/noir_stdlib/src/hash/poseidon2.nr
### Poseidon Parameters (poseidon_params.rs)
- BN254: MDS matrix and round constants for t=2, t=3, t=4 (validated
against circomlib)
- BLS12-381: MDS matrix and round constants for t=2, t=3, t=4 (validated
against reference Sage script and
[poseidon-bls12381-circom](https://github.com/jmagan/poseidon-bls12381-circom))
### Poseidon2 Parameters (poseidon2_params.rs)
- BN254: Diagonal matrix (MAT_DIAG) and round constants for t=2, t=3,
t=4
- BLS12-381: Diagonal matrix and round constants for t=2, t=3, t=4
- Parameters generated using reference Sage script and validated against
reference test vectors (generated by the script)
### Sponge Implementations
- PoseidonSponge and Poseidon2Sponge with configurable parameters via
PoseidonConfig and Poseidon2Config
- Proper capacity/rate handling matching reference implementations
### Test Coverage
- Poseidon (BN254) - hash_n validated against circomlib
- Poseidon (BLS12-381) - hash_n validated against
poseidon-bls12381-circom
- Poseidon2 (BN254) - hash validated against barretenberg, permutation
validated against reference test vectors
- Poseidon2 (BLS12-381) - permutation validated against reference test
vectors1 parent b3de265 commit 984f63e
File tree
6 files changed
+16031
-868
lines changed- soroban-sdk/src
- crypto
- tests
6 files changed
+16031
-868
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
18 | | - | |
| 17 | + | |
| 18 | + | |
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| |||
199 | 199 | | |
200 | 200 | | |
201 | 201 | | |
202 | | - | |
203 | | - | |
204 | | - | |
205 | | - | |
206 | | - | |
207 | | - | |
208 | | - | |
209 | | - | |
210 | | - | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
211 | 223 | | |
212 | 224 | | |
213 | | - | |
214 | | - | |
215 | | - | |
216 | | - | |
217 | | - | |
218 | | - | |
219 | | - | |
220 | | - | |
221 | | - | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
222 | 241 | | |
223 | 242 | | |
224 | 243 | | |
| |||
0 commit comments