Skip to main content

Algebraic Structures

Finite fields

An AO hash function operates over a prime field Fp=Z/pZ\mathbb{F}_p = \mathbb{Z}/p\mathbb{Z}. All arithmetic (addition, multiplication, inversion) is modulo a large prime pp, 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):

FieldPrime ppBits2-adicity
BN254 scalar218882428718392752222464057452572750885483644004160343436982041865758084956172188824287183927522224640574525727508854836440041603434369820418657580849561725428
BLS12-381 scalar524358751751261904794477405081859658376905525005276378226036586999385811845135243587517512619047944774050818596583769055250052763782260365869993858118451325532

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:

FieldPrime ppFormBits2-adicityNotes
Mersenne-3123112^{31} - 1Mersenne311Reduction is a single addition; no NTT (2-adicity too low)
BabyBear231227+12^{31} - 2^{27} + 1Pseudo-Mersenne3127Highest 2-adicity among 31-bit primes
KoalaBear231224+12^{31} - 2^{24} + 1Pseudo-Mersenne3124Cube map xx3x \mapsto x^3 is an automorphism
Goldilocks264232+12^{64} - 2^{32} + 1Pseudo-Mersenne6432Fits in a single 64-bit word; fast reduction

The 2-adicity of a prime pp is the largest kk such that 2kp12^k \mid p - 1. It determines the maximum NTT size: the field supports NTTs of length up to 2k2^k. This is critical for FRI-based proof systems where the prover evaluates polynomials over multiplicative subgroups of order 2k2^k.

Plonky3 also defines extension fields over these base fields to increase the security level while keeping base-field arithmetic cheap:

Base fieldExtension degreeIrreducible polynomialExtension order
BabyBear4x411x^4 - 11p42124p^4 \approx 2^{124}
BabyBear5x52x^5 - 2p52155p^5 \approx 2^{155}
KoalaBear4x43x^4 - 3p42124p^4 \approx 2^{124}
Goldilocks2x27x^2 - 7p22128p^2 \approx 2^{128}
Mersenne-313x35x^3 - 5p3293p^3 \approx 2^{93}

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 Fp\mathbb{F}_p.

Power map S-box

The most common choice: S(x)=xαS(x) = x^{\alpha} where α\alpha is chosen so that gcd(α,p1)=1\gcd(\alpha, p - 1) = 1 (ensuring the map is a permutation).

Common values of α\alpha:

α\alphaUsed by
3Poseidon (some instances)
5Poseidon, Poseidon2, Neptune
7Poseidon (some instances)
1-1 (i.e. xp2x^{p-2})Rescue (inverse map)

The algebraic degree of xαx^{\alpha} is α\alpha, and the algebraic degree of its inverse x1/αx^{1/\alpha} is 1/αmod(p1)1/\alpha \mod (p-1), 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 MM over Fp\mathbb{F}_p is used as the linear layer. An t×tt \times t 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 MM.

MDS matrices are typically constructed as:

  • Cauchy matrices: Mi,j=1/(xiyj)M_{i,j} = 1/(x_i - y_j) for distinct elements xi,yjFpx_i, y_j \in \mathbb{F}_p
  • 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 π\pi.

The state is split into:

  • Rate rr: absorbs input and squeezes output
  • Capacity cc: provides security; never directly exposed

The security level is min(2c/2,2r)\min(2^{c/2}, 2^r) for collision resistance and min(2c,2r)\min(2^c, 2^r) for preimage resistance.

For AO hash functions, the state width is measured in field elements, not bits. A state of tt elements over Fp\mathbb{F}_p has tlog2pt \cdot \lceil \log_2 p \rceil bits.