Hunting the SNARK … How Do We Prove A Mathematical Computation Without Knowing The Values Used?

Image for post
Image for post

In the future, we need to be much more careful in how we use data and how much personal data we reveal.

Let’s say you want to prove that Alice can produce two numbers which adds up to 8. How does Bob prove that she knows them, without actually knowing the numbers that she picks? This method is the core of zkSNARK (Zero-Knowledge Succinct Non-Interactive Argument of Knowledge) and overcomes the major problem of Blockchain — which is the lack of privacy in computations and transactions. It is used in zCash, and now being considered in a number of application areas around blockchain technology, as they can hide the entities, data and transaction details.

The core element of the method is the usage of HH (Homomorphic Hiding), and which allows us to perform a mathematical operation on encrypted values. For example if we have a value x and a value y, and we want to encrypt them we get:

E(x) and E(y)

Now with homomorphic encryption we can take the encrypted values and multiply them to get the addition:

E(x+y) = E(x) E(y)

We can perform this with discrete logs and where:

E(x+y) = g^{(x+y) mod p-1}

which is equal to:

E(x+y) = g^x g^y

Thus Alice encrypts x at g^x, and y with g^y, and then just multiply the values together to get:


Now if Bob wanted to know if x plus y equals 8, Bob will then encrypt:


and check they are the same. If they are then Alice knows how two numbers which add to 8. Here is the code:

import sys
import random

Here is a sample run here.

Blind evaluation problem

In the blind evaluation problem, we do not want Bob to determine the method we are using to implement a given function, but we want him to know the result with a value of s. Then although we get Alice to compute the result, she will not know s.

For this we use polynomials, and where we have an equation such as:

P(x)= a₀ + a₁ x + a₂ x²

Bob sends all the elements — known as hidings — of the computation for a value of s:

E(a₀), E(a₁ s) and E(a₂ s²)

Alice will not know the value of s used, but she knows the “wiring” of the function. In this case she knows that it is a simple adding operation, so she can compute using Homomorphic encryption:

E(P(s)) = E(a₀) + E(a₁ s) + E(a₂ s²)

She can do this because:


So Alice, who knows a and b, can simply raise the values received to the polynomial factors and multiply and return to Bob. Bob then knows the answer, but Alice doesn’t know the value of s used.

Here is some sample code for an equation of a x + b x²:

import sys
import random

Alice gets sent E1 and E2 and then she adds then (which is a multiplication with discrete logarithms), and sends E3 back. This is the result of E(3x + 4x²) for a value of x = 5. Alice does not know the value of x, and Bob doesn’t know how Alice did the computation.

Here is an example.


Within some blockchain implementations, we cannot hide the identities involved in a transaction and the code the implement. Thus we can tell how many bitcoins that Bob has in his account and all of this transactions. With zkSNARK we can hide the values used within computations on the blockchain.

If you are interested in Homomorphic encryption, try here.

Professor of Cryptography. Serial innovator. Believer in fairness, justice & freedom. EU Citizen. Auld Reekie native. Old World Breaker. New World Creator.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store