Crypto Training

Engineering ZK Prover Pipelines (With a Security Mindset)

A proof is only as sound as the pipeline that produced its circuit, keys and verifier. This post follows a proof from circuit to on-chain verifier, with a publicly disclosed bug at each stage and the build check that would have caught it.

Crypto Training•2026-02-08•10 min read

ZK pipeline illustration

A prover pipeline can fail in two directions. When it cannot prove a true statement, the result is an outage that everyone notices. When its verifier accepts a false statement, nothing looks wrong until funds leave, and that second failure is the subject of this post.

Soundness bugs are also the common case in practice. A 2024 survey of 141 SNARK vulnerabilities placed 99 of them in circuits, and 95 of those were under-constrained logic (Chaliasos et al.). The remaining stages have each produced critical bugs as well, so we go through the pipeline in order and attach a real disclosure to every stage.

flowchart LR SRC["Circuit or guest program"] --> CMP["Compile"] CMP --> ART["Constraint system or ELF"] ART --> SET["Setup"] SET --> PK["Proving key"] SET --> VK["Verifying key"] IN["Inputs"] --> WIT["Witness generation"] ART --> WIT WIT --> PRV["Prove"] PK --> PRV PRV --> REC["Recursion and wrap"] REC --> PROOF["Final proof and public inputs"] VK --> VER["Verifier contract"] PROOF --> VER

A circuit is two programs that must agree#

A circuit source file compiles into two artifacts. One is the witness generator, ordinary code that computes every signal from the inputs. The other is the constraint system, the set of equations the verifier ends up checking. Soundness depends only on the constraints, and tests that run an honest prover exercise only the generator.

Circom makes the split visible in its operators. <== assigns a signal and adds a constraint, while <-- assigns in the witness generator and constrains nothing, which the circom documentation describes as the most common source of buggy circuits. The operator has a legitimate use when a value cannot be written as a quadratic constraint, and circomlib's IsZero shows the pattern of pairing it with constraints that pin the result.

CIRCOM
// from circomlib v2.0.5, circuits/comparators.circom (comments added)
template IsZero() {
    signal input in;
    signal output out;

    signal inv;

    inv <-- in!=0 ? 1/in : 0;   // hint: computed off-circuit, unconstrained by itself

    out <== -in*inv +1;         // constraint 1
    in*out === 0;               // constraint 2: together they force out = (in == 0)
}

Replace the first <== with <-- and drop the last line, and the template still produces correct witnesses and passing tests, while a malicious prover can set out to anything. That is what happened in circomlib's MiMC sponge in 2019. One line read outs[0] = S[nInputs - 1].xL_out; where it needed <==, so the hash output was not tied to its inputs. Tornado Cash used that hash for its Merkle tree, and a forged root would have let an attacker withdraw other users' deposits. Kobi Gurkan found it, and the one-line fix merged on 17 September 2019 (zk-bug-tracker entry).

The check that catches this class is adversarial. Take a valid witness, change one intermediate signal, and confirm that snarkjs wtns check now rejects it. Static tools such as circomspect flag unconstrained assignments, and Picus tries to prove that the outputs are uniquely determined by the inputs.

The verifying key is part of the trusted code#

Groth16 needs a circuit-specific setup, and the verifying key that comes out of it is as security-critical as the verifier contract that embeds it. PLONK-family systems need only a universal setup, which removes one ceremony per circuit from the pipeline.

In snarkjs the first Groth16 step, snarkjs groth16 setup, writes a circuit_0000.zkey that the README marks with the warning "Do not use this zkey in production". The reason is visible in the source, where zkey_new.js writes the G2 generator as both gamma and delta. Phase 2 contributions are what move delta to a secret multiple of the generator.

The FoomCash exploit of February 2026 shows the consequence. Its deployed verifier had gamma equal to delta, both still the generator, which is what a key without any phase 2 contribution contains. Equal values collapse the Groth16 pairing check, so a proof built from the public verifying-key points alone (A = alpha, B = beta, C = -vk_x) verified for any public inputs. The attacker claimed the pool's rewards in a loop for a loss of about $1.3 million.

Two pipeline steps address it. snarkjs zkey verify circuit.r1cs pot_final.ptau circuit_final.zkey checks that the key matches the circuit and verifies the phase 2 contributions recorded in it, and the pipeline should refuse a key that has none. A deploy-time assertion can then compare the constants in the generated verifier against the exported key and fail if gamma and delta are equal.

The transcript is an attack surface#

Non-interactive proofs derive the verifier's challenges by hashing a transcript. If a value the prover controls is left out of that hash, the prover can choose it after seeing the challenge.

Trail of Bits disclosed this class in April 2022 under the name Frozen Heart. Several independent implementations, among them SnarkJS, gnark and Dusk's PlonK, omitted public values from the Fiat-Shamir hash, and proofs could be forged for statements the prover could not satisfy.

