This repository contains full, detailed implementations and explanations
for a collection of different ZK proof algorithms
commonly used in MPC (multiparty computation) protocols. Currently, only an example for Schnorr's ZKP is completed, but I will continue to add more as I get the chance.
The Full code tutorials and examples of the different proofs are hosted in their own directories in the src
folder. Each proof repository contains its own README.md
file for you to follow along with. Here you can find detailed explanations
of the underlying algorithms
, the math involved
, important crypto terminology
, and a line by line breakdown of the code
implementation itself. There are also test files in each repository that you can run and execute to understand how to implement these proofs on real data. I recommend you clone this repository, play around with the code, and try to add your own test cases. It will help you gain a better understanding.
to set up on your local machine simply begin by cloning this repo
git clone https://github.com/ChefBingbong/ZK-Proof-tutorials.git
cd into the root directory
cd zk-tutorials/
install the project dependancies
pnpm i
run all tests
pnpm test
Anyone with basic proficiency in Typescript
and basic knowledge of what ZKPs are
can follow this tutorial. However, before we explain how the proof works and break down the code, there are some definitions and background knowledge that are crucial to understanding the implementation.
All zero-knowledge proofs implement arithmetic operations based on some elliptic curve
. Many ZKP algorithms use a series of mathematical operations to both create and generate proofs according to some underlying algorithm. These operations are usually scalar point matrix operations such as multiply
, add
, etc that use linear algebra to do arithmetic on points that lie on the underlying elliptic curve with different scalars involved in the algorithm. A common curve used in Ethereum is the Secp256k1
curve. EVM EOA
addresses are actually just derived from public keys
which are just a point on one of these elliptic curves
. Nearly all operations
in public key cryptography boil down
to different combinations of arithmetic operations of these curve posint coordinates
, wthether it be to store data, or to bind values to some point so that the new point can be used without revealing the underlying data
The good thing is there are only a few different types of arithmetic operations used. The most important ones are:
Jacobian aritemtic
is commonly used to preform multiple aritemtic operations
on Projective or Affine curve points
. The reason jacobian aritemtic is used is because its much more efficent to do point operations
in the jacobian coordinate system compared to the Affine or projective cordinate systems, which points are commonly expressed in:
Jacobian addition is a method used to add two points addition operation
in Jacobian coordinates uses specific formulas derived from the elliptic curve group law
(properties of the crurve). Each curve has different properties. for example most curves have a base generator point
Jacobian multiplication refers to the scalar multiplication Multiplication
is commonly used for efficiently doubleing a point
in Jacobian coordinates. Jacobian multiplication is also commonly used to compute
When performing these arithmetic operations on EC points in a ZKP formula, particularly with curves like secp256k1, we usually operate on the points in different coordinate-system formats (such as the Affine and Projective systems mentioned above), such as affine and projective coordinates.
An affine point Affine points
are commonly used to represent cryptographic keys
(e.g., public keys) and are a standard output format for most cryptographic operations. They are also straightforward to add and subtract but are not efficient for multiplying with scalars. When performing scalar point multiplication, we usually convert from affine to the projective point coordinate system.
A projective point
three coordinates
where $\( (X/Z, Y/Z) \)$
represents the corresponding affine point
. Unlike affine points, projective coordinates allow for efficient point addition and scalar multiplication by exploiting the structure of elliptic curves. Projective points are used internally in many elliptic curve algorithms (e.g., ECDSA, Schnorr) for efficient point operations.
During the different implementations in this repo, you will often see the conversion of things like the prover's public key and secret
from affine coordinates multiply
that are required by the Schnorr SCH Proof.