Subroutine Logo
Subroutine
← Back to Articles Security Advanced 5 min read

Zero-Knowledge Proofs (zk-SNARKs) & Polynomial Commitments

The math behind Groth16, PLONK, KZG commitments, and elliptic curve bilinear pairings.

Published: 2026-08-09
#Security#Cryptography#Zero Knowledge#zk-SNARKs#Math#Rust

In cryptography, a Zero-Knowledge Proof (ZKP) allows one party (the Prover) to mathematically convince another party (the Verifier) that a statement is true, without revealing any underlying private data beyond the validity of the statement itself.

A zk-SNARK stands for:

  • Zero-Knowledge: No private information is leaked to the verifier.
  • Succinct: Proof sizes are minuscule (e.g. 288 bytes) and verification takes O(1)O(1) constant time (1ms\sim 1\text{ms}).
  • Non-Interactive: The prover generates a single proof payload sent to the verifier without back-and-forth roundtrips.
  • Argument of Knowledge: The prover cannot forge a valid proof without actually possessing the private witness.

1. Summary & Key Takeaways

  • Bilinear Curve Pairings: Verification evaluates e(A,B)=e(C,D)e(A, B) = e(C, D) over pairing-friendly elliptic curves (BLS12-381 or BN254).
  • Arithmetization (R1CS): Programs are compiled into Rank-1 Constraint Systems (AxBx=CxA x \cdot B x = C x).
  • Polynomial Commitments (KZG): Allows committing to a polynomial P(X)P(X) in a single 3232-byte elliptic curve point.

2. Interactive zk-SNARK Prover-Verifier Simulator

Test polynomial root verification without exposing private secret xx:

Zero-Knowledge Proofs (zk-SNARKs) & KZG Commitments

Prove knowledge of secret $x$ such that $P(x) = 0$ without revealing $x$

Zero-Knowledge Privacy
Prover Secret Input ($x$):
Target Polynomial: $P(x) = x^2 - 49$
Prover (Holds Secret)Private Input
Secret Variable $x$:Hidden (7)
Polynomial Root Check:$7^2 - 49 = 0$
Generated Proof $\pi$:Not Generated
Verifier (Public Auditor)Zero Knowledge
Learns Secret $x$?NO (Zero-Knowledge)
Bilinear Pairing Check:e(A, B) == e(C, D)
Verification Result:Awaiting Proof
zk-SNARK Engine Ready: Prover holds secret x. Verifier checks proof without learning x.

3. zk-SNARK Dataflow Architecture

graph TD
    subgraph Dataflow["zk-SNARK Compilation & Verification Pipeline"]
    PROG["Computation / Circuit"] --> R1CS["1. Arithmetization (R1CS)"]
    R1CS --> QAP["2. Quadratic Arithmetic Program (QAP)"]
    QAP --> PROVER["3. Prover (Secret Witness x)"]
    PROVER --> PROOF["4. Succinct Proof (288 bytes)"]
    PROOF --> VERIFIER["5. Verifier: e(A, B) == e(C, D)"]
    VERIFIER --> RESULT["6. Valid (True) / Invalid (False)"]
    end

4. Multi-Language zk Circuit Code Implementation

zk-SNARK Circuit & Verification Code
zk_proof.rs
Rust (arkworks-rs zk-SNARK)
use ark_bls12_381::{Bls12_381, Fr};
use ark_groth16::Groth16;
use ark_snark::SNARK;

pub fn generate_and_verify_zk_proof() {
    let mut rng = ark_std::test_rng();

    // 1. Setup Trusted Setup CRS Parameters
    let (pk, vk) = Groth16::<Bls12_381>::circuit_specific_setup(circuit, &mut rng).unwrap();

    // 2. Prover generates succinct proof without exposing secret 'x'
    let proof = Groth16::<Bls12_381>::prove(&pk, circuit, &mut rng).unwrap();

    // 3. Verifier checks proof in O(1) time using bilinear pairings
    let is_valid = Groth16::<Bls12_381>::verify(&vk, &public_inputs, &proof).unwrap();
    assert!(is_valid);
}

5. Engineering Guidance

  1. Use Cases: Anonymous authentication, privacy-preserving identity (Semaphore/Worldcoin), layer-2 zk-Rollups (Starknet, zkSync, Polygon zkEVM).
  2. Performance: Proving time is computationally heavy (O(NlogN)O(N \log N) FFT multiexponentiation), but verification is blazingly fast (O(1)O(1) constant time).