The class came back in January 2025. Succinct's SP1 security update reports that Plonky3, the proving library under SP1, batched polynomial evaluation claims with a random coefficient that was sampled before the claims had been absorbed into the challenger.

For a pipeline owner the consequence is dependency management. The proof system is a library with advisories, so its version belongs in the lockfile, in the artifact metadata of every proof, and in whatever feed your team watches for security releases.

This stage is also where the usual advice about determinism needs care. Zero-knowledge provers are randomized on purpose, and a Groth16 prover samples fresh blinding scalars for each proof (Groth, 2016). Two honest runs on the same witness give different bytes, so byte-identical proofs are the wrong reproducibility target. The artifacts that must reproduce are the compiled circuit or guest binary, the keys, and the witness for a given input.

Recursion adds a verifier at each layer#

zkVMs prove a long execution in pieces. SP1's documentation describes core proofs whose size grows with the execution, a compressed proof of constant size produced by recursion, and a final Groth16 or PLONK wrap of roughly 260 or 868 bytes for on-chain verification. Each step is a circuit that verifies the previous step's proofs, and a missing check in any of them breaks the chain.

The same SP1 update discloses one such gap. A flag marking a proof as complete was not asserted in parts of the recursive verifier, including the first recursion layer, which Aligned, LambdaClass and 3MI Labs reported and Succinct had also found.

The base layer can be wrong too. In June 2025 RISC Zero's advisory described a missing constraint in the rv32im circuit of zkVM 2.0.0 to 2.0.2 that let a malicious prover make the machine treat the rs1 operand of any three-register instruction as equal to rs2. Christoph Hochrainer reported it through the bug bounty, and version 2.1.0 fixed it.

The verifier contract binds three things#

An on-chain verification call has to pin the program, the public inputs and the verifier version. Leaving any one of them to the caller turns a valid proof of something else into an accepted proof.

For zkVMs the program is identified by a key or hash derived from the guest binary. SP1's gateway exposes verifyProof(bytes32 programVKey, bytes publicValues, bytes proofBytes) (source), and RISC Zero's verify takes a seal, an image ID and a journal digest (docs). The application must hard-code or govern that identifier, and a third party should be able to rebuild it from source. SP1 documents cargo prove build --docker for a reproducible ELF for that reason.

Public inputs need two checks. The generated verifier has to reject values outside the scalar field, which the snarkjs Groth16 template does in checkField. The application then has to make sure every value it acts on (recipient, amount, nullifier, chain) is a public input that the circuit constrains, since a parameter outside the proof can be changed by whoever relays it.

The verifier version matters because verifiers get retired. Both zkVM teams route calls to a versioned verifier contract by a 4-byte selector carried in the proof. Succinct froze its routes after the January 2025 disclosure, and RISC Zero disabled the 2.0 verifiers through its emergency stop, which a guardian can trigger and which also opens to anyone who submits a proof demonstrating a break (design note).

Calling the router gives your application that kill switch and makes the router's admin part of your trust model. Calling a fixed verifier address removes the admin and leaves you to notice the next advisory yourself. We would take the router for anything that holds funds, and write the admin into the threat model.

Reproducibility and failure bundles#

Auditing a pipeline means being able to rerun it. Content-address every artifact (constraint system or ELF, proving key, verifying key) and record the hashes next to each proof, together with the commit, the compiler and prover versions, and the build flags. For Groth16 keys, keep the ceremony transcript as well.

When proving fails in production, the same record becomes a bundle that someone else can replay. A small interface is enough.

BASH
# interface sketch for your own tooling
prove  --input inputs.json --out proof.bin --bundle bundle.tgz
verify --proof proof.bin --public public.json --vk vk.json
replay --bundle bundle.tgz   # inputs, witness, artifact hashes, versions, logs

Logs should say which stage failed. An unsatisfied constraint in witness generation points at inputs or circuit logic, a prover error with a satisfied witness points at keys or versions, and a rejection by the verifier of a proof the prover accepted points at a key or public-input mismatch between the two sides.

Checklist before trusting a pipeline#

  • Has every <-- or other hint been reviewed against the constraints that pin it, and is there a test that mutates a witness and expects rejection?
  • Can a third party rebuild the constraint system or guest binary and arrive at the verifying key or program identifier that is on chain?
  • For Groth16, does zkey verify pass against the final key, and does the deployed verifier contain that key with gamma different from delta?
  • Are the proof-system libraries pinned, and does someone receive their security advisories?
  • Does the contract fix the program identifier and constrain every value it acts on as a public input?
  • If the proof system is found unsound tomorrow, who can stop verification, and how long does it take?

Background talk#

The recording below, "Using Zero Knowledge Proofs to Scale Ethereum" from the Ethereum Engineering Group, gives the rollup context in which these pipelines carry the most value.

Sources#