Back to Articles

Zero-Knowledge Proofs (ZKPs) Explained: How zk-SNARKs and zk-STARKs Prove Truth Without Revealing Secrets

Zero-Knowledge Proofs (ZKPs) Explained: How zk-SNARKs and zk-STARKs Prove Truth Without Revealing Secrets
Photo from Sendly Team / Unsplash

In conventional computing, proving that you know a secret or that a complex computation was executed faithfully requires revealing either the secret itself or the full trace of intermediate state transitions. Zero-Knowledge Proofs (ZKPs) shatter this paradigm: they allow a prover to mathematically convince a verifier that a statement is true without disclosing any underlying information beyond the validity of the statement itself.

Originally formulated in 1985 by Shafi Goldwasser, Silvio Micali, and Charles Rackoff, zero-knowledge proofs have transitioned from theoretical cryptographic curiosities into the foundational architecture powering decentralized identity, privacy-preserving rollups, verifiable cloud offloading, and trustless cross-chain state synchronization.

The Three Inviolable Properties of Zero-Knowledge Proofs

To qualify as a zero-knowledge proof system, a cryptographic protocol must satisfy three non-negotiable mathematical properties:

  • Completeness: If the statement is true and both the prover and verifier follow the protocol honestly, the verifier will always accept the proof with probability 1 (or negligible error).
  • Soundness: If the statement is false, no cheating prover can convince an honest verifier that it is true, except with an infinitesimally small probability (the soundness error, typically bounded by (2^{-128})).
  • Zero-Knowledge: If the statement is true, the verifier learns nothing from the proof except that the statement is true. Mathematically, this is formalized by the existence of a probabilistic polynomial-time simulator that can generate a transcript indistinguishable from a real proof interaction without having access to the secret witness.

Arithmetic Circuits: Translating Code into Equations

Computers do not execute abstract mathematical theorems directly; they execute machine instructions, loops, and conditional branching. To prove arbitrary computation, the code must first be transformed into a format that algebraic geometry and polynomial systems can reason about: an arithmetic circuit.


+-------------------------------------------------------------+
|               HOW COMPUTATION BECOMES A ZKP                 |
+-------------------------------------------------------------+

 1. High-Level Code (Rust / Circom / Cairo)
    fn verify_secret(x, w) { assert(hash(w) == x); }
                          │
                          ▼
 2. Arithmetic Circuit (Addition & Multiplication Gates over Finite Field)
    Gate 1: t1 = w * w
    Gate 2: out = t1 * c
                          │
                          ▼
 3. Rank-1 Constraint System (R1CS)
    (A · s) * (B · s) - (C · s) = 0
                          │
                          ▼
 4. Quadratic Arithmetic Program (QAP)
    Interpolate vectors into polynomials A(x), B(x), C(x)
    Check divisibility by Target Polynomial T(x):
    A(x) * B(x) - C(x) = H(x) * T(x)
                          │
                          ▼
 5. Polynomial Commitment Scheme (KZG / IPA / FRI)
    Succinct proof generation (Proof size: ~200 bytes to 100 KB)

Every computation can be unrolled into a DAG of gates over a finite field (mathbb{F}_p). Once flattened into a Rank-1 Constraint System (R1CS), constraints are expressed in the form ((A cdot s) imes (B cdot s) = (C cdot s)), where (s) is the vector containing the public inputs and the private witness. Lagrange interpolation then converts these discrete constraints into a single polynomial divisibility check, known as a Quadratic Arithmetic Program (QAP).

zk-SNARKs vs zk-STARKs: The Architectural Showdown

Modern zero-knowledge systems are dominated by two major architectural families: zk-SNARKs (Zero-Knowledge Succinct Non-Interactive Arguments of Knowledge) and zk-STARKs (Zero-Knowledge Scalable Transparent Arguments of Knowledge). Each makes fundamentally different engineering trade-offs:

