DEV Community

이준범
이준범

Posted on

Key insights from implementing zk-SNARK from scratch

I recently took on the challenge of implementing a zk-SNARK — not just studying the theory, but writing the full end-to-end code myself.

Going through the full flow — from R1CS to QAP, trusted setup, and pairing-based verification — helped me understand how all the pieces fit together in a much clearer way.

Here are the key insights I gained through that process:

1️⃣ Break down the logic you want to prove into multiple constraints
For example, the equation (x + 1) * (x + 2) = 12 can be broken into: Let a = x + 1, b = x + 2, then enforce a * b = 12.

2️⃣ Combine all constraints into a single polynomial and check it at one point
Each constraint is turned into a polynomial, and they’re all combined into a single equation. Instead of checking every constraint one by one, you only need to check that this combined equation equals zero at a single random point.

3️⃣ Verify computations without revealing actual values — by committing them on the curve
To prove 1 + 2 = 3 without revealing any values, you commit to g¹, g², and g³, and verify that g¹ * g² = g³ (i.e., g^(1+2) = g^3) using a pairing check.

I wrote a post summarizing the full implementation process for anyone trying to understand zk-SNARKs not just conceptually, but also through actual working code

📄 Documentation: https://0xshardlab.substack.com/p/zk-snarks-understand-it-then-build
💻 Implementation: https://github.com/shard-lab/protocol-camp/tree/main/zk/zksnark

Top comments (0)