Algebraic Structures
Finite fields
An AO hash function operates over a prime field . All arithmetic (addition, multiplication, inversion) is modulo a large prime , typically the scalar field of an elliptic curve used in a proof system.
Common choices:
Elliptic curve scalar fields
These fields arise as the scalar fields of pairing-friendly elliptic curves used in SNARK proof systems (Groth16, PLONK with KZG):
| Field | Prime | Bits | 2-adicity |
|---|---|---|---|
| BN254 scalar | 254 | 28 | |
| BLS12-381 scalar | 255 | 32 |
STARK-friendly fields
Modern STARK provers (in particular Plonky3) use small primes with fast modular reduction and high 2-adicity, enabling efficient NTT-based polynomial arithmetic and SIMD vectorisation:
| Field | Prime | Form | Bits | 2-adicity | Notes |
|---|---|---|---|---|---|
| Mersenne-31 | Mersenne | 31 | 1 | Reduction is a single addition; no NTT (2-adicity too low) | |
| BabyBear | Pseudo-Mersenne | 31 | 27 | Highest 2-adicity among 31-bit primes | |
| KoalaBear | Pseudo-Mersenne | 31 | 24 | Cube map is an automorphism | |
| Goldilocks | Pseudo-Mersenne | 64 | 32 | Fits in a single 64-bit word; fast reduction |
The 2-adicity of a prime is the largest such that . It determines the maximum NTT size: the field supports NTTs of length up to . This is critical for FRI-based proof systems where the prover evaluates polynomials over multiplicative subgroups of order .
Plonky3 also defines extension fields over these base fields to increase the security level while keeping base-field arithmetic cheap:
| Base field | Extension degree | Irreducible polynomial | Extension order |
|---|---|---|---|
| BabyBear | 4 | ||
| BabyBear | 5 | ||
| KoalaBear | 4 | ||
| Goldilocks | 2 | ||
| Mersenne-31 | 3 |
The prover performs most work over the base field (cheap, SIMD-friendly), and only uses the extension field for the verifier's random challenges where 128-bit security is needed.
S-boxes
The S-box (substitution box) is the nonlinear component of an AO hash function. Unlike AES which uses lookup tables, AO S-boxes are defined by algebraic expressions over .
Power map S-box
The most common choice: where is chosen so that (ensuring the map is a permutation).
Common values of :
| Used by | |
|---|---|
| 3 | Poseidon (some instances) |
| 5 | Poseidon, Poseidon2, Neptune |
| 7 | Poseidon (some instances) |
| (i.e. ) | Rescue (inverse map) |
The algebraic degree of is , and the algebraic degree of its inverse is , which is typically very large. This asymmetry is exploited by Rescue.
Flystel S-box (Anemoi)
Anemoi uses the open Flystel construction, a 2-to-2 map built from the power map. See the Anemoi page for details.
MDS matrices
A Maximum Distance Separable (MDS) matrix over is used as the linear layer. An MDS matrix has the property that every square submatrix is invertible. This ensures full diffusion: every output element depends on every input element after one application of .
MDS matrices are typically constructed as:
- Cauchy matrices: for distinct elements
- Circulant matrices: defined by a single row, used in Poseidon2
- Vandermonde-based: used in some Rescue variants
Sponge construction
Most AO hash functions use the sponge construction to build a variable-input-length hash from a fixed-width permutation .
The state is split into:
- Rate : absorbs input and squeezes output
- Capacity : provides security; never directly exposed
The security level is for collision resistance and for preimage resistance.
For AO hash functions, the state width is measured in field elements, not bits. A state of elements over has bits.