or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Do you want to remove this version name and description?
Syncing
xxxxxxxxxx
Briefly on zk-SNARKs mathematical foundations
Note:
Hello!
Note:
What they are and how work
Talk about mathematical underpinings, such as…
Introduction
Note:
A lot of great explainers, definitely check them out
Will focus more on key mathematical insights, less on mechanical aspects
Note:
Sure you guys are familiar, so I'll brief with intro here
Will break that down soon, but first what useful for?
Allow us to do many things
Note:
Proving have access to some system w/o revealing who one is
Making digital money fungible
In p2p, one node doing expensive computation, other nodes verify
Where's Waldo?
Note:
A great example for simple intuition to laypeople is "Where's Waldo?". In this illustration prover Peggy want to prove to the verifier Victor that they know where Waldo is, without revealing where he is.
Of course, this is just a toy example to build intuition and doesn't tell us anything about the actual math behind it. We'll dive into that next.
Protocol properties
Note:
As it turns out, even though ZK property seems most magical, and is in some sense,
it falls out naturally from verifiable copmuting / soundness aspect
Why do we use polynomials in zk-SNARKs?
Note:
Probably heard zkSNARKs use polynomials, but why?
Example p, deg 2, more general form
A simple proof
Note:
Naive simple proof to contrast with polynomials
Victor randomly or sequentially check each one, inefficient
Polynomials
Note:
If we change p a tiny bit we get diff solution
Set two polynomials equal to each other get another one
Proof of polynomial
Note:
If Peggy says they know a polynomial…
太陽從西邊出來
Good proof medium
Note:
So polynomials are very easy to work with…
Hopefully contrasting it with naive proof gives some idea for why zksnarks relies on polynomials
Target polynomial
Note:
In a better world Victor wouldn't know p(x) on its own, only Peggy would
Then Peggy would prove it
Because of fundamental theorem of algebra, can factor polynomial into product of linear factors
Can express p(x) as such
Instead of Victor knowing p(x) it'd know target polynomial t(x) which are cofactors in p(x)
Modified example
Note:
In this slightly modifed example
A reason to hide
Note:
In above example Peggy knows \(r\)
This is a problem, Peggy might not know p(x) at all
Instead Peggy can cheat, they can choose random number \(h\) and set polynomial to …
This would pass verification check, despite Peggy not knowing p(x), which breaks soundness
Homomorphic encryption
Note:
Can think of it as hash with math
Encrypt value and apply arithmetic operations on it
Under certain assumptions, we can think of the modulo operation as a form of encryption. Let's see why.
Modulo, where art thou?
Modular arithmetic
Note:
New encryption function
Different values, same result
Note:
Different values will have same result
Hard to figure out what the encrypted value is if order is high enough
Discrete logarithm problem
Note:
This is called the discrete logarithm problem, that essentially says…
In this case we are using this group, the multiplic…
A group is just a set of some elements, integer up to p-1 in this case, and some operation, *,
Since p is a prime it is a cyclic group, and exists g generator that can generate every element in group
Equivalent groups exists for ECC, touch on later
Encrypted operations
Note:
Now we have a way to compute E(x+y) from the encrypted values separately
We'll look at dealing with exponentiated encrypted values next
Can't yet multiply encrypted values, will look at pairings later
This is basic HE, also FHE
Encrypted powers
Note:
Can't exponentiate encrypted values, so we encrypt polynomial by doing each power sep
To know polynomial means knowing coefficient and degree
We encrypt each of these terms, so x 1st degree, x 2nd degree, x 3rd degree, and encrypt these powers
Encrypted powers, cont
\((g^{x^3})^1 \cdot (g^{x^2})^{-3} \cdot (g^x)^2 = g^{1 x^3} \cdot g^{-3 x^2} \cdot g^{2 x} =\)
\(g^{x^3 - 3x^2 +2x}\)
Note:
We have all these encrypted powers, and when you apply encryption function with coefficients and add together
The result is that our polynomial is encrypted at some x
With that, how does that change our proof procedure?
Victor uses encrypted powers
Note:
As before, sample some random value
Encrypt s for each term, each power
Evaluate unencrypted target polynomial with s
Provide these encrypted powers to Peggy
Peggy proves
Note:
Similar to before, calculate arbitrary polynomial h(x)
Using encrypted powers given by Victor, and apply the coefficients for p(x) polynomial
Do same thing for arbitrary polynomial h(s)
Then we provide these p and h values but in encrypted space to Victor
Victor verifies
Note:
Now Victor is checking that p=t(s)*h, i.e. that t(x) is a cofactor of p(x), but doing so in encrypted space
This is progress! Peggy doesn't know s or t(s) but can use encrypted evaluation
But…
Restrict your polynomials
Use random \(r\), set \(h=g^r\) and \(p=(g^{t(s)})^r\)
\(g^p = g^{t(s) \cdot h}\) becomes \((g^{t(s)})^r = g^{t(s) \cdot g^r}\)
Note:
In zk-SNARKs, we can think of coefficients as representing knowledge
But for that to be the case, we have a requirement - we need the proof to be based on the exponentiation of encrypted powers
That is, our polynomial has to be on the right form
If it isn't, Peggy can cheat, breaking soundness
For example…
Polynomial restriction
KEA - basic idea
The assumption in KEA
Choose some random \(c\),
Calculate \(b = (a)^c\), \(b'=(a')^c \mod n\)
Reply with \((b, b')\)
KEA, cont
Peggy now provides \(g^p\), \(g^h\), \(g^{p'}\) to Victor
Sound, not zero knowledge
Can't convince verifier of a wrong statement
Note:
With this, we now have a computationally sound protocol
Can't convince verifier of a false statement
We call it computational because there's a small soundness error, arbitrary small possibility
That Peggy can provide false proof
We can be rigorous about this, quantify it and minimize it, so in practice it isn't something we worry about
Still not ZK - we don't want to leak anything about p(x), let's look at the state of things now
Zero knowledge
Zero knowledge, cont
Non-interactivity
Non-interactivity, cont
\(g^p = (g^h)^{t(s)}\), \((g^p)^{\alpha} = g^{p'}\)
First, briefly on elliptic curve cryptography
(insert comic relief)
Note:
Silence
Waves to you, the reader, who somehow found this tiny little invisible note, greetings!
Here's a treat: https://www.youtube.com/watch?v=dQw4w9WgXcQ
Elliptic curve cryptography
Note:
ECC … smaller keys than RSA, e.g. 256-bit corresponds to 3072-bit RSA, 10x impact on perf, why people use it now
Earlier had multiplicative group of integers modulo some prime, or over some some finite field modulo p more generally
We have a similar DLP problem for elliptic curves over a finite field, sometimes called ECDLP
How to choose these curves and making them pairing friendly and so on is a whole thing on its own
If interested I recommend checking out djb's Daniel Bernstein work on safe curves, as a starting point
Cryptographic pairings
Note:
The G_T group is output group, different space
In our case care about EC over finite field, you can "change place" of exponent and basically multiply them
One sloppy way to read this is just to focus on exponent, so in this case we see ab=ba
e pairing operation efficient
Illustration of pairings
Output target group \(G_T\) is in a different space
(from Dan Boneh's talk on cryptographic pairings)
Note:
Illustrate that output group is in a different space, we can't take output and use as input in another pairing
Basically teleported into a different dimension, and unlike Rick and Morty can't easily go back
Finding pairing friendly curves is a problem here, where we want to balance e being efficient to compute
with DLP being hard in the output group
Intermission: Andrew Weil
to be productive
Note:
Had pen and paper
Pairings in BLS signatures
KeyGen: \(pk=(g_2)^{\alpha}\), \(\alpha\) secret key
Sign(\(sk\), \(m\)): \(\sigma = H(m)^{\alpha}\)
Verify(\(pk\), \(m\), \(\sigma\)): \(e(H(m), pk) = e(\sigma, g_2)\),
both sides equal to \(e(H(m), g_2)^{\alpha}\)
Note:
Very basic and elegant example for pairings
Allows for aggregation, so multiple parties signing results in one signature, used in Eth2
Also very short signatures
…you see in verification that if we substitute pk and sigma, we get alpha as exponent
Recall that we can basically "swap" these, so if sig is valid we get both sides equal to same expression
Pairings, cont
\(e(g^a, g^b) \cdot e(g^c, g^d) = g_2^{ab} \cdot g_2^{cd} = g_2^{ab+cd}\)
Trusted setup
Verification with pairings
Proving key: \((g^{s^i}, g^{\alpha s^i})\), for i in \(0..d\)
Verification key: \((g^{t(s)}, g^{\alpha})\)
Trusted setup ceremony
Note:
We can extend this to trusting 1/M
Very similar tools used to do this, have to do it sequentially where output of one step is used as input to next,
Ensuring that each step is used, some additional checks to make sure no toxic waste is leaked
Called toxic waste because…
Can particpate in these yourself … if you don't trust other people, maybe you trust yourself?
Beyond polynomials
Computation and constraints
Arithmetic circuit
Similar to making a computer with logical gates
(From Ariel Gabizon's Explaining SNARKs series)
Multiple constraints
\(a \times b = r_1\)
\(r_1 \times c = r_2\)
\(2 \times 1 = 2\)
\(2 \times 3 = 6\)
\(6 \times 2 = 12\)
Constraint systems
Operation polynomial
Note:
We want to express constraints as operation polynomial, which is this equation here: ..
where you have a left and right operand polynomial, a binary operation, and output polynomial
At some x=a the corresponding value in constraint represent evaluation of l(x)
and similar for r(x) and o(x)
Finding operand polynomial
1: \(2 \times .. = ..\), 2: \(2 \times .. = ..\), 3: \(6 \times .. = ..\)
\(l(1) = 2\)
\(l(2) = 2\)
\(l(3) = 6\)
Note:
Previously we had numerical example, and we have left operand, op, right operand, and output
We can look at these constraints as rows,
The first row has 2 in left position, 2nd row as 2, and 3rd row 6
We are looking for a polynomial l that represents the left operand at each row
For example, l(1) here is 2 because the first row has value 2 in the left position
If we do this for each row,
This then gives us 3 points, and those are 3 points which polynomial must go through
Polynomial interpolation
Note:
We have some points and we want a polynomial? What do we do? Interpolation!
Want to find equation of this form, basically finding coefficients a,b,c
Recall Fundamental Theorem of Algebra, in this case basic set of eq with some unknowns, and with n+1 points (3) polynomial of at most n (2) degrees exists that expresses
We solve it for a,b,c and get this operand polynomial
In practice, better methods exists like …
Polynomials are flexible
Note:
In practice things are a bit more involved, but mostly mechanical, need to take care of variables, constant etc - basic idea same
Polynomials flexible, can…
Same as we did for left operand polynomial do for right and for output polynomials
Succinctness
Variable polynomials
Ex: \(c_a \cdot a \times c_b \cdot b = c_r \cdot r\); \((a+c) \times b = r\)
Free operations
(From Petkus's "Why and How zk-SNARK Works")
Note:
Here's an illustration of how you get free constants and addition
See L(x) here is composed of 3 curves, for a*la(x) we have l_a polynomial is a at x=1 and 0 at x=2, x=3
This means we can scale it by some constant, eqv for b and c
To do addition, we can take a+c at x=1 curves and add together basically to get L(x)
Hopefully gives some intuition for why constants and additions can be expressed in one constraint
Quadratic arithmetic program
Where did we end up?
Note:
Previously Peggy proved they know a polynomial
Now they instead prove they know result of some computation, and Victor…
Main difference is basically that we have to check a few more polynomials, and add some verification check to variable values and valid operations
Private and public inputs
Conclusion
Note:
We looked at what zk-SNARKs are and why they are useful, and looked at the mathematics underlying them
We looked at polynomials, why they are used in zk-SNARKs and their properties, we looked at how to prove we know a polynomial,
we looked at how to hide information with HE
We looked at how we can use the Knowledge Exponent Assumption to ensure soundness, we looked at how we get zk "for free"
We looked at how to make things non interactive and the shape of a trusted setup
We looked briefly at ECC, why we need cryptographic pairings and how they work
We looked at how to go from computation to constraints to polynomials
We looked at how we achieve succinctness by compressing constraints down into polynomial expressions
…
Hopefully this was interesting to you, if you want to learn more I highly recommend check out Petkus 'why and how zksnarks',
Vitalik's writings and Ariel Gabizon for more details
Thanks!
Note:
Thank you! Any questions?
You can find me here and on Twitter