BSV
$53.49
Vol 16.54m
-4.57%
BTC
$95921
Vol 44940.4m
-2.55%
BCH
$437.54
Vol 239.26m
-5.22%
LTC
$102.57
Vol 583.26m
-5.32%
DOGE
$0.31
Vol 2640.02m
-4.77%
Getting your Trinity Audio player ready...

This post was first published on Medium.

Previously, we have proved one knows some mathematical secret using zero knowledge proof (ZKP), without revealing the secret itself. The secret knowledge include:

While useful in their specific applications, these ZKPs cannot be applied to arbitrary mathematical functions. Overcoming these limitations, a zk-SNARK (zero-knowledge Succinct Non-interactive ARguments of Knowledgeis a protocol designed to generate a ZKP for any mathematical function. The generated proof is “succinct” and “non-interactive”: a proof is only a few hundred bytes and can be verified in constant time and within a few milliseconds, without needing to ask additional questions of the prover. Together, these properties make zk-SNARK especially suitable for blockchains, where on-chain storage and computation can be expensive and senders often go offline after sending a transaction. Anonymous cryptocurrency Zcash and the smart-contract platform Ethereum are among its notable early adopters, among others.

zk-SNARK

A zk-SNARK consists of the following three algorithms: G ,P, andV.

https://twitter.com/ChrisLundkvist/status/799807876982251520?s=20&t=-Pa3US30hCFPMskd-MyhiA

Key Generation

A key generator G takes a secret parameter λ and a function C, and produces a proving key pk and a verification key vk. Both keys are made public.

Key Generator
Key Generator

C is a boolean function (also called a program or circuit) that takes two inputs: a public input x and a private input w (aka, witness). For example, C can be a function that checks if w is the sha256 preimage of the digest x.

C(x, w) = sha256(w) == x

Prover

The prover P takes as input the proving key pk, a public input x and a private witness w to produce a proof that the prover knows a witness w that makes C(x, w) evaluates to true.

Prover
Prover

Verifier

The verifier V takes verification key vk, the proof, and the public input x and accepts the proof only if it is produced with the knowledge of witness w¹.

Verifier
Verifier

Implementation

When zk-SNARKs are used in blockchains, both the key and proof generation are executed off-chain. Only the general verification algorithm is run inside a smart contract on chain.

There are multiple schemes of zk-SNARKs in the literature. We implement the most widely used scheme Groth16 due to its small proof size and fast verification.

Verifier in Groth16: page 18
Verifier in Groth16: page 18

The full code is listed below, based on our elliptic curve arithmetic and pairing libraries.

Contract ZKSNARK

It is worth noting that the proof size (Line 23–27) and the number of pairings (Line 43–44) are constant, regardless of how complex the function C being proved is.

Summary

zk-SNARK is a powerful primitive for blockchain privacy and scalability. Today we only showed what zk-SNARK is and how to implement it on Bitcoin. We will explore how to use it in the near future. Why and how it works internally, which is quite math heavy, is beyond the scope of this single article. There are many excellent tutorials such as this series and this paper.

***

NOTE:

[1] There is an exception. Anyone knows the secret parameter λ used in the generator can generate fake yet valid proof without knowledge of witness. That is why it is called toxic waste. It must be discarded after the trusted setup phase.

Watch: The BSV Global Blockchain Convention presentation, Smart Contracts and Computation on BSV

https://www.youtube.com/watch?v=RzSCrXf1Ywc&t=6154s

Recommended for you

SK Telecom ends metaverse offering; Meta launches AI model
South Korea's SK Telecom will end its metaverse platform ifland and focus on AI instead; meanwhile, Meta released "Meta Motivo"...
December 26, 2024
Google unveils ‘Willow’; Bernstein downplays quantum threat to Bitcoin
Google claims that Willow can eliminate common errors associated with quantum computing, while Bernstein analysts noted that Willow’s 105 qubits...
December 18, 2024
Advertisement
Advertisement
Advertisement