Poseidon
1. Why This Chapter Exists
Poseidon is the algebraic hash that drives the nullifier derivation key combinator. It is cheap inside a Halo 2 circuit because every round is a polynomial identity. A contributor who needs to add a Poseidon call (a new PRF, a new transcript-style mixer) must understand the parameter choices for and the sponge construction. After this chapter the reader can predict how many rows a new Poseidon call will cost.
2. Definitions
Definition 2.1 (Poseidon Permutation)
A permutation over a prime field , parameterised by:
- width ;
- S-box exponent such that ;
- full rounds , in which the S-box is applied to every element;
- partial rounds , in which the S-box is applied only to the first element;
- a sequence of round constants and an MDS matrix .
Definition 2.2 (Orchard Parameters)
Orchard uses with , , full rounds, partial rounds, targeting 128-bit security.
Definition 2.3 (Sponge as Hash)
The sponge absorbs field elements per permutation call and squeezes one. Used as a length-2 hash:
Definition 2.4 (Orchard Nullifier PRF)
3. The Code
3.1 The Implementation Crate
Orchard re-exports the upstream
halo2_poseidon crate
under the local alias poseidon:
loading...
3.2 The Parameter Set
P128Pow5T3 (the trait) lives in
halo2_gadgets::poseidon::primitives. It exposes the MDS matrix
and the round-constants table.
3.3 Use Site
The nullifier derivation in
src/note/nullifier.rs
calls the Poseidon sponge with as the first input
and as the second. The output is then combined with the
point , the trapdoor , and
before ; see
Chapter 9.
3.4 Inside the Circuit
halo2_gadgets::poseidon::Pow5Chip is the in-circuit
implementation. Its Config is bundled into the Action circuit
Config.
Each Poseidon permutation costs rounds; a
two-input hash is a single permutation call.
4. Failure Modes
- Parameter drift. Hard-coding or in two places
invites them to drift. Orchard uses a typeclass instead, so
parameter changes propagate. Watch for "magic"
8or56literals in PRs. - Field mismatch. Calling Poseidon with a value that should
be a
pallas::Scalarbut is provided as apallas::Basesilently changes the output. The type signature of the primitive enforces the field; bypassing it viato_baseis a red flag. - Wrong S-box exponent. is a permutation only because . A future field change (a new curve choice) breaks Poseidon if the exponent is not re-derived.
5. Spec Pointers
- Poseidon paper: the security analysis and the round-count formula.
- Zcash Protocol Specification, Section 5.4.1.10: the Orchard parameter choice.
- Halo 2 Book, Poseidon: the rationale for over the Pasta scalar field.
halo2_poseidon: the implementation crate.
6. Exercises
- Compute for the Pallas scalar field modulus from Chapter 3. Show that is therefore a permutation.
- The Poseidon paper gives the minimal that resists linear and algebraic attacks at bits. Look up the formula in Section 5 and apply it to , . Compare with the Orchard choice , .
- Code task. Write a five-line program that runs the
halo2_poseidonsponge over two zero scalars and prints the output. Cross-check with the value embedded in the unit tests ofsrc/note/nullifier.rs.
7. Further Reading
- The
halo2_poseidonsource for the bit-exact constants. - Constant-time Poseidon for a discussion of side-channels in algebraic hashes.