Feature zk-SNARKs (e.g., Groth16, PLONK) zk-STARKs (e.g., Cairo, Starknet)
Trusted Setup Ceremony Requires ceremony (Groth16 per-circuit; PLONK universal SRS) Transparent: No trusted setup required (uses public randomness)
Cryptographic Assumptions Elliptic curve pairings, discrete logarithms Collision-resistant cryptographic hashes (SHA-256 / Keccak / Poseidon)
Post-Quantum Resistance Vulnerable to Shor's algorithm on quantum computers Quantum-resistant (based strictly on symmetric hash security)
Proof Size Extremely tiny: ~130 to 800 bytes Larger: ~40 to 150 Kilobytes
Verification Cost Constant time (O(1)), cheap on Ethereum L1 (~200k gas) Polylogarithmic (O(log^2 N)), higher on-chain gas costs
Prover Scaling Heavy memory consumption during multi-scalar multiplication (MSM) Quasilinear (O(N log N)) via Fast Reed-Solomon Interactive Oracle (FRI)

The Core Trade-off: SNARKs prioritize tiny proof sizes and instant verification at the cost of trusted setups and quantum vulnerability. STARKs eliminate trusted setups and quantum risk via transparent hash-based math, but generate proofs that are two orders of magnitude larger.

Circom Circuit: Proving Knowledge of a Secret Preimage

Below is a production-grade Circom circuit demonstrating how a prover proves they know the private preimage secret to a public hash without revealing the secret value:


pragma circom 2.1.6;

include "node_modules/circomlib/circuits/poseidon.circom";

// Verifies that Poseidon(secret) == publicHash without revealing secret
template PreimageVerifier() {
    // 1. Private input: The witness kept secret by the prover
    signal input secret;

    // 2. Public input: Known to both prover and verifier
    signal input publicHash;

    // 3. Instantiate Poseidon hash primitive (algebraic SNARK-friendly hash)
    component hasher = Poseidon(1);
    hasher.inputs[0] <== secret;

    // 4. Enforce strict constraint: calculated hash must equal declared public hash
    hasher.out === publicHash;
}

component main {public [publicHash]} = PreimageVerifier();

Real-World Systems Applications

  1. zk-Rollups (L2 Scaling): Instead of re-executing thousands of decentralized transactions, execution happens off-chain in parallel. The sequencer generates a single STARK/SNARK proof demonstrating valid state progression, which the L1 smart contract verifies in milliseconds.
  2. Verifiable Cloud Computing: Heavy database queries and ML model inferences can run on untrusted commodity cloud nodes. The worker returns the result alongside a ZK proof of correct execution, preventing silent bit-rot, rogue cloud providers, or data tampering.
  3. Selective Credential Disclosure: Users can prove they are over 21, possess a valid passport, or maintain a credit score over 750 without revealing their birth date, passport number, or financial balances.

Frequently Asked Questions

What is a "Trusted Setup" in zk-SNARKs?

A trusted setup generates the structured reference string (SRS) needed to construct and verify proofs. It involves "toxic waste" numbers that must be permanently discarded. If the parties running the ceremony collude and preserve this secret entropy, they can forge fraudulent proofs indistinguishable from legitimate proofs, although they still cannot steal private keys.

Why do zk-STARKs use Poseidon instead of SHA-256?

Standard cryptographic hashes like SHA-256 and MD5 rely heavily on bitwise XORs, bit rotations, and S-boxes that are computationally cheap on silicon CPUs but translate into millions of non-linear constraints in finite-field arithmetic circuits. Poseidon is an algebraic hash designed specifically over native prime fields, reducing the required circuit constraints by over 95%.

Can ZK proofs hide data from the prover itself?

No. The prover must possess the full unencrypted witness to evaluate the arithmetic circuit and generate polynomial commitments. Zero-knowledge guarantees secrecy exclusively with respect to the verifier and any third-party network eavesdroppers.

PREVIOUS ARTICLE
CPU Microarchitectural Attacks: How Speculative Execution and Cache Timing Leak Kernel Secrets

Software security models rest on an inviolable hardware guarantee: user-space applications cannot read memory belonging to the operating system kernel or other ...

NEXT ARTICLE
Virtual Memory and Paging Internals: How MMUs, Multi-Level Page Tables, and TLBs Power Operating Systems

Every user-space program running on modern operating systems operates under a master illusion: it believes it has exclusive access to a flat, unbroken, continuo...