EIP-5988 Adding a Poseidon hash precompile (Add Poseidon hash function precompile)

No call decision · EVM & execution · EIP status Stagnant · created 2022-11-15

Adds a precompile to the EVM that computes the Poseidon hash function, letting ZK/validity rollups integrate their proofs with the EVM at lower cost.

Why it is needed

ZK rollups must compute hashes inside the proof system used to generate zero-knowledge proofs, but the traditional hashes the EVM natively uses, such as SHA256 or Keccak, are expensive to compute inside that proof system. Poseidon is a hash function built entirely from arithmetic operations over a prime field, designed to be much cheaper to compute inside a proof system. Several rollups and projects, including StarkWare, Polygon, Loopring, and Filecoin, already use Poseidon with different parameter sets, and differing configurations make it hard to unify into a single EVM precompile. This EIP proposes a general-purpose precompile that takes the parameters themselves as input, so that ZK rollups using different configurations can still interact efficiently with the EVM.

What changes

Today

After EIP-5988

Who is affected

In depth

Background and Purpose

Poseidon is an arithmetic hash function built from permutations over a prime field, and it is efficient to compute inside major proof systems such as SNARKs, STARKs, and Bulletproofs. As Ethereum follows a rollup-centric roadmap, L2s need an optimal way to communicate with the EVM, and Poseidon is a candidate for that. However, since each ZK rollup chooses a different parameter set, a single fixed precompile cannot support all of them. This EIP therefore designs a general-purpose precompile that accepts arbitrary parameters, letting each rollup choose the parameters it wants.

Precompile address and undetermined values

The precompile address is fixed as POSEIDON_PRECOMPILE_ADDRESS, 0xA. In contrast, the fork block number (FORK_BLKNUM) at which this precompile is activated and the gas cost (GAS_COST) are left as TBD in the original text and have not yet been finalized.

Input encoding format

The input data is encoded by concatenating the following fields in order: p (the prime field modulus, 32 bytes), security_level (the security level, M in the Poseidon paper, 2 bytes), alpha (the S-box exponent, 1 byte), input_rate (the input size, 2 bytes), t (the state size, 1 byte), full_round (the number of full rounds, R_F in the paper, 1 byte), partial_round (the number of partial rounds, R_P in the paper, 1 byte), and input (the values to be hashed, input_rate*32 bytes long).

Computation logic

The precompile computes the hash function according to the method specified in the Poseidon paper, using the parameters received as input, and returns the hash output. Because the parameters are taken as input rather than fixed, multiple ZK rollups using different configurations can call the same precompile with their own chosen parameters.

Backward compatibility

The risk of breaking existing contracts is minimal. A problem would arise only if someone built a contract assuming address 0xA is empty, which is unlikely, and if such a case does appear, the precompile address can be changed to a different arbitrary value.

Security considerations

Poseidon is a relatively young hash function published in 2019, with a shorter track record of scrutiny than traditional hashes such as SHA256 or Keccak. However, StarkWare, Polygon, Loopring, Filecoin, Dusk Network, Sovrin, and others already use it in production, and no bugs have been reported from it so far. Even if a vulnerability were found, its impact would be limited to the rollups using that hash, following the same risk logic as the KZG ceremony in EIP-4844. The choice of the MDS matrix, which mixes internal state, is particularly important: it must be generated randomly, verified as safe using known algorithms, and regenerated if found unsafe.

Incomplete state

The gas cost (GAS_COST) and fork block number (FORK_BLKNUM) in the spec are still left as TBD, and the Rationale section and the gas cost justification (benchmarks) also remain TODO, so the details have not been finalized. The EIP is currently Stagnant and has not progressed further in this form.

Original EIP · ← EIPs