Skip to content

impl poseidon2 with plonky3 - #9

Merged
lighter-zz merged 26 commits into
devfrom
zz/impl_poseidon2_with_plonky3
Dec 11, 2025
Merged

impl poseidon2 with plonky3#9
lighter-zz merged 26 commits into
devfrom
zz/impl_poseidon2_with_plonky3

Conversation

@lighter-zz

@lighter-zz lighter-zz commented Nov 11, 2025

Copy link
Copy Markdown
Contributor

Summary

This PR implements Poseidon2 hash function in Plonky2, adapted from the zklighter-perps-circuits-plonky repository with additional hand-optimizations.

It is split into two PRs: this one #9 and a follow up one #10. For the ease of reviewing.

  • impl poseidon2 with plonky3 #9 (this one) enables poseidon2 for plonky2. The poseidon2 source code was copy-pasted from "zklighter-perps-circuits-plonky" with minimal changes to make the code compile. The hope is that the review can be focused on the rest of the code.
  • optimize poseidon2 #10 contains actual improvement on poseidon2 itself.

Key Features

  • Hand-optimized Poseidon2 implementation for GoldilocksField
  • Recursion support for Poseidon2

Performance (single permutation, GoldilocksField, width=12)

  • Original Poseidon: 529.97 ns (baseline)
  • Optimized Poseidon2 (this PR): 492.63 ns (~7% faster than Poseidon)
  • Plonky3's Poseidon2: 635.02 ns (~20% slower)
  • Lighter's Poseidon2: 879.34 ns (~66% slower)

Notes

Poseidon2 implementation will be removed from zklighter-perps-circuits-plonky https://github.com/elliottech/zklighter-perps-circuits-plonky/pull/379

Misc

Replace #8

Reason: #8 uses poseidon2 from horizon labs. this PR uses zklighter-perps-circuits-plonky's version

@lighter-zz lighter-zz mentioned this pull request Nov 11, 2025
@lighter-zz lighter-zz changed the title Zz/impl poseidon2 with plonky3 impl poseidon2 with plonky3 Nov 11, 2025
@lighter-zz
lighter-zz marked this pull request as ready for review November 12, 2025 21:57
@lighter-zz lighter-zz mentioned this pull request Nov 13, 2025
@lighter-zz lighter-zz linked an issue Nov 15, 2025 that may be closed by this pull request
Comment thread plonky2/Cargo.toml
Comment thread field/src/goldilocks_field.rs
Comment thread field/src/lib.rs
Comment thread plonky2/src/hash/poseidon2/gate.rs
Comment thread plonky2/src/hash/poseidon2/pure.rs Outdated
* optimize poseidon2

* Merge branch 'zz/impl_poseidon2_with_plonky3' into zz/optimize_poseidon2

* finally faster than poseidon

* clean up

* update num_constants for poseidon

* reverting add_canonical_u64

* Update hash.rs

* Update hash.rs
@lighter-zz
lighter-zz merged commit e8a2283 into dev Dec 11, 2025
3 checks passed
@lighter-zz
lighter-zz deleted the zz/impl_poseidon2_with_plonky3 branch December 11, 2025 19:29
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.

implement Poseidon2

2 participants