What is this?
-
ZK-SNARKs stands for Zero-Knowledge Succinct Non-Interactive Argument of Knowledges.
-
Nowadays, we often hear this word when mentioning zk-rollups. But it is actually a Privacy-enhancing technology, and has a lot of applications that we will delve into in another post.
Decomposition
- ZK aka Zero-Knowledge mean:
- Prove possession of certain information.
- Without revealing that information.
- For Example:
- Given the hash of a random number.
- The prover could convince the verifier that a number with this hash value exists without revealing what it is.
- Succinct:
- Can be verified within a few milliseconds.
- no matter how long the statement is.
- Non-interactive:
- In the first version of ZK, the prover and verifier had to communicate repeatedly for multiple rounds.
- Now, by implementing this characteristic, the proof consists of a single message sent from the prover to the verifier.
Implementation by Example
Example 1: Function C
- You have a program denoted
C
. - C have 2 input
C(x,w)
:x
is the public stuff, that can be shared with anyone.w
is the secret witness.
- The condition
C(x,w)===true
, means "Prover actually knows a secret witnessw
satisfied a statement related tox
". - As a prover, how can we prove that we know
w
, without sendingw
to the verifier to check with the statements? - Can map this example to the example of the hash function of the previous part. Let's do it, and go to the next example.
Example 2: Bob, Alice, and Hash
- Bob is given a hash
H
. - Alice is given the original string
S
satisfied the condition when hashingS
by a hash function such asSHA
,H
is issued (akaSHA(S) === H
). - How can Alice prove to Bob know that she knows the
S
? - Normally
- Alice needs to send
S
to Bob. - Bob needs to hash again to check
SHA(S) === H
.
- Alice needs to send
- But in this case,
S
is a secret witness, and must not send to any locations, how can Alice prove this statement to Bob?- Solution:
- Alice need a proof to send to Bob.
- This proof can prove
SHA(S)===H
is true. Mapping to programC
, with publicx
asH
and privatew
asS
, in other words, when this proof provesC(x,w)===true
, it means Bob can confirm that Alice knows thisw
akaS
satisfiedSHA(S)===H
without knowledge aboutS
. - Example of
C
:function C(x, w) { return ( sha256(w) == x );}
- Note that
C(x,w)===true
is proved by theproof
, not by itself. How can?
- Solution:
Example 3: Implementation of zk-SNARKs in simple words
-
AÂ ZK-SNARKÂ consists of three functions
G, P, V
 defined as follows:-
Key generator aka
G
G(lambda, C) = pk,vk
lambda
: secret parameter. Noted this.C
: a program that proves thatprover
knowsw
byC(x,w)=true
. Aka aboveC
in Example 1 and Example 2.pk
: proving keyvk
: verification key
pk
andvk
are public parameters that only need to be generated once for a given programÂC
.- Can assume that:
- From
pk
, we can create aproof
that can be verified by usingvk
in a pre-defined way.
- From
-
Prover function aka
P
P(pk,x,w) = prf
pk
: proving key issued fromG
x
: public inputw
: private witnessprf
: proof proves that prover knowsw
satisfy programC
.
-
Verifier function aka
V
V(vk,x,prf)=true/false
vk
: verification key generated fromG
x
: public inputprf
: proof generated fromP
-
-
By above functions,
V(vk,x,prf)=true
means:- With the proof
prf
generated depends on a logic that includesx
,w
andpk
. - And
pk
is a pair withvk
so they are closely related to each other. - So when having
vk
,x
,prf
, by a pre-defined way, we can confirm thatC(x,w)===true
.
- With the proof
-
Note that
lambda
can cause security issues when used in real work- Reason: anyone who knows
lambda
can generate fake proofs - Example:
- From any
C
, and knownlambda
, can find a pairf_pk
andf_vk
- From
f_pk
, malicious actor can generate afake_prf
that representsC(x,w)==true
when checking withf_vk
.
- From any
- Solution: multi-party-ceremonies for Trusted Setup -> To build
lambda
.
- Reason: anyone who knows
-
Resolve the Example 2:
-
Bob uses
G
to generate key, sendpk
to Alice -
Alice gen
prf
-> Sent to Bob -
Bob verifies using
vk
-
Issue: Bob can't be a prover because he holds the
Lambda
.- A trusted independent group separate from Alice and Bob could run the generator and create the proving key pk and verification key vk in such a way that no one learns about lambda.
-
Example 4: In Ethereum zk-rollups
- Can add the building blocks of the verification algorithm to Ethereum in the form of precompiled contracts.