Photo by Aditya Saxena on Unsplash

The Magic of zkSnarks: From Equation to Verification

--

With a zkSnark — a non-interactive adaptive argument of knowledge — we provide a short proof from a Prover to one or more verifiers that we have specific knowledge of some private data and of a function (f). The proof is fast to prove. So, let me take you through the steps taken to create a zero-knowledge proof with zkSnarks.

To run this tutorial, you need to first install two Node.js programs:

npm install snarkjs
npm install circom

Creating the circuit

The first part of creating a zero-knowledge proof in zkSnarks is to break down the function into logical steps. This involves creating an arithmetic circuit, and which will be made up of basic arithmetic operations of addition, subtraction, multiplication, and division. In this case, we will use an equation of:

d=a²+b

and where a and b are private input values. We then want to prove that we know the result of the equation for inputs of a and b, without actually revealing a, b or d. For example, if a=3 and b=11, the answer will be:

d=3×3+11=20

Our proof would then be that we know that d=20, when a=3 and b=11 (but without giving away these values). First, we will create a circuit from this equation (from a file named…

--

--

Prof Bill Buchanan OBE FRSE
ASecuritySite: When Bob Met Alice

Professor of Cryptography. Serial innovator. Believer in fairness, justice & freedom. Based in Edinburgh. Old World Breaker. New World Creator. Building trust.