Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
duyuefeng0708
GitHub Repository: duyuefeng0708/Cryptography-From-First-Principle
Path: blob/main/frontier/10-snarks-starks/README.md
483 views
unlisted

Module 10: SNARKs and STARKs

View on nbviewer

Succinct proofs of computation, from arithmetic circuits to verifiable computation.

Prerequisites

Learning Objectives

After completing this module you will:

  1. Understand arithmetic circuits and how to express computations as Rank 1 Constraint Systems (R1CS)

  2. Construct a Quadratic Arithmetic Program (QAP) from an R1CS instance

  3. Grasp the Groth16 proof system at a conceptual level: setup, prove, verify

  4. Understand the FRI protocol and how STARKs achieve transparency without a trusted setup

  5. Compare the trust assumptions, proof sizes, and verification costs of SNARKs vs STARKs

Explore (SageMath Notebooks)

Work through these notebooks in order:

#NotebookWhat You'll Learn
aArithmetic CircuitsRepresenting computation as addition and multiplication gates over a field
bR1CS ConstraintsFlattening a circuit into A, B, C matrices and checking a witness
cQAP ConstructionInterpolating R1CS into polynomials and the divisibility check
dGroth16 OverviewTrusted setup, proving key, verification key, and the pairing check
eFRI ProtocolFast Reed-Solomon proximity testing via recursive folding
fSTARKs vs SNARKsSide by side comparison of trust model, proof size, and quantum resistance

Implement (Rust)

Build these from scratch in rust/src/lib.rs:

#FunctionDescription
1evaluate_circuitEvaluate an arithmetic circuit on given inputs and return all wire values
2circuit_to_r1csConvert a flat arithmetic circuit into R1CS matrices (A, B, C)
3check_r1cs_witnessVerify that a witness vector satisfies Az * Bz = Cz element-wise
4fri_foldPerform one round of FRI folding on a polynomial evaluation domain

Run: cargo test -p snarks-starks

Break

Try these attacks in the break/ folder:

  • Forge a proof with compromised trusted setup. Given the toxic waste from a Groth16 ceremony, craft a valid proof for a false statement.

  • Demonstrate soundness failure with bad CRS. Show that a malicious setup can produce a Common Reference String that lets anyone prove anything.

Connect

See where this shows up in practice (in the connect/ folder):

  • Groth16 in Zcash shielded transactions. Every shielded spend and output is accompanied by a Groth16 proof of validity.

  • STARKs in StarkNet. StarkNet uses STARK proofs for ZK rollup transaction validity on Ethereum.

  • Recursive SNARKs in Mina. Mina's blockchain stays a constant 22 KB by recursively verifying SNARK proofs of prior state.


Next: Module 11: Homomorphic Encryption