├── .gitignore
├── Plonk
├── .DS_Store
├── lesson 6
│ ├── image.png
│ ├── README.md
│ ├── util.py
│ ├── bls12381.py
│ ├── pairing.py
│ ├── fft.py
│ ├── poly_commit.py
│ └── poly_utils.py
├── lesson 7
│ └── Plonk.pdf
├── co-learn-notes
│ ├── Kyrin(demo)
│ │ └── template.md
│ ├── .DS_Store
│ └── co-learn-notes_MartinYeung5.md
├── lesson 5
│ ├── img
│ │ └── circuit.png
│ └── PLONK - Lecture 5 - 算术约束与拷贝约束.pdf
├── lesson 1
│ └── whyplonk 2024-05-28.pdf
├── co-learn notes
│ └── Eta
│ │ ├── images
│ │ ├── 28_ring.png
│ │ └── 29_plonkish.png
│ │ ├── 02_Lagrange.md
│ │ ├── 01_R1CS_Plonklish.md
│ │ ├── 03_Permutation.md
│ │ ├── 04_Copy_Constraints_Optimization.md
│ │ └── 05_Polynomial_Commitments.md
├── lesson 8
│ └── plookup and custom gates.pdf
└── README.md
├── FRI&Stark
├── .DS_Store
├── stark101
│ ├── imgs
│ │ ├── 1.png
│ │ ├── 2.png
│ │ └── 3.png
│ └── stark101_arithmetization.md
├── assets
│ └── SN-Linear-Flat colour.png
├── lesson 1
│ └── FRI overview 2024-08-13 19-54-37.pdf
├── co-learn-notes
│ └── STARK 101 note by neuroney.md
├── README.md
└── part2 lesson4
│ └── 2024-09-05-STARK.md
├── lattice
├── slides
│ ├── NTT.pdf
│ ├── Lattice-1.pdf
│ ├── Lattice-2.pdf
│ ├── Lattice-3.pdf
│ ├── 8.LaBRADOR.pdf
│ ├── 9.Greyhound.pdf
│ ├── 6.Building_SNARKs.pdf
│ └── 7.Realizing_PCS.pdf
├── assets
│ └── KEF-LND-BLK.png
├── co-learn-notes
│ ├── SIS lattice and bkz.pdf
│ ├── 01-Kurt Pan-Lattice-Overview-lecture-note.txt
│ ├── 04-Bing-NTT-note-by-MT.txt
│ ├── 02-Yingfei-What is Lattice & average-case and worst-case hard problems-note.txt
│ ├── 05-Yingfei-Ajtai Commitment and Lyubashevsky Signature Proofs-note-by MT.txt
│ ├── 06.Building_SNARKs-note-by MT.txt
│ ├── 03-Discrete Gaussians, Rejection Sampling, Rings and Modules-note-by-MT.txt
│ ├── master-problem-underlying-all-cryptography.md
│ ├── 06-Building_SNARKs-note.md
│ ├── 09.Greyhound-note-by MT.md
│ ├── 07.Realizing_PCS-note-by MT.md
│ ├── 10.Lattice ZKP Implementation Lantern, Lattirust and Labrador & Greyhound PoC-note-by MT.md
│ └── 08.LaBRADOR-note-by MT.md
└── README.md
├── ZKVM
├── co-learn-notes
│ └── .DS_Store
├── lesson 1
│ ├── zkvm-wangyao.pdf
│ └── Add instruction in SP1.md
├── lesson 4
│ └── Introduce the zkVM.pdf
├── lesson 7
│ └── ZKM Prover基本构造课程.pptx
├── assets
│ └── ZKM Logo Horizontal Black-1.png
└── README.md
├── README.md
└── LICENSE
/.gitignore:
--------------------------------------------------------------------------------
1 | .vscode
2 | __pycache__
--------------------------------------------------------------------------------
/Plonk/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coset-io/zkp-academy/main/Plonk/.DS_Store
--------------------------------------------------------------------------------
/FRI&Stark/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coset-io/zkp-academy/main/FRI&Stark/.DS_Store
--------------------------------------------------------------------------------
/lattice/slides/NTT.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coset-io/zkp-academy/main/lattice/slides/NTT.pdf
--------------------------------------------------------------------------------
/Plonk/lesson 6/image.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coset-io/zkp-academy/main/Plonk/lesson 6/image.png
--------------------------------------------------------------------------------
/Plonk/lesson 7/Plonk.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coset-io/zkp-academy/main/Plonk/lesson 7/Plonk.pdf
--------------------------------------------------------------------------------
/Plonk/co-learn-notes/Kyrin(demo)/template.md:
--------------------------------------------------------------------------------
1 | 例子可见 https://github.com/KyrinCode/ZKP/blob/main/KZG.md
2 |
3 | 中文即可
--------------------------------------------------------------------------------
/lattice/slides/Lattice-1.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coset-io/zkp-academy/main/lattice/slides/Lattice-1.pdf
--------------------------------------------------------------------------------
/lattice/slides/Lattice-2.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coset-io/zkp-academy/main/lattice/slides/Lattice-2.pdf
--------------------------------------------------------------------------------
/lattice/slides/Lattice-3.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coset-io/zkp-academy/main/lattice/slides/Lattice-3.pdf
--------------------------------------------------------------------------------
/FRI&Stark/stark101/imgs/1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coset-io/zkp-academy/main/FRI&Stark/stark101/imgs/1.png
--------------------------------------------------------------------------------
/FRI&Stark/stark101/imgs/2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coset-io/zkp-academy/main/FRI&Stark/stark101/imgs/2.png
--------------------------------------------------------------------------------
/FRI&Stark/stark101/imgs/3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coset-io/zkp-academy/main/FRI&Stark/stark101/imgs/3.png
--------------------------------------------------------------------------------
/Plonk/co-learn-notes/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coset-io/zkp-academy/main/Plonk/co-learn-notes/.DS_Store
--------------------------------------------------------------------------------
/Plonk/lesson 5/img/circuit.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coset-io/zkp-academy/main/Plonk/lesson 5/img/circuit.png
--------------------------------------------------------------------------------
/ZKVM/co-learn-notes/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coset-io/zkp-academy/main/ZKVM/co-learn-notes/.DS_Store
--------------------------------------------------------------------------------
/ZKVM/lesson 1/zkvm-wangyao.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coset-io/zkp-academy/main/ZKVM/lesson 1/zkvm-wangyao.pdf
--------------------------------------------------------------------------------
/lattice/assets/KEF-LND-BLK.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coset-io/zkp-academy/main/lattice/assets/KEF-LND-BLK.png
--------------------------------------------------------------------------------
/lattice/slides/8.LaBRADOR.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coset-io/zkp-academy/main/lattice/slides/8.LaBRADOR.pdf
--------------------------------------------------------------------------------
/lattice/slides/9.Greyhound.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coset-io/zkp-academy/main/lattice/slides/9.Greyhound.pdf
--------------------------------------------------------------------------------
/ZKVM/lesson 4/Introduce the zkVM.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coset-io/zkp-academy/main/ZKVM/lesson 4/Introduce the zkVM.pdf
--------------------------------------------------------------------------------
/ZKVM/lesson 7/ZKM Prover基本构造课程.pptx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coset-io/zkp-academy/main/ZKVM/lesson 7/ZKM Prover基本构造课程.pptx
--------------------------------------------------------------------------------
/lattice/slides/6.Building_SNARKs.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coset-io/zkp-academy/main/lattice/slides/6.Building_SNARKs.pdf
--------------------------------------------------------------------------------
/lattice/slides/7.Realizing_PCS.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coset-io/zkp-academy/main/lattice/slides/7.Realizing_PCS.pdf
--------------------------------------------------------------------------------
/Plonk/lesson 1/whyplonk 2024-05-28.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coset-io/zkp-academy/main/Plonk/lesson 1/whyplonk 2024-05-28.pdf
--------------------------------------------------------------------------------
/FRI&Stark/assets/SN-Linear-Flat colour.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coset-io/zkp-academy/main/FRI&Stark/assets/SN-Linear-Flat colour.png
--------------------------------------------------------------------------------
/Plonk/co-learn notes/Eta/images/28_ring.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coset-io/zkp-academy/main/Plonk/co-learn notes/Eta/images/28_ring.png
--------------------------------------------------------------------------------
/Plonk/lesson 8/plookup and custom gates.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coset-io/zkp-academy/main/Plonk/lesson 8/plookup and custom gates.pdf
--------------------------------------------------------------------------------
/ZKVM/assets/ZKM Logo Horizontal Black-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coset-io/zkp-academy/main/ZKVM/assets/ZKM Logo Horizontal Black-1.png
--------------------------------------------------------------------------------
/lattice/co-learn-notes/SIS lattice and bkz.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coset-io/zkp-academy/main/lattice/co-learn-notes/SIS lattice and bkz.pdf
--------------------------------------------------------------------------------
/Plonk/co-learn notes/Eta/images/29_plonkish.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coset-io/zkp-academy/main/Plonk/co-learn notes/Eta/images/29_plonkish.png
--------------------------------------------------------------------------------
/Plonk/lesson 5/PLONK - Lecture 5 - 算术约束与拷贝约束.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coset-io/zkp-academy/main/Plonk/lesson 5/PLONK - Lecture 5 - 算术约束与拷贝约束.pdf
--------------------------------------------------------------------------------
/FRI&Stark/lesson 1/FRI overview 2024-08-13 19-54-37.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/coset-io/zkp-academy/main/FRI&Stark/lesson 1/FRI overview 2024-08-13 19-54-37.pdf
--------------------------------------------------------------------------------
/Plonk/lesson 6/README.md:
--------------------------------------------------------------------------------
1 |
2 | # Motivation
3 | 
4 |
5 | ## References
6 | - [MIT IAP 2023 :Commitment Schemes](https://assets.super.so/9c1ce0ba-bad4-4680-8c65-3a46532bf44a/files/61fb28e6-f2dc-420f-89e1-cc8000233a4f.pdf)
7 | - [理解 Plonk(五):多项式承诺](https://github.com/sec-bit/learning-zkp/blob/master/plonk-intro-zh/5-plonk-polycom.md)
8 | - [Shplonk: batch several polynomials over **a set of points**](https://hackmd.io/@walpo/shplonk)
9 |
10 | ## [code](./poly_commit.py)
--------------------------------------------------------------------------------
/ZKVM/lesson 1/Add instruction in SP1.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: 'What do you need to do to add '
3 |
4 | ---
5 |
6 |
7 | Let's say we would like to add a new function in sp1's riscv machine
8 | SQR that takes a u32 x and returns x * x
9 |
10 | There are two ways of doing it.
11 | Add SQR as an instruction in RISCV or as an pre-compile.
12 |
13 | What do you need to do to add a new risc-v instruction on SP1?
14 |
15 | What do you need to do to add a new pre-compile in sp1?
16 |
17 |
18 | Read sp1 code https://github.com/succinctlabs/sp1
19 | with this two questions.
20 | You should mainly read codes in the crates/core.
21 |
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # ZKP Academy
2 |
3 | ## Courses
4 |
5 | - [Lattice-based PCSs and SNARKs course from June 16 to Jul 27, 2025](https://github.com/coset-io/zkp-academy/tree/main/lattice)
6 |
7 | - [zkVM course from 30th Dec 2024 to 27th Jan 2025](https://github.com/Antalpha-Labs/zkp-academy/tree/main/ZKVM)
8 |
9 | - [FRI & Stark course from 12th Aug to 22nd Sep, 2024](https://github.com/Antalpha-Labs/zkp-academy/tree/main/FRI%26Stark)
10 |
11 | - [Plonk course run from May 27 to June 30, 2024, focusing on the principles and coding of the Plonk](https://github.com/Antalpha-Labs/zkp-study-group/tree/main/Plonk)
12 |
13 |
14 |
15 | ## Study group
16 | A month-long zkp study group, one topic at a time.
17 | - Jolt -> Finished
18 | - Binius -> [Binius学习小组 Finished](https://github.com/Antalpha-Labs/zkp-academy/issues/5)
19 | - Circle Starks -> [Finished](https://github.com/Antalpha-Labs/zkp-academy/issues/61)
20 |
21 | ### 🔥 zkp-academy Contributors
22 |
23 |
24 |
25 | Thank you for all your contributions!!
26 |
27 |
28 |
29 |
30 |
31 |
32 | ### 🖐️ Contact
33 |
34 | Contact us: tg @qijinz , wechat: coset2025
35 |
--------------------------------------------------------------------------------
/lattice/co-learn-notes/01-Kurt Pan-Lattice-Overview-lecture-note.txt:
--------------------------------------------------------------------------------
1 | 整理了昨晚Kurt老师的内容,供大家对照讲义视频参考,请自取~如有疏漏,请直接向老师提问
2 |
3 | p1 格密码概述
4 |
5 | p2 目录
6 | 格密码的五个优势:基于数学通用语言,有理论计算科学基础,密码分析利器,后量子安全,性能好
7 |
8 | p5 格的3个数学定义
9 | 1)n维实数域上的离散加法子群;
10 | 2)线性无关的基向量B的整数线性组合的集合;
11 | 3)整数矩阵的列空间
12 |
13 | p6-10 格的核心困难问题
14 | SVP:最短向量问题
15 | SVPγ:找到长度小于γλ1的最短非零格向量(近似),λ1为格上两点最短距离,γ是放松倍数
16 | SIVPγ:找到一组长度小于γλ1~γλn的最短独立向量
17 | CVPγ:找到离指定的t点长度小于γμ的向量,μ是离原点最近的向量长度
18 | CVP变体:离t点的距离最大为d。BDD(有界距离解码):最多一个解,d小于λ1/2;ADD:至少一个解,d>=μ
19 | LWE:带错学习。As+e=t
20 |
21 | p12 CVP可用于解码:m=CVP(B,t)
22 |
23 | p13 q元格具有周期性,SIS格可以看做满足线性方程组的点集
24 |
25 | p14 LWE可以被看作q元格中的CVP。LWE可以看做SIVP的平均版本(LWE的噪声 e 可以被视为SIVP中的“扰动”)。因此,LWE与CVP的近似BDD等价
26 |
27 | p15 MSIS即模SIS(最短整数Solution)问题,对随机A,求满足Az模q为0,且范数小于β的z,z是多项式环Rq上的向量
28 |
29 | p16 SIS格上的SVP问题
30 |
31 | p17 SIS应用:hash算法Ajtai。把m维z向量通过SIS格映射成n维点
32 |
33 | p18 NTRU加解密算法:多项式环上的SVP和CVP问题
34 | 密钥生成:h=2g/s,s和g都是短多项式。基于SVP,已知h无法推出短向量s
35 | 加密:c=rh+m mod q,r是随机多项式
36 | 解密:a=cs=rhs+ms=r2g+ms, m=a mod 2。基于CVP,已知c无法求出最接近的a
37 |
38 | p21
39 | Kyber基于Ring-LWE,公钥加密
40 | Dilithium基于module格上的LWE,签名
41 | FALCON基于NTRU格结构,签名
42 |
43 | p33
44 | 最坏情况到平均情况的归约在密码学中是“圣杯”,意味着破解难度在所有情况下都是一致的
45 |
46 | p34
47 | 即使多项式因子的近似SVP也展示了指数级难度
48 |
49 | p35
50 | 计算复杂性理论定义的六个世界:多项式世界,启发式世界(P不等于NP,但平均情况下不难),悲观世界(平均情况下难但不存在单向函数可以利用),最小密码世界(有单向函数,没有公钥密码学),密码世界(有公钥密码),混淆世界(不可区分,格)
51 |
52 | p62
53 | ZKP相关:LaBRADOR and Greyhound
54 |
55 | 其它:
56 | NIST格算法:C实现,区块链:Rust实现
57 | 其它参考文章:16年的Lattice十年综述
--------------------------------------------------------------------------------
/Plonk/lesson 6/util.py:
--------------------------------------------------------------------------------
1 | import hashlib
2 |
3 | HMAC_BLOCK_SIZE = 64
4 |
5 |
6 | def hash256(m):
7 | if type(m) != bytes:
8 | m = m.encode("utf-8")
9 | return hashlib.sha256(m).digest()
10 |
11 |
12 | def hash512(m):
13 | if type(m) != bytes:
14 | m = m.encode("utf-8")
15 | return hash256(m + bytes([0])) + hash256(m + bytes([1]))
16 |
17 |
18 | def hmac256(m, k):
19 | if type(m) != bytes and type(m) != bytearray:
20 | m = m.encode("utf-8")
21 | if type(k) != bytes and type(k) != bytearray:
22 | k = k.encode("utf-8")
23 | k = bytes(k)
24 | if len(k) > HMAC_BLOCK_SIZE:
25 | k = hash256(k)
26 | while len(k) < HMAC_BLOCK_SIZE:
27 | k += bytes([0])
28 | opad = bytes([0x5C] * HMAC_BLOCK_SIZE)
29 | ipad = bytes([0x36] * HMAC_BLOCK_SIZE)
30 | kopad = bytes([k[i] ^ opad[i] for i in range(HMAC_BLOCK_SIZE)])
31 | kipad = bytes([k[i] ^ ipad[i] for i in range(HMAC_BLOCK_SIZE)])
32 | return hash256(kopad + hash256(kipad + m))
33 |
34 |
35 | """
36 | Copyright 2020 Chia Network Inc
37 |
38 | Licensed under the Apache License, Version 2.0 (the "License");
39 | you may not use this file except in compliance with the License.
40 | You may obtain a copy of the License at
41 |
42 | http://www.apache.org/licenses/LICENSE-2.0
43 |
44 | Unless required by applicable law or agreed to in writing, software
45 | distributed under the License is distributed on an "AS IS" BASIS,
46 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
47 | See the License for the specific language governing permissions and
48 | limitations under the License.
49 | """
--------------------------------------------------------------------------------
/lattice/co-learn-notes/04-Bing-NTT-note-by-MT.txt:
--------------------------------------------------------------------------------
1 | 01 NTT数论变换
2 |
3 | 02 不止butterfly
4 |
5 | 03 why & how
6 |
7 | 04 NTTs == FFTs?
8 | FFT是为了计算DFTs
9 | FFT NTT在很多地方指一个东西
10 |
11 | 05 Motivation:提高模多项式乘法,商环多项式乘法的操作效率
12 |
13 | 07 多项式乘法Y=G*H,假设G,H都是d-1度
14 |
15 | 08-10 基本乘法计算和问题:多项式结果的度为2d-2;复杂性:O(n^2)
16 |
17 | 11 y[k]=(g*h)[k]=Σg[i]*h[k-i], i∈[0,k] (离散线性卷积)
18 | 当i或k-i超出最终Y的长度(2d-1),相关项就不计算了
19 |
20 | 解决度为2d-2,无法处理边界的问题:
21 | 14 多项式环: 取模φ(x)
22 |
23 | 15 循环卷积(CC) wraps around
24 | 与上面p11的线性卷积不同,取模后有了周期
25 | 这里计算c=a*b:
26 | a和b都补齐n次
27 | c[k]分为2项计算,第1项类似p11,第2项是i大于k之后,wrap计算直到i=n
28 |
29 | 16 在Zq[X]/(x^n-1)称为positive,Zq[X]/ (x^n+1) 称为negtive
30 |
31 | 17 PWC/NWC的不同在于计算c[k]的第二项的±不同
32 |
33 | 解决复杂性:O(n^2)太慢的问题
34 | 19 卷积(convolution) 理论。一个域中的卷积=另一个域中的点×
35 | 所以,把2个多项式系数向量转为NTT,点乘,然后把结果变回多项式即可
36 |
37 | 20 NTT的好属性。 转换NTT后还可可保持随机多项式的randomness,保持dimension和bit长度
38 |
39 | 21-22 NTT iNTT的转换计算
40 | 多项式系数向量a的NTT向量:NTT(a)
41 | iNTT向量的计算:乘以n的逆,w^-ij是模q下的w^ij的逆元
42 | w是n维原根 w^n=1 mod q
43 |
44 | 23-24
45 | 单位根在复平面上的单位圆上均匀分布,构成了圆周多项式的根,这些圆周多项式(cyclotomic polynomials)是多项式 x^n −1 的一个因式
46 | 图中的3个点是1的三个单位根
47 |
48 | 25 例子 2^8 mod 17 =1 , 所以2是8次原根 unity
49 |
50 | 26-28 FFT trick 基于CRT(环版本)简化多项式乘法
51 | 定理核心:R:环,Ii:互素的理想,I是理想的交集,那么模I下的元素可以分解为模Ii元素的乘积
52 | 例如:R:整数环,I1=2的倍数集合,I2=3的倍数集合,模6整数可分解为模2和模3整数乘积
53 | FFT即使用了类似分解,方根求解到最后,高次递归到线性多项式
54 |
55 | 29 公式10,11即上述CRT正向分解和逆向映射公式
56 |
57 | 30-31 CT butterfly 公式10
58 |
59 | 32 GS butterfly 公式11
60 |
61 | 33
62 | NTT ct no-bo 自然顺序转bit顺序,这里bit顺序(bo)不是0-7是因为输出的顺序是这样
63 | INTT GS bo-no
64 |
65 | 34 NTT的算法应用
66 | NTT友好:Kyber:Zq [x]/(x^n+1),Dilithium:Zq [x]/(x^n+1),Falcon:Zq [x]/(x^n+1)
67 | 不友好:Saber,NTRU Prime
68 |
--------------------------------------------------------------------------------
/lattice/co-learn-notes/02-Yingfei-What is Lattice & average-case and worst-case hard problems-note.txt:
--------------------------------------------------------------------------------
1 | 整理了周四晚Yingfei老师的内容,供对照书本讲义视频参考,请自取~如有疏漏,请直接向老师提问
2 |
3 | p1
4 | 基本概念。L 和 Λ 都代表格
5 | 格的定义:n维实数域上的离散加法子群,只考虑整数格
6 | 格的基B。理论分析通常用列变量,工程中经常用行变量表示
7 |
8 | p2
9 | 对任何格基B,可定义基本平行六面体P(B) (parallelepiped)。P(B)可以无缝铺满整个格空间 L(B)。
10 | P(B)在三维空间的含义是平行六面体,在二维空间是平行四边形,见kurt老师提供的parallelepiped链接,介绍了线性空间变换(缩放)概念,与B相乘的矩阵A的det(A)即P(B)体积的缩放倍数:
11 | https://www.3blue1brown.com/lessons/determinant
12 |
13 | p3
14 | 等价基。基可以变化,但格的形状(格点集)、P(B)的体积保持不变,只要满足B2=B1U(定义4)
15 | 其中,U是幺模矩阵(unimodular),即行列式det=±1 的n*n整数矩阵,det可用高斯消元法求解
16 | 由于幺模矩阵的det=±1,所以B1U是不会对P(B1)的体积大小有缩放的,B2和B1是等价的
17 | 如果Λ=L(B) 是满秩格(n),那么det(A)=|det(B)|,det越小,格点越稠密
18 |
19 | p4
20 | GSO:Gram-Schmidt 正交化将格的基向量B转为正交基,即减去在之前基向量上的投影
21 | B=QR,Q是正交矩阵,列向量是B的正交基;R是上三角矩阵,是B在Q上的表示
22 | 好的基接近正交。无论SVP还是CVP,在正交的基向量之间的相互影响较小,可限制搜索过程。
23 |
24 | p5
25 | 定理5 格的最短非零向量长度λ1大于正交化后的最小长度
26 | Minkowski定理:任何体积大于 2^n det(L) 的凸中心对称体 S 包含一个非零格点
27 | λ1上界见推论1.1.7,n个最短向量
28 | Minkowski 定理 2给出了格所有连续最小值的几何平均值的上界
29 |
30 | 最差情况计算问题:
31 | 简单问题:多项式时间
32 | 向量是否属于格的成员判定问题:利用高斯消元法
33 | 格基等价问题:求解两个线性方程组,检查B1的每个向量在B2中,反之亦然
34 |
35 | SVP(λ参数版)
36 | search SVPλ:在格L(B)中寻找最短非零向量v,使得v的长度小于γλ1
37 | optimization SVPλ:在格L(B)中寻找这样的距离d:d<=最短非零向量长度λ1<=γd
38 | promise SVPλ:判定最小非零向量长度λ1不超过实数r或大于γr
39 |
40 | p6
41 | CVP(λ参数版), 类似SVP
42 | search CVPλ:在格L(B)中寻找离给定向量t距离小于t长度的γ倍的非零向量v
43 | optimization CVPλ:在格L(B)中寻找这样的距离d:d<=给定向量t长度<=γd
44 | promise CVPλ:判定给定向量t长度不超过实数r或大于γr
45 | LLL约简算法:
46 | 给定n个线性无关向量b1-n,计算其GSO正交向量;
47 | 如果B约简后满足两个要求,可称为δ-LLL约简基(定义2)
48 | 如果是δ-LLL约简基,那么b1的长度有上界(与λ1有关)
49 |
50 | p7
51 | LLL属于P算法范畴
52 | GapSVPγ:判定最短非零向量长度λ1<=d 或 λ1>γd
53 |
54 | 平均情况问题:
55 | q元格定义
56 | Parity Check Lattice指:对矩阵A:n*m,满足Ax=0 mod q的x向量集合构成的格。这里的x即A的核空间,由所有将A映射(或理解为压缩)到0向量的向量组成
57 |
58 | Row-Generated Lattice指:对A:m*n和指定的s,满足y=As mod q的m维向量集构成的格。这里的y由所有将A通过与s相乘模q得到的m维向量组成,对A来说,y是根据其行向量生成的。
59 |
60 | 两个格的应用:
61 | Row-Generated Lattice与后续Ajtai hash的H=Az mod q形式类似。
62 | 要证明Ajtai hash的抗碰撞性,可以假设两个z1和z2得到相同的H,那么必然有A(z1-z2)=0,这样就等同于Parity Check Lattice(SIS格)上的SVP问题了(见01课p17)
63 | 个人觉得就这里讲的内容而言,没必要把A从(Parity Check Lattice定义中的)n*m改成m*n
64 |
65 | Lemma5:求λ1的上界(Minikowski定理)和下界
66 |
67 | p8
68 | SIS问题
69 | 这里definition6 SIS问题定义,A应该是n*m矩阵
70 | 对A求SIS等价于在SIS格L(C)上找最短非零向量
71 | 这页的PPT的L(C)写出的C矩阵和p7的Parity Check Lattice应该是等价的
72 | 不同β表示SIS难度,β越大,难度越低。
73 | 对β的分析:A是m*n的矩阵,求Ax=0 mod q 的x,且x的范数小于β
74 | n>m时无法简单解出线性方程组
75 | 若β 太小,导致晶格中的向量相对而言太长,x可能无解
76 | 若β 太大,可用LLL求解
77 | β处于中间值,可用于密码构造
--------------------------------------------------------------------------------
/lattice/co-learn-notes/05-Yingfei-Ajtai Commitment and Lyubashevsky Signature Proofs-note-by MT.txt:
--------------------------------------------------------------------------------
1 | 主题:Ajtai承诺和承诺打开的证明
2 | 内容:
3 | 承诺: 1)SIS,2)Chor-Rivest 哈希,3)Ajtai承诺的binding& hiding
4 | 证明: 1)协议,2)安全性:HVZK和知识soundness(relaxed),如果不考虑ZK
5 |
6 | 1 SIS/M-SIS回顾:找到Az=0,z是足够小的m维向量,A是n*m矩阵
7 |
8 | 2 Chor-Rivest Hash
9 | key是n×m的矩阵A,消息是m维比特向量x
10 | Hash函数:fA(x)=Ax mod q
11 | 压缩性:因为nq^n
12 | 抗碰撞性:首先,y=fA(x)=Ax;若找到x'≠ x,且fA(x')=Ax'=y,那么:A(x'-x)=0
13 | 若(x'-x)非零,那么可以找到SIS的解(x'-x),归结到SIS问题
14 |
15 | 3 C-R Hash可以应用到Ajtai承诺构造
16 | 单bit版本:
17 | Keygen/Setup: 选择 pk=A∈Z(n×m矩阵)
18 | Commit (u, pk): 承诺1bit u,随机选择(m-1)×1向量r←Dσ,计算com= A * [u,r]^T mod q
19 | Open(u,r,com,pk):计算得到{0,1}
20 |
21 | binding性质证明:
22 | 首先,com:=commit(u,pk);然后,要找到u',r', 使得 commit(u', pk)=com
23 | 同上抗碰撞证明,可归约到SIS m,n,q,2β 问题
24 |
25 | hiding性质证明(Pr[u=0]=Pr[u=1] ,即无法从com中区分承诺的是0还是1):
26 | 将矩阵A分解为[a0 | A'],a0是 A 的第一列(n×1),A′是剩余的 n×(m−1) 子矩阵
27 | 那么,com=[a0 | A'] * [u,r]^T=a0 u + A'r
28 | 当 u=0 时,com=A′r mod q (可看做A'的SIS格 ={r∈Z^(m-1)| A'r=com mod q})
29 | 当 u=1 时,com=a0+A′r mod q (可看做上述SIS格的偏移: a0+L)
30 | 第3课讲到的用高斯分布平滑参数s可做到L和c+L采样分布不可区分,因此,u=0和1也无法区分
31 |
32 | 同理,多bit version的承诺形式如下:
33 | com=A1m+A2r
34 |
35 | 4 证明commitment的open正确即不能打开成别的值(binding)
36 |
37 | Shnorr零知识协议: 证明P知道x满足g^x=X,协议满足zk和soundness,协议如下
38 | P V
39 | 选随机数y, 计算g^y=Y (Ay=w) →
40 | 计算z=y+xc ← 选随机挑战值c
41 | 发送z → 使用Y(w),z,c验证g^z=YX^c (Az=w+tc)
42 | Shnorr可改为Ajtai格版本(见协议的括号部分):A* [u,r]^T=com =t ∈Rq^n (即Ax=t)
43 | 格版本将Shnorr的计算进行了转换:幂次->乘法,乘法->加法,证明P知道x满足Ax=t
44 |
45 | 在Ajtai中,y是如何选取的很关键。y←Dσ,故y较小,c是small norm通常也小,x也小(||x||<=2β),故z=y+xc 也小,那么P要伪造z就不容易
46 |
47 | 5 协议安全性
48 | knowledge soundness的证明
49 | 这里是relaxed版本,秘密x*可以满足一些要求,但有损失:若P*能伪造一个证明 (z,c,w),那么可以构造一个提取器E,提取出x,使得 Ax=t,且||x||∞<=2β
50 | 用rewinding的方法提取:
51 | P* V
52 | w
53 | c
54 | z
55 | 倒带:
56 | P* V
57 | w
58 | c’
59 | z’
60 | 根据协议有:Az=w+ct,Az'=w+c't(倒带后)
61 | 那么有,A(z-z')=(c-c')t,令x*=(z−z′)/(c−c′) ,则 Ax*=t(要求(c-c')≠0,(c-c')可逆,逆元的范数=0,相对于 SIS 的主要优势在于其紧凑性效率
84 | 用ring就可以用FFT加速
85 | 环-SIS 是 SIS 的一个变体,其中 A 被限制为块负循环矩阵:A=[Rot(a1)∣…∣Rot(am )],其中 Rot(b) 是一个将向量 b 的系数逆序排列的矩阵
86 | bz=t 等价于Rot(b)z=t,节省了空间,但Rot代数结构的问题,可能会有针对性攻击
87 |
88 | p11
89 | M-SIS: 找到z使得Az=0,也类似R-SIS可以解释为矩阵:d*m,这个矩阵的每一块是Rot(ai,j),每个Rot(ai,j)是N/d方阵:将向量ai,j的系数逆序排列的矩阵
90 |
--------------------------------------------------------------------------------
/lattice/co-learn-notes/master-problem-underlying-all-cryptography.md:
--------------------------------------------------------------------------------
1 | 作者:黄芸(github账号hygithub-art)
2 |
3 | 6月19日,我看了Kurt老师分享的文章“一个关乎密码学存在性的主问题”,对文中提及的“Kolmogorov复杂度”感兴趣,查了些资料,写了这篇读书笔记:
4 |
5 | # computer-complexity
6 | 一、Kolmogorov复杂度(柯尔莫戈洛夫复杂度)的定义
7 |
8 | 定义:“生成该对象的最短程序的长度”(用某种通用编程语言,比如Python或图灵机)。
9 |
10 | Kolmogorov复杂度用于衡量对象的“信息本质”或“最简单描述的复杂度”:“真正的复杂性不在于对象本身的大小,而在于生成它的最小知识”。它是理解信息、随机性和计算本质的基石之一。
11 |
12 | 二、"Kolmogorov复杂度"名字来由:
13 |
14 | 背景:科学家们的“终极问题”
15 |
16 | 在20世纪中叶,数学家们对以下问题争论不休:
17 | “什么是随机?如何定义‘信息量’?是否存在绝对的‘复杂性’?
18 |
19 | 当时的理论(如香农的信息熵)无法区分“看似随机但实际有规律”和“真正随机”的数据。
20 |
21 | 三位“侦探”的突破
22 |
23 | (1) 雷·所罗门诺夫(Ray Solomonoff)—— 1960年
24 | 贡献:最早提出用“程序长度”描述复杂性,奠定了算法概率论的基础。
25 | 动机:想用计算机科学的方法解决归纳推理问题(比如预测序列的下一个数字)。
26 |
27 | (2) 安德雷·柯尔莫戈洛夫(Andrey Kolmogorov)—— 1963年
28 | 贡献:独立提出类似概念,并严格数学化,最终以他的名字命名。
29 | 动机:想用计算理论(而非概率统计)定义“随机性”。
30 | 名言:“随机序列是那些无法被显著压缩的序列。”
31 |
32 | (3) 格里高利·柴廷(Gregory Chaitin)—— 1966年
33 | 贡献:进一步完善理论,并发现其与哥德尔不完备定理的深刻联系。
34 | 动机:研究数学证明的极限时,发现复杂性是不可计算的。
35 |
36 | 虽然三位科学家几乎同时独立提出,但柯尔莫戈洛夫因其在数学界的权威地位(尤其是概率论和复杂性理论的工作),名字被广泛采用。不过现在学界也常用“算法信息论”(Algorithmic Information Theory)统称这一领域。
37 |
38 | 三、意义
39 |
40 | 解决了“随机性”的定义问题:首次用计算资源(程序长度)而非统计特性区分真随机和伪随机。
41 |
42 | 连接数学与计算机科学:揭示了计算局限性(如不可计算性)与信息本质的关系。
43 |
44 | 影响深远:现代数据压缩、机器学习(奥卡姆剃刀原则)、密码学均受其启发。
45 |
46 | 四、(↓来自"腾讯元宝")
47 | Kolmogorov 复杂度的研究现状
48 |
49 |
50 | Kolmogorov复杂度(以下简称KC)的研究至今仍是理论计算机科学、数学和信息论的前沿领域之一。虽然它的核心定义简单,但衍生出的问题和应用极其丰富。↓用“一棵知识树”的比喻梳理当前的研究现状——从根基到枝叶,逐步展开:
51 |
52 | 1. 根基:理论核心的深化
53 |
54 | (1) 不可计算性的突破
55 |
56 | 核心结论:KC无法被任何算法精确计算(柴廷不完备定理)。
57 | 新进展:
58 | 研究近似计算:如何用有限资源估计KC的上/下界(如基于压缩算法LZW、gzip等)。
59 | 资源受限KC:在有限时间/空间内定义KC的变体(如“时间有界KC”)。
60 |
61 | (2) 与其他理论的融合
62 |
63 | 算法概率论:KC与所罗门诺夫的通用先验概率结合,用于机器学习中的归纳推理。
64 | 量子信息论:量子版本的KC(如量子柯尔莫戈洛夫复杂度)被提出,探索量子比特的信息本质。
65 |
66 | 3. 主干:关键研究方向
67 |
68 | (1) 数据压缩的极限
69 |
70 | 理想:KC是最优压缩的理论极限(如ZIP、PNG等压缩算法的终极目标)。
71 | 现实挑战:
72 | 实际压缩算法只能逼近KC,但差距多大?如何优化?
73 | 神经压缩:用深度学习模型(如Transformer)逼近KC,效果如何?
74 |
75 | (2) 机器学习与奥卡姆剃刀
76 |
77 | 最小描述长度(MDL):KC是“选择最简单模型”的理论基础(如深度学习中的模型压缩)。
78 | 当前热点:神经网络的KC如何衡量?过参数化模型为何泛化性好?
79 |
80 | (3) 密码学与随机性
81 |
82 | 真随机 vs 伪随机:KC区分两者的能力被用于密码安全性证明。
83 | 例如:高KC的序列更难被预测,适合作为密钥。
84 |
85 | (4) 数学中的不可解问题
86 |
87 | 哥德尔不完备性:KC证明某些数学命题的复杂性无法被穷尽(柴廷的“算法信息论”视角)。
88 |
89 | 当前研究:KC在证明论和数论中的新应用(如黎曼猜想的复杂性分析)。
90 |
91 | 5. 枝叶:新兴应用领域
92 |
93 | (1) 人工智能解释性
94 |
95 | 问题:AI模型的决策是否“简单”?
96 |
97 | 用KC衡量模型行为的复杂度,例如:
98 | 对抗样本(高KC) vs 正常样本(低KC)。
99 |
100 | (2) 生物信息学
101 |
102 | DNA序列分析:基因的KC是否揭示进化规律?
103 | 例如:病毒变异后的KC变化与传染性关联。
104 |
105 | (3) 区块链与去中心化
106 |
107 | 智能合约验证:用KC证明合约的“简洁性”以减少漏洞。
108 |
109 | (4) 艺术与创造力
110 |
111 | 生成艺术:AI生成的作品的KC如何影响人类审美?
112 |
113 | 实验发现:人类偏爱中等KC的图像(既非完全规律,也非完全随机)。
114 |
115 | 7. 未解之谜(挑战)
116 | 8.
117 | 问题1:KC的近似计算能否突破理论极限?
118 |
119 | 当前最佳方法:用压缩算法(如LZMA)估计,但误差无法保证。
120 |
121 | 问题2:如何定义网络的KC(如社交网络、神经网络的结构复杂度)?
122 |
123 | 问题3:KC与热力学第二定律(熵增)是否存在深层联系?
124 |
125 | 10. 趣味案例:ChatGPT的KC
126 |
127 | 如果让ChatGPT生成一段文本,其KC可以理解为:
128 | 低KC:输出常见套话(如“你好!”)。
129 | 高KC:输出一首独创的诗歌。
130 |
131 | 研究问题:大语言模型的训练是否降低了其输出的平均KC?(答案可能是肯定的!)
132 |
133 | !!!总结现状
134 |
135 | KC的研究像一座活火山——理论核心稳定,但应用喷发不断。目前最活跃的领域是:
136 |
137 | 机器学习(模型简化、解释性)
138 |
139 | 算法信息论(量子扩展、不可计算性)
140 |
141 | 跨学科应用(生物、密码学、艺术)。
142 |
--------------------------------------------------------------------------------
/Plonk/lesson 6/bls12381.py:
--------------------------------------------------------------------------------
1 | # flake8: noqa
2 | from fields import Fq, Fq2
3 |
4 | # BLS parameter used to generate the other parameters
5 | # Spec is found here: https://github.com/zkcrypto/pairing/tree/master/src/bls12_381
6 | x = -0xD201000000010000
7 |
8 | # 381 bit prime
9 | # Also see fields:bls12381_q
10 | q = 0x1A0111EA397FE69A4B1BA7B6434BACD764774B84F38512BF6730D2A0F6B0F6241EABFFFEB153FFFFB9FEFFFFFFFFAAAB
11 |
12 | # a,b and a2, b2, define the elliptic curve and twisted curve.
13 | # y^2 = x^3 + 4
14 | # y^2 = x^3 + 4(u + 1)
15 | a = Fq(q, 0)
16 | b = Fq(q, 4)
17 | a_twist = Fq2(q, 0, 0)
18 | b_twist = Fq2(q, 4, 4)
19 |
20 | # The generators for g1 and g2
21 | gx = Fq(
22 | q,
23 | 0x17F1D3A73197D7942695638C4FA9AC0FC3688C4F9774B905A14E3A3F171BAC586C55E83FF97A1AEFFB3AF00ADB22C6BB,
24 | )
25 | gy = Fq(
26 | q,
27 | 0x08B3F481E3AAA0F1A09E30ED741D8AE4FCF5E095D5D00AF600DB18CB2C04B3EDD03CC744A2888AE40CAA232946C5E7E1,
28 | )
29 |
30 | g2x = Fq2(
31 | q,
32 | 352701069587466618187139116011060144890029952792775240219908644239793785735715026873347600343865175952761926303160,
33 | 3059144344244213709971259814753781636986470325476647558659373206291635324768958432433509563104347017837885763365758,
34 | )
35 | g2y = Fq2(
36 | q,
37 | 1985150602287291935568054521177171638300868978215655730859378665066344726373823718423869104263333984641494340347905,
38 | 927553665492332455747201965776037880757740193453592970025027978793976877002675564980949289727957565575433344219582,
39 | )
40 |
41 | # The order of all three groups (g1, g2, and gt). Note, the elliptic curve E_twist
42 | # actually has more valid points than this. This is relevant when hashing onto the
43 | # curve, where we use a point that is not in g2, and map it into g2.
44 | n = 0x73EDA753299D7D483339D80809A1D80553BDA402FFFE5BFEFFFFFFFF00000001
45 |
46 | # Cofactor used to generate r torsion points
47 | h = 0x396C8C005555E1568C00AAAB0000AAAB
48 |
49 | # https://tools.ietf.org/html/draft-irtf-cfrg-hash-to-curve-07#section-8.8.2
50 | h_eff = 0xBC69F08F2EE75B3584C6A0EA91B352888E2A8E9145AD7689986FF031508FFE1329C2F178731DB956D82BF015D1212B02EC0EC69D7477C1AE954CBC06689F6A359894C0ADEBBF6B4E8020005AAA95551
51 |
52 | # Embedding degree
53 | k = 12
54 |
55 | # sqrt(-3) mod q
56 | sqrt_n3 = 1586958781458431025242759403266842894121773480562120986020912974854563298150952611241517463240701
57 |
58 | # (sqrt(-3) - 1) / 2 mod q
59 | sqrt_n3m1o2 = 793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620350
60 |
61 | # This is the normal elliptic curve. G1 points are on here.
62 | def parameters():
63 | return (q, a, b, gx, gy, g2x, g2y, n, h, x, k, sqrt_n3, sqrt_n3m1o2)
64 |
65 |
66 | # This is the sextic twist used to send elements of G2 from
67 | # coordinates in Fq12 to coordinates in Fq2. It's isomorphic
68 | # to the above elliptic curve. See Page 63 of Costello.
69 | def parameters_twist():
70 | return (
71 | q,
72 | a_twist,
73 | b_twist,
74 | gx,
75 | gy,
76 | g2x,
77 | g2y,
78 | n,
79 | h_eff,
80 | x,
81 | k,
82 | sqrt_n3,
83 | sqrt_n3m1o2,
84 | )
85 |
86 |
87 | """
88 | Copyright 2020 Chia Network Inc
89 |
90 | Licensed under the Apache License, Version 2.0 (the "License");
91 | you may not use this file except in compliance with the License.
92 | You may obtain a copy of the License at
93 |
94 | http://www.apache.org/licenses/LICENSE-2.0
95 |
96 | Unless required by applicable law or agreed to in writing, software
97 | distributed under the License is distributed on an "AS IS" BASIS,
98 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
99 | See the License for the specific language governing permissions and
100 | limitations under the License.
101 | """
--------------------------------------------------------------------------------
/lattice/co-learn-notes/06-Building_SNARKs-note.md:
--------------------------------------------------------------------------------
1 | # 06-Building_SNARKs-note
2 |
3 | by shawn
4 |
5 | ## PPT第2页
6 |
7 | **对于完整性和健全性两性质,老师举例:**
8 | 如果P试图向V证明F∈L,这里L就是某个NP语言(比如3SAT或哈希预映像等),
9 |
10 | completeness:如果F∈L,那么V一定输出accept。
11 |
12 | soundness:如果F $\notin$ L,那么V一定输出reject。
13 |
14 |
15 | ## PPT第3页
16 |
17 | **ZK在链上的意义:**
18 |
19 | 某个prover计算了s.t. f(x,w)=1,将这个proof在链上发布。随后这个proof可以在链上被多方验证。整个计算过程只由一个prover执行了一次,且验证proof比计算f更快,省gas且cheap,并且保证了计算的完整性。
20 |
21 |
22 | ## PPT第4页
23 |
24 | **SNARKs的各字母依次含义:**
25 | Succinct:small proof size和small verification time。
26 |
27 | Non-interactive:证明者只需一次性发送证明,不需要和验证者进行多轮交互(非交互式的意义:不需要verifier一直在线)。
28 |
29 | Argument:基于计算假设(如EC离散对数/LWE)而安全。也就是说在argument里,如果相应的困难假设(如EC离散对数/LWE)被破解,那么就不再安全。而在更为严格的proof里,即使P有无限的计算能力,也无法让V相信假statement为真。
30 |
31 | Knowledge:证明者不仅表明语句为真,还证明自己知道该statement成立的秘密证据。
32 |
33 | **老师讲的rewind是什么:**
34 |
35 | 那如果有一个多项式时间的P,能说服V接受(P输出一个有效proof),那么存在一个多项式时间的extractor,它可以和P交互(也就是老师说的rewind P),最终把这个证明所依赖的witness挖出来。
36 |
37 | 而上面的Knowledge要求允许在安全证明里对P做rewind,以此来强调P必须真的掌握那个证据witness,否则就无法持续给出合格回答。
38 |
39 | **老师的例子里:**
40 |
41 | x是public input
42 | w是secret witness
43 |
44 | P发送给V:small size的π
45 |
46 | V:检测π,输出1或0。
47 |
48 | 可以认为|T|≈|Circuit Size|。
49 |
50 | 定义P的time bound:这个function可以在T time steps里完成证明。
51 |
52 | 定义V的time bound:由于V会把function和x都会读一遍,所以有poly(T) or poly(|F|+|x|+ $\log T$),其中T>|F|,T>|x|。
53 |
54 | **所有的snark都需要setup:Public(Transparent)setup和Private setup。**
55 | Public setup:setup的randomness完全是public的。
56 | Private setup:setup的randomness不可以公开,只能setup时候用,setup后必须丢弃(有毒废料)。
57 |
58 | Universal setup:setup和function无关,只需要取到T的upper bound即可。对多个function可用。
59 | Specific setup:与function强关联且绑定。构建出了最短的常数级别proof size,最少的 prover时间,常数验证时间。
60 |
61 |
62 | ## PPT第7页
63 |
64 | **根据给V不同的能力来实现不同的证明系统:**
65 |
66 | oracle access:P发给V一个oracle(数组),V可以只读oracle的其中几位。
67 |
68 | random access:希望V随机选择几位来读。
69 |
70 | interaction:试图转化成非交互。
71 |
72 | multi-prover:V和多个P交互,并且要求P之间独立,不可共谋(限制prover作恶的能力,如果能共谋那么多P和单P没区别)。
73 |
74 | PCP:P发给V一个 oracle,V随机选读几个点,结束。
75 |
76 | IP:V每次返回给P的挑战是随机的。
77 |
78 | IOP:主流方向。P发送oracle,V读一些点,回复msg;重复。
79 |
80 | MIP:多个P和V交互,V可以选择与哪个P继续交互,最终V得到0或1。只考虑MIP的话,V必须读P发送的整个msg,而不是读oracle。
81 |
82 | MIOP:在MIP的基础上P发oracle。
83 |
84 | **不同oracle的种类可以设计不同的snark:**
85 |
86 | oracle也可以发polynomial:P发送f(x)给V,V不读整个f(x),而是问oracle一些evaluation。
87 |
88 | 以及vector oracle等
89 |
90 |
91 | ## PPT第8页
92 |
93 | IP:V是要读P发送的整个msg的。一般用作整个protocol的Sub-routines。也就是说它不是完整的主协议,而是主流程里被反复调用的子协议模块。
94 |
95 | PCP:,只能发一个oracle。point queries PCPs不efficient,Linear queries PCPs是efficient。
96 |
97 | MIP,MIOP:概念和性质上看起来很好,实际上很难用。那么如何变实用目前还是研究方向。
98 |
99 | IOP:用的最多,可以多次发oracle。
100 |
101 |
102 | ## PPT第9页
103 |
104 | Probabilistic:PCP不能interactive,只能发一个oracle。V可以生成随机挑战进行query。
105 | V不读整个oracle size,得到O($\log T$)复杂度。但oracle是理想的,要求P发出去之后不能再更改。
106 |
107 |
108 | ## PPT第11页
109 |
110 | **PCP不好怎么办?** 用IOP。
111 | 流程:P发送oracle,V query,oracle返回值;重复步骤,最终V输出0或1。
112 |
113 | **如何构建SNARK?** 1.怎么去构建一个IOP,2.把IOP里的理想oracle转化成实际中可以用的(比如通过commitment)。那么focus IOP设计即可。
114 | 如果发送的是polynoimal IOP,那么就需要PCS。
115 |
116 |
117 | ## PPT第12页
118 |
119 | Interactive proof composition:比如有两个prove system,第一个proof size小,verifier time大,第二个相反。那么通过将两个系统结合,得到两个system的优点。
120 |
121 |
122 | ## PPT第13页
123 |
124 | 对于IOP的oracle进行选择,再选择对应的commitment或者encoding等来构建query oracle。
125 |
126 | **Probabilistic Proof列决定了计算的类型:**
127 |
128 | Circuit computation:比如把function的各种谓词和逻辑条件展开成Circuit,证明该Circuit是满足约束的。
129 |
130 | Machine computation:把machine每一步的状态模拟,证明状态1到状态2,AIR和ZKVM那种感觉。
131 |
132 | **Cryptography列决定了P和V的cost,是否前量子or后量子,setup的种类。**
133 |
134 |
135 | ## PPT第14页
136 |
137 | Polynomial IOP:每次P发的oracle是polynomial,V query 这些polynomial的evaluation;多次重复,最终输出1 or 0。
138 |
139 |
140 | ## PPT第15页
141 |
142 | 用PCS:对polynomial $f_1(X)$承诺,比如对它的系数向量算commitment得到 $\mathsf{Com}(f_1)$。
143 |
144 | V返回evaluation query $z_1$,P返回 $v=f_1(z_1)$,以及small size的π来证明 $f_1(X)$在 $z_1$处确实等于v。
145 |
146 | 其中,witness是 $f_1(X)$,public input是 $\mathsf{Com}(f_1)$, $z_1$和evaluation值v。
147 |
148 | 对于多变量PCS:把上述符号换成下面这些即可。
149 |
150 | $f(\mathbf X)=f(X_1,\dots ,X_m)\in\mathbb F[\mathbf X]$, $\mathbf z=(z_1,\dots ,z_m)\in\mathbb F^m$ , $v=f(\mathbf z)\in\mathbb F$ .
151 |
--------------------------------------------------------------------------------
/Plonk/lesson 6/pairing.py:
--------------------------------------------------------------------------------
1 | from collections import namedtuple
2 | from typing import List
3 |
4 | import bls12381
5 | from ec import AffinePoint, JacobianPoint, untwist
6 | from fields import Fq, Fq12
7 |
8 | # Struct for elliptic curve parameters
9 | EC = namedtuple("EC", "q a b gx gy g2x g2y n h x k sqrt_n3 sqrt_n3m1o2")
10 |
11 | default_ec = EC(*bls12381.parameters())
12 | default_ec_twist = EC(*bls12381.parameters())
13 |
14 |
15 | def int_to_bits(i: int) -> List[int]:
16 | if i < 1:
17 | return [0]
18 | bits = []
19 | while i != 0:
20 | bits.append(i % 2)
21 | i = i // 2
22 | return list(reversed(bits))
23 |
24 |
25 | def double_line_eval(R: AffinePoint, P: AffinePoint, ec=default_ec):
26 | """
27 | Creates an equation for a line tangent to R,
28 | and evaluates this at the point P. f(x) = y - sv - v.
29 | f(P).
30 | """
31 | R12 = untwist(R)
32 |
33 | slope = (Fq(ec.q, 3) * (R12.x ** 2) + ec.a) / (Fq(ec.q, 2) * R12.y)
34 | v = R12.y - slope * R12.x
35 |
36 | return P.y - P.x * slope - v
37 |
38 |
39 | def add_line_eval(R: AffinePoint, Q: AffinePoint, P: AffinePoint, ec=default_ec) -> Fq:
40 | """
41 | Creates an equation for a line between R and Q,
42 | and evaluates this at the point P. f(x) = y - sv - v.
43 | f(P).
44 | """
45 | R12 = untwist(R)
46 | Q12 = untwist(Q)
47 |
48 | # This is the case of a vertical line, where the denominator
49 | # will be 0.
50 | if R12 == Q12.negate():
51 | return P.x - R12.x
52 |
53 | slope = (Q12.y - R12.y) / (Q12.x - R12.x)
54 | v = (Q12.y * R12.x - R12.y * Q12.x) / (R12.x - Q12.x)
55 |
56 | return P.y - P.x * slope - v
57 |
58 |
59 | def miller_loop(T: int, P: AffinePoint, Q: AffinePoint, ec=default_ec) -> Fq12:
60 | """
61 | Performs a double and add algorithm for the ate pairing. This algorithm
62 | is taken from Craig Costello's "Pairing for Beginners".
63 | """
64 | T_bits = int_to_bits(T)
65 | R = Q
66 | f = Fq12.one(ec.q) # f is an element of Fq12
67 | for i in range(1, len(T_bits)):
68 | # Compute sloped line lrr
69 | lrr = double_line_eval(R, P, ec)
70 | f = f * f * lrr
71 |
72 | R = Fq(ec.q, 2) * R
73 | if T_bits[i] == 1:
74 | # Compute sloped line lrq
75 | lrq = add_line_eval(R, Q, P, ec)
76 | f = f * lrq
77 |
78 | R = R + Q
79 | return f
80 |
81 |
82 | def final_exponentiation(element: Fq12, ec=default_ec) -> Fq12:
83 | """
84 | Performs a final exponentiation to map the result of the Miller
85 | loop to a unique element of Fq12.
86 | """
87 | if ec.k == 12:
88 | ans = element ** ((pow(ec.q, 4) - pow(ec.q, 2) + 1) // ec.n)
89 | ans = ans.qi_power(2) * ans
90 | ans = ans.qi_power(6) / ans
91 | return ans
92 | else:
93 | return element ** ((pow(ec.q, ec.k) - 1) // ec.n)
94 |
95 |
96 | def ate_pairing(P: JacobianPoint, Q: JacobianPoint, ec=default_ec) -> Fq12:
97 | """
98 | Performs one ate pairing.
99 | """
100 | t = default_ec.x + 1
101 | T = abs(t - 1)
102 | element = miller_loop(T, P.to_affine(), Q.to_affine(), ec)
103 | return final_exponentiation(element, ec)
104 |
105 |
106 | def ate_pairing_multi(
107 | Ps: List[JacobianPoint], Qs: List[JacobianPoint], ec=default_ec
108 | ) -> Fq12:
109 | """
110 | Computes multiple pairings at once. This is more efficient,
111 | since we can multiply all the results of the miller loops,
112 | and perform just one final exponentiation.
113 | """
114 | t = default_ec.x + 1
115 | T = abs(t - 1)
116 | prod = Fq12.one(ec.q)
117 | for i in range(len(Qs)):
118 | prod *= miller_loop(T, Ps[i].to_affine(), Qs[i].to_affine(), ec)
119 | return final_exponentiation(prod, ec)
120 |
121 |
122 | """
123 | Copyright 2020 Chia Network Inc
124 |
125 | Licensed under the Apache License, Version 2.0 (the "License");
126 | you may not use this file except in compliance with the License.
127 | You may obtain a copy of the License at
128 |
129 | http://www.apache.org/licenses/LICENSE-2.0
130 |
131 | Unless required by applicable law or agreed to in writing, software
132 | distributed under the License is distributed on an "AS IS" BASIS,
133 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
134 | See the License for the specific language governing permissions and
135 | limitations under the License.
136 | """
--------------------------------------------------------------------------------
/Plonk/lesson 6/fft.py:
--------------------------------------------------------------------------------
1 | def _simple_ft(vals, modulus, roots_of_unity):
2 | L = len(roots_of_unity)
3 | o = []
4 | for i in range(L):
5 | last = 0
6 | for j in range(L):
7 | last += vals[j] * roots_of_unity[(i*j)%L]
8 | o.append(last % modulus)
9 | return o
10 |
11 | def _fft(vals, modulus, roots_of_unity):
12 | if len(vals) <= 4:
13 | #return vals
14 | return _simple_ft(vals, modulus, roots_of_unity)
15 | L = _fft(vals[::2], modulus, roots_of_unity[::2])
16 | R = _fft(vals[1::2], modulus, roots_of_unity[::2])
17 | o = [0 for i in vals]
18 | for i, (x, y) in enumerate(zip(L, R)):
19 | y_times_root = y*roots_of_unity[i]
20 | o[i] = (x+y_times_root) % modulus
21 | o[i+len(L)] = (x-y_times_root) % modulus
22 | return o
23 |
24 | def expand_root_of_unity(root_of_unity, modulus):
25 | # Build up roots of unity
26 | rootz = [1, root_of_unity]
27 | while rootz[-1] != 1:
28 | rootz.append((rootz[-1] * root_of_unity) % modulus)
29 | return rootz
30 |
31 | def fft(vals, modulus, root_of_unity, inv=False):
32 | rootz = expand_root_of_unity(root_of_unity, modulus)
33 | # Fill in vals with zeroes if needed
34 | if len(rootz) > len(vals) + 1:
35 | vals = vals + [0] * (len(rootz) - len(vals) - 1)
36 | if inv:
37 | # Inverse FFT
38 | invlen = pow(len(vals), modulus-2, modulus)
39 | return [(x*invlen) % modulus for x in
40 | _fft(vals, modulus, rootz[:0:-1])]
41 | else:
42 | # Regular FFT
43 | return _fft(vals, modulus, rootz[:-1])
44 |
45 | # Evaluates f(x) for f in evaluation form
46 | def inv_fft_at_point(vals, modulus, root_of_unity, x):
47 | if len(vals) == 1:
48 | return vals[0]
49 | # 1/2 in the field
50 | half = (modulus + 1)//2
51 | # 1/w
52 | inv_root = pow(root_of_unity, len(vals)-1, modulus)
53 | # f(-x) in evaluation form
54 | f_of_minus_x_vals = vals[len(vals)//2:] + vals[:len(vals)//2]
55 | # e(x) = (f(x) + f(-x)) / 2 in evaluation form
56 | evens = [(f+g) * half % modulus for f,g in zip(vals, f_of_minus_x_vals)]
57 | # o(x) = (f(x) - f(-x)) / 2 in evaluation form
58 | odds = [(f-g) * half % modulus for f,g in zip(vals, f_of_minus_x_vals)]
59 | # e(x^2) + coordinate * x * o(x^2) in evaluation form
60 | comb = [(o * x * inv_root**i + e) % modulus for i, (o, e) in enumerate(zip(odds, evens))]
61 | return inv_fft_at_point(comb[:len(comb)//2], modulus, root_of_unity ** 2 % modulus, x**2 % modulus)
62 |
63 | def shift_domain(vals, modulus, root_of_unity, factor):
64 | if len(vals) == 1:
65 | return vals
66 | # 1/2 in the field
67 | half = (modulus + 1)//2
68 | # 1/w
69 | inv_factor = pow(factor, modulus - 2, modulus)
70 | half_length = len(vals)//2
71 | # f(-x) in evaluation form
72 | f_of_minus_x_vals = vals[half_length:] + vals[:half_length]
73 | # e(x) = (f(x) + f(-x)) / 2 in evaluation form
74 | evens = [(f+g) * half % modulus for f,g in zip(vals, f_of_minus_x_vals)]
75 | print('e', evens)
76 | # o(x) = (f(x) - f(-x)) / 2 in evaluation form
77 | odds = [(f-g) * half % modulus for f,g in zip(vals, f_of_minus_x_vals)]
78 | print('o', odds)
79 | shifted_evens = shift_domain(evens[:half_length], modulus, root_of_unity ** 2 % modulus, factor ** 2 % modulus)
80 | print('se', shifted_evens)
81 | shifted_odds = shift_domain(odds[:half_length], modulus, root_of_unity ** 2 % modulus, factor ** 2 % modulus)
82 | print('so', shifted_odds)
83 | return (
84 | [(e + inv_factor * o) % modulus for e, o in zip(shifted_evens, shifted_odds)] +
85 | [(e - inv_factor * o) % modulus for e, o in zip(shifted_evens, shifted_odds)]
86 | )
87 |
88 | def shift_poly(poly, modulus, factor):
89 | factor_power = 1
90 | inv_factor = pow(factor, modulus - 2, modulus)
91 | o = []
92 | for p in poly:
93 | o.append(p * factor_power % modulus)
94 | factor_power = factor_power * inv_factor % modulus
95 | return o
96 |
97 | def mul_polys(a, b, modulus, root_of_unity):
98 | rootz = [1, root_of_unity]
99 | while rootz[-1] != 1:
100 | rootz.append((rootz[-1] * root_of_unity) % modulus)
101 | if len(rootz) > len(a) + 1:
102 | a = a + [0] * (len(rootz) - len(a) - 1)
103 | if len(rootz) > len(b) + 1:
104 | b = b + [0] * (len(rootz) - len(b) - 1)
105 | x1 = _fft(a, modulus, rootz[:-1])
106 | x2 = _fft(b, modulus, rootz[:-1])
107 | return _fft([(v1*v2)%modulus for v1,v2 in zip(x1,x2)],
108 | modulus, rootz[:0:-1])
--------------------------------------------------------------------------------
/Plonk/co-learn notes/Eta/02_Lagrange.md:
--------------------------------------------------------------------------------
1 | # 02. Lagrange Interpolation
2 |
3 |
4 |
5 | | title |
6 | tags |
7 |
8 |
9 | | 02. Lagrange Interpolation |
10 |
11 |
12 |
13 | | zk-meme |
14 | basic |
15 | quick_read |
16 | Lagrange_Interpolation |
17 |
18 |
19 | |
20 |
21 |
22 |
23 | [Github](https://github.com/ETAAcademy)|[Twitter](https://twitter.com/ETAAcademy)|[ETA-ZK-Meme](https://github.com/ETAAcademy/ETAAcademy-ZK-Meme)
24 |
25 | Authors: [Eta](https://twitter.com/pwhattie), looking forward to your joining
26 |
27 | ## Lagrange Interpolation
28 |
29 | Provers can combine multiple constraints into a single polynomial, which reduces communication and simplifies verification for Verifiers.
30 |
31 | ### Probabilistic Check of Polynomials
32 |
33 | 1. **Schwartz-Zippel Theorem**: The Verifier provides a random challenge $\zeta \in \mathbb{F}$ for two polynomials $f(\zeta) = g(\zeta)$. If the degree of the polynomials is small compared to the size of the field they're working in (like the number of elements in a set), the chance of $f(X) = g(X)$ getting a wrong answer is less than $\leq \frac{d}{|\mathbb{F}|}$(since a polynomial of degree d is determined by \(d+1\) points).
34 |
35 | 2. **Vector Verification**: Similar to above, vectors (lists of numbers) can be encoded as polynomials. To verify that three vectors $\vec{a} + \vec{b} = \vec{c}$, the direct method is to encode the vectors into polynomials (using the vector as polynomial coefficients), such as $a(X) = a_0 + a_1X + a_2X^2 + \cdots + a_{n-1}X^{n-1}$. We can create polynomials a(X), b(X), and c(X) from the lists a, b, and c, respectively. If the property $a_i + b_i = c_i$ holds true, then interestingly, adding the polynomials a(X) + b(X) will result in the polynomial c(X), a(X) + b(X) = c(X). By challenging with a random number $\zeta$, If we evaluate both sides of the equation a(ζ) + b(ζ) = c(ζ), then $\vec{a} + \vec{b} = \vec{c}$.
36 |
37 | ### Lagrange Interpolation and Evaluation Form
38 |
39 | Multiplying polynomials can get messy. So, for checking if the element-wise product (think multiplication of corresponding entries) of two vectors equals a third vector, a special kind of polynomial encoding is used called Lagrange interpolation.
40 |
41 | - Using Lagrange Interpolation to validate $\vec{a} \circ \vec{b} \overset{?}{=} \vec{c}$, where terms $a_i \cdot b_i$ and $c_i$ do not correspond to the coefficients of $X^i$.
42 | - Instead, we use Lagrange interpolation polynomials Interpolation: $\{L_i(X)\}_{i\in[0,N-1]}$, where $L_i(w_i)=1$, and $L_i(w_j)=0 (j\neq i)$. Then $\vec{a}$ can be encoded as follows:
43 |
44 | $$
45 | a(X)=a_0\cdot L_0(X) + a_1\cdot L_1(X)+ a_2\cdot L_2(X) + \cdots + a_{N-1}\cdot L_{N-1}(X)
46 | $$
47 |
48 | - The element-wise product of vectors $a_i \cdot b_i = c_i$ resulting in $a(w_i) \cdot b(w_i) = c(w_i)$. Similarly, $\vec{a} \circ \vec{b} = \vec{c}$ translates to functions $a(X) \cdot b(X) = c(X)$ for all $X \in H$.
49 |
50 | ### Single Challenge Verification
51 |
52 | To detect Prover’s cheating with a single challenge, transform the above equality by removing the specific X values (since X should cover a large range like $\mathbb{F}:$
53 |
54 | $$
55 | a(X) \cdot b(X) - c(X) = q(X) \cdot z_H(X), \quad \forall X \in \mathbb{F}
56 | $$
57 |
58 | Since $f(X) = 0$ for all $X \in H$ and $f(X) = a(X) \cdot b(X) - c(X)$,H is the root set of f(X):
59 |
60 | $$
61 | f(X)=(X-w_0)(X-w_1)(X-w_2)\cdots(X-w_{N-1})\cdot q(X)
62 | $$
63 |
64 | Thus, f(X) is divisible by the vanishing polynomial $z_H(X) = (X - w_0)(X - w_1) \cdots (X - w_{N-1})$. The Prover computes q(X) and sends it to the Verifier. Since H is a known system parameter, the Verifier can compute $z_H(X)$ and check:
65 |
66 | $$a(\zeta) \cdot b(\zeta) - c(\zeta) \overset{?}{=} q(\zeta) \cdot z_H(\zeta)$$
67 |
68 | ### Optimization: Roots of Unity
69 |
70 | There's a clever way to choose the roots of unity to simplify calculations. The subgroup H is formed by the powers of $\omega$:
71 |
72 | $$
73 | H = (1, \omega, \omega^2, \ldots, \omega^{N-1})
74 | $$
75 |
76 | These elements satisfy certain symmetries, e.g., $\omega = -\omega^{\frac{N}{2} + 1}$ and $\omega^i = -\omega^{\frac{N}{2} + i}$. Summing all roots of unity yields zero:
77 |
78 | $$
79 | \sum\_{i=0}^{N-1} \omega^i = 0
80 | $$
81 |
82 | In practical, we choose a large finite field with a large powers-of-2 multiplicative subgroup. Due to the symmetry of $\omega^i$, on the subgroup H, we have:
83 |
84 | $$
85 | z_H(X) = \prod*{i=0}^{N-1} (X - \omega^i) = X^N - 1
86 | $$
87 |
88 | In essence, polynomial encoding and Lagrange interpolation provide a powerful way to compress and verify complex relationships between data, simplifies many calculations and enhances efficiency in verification.
89 |
--------------------------------------------------------------------------------
/lattice/co-learn-notes/09.Greyhound-note-by MT.md:
--------------------------------------------------------------------------------
1 | 作者:MT, https://github.com/mountaintower/learningzkp
2 |
3 | ## 01 Greyhound
4 |
5 | 是基于lattice的PCS,基于laBRADOR 实现PCS。
6 |
7 | ## 02 内外双层承诺 (承诺多项式$f(X)$)
8 |
9 | 假设$f(X)=f_0 X^0 + f_1 X^1 + ... + f_{N-1} X^{N-1}$,将N个多项式系数切分成$r*m$ 矩阵,r*m=N,后面,我们可以将多项式系数矩阵表示成每个m维向量$\vec{f_i}$ 作为列向量的矩阵 。
10 |
11 | 现在承诺r条m维向量$\vec{f_0}, ..., \vec{f_{r-1}} \in \mathcal{R_q^m}$ :
12 |
13 | 1)内层承诺:因为$\vec{f_i}$ 可能很长,不能直接承诺。故将每个$\vec{f_i}$ 分解为短向量$\vec{s_i} \in \mathcal{R_q^{m\delta}}$ (指m维向量$\vec{f_i}$ 中的每一维都拆成$\delta$ 份=>$(f_{i0}, f_{i1}, ..., f_{i (\delta-1)})$,$\delta$ 是分解基),然后做Ajtai承诺得到$\vec{t_i}=A \vec{s_i} \in \mathcal{R_q^n}$, $A$ 是$n * mδ$ 矩阵。
14 |
15 | 2)外层承诺:将每个n维向量 $\vec{t_i}$ 分解为短向量$\vec{t'_i} \in \mathcal{R_q^{n\delta}}$,然后将r个$\vec{t'_i}$ 串联起来($\in \mathcal{R_q^{r n \delta}}$),再次做Ajtai承诺得到$\vec{u}=B (\vec{t'_1}, ..., \vec{t'_n}) \in \mathcal{R_q^n}$, $B$ 是$n * rnδ$ 矩阵。
16 |
17 | 等于将多项式系数表示成了短向量$\vec{u}$。
18 |
19 | 分解的时候可以选择2进制,这样分解的结果只有0或1,向量小,容易处理。
20 |
21 | ## 03 二次型关系(两个线性映射的乘积,如$a F b=y$ ,参见第7课第6页)
22 |
23 | 上面的双层承诺已经把多项式系数压缩成一个短承诺 $\vec{u}$ ,现在证明:对于公开点x,二次型关系成立,并且不会泄露witness。
24 |
25 | witness:$(\vec{s_i}, \vec{t_i})_{i \in [r]}$。
26 | 公开输入:$\vec{u},\vec{a},\vec{b}$,整数 $y$。
27 |
28 | 关系:
29 |
30 | 验证矩阵:$y=f(x)$ 求值;
31 |
32 | 验证$\vec{f_i}$正确分解成$\vec{s_i}$:$\vec{f_i}=G_m \vec{s_i}$;
33 |
34 | 验证$\vec{t_i}$ 是$\vec{s_i}$ 的承诺;
35 |
36 | 验证$\vec{t_i}$生成$u$:先分解成$\vec{t'_i}$,然后生成最终承诺。
37 |
38 | ## 04 简单版协议:证明上述关系
39 |
40 | 类似brakedown的方法:
41 |
42 | 1)P发左乘向量$\vec{w}$;
43 |
44 | 2)V发短向量挑战$\vec{c}$;
45 |
46 | 3)P发分解向量$\vec{t'_i}$,计算$\vec{z}$(即$\vec{c}$ 和$\vec{s}$ 的随机线性组合,$\vec{s}$ 与$\vec{f}$ 只差一个$G_m$,验证$\vec{c}$ 和$\vec{f}$ 的组合也是一样的)
47 |
48 | ## 05简单版协议
49 |
50 | 4)V验证:
51 |
52 | y的计算正确,即第一行验证的前半部分;
53 |
54 | $\vec{w}$ 的计算正确,即第一行验证的后半部分:挑战随机线性组合关系的计算正确(左边等于$\vec{a} \vec{f} \vec{c}$,右边等于$\vec{a} G_m \vec{s} \vec{c}= \vec{a} \vec{f} \vec{c}$);
55 |
56 | 验证ajtai承诺正确,即第二行验证的前两个部分:先用分解向量$\vec{t'_i}$ 组合成inner承诺$\vec{t_i}$,然后验证$\vec{t_i}$ 与挑战$\vec{c}$ 组合是否等于线性组合$\vec{z}$ 的承诺;
57 |
58 | 验证outer 承诺,即第二行验证的最后一个部分:用inner承诺$\vec{t_i}$ 的承诺验证;
59 |
60 | 最后验证$\vec{t'_i}, \vec{z}$ 是短的。
61 |
62 | ## 06 减少证据大小:使用LaBRADOR关系
63 |
64 | P发送的大小取决于: $\vec{w} \in \mathcal{R_q^r},\vec{t'_i} \in \mathcal{R_q^{n \delta}}$(虽然大,与r和m无关),$\vec{z} \in \mathcal{R_q^m}$。
65 |
66 | 使用LaBRADOR关系描述第5页的验证关系,从而将代价减少到 $r=m=\sqrt N$。
67 |
68 | ## 07 减少证据大小:使用LaBRADOR关系
69 |
70 | 首先,第4页协议第1步:P不发送$\vec{w}$,而是发送$\vec{w}$分解后的$\vec{w'}$的承诺$\vec{v}$ ,以及第3步发送 $\vec{w'}$;
71 |
72 | 然后,第5页验证:要增加验证承诺$\vec{v} \overset{?}= Com(\vec{w'})$。
73 |
74 | 单纯地看,Proof大小还增加了分解后的$\vec{w'}$,但这里的问题是如何调用LaBRADOR。
75 |
76 | 使用本页的矩阵乘法:
77 |
78 | 第1行:验证承诺$\vec{v}$;
79 |
80 | 第2行:验证第5页outer 承诺$\vec{u}$;
81 |
82 | 第3行:验证第5页$\vec{w}$ 和$\vec{b}$ 左乘等于求值y (第5页第1行左边验证);
83 |
84 | 第4行:验证第5页$\vec{w}$ 和$\vec{c}$ 随机线性组合等于$\vec{w}, G_m$ 和$\vec{z}$ 线性组合(第5页第1行右边验证),即验证$\vec{w}$ 是正确的;
85 |
86 | 第5行:验证第5页$\vec{t_i}$ 的分解和ajtai承诺(见第3页对$\vec{s_i}$ 的承诺$\vec{t_i}$ );
87 |
88 | 最后验证3个向量是短的。
89 | 若将矩阵公式精简成$E \vec{d}= \vec{f}$ ,那么 $\vec{d}$ 是witness,其它都是公开输入。这个关系完全可以用第6页LaBRADOR的公式第2项($\Sigma<\Phi_i,s_j>$)检查。
90 |
91 | 所以Greyhound 等于把N维向量变为$\sqrt N$ 大小的向量,然后在上面实施LaBRADOR-IPA得到$O(log\sqrt N)=O(logN)$ 的Proof大小,验证时间是$O(\sqrt N)$ 的。
92 |
93 | ## 08 多项式承诺
94 |
95 | 最终要证明的是普通整数域$ {ℤ_q} $上的多项式$f(X)$求值(多项式的系数$f_i$ 是标量),而Greyhound的双层承诺是在环 $R_q = ℤ_q[X]/(X^m + 1)$ 定义的(多项式$f(X)$的r 个原始系数$\vec{f_i}$ 都是m维向量,见第2页第1行,所以需要被拉平成mr个${ℤ_q}$标量计算)。
96 |
97 | 即把在$R_q$ 上的$f(X)$ 求值证明扩展到${ℤ_q}$上:$f(x) = Σ_{i=0}^{mr-1} f_i x^i = y\ mod\ q$。
98 |
99 | Greyhound 方案:
100 |
101 | 1)把r 个环元素系数$\vec{f_i}$ 展开成 m·r个$ℤ_q$标量(即把环里的每个多项式系数 $\vec{f_i}$ 拆成 m个整数系数),系数$\vec{f_i} $ 的展开见PPT,按 m×r 矩阵展开):$f(x)= [1,x,x^2,…,x^{m-1}][\vec{f_0},\vec{f_1},...\vec{f_{r-1}}][1,x^m,x^{2m},…,x^{(r-1)m}]^T$。
102 |
103 | 这里的$f(x) $分解的3项中的第1个(长度为m)和第3个(长度为r)与x相关的向量,相当于第3页的向量a和b,做外积展平: $a ⊗ b=(1,x^1, ... x^{mr-1})$。所以全部乘起来就是$f(x)$的取值,这样可以压缩协议传输的通信量。
104 |
105 | 2)用$ℤ_q$上的内积完成最终的Σ-check 求值检查:
106 |
107 | 已知 $f(x)=⟨ (f_0,…,f_{mr-1}), (1,x,x²,…,x^{mr-1}) ⟩ $, 实际上是对公开点z,求解$<\vec{f},\vec{z}>=\Sigma_{i \in [0,mr-1]} f_i z_i$。 采用LaBRADOR的$ct(<\sigma(\vec{a}),\vec{a})>$技巧(见LaBRADOR讲课PPT第2页),就能将上述向量内积转换为$ct(<\sigma(\vec{f}),\vec{z})>$ (交叉项都被丢弃了)。
108 |
109 | 然后用LaBRADOR-IPA就可以一次性递归证明内积了,代价是O(logN) 。
110 |
111 | ## 09 HyperWolf:从单变量->多变量线性
112 |
113 | 目标:把 Greyhound 的二次型关系证明从二维矩阵压缩推广到 k 维超立方体,进一步降低通信与验证复杂度。
114 |
115 | 核心思想:
116 |
117 | 1)将长向量 f(长度 N)视为 k 维超立方体网格(每维大小 N^{1/k})。
118 |
119 | 2)用 k 维分段幂向量 代替 Greyhound 的二维 a、b 向量:通信/验证复杂度降至 $O(k N^{1/k})$。
120 |
121 | 3)取 k = log N 时,复杂度变为 O(log N),无需再跑 LaBRADOR,协议自身即递归 Σ-check。
122 |
123 | ## 10 -11 HyperWolf举例(假设有8个$f_i$系数,立方体)
124 |
125 | 证明这里的$f(x)$取值(3个变量$x_i$),将x向量拆成$x_1, x_2$和$x_3$两部分
126 |
127 | 所以reduce成的第9页最后一行图的关系(蓝色部分乘积公开g_i,绿色部分乘积公开y_g)等同第10页最后一行
128 |
129 | ## 12 HyperWolf举例
130 |
131 | 这里实际上是Greyhound了,V最后验证的等式类似第5页Grey第一行后半部分验证。
132 |
133 | ## 答疑
134 |
135 | 关于knowledge soundness:greyhound PCS 调用了LaBRADOR的knowledge soundness
136 | 仍然使用rewind技术,得到:(c1-c2) (f1-f2) =A,需要考虑c‘ 可逆,向量是短的等等,与LaBRADOR的投影有关(是relaxed的)。见Greyhound的lemma 3.2:CWSS:Commit-With-Small-Solution,保证协议“要么提取有效见证,要么破坏格假设”。
137 |
--------------------------------------------------------------------------------
/lattice/co-learn-notes/07.Realizing_PCS-note-by MT.md:
--------------------------------------------------------------------------------
1 | Author:MT
2 | https://github.com/mountaintower/learningzkp
3 |
4 | 01 为什么讲多项式承诺方案PCS
5 | PIOP+PCS=>SNARKs,能根据需要直接组合出很多方案
6 | VDB也可以用PCS做
7 |
8 | 补充说明:多项式承诺方案(PCS)的原语,证明承诺的多项式f(X)在z点取值为v=f(z)
9 |
10 | Setup($1^λ$, d) → pp
11 | 输入:安全参数 λ,多项式最高阶 d
12 | 输出:公开参数 pp(可能为空,也可能含可信设置)
13 |
14 | Commit(pp, f(X)) → (C, aux)
15 | 输入:pp 与多项式 f(X)(deg ≤ d)
16 | 输出:承诺 C(恒定长度),辅助信息 aux(仅 Prover 保留,用于后续open证明)
17 |
18 | Open(pp, C, z, v, aux) → π
19 | 输入:pp, 承诺 C, 点 z, 声称值 v=f(z), 辅助 aux
20 | 输出:开证明 π
21 |
22 | VerifyEval(pp, C, z, v, π) → {0,1}
23 | 输入:pp, C, z, v, π
24 | 输出:1 表示接受“v = f(z)”;0 表示拒绝在z点的多项式值为v
25 |
26 | 一些补充原语:
27 |
28 | Batch-Verify:一次验证多点求值
29 |
30 | Succinct-Update:更新承诺而不重算整个多项式
31 |
32 | 一些PCS实例:
33 |
34 | KZG:Setup 输出 SRS,Commit 用 SRS 做椭圆曲线运算,Open 生成商多项式证明
35 |
36 | IPA-based (Bulletproofs):Setup 为空,Commit 用 Pedersen-向量承诺,Open 运行对数轮内积协议
37 |
38 | 02 单变量PCS方案1:内积论证IPA
39 | 设多项式f(X) 的系数向量为$\vec{f}$,设$\vec{z}$ 为$(z^0,z^1, ...z^{N-1})$,那么多项式值f(z) 就是两个向量做内积的结果
40 |
41 | 1)Commit:Prover 对$\vec{f}$ 做承诺得到$F= ⟨\vec{f}, \vec{G}⟩$,公共输入为群元素生成的向量 $\vec{G}=(G_0,..., G_{N-1})$ (在Setup做)
42 |
43 | 2)Open:公开$F$ ,对公开点$z$ 计算 $v=f(z)$,生成 $v=<\vec{f}, \vec{z}>$ 的多轮(log N)内积论证,输出证明 π。具体过程:
44 |
45 | 每一轮都对折上一轮的 $\vec{f}$, $\vec{z}$, $\vec{G}$ 为左L右R两部分,然后计算本轮的:$L=<\vec{f_L}, \vec{G_R}>, R=<\vec{f_R}, \vec{G_L}>$,挑战 $c=H(F, z, v, 之前所有轮的L,之前所有轮的R)$
46 |
47 | 接着进行折叠:$\vec{z'}=\vec{z_L}+c\vec{z_R},\\\vec{f'}=\vec{f_L}+c\vec{f_R},\\\vec{G'}=\vec{G_L}+c^{-1}\vec{G_R},\\F'=<\vec{f'}, \vec{G'}>=<\vec{f_L}+c\vec{f_R},\vec{G_L}+c^{-1}\vec{G_R}>\\=<\vec{f_L},\vec{G_L}>+c^{-1}<\vec{f_L},\vec{G_R}>+c<\vec{f_R},\vec{G_L}>+<\vec{f_R},\vec{G_R}>\\= F+c^{-1}L+cR$
48 |
49 | 共计算logN轮折叠到1维,得到$π=(L_0,R_0, L_1,R_1, …, L_{logN-1},R_{logN-1},f_{final})$
50 |
51 | 3)VerifyEval:Verifier输入F,z,v,π,进行值的验证(无需知道f多项式)
52 |
53 | 同样计算所有挑战c,通过$F'= F+c^{-1}L+cR$,${z'}={z_L}+c{z_R}$,逐轮进行标量计算折叠得到最终轮的$F_{final}, G_{final}, z_{final}$,验证$F_{final}=f_{final} G_{final}, v=f_{final} z_{final}$
54 |
55 | 以上是基于Bulletproof的内积论证(inner-product argument,IPA) ,使用Pederson承诺可达到:2log𝑁 证明大小,线性证明(显然下界lower bound是O(N))和验证时间(O(N)),但这里验证时间并不比证明少
56 |
57 | 03 单变量PCS方案2:商多项式
58 | 对公开点z,若有𝑓(𝑧)=𝑣,则: 𝑓(𝑋)−𝑣=𝑞(𝑋)⋅(𝑋−𝑧),基本协议是:
59 |
60 | P发:q(X)
61 |
62 | V检查:𝑓(𝑋)−𝑣=𝑞(𝑋)⋅(𝑋−𝑧) 是否成立
63 | 但商多项式直接做proof的话,proof太大(比f(X)的度数只小1)
64 | 所以可用承诺使得商多项式大小变成O(1),同时验证等式也要修改:
65 |
66 | P发送:商多项式的承诺Com(q(X))
67 |
68 | V检查:(Com(𝑓(𝑋))−Com(𝑣))⋅Com(1)=Com(q(X))⋅Com(𝑋−𝑧).
69 | 使用采用pairing的KZG做PCS方案如下(KZG把整个商多项式压缩成一个群元素$\pi$,然后用1次配对验证点值):
70 |
71 | 1)Setup
72 |
73 | 可信设置:
74 |
75 | $SRS=\{\tau^0 G_1, ..., \tau^{N-1} G_1, \tau^0 G_2, ..., \tau^{N-1} G_2\}$, $\tau$ 是随机的秘密标量,本次协议完成后需要销毁
76 |
77 | 2)Commit
78 |
79 | Prover 计算$\tau$ 点在$G_1$ 上的承诺:
80 |
81 | $Com_1(f(\tau))=f(\tau)G_1$
82 |
83 | 3)Open
84 |
85 | Prover计算商多项式q(X)= (f(X) – v)/(X – z),输出$\tau$ 点在$G_1$ 的证明(即q在$\tau$ 点的值在$G_1$ 上的承诺):
86 |
87 | $\pi=Com_1(q(\tau))=q(\tau)G_1$
88 |
89 | 4)VerifyEval:Verifier用$\tau$ 点在$G_2$ 做配对验证
90 |
91 | Verifier计算:
92 |
93 | $v$ 点在$G_1$ 上的承诺:$Com_1(v)=v G_1$
94 |
95 | $\tau-z$ 点在$G_2$ 上的承诺:$Com_2(\tau-z)= (\tau-z)G_2$
96 |
97 | $G_2$ 其实是1在$G_2$ 上的承诺:$Com_2(1)= 1 G_2= G_2$
98 |
99 | 检查配对:$e(Com_1(f(\tau))-Com_1(v), Com_2(1))=e(Com_1(q(\tau)),Com_2(\tau-z) )$如果配对验证成功,则有:
100 |
101 | $e((f(\tau)-v)G_1, G_2=e(q(\tau)G_1,(\tau-z)G_2)$,即:
102 |
103 | $e(G_1,G_2)^{(f(\tau)-v)}=e(G_1,G_2)^{q(\tau)(\tau-z)}$,故有指数相等:
104 |
105 | $(f(\tau) – v)=q(\tau)(\tau – z)$,由于$\tau$ 是随机的,故多项式恒等式$q(X)= (f(X) – v)/(X – z)$在全域成立
106 |
107 | 以上是基于KZG承诺的PCS方案,KZG的proof是 size O(1) (即1个群元素$\pi$),验证时间也是O(1) (1次配对),证明时间是线性的(涉及FFT是拟线性NlogN)
108 |
109 | 04 多变量线性PCS
110 | Multilinear:多变量线性,对每个变量而言其它变量都是常量
111 | 有coefficient系数和evalation求值两种形式
112 | 系数形式:把多变量项式写成单变量多项式的线性组合,如$f(X_0,X_1)=f_{00}+f_{10}X_0+f_{01}X_1+f_{11}X_0X_1$
113 | 求值形式:把多项式看成超立方体(每个$X_i$ 维只能取0或1)上的拉格朗日插值,如$f(X_0,X_1)=f(0,0)⋅(1−X_0)(1−X_1)+f(1,0)⋅X_0(1−X_1)+⋯+f(1,1)⋅X_0X_1$两种形式是为了用于PIOP+PCS的匹配更方便
114 |
115 | 05 多变量线性PCS:IPA
116 | 上述两种形式都可以看做IPA $<\vec{f}, \vec{z}>= v$
117 |
118 | $\vec{z}$ 就是上述形式中的多变量$X_i$的组合形式
119 |
120 | 假设多项式系数有$N=2^n$,那么验证时间也是O(N)
121 | 我们希望有个小于$2^n$的sublinear算法(√N )
122 |
123 | 06 多变量线性PCS:IPA举例
124 | $<\vec{f}, \vec{z}>$的内积计算举例($\vec{z}$ 可以选择第4页提到的任意两种形式之一)
125 | 把内积运算中的$\vec{z}$ 拆成了z0z1分量和z2z3分量两个部分,最终得到的内积结果和第4页的多项式是相同的
126 | 好处是P V可以分开计算
127 |
128 | 07 多变量线性PCS:IPA举例
129 |
130 | P向V发送计算的$[w_0, w_1, w_2, w_3]$, 即z0z1分量部分与f矩阵的乘积
131 |
132 | V需要验证其与z2z3分量部分的乘积是否等于v,以及$[w_0, w_1, w_2, w_3]$ 是正确计算出来的(后续发挑战验证)
133 |
134 | 08 多变量线性PCS:IPA举例
135 |
136 | V发送挑战$\vec{c}$
137 |
138 | P计算f矩阵与挑战的乘积,记为$\vec{t}$
139 |
140 | V验证$[w_0, w_1, w_2, w_3]$ 与挑战的乘积$\overset{?}=$ z0z1分量部分与$\vec{t}$的乘积
141 |
142 | 09 多变量线性PCS:IPA举例
143 |
144 | 设$M=2^m, m=n/2, n= log_2 N$, $M= 2^{({log_2 N}/2)}=2^{{log_2 N^{1/2}}}=2^{log_2 \sqrt N}= \sqrt N$
145 |
146 | 这样两边的代价都是M
147 |
148 | Proof size:P 需要发$\vec{w},\vec{t}$ ,故为 O(M)
149 |
150 | 使用Bulletproofs-IPA 与 KZG 两种实现可以进一步将多变量求值转化为内积论证IPA,那么proof大小可以到log M和N log N,验证时间是$O(\sqrt N)$ 和O(N)的
151 |
152 | 10 多变量线性PCS-IPA工作
153 | 第6页的Bivariant sumcheck:
154 |
155 | 把 2ᴹ 个系数先排成一个 √N × √N 的矩阵,先对列做一次 sumcheck,再对行做一次 sumcheck,于是:每轮只需处理 √N长度的向量;总复杂度从 O(N) 降到 O(√N)
156 |
157 | Bivariant sumcheck+Pederson承诺/RS code/KZG/LaBRADOR=>Hyrax/Brakedown/MERCURY/Greyhound
158 |
159 | sumcheck argument(2021): Sum-check 协议 + 折叠式承诺
160 |
161 | basefold(2023): 多线性多项式+RS码, 使用Σ-check对多线性和式检查+TIPP(2020)双线性群上IPA可实现高效Pairing-based PCS
162 |
163 | Hyperwolf (2024):将Σ-check(basefold思路)转换到格,使用SIS/Module-SIS 假设做承诺(用格上的可折叠承诺(Ajtai/Bonsai-tree 等)替代 RS 码),实现后量子安全的多线性 PCS
164 |
165 | 11 多变量线性PCS-IPA
166 | Sum-check 把“多维”压成“一维”,让 IPA 单变量工具也能给多线性多项式做 PCS。因为基于 Sum-check 的多线性 PCS 协议,把多变量线性多项式(Multilinear)的证明任务,转化成了单变量多项式(Univariate)的打开任务
167 |
168 | 12 多变量线性PCS-商多项式
169 | 也可以用类似KZG的商多项式构造
170 |
171 | 基本协议和基于承诺的改进协议思路见第3页
172 | PST的solution得到的结果是:O(logN)的证明大小和验证时间
173 |
--------------------------------------------------------------------------------
/Plonk/co-learn notes/Eta/01_R1CS_Plonklish.md:
--------------------------------------------------------------------------------
1 | # 01. R1CS V.S. Plonkish
2 |
3 |
4 |
5 | | title |
6 | tags |
7 |
8 |
9 | | 01. R1CS_Plonkish |
10 |
11 |
12 |
13 | | zk-meme |
14 | basic |
15 | quick_read |
16 | R1CS_Plonkish |
17 |
18 |
19 | |
20 |
21 |
22 |
23 | [Github](https://github.com/ETAAcademy)|[Twitter](https://twitter.com/ETAAcademy)|[ETA-ZK-Meme](https://github.com/ETAAcademy/ETAAcademy-ZK-Meme)
24 |
25 | Authors: [Eta](https://twitter.com/pwhattie), looking forward to your joining
26 |
27 | ## Plonkish Arithmetization
28 |
29 | Plonkish Arithmetization represents a significant advancement in Zero-knowledge proofs (ZKPs) that allow one party, the Prover, to prove to another party, the Verifier, that a statement is true without revealing any additional information. Let's delve into the intricacies of Plonkish Arithmetization and its comparison with the well-established R1CS framework.
30 |
31 | ### 1. R1CS: A Foundation in Multiplication Gates
32 |
33 | R1CS, or Rank-1 Constraint Systems, **revolves around multiplication gates**, where three "selector" matrices - U, V, and W - designate the "left input", "right input", and "output" of each multiplication gate, respectively, 1 of which indicates involvement in computations and 0 non-involvement. The selector matrix usually has a number of columns equivalent to the number of variables, with the number of rows matching the count of multiplication gates. Additionally, R1CS accommodates constant multiplication gates, a special case treated as addition gates.
34 |
35 |
36 |

37 |
38 |
39 | Consider a scenario where we have four input variables labeled $(x_1, x_2, x_3, x_4).$ In this scenario, $x_5$ acts as the output of the second multiplication gate and also functions as the right input of the first multiplication gate, while \(out\) represents the output of the first multiplication gate.
40 |
41 | $$\vec{a} = (x_1, x_2, x_3,x_4,x_5,out)$$
42 |
43 | Imagine a circuit with multiplication gates. Three matrices \(U\), \(V\), and \(W \in \mathbb{F}^{n\times m}\) describe how the gates are connected (circuit's setup). W is a table with rows matching the number of gates (n) and columns hinting at the number of wires (m). Each row in W tells how the corresponding gate connects its inputs and output.
44 |
45 | Left input matrix \(U\):
46 |
47 | $$
48 | \begin{array}{|c|c|c|c|c|}
49 | \hline
50 | x_1 & x_2 & x_3 & x_4 & x_5 & out & \texttt{i} \\
51 | \hline
52 | 1 & 1 & 0 & 0 & 0 & 0 & \texttt{1}\\
53 | \hline
54 | 0 & 0 & 1 & 0 & 0 & 0 & \texttt{2}\\
55 | \hline
56 | \end{array}
57 | $$
58 |
59 | Right input matrix \(V\):
60 |
61 | $$
62 | \begin{array}{|c|c|c|c|c|}
63 | \hline
64 | x_1 & x_2 & x_3 & x_4 & x_5 & out &\texttt{i}\\
65 | \hline
66 | 0 & 0 & 0 & 0 & 1 & 0 & \texttt{1}\\
67 | \hline
68 | 0 & 0 & 0 & 1 & 0 & 0 & \texttt{2}\\
69 | \hline
70 | \end{array}
71 | $$
72 |
73 | Output matrix \(W\):
74 |
75 | $$
76 | \begin{array}{|c|c|c|c|c|}
77 | \hline
78 | x_1 & x_2 & x_3 & x_4 & x_5 & out & \texttt{i}\\
79 | \hline
80 | 0 & 0 & 0 & 0 & 0 & 1 & \texttt{1}\\
81 | \hline
82 | 0 & 0 & 0 & 0 & 1 & 0 & \texttt{2}\\
83 | \hline
84 | \end{array}
85 | $$
86 |
87 | We can easily verify the following equation:
88 | $$(U \cdot \vec{a}) \circ (V \cdot \vec{a}) = (W \cdot\vec{a})$$
89 |
90 | ## 2. Plonkish Arithmetization: A Leap Forward
91 |
92 | Plonkish arithmetization is a more efficient way to express circuits for zero-knowledge proofs:
93 |
94 | **Circuit Setup:**
95 |
96 | Instead of three tables (U,V,W) with potentially many columns, Plonk uses a single W table with just 3 columns to reduces complexity.
97 |
98 | Plonk can handle more than just addition and multiplication gates, such as comparisons, lookups, and even memory access (RAM).
99 |
100 | **Key Tables: $\mathsf{Plonkish}_0 \triangleq (Q, \sigma;$ W)**
101 |
102 | - W table: Stores assignments (secret).
103 | - Q table (Selector): Defines operation for each row (addition or multiplication).
104 | - Permutation table: Ensures consistency when values are moved around in W.
105 |
106 | We define a matrix $W\in\mathbb{F}^{n\times 3}$ to represent constraints where n is the number of arithmetic gates):
107 |
108 | $$
109 | \begin{array}{c|c|c|c|}
110 | i & w_a & w_b & w_c \\
111 | \hline
112 | 1 & \boxed{x_6} & \underline{x_5} & [out] \\
113 | 2 & x_1 & x_2 & \boxed{x_6} \\
114 | 3 & x_3 & x_4 & \underline{x_5} \\
115 | 4 & 0 & 0 & [out] \\
116 | \end{array}
117 | $$
118 |
119 | To distinguish addition and multiplication, we define a vector $Q\in\mathbb{F}^{n\times 5}$ to represent operators:
120 |
121 | $$
122 | \begin{array}{c|c|c|c|}
123 | i & q_L & q_R & q_M & q_C & q_O \\
124 | \hline
125 | 1 & 0 & 0 & 1 & 0& 1 \\
126 | 2 & 1 & 1 & 0 & 0& 1 \\
127 | 3 & 0 & 0 & 1 & 0& 1 \\
128 | 4 & 0 & 0 & 0 & out& 1 \\
129 | \end{array}
130 | $$
131 |
132 | Permutation proofs confirm this consistency post rearrangement, verified by Prover.
133 |
134 | $$
135 | \begin{array}{c|c|c|c|}
136 | i & w_a & w_b & w_c \\
137 | \hline
138 | 1 & \boxed{x_6} & \underline{x_5} & out \\
139 | 2 & x_1 & x_2 & \boxed{x_6} \\
140 | 3 & x_3 & x_4 & \underline{x_5} \\
141 | \end{array}
142 | $$
143 |
144 | If three or more vector positions must share a value, Prover cyclically shifts them, ensuring equality with the original.
145 |
146 | $$
147 | A = (b_1, b_2, \underline{a_1}, b_3, \underline{a_2}, b_4, \underline{a_3}) = (b_1, b_2, \underline{a_3}, b_3, \underline{a_1}, b_2, \underline{a_2}) = A'
148 | $$
149 |
150 | To ensure that $w_c$ in the first row equal to the out variable, an additional copy constraint is added to the $\sigma$ matrix. In short, if the Prover is honest, then for $i \in (1,2,3,4),$ the following arithmetic constraint equation holds:
151 |
152 | $$
153 | q_{L,i} \circ w_{a,i} + q_{R,i} \circ w_{b,i} + q_{M,i}\circ(w_{a,i}\cdot w_{b,i}) + q_{C,i} - q_{O,i}\circ w_{c,i} = 0
154 | $$
155 |
--------------------------------------------------------------------------------
/Plonk/co-learn notes/Eta/03_Permutation.md:
--------------------------------------------------------------------------------
1 | # 03. Permutation
2 |
3 |
4 |
5 | | title |
6 | tags |
7 |
8 |
9 | | 03. Permutation |
10 |
11 |
12 |
13 | | zk-meme |
14 | basic |
15 | quick_read |
16 | Permutation |
17 |
18 |
19 | |
20 |
21 |
22 |
23 | [Github](https://github.com/ETAAcademy)|[Twitter](https://twitter.com/ETAAcademy)|[ETA-ZK-Meme](https://github.com/ETAAcademy/ETAAcademy-ZK-Meme)
24 |
25 | Authors: [Eta](https://twitter.com/pwhattie), looking forward to your joining
26 |
27 | ## Permutation
28 |
29 | A verifier can verify multiple copy constraints within a table $\omega$ using just one random challenge, without even seeing the table itself. For $\omega$, cyclic permutations are performed for the positions that need to be equal, and then the prover demonstrates that the original $\omega$ table is equal to the cyclically permuted $\omega'$ table. **Verifying table equality can be achieved through polynomial encoding and probabilistic checking**
30 |
31 | ### Cold Start: Grand Product
32 |
33 | 1. **Product Relation:**
34 | The product $p = q_0 \cdot q_1 \cdot q_2 \cdot \cdots \cdot q_{n-2}$ is proved by converting a cumulative product calculation into multiple single multiplication. An auxiliary vector $\vec{r}$, acting as an accumulator, is introduced to represent the "intermediate values" after each multiplication, essentially capturing the entire calculation trace of the product process. The leftmost column represents the original vector to be multiplied { $q_i$ }, the middle column { $r_i$ } is the auxiliary variable that stores the intermediate value "before each single multiplication," and the rightmost column shows the value after each multiplication.
35 |
36 | Interestingly, when we shift the "middle column" vector, r , up one row, it becomes almost identical to the "rightmost column," except for the last element.
37 |
38 | 2. **Polynomial Constraints:**
39 | When we encode the three columns of the table as polynomials, they satisfy three specific constraints based on Lagrange Basis polynomials:
40 |
41 | - Initial value: $r_0 = 1, r_{n-1} = p$:
42 | $L_0(X) \cdot (r(X) - 1) = 0,$
43 | $L_{n-1}(X) \cdot (r(X) - p) = 0, \quad \forall X \in H.$
44 | - Recursive multiplication relation (removing $\omega^{-1}$ from the set):
45 | $q(X) \cdot r(X) = r(\omega \cdot X), \quad \forall X \in H \setminus \{\omega^{-1}\}.$
46 |
47 | Simplifying the Constraints:
48 |
49 | - We add a row to the product table, setting $q_{n-1} = 1/p$ (note: p is the product of vector $\vec{q}$. Thus, $r_n = r_0 = 1$. The rightmost column is exactly a cyclic shift of $vec{r}$.
50 | - The verifier can challenge the following polynomial equation:
51 | $L_0(X) \cdot (r(X) - 1) + \alpha \cdot (q(X) \cdot r(X) - r(\omega \cdot X)) = h(X) \cdot z_H(X).$
52 | Here, $\alpha$ is a random challenge number used to combine multiple polynomial constraints, and $h(X)$ represents the quotient polynomial, with $z_H(X) = (X-1)(X-\omega) \cdots (X-\omega^{n-1})$.
53 |
54 | $$
55 | \begin{array}{c|c|c}
56 | q_i & r_i & q_i\cdot r_i \\
57 | \hline
58 | q_0 & 1 & r_0\\
59 | q_1 & r_0 & r_1\\
60 | q_2 & r_1 & r_2\\
61 | \vdots & \vdots & \vdots\\
62 | q_{n-2} & r_{n-2} & r_{n-1}\\
63 | q_{n-1}=\frac{1}{p} & r_{n-1} & 1 \\
64 | \end{array}
65 | $$
66 |
67 | ### Using Grand Product to Prove Multiset Equality:
68 |
69 | 1. If two polynomials p(X) and q(X) are equal, they must share the same set of roots { $q_i$ }.
70 | For example: $\prod_{i}(X - q_i) = q(X) = p(X) = \prod_{i}(X - p_i),$ $\\{q_i\\}=_{multiset}\\{p_i\\}$.
71 |
72 | By requesting a random number $\gamma$ from the verifier, the prover can prove that the vectors { $p_i$ } and { $q_i$} are equal in the multiset sense through the following equation:
73 | $\prod_{i \in [n]}(\gamma - p_i) = \prod_{i \in [n]}(\gamma - q_i)$
74 |
75 | 2. **Product Proof:**
76 | As mentioned earlier, the multiplication process is converted into a series of single multiplications using auxiliary vectors. Interestingly, two multiplications can be merged into one, as shown here:
77 | $\prod_{i \in [n]} \frac{(\gamma - p_i)}{(\gamma - q_i)} = 1.$
78 |
79 | ### From Multiset Equality to Permutation Proof:
80 |
81 | If two vectors $\vec{a}$ and $\vec{b}$ satisfy a permutation $\sigma$, the combined vectors $\vec{a}'$ and $\vec{b}'$ will satisfy the multiset equality relationship. By combining vectors and position values, treating $(a_i, i)$ as one element and $(b_i, \sigma(i))$ as another element, a "permutation proof" can be converted into a "multiset equality." By requesting a random number $\beta$ from the verifier, the tuples can be "folded" into a single value.
82 |
83 | $$
84 | \begin{array}{|c|c | c|c|}
85 | a_i & {i} & b_i & \sigma({i}) \\
86 | \hline
87 | a_0 & 0 & b_0=a_1 & 1 \\
88 | a_1 & 1 & b_1=a_0 & 0 \\
89 | a_2 & 2 & b_2=a_3 & 3 \\
90 | a_3 & 3 & b_3=a_2 & 2 \\
91 | \vdots & \vdots & \vdots & \vdots \\
92 | a_{n-1} & n-1 & b_{n-1}=a_n & n \\
93 | a_n & n & b_n=a_{n-1} & n-1 \\
94 | \end{array}
95 | $$
96 |
97 | $$
98 | \begin{array}{|c|c|}
99 | a'_i=(a_i, i) & b'_i=({b}_i, \sigma(i)) \\
100 | \hline
101 | (a_0, 0) & (b_0=a_1, 1) \\
102 | (a_1, 1) & (b_1=a_0, 0) \\
103 | \vdots & \vdots \\
104 | (a\_{n-1}, n-1) & (b\_{n-1}=a\_{n}, n) \\
105 | (a\_n, n) & (b\_n=a\_{n-1}, n-1) \\
106 | \end{array}
107 | $$
108 |
109 | $$
110 | \begin{array}{|c|c|}
111 | a'_i=(a_i+\beta\cdot i) & b_i'=(b + \beta\cdot \sigma(i)) \\
112 | \hline
113 | (a_0 + \beta\cdot 0) & (b_0 + \beta\cdot 1) \\
114 | (a_1 + \beta\cdot 1) & (b_1 + \beta\cdot 0) \\
115 | \vdots & \vdots \\
116 | (a\_{n-1} + \beta\cdot n-1) & (b\_{n-1} + \beta\cdot n) \\
117 | (a\_n + \beta\cdot n) & (b\_n + \beta\cdot (n-1))\\
118 | \end{array}
119 | $$
120 |
121 | The verification process leverages multiset equivalence as a stepping stone to prove the existence of a permutation between two vectors, which relies on random challenges and polynomial encoding to ensure the validity of the proof.
122 |
--------------------------------------------------------------------------------
/Plonk/co-learn notes/Eta/04_Copy_Constraints_Optimization.md:
--------------------------------------------------------------------------------
1 | # 04. Copy Constraints and Optimization
2 |
3 |
4 |
5 | | title |
6 | tags |
7 |
8 |
9 | | 04. Copy Constraints and Optimization |
10 |
11 |
12 |
13 | | zk-meme |
14 | basic |
15 | quick_read |
16 | Copy_Constraints_Optimization |
17 |
18 |
19 | |
20 |
21 |
22 |
23 | [Github](https://github.com/ETAAcademy)|[Twitter](https://twitter.com/ETAAcademy)|[ETA-ZK-Meme](https://github.com/ETAAcademy/ETAAcademy-ZK-Meme)
24 |
25 | Authors: [Eta](https://twitter.com/pwhattie), looking forward to your joining
26 |
27 | ## Plonk Protocol: Copy Constraints and Position Vector Optimization
28 |
29 | ### Copy Constraints
30 |
31 | The copy constraints in the Plonk protocol ensure that the values of certain variables remain consistent across different columns of the W table. This is necessary for the protocol to correctly verify the computation of a circuit.
32 |
33 | **Table W**
34 |
35 | $$
36 | \begin{array}{c|c|c|c|}
37 | i & w_a & w_b & w_c \\
38 | \hline
39 | 0 & 0 & 0 & {\color{green}out} \\
40 | 1 & {\color{red}x_6} & {\color{blue}x_5} & {\color{green}out} \\
41 | 2 & x_1 & x_2 & {\color{red}x_6} \\
42 | 3 & x_3 & x_4 & {\color{blue}x_5} \\
43 | \end{array}
44 | $$
45 |
46 | **Table of IDs**
47 |
48 | $$
49 | \begin{array}{c|c|c|c|}
50 | i & id_{a,i} & id_{b,i} & id_{c,i} \\
51 | \hline
52 | 0 & 0 & 4 & {\color{green}8} \\
53 | 1 & {\color{red}1} & {\color{blue}5} & {\color{green}9} \\
54 | 2 & 2 & 6 & {\color{red}10} \\
55 | 3 & 3 & 7 & {\color{blue}11} \\
56 | \end{array}
57 | $$
58 |
59 | **Permutation Vectors**
60 |
61 | Introduce permutation vectors $\sigma_a, \sigma_b, \sigma_c:$
62 |
63 | $$
64 | \begin{array}{c|c|c|c|}
65 | i & \sigma_{a,i} & \sigma_{b,i} & \sigma_{c,i} \\
66 | \hline
67 | 0 & 0 & 4 & {\color{green}9} \\
68 | 1 & {\color{red}10} & {\color{blue}11} & {\color{green}8} \\
69 | 2 & 2 & 6 & {\color{red}1} \\
70 | 3 & 3 & 7 & {\color{blue}5} \\
71 | \end{array}
72 | $$
73 |
74 | **Prover's Process**
75 |
76 | The prover uses random numbers $\beta$ and $\gamma$ provided by the verifier to merge and permute vectors, obtaining the multisets $f_i$ and $g_i$, which could be encoded into polynomials:
77 |
78 | $$
79 | \begin{split}
80 | f(X)&=\Big(w_a(X)+\beta\cdot {id_a}(X)+\gamma\Big)\Big(w_b(X)+\beta\cdot {id_b}(X)+\gamma\Big)\Big(w_c(X)+\beta\cdot {id_c}(X)+\gamma\Big)\\
81 | g(X)&=\Big(w_a(X)+\beta\cdot {\sigma_a}(X)+\gamma\Big)\Big(w_b(X)+\beta\cdot {\sigma_b}(X)+\gamma\Big)\Big(w_c(X)+\beta\cdot {\sigma_c}(X)+\gamma\Big)\\
82 | \end{split}
83 | $$
84 |
85 | **Auxiliary Vector $\vec{z}$**
86 |
87 | Construct $\vec{z}$ to represent intermediate steps:
88 |
89 | $$
90 | z_0 = 1, \qquad z_{i+1}=z_i\cdot \frac{f_i}{g_i}\\
91 | $$
92 |
93 | $$
94 | \begin{array}{|c|c|c|}
95 | i & H_i & z_i\\
96 | \hline
97 | 0 & \omega^0=1 & 1\\
98 | 1 & \omega^1 & 1\cdot \frac{f_0}{g_0}\\
99 | 2 & \omega^2 & \frac{f_0}{g_0}\cdot \frac{f_1}{g_1}\\
100 | 3 & \omega^3 & \frac{f_0f_1}{g_0g_1}\cdot \frac{f_2}{g_2}\\
101 | \vdots & & \vdots\\
102 | N-1 & \omega^{N-1} & \frac{f_0f_1\cdots f_{N-3}}{g_0g_1\cdots g_{N-3}}\cdot \frac{f_{N-2}}{g_{N-2}} \\
103 | N & \omega^{N}=1 & \frac{f_0f_1\cdots f_{N-1}}{g_0g_1\cdots g_{N-1}} = 1
104 | \end{array}
105 | $$
106 |
107 | If $\vec{f}$ and $\vec{g}$ are equivalent, $z_N = 1$. This is verified by ensuring:
108 |
109 | $$
110 | z(\omega^0) = 1
111 | $$
112 |
113 | $$
114 | z(\omega\cdot X)g(X) = z(X)f(X)
115 | $$
116 |
117 | where:
118 |
119 | - $z_0$ is an initial value of 1
120 | - $z_i$ is the value of the copy constraint at step $i$
121 | - $f_i$ is a polynomial expression representing the value of a variable at step $i$
122 | - $g_i$ is a polynomial expression representing the value of a variable at step $i$
123 | - $X$ is a variable
124 | - $\omega$ is a generator of the multiplicative subgroup $H$
125 |
126 | ### Position Vector Optimization
127 |
128 | The σ vectors only need to use distinct values to mark the permutations, not necessarily increasing natural numbers. If we use H = (1, ω, $ω^2,$ ...), then the polynomial ${id_a}(X)$ will be greatly simplified:
129 |
130 | $$
131 | \begin{split}
132 | \vec{id}_a &= (1,\omega,\omega^2,\omega^3)\\
133 | \vec{id}_b &= (k_1,k_1\omega,k_1\omega^2,k_1\omega^3)\\
134 | \vec{id}_c &= (k_2,k_2\omega,k_2\omega^2,k_2\omega^3)\\
135 | \end{split}
136 | $$
137 |
138 | where $k_i$ are distinct quadratic non-residues.
139 |
140 | $$
141 | id_a(X) = X, \quad id_b(X) = k_1 \cdot X, \quad id_a(X) = k_2 \cdot X
142 | $$
143 |
144 | If there are more columns in σ, then we need to choose multiple $k_1, k_2, k_3, ... = g^1, g^2, g^3, ...$ where g is a generator of the multiplicative subgroup T, and $|T|\*2^λ = p-1.$
145 |
146 | ### Public Inputs
147 |
148 | $$
149 | \begin{array}{c|c|c|c|}
150 | i & q_L & q_R & q_M & q_C & q_O \\
151 | \hline
152 | 0 & 0 & 0 & 0 & 99 & 1 \\
153 | 1 & 0 & 0 & 1 & 0 & 1 \\
154 | 2 & 1 & 1 & 0 & 0 & 1 \\
155 | 3 & 0 & 0 & 1 & 0 & 1 \\
156 | \end{array}
157 | $$
158 |
159 | To prove that a circuit output equals a specific public value (e.g., out=99), the simplest method is to use the $q_C$ column with constraints $q_L = q_R = q_M = 0:$
160 |
161 | $q_C(X) - q_O(X)w_c(X) = 0$
162 |
163 | This method fixes the public values as constants, requiring recomputation of the $q_C(X)$ polynomial if values change, which is inefficient.
164 |
165 | Introduce a new column $\phi$ for public parameters, which allow public input changes without affecting other parts of the circuit. The new arithmetic constraint is:
166 |
167 | $q_L(X)w_a(X) + q_R(X)w_b(X) + q_M(X)w_a(X)w_b(X) - q_O(X)w_c(X) + q_C(X) + \phi(X) = 0$
168 |
169 | In summary, handling public inputs efficiently in the Plonk protocol involves introducing a dedicated column for public parameters to avoid frequent recalculations of constraint polynomials. Additionally, optimizing position vectors and managing copy constraints with auxiliary vectors and random merging helps ensure the integrity and efficiency of the proof system.
170 |
--------------------------------------------------------------------------------
/Plonk/README.md:
--------------------------------------------------------------------------------
1 | # Plonk Course
2 |
3 | ## 基本信息
4 |
5 | ZKP(零知识证明)技术为加密行业带来了新的叙事和活力,ZKP 和区块链的结合正在经历快速发展和广泛应用的过程,充满着巨大的想象和潜力, 而当下只有较少人踏足,这意味着 **ZK 领域仍是一片蓝海**。
6 |
7 | **无论是从理论层面还是工程实践层面,想要高效学习 ZKP,PLONK 是绝佳之选。**
8 |
9 | PLONK 理论基础扎实,它借鉴了很多经典 ZKP 技术的理论基础,如算术电路、查找表、内积证明等,很多后续的优化方案,包括 PlonkUp、UltraPlonk、Halo2 等,都是 PLONK 家族的一员。**随着对 ZKP 性能和可扩展性需求的不断提高,PLONK 家族方案已成为目前最受欢迎和应用最广泛的 ZKP 系统之一。**
10 |
11 | 除此以外,PLONK 工程价值极高,创新地使用了新的算术电路编码方案和新的开箱即用(out-of-the-box)证明系统,为构建高效、可扩展的通用零知识证明系统奠定了基础,包括 Starkware 和 zkSync 的以太坊二层网络,Filecoin 等分布式存储项目、Mina 和 Aleo 等隐私区块链,**众多热门项目都使用或基于 PLONK 实现**。
12 |
13 | 只有全面深入研习 PLONK 的理论基础、数学原理和工程实践,克服知识的"诅咒",才能嗅得金蔷薇的纯粹芬芳。
14 |
15 | 围绕 PLONK,我们准备了系列课程,面向有一定 ZKP 相关的数学和理论基础者,**每节课程将结合具体的例子和代码,带你全面构建 PLONK 的认知框架**,帮你更好理解有关理论基础的实际运用,并带你深入 PLONK 的理论和工程代码实践。
16 |
17 | ### 课程安排
18 |
19 | * **课程形式:** 线上视频直播课程 + 代码实践
20 | * **开营时间:** 5月26日
21 | * **课程时间:** 共计5周,每周二、周四20:00~21:30上课。
22 | * **线上答疑:** [Github Discussion](https://github.com/Antalpha-Labs/zkp-academy/discussions/categories/q-a)
23 | * **课程目标:** 通过本课程的学习,学习者将更加深入地理解 Plonk 协议的底层原理,如 Plonk 算术化、置换证明、算术约束、多项式承诺、Lookup等,并有能力用代码实现一个完整的 Plonk 证明流程。
24 |
25 | ### 前置知识
26 |
27 | 对 ZKP 有一定的了解,了解 ZKP 中的基本概念。如果不了解也没关系,推荐同时学习这门课程[Zero Knowledge Proofs](https://zk-learning.org/)。
28 |
29 | ### 工作人员
30 |
31 | * 👨🏫 讲师:
32 | * 郭宇:SECBIT Labs (安比实验室)创始人,曾经高校教育从业者,关注领域为零知识证明,智能合约安全,程序语言理论。
33 | * Yan:中科大本硕博,科大软件学院网安方向教师,当前兴趣包括AI和区块链,持续学习中。
34 | * Wangyao:数学博士(未完成)研究 ZK,学习 FHE,探索代数学和密码学的相交地带。
35 | * Jade:ZK 开发者@安比实验室。电子科技大学数学硕士,热爱数学与密码学,致力于将理论知识转化为实际应用。
36 | * Po:EthStorage ZK Researcher, 半路出家区块链,持续学习 DA 和 ZK 前沿研究。
37 | * Yingfei:密码学博士生, interested in lattice-based zero-knowledge proofs and signatures。
38 | * Harry Liu:零知识证明(ZKP)技术爱好者, 在个人学习的同时, 也积极在社区进行分享和组织各种 ZKP 相关的活动。
39 | * 👨🎓 助教:
40 | * Harold:“zkp 真的是太好玩啦!”,喜欢开源。
41 | * Purple:文转码,zkp 学习ing。
42 | * Jade:ZK 开发者@安比实验室。电子科技大学数学硕士,热爱数学与密码学,致力于将理论知识转化为实际应用。
43 |
44 | ### 开营 AMA
45 | * 视频回放 [开营 AMA](https://www.youtube.com/watch?v=3h972SlVsoI)
46 |
47 | ## 课程表
48 |
49 | ### Lesson 1【5月28日周二】 ZKP & Plonk overivew
50 |
51 | 在第一次课程中,我们将对 ZKP 和 Plonk 有个整体的认识,知道 Plonk 在 ZKP 发展中的位置,并认识到其重要性。
52 |
53 | * 主讲老师:郭宇
54 | * 课程回放:[YouTube 链接](https://youtu.be/OOBD7cnR1J4)
55 | * 补充材料:[课程笔记](https://github.com/Antalpha-Labs/zkp-academy/blob/main/Plonk/lesson%201/whyplonk%202024-05-28.pdf)
56 |
57 | ### Lesson 2【5月30日周四】 Plonk 算术化
58 |
59 | 我们将理解引入 Plonkish 算术化的优点,清楚它与 R1CS 的区别,并掌握 Plonkish 算术化的具体过程。
60 |
61 | * 主讲老师:Yan
62 | * 课程回放:[Youtube 链接](https://youtu.be/L3qMBzPgfWY)
63 | * 课程笔记:[链接](https://github.com/sec-bit/learning-zkp/blob/master/plonk-intro-notebook-zh/1-plonk-arithmetization.ipynb)
64 | * 补充材料:[理解 PLONK(一):Plonkish Arithmetization](https://github.com/sec-bit/learning-zkp/blob/master/plonk-intro-zh/1-plonk-arithmetization.md)
65 | * 补充材料:[分享理解 PLONK 原理 一](https://www.youtube.com/watch?v=HtKmRcSJUG4&list=PLbQFt1T_44DwN1zWl-KWhkp3s0LAkF2a8&index=5&t=376s)
66 |
67 | ### Lesson 3【6月4日周二】 Plonk 中的多项式
68 |
69 | 我们将深入多项式编码的细节,掌握多项式编码将多个约束压缩成一个约束的具体过程。
70 |
71 | * 主讲老师:Wangyao
72 | * 课程回放:[Youtube 链接](https://youtu.be/bNGac1CJEKM)
73 | * 课程幻灯片
74 | * 补充材料:[理解 PLONK(二):多项式编码](https://github.com/sec-bit/learning-zkp/blob/master/plonk-intro-zh/2-plonk-lagrange-basis.md)
75 | * 补充材料:[分享 PLONK 原理 二](https://www.youtube.com/watch?v=O5HGp3EHDI0&list=PLbQFt1T_44DwN1zWl-KWhkp3s0LAkF2a8&index=4)
76 |
77 | ### Lesson 4【6月6日周四】 置换证明
78 |
79 | 我们将深入理解置换证明底层原理。
80 |
81 | * 主讲老师:Wangyao
82 | * 课程回放:[Youtube 链接](https://youtu.be/B7ubzpXSpqI)
83 | * 课程幻灯片
84 | * 补充材料:[理解 PLONK(三):置换证明](https://github.com/sec-bit/learning-zkp/blob/master/plonk-intro-zh/3-plonk-permutation.md)
85 |
86 | ### 2nd Office Hour 【6月8日周六】
87 |
88 | * 答疑老师:郭宇、Wangyao、Harry、Keep...
89 | * 答疑回放:[Youtube 链接](https://youtu.be/SkTmEwbBx-I)
90 |
91 | ### Lesson 5【6月11日周二】 Plonk中的约束
92 |
93 | 我们将掌握算术约束与拷贝约束的底层原理。
94 |
95 | * 主讲老师:Jade
96 | * 课程回放:[Youtube 链接](https://youtu.be/J1P60urkGwc)
97 | * 课程幻灯片: [链接](/Plonk/lesson%205/PLONK%20-%20Lecture%205%20-%20算术约束与拷贝约束.pdf)
98 | * 课程代码: [链接](/Plonk/lesson%205/plonk-lecture5-constraints.ipynb)
99 | * 补充材料:[理解 PLONK(四):算术约束与拷贝约束](https://github.com/sec-bit/learning-zkp/blob/master/plonk-intro-zh/4-plonk-constraints.md)
100 |
101 | ### Lesson 6【6月13日周四】 Plonk中的多项式承诺
102 |
103 | 我们将明白什么是多项式承诺,掌握 KZG10 的多项式承诺构造。
104 |
105 | * 主讲老师:Po
106 | * 课程回放:[Youtube 链接](https://youtu.be/yEH23SwxCG0)
107 | * 课程幻灯片
108 | * 补充材料:[理解 Plonk(五):多项式承诺](https://github.com/sec-bit/learning-zkp/blob/master/plonk-intro-zh/5-plonk-polycom.md)
109 |
110 | ### 3rd Office Hour 【6月15日周六】
111 |
112 | * 答疑老师:郭宇、Harry、Kurt Pan...
113 | * 答疑回放:[Youtube 链接](https://youtu.be/qagV_-Sqb9o)
114 |
115 | ### Lesson 7【6月18日周二】 Lookup Gate
116 |
117 | 我们将深入 Lookup 的细节,学习 Lookup Gate 不同方案以及优化。
118 |
119 | * 主讲老师:Yingfei
120 | * 课程回放:[Youtube 链接](https://youtu.be/pmO6p9Q-x6g)
121 | * 课程幻灯片:[链接](/Plonk/lesson%207/Plonk.pdf)
122 | * 补充材料:[理解 PLONK(七):Lookup Gate](https://github.com/sec-bit/learning-zkp/blob/master/plonk-intro-zh/7-plonk-lookup.md)
123 | * 补充材料:[分享理解 PLONK 原理 三 Lookup argument](https://www.youtube.com/watch?v=StvnHnC4Dk4&list=PLbQFt1T_44DwN1zWl-KWhkp3s0LAkF2a8&index=3)
124 |
125 | ### Lesson 8【6月20日周四】 Custom Gate & Lookup Gate
126 |
127 | 我们将明白 Custom Gate 的底层原理。
128 |
129 | * 主讲老师:Yingfei
130 | * 课程回放:[Youtube 链接](https://youtu.be/I6asKtO8Q8E)
131 | * 课程幻灯片:[链接](/Plonk/lesson%208/plookup%20and%20custom%20gates.pdf)
132 | * 补充材料:
133 |
134 | ### 4th Office Hour 【6月22日周六】
135 |
136 | * 答疑老师:Harry...
137 | * 答疑回放:[Youtube 链接](https://youtu.be/DRfMGSvaluQ)
138 |
139 | ### Lesson 9【6月25日周二】 代码实践
140 |
141 | 我们将从代码入手,实现一个完整的 Plonk 协议。
142 |
143 | * 主讲老师:Harry Liu
144 | * 课程回放:[Youtube 链接](https://youtu.be/lHEJuYYk3VU)
145 | * 课程幻灯片
146 | * 补充材料:[Baby Plonk](https://github.com/Antalpha-Labs/baby-plonk)
147 |
148 | ## 作业
149 |
150 | ## Co-learn notes bounty
151 |
152 | 为鼓励学员学习与分享,本课程推出 Co-learn notes bounty 活动,学员可以将学习中的内容整理成个人笔记提交到 Plonk/co-learn notes 目录下,收录后每篇笔记给出 200CNY 的 bounty,并发布在 Antalpha-Labs 公众号上。笔记主题围绕 ZKP 相关技术,不局限于 Plonk 协议。
153 |
154 | ## References
155 |
156 | * [理解 Plonk 协议](https://github.com/sec-bit/learning-zkp/tree/master/plonk-intro-zh)
157 | * [Plonk intro notebook](https://github.com/Antalpha-Labs/plonk-intro-notebook?tab=readme-ov-file)
158 |
159 | **联系方式**:添加小助手微信 Coset2025
160 | **备注**:不要吝啬给我们一个 star 哦~
161 |
--------------------------------------------------------------------------------
/ZKVM/README.md:
--------------------------------------------------------------------------------
1 | # zkVM Course
2 |
3 | ## Background
4 |
5 | zkVM 作为一种结合零知识证明(Zero-Knowledge Proof, ZKP)和虚拟机(Virtual Machine, VM)的新型技术,背后承载了多个领域的努力,包括密码学、区块链、分布式系统和计算理论,才走到如今,被普遍认为是突破区块链和分布式系统技术瓶颈的「潜力股」。然而,无法否认的是 zkVM 的学习较为艰难。收集了各方的需求和问题,我们发现 zkVM 的学习主要存在以下现实难题:
6 |
7 | 首先,zkVM 学习门槛相对较高。除了所用到的高级数学理论、证明系统设计以及计算的复杂性;还有为了支持通用计算,要比传统虚拟机更加复杂的设计;此外,零知识证明与虚拟机的架构要无缝结合的需求,也带来了额外的复杂性。
8 |
9 | 其次,zkVM 缺少学习材料。现在通用的 zkVM,如 Risc Zero、SP1、Miden VM、zkWASM,大部分的文档材料并不完善,并且很多关于工程类的问题难以深究,对个人来说需要耗费巨大精力,学习阻力很大。
10 |
11 | 针对上述问题,本次课程将作为学习 zkVM 系列的起步课程,后续会有更多的进阶课程。通过理论讲解和代码实践相结合的方式,从基础到进阶帮助大家全面掌握 zkVM。
12 |
13 | ## Intro
14 |
15 | ### 1. 课程时间:
16 |
17 | 2024 年 12 月 30 日 - 2015 年 1 月 27 日 (4 周)
18 |
19 | ### 2. 课程形式:
20 |
21 | - 🧑🏫 线上直播授课(Zoom),每周一节课(1-1.5h/节)
22 |
23 | - 📢 课程通知、交流讨论(微信群)
24 |
25 | - 💬 线上答疑:https://github.com/Antalpha-Labs/zkp-academy/discussions/categories/q-a
26 |
27 | ### 3. 课程目标:
28 |
29 | 通过本期共学,参与学员将对 zkVM 形成一个高层认知,可以了解到 zkVM 的历史发展与未来的发展机会,其系统架构、虚拟机(VM) 、prover 架构设计,以及最起码会使用一个 zkVM。
30 |
31 | ## Course materials
32 |
33 | 1. [Lita - zkVM](https://www.lita.foundation/blog/zero-knowledge-paradigm-zkvm)
34 | 2. [RiscZero - zkVM](https://dev.risczero.com/api/zkvm)
35 | 3. [SP1 - zkVM](https://docs.succinct.xyz/docs/introduction)
36 | 4. [awesome-zkvm](https://github.com/rkdud007/awesome-zkvm?tab=readme-ov-file)
37 | 5. [zkMIPS](https://learnblockchain.cn/column/99)
38 | 6. [All about zkVM by Stephen Duan](https://oxidized-relation-91c.notion.site/All-about-zkVM-112f0a489b988062b4b8c51f825c2f4e)
39 | 7. [Brainfuck STARK Tutorial](https://neptune.cash/learn/brainfuck-tutorial/#wikipediaonbfdialects)
40 |
41 | ## Class schedule
42 |
43 | 【第一周课程安排】
44 |
45 | - 第一节课:zkVM 的历史和现状
46 | - 讲师:wangyao,时间:12 月 31 日晚 8 点(星期二)
47 | - 课程回放:[Youtube 链接](https://youtu.be/xoGte-TzHHk)
48 | - 参考资料:
49 | - [A guide to Zero Knowledge Proofs](https://medium.com/@Luca_Franceschini/a-guide-to-zero-knowledge-proofs-f2ff9e5959a8) Explains basics of zkp, especially IOP and PCS.
50 | - [The different types of ZK-EVMs](https://vitalik.eth.limo/general/2022/08/04/zkevm.html)
51 | - [Jolt](https://eprint.iacr.org/2023/1217)
52 | - 课件:[链接](https://github.com/Antalpha-Labs/zkp-academy/blob/main/ZKVM/lesson%201/zkvm-wangyao.pdf)
53 | - 第二节课:深入解析 Jolt
54 | - 讲师:Backdoor,时间:2025 年 1 月 2 日晚 8 点(星期四)
55 | - 课程回放:[Youtube 链接](https://youtu.be/lFUYsULyUNY)
56 | - 课件:[Jolt & Lasso: for Newbies](https://doutv.notion.site/Jolt-Lasso-for-Newbies-1591aee049b480b7a44ad7d00e3e9265?pvs=4)
57 | - 推荐阅读:[Lasso + Jolt - YouTube](https://www.youtube.com/playlist?list=PLjQ9HCQMu_8xjOEM_vh5p26ODtr-mmGxO)
58 | - [Binius: highly efficient proofs over binary fields](https://vitalik.eth.limo/general/2024/04/29/binius.html)
59 | - [Jolt - JoltBook](https://jolt.a16zcrypto.com/how/jolt.html)
60 | - [Jolt R1CS - How + why we rewrote Circom in Rust 🦀](https://x.com/samrags_/status/1820429579787423759?s=46) | Sam Ragsdale
61 | - [A Technical Dive into Jolt: The RISC-V zkVM](https://www.zksecurity.xyz/blog/posts/how-jolt-works/)
62 | - [往期 jolt 学习小组视频](https://github.com/Antalpha-Labs/zkp-academy/issues/1)
63 | - 第一周思考题(作业):[discussion](https://github.com/Antalpha-Labs/zkp-academy/discussions/66)
64 | - 答疑:周六晚上 8 点
65 |
66 | 【第二周课程安排】
67 | - 第三节课:zkwasm 介绍
68 | - 讲师:Sinka,时间:2025年1月7日晚8点(星期二)
69 | - 课程回放:[Youtube 链接](https://youtu.be/ZwibS4uGEj4)
70 | - 第四节课:zkVM 的虚拟机 (VM) 简析
71 | - 讲师:johnxu,时间:2025 年 1 月 9 日晚 8 点(星期四)
72 | - 课程回放:[Youtube 链接](https://www.youtube.com/watch?v=KxxeyKTksxs)
73 | - 推荐阅读:
74 | - [Building a RISC-V simulator in Rust](https://gregchadwick.co.uk/blog/building-rrs-pt1/)
75 | - [Zero Knowledge Proof — Introduction to SP1 zkVM Source Code](https://trapdoortech.medium.com/zero-knowledge-proof-introduction-to-sp1-zkvm-source-code-d26f88f90ce4)
76 | - [Memory management in VM](https://blog.tigris.fr/2019/07/28/writing-an-emulator-memory-management/)
77 | - [Writing a simple RISC-V emulator in plain C](https://fmash16.github.io/content/posts/riscv-emulator-in-c.html)
78 | - 课件:[链接](https://github.com/Antalpha-Labs/zkp-academy/blob/main/ZKVM/lesson%204/Introduce%20the%20zkVM.pdf)
79 | - 第二周思考题(作业):[discussion](https://github.com/Antalpha-Labs/zkp-academy/discussions/69)
80 | - 答疑:周六晚上 8 点
81 |
82 | 【第三周课程安排】
83 |
84 | - 第五节课:zkVM 电路设计与 prover 证明
85 | - 讲师: Dream, 时间:2025 年 1 月 14 日晚 8 点(星期二)
86 | - 课程回放:[Youtube](https://youtu.be/avAIjRvgwqc)
87 | - 第六节课:zkVM 电路设计与 prover 证明
88 | - 讲师: Dream, 时间:2025 年 1 月 16 日晚 8 点(星期四)
89 | - 课程回放:[Youtube](https://youtu.be/sALgu6tHEhs)
90 | - 答疑:周六晚上 8 点
91 |
92 | 【第四周课程安排】
93 |
94 | - 第七节课:ZKM 的 prover 证明详解
95 | - 导师:Daniel,时间:2025 年 1 月 21 日晚 8 点(星期二)
96 | - 课程回放:[Youtube](https://youtu.be/KlhQns_8QII)
97 | - 课件:[链接](https://github.com/coset-io/zkp-academy/blob/main/ZKVM/lesson%207/ZKM%20Prover%E5%9F%BA%E6%9C%AC%E6%9E%84%E9%80%A0%E8%AF%BE%E7%A8%8B.pptx)
98 | - 第八节课:zkVM 实操讲解
99 | - 导师:johnxu,时间:2025 年 1 月 23 日晚 8 点(星期四)
100 | - 课程回放:[Youtube](https://youtu.be/rSNyOY1U7x0)
101 | - 答疑:周六晚上 8 点
102 |
103 | 【课后作业】
104 | @所有人 本期课程全部结束🎉,目前有四个作业给到大家,其实也是思考题,大家可以挑选任意一个(里面的任何一个问题)解答,这些问题也是帮助大家更了解zkVM,提前祝大家过节好呀🧧!
105 | [第一周作业](https://github.com/coset-io/zkp-academy/discussions/66)
106 |
107 | [第二周作业](https://github.com/coset-io/zkp-academy/discussions/69)
108 |
109 | [zkVM课程作业(三)Add instruction in SP1](https://github.com/coset-io/zkp-academy/discussions/70)
110 |
111 | [zkVM系列课程作业(四) 性能分析](https://github.com/coset-io/zkp-academy/discussions/71)
112 |
113 |
114 | ## Mentors & Assistants
115 |
116 | - **Dream:** 前 Scroll Core Engineer, Blocksight 作者。数学&密码学持续学习者,前爱立信,微软高级工程师,区块链与隐私计算一线工程研发。
117 | - **wangyao:** fluent zk 工程师。数学博士(未完成)研究 ZK,学习 FHE,探索代数学和密码学的相交地带。
118 | - **郭宇:** SECBIT Labs (安比实验室)创始人,曾经高校教育从业者,关注领域为零知识证明,智能合约安全,程序语言理论。
119 | - **backdoor:** OKX ZK Dev,代码和理论两手抓,希望跟大家多交流学习~
120 | - **johnxu:** zk 和 rust 爱好者, 密码学工程师
121 | - **Daniel:** 浙江大学博士后研究员,密码学博士,曾在 NDSS,TIFS 等旗舰会议和期刊发表多篇论文,主要研究方向为安全多方计算和零知识证明。
122 | - **Harold:** 研究 zk 协议 todolist 望不到头的人,偶尔会做一些技术分享,欢迎大家来一起讨论~
123 | - **Kyrin:** 区块链方向博士,zkp 技术爱好者,与大佬们学习最新技术。
124 |
125 | ## Co-learning bounty
126 |
127 | - 为鼓励学员学习与分享,本课程继续 Co-learn notes bounty 活动,学员可以将学习中的内容整理成个人笔记提交到 [co-learn notes](https://github.com/Antalpha-Labs/zkp-academy/tree/main/ZKVM/co-learn-notes) 目录下,收录后每篇笔记给出 200 CNY 的 bounty,并发布在 Coset 公众号上。
128 |
129 | - 报名助教,积极回答技术问题,推动学员一起学习,不止退回押金,还可以收获 200 CNY 的 bounty。
130 |
131 | \*笔记主题围绕 ZKP 相关技术,不局限于 zkVM。
132 |
133 | **联系方式**:添加小助手微信 Coset2025
134 |
135 | ## Sponsor
136 |
137 |
138 |
--------------------------------------------------------------------------------
/Plonk/lesson 6/poly_commit.py:
--------------------------------------------------------------------------------
1 | from ec import (default_ec, G1Generator, G2Generator)
2 | from poly_utils import PrimeField
3 | import random
4 | from fft import fft
5 | from pairing import ate_pairing
6 | from fields import Fq
7 |
8 | class PolyCommit:
9 | def __init__(self):
10 | self.modulus = default_ec.n
11 | self.pf = PrimeField(self.modulus)
12 | self.secret = random.randint(0, self.modulus -1)
13 | self.G1 = G1Generator()
14 | self.G2 = G2Generator()
15 | self.G1Vec = []
16 | self.G2Vec = []
17 |
18 | def getSetupG1Vec(self, length):
19 | for i in range(len(self.G1Vec), length):
20 | self.G1Vec.append(self.G1 * (self.secret ** i))
21 | return self.G1Vec[0:length]
22 |
23 | def getSetupG2Vec(self, length):
24 | for i in range(len(self.G2Vec), length):
25 | self.G2Vec.append(self.G2 * (self.secret ** i))
26 | return self.G2Vec[0:length]
27 |
28 | # g: root of unity
29 | def getCommitment(self, evals, g):
30 | coeffs = fft(evals, self.modulus, g, True)
31 | g1vec = self.getSetupG1Vec(len(coeffs))
32 | return sum( s * c for s,c in zip(g1vec, coeffs))
33 |
34 | def getCommitmentByCoeffs(self, coeffs):
35 | g1vec = self.getSetupG1Vec(len(coeffs))
36 | return sum( s * c for s,c in zip(g1vec, coeffs))
37 | def getG2CommitmentByCoeffs(self, coeffs):
38 | g2vec = self.getSetupG2Vec(len(coeffs))
39 | return sum( s * c for s,c in zip(g2vec, coeffs))
40 |
41 | def getSingleProofAtEvalIdx(self, evals, g, idx):
42 | # qx = (fx - y0)/ (x = x0)
43 | coeffs = fft(evals, self.modulus, g, True)
44 | x0 = self.pf.exp(g, idx)
45 | y0 = evals[idx]
46 | coeffs[0] = coeffs[0] - y0
47 | qx = self.pf.div_polys(coeffs, [self.modulus - x0, 1])
48 | g1Vec = self.getSetupG1Vec(len(qx))
49 | return x0, y0, sum( s * c for s,c in zip(g1Vec, qx))
50 |
51 | def verifySingleProof(self, commitment, proof, x0, y0):
52 | pairLeft = ate_pairing(commitment + (self.G1 * y0).negate(), self.G2)
53 | g2 = self.getSetupG2Vec(2)[1] # g2 * secret
54 | pairRight = ate_pairing(proof, g2 + (self.G2 * x0).negate())
55 | assert pairLeft == pairRight, "Pairing check failed"
56 |
57 | import unittest
58 | class Test(unittest.TestCase):
59 | def test_single_proof(self):
60 | pc = PolyCommit()
61 | evals = [101,12,13,24] # f(x)
62 | G = pc.pf.exp(7, (pc.pf.modulus -1) // 4)
63 | commitment = pc.getCommitment(evals, G)
64 | print("poly commitment:", commitment)
65 |
66 | # random
67 | idx = random.randint(0, len(evals)-1)
68 | x0, y0, evaluation_proof = pc.getSingleProofAtEvalIdx(evals, G, idx)
69 | print("evaluation point:", idx, x0, y0)
70 | print("evaluation proof:", evaluation_proof)
71 |
72 | pc.verifySingleProof(commitment, evaluation_proof, x0, y0)
73 | print("proof verification check passed")
74 |
75 | def test_multi_openning_proofs(self):
76 | pc = PolyCommit()
77 | G = pc.pf.exp(7, (pc.pf.modulus -1) // 4)
78 | f1_evals = [1,2,3,4]
79 | f2_evals = [4,5,6,7]
80 | commit_f1 = pc.getCommitment(f1_evals, G)
81 | commit_f2 = pc.getCommitment(f2_evals, G)
82 |
83 | ## Verifier send random number v
84 | idx = random.randint(0, max(len(f1_evals), len(f2_evals)) -1)
85 |
86 | ## Prover calculate q(x) = q1(x) + v * q2(x)
87 | x0, y1_0, q1_x = pc.getSingleProofAtEvalIdx(f1_evals, G, idx) # xo is the random number
88 | _, y2_0, q2_x = pc.getSingleProofAtEvalIdx(f2_evals, G, idx)
89 | proof = q1_x + q2_x * x0
90 | ## pairing check
91 | cg = commit_f1 + commit_f2 * x0
92 | yg = y1_0 + y2_0 * x0
93 | pc.verifySingleProof(cg,proof,x0, yg)
94 | print("multi opening proof check passed")
95 |
96 | def test_shplonk(self):
97 | # shplonk
98 | pc = PolyCommit()
99 | f1_evals = [10,20,30,40]
100 | f2_evals = [4,5,6,7]
101 | G = pc.pf.exp(7, (pc.pf.modulus -1) // 4)
102 | idxs_1 = [0,1]
103 | idxs_2 = [0,1,2]
104 |
105 | ## calculate ri(x)
106 | xs_1 = [pc.pf.exp(G, idx) for idx in idxs_1]
107 | ys_1 = [f1_evals[idx] for idx in idxs_1]
108 | rx_1 = pc.pf.lagrange_interp(xs_1, ys_1)
109 |
110 | xs_2 = [pc.pf.exp(G, idx) for idx in idxs_2]
111 | ys_2 = [f2_evals[idx] for idx in idxs_2]
112 | rx_2 = pc.pf.lagrange_interp(xs_2, ys_2)
113 |
114 | ## bind all polynomials of fi(x)
115 | gama = pc.pf.exp(G, random.randint(0, 4))
116 |
117 | print("r1_coeffs:", pc.pf.degree(rx_1))
118 | print("r2_coeffs:", pc.pf.degree(rx_2))
119 |
120 | # Prover makes the bound-together quotient polynomial
121 | # zx_1 = pc.pf.lagrange_interp(xs_1, [0]*len(xs_1))
122 | zx_1 = pc.pf.zpoly(xs_1)
123 | # zx_2 = pc.pf.lagrange_interp(xs_2, [0]*len(xs_2))
124 | zx_2 = pc.pf.zpoly(xs_2)
125 | print("zx_1_coeffs:", pc.pf.degree(zx_1))
126 | print("zx_2_coeffs:", pc.pf.degree(zx_2))
127 | ztx = zx_2
128 | fx_1 = fft(f1_evals, pc.modulus, G, True)
129 | fx_2 = fft(f2_evals, pc.modulus, G, True)
130 | print("fx_1_coeffs:", pc.pf.degree(fx_1))
131 | print("fx_1_coeffs:", pc.pf.degree(fx_2))
132 | hx_1 = pc.pf.div_polys(pc.pf.sub_polys(fx_1, rx_1), zx_1)
133 | hx_2 = pc.pf.div_polys(pc.pf.sub_polys(fx_2, rx_2), zx_2)
134 | print("hx_1_coeffs:", pc.pf.degree(hx_1))
135 | print("hx_2_coeffs:", pc.pf.degree(hx_2))
136 | hx = pc.pf.add_polys(hx_1, pc.pf.mul_by_const(hx_2, gama))
137 | print("hx_coeffs:", pc.pf.degree(hx))
138 |
139 | ## proofs
140 | fx_1_commit = pc.getCommitmentByCoeffs(fx_1) # c1
141 | fx_2_commit = pc.getCommitmentByCoeffs(fx_2) # c2
142 | rx_1_commitG1 = pc.getCommitmentByCoeffs(rx_1)
143 | rx_2_commitG1 = pc.getCommitmentByCoeffs(rx_2)
144 | zt_div_z1_commitG2 = pc.getG2CommitmentByCoeffs(pc.pf.div_polys(ztx, zx_1))
145 | zt_div_z2_commitG2 = pc.getG2CommitmentByCoeffs(pc.pf.div_polys(ztx, zx_2))
146 | ztx_commitG2 = pc.getG2CommitmentByCoeffs(ztx)
147 | proof = pc.getCommitmentByCoeffs(hx)
148 |
149 | ## verfier checks the proofs
150 | pair_left_1 = ate_pairing(fx_1_commit + rx_1_commitG1.negate(), zt_div_z1_commitG2)
151 | pair_left_2 = ate_pairing(
152 | (fx_2_commit + rx_2_commitG1.negate())*gama,
153 | zt_div_z2_commitG2
154 | )
155 | pair_left = pair_left_1 * pair_left_2
156 | pair_right = ate_pairing(proof, ztx_commitG2)
157 | assert pair_left == pair_right, "pairing check failed"
158 |
159 |
160 |
161 |
162 | if __name__ == '__main__':
163 | unittest.main(verbosity=2) # run all test cases
--------------------------------------------------------------------------------
/lattice/co-learn-notes/10.Lattice ZKP Implementation Lantern, Lattirust and Labrador & Greyhound PoC-note-by MT.md:
--------------------------------------------------------------------------------
1 | Author:MT
2 | https://github.com/mountaintower/learningzkp
3 |
4 | # 参考文献
5 |
6 | Lattice-Based Zero-Knowledge Proofs Implementing Lantern
7 | https://lattice-zk.isec.tugraz.at/
8 |
9 | Greyhound PCS PoC https://wiki.lacom.io/wiki/cryptography/greyhound-poc
10 |
11 | https://github.com/lattirust/lattirust
12 |
13 | https://github.com/NethermindEth/latticefold
14 |
15 | https://hackmd.io/@Ingonyama/fast-labrador-prover
16 |
17 | # Lattice-Based Zero-Knowledge Proofs Implementing Lantern
18 |
19 | ## 目录
20 |
21 | 1. [介绍](https://lattice-zk.isec.tugraz.at/#1.-Introduction)
22 |
23 | 1.1 [零知识证明](https://lattice-zk.isec.tugraz.at/#1.1-Zero-Knowledge-Proofs)
24 |
25 | 1.2 [格密码](https://lattice-zk.isec.tugraz.at/#1.2-Lattice-Cryptography)
26 |
27 | 2. [相关工作](https://lattice-zk.isec.tugraz.at/#2.-Related-Work)
28 |
29 | 3. [Lantern 零知识证明方法](https://lattice-zk.isec.tugraz.at/#3.-Lantern-Zero-Knowledge-Proof-Approach)
30 |
31 | 3.1 [承诺方案](https://lattice-zk.isec.tugraz.at/#3.1-Commitment-Scheme)
32 |
33 | 3.2 [线性关系](https://lattice-zk.isec.tugraz.at/#3.2-Linear-Relations)
34 |
35 | 3.3 [二次关系](https://lattice-zk.isec.tugraz.at/#3.3-Quadratic-Relations)
36 |
37 | 4. [实现](https://lattice-zk.isec.tugraz.at/#4.-Implementation)
38 |
39 | 4.1 [预备知识](https://lattice-zk.isec.tugraz.at/#4.1-Preliminaries)
40 |
41 | 4.1.1 [多项式环 Polynomial ring](https://lattice-zk.isec.tugraz.at/#4.1.1-Polynomial-Rings)
42 |
43 | 4.1.2 [随机分布和抽样](https://lattice-zk.isec.tugraz.at/#4.1.2-Random-Distributions-and-Sampling)
44 |
45 | 4.1.3 [拒绝抽样](https://lattice-zk.isec.tugraz.at/#4.1.3-Rejection-Sampling)
46 |
47 | 4.1.4 [挑战空间](https://lattice-zk.isec.tugraz.at/#4.1.4-Challenge-Space)
48 |
49 | 4.2 [ABDLOP 承诺Opening证明——在$\mathcal{R_q}$ 上的线性证明](https://lattice-zk.isec.tugraz.at/#4.2-ABDLOP-Commitment-Opening-Proof-with-Linear-Proofs-over-Rq)
50 |
51 | 4.3 [$\mathbb{Z_q}$上的线性证明](https://lattice-zk.isec.tugraz.at/#4.3-Linear-Proofs-over-Zq)
52 |
53 | 4.4 [$\mathcal{R_q} $上的二次证明](https://lattice-zk.isec.tugraz.at/#4.4-Quadratic-Proofs-over-Rq)
54 |
55 | 4.5 [$\mathbb{Z_q}$ 上的二次证明](https://lattice-zk.isec.tugraz.at/#4.5-Quadratic-Proofs-over-Zq)
56 |
57 | 4.6 [模-LWE 秘密的知识证明](https://lattice-zk.isec.tugraz.at/#4.6-Proving-Knowledge-of-a-Module-LWE-Secret)
58 |
59 | 4.7 [用于证明格关系的工具箱](https://lattice-zk.isec.tugraz.at/#4.7-Toolbox-for-Proving-Lattice-Relations)
60 |
61 | 4.8 [基准代码](https://lattice-zk.isec.tugraz.at/#4.7-Benchmark-Code)
62 |
63 | 5. [基准测试](https://lattice-zk.isec.tugraz.at/#5.-Benchmarks)
64 |
65 | 6. [结论](https://lattice-zk.isec.tugraz.at/#Conclusion)
66 |
67 | ## 1 介绍
68 |
69 | 2022年提出的Lantern(LNP)是高效的对MLWE秘密(及其它格statement)的知识证明算法,比19年基于Hash的Aurora(实际效率基本不可用),证明格statement的效率高。
70 |
71 | 但该算法的Proof大小,验证时间没有那么好,不是简洁的,是交互式的。
72 |
73 | ### 1.1 ZKP
74 |
75 | ZKP三个性质:正确性,可靠性,零知识性。
76 |
77 | 为了达到ZKP先要理解承诺方案:分为两步。一方承诺一个选定值(作为秘密),稍后打开/open这个值;其它方可验证这个值与承诺是对应的。有两个性质:隐藏和绑定。
78 |
79 | 承诺原语一般基于DL。直接给DL承诺,如$g^s$,验证会泄露s。Schnorr协议通过增加对y的承诺$g^y$,公开$z\leftarrow y+ cs$,可以让P证明知识s(验证:$g^z \overset {?}= w t^c$),但不会泄露s给V。
80 |
81 | 但在格里要求范数小的问题会对协议造成困难,原本y只需要在Zq均匀抽样,但这样y就太大导致z太大,而且y的取值还要不能泄露s(格的多边形分布)。那么就需要比较小y,因此y是从高斯分布采样且不是随机的。由于y不是随机的,z需要拒绝采样、防止泄露s的信息。另外,格中的c也要小,要在特定挑战空间中采样。
82 |
83 | ### 1.2 格密码
84 |
85 | Lantern协议建立在多项式环上的MLWE和MSIS问题上。
86 |
87 | MSIS可以用来做承诺:$\bold{t=As}$;打开:$\bold {s}$,要求||$\bold {s}$||小
88 |
89 | 09年Lyubashevsky提出基于格的Schnorr证明,与上面的Schnorr类似,验证:$||\bold{z}|| \overset {?} \leq B, \bold{w \overset {?} = Az} -c\bold{t}$
90 |
91 | 证明了知道一个$\bold {\overline s} \in \mathcal{R_q}$ ,使得$\bold{A\overline s}=c\bold{t}$,且其范数大于||$\bold {s}$||。
92 |
93 | 这里的P计算$\bold{z}$时,需要拒绝采样。具体原因1.1已说明。
94 |
95 | 以上协议已经可以做签名了,比如Dilithium(ML-DSA)就是其非交互式版本。但是上面说的提取的$\bold {\overline s}$范数大于$\bold{s}$ (实际上是个relaxed版本)通常会导致效率或功能问题。比如基于Regev风格的格加密方案:$\bold{A\overline s}=c\bold{t}$,$\bold{s}$(包括明文消息)是随机的,$\bold{t}$是密文。解密时,$\bold{t}$必须有短的原像。但模约简的proof不能保证$\bold{s}$是短的,只能保证$c\bold{t}$有短的原像(解密算法不知道c)。
96 |
97 | 而Lantern就不用放松了,是精确的证明。
98 |
99 | ## 2 相关工作
100 |
101 | Lantern的证明大小最小:13KB,接近最低的8KB。
102 |
103 | ## 3 Lantern 零知识证明方法
104 |
105 | 关键在于证明$\bold{s}$的范数是小的,即$\mathbb{Z}$上的二次关系:$<\bold{s},\bold{s}><=B^2, B \in \mathbb{Z}$。
106 |
107 | 先用承诺方案在$\mathcal{R_q}$上证明线性关系,然后在$\mathbb{Z_q}$上,最后在$\mathbb{Z}$上。
108 |
109 | 然后用承诺方案证明$\mathcal{R_q}$上的二次关系,然后是$\mathbb{Z_q}$上,最后为了在$\mathbb{Z}$上证明二次关系,混合了$\mathbb{Z}$上的线性关系和$\mathbb{Z_q}$上的二次性关系。
110 |
111 | ### 3.1 承诺方案
112 |
113 | 结合Ajtai($\bold{A_1s_1+A_2s_2=t}$)和BDLOP,提出ABDLOP承诺。
114 |
115 | $\bold{s_1}$是秘密,$\bold{s_2}$是随机数。
116 |
117 | ### 3.2 线性关系
118 |
119 | $\mathcal{R_q}$上的线性关系(用Ajtai举例说明):
120 |
121 | 除了对Ajtai承诺($\bold{A_1s_1+A_2s_2=t}$)中的$\bold{s_1} \in \mathcal{R_q}$证明线性关系,再加一个:$\bold{-Rs_1+0 s_2=r}$ 即 $\bold{Rs_1+r =0}$,证明了$\mathcal{R_q}$上的给定线性关系。
122 |
123 | $\mathbb{Z_q}$上的线性关系:
124 |
125 | 接下来可以用代数等式提升证明,得到$\mathbb{Z_q}$上的线性关系。
126 |
127 | 两个多项式系数向量($\bold{a,b} \in \mathcal{R_q}$)内积($\mathbb{Z_q}$上的线性关系)$\langle \mathbf{a},\mathbf{b} \rangle$可以用之前讲的多项式乘积($\mathcal{R_q}$上的线性关系)$ct(\langle\sigma({\mathbf{a}}), \mathbf{b}\rangle)$计算。这里采用的是环自同构结构,与之前讲的$\sigma$不太一样,但结果相同。
128 |
129 | $\mathbb{Z}$上的线性关系:
130 |
131 | 这里用到第8次课 LaBRADOR第6页的JL引理:如果$||\Pi \vec{s}||_2$ 够小,那么$||\vec{s}||_2$ 也够小,其中,$\Pi $是个抽样产生的只包含0(1/2概率),1(1/4概率),-1(1/4概率) 的矩阵。
132 |
133 | Lantern的定理:如果$||\bold{z=y+Cs}\ mod\ q||_2$ 够小,那么$||\bold{z}||_2$ 也够小。但这只是近似的短证明,$\bold{z}$并不是和$\bold{s}$完全一样大,因为有$\bold{y}$和$\bold{C}$,但现在可以近似验证没有大于模q的情况发生。
134 |
135 | ### 3.2 二次关系
136 |
137 | 每个协议都会实现自己的二次关系。
138 |
139 | ## 4 实现
140 |
141 | 注意4.1.2 使用的随机函数random并不安全,实践中应该替换。
142 |
143 |
144 |
145 | # Greyhound PCS PoC
146 |
147 | 1 Gadget矩阵构造
148 |
149 | 1.1 什么是Gadget矩阵
150 |
151 | 1.2 数学定义
152 |
153 | 1.3 二进制分解(Gadget Inverse)
154 |
155 | 1.3.1 算法
156 |
157 | 1.3.2 为什么用二进制分解
158 |
159 | 2 LaBRADOR承诺方案
160 |
161 | 2.1 概述
162 |
163 | 2.2 数学架构
164 |
165 | 2.2.1 内承诺
166 |
167 | 2.2.2 外承诺
168 |
169 | 2.3 承诺打开
170 |
171 | 2.3.1 打开组件
172 |
173 | 2.3.2 验证条件
174 |
175 | 3 证明二次关系
176 |
177 | 3.1 概述
178 |
179 | 3.2 协议结构
180 |
181 | 3.3 验证条件
182 |
183 | 3.4 Prover实现
184 |
185 | 3.5 Verifier实现
186 |
187 | 4 减少证明大小
188 |
189 | 4.1 证据太大的问题
190 |
191 | 4.2 解决办法:承诺w
192 |
193 | 4.3 修改协议
194 |
195 | 4.4 额外验证
196 |
197 | 4.5 实现:优化协议
198 |
199 | 5 多项式求值证明
200 |
201 | 5.1 从二次关系到多项式求值
202 |
203 | 5.2 提高批效率构建
204 |
205 | 5.3 二次关系
206 |
207 | 5.4 协议流
208 |
209 | 5.5 优点
210 |
211 | 5.6 实现:多项式求值
212 |
213 | 5.7 多变量多项式框架
214 |
215 | 5.7.1 向量-矩阵-向量 表示
216 |
217 | 5.8 FS变换
218 |
219 | 6 结论和应用
220 |
221 | 6.1 成果总结
222 |
223 | 6.2 Greyhound PCS的关键优点
224 |
225 | 参考文献:2篇
226 |
227 |
228 |
229 | # 其它
230 |
231 | 今天讲的都是Python,区块链用Rust很多。
232 |
233 | LaBRADOR和Greyhound原文都有C实现,但细节过多,不建议。
234 |
235 | lattirust实现了LaBRADOR:[https://github.com/lattirust/lattirust]()
236 |
237 | 借鉴上面的代码,实现了latticefold:[https://github.com/NethermindEth/latticefold]()
238 |
239 | 比较快的实现了LaBRADOR,可以直接看末尾的rust:[https://hackmd.io/@Ingonyama/fast-labrador-prover]()
240 |
--------------------------------------------------------------------------------
/lattice/co-learn-notes/08.LaBRADOR-note-by MT.md:
--------------------------------------------------------------------------------
1 | Author:MT
2 | https://github.com/mountaintower/learningzkp
3 |
4 | 01
5 | LaBRADOR是基于lattice的SNARKs,声称是第一个和不基于lattice的方案代价相近(即practical)
6 |
7 | 02 术语
8 | $\vec{a} \in \mathbb{Z}_q^m$:m维向量
9 | $\mathbf{a} \in \mathcal{R}_q$:模d阶的多项式环上的多项式,$ct(\mathbf{a})=a_0$,即constant term(多项式的常数项$a_0$)。如果多项式 $\mathbf{a}$ 有d-1阶,那么多项式 $\mathbf{a}$ 可以对应于一个d维向量 $\vec{a}$ (每个分量是多项式的系数)
10 | $\vec{\mathbf{a}} \in \mathcal{R}_q^m$:m维多项式向量
11 |
12 | $\sigma(\mathbf{a})$:与 $\mathbf{a}$ 的系数相同,X的幂次取 $\mathbf{a}$ 对应项幂次的负数
13 |
14 | 内积IP :向量$\vec{a}, \vec{b}$ 内积和多项式向量$\vec{\mathbf{a}}, \vec{\mathbf{b}}$ 内积的计算是类似的,都是做对应维的多项式分量$a_i$和$b_i$的乘积,再求和
15 |
16 | 多项式分量$a_i$和$b_i$的乘积计算:对应多项式$a_i$和$b_i$中每一项的乘积,累加求和得到新的多项式
17 |
18 | $\langle \vec{a},\vec{b} \rangle=ct(\langle\sigma(\vec{\mathbf{a}}), \vec{\mathbf{b}}\rangle)$
19 |
20 | 即:先做多项式向量内积Σ$\sigma(a_i)b_i$,然后对每个多项式$\sigma(a_i)$和$b_i$ 的每一项逐个做乘法,然后累加,没有消掉的X的丢弃,消掉X的是常数项,即两个多项式的系数相乘累加
21 |
22 | 03 LaBRADOR 关系 $\mathcal{R}$
23 | Rank-1 Quadratic Constraint Systems(R1CS)是一种用于描述计算问题的约束系统,由一组线性和二次约束组成,这些约束可以表示为矩阵形式的等式:
24 | $A \vec{z} \circ B \vec{z} = C \vec{z}$
25 | 其中, $\circ$ 表示向量的哈达玛积(即逐元素乘积)。这个等式表示的是,如果存在一个向量 $\vec{z}$,使得 $A \vec{z}$ 和 $B \vec{z}$ 的逐元素乘积等于$C \vec{z}$,则 R1CS 是可满足的。
26 |
27 | 实际上,等于$A$的每一行与向量$\vec{z}$ 做内积 $\circ$ $B$的每一行与向量$\vec{z}$ 做内积 = $C$的每一行与向量$\vec{z}$ 做内积
28 |
29 | LaBRADOR 关系中的$f(\mathbf{\vec{s_1}},...,\mathbf{\vec{s_r}})=\mathbf{0}$ 计算可以覆盖R1CS 的计算,上述R1CS约束中的向量$\vec{z}$ 包含witness 和instance
30 |
31 | f' 用于保证$\mathbf{\vec{s_i}}$ 的范数够小,使用ct 节省了验证开销,只对应256个关系而不是f函数的256*d大小
32 |
33 | Bulletproof也是内积arg,通过将(左右边界)向量压缩减少大小,每一轮减少1/2。
34 | lattice无法直接用bulletproof直接做递归的原因:
35 |
36 | 假设用rewind技巧,把bulletproof的$\vec{s}$ 拆成左L右R两部分,取两次challenge c和c',那么可得到$\vec{s_R} = (c'-c)^{-1}(\vec{s_c'}-\vec{s_c})$
37 |
38 | 首先,c'-c 不一定可逆,第二,即使可逆,由于c 的缘故,$\vec{s_R}$ 的范数不一定够小
39 |
40 | LaBRADOR 用投影解决了这个问题
41 |
42 | 04 概述
43 |
44 | 1)承诺:承诺所有$\mathbf{\vec{s_i}}$ 向量,因为上面的关系未必是绑定的
45 |
46 | 2)投影:重点,证明$\mathbf{\vec{s_i}}$ 向量范数小于$β^2$
47 | 3)聚合结果:但cost还是mr
48 |
49 | 4)摊销:开销变为m
50 |
51 | 5)验证
52 |
53 | 05 承诺的承诺
54 | 第一次承诺:用ajtai承诺r个$\mathbf{\vec{s_i}}$ ,$com=\mathbf{\vec{t_i}}=\mathbf{A\vec{s_i}} \in \mathcal{R_q^K}$,$\mathbf{A}$ 是$k*m$ 的,$\mathbf{\vec{s_i}}$ 是$m*1$ 的,承诺的长度是 r 个 $\mathcal{K}$ 维 $\mathbf{\vec{t_i}}$
55 |
56 | 再次承诺:将上述承诺$\mathbf{\vec{t_i}}$ 串接起来再次承诺。但这样的 $\mathbf{\vec{t_i}}$ 长度无法保证小,所以可以把$\mathbf{\vec{t_i}}$ 二进制分解为多个分向量(只有bit大小),将这些分向量连接起来、再做承诺,这样大小就变小了
57 |
58 | 06 投影:降低范数
59 |
60 | 根据模JL 引理:如果$||\Pi \vec{s}||_2$ 够小,那么$||\vec{s}||_2$ 也够小,其中,$\Pi$ 是个抽样产生的只包含0(1/2概率),1(1/4概率),-1(1/4概率) 的$256*d$ 的矩阵
61 |
62 | 07 投影方法
63 |
64 | 对每个$\vec{s_i}$,选择一个矩阵 $\Pi_i$
65 |
66 | 根据第2页向量内积计算等于多项式向量内积取常数项的公式:$\langle \vec{a},\vec{b} \rangle=ct(\langle\sigma(\vec{\mathbf{a}}), \vec{\mathbf{b}}\rangle)$,把向量$\vec{\pi}_i^{(j)}$ (即$\Pi_i$ 的第$j$ 行) 和 $\vec{s_i}$ 的向量内积转换为多项式向量内积 $\sigma(\bm{\vec{\pi}_i^{(j)}})$ 和$\mathbf{\vec{s_i}}$($\Pi$ 是公开的)
67 |
68 | 首先,保证范数在一定范围内。基于第6页的模JL 引理:
69 |
70 | 先发送 $\Pi \vec{s} =p $ ,再验证$p<\sqrt{30}b$ ,则$\mathbf{\vec{s}}$ 的范数满足要求
71 |
72 | 然后,验证$p$ 是正确的。根据上面所说的把向量内积转换为多项式向量内积的公式验证,实际上就是对应于第3页关系中的f'约束
73 |
74 | 08 压缩
75 | 压缩F’函数和256个投影函数压缩(随机合成)为1个$\mathbb{Z}_q$ 约束(也可以扩展为$\mathcal{R}_q$约束)
76 |
77 | 上面的约束+F函数,再压缩成1个$\mathcal{R}_q$约束
78 |
79 | 09 摊销
80 |
81 | 压缩后只有一个$\mathcal{R}_q$ 约束,形式是第3页的f函数,f函数左边有r个$\mathbf{\vec{s}} ( \vec z )$,故证据proof的大小是mr 个$\mathcal{R}_q$,摊销的目的是把大小减少为m 个$\mathcal{R}_q$
82 |
83 | 根据下一页的具体推导,验证公式中的每一项展开为:
84 |
85 | $f(\mathbf{\vec{s_1}},...,\mathbf{\vec{s_r}})\\ = \Sigma a_{i,j} \langle \mathbf{\vec{s_i}}, \mathbf{\vec{s_j}} \rangle + \Sigma \langle \bm{\vec{\phi_i}}, \mathbf{\vec{s_i}} \rangle - \mathbf{b} \\= \Sigma a_{i,j} g_{ij} + \Sigma h_{i,i} - \mathbf{b} \\= \mathbf{0}$
86 | 注意PPT的公式最右边$\bm{\vec{s_j}}$ 是$\bm{\vec{s_i}}$,只有在$\bm{\phi}$ 和$\bm{s}$ 下标 i=j 的时候,才需要
87 |
88 | 10 摊销方法:对$\mathbf{\vec{s_i}}$ 根据挑战$\mathbf{\vec{c}}$ 进行随机线性组合得到 $\mathbf{\vec z}=\mathbf{c_1} \mathbf{\vec{s_1}} + ... +\mathbf{c_r} \mathbf{\vec{s_r}}$
89 |
90 | 1)对第5页的ajtai承诺 $\mathbf{\vec{t_i}}=\mathbf{A\vec{s_i}}$,需要在不知道$\mathbf{\vec{s}}$ 的情况下,通过$\mathbf{\vec z}$ 来验证:
91 |
92 | 两边都乘以 $\mathbf{A}$,得到:$\mathbf{A\vec{z}}=\Sigma\mathbf{c_i\vec{t_i}}$ ,证明这个等式即可
93 |
94 | 2)对向量$\mathbf{\vec{s_i}}$ 和 $\mathbf{\vec{s_j}}$ 的内积,验证$\mathbf{\vec z}$ 和$\mathbf{\vec z}$ 的内积:
95 |
96 | $\langle \mathbf{\vec z},\mathbf{\vec z} \rangle \\= \langle \mathbf{c_1}\mathbf{\vec{s_1}} + ... +\mathbf{c_r} \mathbf{\vec{s_r}},\mathbf{c_1}\mathbf{\vec{s_1}} + ... + \mathbf{c_r} \mathbf{\vec{s_r}} \rangle \\= \mathbf{c_1}\mathbf{c_1} \langle \mathbf{\vec{s_1}}, \mathbf{\vec{s_1}} \rangle + \mathbf{c_1}\mathbf{c_2} \langle \mathbf{\vec{s_1}}, \mathbf{\vec{s_2}} \rangle + ... + \mathbf{c_1}\mathbf{c_r} \langle \mathbf{\vec{s_1}}, \mathbf{\vec{s_r}} \rangle \\+ \mathbf{c_2}\mathbf{c_1} \langle \mathbf{\vec{s_2}}, \mathbf{\vec{s_1}} \rangle + \mathbf{c_2}\mathbf{c_2} \langle \mathbf{\vec{s_2}}, \mathbf{\vec{s_2}} \rangle + ... + \mathbf{c_2}\mathbf{c_r} \langle \mathbf{\vec{s_2}}, \mathbf{\vec{s_r}} \rangle \\+ ...\\ + \mathbf{c_r}\mathbf{c_1} \langle \mathbf{\vec{s_r}}, \mathbf{\vec{s_1}} \rangle + \mathbf{c_r}\mathbf{c_2} \langle \mathbf{\vec{s_r}}, \mathbf{\vec{s_2}} \rangle + ... + \mathbf{c_r}\mathbf{c_r} \langle \mathbf{\vec{s_r}}, \mathbf{\vec{s_r}} \rangle $
97 |
98 | 这里的$\mathbf{\vec{c}}$ 是r*r 矩阵,与m 无关,每个$\mathbf{\vec{s_i}}$ 和 $\mathbf{\vec{s_j}}$内积和$\mathbf{\vec{c}}$ 无关(由于对称,只需要发送一半$\langle \mathbf{\vec{s_i}}, \mathbf{\vec{s_j}} \rangle$ 即可。实际上,可以设$g_{ij} = \langle \mathbf{\vec{s_i}}, \mathbf{\vec{s_j}} \rangle$,发送矩阵G即可
99 |
100 | 验证$g_{ij}$和$\langle \mathbf{\vec z},\mathbf{\vec z} \rangle$内积是否匹配,从而验证$g_{ij}$ 合法
101 | 3)对$\langle \bm{\vec{\phi_i}}, \mathbf{\vec{s_j}} \rangle$,验证:
102 |
103 | $\langle \bm{\vec{\phi_i}}, \mathbf{\vec{z}} \rangle \\ =\langle \bm{\vec{\phi_i}}, \mathbf{c_1} \mathbf{\vec{s_1}} + ... +\mathbf{c_r} \mathbf{\vec{s_r}} \rangle \\ = c_1\langle \bm{\vec{\phi_i}}, \mathbf{\vec{s_1}}\rangle + c_2\langle \bm{\vec{\phi_i}}, \mathbf{\vec{s_2}}\rangle + ... + c_r\langle \bm{\vec{\phi_i}}, \mathbf{\vec{s_r}}\rangle$
104 |
105 | 展开为r项,i再展开、总共发送$r^2$ 项,实际上也只需要发一半,设$h_{ij} = 1/2 (\langle \bm{\vec{\phi_i}}, \mathbf{\vec{s_j}} \rangle + \langle \bm{\vec{\phi_j}}, \mathbf{\vec{s_i}} \rangle)$ ,只有在$\bm{\phi}$ 和$\bm{s}$ 下标 i=j 的时候,才需要
106 |
107 | 这里的$\bm\phi$ 与后面的$\bm{b}$ 没有关系
108 |
109 | 现在讨论大小。$g_{ij} = \langle \mathbf{\vec{s_i}}, \mathbf{\vec{s_j}} \rangle$ ,故是短的,但$h_{ij}$ 不一定是短的,因为 $\bm\phi$ 可能是长的,可以再做分解
110 |
111 | 11
112 | 递归时,不直接发g,h,需发其承诺(先做分解)
113 |
114 | 12 验证
115 |
116 | P发送:$\bm{\vec t,\vec g,\vec h,\vec z}$
117 |
118 | V依次验证:
119 | 验证承诺:$\mathbf{A\vec{z}}\overset{?}=\Sigma\mathbf{c_i\vec{t_i}}$
120 | 验证$\bm{\vec g,\vec h}$正确:$\langle \mathbf{\vec z},\mathbf{\vec z} \rangle \overset{?}=\Sigma\mathbf{c_i c_j g_{ij}}, \Sigma c_i\langle \bm{\vec{\phi}_i}, \bm{\vec{z}} \rangle \overset{?}= \Sigma c_i c_j h_{ij} $
121 | 验证压缩后约束f:$f(\mathbf{\vec{s_1}},...,\mathbf{\vec{s_r}})\ = \Sigma a_{i,j} g_{ij} + \Sigma h_{i,i} - \mathbf{b} = \mathbf{0}$
122 | 验证$\bm{\vec t,\vec g,\vec h,\vec z}$ 是短的(范数小于β),其大小分别是$r,r^2, r^2, m$ ,若r是很小的常数,那么递归后rm变成m
123 |
124 | 以上是一步递归验证
125 |
126 | 13 递归
127 |
128 | P不发$\bm{\vec t,\vec g,\vec h,\vec z}$ ,将之视为witness,那么又有了一个新的LaBRADOR 关系 $\mathcal{R}$,可以再做一次递归
129 |
130 | z做多次递归会爆炸(见第10页),可以做分解解决
131 |
132 | LaBRADOR是类似Bulletproof,基于IPA的构造,不是基于PIOP+PCS的形式
133 |
134 | LaBRADOR对零知识性质的说明:对亚线性规模的证明系统而言,零知识性质并非关键;当证明长度确实短于见证长度时,非零知识的证明系统反而有有趣的应用场景。此外,只需设计一个简单的线性规模shim协议,即可将输入见证进行掩码,从而轻松实现零知识。该shim可与我们的非零知识证明系统组合,使得组合后的协议仍具备零知识性,且证明长度仅比原系统略有增加。基于上述原因,本文不再关注零知识性质。在与其他证明系统的所有比较中,我们均选用同样不具备零知识性质的版本。
--------------------------------------------------------------------------------
/Plonk/co-learn notes/Eta/05_Polynomial_Commitments.md:
--------------------------------------------------------------------------------
1 | # 05. Polynomial Commitments
2 |
3 |
4 |
5 | | title |
6 | tags |
7 |
8 |
9 | | 05. Polynomial Commitments |
10 |
11 |
12 |
13 | | zk-meme |
14 | basic |
15 | quick_read |
16 | Polynomial_Commitments |
17 |
18 |
19 | |
20 |
21 |
22 |
23 | [Github](https://github.com/ETAAcademy)|[Twitter](https://twitter.com/ETAAcademy)|[ETA-ZK-Meme](https://github.com/ETAAcademy/ETAAcademy-ZK-Meme)
24 |
25 | Authors: [Eta](https://twitter.com/pwhattie), looking forward to your joining
26 |
27 | ## Polynomial Commitments
28 |
29 | Polynomial commitment, `c = commit(x)`, is a cryptographic scheme that allows a prover to commit to a polynomial $f(X)$ in such a way that they can later prove that they know the value of $f(X)$ at a given point $x$ without revealing the entire polynomial.
30 |
31 | **Hash**
32 |
33 | The most basic construction of a polynomial commitment is to simply hash the coefficients of the polynomial. For example, if $f(X) = a_0 + a_1X + a_2X^2 + \cdots + a_nX^n$, then the commitment $C$ is:
34 |
35 | $$
36 | C = SHA256(a_0 || a_1 || a_2 || ... || a_n)
37 | $$
38 |
39 | **Petersen Commitment**
40 |
41 | Another construction is the Petersen commitment, using a set of randomly chosen bases to compute an ECC point:
42 |
43 | $$
44 | C = a_0 G_0 + a_1 G_1 + \cdots + a_n G_n
45 | $$
46 |
47 | **KZG Commitment**
48 |
49 | One of the most efficient construction is the KZG commitment, using a set of bases with internal algebraic structure $(G, \chi G, \chi^2G, \ldots, \chi^{d-1}G, H, \chi H)$. The KZG commitment to a polynomial $f(X)$ is:
50 |
51 | $$
52 | C_{f(X)} = a_0 G_0 + a_1 G_1 + \cdots + a_{n-1} G_{n-1}
53 | = a_0 G + a_1 \chi G + \cdots + a_{n-1}\chi^{n-1} G
54 | = f(\chi) G
55 | $$
56 |
57 | where $\chi$ is a random provided by a trusted third party, known as the trapdoor, which is destroyed after the setup phase. There is a bilinear pairing $e\in \mathbb{G}_1\times\mathbb{G}_2\to \mathbb{G}_T$, with $G\in \mathbb{G}_1$ and $H\in \mathbb{G}_2.$
58 |
59 | ## Optimization Round One🍄: Polynomial Remainder Theorem
60 |
61 | KZG is a powerful tool for proving knowledge of a polynomial without revealing the polynomial itself. However, they can be computationally expensive, especially when proving the value of the polynomial at a point. The polynomial remainder theorem can be used to optimize KZG polynomial commitments and reduce the computational cost of proving polynomial values.
62 |
63 | **Polynomial Remainder Theorem**
64 |
65 | To make KZG polynomial commitments more succinct, we can use the Polynomial Remainder Theorem:
66 |
67 | $$
68 | f(X) = q(X) \cdot (X - \zeta) + y
69 | $$
70 |
71 | The prover provides the commitment to the polynomial q(X), $C_q,$ to prove $f(\zeta) = y$. The verifier checks whether $[q(\chi)]$ satisfies the divisibility:
72 |
73 | $$
74 | (f(X)-y) \cdot 1 \overset{?}{=} q(X) \cdot (X - \zeta)
75 | $$
76 |
77 | Using Groth's notation, where $[1]_1 \triangleq G$ and $[1]_2 \triangleq H$ are generators of two groups, we can express the verification equation as:
78 |
79 | $$
80 | e(C\_{f(X)} - y[1]_1, [1]_2) \overset{?}{=} e(C\_{q(X)}, [\chi]_2 - \zeta [1]_2)
81 | $$
82 |
83 | To reduce the expensive operations on \(\mathbb{G}2\), we can simplify to:
84 |
85 | $$
86 | f(X) + \zeta \cdot q(X) - y = q(X) \cdot X
87 | $$
88 |
89 | Hence:
90 |
91 | $$
92 | e(C\_{f(X)} + \zeta\cdot C\_{q(X)} -y\cdot[1]_1,\ [1]_2)\overset{?}{=} e(C\_{q(X)},\ [\chi]_2)
93 | $$
94 |
95 | This equation is equivalent to the original equation, but it reduces the number of operations in $\mathbb{G}\_2$.
96 |
97 | ## Batch Verification of Multiple Polynomial Commitments
98 |
99 | One approach to batch verification is to use random linearization. Multiple polynomials can be combined into a larger polynomial using random numbers, allowing batch verification by opening at a single point:
100 |
101 | **Combining Two Polynomials**:
102 |
103 | - Given two polynomials $f_1(X)$ and $f_2(X)$, we can form a new polynomial $g(X) = f_1(X) + \nu \cdot f_2(X),$ where $\nu$ is a random number.
104 | - Similarly, $q(X) = q_1(X) + \nu \cdot q_2(X)$ leads to $[q(\chi)]\_1 = \pi = \pi_1 + \nu \cdot \pi_2.$
105 | - The commitment for the new polynomial g is $C_g = C_1 + \nu \cdot C_2.$
106 | - The value of the polynomial at a single point $X = \zeta$ can be computed as $y_g = y_1 + \nu \cdot y_2.$
107 | - The verifier checks the relation:
108 |
109 | $$
110 | e(C - y \cdot G_0, H_0) \overset{?}{=} e(\pi, H_1 - x \cdot H_0)
111 | $$
112 |
113 | **Combining Multiple Polynomials**:
114 |
115 | - For a more complex case, consider the polynomial constraint $f_1(X) f_2(X) + h_1(X) h_2(X) h_3(X) + g(X) = 0.$
116 | - The straightforward approach involves the prover opening the commitments at $X = \zeta$ and sending the evaluations and corresponding proofs for each polynomial:
117 |
118 | $$
119 | (f_1(\zeta),\pi_{f_1}),(f_2(\zeta),\pi_{f_2}),(h_1(\zeta),\pi_{h_1}),(h_2(\zeta),\pi_{h_2}),(h_3(\zeta),\pi_{h_3}),(g(\zeta),\pi_{g})
120 | $$
121 |
122 | - The verifier then checks all six evaluation proofs and verifies the polynomial constraint:
123 |
124 | $$
125 | f_1(\zeta)f_2(\zeta) + h_1(\zeta)h_2(\zeta)h_3(\zeta) + g(\zeta) \overset{?}{=} 0
126 | $$
127 |
128 | ## Optimization Round Two 🍄🏰: Reducing the Number of Openings
129 |
130 | we will further optimize the process by reducing the number of openings required.
131 |
132 | Consider a simple polynomial constraint of the form:
133 |
134 | - The prover first opens $\bar{f} = f(\zeta)$ and sends the proof $\pi_{f(\zeta)}.$
135 | - Introduce an auxiliary polynomial $L(X) = \bar{f} \cdot g(X) - h(X),$ then open $L(X)$ at $X = \zeta.$
136 |
137 | In this optimized scheme, the prover needs to open only twice. The first opening is $\bar{f},$ and the second opening is for the constant 0, which does not need to be sent to the verifier. Thus, the prover only needs to send two evaluation proofs. Using the aggregation method from the previous section, with a challenge number 𝜈, the prover can aggregate the two polynomial commitments and only needs to send one evaluation proof.
138 |
139 | **Complex Polynomial Constraint**
140 |
141 | Similarly, consider a more complex polynomial constraint involving six polynomials:
142 |
143 | $$
144 | f_1(X) f_2(X) + h_1(X) h_2(X) h_3(X) + g(X) = 0
145 | $$
146 |
147 | This constraint can be optimized by introducing an auxiliary polynomial:
148 |
149 | $$
150 | L(X) = \bar{f}_1 ⋅ f_2(X) + \bar{h}_1 \bar{h}_2 ⋅ h_3(X) + g(X)
151 | $$
152 |
153 | The verifier sends a random number $\nu$, and the prover computes the commitment of the folded polynomial:
154 |
155 | $$
156 | [F]_1 = [L]_1 + \nu ⋅ [f_1(\chi)]_1 + \nu^2 [h_1(\chi)]_1 + \nu^3 [h_2(\chi)]_1
157 | $$
158 |
159 | and the value of the folded polynomial at $X = \zeta$:
160 |
161 | $$
162 | E = \nu ⋅ \bar{f}_1 + \nu^2 ⋅ \bar{h}_1 + \nu^3 ⋅ \bar{h}_2
163 | $$
164 |
165 | The verifier checks the following bilinear mapping equation:
166 |
167 | $$
168 | e([F]_1 - [E]_1 + \zeta [q(\chi)]_1, [1]_2) \overset{?}{=} e([q(\chi)]_1, [\chi]_2)
169 | $$
170 |
171 | This optimized protocol reduces the prover's workload to sending only three openings and one evaluation proof, compared to the original six openings and six evaluation proofs, thus significantly reducing the communication overhead (i.e., the proof size).
172 |
173 | ### Conclusion
174 |
175 | Polynomial commitments are a powerful tool for proving knowledge of polynomials in a cryptographically secure way. They have a wide range of applications in cryptography and are likely to become even more important in the future as applications such as zk-SNARKs and zk-rollups become more widely adopted.
176 |
--------------------------------------------------------------------------------
/FRI&Stark/co-learn-notes/STARK 101 note by neuroney.md:
--------------------------------------------------------------------------------
1 | # STARK 101 学习笔记
2 |
3 | 该笔记是学习 STARKWARE 的 STARK 101 课程所做记录。
4 |
5 | ## STARK 101: 第一、二部分
6 |
7 | STARK 101 的第一部分和第二部分主要描述如何将一个具体问题算数化(arithmetization)。目前大多数的证明系统支持证明的语言都为多项式形式,因此我们在 STARK 中也需要算数化的过程。
8 |
9 | STARK 采用的证明系统是对近似性质的交互式随机预言机证明(Interactive Oracle Proofs of Proximity, IOPP),是基于交互式随机预言机证明(Interactive Oracle Proofs, IOP)的一个变体。IOP 是交互式证明(Interactive Proofs, IP)和概率可检验证明(Probabilistic Checkable Proofs, PCP)的结合,既允许证明者和验证者进行多轮交互(IP),也允许每轮交互中验证者可以随机访问证明者的证明(PCP)。
10 |
11 | 一个证明系统需要满足两个性质完备性(completeness)和健壮性(soundness),完备性要求诚实的证明者输出的证明可以通过验证,健壮性要求不诚实的证明者输出的证明不可以通过验证(通常情况下,这里的“可以”也可替换为“极大概率“)。
12 |
13 | 相较于 IOP,IOPP 在健壮性的要求上做出了让步,不诚实的证明者输出的证明和诚实的证明者输出的证明差异较大的情况下,才不可以通过验证。此时,如果不诚实的证明者输出的证明与诚实的证明者相差较小,也可能通过验证,增加了作恶的风险。
14 |
15 | STARK 的算术化利用了一种放大差异的特性,来避免这个问题,即不诚实的证明者总是输出差异较大的证明。
16 |
17 | ### 斐波拉契平方序列
18 |
19 | 在本课程中,我们将用 STARK 协议证明关于斐波拉契平方序列(Fibonacci Square, FibonacciSq)的声明。
20 |
21 | FibonacciSq 中的每一项为前两项的平方和,即给定 $a_0,a_1$,它的通项公式为: $a_{n+2}=a_{n+1}^2+a_{n}^2$。
22 |
23 | 如果在有限域 $`\mathbb{F}_q`$ 中,定义 FibonacciSq,那么通项公式为 $`a_{n+2}=a_{n+1}^2+a_{n}^2 \mod q`$。
24 |
25 | 示例:在有限域 $`\mathbb{F}_7`$ 中,有如下 FibonacciSq:$`1,3,3,4,4,4,\dots`$。
26 |
27 | 在本课程中,我们将用 STARK 协议证明如下声明:
28 |
29 | > 证明者知晓域元素 $`x=3141592\in \mathbb{F}_q`$,使得定义在 $`\mathbb{F}_q`$ 中的 FibonacciSq($`a_0 = 1, a_1 = x`$)有 $`a_{1022} = 2338775057`$,其中 $`q=3221225473 = 3 \cdot 2^{30} + 1`$。
30 |
31 | ### 低度扩展
32 |
33 | 低度扩展(Low Degree Extension, LDE)是一种在零知识证明系统(例如 STARK 协议)中使用的数学技术。它的主要目的是将定义在较小的集合上的函数扩展到较大的集合上,同时保持函数是一个低度多项式。
34 |
35 | LDE 一般分为三个步骤,输入、插值、扩展。
36 |
37 | 1. 输入:准备较小集合上的数据点(如 $( (x_1, y_1), (x_2, y_2), \dots, (x_n, y_n) $)。
38 | 2. 插值:使用拉格朗日插值法构建一个多项式 $f(x)$,使得 $\forall\ i \in [n], f(x_i) = y_i$。
39 | 3. 扩展:在较大的集合上,准备新的数据点坐标 $(x_1',x_2',\dots,x_n',\dots)$,计算多项式 $f(x)$ 在这些点上的值:$`(f(x_1'),P(x_2'),\dots,f(x_n'),\dots)`$。
40 |
41 | 在 STARK 中,我们需要对 FibonacciSq 序列做 LDE。具体步骤如下:
42 |
43 | 首先我们记有限域 $`\mathbb{F}_q`$ 所对应的乘法群为 $`\mathbb{F}_q^{\times}`$,其生成元为 $`w`$;记 $`\mathbb{F}_q^{\times}`$ 中一个较小的子群($`1024`$ 个元素)为 $`G=\{g^0,\dots,g^{1023}\}`$,一个较大的子群($`8192`$ 个元素)为 $`H=\{h^0,\dots,h^{8191}\}`$,斐波拉契平方序列 $`a=(a_0,\dots,a_{1022})`$。我们可以做如下 LDE:
44 |
45 | 1. 输入:准备较小集合上的数据点($`((g^0,a_0),(g^1,a_1),\dots,(g^{1022},a_{1022}))`$)。
46 | 2. 插值:使用拉格朗日插值法构建多项式 $`f(x)`$,使得 $`\forall\ i \in [0,1022], f(g^i) = a_i`$。
47 | 3. 扩展:在较大的集合上($`H`$ 的左陪集 $`wH=\{w\cdot h^0,w\cdot h^1,\dots,w\cdot h^{8191}\}`$)上,计算多项式 $f(x)$ 在这些点上的值:$`(f(w\cdot h^0),f(w\cdot h^1),\dots,f(w\cdot h^{8191}))`$。
48 |
49 | 原先我们对 $1023$ 个数据点进行插值,可以得到一个最高次为 $1022$ 的多项式,即包含了 $1022$ 个信息符号。LDE 通过在较大的集合上扩展多项式,得到 $8192$ 个点,实现了与 Reed-Solomon 编码类似的冗余信息生成能力,从而增强了信息的错误检测和纠正能力。
50 |
51 | #### Reed-Solomon 编码
52 |
53 | Reed-Solomon(RS)编码是一种广泛应用的纠错编码技术。假设有 $k$ 个信息符号,表示为 $\{m_0,m_1,\dots,m_{k-1}\}$,每个信息符号都是有限域 $\mathbb{F}_q$ 中的元素,这些符号可以构造多项式
54 | ```math
55 | P(x)=m_0+m_1x+\dots+m_{k-1}x^{k-1}.
56 | ```
57 | 这些符号的 RS 码字(Codeword) $\mathbf{c}$ 可以通过求多项式 $P(x)$ 在乘法群为 $\mathbb{F}_q^{\times}$ 上 $q$ 个不同点处的取值得到,即
58 | ```math
59 | \mathbf{c}=(P(\omega^0),\dots,P(\omega^{q-1})).
60 | ```
61 | 该码字可以表达为如下的线性方程组的形式:
62 |
63 | ```math
64 | \begin{bmatrix} 1 & \omega^0 & \cdots & \omega^0
65 | \\ 1 & \omega^1 & \cdots & \omega^{k-1}
66 | \\ \vdots & \vdots & \ddots & \vdots
67 | \\ 1 & \omega^{q-1} & \cdots & \omega^{(q-1)(k-1)}\end{bmatrix}
68 | \begin{bmatrix} m_0 \\ m_1 \\ \vdots \\ m^{k-1}\end{bmatrix}=
69 | \begin{bmatrix} P(\omega^0) \\ P(\omega^1) \\ \vdots \\ P(\omega^{q-1})\end{bmatrix}.
70 | ```
71 | 从码字 $\mathbf{c}$ 的任意 $k$ 个符号,我们都可以唯一的解出 $k$ 个变量 $\{m_0,m_1,\dots,m_{k-1}\}$。
72 |
73 | 码字 $\mathbf{c}$ 中隐藏了原始信息符号 $\{m_0,m_1,\dots,m_{k-1}\}$,如果我们构造多项式 $P(x)$ 使得 $P(\omega^0)=m_0,P(\omega^1)=m_1,\dots,P(\omega^{k-1})=m_{k-1}$,然后完成编码,这样得到的码字中没有隐藏原始的信息符号,所以能够使译码更加直观,正类似我们在 LDE 中所做的。
74 |
75 | ## 多项式约束
76 |
77 | 我们所要证明的关于 FibonacciSq 的陈述有 3 个已知条件(约束):
78 |
79 | 1. $a_0=1$,
80 | 2. $a_{1022}=2338775057$,
81 | 3. $a_{n+2}=a_{n+1}^2+a_{n}^2$。
82 |
83 | 如果 FibonacciSq 满足这三个约束,那么陈述为真,即证明者知道 $a_1=x$。
84 |
85 | 在 LDE 中,我们将 FibonacciSq 转化为了一个等价的多项式 $f(x)$,使得 $\forall\ i \in [0,1022], f(g_i) = a_i$,那么关于 FibonacciSq 的 3 个约束可以转化为 3 个多项式约束:
86 |
87 | 1. $f(g^0)=1$,
88 | 2. $f(g^{1022})=23387755057$,
89 | 3. $f(g^2x)=f(gx)^2+f(x)^2, {\rm where\ }x=g^i,0\leq i \leq 1020$。
90 |
91 | 根据因式定理(若多项式 $g(a)=0$,则多项式 $g(x)$ 必定含有因式 $x-a$,即 $\frac{g(x)}{x-a}$ 仍为多项式),上述三个条件可以转化为关于多项式整除的约束:
92 |
93 | 1. $p_0(x)=\frac{f(x)-1}{x-g^0}$,
94 | 2. $p_1(x)=\frac{f(x)-23387755057}{x-g^{1022}}$,
95 | 3. $p_2(x)=\frac{f(g^2x)-f(gx)^2-f(x)^2}{\prod_{i=0}^{1020}(x-g^i)}=\frac{f(g^2x)-f(gx)^2-f(x)^2}{(x^{1024}-1)/\prod_{i=1021}^{1023}(x-g^i)}$。
96 |
97 | 此时,如果多项式 $p_0(x),p_1(x),p_2(x)$ 都是多项式,那么陈述为真。
98 |
99 | 进一步地,我们可以选取随机数 $\alpha_0,\alpha_1,\alpha_2$,令 $CP=\alpha_0 p_0(x)+\alpha_1 p_1(x)+\alpha_2 p_2(x)$。此时,若 $CP$ 为多项式,那么 $p_0(x),p_1(x),p_2(x)$ 都是多项式,亦即若 $CP$ 为多项式,那么陈述为真。
100 |
101 | ## 承诺方案
102 |
103 | 在 STARK 中,使用的承诺(commitment)方案为默克尔树(Merkle Tree)。对一个多项式 $f(x)$ 的承诺方案为计算这个多项式在定义域中每个值 $x\in D$ 的多项式值 $f(x)$ 的哈希值,然后按照默克尔树的方案(如下图)计算出根节点哈希值,发送给验证者。
104 |
105 | 
106 |
107 | 在基于默克尔树的承诺方案中,验证者向证明者发出随机挑战(challenge)$`c`$,证明者计算函数值 $f(c)$,并生成对应的默克尔树路径(从需要验证的叶子节点开始,向上找到它的兄弟节点(即同一父节点的另一个子节点),将这些兄弟节点的哈希值依次记录,直到到达根节点。这个哈希值的序列就是默克尔树路径) 。
108 |
109 | 验证者可通过验证默克尔树路径最终生成的哈希是否与先前接受的根节点哈希值是否匹配,来确认挑战是否成功。
110 |
111 | ## STARK 101: 第三部分
112 |
113 | 第三部分介绍如何使用 FRI(Fast Reed-Solomon Interactive Oracle Proofs)证明 $CP$ 是多项式。
114 |
115 | ### 多项式的近似
116 |
117 | 在 FRI 中,我们并不直接证明 $CP$ 是多项式,而是证明 $CP$ 近似于一个低度的多项式。我们需要解决解决两个问题:何为近似,何为低度。
118 |
119 | 低度指的是证明者和验证者约定的度数边界,在本例中,低度是较小集合的基数。
120 |
121 | 近似指的是多项式之间的接近程度,我们可以采用如下定义:令 ${\sf Dis}(f,p)$ 为在函数 $f$ 的定义域 $D$ 中,函数值 $f(x)\neq p(x)$ 的 $x$ 的数量,我们称 ${\sf Dis}(f,p)$ 为函数 $f$ 和多项式 $p$ 的距离。 如果函数 $f$ 和多项式 $p$ 是近似的,那么 ${\sf Dis}(f,p)$ 很小。
122 |
123 | ### FRI 算子
124 |
125 | 一个 FRI 协议包括四个步骤:接收随机数 $\beta$,运行 FRI 算子(operator),承诺(commitment),重复上述三个步骤,最后发送证明。
126 |
127 | FRI 算子的具体操作为,对于一个随机数 $\beta$,将一个多项式函数 $`F_0(x)`$,表达为两个多项式之和,即 $`F_0(x)=g(x^2)+xh(x^2)`$,其中 $g(x^2)$ 的系数对应 $f(x)$ 中偶次幂的系数, $h(x^2)$ 的系数对应 $F(x)$ 中奇次幂的系数。
128 |
129 | 此时,构造新的多项式函数 $F_1(x)=g(x)+\beta h(x)$,$`F_1(x)`$ 的次数为 $F_0(x)$ 次数的一半(向下取整),$`F_1(x)`$ 定义域的大小亦为 $F_0(x)$ 定义域大小的一半(在 $F_0(x)$ 的定义域(乘法群)中,对每个元素计算其平方,可以得到 $F_1(x)$ 的定义域(乘法子群),其个数是 $F_0(x)$ 的定义域的一半)。
130 |
131 | FRI 算子的作用是折半减小问题的规模,例如,“证明一个定义域大小有 8192 个元素的函数 $f$ 近似于一个最高次数小于 1024 的多项式“。运行 1 次 FRI 算子之后,该问题可以变成“证明一个定义域大小有 4096 个元素的函数 $f$ 近似于一个最高次数小于 512 的多项式“。运行 FRI 算子 10 次后,问题可以变成“证明一个定义域大小有 8 个元素的函数 $f$ 近似于一个最高次数小于 1 的多项式“,即“证明一个定义域大小有 8 个元素的函数 $f$ 近似于一个常数“。
132 |
133 | ## STARK 101: 第四部分
134 |
135 | 第四部分介绍 FRI 中如何取信验证者,即证明者承诺了什么,验证者如何验证。
136 |
137 | ### 承诺
138 |
139 | 在证明者计算过程中,证明者首先拥有一条关于陈述的计算轨迹(trace),在本例中,为 LDE 的输出,即函数 $f$ 在较大集合上的函数值,我们对所有的函数值计算哈希值,作为默克尔树的叶子节点,并计算根节点的哈希值,记作 Trace Root。
140 |
141 | 其次,证明者将计算轨迹转换为多项式约束问题,得到一个多项式 $CP$,同样地,计算 $CP$ 在较大集合上的函数值,并计算其默克尔树,记根节点哈希值为 $CP$ Root。
142 |
143 | 令 $CP_0=CP$,在 FRI 过程中,第 $i$ 轮算子操作,验证者随机发送挑战 $\beta_i$ 给证明者,证明者折半当前的多项式 $CP_{i-1}$ 得到 $CP_i$,对 $CP_i$ 计算默克尔树,记根节点哈希值为 $CP_i$ Root。直到多项式 $CP_i$ 的次数小于 $1$。
144 |
145 | 最终,证明者,将所有的根节点哈希值(Trace Root, $CP$ Root, $CP_1$ Root, $\dots$)发送给验证者,见下图。这些根节点哈希值构成了证明者的承诺,即计算轨迹是正确的。
146 |
147 | 
148 |
149 | ### 验证
150 |
151 | 接下来,验证者将对证明者发起多轮挑战,来判断证明者承诺的正确性。
152 |
153 | 在每一轮挑战中,验证者随机发送挑战 $x$,$`x`$ 在较大的集合中。证明者首先计算该挑战在 Trace 中的函数值 $f(x),f(gx),f(g^2x)$(这三个值可以计算出 $CP(x)$)以及每个函数值对应的默克尔树路径,将函数值和对应的默克尔树路径发送给验证者。接下来在函数 $CP_0$ 以及 FRI 的每一轮算子操作得到的函数 $CP_i,i\geq 1$ 上计算函数值 $CP_i(x^{2^{i}})$ 和 $CP_i(-x^{2^{i}})$,以及它们对应的默克尔树路径。
154 |
155 | 注:因为 $CP_i(x)=g(x^2)+xh(x^2),CP_{i}(-x)=g(x^2)-xh(x^2)$,所以 $CP_{i+1}(x^2)=g(x^2)+\beta_{i+1} h(x^2)$ 可由 $CP_i(x)$ 和 $CP_i(-x)$ 计算而出。
156 |
157 | 最终,在每一轮挑战中,验证者随机发送一个挑战 $x$,证明者计算并发回多个函数值以及对应的默克尔树路径。验证者可以验证默克尔树路径是否和先前的根节点哈希值匹配以及函数值之间的等式关系是否成立。
158 |
159 | 
160 |
161 | 总结:在一次证明中,证明者首先向验证者发送了 $O(\log n)$ 个默克尔树根节点哈希值,其中 $n$ 是要证明的多项式的次数。在每一轮验证者的挑战中,证明者发送了 $O(\log n)$ 个函数值,以及其对应的默克尔树路径,每条路径大小约为 $`O(\log n/2^i)`$,$`i`$ 为当前 FRI 层次。
162 |
163 | ### 参考资料:
164 |
165 | 1. https://github.com/starkware-industries/stark101
166 | 2. https://github.com/Antalpha-Labs/zkp-academy/blob/main/FRI%26Stark/stark101
167 | 3. Eli Ben-Sasson, Iddo Bentov, Yinon Horesh and Michael Riabzev. “Fast Reed-Solomon Interactive Oracle Proofs of Proximity.” *ECCV* (2017).
168 |
--------------------------------------------------------------------------------
/FRI&Stark/stark101/stark101_arithmetization.md:
--------------------------------------------------------------------------------
1 | # Arithmetization
2 |
3 | Stark101 前2个视频主要是描述如何做算术化(Arithmetization),我们学完之后应该能够回答三个问题:
4 |
5 | 1. Why:为什么需要算术化?
6 | 2. How:怎么做算术化?
7 | 3. What:算术化究竟做了什么?
8 |
9 | ## 1. Why
10 |
11 | 要解释原因,通常需要熟悉一个方案的构造框架。一个主流的 SNARK 方案构造框架以及基于FRI的SNARK构造框架(草图)如下:
12 |
13 |
14 |
15 | 证明系统的目的是:**证明一个计算的正确执行**。在计算机中,我们把计算(Computation)通常建模为电路,把计算的验证转换为电路的可满足问题(C-SAT),然后把电路的可满足问题规约成某些易证明语言,这种语言通常以多项式形式表达。最后利用证明系统对这个特定语言生成证明。
16 |
17 | 证明的过程本质上就是 Prover 把计算过程中产生的中间变量全部保存下来,形成一个执行轨迹(Execution Trace),诚实的Prover只需要证明它真的拥有着一条**满足计算约束的执行轨迹**即可。
18 |
19 | > Q1: “某些易证明语言”是什么?
20 | >
21 | > A1: 不同的证明系统选择的易证明语言不一样,比如Groth16的QAP问题,即判断是否存在一个多项式能够被一个公开的多项式整除;基于 IPA 的证明系统:判断一个多项式是否是零多项式。
22 | >
23 | > Q2:能否直接证明电路可满足问题,而不经过这些“特定语言”?
24 | >
25 | > A2: 当然可以!但是直接证明电路可满足性问题代价太大,比如 Prover 直接把运行轨迹发送给 Verifier ,且不考虑证明和验证复杂度,通信复杂度已与电路规模成线性关系。这开销远大于证明这些易证明的语言。
26 |
27 | 算术化的过程就是**把“存在一条运行轨迹满足计算运行约束”表达为一种易证明的语言**。举例,STARK101教程中, Prover 要证明它确实执行了 fibonacciSq 这个计算,并且把计算过程的中间变量(数列的每一个值)都保存下来,那么计算约束就是首项、尾项和递推公式,我们把计算约束。 Prover 证明了它的执行轨迹满足这三个多项式约束后,验证着即可相信。
28 |
29 | 因此做算术化的第一个原因就是:把计算的可验证问题转化成证明基于多项式的某些易证明语言,可以让证明更简洁。
30 |
31 | 对于基于 IOPP 的 STARK 方案,这还不够!我们深入讨论一下 IOP 和 IOPP 的差别。
32 |
33 | IOP 证明系统框架来源于两个更古老的证明系统框架:IP和PCP,分别如图所示。
34 |
35 | - IP(Interactive Proofs):这是最早提出的交互式证明模型。在这个模型中,Prover 和 Verifier 进行多轮交互,交互结束后,Verifier 输出 0 或者 1,表示是否接受这次证明。
36 | - PCP(Probabilistic Checkable Proofs):在这个模型中,Prover和 Verifier 只进行一次交互,这一次交互中,Prover 向 Verifier 发送一个字符串,叫做PCP。和IP的主要区别是,Verifier 不需要读取完整的 PCP 字符串,而是可以对其进行随机访问。Verifier 计算结束后,输出 0 或者 1,表示是否接受这次证明。
37 | - IOP(Interactive Oracle Proofs)其实就是 IP 和 PCP 的结合:它像IP一样允许多轮交互,而每一轮交互都是一个 PCP 模型,即 Verifier 可以随机访问 Prover 发来的字符串,但不需要读取整个字符串。多轮交互结束后,Verifier 输出 0 或者 1。
38 |
39 |
40 |
41 | IOP 具有两个性质,分别是: Completeness,诚实的 Prover 和 诚实的 Verifier 一定使得协议输出为 1;Soundness,不诚实(执行计算)的 Prover 一定没有合法的执行轨迹,它所使用的假的执行轨迹只要和诚实的执行轨迹有一丁点不一样,整个协议以大概率输出 0。
42 |
43 | IOPP(Interactive Oracle Proofs of Proximity)是 IOP 模型的变体,同样考察这两个性质,Completeness是一致的,但是 Soundness 的定义做了让步:不诚实(执行计算)的 Prover 一定没有合法的执行轨迹,它所使用的假的执行轨迹只要和诚实的执行轨迹差异较大,整个协议以很高概率输出 0。
44 |
45 | 有人可能会问:这怎么能行!?Prover 只需要知道一条跟诚实执行轨迹相差不大且符合计算约束的多项式,也可以通过 Verifier 的验证。那 Prover 作恶的机会大大增加了!
46 |
47 | 这也就引出了算术化在 STARK 中的第二个原因:STARK 的算术化确保了只要证明者不诚实执行整个计算,那么它的那条假的执行轨迹在算术化之后一定离真实的执行轨迹很远。这利用 Reed Solomon Code 这类纠错码的距离放大特性,后文会谈。
48 |
49 | ## 2. How
50 |
51 | STARK101 前两节课的内容简单扼要地告诉我们如何做算术化,总结下来就是四板斧。
52 |
53 | - 小域插值:在一个小域 $\langle g\rangle$ 上利用 lagrange 插值把执行轨迹编码成多项式 $f(X)$;
54 |
55 | - 构建约束多项式等式:执行轨迹需要对首尾和中间状态进行三个约束,表示成3个多项式等式;
56 |
57 | $$
58 | \begin{aligned}
59 | f(g^{0})=1\\
60 | f(g^{1022})=2338775057\\
61 | f(g^2X)=f^2(gX)+f^2(X)\\
62 | \end{aligned}
63 | $$
64 |
65 | - 构造Rational多项式并合并:进一步地把多项式等式处理成 Rational 多项式,并通过随机线性结合(random linear combination)把三个多项式合并成一个多项式。
66 |
67 | $$
68 | \begin{aligned}
69 | p_0(X)=\frac{f(X)-0}{X-g^{0}}\\
70 | p_1(X)=\frac{f(X)-2338775057}{X-g^{1022}}\\
71 | p_2(X)=\frac{f(g^2X)-f^2(gX)-f^2(X)}{\prod_{i=0}^{1020}{X-g^i}}=\frac{f(g^2X)-f^2(gX)-f^2(X)}{\frac{X^{1024}-1}{(X-g^{1021})(X-g^{1022})(X-g^{1023})}}\\
72 | p(X)=p_0(X) + \alpha_1p_1(X)+\alpha_2p_2(X)
73 | \end{aligned}
74 | $$
75 |
76 | - 大域求值:在一个更大的域上 $\langle l\rangle$ 对所有元素求它们 $f(x)$ 的求值。
77 |
78 | 正确的,但要知道其中道理,我们需要掌握更多的知识。
79 |
80 | ### Prelimilary
81 |
82 | 为了理解算术化的本质,我们需要了解三个数学基本构件,分别是有限域,多项式和Reed-Solomon编码。这里仅列出部分让本文自洽的定义和定理。
83 |
84 | #### Finite Field
85 |
86 | - 素数阶有限域的乘法群构成循环群。(费马小定理可证)
87 | - 循环群的子群也是循环群。(反证法)
88 | - 循环群必是 Abel 群。
89 | - 拉格朗日定理(Lagrange Theorem):设 $H$ 是有限群 $G$ 的子群,则 $|H|$ 的阶整除 $|G|$ 的阶。
90 | - 陪集(coset):给定群 $G$ 及其子群 $H$ 。定义左陪集为 $\set{g \circ h \quad \forall h\in H}$ ,其中 $g\in G$。右陪集同理。Abel 群的左右陪集相同。
91 |
92 | 1. 为了能在“小域”上插值,在“大域”上求值,我们需要找到两个乘法子群(一小一大)。
93 |
94 | 计算素数阶有限域 $\mathbb{F}_p$ 上所构成的乘法循环群 $\langle g\rangle$ 的 $d$ 阶乘法子群的生成元 $w$:
95 |
96 | $$
97 | w=g^{(p-1)/d}
98 | $$
99 |
100 | 2. 上述从“小域”到“大域”的 blowup,并不是简单地扩大到一个规模更大的乘法子群,而是要取这个大域上的 coset。
101 |
102 | 为什么取 Coset?目前的观点是起到隔离作用。同样的技巧可以参考[郭老师文章](https://learn.z2o-k7e.world/plonk-intro-cn/plonk-constraints.html#%E4%BD%8D%E7%BD%AE%E5%90%91%E9%87%8F%E7%9A%84%E4%BC%98%E5%8C%96)。
103 |
104 |
105 | #### Polynomial over Finite Field
106 |
107 | 考虑有限域 $\mathbb{F}_p$ 上的 $n$ 次单变量多项式。
108 |
109 | - $f(X)=\sum_{i=0}^{n-1}{f_iX^i}$ ,其中 $f_i,X\in \mathbb{F}_p$ 。
110 | - Fact 1: $n + 1$ 个点唯一确定一个 $n$ 次多项式。
111 | - 代数基本定理(Foundamental Theorem of Algebra): $n$ 次多项式至少有 $n$ 个零点。
112 | - 拉格朗日插值:给定一个点向量 $\vec{f}=\set{(x_0, y_0), \dots, (x_{n-1}, y_{n-1})}$,使用 lagrange插值法计算穿过这些点的多项式: $f(X)=\sum_{i=0}^{n-1}{y_i L_i(X)}$,其中 $L_i=\prod_{j=0, j\ne i}{\frac{X-x_j}{x_i - x_j}}$。
113 |
114 | Intuition:这个方法的思路在于设计一个 Basis 多项式 $L_i(X)$,使得当 $X=x_i$ 时,输出为 1;否则输出为 0。
115 | - Schwazch Zipple lemma:有限域 $\mathbb{F}_p$ 上任意两个不同的 $n$ 次多项式在大多数点上的取值不同。
116 |
117 | 给定两个多项式 $f(X),g(X)$ ,在有限域任取一元素 $a$ 对两个多项式求值,如果 $f(a)=g(a)$ ,则认为它们是相同的多项式,出错的概率为 Soundness error = $\frac{n}{p-1}$。由于 $n\ll p$,因此错误的概率很低。
118 | - Low Degree Extension (LDE)
119 |
120 | - Extension:给定一个函数映射 $f: \set{0,1}^v\rightarrow\mathbb{F}$,如果一个 v 元多项式 $g(\cdot)$ 满足 $f$ 的所有映射关系,那么称这个多项式 $g(\cdot)$ 是函数映射 $f$ 的扩展(extension)。
121 | - Low Degree:关于低次的定义是根据上下文变化的,但至少 $g(\cdot)$ 的次数不大于有限域的规模。
122 | - 在 STARK 上下文中,低次的定义是不大于“小域”的规模。
123 |
124 | 人们的一个误区是:以为 LDE 是一个单独的算法。但其实 LDE 其实描述一种寻找多项式来扩展原始函数映射的思想。很多工具都可以实现这种思想,上述的 lagrange 插值法就是找到 LDE 中所定义的多项式的一种常用方法。
125 |
126 | 非常重要的一点:LDE 赋予了向量(或者函数映射)一种距离放大(distance amplifying)的特性。函数映射本身的表现力局限在本身的定义域上,这样两个映射之间的差异其实是细微的(或者说差异很小)。但是如果将它们扩展成多项式,那么在一个更大的域上取值求得的向量,再比较,则差异就显著起来。下面是 PAZK 中对 LDE 距离放大特性的展示。
127 |
128 |
129 |
130 | #### Reed Solomon Code
131 |
132 | 编码理论,故名思义,一门研究对消息进行编码的理论。编码的过程为 $enc:\Sigma^k\rightarrow\Sigma^n$,解码是其反向操作。其中 $\Sigma$ 表示字母表, $k$ 表示原始消息(message)长度, $n$ 表示编码之后的码字(codeword)长度。
133 |
134 | - 一个码(Code)对应着一个 n 维向量空间的子空间,记作: $C\subseteq\mathbb{F}^n$,
135 |
136 | - 也就是说,一个码是向量的集合。
137 | - 码字(Codeword)是这个向量集合中的任意元素,码元(code symbol)是码字向量中的任意元素。
138 | - 码的维度指消息的长度: $\dim C=k$。
139 | - 码率: $\rho=k/n$
140 | - 最小汉明距离: $d=\min_{u,v\in C, u\ne v}\Delta(u,v)$。其中 $\Delta$ 表示两个码字之间汉明距离,也就是不同的码元个数。我们用最小汉明距离来刻画码字之间的差异程度。
141 | - 最小汉明重量: $w=\min_{v\in C}\text{码字v中非零码元个数}$。
142 |
143 | 我们期望编码之后,对消息的传递具有一定增益,比如检错和纠错。如何带来增益?原理就是增加码字之间的距离。任意两个码字之间的距离增大,意味着我们纠错的范围越大,更容易恢复原始消息。但伴随而来的缺陷是:码率降低,编码速率降低。因此在设计纠错码时会有权衡(trade-off)。
144 |
145 | 纠错码的检错和纠错能力使用最小汉明距离 $d$ 描述:
146 | - 检错能力: $d-1$,
147 | - 纠错能力: $\lfloor\frac{d-1}{2}\rfloor$
148 |
149 | - 线性码
150 | - 线性码是一类纠错码,定义为: 一个线性码码(Linear Code)对应着一个 n 维向量空间的线性子空间,记作: $C\leqslant\mathbb{F}^n$。
151 | - 线性是说:给定两个码元 $u,v\in C$,两个有限域元素 $\alpha, \beta$,则 $\alpha u+\beta v\in C$。
152 | - 线性码中,最小汉明距离和最小汉明重量是等价的。
153 | - 习惯上会把参数附加上,比如 $[n, k]$-线性码, $[n, k, d]$-线性码,或者 $[n, \rho, d]$-线性码。(用 $k$ 还是 $\rho$ 取决于自己偏好,反正知道 $n,k,\rho$ 其二即可)
154 | - Singleton Bound: $[n,k]$-线性码的最小汉明距离 $d\le n-k+1$
155 |
156 | - Reed Solomon Code
157 |
158 | - RS码是一类 $[n, \rho, d]$-线性码,早在1960年提出,名为“Polynomial code over Certain Finite Field”。
159 | - 定义: $C=\set{(p(a_0), p(a_2), \dots,p(a_{n-1}))|p\text{ is a polynomial over } \mathbb{F}_p\text{ of order }
185 |
186 |
187 |
188 |
189 |
--------------------------------------------------------------------------------
/FRI&Stark/README.md:
--------------------------------------------------------------------------------
1 | # FRI & Stark Course
2 |
3 | ## 基本信息
4 |
5 | FRI(Fast Reed-Solomon Interactive Oracle Proof of Proximity)是 STARKs(Scalable Transparent ARguments of Knowledge)的核心组成部分。
6 |
7 | 作为一种重要的证明系统,FRI 正迅速崭露头角。
8 |
9 | FRI 是一种基于 Reed-Solomon 码的交互式证明系统,能为零知识证明提供高效的低复杂度验证,提升验证效率并显著降低验证成本。具体来说,它允许证明者(Prover)向验证者(Verifier)证明某个多项式的评估值确实具有低度性,而不需要验证者重新计算这个多项式。
10 |
11 | 值得一提的是,FRI 在后量子时代拥有独特的优势。
12 |
13 | 一方面,FRI 依赖于信息论的安全性和哈希函数的抗碰撞特性,而不是传统的基于数学难题的密码系统。这意味着即使面对能够高效解决整数分解和离散对数问题的量子计算机,FRI 仍然能够保持其安全性。这种设计使得 FRI 能够在量子计算环境下依然可靠,提供高强度的防护。
14 |
15 | 另一方面,FRI 使用 Merkle Tree 进行数据承诺和验证,通过哈希函数的抗碰撞性确保数据完整性和真实性。Merkle Tree 的安全性依赖于选定哈希函数的抗碰撞性,如 SHA-256、Blake3 等,这些哈希函数在量子计算时代依然具有较高的安全性。通过 Merkle Tree,FRI 能够高效地验证多项式评估值,从而减少计算开销和验证时间。
16 |
17 | 总而言之,FRI 及其在 STARKs 中的应用,凭借其独特的设计和依赖于信息论的安全性,使得 FRI 不仅是未来密码学中不可或缺的关键技术,也将在 Crypto 领域成为保障系统安全和隐私的重要工具。
18 |
19 | 当我们站在历史的风陵渡,用未来的眼光审视当下,FRI 显然是一片充满可能性的土壤。
20 |
21 |
22 | ### 前置知识
23 |
24 | 对 ZKP 有一定的了解,了解 ZKP 中的基本概念。如果不了解也没关系,推荐同时学习这门 MOOC [Zero Knowledge Proofs](https://zk-learning.org/) 以及我们的往期课程 [Plonk一期](https://www.youtube.com/playlist?list=PLbQFt1T_44DwN1zWl-KWhkp3s0LAkF2a8) [Plonk二期](https://www.youtube.com/playlist?list=PLbQFt1T_44Dy2FQU5oSbIdtfw2S64L72y)
25 |
26 | + **线上答疑:** [Github Discussion](https://github.com/Antalpha-Labs/zkp-academy/discussions/categories/q-a)
27 |
28 | ### 开营AMA
29 |
30 | + 视频回放:[Youtube 链接](https://www.youtube.com/watch?v=mXHaBqJ0aYI)
31 |
32 | ## 课程表
33 |
34 | ### Part 1: STARK101【8月12日 - 8月25日】
35 |
36 | 通过 STARK101 课程入门,了解 STARKs 中各个组件的功能,以及这些功能在 ZKP 中起到了什么作用。
37 | 在 Part1 中我们将布置下我们需要完成的第一个作业 [(discussion链接)](https://github.com/Antalpha-Labs/zkp-academy/discussions/35)
38 |
39 | 【第一周课程安排】
40 | - 第一节课:Overview of FRI.
41 | - 预习材料:有时间的可以看一下上一期 Plonk 的内容,领航员: Guoyu,时间:星期二,晚上8点
42 | - 课程回放:[Youtube 链接](https://youtu.be/VUjiC5Qwdmo)
43 | - PPT [链接](https://github.com/Antalpha-Labs/zkp-academy/blob/main/FRI%26Stark/lesson%201/FRI%20overview%202024-08-13%2019-54-37.pdf)
44 | - 第二节课:How to do Low Degree Extension and constrain our LDE.
45 | - 预习材料:STARK101 第一及第二个视频,领航员: Tim,时间:星期四,晚上8点
46 | - 课程回放:[Youtube 链接](https://youtu.be/HLgiprbnsBA)
47 | - Note [链接](./stark101/stark101_arithmetization.md)
48 | - 答疑:周六晚上时间 8 点
49 |
50 | 【第二周课程安排】
51 | - 第三节课:What does FRI actually do?
52 | - 预习材料:STARK101 第三个视频,领航员: Dream,时间:星期二,晚上8点
53 | - 课程回放:[Youtube 链接](https://www.youtube.com/watch?v=dfUQaLOeHFc)
54 | - 第四节课:How to convince the verifier by FRI?
55 | - 预习材料:STARK101 第四个视频,领航员: Harold, 时间:星期四,晚上8点
56 | - 课程回放:[Youtube 链接](https://youtu.be/FigtQ5C6G5s)
57 | - 答疑:周六晚上时间 8 点
58 | - 答疑回放:[YouTube 链接](https://www.youtube.com/watch?v=65-PcleywRg)
59 |
60 | 共学资料:[STARK101](https://starkware.co/stark-101/)
61 |
62 |
63 | **第一 part 作业**:[Arithmetization in STARKs](https://github.com/Antalpha-Labs/zkp-academy/discussions/35)
64 |
65 | ### Part 2: zk-learning.org Lecture 8【8月26日 - 9月8日】
66 |
67 | 通过 zk-learning 的第八讲及其它辅助材料,深入理解 zk-STARKs 的工作原理和技术细节。
68 |
69 | 讲师:backdoor、Kyrin、0xhhh、Yingfei
70 |
71 | 【第一周课程安排】
72 | - 第一节课:FRI by Hand.
73 | - 课程内容:FRI的例子及协议细节,讲师:backdoor,时间:星期二晚上8点
74 | - 课程回放:[Youtube 链接](https://www.youtube.com/watch?v=W5dXnaSwrQw)
75 | - 第二节课:Attack Cases in FRI & Comparison of PCSs(KZG, IPA).
76 | - 课程内容:LDT的安全分析及PCS对比,讲师:Kyrin,时间:星期四晚上8点
77 | - 课程回放:[Youtube 链接](https://youtu.be/_0aMoAZ1L7k)
78 | - 答疑:周六晚上时间 8 点
79 | - 答疑回放:[Youtube 链接](https://youtu.be/unvwDkqpbpA)
80 |
81 | 【第二周课程安排】
82 | - 第三节课:Stark by Hand (PCS with FRI).
83 | - 课程内容:FRI的多项式承诺,讲师:0xhhh,时间:星期二晚上8点
84 | - 课程回放:[Youtube 链接](https://youtu.be/ak1wGXfGlyc)
85 | - 第四节课:Soundness of STARK.
86 | - 课程内容:STARK的形式化流程及安全性分析,讲师:Yingfei,时间:星期四晚上8点
87 | - 课程回放:[Youtube 链接](https://youtu.be/p3zxhnSDqFM)
88 | - 第五节课:Soundness of FRI.
89 | - 课程内容:FRI协议的安全性分析,讲师:Yingfei,时间:星期六晚上8点
90 | - 课程回放:[Youtube 链接](https://youtu.be/Sfm5GjI69fc)
91 |
92 |
93 | 共学资料:[zk-learning.org](https://zk-learning.org/)
94 |
95 | 【辅助教程】
96 |
97 | + [STARK Anatomy](https://aszepieniec.github.io/stark-anatomy/)
98 | + [Vitalik Blogs Part 1](https://vitalik.eth.limo/general/2017/11/09/starks_part_1.html) [Part 2](https://vitalik.eth.limo/general/2017/11/22/starks_part_2.html) [Part 3](https://vitalik.eth.limo/general/2018/07/21/starks_part_3.html)
99 |
100 | 【安全分析】
101 |
102 | + [SNARK Security and Performance](https://a16zcrypto.com/posts/article/snark-security-and-performance/)
103 | + [Safe and Sound – A Deep Dive into STARK Security](https://starkware.co/safe-and-sound-a-deep-dive-into-stark-security)
104 |
105 | + [ethSTARK Documentation – Version 1.2](https://eprint.iacr.org/2021/582.pdf)
106 |
107 | + [Fiat-Shamir Security of FRI and Related SNARKs](https://eprint.iacr.org/2023/1071.pdf)
108 |
109 | + [Proximity Gaps for Reed-Solomon Codes](https://eprint.iacr.org/2020/654.pdf)
110 |
111 | + https://snargsbook.org/
112 |
113 | ### Part 3: FRI 代码【9月9日 - 9月22日】
114 |
115 | 学习和实现 FRI 代码,通过 Plonky3 和 lambda class团队的 zk-stark,掌握 FRI 的实际编程技巧。
116 |
117 | 【第一周课程安排】
118 | - 第一节课:lambda class版zk-stark实现
119 | - 预习材料: 阅读lambda class版zk-stark的[理论和实现流程](https://lambdaclass.github.io/lambdaworks/starks/recap.html),有余力的可以看看[代码实现](https://github.com/lambdaclass/lambdaworks/tree/main/provers/stark),领航员: 饭卡,时间:星期二,晚上8点
120 | - 课程回放:[Youtube 链接](https://youtu.be/wEIiSuaMH4o)
121 | - 第二节课:Plonky3 two_adic_pcs概述
122 | - 预习材料:
123 | - [Plonky3](https://github.com/Plonky3/Plonky3)fri文件夹内的代码,
124 | - two_adic_pcs运行流程图:https://miro.com/app/board/uXjVNbLn8WU=/?share_link_id=878894620109
125 | - 领航员: 阳小雪,时间:星期四,晚上8点
126 | - 课程回放:[Youtube 链接](https://youtu.be/swCjt9YibyE)
127 | - [课堂手写文档](https://learned-elm-078.notion.site/plonky3-fri-111680b62bca80048868e562373ec851?pvs=4)
128 |
129 | 【第二周课程安排】
130 | - 第三节课:
131 | - Plonky3/fri/src/two_adic_pcs.rs
132 | - 预习材料:[Plonky3](https://github.com/Plonky3/Plonky3)fri文件夹内的代码,领航员: 阳小雪,时间:星期四,晚上8点
133 | - 课程回放:[Youtube 链接](https://youtu.be/rUQK6j3Bhsk)
134 | - [课堂手写文档](https://learned-elm-078.notion.site/plonky3-fri-111680b62bca80048868e562373ec851?pvs=4)
135 | - 第四节课:
136 | - uni-stark of plonky3
137 | - 预习材料:[Plonky3](https://github.com/Plonky3/Plonky3)uni-stark 文件夹内的代码,领航员: hhh,时间:星期六,晚上8点
138 | - 代码注释: https://github.com/cyl19970726/Plonky3/tree/main_comment
139 | - 课程回放:[Youtube 链接](https://youtu.be/UHfP-1Pm1Ak)
140 |
141 |
142 | 共学资料:
143 | - [Plonky3](https://github.com/Plonky3/Plonky3)
144 |
145 | + 辅助学习:
146 | 1. [Winterfell - FRI](https://github.com/facebook/winterfell)
147 | 2. [RiscZero - FRI](https://github.com/risc0/risc0/blob/main/risc0/zkp/src/prove/fri.rs)
148 | 3. [how to code fri from scratch](https://blog.lambdaclass.com/how-to-code-fri-from-scratch/)
149 | 4. lambda class版zk-stark ([理论](https://lambdaclass.github.io/lambdaworks/starks/recap.html), [代码](https://github.com/lambdaclass/lambdaworks/tree/main/provers/stark))
150 |
151 | **第三 part 作业**:[Plonky3-fri](https://github.com/Antalpha-Labs/zkp-academy/discussions/58)
152 |
153 |
154 | ### Part 4: Circle STARKs 【时间10月13日至10月19日,地点 清迈,泰国,参与此课程须完成线上课程,提前报名】
155 |
156 | + 讲师:Kurt Pan、小熊、wangyao
157 | + 课程回放:
158 | + 共学资料:
159 | 1. [Vitalik Blog](https://vitalik.eth.limo/general/2024/07/23/circlestarks.html)
160 | 2. [Kurt Pan 译](https://mp.weixin.qq.com/s/g6hcok1tJVIIOSoz3dxRFQ)
161 | 3. [David Wong Post](https://www.zksecurity.xyz/blog/posts/circle-starks-1/)
162 | 4. [circle stark and stwo](https://elibensasson.blog/why-im-excited-by-circle-stark-and-stwo/)
163 | 5. [Paper](https://eprint.iacr.org/2024/278.pdf)
164 |
165 |
166 |
167 | 【**课程其他补充学习资料**】
168 |
169 | + [Cairo 推荐](https://github.com/lambdaclass/cairo-vm?tab=readme-ov-file#starks)
170 |
171 | + [RiscZero 推荐](https://dev.risczero.com/reference-docs/about-fri)
172 |
173 | + [RiscZero Introduction to FRI](https://www.youtube.com/playlist?list=PLcPzhUaCxlCi6rRRiIlkzJ_YELUlKO4Mz)
174 |
175 | + [Fast Reed-Solomon IOP (FRI) Proximity Test](https://rot256.dev/post/fri/)
176 |
177 | + [(综述) A summary on the FRI low degree test](https://eprint.iacr.org/2022/1216.pdf)
178 |
179 | + [(DAS应用) FRIDA: Data Availability Sampling from FRI](https://eprint.iacr.org/2024/248.pdf)
180 |
181 | + [(算术化) Study of Arithmetization Methods for STARKs](https://eprint.iacr.org/2023/661.pdf)
182 |
183 | ## 作业
184 | 第一 part 作业:[Arithmetization in STARKs](https://github.com/Antalpha-Labs/zkp-academy/discussions/35)
185 |
186 | 第三 part 作业:[Plonky3-fri](https://github.com/Antalpha-Labs/zkp-academy/discussions/58)
187 |
188 | ### 老师介绍
189 |
190 | + Dream:Scroll Core Engineer,Blocksight 作者。数学&密码学持续学习者,前爱立信,微软高级工程师,区块链与隐私计算一线工程研发。
191 | + wangyao:数学博士(未完成)研究 ZK,学习 FHE,探索代数学和密码学的相交地带。
192 | + Kurt Pan:学院派新密码朋克,郭宇老师的好学生
193 | + Tim:Tim,北京邮电大学硕士,密码学爱好者,CTFer,热衷ZK安全。
194 | + 小熊:pku 物理本科,法国 AI 硕士,现正专注密码学,做 ZK 相关科研
195 | + Harold:研究 zk 协议 todolist 望不到头的人,偶尔会做一些技术分享,欢迎大家来一起讨论~
196 | + Kyrin:区块链方向博士生,zkp 技术爱好者,与大佬们学习最新技术。
197 | + 0xhhh: 正在学习 binuis,circle stark,zk 爱好者
198 | + backdoor:OKX ZK Dev,代码和理论两手抓,希望跟大家多交流学习~
199 | + Po:EthStorage ZK Researcher, 半路出家区块链,持续学习 DA 和 ZK 前沿研究。
200 | + 阳小雪:安比实验室 ZK Researcher, 最近在学习 Plonky3 的代码
201 | + Yingfei:密码学博士生,interested in lattice-based zero-knowledge proofs and signatures。
202 | + 饭卡:电子科技大学硕士,持续学习 zk ing
203 |
204 |
205 | ## Co-learn notes bounty
206 |
207 | 为鼓励学员学习与分享,本课程推出 Co-learn notes bounty 活动,学员可以将学习中的内容整理成个人笔记提交到 co-learn notes 目录下,收录后每篇笔记给出 200CNY 的 bounty,并发布在 Antalpha-Labs 公众号上。笔记主题围绕 ZKP 相关技术,不局限于 FRI or Stark 协议。
208 |
209 | **联系方式**:添加小助手微信 Coset2025
210 | **备注**:不要吝啬给我们一个 star 哦~
211 |
212 | ## Sponsor
213 |
214 |
215 |
--------------------------------------------------------------------------------
/Plonk/lesson 6/poly_utils.py:
--------------------------------------------------------------------------------
1 | # Creates an object that includes convenience operations for numbers
2 | # and polynomials in some prime field
3 | class PrimeField():
4 | def __init__(self, modulus):
5 | assert pow(2, modulus, modulus) == 2
6 | self.modulus = modulus
7 |
8 | def add(self, x, y):
9 | return (x+y) % self.modulus
10 |
11 | def sub(self, x, y):
12 | return (x-y) % self.modulus
13 |
14 | def mul(self, x, y):
15 | return (x*y) % self.modulus
16 |
17 | def exp(self, x, p):
18 | return pow(x, p, self.modulus)
19 |
20 | # evaluate the polynomal in the evaluation form in a coset
21 | # xs[0] must the shifting parameter h
22 | # formula is (x^m - h^m) / (m h^m) * sum(ys[i] * xs[i] / (x - xs[i]))
23 | def eval_barycentric(self, x, xs, ys):
24 | m = len(xs) # coset order
25 | xm = self.exp(x, m)
26 | hm = self.exp(xs[0], m)
27 | s = 0
28 | for i in range(len(xs)):
29 | s = self.add(s, self.div(self.mul(xs[i], ys[i]), self.sub(x, xs[i])))
30 | return self.mul(s, self.div(self.sub(xm, hm), self.mul(m, hm)))
31 |
32 | # evaluate the polynomal in the evaluate form for all cosets
33 | # with some optimization on inversion
34 | def eval_barycentric_all(self, x, xs, ys, m):
35 | ncosets = len(xs) // m
36 | # evaluate all inversions in batch
37 | toinv = [x - xx for xx in xs]
38 | toinv.append(m)
39 | inved = self.multi_inv(toinv)
40 | invm = inved[-1]
41 | xm = self.exp(x, m)
42 | ss = []
43 | modulus = self.modulus
44 | for i in range(ncosets):
45 | s = 0
46 | for j in range(m):
47 | idx = j*ncosets+i
48 | s = (s + xs[idx] * ys[idx] * inved[idx]) % modulus
49 | ss.append(s * (xm - xs[i * m]) * invm * xs[-i * m] % modulus)
50 | return ss
51 |
52 | # Modular inverse using the extended Euclidean algorithm
53 | def inv(self, a):
54 | if a == 0:
55 | return 0
56 | lm, hm = 1, 0
57 | low, high = a % self.modulus, self.modulus
58 | while low > 1:
59 | r = high//low
60 | nm, new = hm-lm*r, high-low*r
61 | lm, low, hm, high = nm, new, lm, low
62 | return lm % self.modulus
63 |
64 | def multi_inv(self, values):
65 | partials = [1]
66 | for i in range(len(values)):
67 | partials.append(self.mul(partials[-1], values[i] or 1))
68 | inv = self.inv(partials[-1])
69 | outputs = [0] * len(values)
70 | for i in range(len(values), 0, -1):
71 | outputs[i-1] = self.mul(partials[i-1], inv) if values[i-1] else 0
72 | inv = self.mul(inv, values[i-1] or 1)
73 | return outputs
74 |
75 | def div(self, x, y):
76 | return self.mul(x, self.inv(y))
77 |
78 | # Evaluate a polynomial at a point
79 | def eval_poly_at(self, p, x):
80 | y = 0
81 | power_of_x = 1
82 | for i, p_coeff in enumerate(p):
83 | y += power_of_x * p_coeff
84 | power_of_x = (power_of_x * x) % self.modulus
85 | return y % self.modulus
86 |
87 | # Arithmetic for polynomials
88 | def add_polys(self, a, b):
89 | return [((a[i] if i < len(a) else 0) + (b[i] if i < len(b) else 0))
90 | % self.modulus for i in range(max(len(a), len(b)))]
91 |
92 | def sub_polys(self, a, b):
93 | return [((a[i] if i < len(a) else 0) - (b[i] if i < len(b) else 0))
94 | % self.modulus for i in range(max(len(a), len(b)))]
95 |
96 | def mul_by_const(self, a, c):
97 | return [(x*c) % self.modulus for x in a]
98 |
99 | def mul_polys(self, a, b):
100 | o = [0] * (len(a) + len(b) - 1)
101 | for i, aval in enumerate(a):
102 | for j, bval in enumerate(b):
103 | o[i+j] += a[i] * b[j]
104 | return [x % self.modulus for x in o]
105 |
106 | def div_polys(self, a, b):
107 | assert len(a) >= len(b)
108 | a = [x for x in a]
109 | o = []
110 | apos = len(a) - 1
111 | bpos = len(b) - 1
112 | diff = apos - bpos
113 | while diff >= 0:
114 | quot = self.div(a[apos], b[bpos])
115 | o.insert(0, quot)
116 | for i in range(bpos, -1, -1):
117 | a[diff+i] -= b[i] * quot
118 | apos -= 1
119 | diff -= 1
120 | return [x % self.modulus for x in o]
121 |
122 | def div_polys_with_rem(self, a, b):
123 | assert len(a) >= len(b)
124 | a = [x for x in a]
125 | o = []
126 | apos = len(a) - 1
127 | bpos = len(b) - 1
128 | diff = apos - bpos
129 | while diff >= 0:
130 | quot = self.div(a[apos], b[bpos])
131 | o.insert(0, quot)
132 | for i in range(bpos, -1, -1):
133 | a[diff+i] -= b[i] * quot
134 | apos -= 1
135 | diff -= 1
136 | return [x % self.modulus for x in o], [x % self.modulus for x in a[:apos-1]]
137 |
138 | def mod_polys(self, a, b):
139 | return self.sub_polys(a, self.mul_polys(b, self.div_polys(a, b)))[:len(b)-1]
140 |
141 | # Build a polynomial from a few coefficients
142 | def sparse(self, coeff_dict):
143 | o = [0] * (max(coeff_dict.keys()) + 1)
144 | for k, v in coeff_dict.items():
145 | o[k] = v % self.modulus
146 | return o
147 |
148 | # Build a polynomial that returns 0 at all specified xs
149 | def zpoly(self, xs):
150 | root = [1]
151 | for x in xs:
152 | root.insert(0, 0)
153 | for j in range(len(root)-1):
154 | root[j] -= root[j+1] * x
155 | return [x % self.modulus for x in root]
156 |
157 | # Get the set of powers of R, until but not including when the powers
158 | # loop back to 1
159 | def get_power_cycle(self, r):
160 | o = [1, r]
161 | while o[-1] != 1:
162 | o.append((o[-1] * r) % self.modulus)
163 | return o[:-1]
164 |
165 | def degree(self, poly):
166 | for i in reversed(range(len(poly))):
167 | if poly[i] != 0:
168 | return i
169 | return 0
170 |
171 | # Given p+1 y values and x values with no errors, recovers the original
172 | # p degree polynomial.
173 | # Lagrange interpolation works roughly in the following way.
174 | # 1. Suppose you have a set of points, eg. x = [1, 2, 3], y = [2, 5, 10]
175 | # 2. For each x, generate a polynomial which equals its corresponding
176 | # y coordinate at that point and 0 at all other points provided.
177 | # 3. Add these polynomials together.
178 |
179 | def lagrange_interp(self, xs, ys):
180 | # Generate master numerator polynomial, eg. (x - x1) * (x - x2) * ... * (x - xn)
181 | root = self.zpoly(xs)
182 | assert len(root) == len(ys) + 1
183 | # print(root)
184 | # Generate per-value numerator polynomials, eg. for x=x2,
185 | # (x - x1) * (x - x3) * ... * (x - xn), by dividing the master
186 | # polynomial back by each x coordinate
187 | nums = [self.div_polys(root, [-x, 1]) for x in xs]
188 | # Generate denominators by evaluating numerator polys at each x
189 | denoms = [self.eval_poly_at(nums[i], xs[i]) for i in range(len(xs))]
190 | invdenoms = self.multi_inv(denoms)
191 | # Generate output polynomial, which is the sum of the per-value numerator
192 | # polynomials rescaled to have the right y values
193 | b = [0 for y in ys]
194 | for i in range(len(xs)):
195 | yslice = self.mul(ys[i], invdenoms[i])
196 | for j in range(len(ys)):
197 | if nums[i][j] and ys[i]:
198 | b[j] += nums[i][j] * yslice
199 | return [x % self.modulus for x in b]
200 |
201 | # Optimized poly evaluation for degree 4
202 | def eval_quartic(self, p, x):
203 | xsq = x * x % self.modulus
204 | xcb = xsq * x
205 | return (p[0] + p[1] * x + p[2] * xsq + p[3] * xcb) % self.modulus
206 |
207 | # Optimized version of the above restricted to deg-4 polynomials
208 | def lagrange_interp_4(self, xs, ys):
209 | x01, x02, x03, x12, x13, x23 = \
210 | xs[0] * xs[1], xs[0] * xs[2], xs[0] * xs[3], xs[1] * xs[2], xs[1] * xs[3], xs[2] * xs[3]
211 | m = self.modulus
212 | eq0 = [-x12 * xs[3] % m, (x12 + x13 + x23), -xs[1]-xs[2]-xs[3], 1]
213 | eq1 = [-x02 * xs[3] % m, (x02 + x03 + x23), -xs[0]-xs[2]-xs[3], 1]
214 | eq2 = [-x01 * xs[3] % m, (x01 + x03 + x13), -xs[0]-xs[1]-xs[3], 1]
215 | eq3 = [-x01 * xs[2] % m, (x01 + x02 + x12), -xs[0]-xs[1]-xs[2], 1]
216 | e0 = self.eval_poly_at(eq0, xs[0])
217 | e1 = self.eval_poly_at(eq1, xs[1])
218 | e2 = self.eval_poly_at(eq2, xs[2])
219 | e3 = self.eval_poly_at(eq3, xs[3])
220 | e01 = e0 * e1
221 | e23 = e2 * e3
222 | invall = self.inv(e01 * e23)
223 | inv_y0 = ys[0] * invall * e1 * e23 % m
224 | inv_y1 = ys[1] * invall * e0 * e23 % m
225 | inv_y2 = ys[2] * invall * e01 * e3 % m
226 | inv_y3 = ys[3] * invall * e01 * e2 % m
227 | return [(eq0[i] * inv_y0 + eq1[i] * inv_y1 + eq2[i] * inv_y2 + eq3[i] * inv_y3) % m for i in range(4)]
228 |
229 | # Optimized version of the above restricted to deg-2 polynomials
230 | def lagrange_interp_2(self, xs, ys):
231 | m = self.modulus
232 | eq0 = [-xs[1] % m, 1]
233 | eq1 = [-xs[0] % m, 1]
234 | e0 = self.eval_poly_at(eq0, xs[0])
235 | e1 = self.eval_poly_at(eq1, xs[1])
236 | invall = self.inv(e0 * e1)
237 | inv_y0 = ys[0] * invall * e1
238 | inv_y1 = ys[1] * invall * e0
239 | return [(eq0[i] * inv_y0 + eq1[i] * inv_y1) % m for i in range(2)]
240 |
241 | # Optimized version of the above restricted to deg-4 polynomials
242 | def multi_interp_4(self, xsets, ysets):
243 | data = []
244 | invtargets = []
245 | for xs, ys in zip(xsets, ysets):
246 | x01, x02, x03, x12, x13, x23 = \
247 | xs[0] * xs[1], xs[0] * xs[2], xs[0] * xs[3], xs[1] * xs[2], xs[1] * xs[3], xs[2] * xs[3]
248 | m = self.modulus
249 | eq0 = [-x12 * xs[3] % m, (x12 + x13 + x23), -xs[1]-xs[2]-xs[3], 1]
250 | eq1 = [-x02 * xs[3] % m, (x02 + x03 + x23), -xs[0]-xs[2]-xs[3], 1]
251 | eq2 = [-x01 * xs[3] % m, (x01 + x03 + x13), -xs[0]-xs[1]-xs[3], 1]
252 | eq3 = [-x01 * xs[2] % m, (x01 + x02 + x12), -xs[0]-xs[1]-xs[2], 1]
253 | e0 = self.eval_quartic(eq0, xs[0])
254 | e1 = self.eval_quartic(eq1, xs[1])
255 | e2 = self.eval_quartic(eq2, xs[2])
256 | e3 = self.eval_quartic(eq3, xs[3])
257 | data.append([ys, eq0, eq1, eq2, eq3])
258 | invtargets.extend([e0, e1, e2, e3])
259 | invalls = self.multi_inv(invtargets)
260 | o = []
261 | for (i, (ys, eq0, eq1, eq2, eq3)) in enumerate(data):
262 | invallz = invalls[i*4:i*4+4]
263 | inv_y0 = ys[0] * invallz[0] % m
264 | inv_y1 = ys[1] * invallz[1] % m
265 | inv_y2 = ys[2] * invallz[2] % m
266 | inv_y3 = ys[3] * invallz[3] % m
267 | o.append([(eq0[i] * inv_y0 + eq1[i] * inv_y1 + eq2[i] * inv_y2 + eq3[i] * inv_y3) % m for i in range(4)])
268 | # assert o == [self.lagrange_interp_4(xs, ys) for xs, ys in zip(xsets, ysets)]
269 | return o
270 |
271 | # Linear combination of polynomals
272 | def linearcomb_polys(self, ps, c):
273 | psc = []
274 | for i in range(len(c)):
275 | psc = self.add_polys(psc, self.mul_by_const(ps[i], c[i]))
276 | return psc
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/Plonk/co-learn-notes/co-learn-notes_MartinYeung5.md:
--------------------------------------------------------------------------------
1 | # Plonk 學習
2 |
3 | * "證明"的目的很重要,必須要了解到底證明什麼。
4 |
5 | ZKP有兩個角色, 一個是prover, 一個verifier,
6 | 如果要編寫prover, 有兩點要留意,第一是要產生一個有效的proof, 第二是要注意在產生proof時,有沒有暴露了一些不想公開的訊息。
7 | 如果要編寫verifier,要關注檢查的proof是不是有效的,能否滿足成為有效證明的條件。
8 | prover要用最少的資源去證明一件事,verifier要用最少的資源去驗證一件事。
9 |
10 | 當完成一組代碼後,就算順利完成編譯,也不算是完全沒有bug的。因為代碼的完整性是不能忽視,需要經過測試,不過惡意的prover有很多種,在測試上是存在很大難度,難以完全進行所有測試。畢竟技術也在進步,有時候新的技術可能會欺騙到verifier。
11 | 所以在設計上,最重要的要考慮到自己寫的verifier如何不被惡意prover欺騙。
12 |
13 | 一個協議需要關注以下三部分:
14 | 1. 完整性(completeness)
15 | 能否驗證所有為真的證明
16 |
17 | 2. 可靠性(soundness)
18 | 當證明是真的,就會通過驗證
19 |
20 | 3. 零知識(Zero-knowledge)
21 | 保護個人隱私
22 |
23 | 在prover與verifier之間要有大量交互,在有足夠多的交互下,才可以進一步減低作弊的風險。
24 | 真的證明能通過驗證,是其中一項條件,不代表這就是完整的。
25 | 如果要是假的證明又能通過驗證,這就雖然通過完整性,但就欠缺可靠性。所以兩者需要同時
26 | 如果不能區分假的證明,這就雖然通過可靠性,但就欠缺完整性。
27 | 所以兩者需要同時為真,才可以做到有效的驗證。
28 |
29 | 基於Non-interactive zero-knowledge proof ,用戶可以直接生成proof,然後發送到區塊鏈上進行驗證。
30 | 從而加快驗證效率
31 |
32 | 透過Fiat-Shamir transformation,可以實現Non-interactive zero-knowledge proof,
33 | 令public coin protocol變成Non-interactive proof。
34 | public coin protocol 可以讓誠實的驗證點發出隨機的coin(可以理解為隨機數)作為訊息,然後由prover產生一個proof。
35 | 不過發出隨機的coin的動作不一定由verifier負責,可以由其他人負責。
36 | 所以可以引入random oracle(例如是 cryptographic hash function)來生成隨機數,然後由prover產生一個proof,再直接發送給verifier(on-chain)。因此,也減少了verifier的工作量。
37 |
38 | 
39 |
40 | commitment 有以下特性:
41 | - O(1) size
42 | - Binding, 當commitment出現,其數值就不能被修改。保證其他人拿到你的commitment也不可以再改它。
43 | - Hiding, 當數值不公開,就不能被發現。不被人知道你的輸入資料, 每次生成的commitment都不同。
44 |
45 | Plonk具有 commit-and-prove的特性,
46 |
47 | commitment 有什麼種類?
48 | 1. hash
49 | 2. merkle-tree
50 | 3. pedersen commitment
51 | * 當然是還有其他的,我會繼續去深入了解。
52 |
53 | why zkSNARK?
54 | 1. 可以實現verifier on-chain
55 | 2. recursive proof: 可以進一步優化計算的compression及可以做到不同組合的計算效果.
56 |
57 | why Plonk?
58 | 1. 是一個universal trust setup (KZG10)
59 | 2. Proving O(nlogn), Verifier O(logn), Proof-size O(1)
60 |
61 | Plonk 的組成部分是 arithematic + polynomial IOP。
62 |
63 | circut:
64 | 門是屬於 Polynomial Gates。
65 | 當Circut經過計算之後會產出一堆polynomial。
66 |
67 | polynomial會交給polynomial IOP
68 |
69 | polynomial commitment
70 | 例子 : KZG10, IPM, FRI
71 |
72 | 這裡不是單單驗證一件事,而是驗證整個多項式。
73 |
74 | #### 參考文章:
75 | 1. Fiat-Shamir transformation
76 | * https://www.zkdocs.com/docs/zkdocs/protocol-primitives/fiat-shamir/
77 |
78 | 2. zkSNARK是如何組成的 — 1
79 | * https://medium.com/swf-lab/zksnark%E6%98%AF%E5%A6%82%E4%BD%95%E7%B5%84%E6%88%90%E7%9A%84-1-2c6a474bcb06
80 |
81 | 3. Zero Knowledge Proofs: Example with Pedersen Commitments in Monero
82 | * https://medium.com/coinmonks/zero-knowledge-proofs-um-what-a092f0ee9f28
83 |
84 | 4. Understanding KZG10 Polynomial Commitments
85 | * https://taoa.io/posts/Understanding-KZG10-Polynomial-Commitments
86 |
87 | 5. Recursive zkSNARKs: Exploring New Territory
88 | * https://0xparc.org/blog/groth16-recursion
89 |
90 |
91 | ## PLONK算術化
92 | https://www.youtube.com/watch?v=L3qMBzPgfWY
93 |
94 | Plonkish算术化是PLONK證明系統特有的算术化
95 | 在Plonkish出現之前,其實主流的電路表達形式都是為RICS,而這表達形式已被多個零知識證明算法所使用,包括Groth16。
96 | 學習了加法門和乘法門在運算符中的區分。
97 | * 以下是一個電路例子:
98 |
99 | 
100 | 1. 有3個門、6個輸入及1個輸出。
101 | 2. 滿足了3個約束。
102 | * X1 + X2 = X6
103 | * X3 * X4 = X5
104 | * X6 * X5 = OUT
105 |
106 |
107 | * 以下是一個矩陣W表格:
108 |
109 | 
110 |
111 | * 在表格中的第1行是各欄的標題,i是指門、 WL是指左輸入、WR是指右輸入及WO是指輸出。
112 | 第1列是指第1個門,會看到X6是指左輸入、X5是指右輸入及OUT是指輸出。
113 | 第2列是指第2個門,會看到X1是指左輸入、X2是指右輸入及X6是指輸出。
114 | 第3列是指第3個門,會看到X3是指左輸入、X4是指右輸入及X5是指輸出。
115 |
116 | * 為了能對加法門和乘法門進行區分,會以這個矩陣Q表格作展示:
117 |
118 | 
119 |
120 | * QL 和 QR 來表示加法門的輸入
121 | * QL 是指左輸入
122 | * QR 是指右輸入
123 |
124 | * QM 表示乘法門
125 | * QC 表示常量的數值
126 | * QO 表示輸出
127 |
128 |
129 | ### 認識複製約束
130 | * 由於在矩陣W表格中,可以看到第1個門的左轉入W6不一定等於第2個門的輸出X6。所以需要加入複製約束來確保第1個門的左轉入W6一定等於第2個門的輸出X6。也可以看到加入複製約束可以讓輸出的值會等於另一輸入的值,從入讓事出和輸入形成一種關連,而不是各自各的約束。
131 |
132 | ### 插值 (拉格朗日插值)
133 | 拉格朗日插值法可以找到一個多項式,其恰好在各個觀測的點取到觀測到的值。
134 | 有了一個多項式,可以便利驗證。
135 |
136 | ### 例子解說
137 | 矩陣W表格可以說是Prover需要準備的資料,當準備好之後,可以進行編譯。
138 | 完成後編譯,可以將結果發送給Verifier。
139 | 現在在矩陣W加多一項約束,約束是最終輸出是99。
140 | 因此,新增一條約束後的矩陣W表格會是這個:
141 | 
142 |
143 |
144 | * 由於只是新增輸出一項約束,不會影響算術門的數量及輸入的值。
145 |
146 | 假設參數:
147 | * 第1列是指第1個門,左輸入X6是3、右輸入X5是33及OUT輸出是99。
148 | * 第2列是指第2個門,左輸入X1是1、右輸入X2是2及X6是3。
149 | * 第3列是指第3個門,左輸入X3是3、右輸入X4是11及X5是33。
150 | * 第4列是沒有指向任何門,只是其中一個輸出約束,左輸入是0、右輸入是0及輸出是99。
151 |
152 | 另外,新增一條約束後的矩陣Q表格會是這個:
153 | 
154 |
155 | 當拉格朗日插值需要滿足QL[0,1,0,0]時,即f(0)=0, f(1)=1, f(2)=0, f(3)=0 .
156 | ```math
157 | L_{0}(x) = \frac{(x-1)(x-2)(x-3)}{(0-1)(0-2)(0-3)} = 84*[x^3 - 6*x^2 + 11x -6] = 84x^3 + x^2 + 15x + 1
158 | ```
159 |
160 | ```math
161 | L_{1}(x) = \frac{(x)(x-2)(x-3)}{(1-0)(1-2)(1-3)} = 51*[x^3 - 5*x^2 + 6x] = 51x^3 + 48x^2 + 3x
162 | ```
163 |
164 | ```math
165 | L_{2}(x) = \frac{(x)(x-1)(x-3)}{(2-0)(2-1)(2-3)} = 50*[x^3 - 2*x^2 + 49x] = 50x^3 + 2x^2 + 49x
166 | ```
167 |
168 | ```math
169 | L_{3}(x) = \frac{(x)(x-1)(x-2)}{(3-0)(3-1)(3-2)} = 17x^3 + 50x^2 + 34x
170 | ```
171 |
172 | * 最終的拉格朗日插值式為:
173 | ```math
174 | P(x) = 0*L_{0}(x) + 1*L_{1}(x) + 0*L_{2}(x) + 0*L_{3}(x) = 51x^3 + 48x^2 + 3x
175 | ```
176 |
177 | 當拉格朗日插值需要滿足WL[3,1,3,0]時,即f(0)=3, f(1)=1, f(2)=3, f(3)=0 .
178 | * 最終的拉格朗日插值式為:
179 | ```math
180 | P(x) = 3*L_{0}(x) + 1*L_{1}(x) + 3*L_{2}(x) + 0*L_{3}(x) = 49x^3 + 57x^2 + 94x + 3
181 | ```
182 |
183 | 換言之,要滿足QL[3,1,3,0],就必須在f(0)=3, f(1)=1, f(2)=3, f(3)=0時通過以上多項式。
184 |
185 | ## PLONK中的多項式
186 |
187 | * 透過多項式編碼,可以將多個約束轉換成一個約束。
188 |
189 | ### 多項式的概率檢查
190 | * 要做多項式的概率檢查,需要有2個多項式,而且同為2個次數不多於d的多項式。Verifier只要進行一次多項式隨機挑戰就可以。這是Schwartz-Zippel定理。
191 | * 因為可以進一步地去使用多項式承諾(Polynomial Commitment),讓Prover負責計算x在某一任意地方的值,然後發送證明,這樣Verifier的工作量可以減少。
192 | * 假設要驗證向量a + 向量b是否等於向量c:
193 | 可以先把向量編碼成多項式(系數編碼方式)
194 | ```math
195 | a(x) = a_{0} + a_{1}(x) + a_{2}(x^2) + ... + a_{n-1}(x^n-1)
196 | ```
197 | ```math
198 | b(x) = b_{0} + b_{1}(x) + b_{2}(x^2) + ... + b_{n-1}(x^n-1)
199 | ```
200 | ```math
201 | c(x) = c_{0} + c_{1}(x) + c_{2}(x^2) + ... + c_{n-1}(x^n-1)
202 | ```
203 | Verifier 只需要給出一個隨機挑戰值(任意值) ζ∈F
204 | ```math
205 | a(ζ) + b(ζ) = c(ζ)
206 | ```
207 | 如果成功證明到以上公式,則向量a + 向量b是等於向量c。
208 | 不過當要驗證向量a乘向量b是否等於向量c,就需要用拉格朗日插值的編碼方式,經轉換之後如下:
209 | ```math
210 | a(X)⋅b(X)=c(X),∀X∈H
211 | ```
212 | 但在這公式,Verifier需要挑戰多次才可以縮小出錯概率。
213 | 因此,需要更高效的方法來進行檢測,目標是只用一次就可以檢查出Prover是否存在作弊行為。
214 | ```math
215 | a(X)⋅b(X)−c(X)=q(X)⋅z H(X),∀X∈F
216 | ```
217 | 在公式上可以看到a(X)⋅b(X)−c(X)會等於0,所以q(X)⋅zH(X)也會等於0。
218 | 換言之,在X∈H的條件下,H會是a(X)⋅b(X)−c(X)的根集合。因為X必須要使到a(X)⋅b(X)−c(X)等於0。
219 |
220 | 另外,a(X)⋅b(X)−c(X)可以被多項式zH(X)整除,並得到一個商多項式q(X)。所以只要讓Prover計算出q(X),就可以使到Verifier的工作量減少至只需進行一次隨機檢測就可知道a(X)⋅b(X)−c(X)在X∈H的條件下是否等於0。而Verifier 計算 zH(ζ) 需要 O(n) 的計算量。
221 |
222 | ### 單位根 Roots of Unity
223 | 以單位根作為 H,這可使到zH(ζ)的計算量會減少至O(logn)。
224 |
225 | ## PLONK中的置換證明
226 | Plonk 的複製約束是通過置換證明(Permutation Argument)來實現。
227 | 在這個矩陣W表格中(加入位置標示):
228 | 
229 | 可以看到,WL1 = WO2, WR1 = WO3, WO1 = WO4 。而置換證明可以通過轉換它們的位置,然後再證明置換後的新矩陣是等於矩陣W。
230 |
231 | ### 基礎協議 - Grand Product Argument
232 | 由於進行多項式編碼,所以會把多個單乘法壓縮成單次乘法的驗證。
233 | 這裡可以理解成將多個約束壓縮在一起,轉換成1個可驗證的多項式。
234 | * 引入一個輔助向量r
235 | ```math
236 | r_{0} = 1
237 | ```
238 | * r是每一個對上計算的結果(Accumulator)
239 | ```math
240 | r_{k+1} = q_{k}*r_{k}
241 | ```
242 | 假設現在有3個約束,第1個約束的起始值是1,公式是:
243 | ```math
244 | L_{0}*(r(X)-1) = 0 ,∀X∈H
245 | ```
246 | 第2個約束(遞歸的乘法關系)的公式是:
247 | ```math
248 | q(X)*r(X) = r(w.X) ,∀X∈H∖{ω-^1}
249 | ```
250 | 第3個約束 - 為最後結果是:
251 | ```math
252 | r_{n-1} = p ,∀X∈H
253 | ```
254 | 第3個約束的公式是:
255 | ```math
256 | L_{n-1}*(r(X)-r_{n-1}) = 0 ,∀X∈H
257 | ```
258 | 利用遞歸的乘法關系:
259 | ```math
260 | q(X)*r(X) = r(w.X) ,∀X∈H
261 | ```
262 | 最後得出可以驗證的多項式:(以下是相關步驟)
263 | ```math
264 | q(X)*r(X) - r(w.X) = 0 ,∀X∈H
265 | ```
266 | ```math
267 | L_{0}(X)*(r(X) - 1) + q(X)*r(X) - r(w.X) = 0 ,∀X∈H
268 | ```
269 | ```math
270 | L_{0}(X)*(r(X) - 1) + (α*q(X)*r(X) - r(w.X)) = 0 ,∀X∈H
271 | ```
272 | ```math
273 | L_{0}(X)*(r(X) - 1) + α*(q(X)*r(X) - r(w.X)) = h(X)*Z_{H}(X) ,∀X∈H
274 | ```
275 | 當中α是一個隨機數,h(X)是商多項式,
276 | ```math
277 | Z_{H}(X)是(X-1)(X-W)...(X-W^{n-1})
278 | ```
279 | ### 如何利用連乘證明來實現Multiset等價證明(Multiset Equality Argument)
280 |
281 | 假設向量 {qi} 為一個多項式 q(X) 的根集合,即對向量中的任何一個元素qi,都滿足q(ri)=0。這個多項式可以定義為:
282 | ```math
283 | q(X) = (X - q_{0})(X - q_{1})...(X - q_{n-1})
284 | ```
285 | 如果有另一多項式p(X)與q(x)相同,則會具有相同的根集合。
286 | 可以利用 Schwartz-Zippel 定理做檢驗,只要Verifier輸入一個隨機數 γ,Prover就可以通過下面的公式以證明向量 {pi} 和 {qi} 是在多重集合上是等價。
287 | ```math
288 | \prod_{i\in[n]}(γ-p_{i}) = \prod_{i\in[n]}(γ-q_{i})
289 | ```
290 | 然後,再使用連乘證明完成驗證,通過加入輔助向量,轉換成可以驗證的多項式。在目前例子,兩個連乘公式可以轉換成為一個連乘公式:
291 | ```math
292 | \prod_{i\in[n]}\frac{(γ-p_{i})}{(γ-q_{i})} = 1
293 | ```
294 |
295 | ### 如何證明Multiset與置換證明(Permutation Argument)的關係
296 | 首先,要Prover證明兩個向量是滿足奇偶位置互換的置換情況。
297 | ```math
298 | \vec{a} = (a_{0}, a_{1}, a_{2}, ..., a_{n-1}, a_{n})
299 | ```
300 | ```math
301 | \vec{b} = (b_{0}, b_{1}, b_{2}, ..., b_{n-1}, b_{n})
302 | ```
303 | 可以運用多項式編碼把向量轉換成多項式,同時加入位置向置來表示奇偶位置互換。
304 | ```math
305 | \vec{i} = (0, 1, 2, 3, ..., n-1, n)
306 | ```
307 | ```math
308 | σ = (0, 1, 3, 2, ..., n, n-1)
309 | ```
310 |
311 | 兩個向量以表格形式列出一部分:
312 | 
313 | 之後,再整理一下,將表格中的左面和右面分成2組如下:
314 | ```math
315 | a^{\prime} = (a_{i}, i) , b^{\prime} = (b_{i}, σ(i))
316 | ```
317 | ```math
318 | (a_{0}, 0) , (b_{0} = a_{1}, 1)
319 | ```
320 | ```math
321 | (a_{1}, 1) , (b_{1} = a_{0}, 0)
322 | ```
323 | ```math
324 | \vdots , \vdots
325 | ```
326 | ```math
327 | (a_{n-1}, n-1) , (b_{n-1} = a_{n}, n)
328 | ```
329 | ```math
330 | (a_{n}, n) , (b_{n} = a_{n-1}, n-1)
331 | ```
332 | 根據以上情況,如果2個向量(a, b)滿足奇偶位置互換的置換情況,則以上2個向量(a', b')也會滿足Multiset等價的關系。
333 |
334 | 若要轉換為一個多項式(或一個新的向量),可以加入一個隨機數β,結果如下:
335 | ```math
336 | a_{i}^{\prime} = (a_{i} + β*i) , b_{i}^{\prime} = (b_{i} + β*σ(i))
337 | ```
338 | ```math
339 | (a_{0} + β*0) , (b_{0} + β*1)
340 | ```
341 | ```math
342 | (a_{1} + β*1) , (b_{1} + β*0)
343 | ```
344 | ```math
345 | \vdots , \vdots
346 | ```
347 | ```math
348 | (a_{n-1} + β*(n-1)) , (b_{n-1} + β*(n))
349 | ```
350 | ```math
351 | (a_{n} + β*(n)) , (b_{n} + β*(n-1))
352 | ```
353 |
354 | ## 算術約束與複製約束
355 |
356 | ### 向量的複製約束
357 | 一個向量中,可以證明多個不同位置上的向量元素相等,例子如下:
358 | ```math
359 | \vec{a}= (a_{0} + a_{1} + a_{2} + a_{3})
360 | ```
361 | 如果要證明
362 | ```math
363 | a_{0} = a_{2}
364 | ```
365 | 可以將它們的位置對調,以σ 表示位置向量:
366 | ```math
367 | \vec{a}_{σ} 為置換後的向量
368 | ```
369 | ```math
370 | σ = (2, 1, 0, 3), \vec{a}_{σ} = (a_{2} + a_{1} + a_{0} + a_{3})
371 | ```
372 | 只要Prover證明到置換前的向量和置換後的向量相等,就表示:
373 | ```math
374 | a_{0} = a_{2} 是正確的
375 | ```
376 | ### 向量(多個)的複製約束
377 | * 以下會以例子說明整個流程:
378 | 選用矩陣W表格,同時加入一個輸出的約束。
379 | 
380 | 會留意到有些地方的值是相等的,包括:
381 | ```math
382 | w_{a,1} = w_{c,2}, w_{b,1} = w_{c,3}, w_{c,0} = w_{c,1}
383 | ```
384 | * 對表格中的三列向量用三個置換向量統一地進行位置編碼,結果如下:
385 | 
386 | 置換後的向量為:
387 | ```math
388 | σ_{a} , σ_{b} , σ_{c}
389 | ```
390 | 
391 |
392 | 因此,現在會有2個向量,分別是置換前的向量及置換後的向量。為了進行下一步驗證,需要利用一個隨機數β來進行向量合併。
393 | 之後再利用另一個隨機數γ配合連乘以獲得2個向量的Multisets。
394 | 置換前的向量:
395 | ```math
396 | f_{i} = (w_{a,i} + β*id_{a,i} + γ)(w_{b,i} + β*id_{b,i} + γ)(w_{c,i} + β*id_{c,i} + γ)
397 | ```
398 | 置換後的向量:
399 | ```math
400 | g_{i} = (w^{\prime}_{a,i} + β*σ_{a,i} + γ)(w^{\prime}_{b,i} + β*σ_{b,i} + γ)(w^{\prime}_{c,i} + β*σ_{c,i} + γ)
401 | ```
402 | 進一步演示 - 置換前的向量:
403 | ```math
404 | f_{0} = (w_{a,0} + β*0 + γ)(w_{b,0} + β*4 + γ)(w_{c,0} + β*8 + γ)
405 | ```
406 | ```math
407 | f_{1} = (w_{a,1} + β*1 + γ)(w_{b,1} + β*5 + γ)(w_{c,1} + β*9 + γ)
408 | ```
409 | ```math
410 | f_{2} = (w_{a,2} + β*2 + γ)(w_{b,2} + β*6 + γ)(w_{c,2} + β*10 + γ)
411 | ```
412 | ```math
413 | f_{3} = (w_{a,3} + β*3 + γ)(w_{b,3} + β*7 + γ)(w_{c,3} + β*11 + γ)
414 | ```
415 | 進一步演示 - 置換後的向量:
416 | ```math
417 | g_{0} = (w^{\prime}_{a,0} + β*0 + γ)(w^{\prime}_{b,0} + β*4 + γ)(w^{\prime}_{c,0} + β*9 + γ)
418 | ```
419 | ```math
420 | g_{1} = (w^{\prime}_{a,1} + β*10 + γ)(w^{\prime}_{b,1} + β*11 + γ)(w^{\prime}_{c,1} + β*8 + γ)
421 | ```
422 | ```math
423 | g_{2} = (w^{\prime}_{a,2} + β*2 + γ)(w^{\prime}_{b,2} + β*6 + γ)(w^{\prime}_{c,2} + β*1 + γ)
424 | ```
425 | ```math
426 | g_{3} = (w^{\prime}_{a,3} + β*3 + γ)(w^{\prime}_{b,3} + β*7 + γ)(w^{\prime}_{c,3} + β*5 + γ)
427 | ```
428 | 由於
429 | ```math
430 | w_{a,1} = w^{\prime}_{c,2}
431 | ```
432 | ```math
433 | w_{c,2} = w^{\prime}_{a,1}
434 | ```
435 | 所以:
436 | ```math
437 | (w_{a,1} + β*1 + γ) = (w^{\prime}_{c,2} + β*1 + γ)
438 | ```
439 | ```math
440 | (w_{c,2} + β*10 + γ) = (w^{\prime}_{a,1} + β*10 + γ)
441 | ```
442 | 換言之:
443 | ```math
444 | \prod_{x\in H}f(X) = \prod_{i\in H}g(X)
445 | ```
446 | ```math
447 | \prod_{x\in H}\frac{f(X)}{g(X)}
448 | ```
449 | 現在再利用新的向量z,以表示連乘計算的一系列中的過程。
450 | 需假設:
451 | ```math
452 | Z_{0} = 1, Z_{i+1} = Z_{i}*\frac{f(i)}{g(i)}
453 | ```
454 | Prover可以計算出以下的值:
455 | 
456 | ```math
457 | 如果\vec{f} = \vec{g},則Z_{N}會等於1
458 | ```
459 | 所以:
460 | ```math
461 | Z_{N} = Z_{0} = 1
462 | ```
--------------------------------------------------------------------------------
/FRI&Stark/part2 lesson4/2024-09-05-STARK.md:
--------------------------------------------------------------------------------
1 | ---
2 | layout: post
3 | title: STARK
4 | categories: STARK, soundness
5 | author: Yingfei
6 | ---
7 | 本文主要介绍STRAK协议的形式化定义及安全性讨论,会从密码学的角度描述STRAK协议,主要参考文献为ethSTARK。本文默认读者已经熟悉STARK协议的流程。
8 |
9 | ## STARK协议
10 |
11 | 本节我们将形式化描述STARK协议,首先介绍AIR,随后给出STARK(IOP)协议的细节。
12 |
13 | ### AIR
14 |
15 | **定义1(AIR)** 一个algebraic intermediate representation (AIR)是由tuple $\mathsf{A}=(\mathbb{F}, w, h, d, s, g, I, Cset)$组成的, 其中
16 | - $\mathbb{F}$是一个有限域;
17 | - $w, h, d, s$是一些整数;
18 | - $w$是trace的列数。
19 | - $s$是constraints集合的size。
20 | - $d$是一个constraint的最高degree。
21 | - $h$表示trace domain $\mathsf{H}_0$中使用的乘法子群的size的对数,即,$|\mathsf{H}_0| = 2^h$。
22 | - $g$是乘法群$\mathsf{H}_0 \subset \mathbb{F}^*$的生成元,因此 $|\mathsf{H}_0| =2^h$;
23 | - $I\subseteq \{1,...,w\} \times \{0, ...,2^h-1\}$是mask indices的集合。定义$Y=\{Y_{i,j}:{i,j}\in I\}$是由$I$中元素索引的mask variables;
24 | - $Cset = \{C_1, ... C_s\}$ 是constraints的有限集合,大小为s。每个constraint都由$s$个有序对$C_i = (Q_i, \mathsf{H}_i)$组成。
25 | - $Q_i \in \mathbb{F}^{\leq d}[Y]$是一个关于mask variables的多变量多项式,总degree至多为$d$,称为第$i$个 constraint polynomial.
26 | - $\mathsf{H}_i \subseteq \mathsf{H}_0$是trace domain的子集,称为第$i$个constraint enforcement domain.
27 | - 用$|Cset|$表示the arithmetic complexity of the constraints,定义为$|Cset| \sum^s_{i=1} (|Q_i|+ |\mathsf{H}_i|)$,其中,$|Q_i|$是计算多项式$Q_i$的算术电路,$|\mathsf{H}_i|$是vanishing polynomial $\mathsf{Z}_{\mathsf{H}_i}$的算术复杂度。
28 |
29 | **定义2 (AIR assignment and composition)** 一个AIR assignment是由一组多项式$\vec{P} = (P_1, ..., P_w) \in \mathbb{F}[X]^w$ 组成的。
30 | 给定一个AIR约束多项式$Q\in \mathbb{F}[Y]$,那么$Q$的composition 和 assignment $\vec{P}$ 是一个单变元多项式,用$Q \circ \vec{P} \in \mathbb{F}[X]$表示。它是通过用$P_i(g^j\cdot X) \in \mathbb{F}[X]$ 替换$Q(Y)$中的变量 $Y_{i,j} \in Y$得到的,我们用$Y_{i,j} \gets P_i(g^j \cdot X)$来简化表示这个替换。
31 |
32 | **定义3 (Satisfiability)** 一个AIR assignment $\vec{P} = (P_1, ..., P_w) \in \mathbb{F}[X]^w$满足一个AIR实例$\mathsf{A}=(\mathbb{F}, w, h, d, s, g, I, Cset)$当且仅当
33 | $$\forall i \in [s]: x\in \mathsf{H}_i \to (Q \circ \vec{P})(x) = 0.$$
34 | 换句话说,$\vec{P}$满足$\mathsf{A}$ 当且仅当 对于每个constraint $C_i=(Q_i, \mathsf{H}_i) \in Cset$, $Q \circ \vec{P}$ vanishes on $\mathsf{H}_i$。
35 |
36 | vanish:多项式$\mathsf{Z}_{\mathsf{H}_i}(X)$在$\mathbb{F}[X]$上整除多项式$Q \circ \vec{P}$。
37 |
38 | 用大家习惯的statement和witness的方式来表达,在STARK中,statement是一个AIR实例$\mathsf{A}=(\mathbb{F}, w, h, d, s, g, I, Cset)$,它定义了协议需要的公开参数以及寄存器之间的约束关系,witness则是AIR assignment $\vec{P} = (P_1, ..., P_w)$,也就是trace多项式。
39 |
40 | ### 协议
41 |
42 | 在描述协议之前,我们先介绍一些辅助输入aux。
43 | - $\mathbb{K}$ 是有限域 $\mathbb{F}_q$ 的有限扩张,size为 $q^e, e\geq1$。为了简便,全文符号对 $\mathbb{F}$ 和$\mathbb{F}_q$ 不做区分。
44 | - $\mathsf{D} \subset \mathbb{K}^*$是乘法子群 $\mathsf{D}_0 \subset \mathbb{K}^*$的非平凡陪集。称$\mathsf{D}$为evaluation domain。recall:AIR的trace domain $\mathsf{H}_0 \subset \mathsf{D}_0$。
45 | - $k'$表示$|\mathsf{D}|$的对数,即 $|\mathsf{D}| = 2^{k'}$。
46 | - $\rho = 2^h/2^{k'}$ 表示IOP协议的rate, $\rho^{-1}$为blowup factor.
47 | - $\mathsf{aux}_{\mathsf{FRI}}$定义为FRI协议的辅助输入。
48 |
49 | 在实际协议中,上述$\mathsf{D}$是LDE的input domain。注意,$\mathsf{D}$与AIR的trace domain $\mathsf{H}_0$ (trace函数的input domain)是互不相交的。这是为了避免LDE的商多项式的分母为0。
50 |
51 | 我们还会用到下列符号:
52 | - $\mathsf{Quotient} : \mathsf{D} \to \mathbb{F}$: 对于 $(x_0, y_0) \in \mathbb{K}/\mathsf{D} \times \mathbb{K}$ 和函数$f : \mathsf{D} \to \mathbb{K}$,定义函数$f$的quotient 如下:$$\mathsf{Quotient}(f; x_0, y_0) (x) = \frac{f(x)-y_0}{x-x_0}.$$
53 | - $\mathsf{RS}[\mathbb{K},S, \rho]$ 表示定义在域$\mathbb{K}$上的Reed-Solomon码,其evaluation domain为 $S$,码率 rate是$\rho$。 $$\mathsf{RS}[\mathbb{K},S, \rho] = \{f: S\to \mathbb{K}: deg(f) < \rho|S| \}$$
54 | 下面,我们开始描述协议。
55 |
56 | **$\mathcal{P,V}$ 的公共输入**:AIR实例 $\mathsf{A}=(\mathbb{F}, w, h, d, s, g, I, Cset)$ 和IOP辅助输入 $\mathsf{aux}=(\mathbb{K}, e, \mathsf{D}, k', \mathsf{aux}_{\mathsf{FRI}})$。
57 | **$\mathcal{P}$ 的秘密输入**:AIR assignment $\vec{P} = (P_1, ..., P_w) \in \mathbb{F}[X]^w$。
58 |
59 | 0. **预处理**:
60 | - Constraint weighted degree:对每个constraint $C_i=(Q_i, \mathsf{H}_i) \in Cset$,定义第$i$个composed degree $d_i = deg(Q_i)\cdot (2^h-1) - |\mathsf{H}_i|$。
61 | - Designated degree:定义$d_{max}$是比上述最大的$d_i$严格大的一个2个幂次整数。定义$a= d_{max}/2^h$.
62 | - Degree correction:对每个constraint $C_i=(Q_i, \mathsf{H}_i) \in Cset$,定义degree correction参数$c_i = d_{max}-d_i - 1$。
63 | 这一步的预处理是为了在Step2确定degree adjustment的次数,便于把高次多项式拆成$a$个与trace多项式次数相同的多项式。
64 | 1. **执行trace oracle**:证明者发送oracle functions $f_1, ..., f_w : \mathsf{D} \to \mathbb{K}$。
65 | 函数$f_i$是满足AIR的多项式$P_i(X)\in \mathbb{F}$,在evaluation domain $\mathsf{D}$上计算得到的Evaluation。即,对于 $\forall x \in \mathsf{D}$,计算所有$P_i(x)$的取值组成$f_i$。
66 | note:
67 | - $P_i(X)$的次数 $deg(P_i)<2^h$。
68 | - 如果$\mathsf{D} \subset \mathbb{F}$,那么 $f_1, ..., f_w$的取值就在$\mathbb{F}$上。这与$\mathsf{D}$和AIR的trace domain $\mathsf{H}_0$ 互不相交并不冲突。
69 | 2. **constraints线性组合**:验证者选择$2s$个随机值 $\vec{r} = (r_1, r_1', ..., r_s, r_s') \in \mathbb{K}^{2s}$发送给$\mathcal{P}$。随后$\mathcal{P, V}$共同把AIR实例中的s个constraints全部随机组合起来,得到变量$(X,Y)$的一个rational函数 $Q^{\vec{r}}(X,Y)$:$$Q^{\vec{r}}(X,Y):= \sum_{i=1}^s \left( r_i + r_i' X^{c_i}\right)\cdot \frac{Q_i(Y)}{Z_\mathsf{H_i}(X)}$$
70 | 在prover这端,$Y_{i,j}$已经被$P_i(g^jX)$替换了。由于每个$P_i$的次数严格小于$2^h$,而且$Q \circ \vec{P}$ vanishes on $\mathsf{H}_i$,因此等号右侧可以总结成一个关于变量$X$的多项式$R^{\vec{r}}_i(X)$,该多项式的degree小于$d_{max}$。
71 |
72 | 3. **constraint trace oracle**:$\mathcal{P}$ 发送oracle函数$f_0^{\vec{r}}, ..., f_{a-1}^{\vec{r}} : \mathsf{D} \to \mathbb{K}$。
73 | 每个函数$f_i^{\vec{r}}$都是多项式$P_i^{\vec{r}}(X)$在$\mathsf{D}$上的evaluation,满足:$$\left(Q^{\vec{r}}(X,Y) \circ \vec{P} \right)(X) = \sum^{a-1}_{k=0} X^k \cdot P_k^{\vec{r}}(X^a).$$
74 | 由于在 Step4 中线性组合的多项式 $R^{\vec{r}}_i(X)$ degree小于$d_{max}$,超过了trace evaluation domain的size。为了与trace的多项式$P_i$ 线性组合,一起做FRI验证low degree,所以需要拆成多个小degree组合。
75 |
76 | 拆分方式为:拆成$a= d_{max}/2^h$个多项式,每个$P_i^{\vec{r}}(X)$以$a$为次数的间隔,取原多项式中的对应系数。所以最终得到的每个多项式$P_i^{\vec{r}}(X)$的degree均小于$2^h$。
77 |
78 | 4. **DEEP Query**: $\mathcal{V}$ 从 $\mathbb{K}* \setminus (\mathsf{H}_0 \cap \bar{\mathsf{D}})$ 采样一个随机值 $\mathsf{q}$。集合$\bar{\mathsf{D}} = \{y \in \mathbb{K}* : y^{a} \in \mathsf{D}\}$。排除集合 $\mathsf{H}_0$ 是为了保证计算answer $\alpha$ 时 $\mathsf{q} \cdot g^j$ 不会重叠到另一个$g^k$,排除集合 $\bar{\mathsf{D}}$ 是为了避免计算商多项式时分母为0。
79 |
80 | 5. **DEEP Answer**: $\mathcal{P}$ 发送 answer 序列 $\{\alpha_{i,j}: (i,j) \in I\} \cup \{ \beta_k: k \in\{0, ..., a-1\}\}$。其中:$$\alpha_{i,j} = P_i(\mathsf{q} \cdot g^j), \beta_k = P_k^{\vec{r}}(\mathsf{q}^a)$$
81 | 若等式 $Q^{\vec{r}}(\mathsf{q},\{Y_{i,j} \gets \alpha_{i,j}\}) = \sum^{a-1}_{k=0} \mathsf{q}^k \cdot \beta_k$成立,则称约束$Q^{\vec{r}}(X,Y)$ 在该answer下是验证有效的。 $\{Y_{i,j} \gets \alpha_{i,j}\}$表示用$\alpha_{i,j}$替换$Y_{i,j}$。
82 |
83 | 6. **FRI 线性组合**: $\mathcal{V}$ 采样随机值 $$r^F = \{r^F_{(i,j)}: (i,j) \in I\} \cup \{r^F_k: k \in\{0, ..., a-1\}\} \in \mathbb{K}^{I\cup[a]}$$ 并发送给$\mathcal{P}$。
84 |
85 | 7. **FRI协议**:$\mathcal{P, V}$共同利用FRI协议的辅助输入$\mathsf{aux}_{\mathsf{FRI}}$,执行FRI协议,验证 proximity to 函数 $g_{(\vec{r},q,answer, r^F)}:\mathsf{D} \to \mathbb{K}$ 的RS码 $\mathsf{RS}[\mathbb{K},\mathsf{D}, \rho]$。其中,$$g_{(\vec{r},\mathsf{q}, answer, r^F)}:= \sum_{(i,j) \in I} r^F_{(i,j)}\cdot \mathsf{Quotient}(f_i; \mathsf{q}\cdot g^j, \alpha_{i,j})(x) + \sum_{k=0}^{a-1}\mathsf{Quotient}(f_k^{\vec{r}}; \mathsf{q}^a, \beta_k)(x).$$
86 | 8. **协议验证**:$\mathcal{V}$ 接受条件:
87 | 1. FRI 协议接受$g_{(\vec{r},q,answer, r^F)}$ ;
88 | 2. $Q^{\vec{r}}(X,Y)$ 在该answer下是验证有效的。
89 |
90 |
91 | ## STARK安全性
92 | ### 基础定义
93 |
94 | 下面我们简单描述IOP协议涉及的几个安全性定义。
95 | Completeness 说明了诚实执行协议的证明者与诚实执行协议的验证者交互,最终验证者会(以指数接近1的概率)接受证明。
96 |
97 | Soundness 指的是,如果(恶意的)证明者证明的statement是错误的,在上述协议中,即$\mathsf{A}$不是AIR实例,那么验证者会(以指数接近1的概率,$1-\epsilon$)拒绝证明。
98 |
99 | Knowledge Soundness 是说,如果(恶意的)证明者要证明的statement是正确的,验证者以某一个概率接受了证明,则存在一个概率多项式时间的提取器,可以从证明者与验证者的交互中提取出statement对应的witness。
100 |
101 | 以上述协议为例,如果 $\mathsf{A}$ 是AIR实例,验证者以$\epsilon$概率接受了证明,那么我们可以提取出$\mathsf{A}$对应的trace 多项式$\vec{P}$。
102 |
103 | 这个定义意味着恶意的证明者如果能生成正确的证明,则代表这个证明者获得了statement (AIR实例) 的witness。上述定义中提到的$\epsilon$称为soundness error。
104 |
105 | 做安全性证明需要注意的一些细节:
106 | - 提取器的输入和验证者一样。
107 | - 提取器可以调用恶意的证明者作为自己的子程序,但需要注意这个恶意的证明者也没有witness。
108 |
109 | ### 安全性分析需要用到的几个定理
110 |
111 | 首先,我们需要从编码的角度去看STARK协议中出现的多项式:向量$f$是words,AIR的assignment是RS code的codewords。
112 |
113 | **定理1** (Johnson bound)对于所有的$\eta \in (0, 1-\sqrt{\rho})$,编码$V$是$(1-\sqrt{\rho}-\eta, \frac{1}{2\eta \sqrt{\rho}})$- list-decodable。
114 |
115 | 这个定理说明了,对于一个向量$u \in \mathbb{F}^n_q$,在码 (code) $V\subset \mathbb{F}^n$上,至多存在$\ell = \frac{1}{2\eta \sqrt{\rho}}$个的码字 (codeword),与$u$的相关汉明距离(relative Hamming distance)不超过$\gamma = 1-\sqrt{\rho}-\eta$。
116 |
117 | **定理2** (Guruswami–Sudan list decoding)GS list decoding算法输入一个word $u:\mathsf{D} \to \mathbb{F}_q$,一个RS码$V = \mathsf{RS}[\mathbb{F},\mathsf{D}, \rho]$,一个slackness参数$\eta>0$,输出$V$中agree with $u$ 的一组码字(agreement domain $S$),density至少是D的$\sqrt{\rho} +\eta$。该算法的期望时间是 $n, 1/\rho, 1/\eta$ 和 $\log q$ 的多项式级别。
118 |
119 | agree with:在agreement domain $S$ 上,word $u$ 与码字 $v$ 满足:$\forall x \in S, u(x) = v(x)$。
120 | density:agreement domain的 size 与 word $u$ 的全部input比值 $\sigma \leq|S| / |\mathsf{D}|$。
121 |
122 | 因为agree考虑的是$x$ 从 $S$ 集合中取值时codeword与word的值是否相同,density也考虑的是 $x$ 在 $S$ 集合取值与原本 $x$ 在 $\mathsf{D}$ 中任意取值的情况,即两个集合的size对比。
123 |
124 | 下一部分knowledge soundness的提取器将会用到定理2介绍的解码算法。在此之前,我们需要先扩展上述算法到多组words的联合解码。
125 |
126 | **定义4**(Correlated agreement)定义向量集合$V\subset \mathbb{K}^{\mathsf{D}}$,$W=\{w_1, ..., w_k\}$,其中每个$w_i \in \mathbb{K}^{\mathsf{D}}$。定义agreement参数$\sigma \in [0,1]$。称$W$与$V$在 agreement domain $S \subset \mathsf{D}$ 上以density $\sigma$ 相关一致(correlated agree),如果满足:
127 | - $\sigma \leq|S| / |\mathsf{D}|$,
128 | - 存在$v_1, ..., v_k \in V$,使得,$w_i$ 在 $S$ 上与 $v_i$ agree,即$\forall x \in S, w_i(x) = v_i(x)$。
129 |
130 | 我们称S是一个最大agreement domain如果它不真包含 ($\subsetneq$) 在任何一个agreement domain里。
131 |
132 | 下面我们介绍RS算法的一个推导引理,这个引理将直接用于构造STARK协议的知识提取器。
133 |
134 | **引理1**(Correlated agreement list decoder)定义RS码$V = \mathsf{RS}[\mathbb{F},\mathsf{D}, \rho]$,向量集合$W=\{w_1, ..., w_k\}$,其中每个$w_i \in \mathbb{K}^{\mathsf{D}}$。定义$\sigma = \sqrt{\rho} + \eta, \eta>0$是一个agreement density参数。存在一个随机化算法,期望运行时间是 $1/\rho, 1/\eta, k, \log{|\mathbb{K}|}$ 的多项式级别,该算法输出一个列表$\mathcal{S}=\{S_1, ..., S_{\ell} \}$。该列表是所有density至少为$\sigma$的最大agreement domain,满足$\ell \leq 1/(2\eta\sqrt{\rho})$。此外,每一组$S_i, w_j \in W, v_{i,j} \in V$都满足$w_j$ 在 $S_i$ 上与 $v_{i,j}$ agree。
135 |
136 | 这个算法是通过多次调用GS列表解码算法,并对算法输出的agreement domain逐次求交集得到的,而$\ell \leq 1/(2\eta\sqrt{\rho})$这个条件则是直接应用Johnson bound得到的结论。
137 | 在此暂时忽略该引理的证明。
138 |
139 |
140 | ### 安全性证明
141 |
142 | #### 安全性定理
143 |
144 | 定理3给出了STARK协议的soundness error上界。
145 |
146 | **定理3** (Knowledge Soundness)若验证者 $\mathcal{V}$ 满足条件1和2,则存在一个可以成功输出AIR assignment, 即$\vec{P}= {P_1},...,{P_w}$ 的knowledge extractor $\mathcal{E}(\mathsf{A}=(\mathbb{F}, w, h, d, s, g, I, Cset), \mathsf{aux}, f=(f_1, ..., f_w))$。如果 $\mathcal{V}$ 满足以下条件:
147 | 1. 在FRI的Query阶段,$\mathcal{V}$ 调用FRI的验证者 $\mathsf{s}$ 次。
148 | 2. 存在一个证明者$\mathcal{P}^*(\mathsf{A}, \mathsf{aux})$ 在Step1 oracle发送$f=(f_1, ..., f_w)$, 且$\mathcal{V}$与$\mathcal{P}$交互时,$\mathcal{V}$接受的概率大于 $$\epsilon_{total} = \frac{\ell}{|\mathbb{K}|} + \frac{(d_{max}+2^h + a) \cdot \ell}{|\mathbb{K}|-a|\mathsf{D}| + |\mathsf{H}_0|} + \epsilon_{\mathsf{FRI}}(q,n,\rho, m,s,\vec{t}),$$ 其中整数$m\geq2, \ell=m/\rho$.
149 |
150 | 这个定理说明,存在一个提取器可以提取AIR的witness,但这个提取器要输入LDE的多项式$f$。STARK的PIOP中,$f$不是直接发送给验证者的,因此,我们不能直接利用定理4证明STARK协议的knowledge soundness,需要做一点转化。这个转化需要借用下面的推论。
151 |
152 | **推论1**(Knowledge extraction from sufficiently convincing prover)给定整数$R\geq1, m\geq3$, 给定$\mathsf{A}=(\mathbb{F}, w, h, d, s, g, I, Cset), \mathsf{aux}=(\mathbb{K}, e, \mathsf{D},k',\mathsf{aux}_{\mathsf{FRI}})$以及$\mathsf{aux}_{\mathsf{FRI}}=(\vec{t},s)$, $2^{-R}=2^h/2^{k'}$。假设存在证明者$\mathcal{P}^*$,满足
153 | $$\Pr[\langle \mathcal{V}(\mathsf{A, aux}, ), \mathcal{P}(\mathsf{A, aux})\rangle = accept] \geq 2\cdot \epsilon_{total},$$
154 | 那么, $\mathsf{A} \in \mathcal{L}_{\mathsf{AIR}}$,即 $\mathsf{A}$ 是$\mathsf{AIR}$实例, 且存在一个knowledge extractor $\mathcal{E}'$,在输入$(\mathsf{A, aux})$时,与$\mathcal{P}^*$交互可以输出满足 $\mathsf{A}$的assignment,提取器的期望运行时间为$(w,2^h, d, |Cset|, \log|\mathbb{F}|,1/\epsilon)$的多项式。
155 |
156 | **构造$\mathcal{E}'$**:$\mathcal{E}'$重复执行如下步骤$1/\epsilon_{total}$次
157 | - 调用$\mathcal{P}^*$ 并读取oracle $f = (f_1,...,f_w)$;
158 | - 调用定理4中的提取器$\mathcal{E}(\mathsf{A,aux},f)$。
159 |
160 | $\mathcal{E}'$不需要输入$f$,因此可以直接用在STARK的证明里,因此,我们可以通过合适的取值使得soundness error是一个可忽略的函数(安全参数的指数分之一,例如$2^{-128}$),证明上述STARK协议是一个knowledge soundness error至多为$\epsilon$的Scalalbe Transparent IOP of Knowledge协议,满足completeness和knowledge soundness。
161 |
162 | $\epsilon$ 是随机算法Las Vegas algorithm的优势。
163 |
164 | #### Knowledge Extractor的构造
165 |
166 | 现在介绍如何构造定理3中提到的knowledge extractor $\mathcal{E}$。
167 |
168 | $\mathcal{E}$的输入是$\mathsf{A}=(\mathbb{F}, w, h, d, s, g, I, Cset), \mathsf{aux}, f=(f_1, ..., f_w)$,其中$\mathsf{aux} = (\mathbb{K}, e, \mathsf{D}, k', \mathsf{aux}_{\mathsf{FRI}})$是协议的辅助输入。提取器$\mathcal{E}$可以从证明者的第一个oracle function $(f_1, ..., f_w)$ 中提取AIR的assignment $\vec{P}$。
169 | - 准备:$\rho = 2^h/|\mathsf{D}|$。定义$\rho^+ =\frac{2^h+1}{|\mathsf{D}|}$. $\mathsf{RS}[\mathbb{F},\mathsf{D}, \rho]$的码字都是degree小于$2^h$的多项式的求值,所以$\mathsf{RS}[\mathbb{F},\mathsf{D}, \rho^+]$的码字对应的多项式degree都小于$2^h$。
170 | - $\mathcal{E}$首先以 agreement参数$\sqrt{\rho^+}(1+\frac{1}{2m})$, 向量集合$U=\{f_1, ..., f_w\} \subset (\mathbb{F}^{\mathsf{D}})^w$ 和RS码$\mathsf{RS}[\mathbb{F},\mathsf{D}, \rho^+]$ 调用引理1的解码器。定义列表$\mathcal{S}=\{S_1, ..., S_{\ell} \}$ 为算法输出的agreement domain,其density大于等于$\sqrt{\rho^+}(1+\frac{1}{2m})$。定义$\mathcal{P}=\{\vec{P}_1, ..., \vec{P}_{\ell} \}$ 是对应的多项式集合,其中$\vec{P}_i = {P_{i,1},..., P_{i,w}} \in \mathbb{F}^{\leq 2^h[X]}$是与$f_j$在$S_i$上agree的多项式序列,每个$P_{i,j}$的次数都小于$2^h$。
171 | - 对于$k=1,...,\ell$,依次检验$\vec{P}_k$是否满足AIR实例$\mathsf{A}$,如果满足则输出$\vec{P}_k$作为assignment $\vec{P}$;否则输出失败终止算法。
172 |
173 | 根据定义2,每个$\vec{P}_i$都是一个AIR assignment,$\vec{P}_i$包含的多项式在$\mathbb{F}$上。
174 |
175 | 因为每个$\vec{P}_i$中的多项式$P_{i,j}$都与$f_j$在集合$S_i$中取值一致
176 | 如果$S_i= H_i$,那么$\vec{P}_i$就是assignment。
177 |
178 | #### 证明定理3(Knowledge Soundness)
179 |
180 | 上一节我们已经给出了提取器的构造,这一节,我们继续讨论定理3证明soundness error。
181 |
182 | 在这个证明中我们做一些简化的假设。
183 |
184 | - 证明者$\mathcal{P}(\mathsf{A,aux})$是确定算法。特别是
185 | - 对于每个 $\vec{r}$,Step3中证明者的oracle functions $f^\vec{r}_0, ..., f^\vec{r}_{a-1}$, 由 $\vec{r}$ 唯一确定,
186 | - Step5 中的answer序列 $(\alpha, \beta)$ 由$\vec{r}$ 唯一确定。
187 | - answer序列的有效性验证约束 $Q^\vec{r}(X,Y)$ 对于所有 $\vec{r}$ 和 $\mathsf{q}$都成立。
188 |
189 | 上一部分我们讨论过,提取器$\mathcal{E}$在输入$f_1,...,f_w$时,输出为$(\mathcal{S,P})$,$\mathcal{S}=\{S_1, ..., S_{\ell} \}$是density大于等于$\sqrt{\rho^+}(1+\frac{1}{2m})$的agreement domains集合,$\mathcal{P}=\{ \vec{P}_1,...,\vec{P}_\ell \}$ 都是AIR assignment。$\mathcal{P}$中的每个多项式序列都与$f_1,...,f_w$对应一致。
190 |
191 | 设置$\eta = \frac{\sqrt{\rho^+}}{2m}$, 根据定理1(Johnson bound)我们可以得到$\ell \leq m/\rho^+ \leq m/\rho$。
192 |
193 | 接下来把$(f^\vec{r}_0, ..., f^\vec{r}_{a-1})$加到$(f_1,...,f_w)$后面,得到一个更大的序列。然后应用RS码的解码器Correlated agreement list decoder,设置agreement参数$\sqrt{\rho^+} + \eta, \eta = \frac{\sqrt{\rho^+}}{2m}$。把得到的agreement domain记为$\mathcal{S}^\vec{r} = \{ S_1^\vec{r}, ..., S_\ell^\vec{r} \}$,其density是$\sqrt{\rho^+} + \eta$。
194 |
195 | 因为在相关解码器中,我们一直对$\mathcal{S}$求交集,所以每个 $S_i^\vec{r}$ 都一定包含在某个 $S_k \in \mathcal{S}$中。由于$S_i^\vec{r}$的density大于 $\rho^+$,所以函数$(f_1,...,f_w)$,在$\mathcal{S}_i^\vec{r}$ domain中的所有元素的取值,都与$\vec{P}_k$一致。这种情况我们称为$\mathcal{S}_i^\vec{r}$ 与$\vec{P}_k$相关联(associated with)。
196 |
197 | 定义 $\vec{P}_i^{\vec{r}} = (P_0^{\vec{r}},..., P_{a-1}^{\vec{r}})$ 是次数$\leq 2^h$,与$(f^\vec{r}_0, ..., f^\vec{r}_{a-1})$ 在$S_\ell^\vec{r}$ agree的多项式序列,定义$\mathcal{P}^\vec{r} = \{\vec{P}_1^{\vec{r}},...,\vec{P}_\ell^{\vec{r}}\}$。由于$\mathcal{S}_i^\vec{r}$ 与$\vec{P}_k$相关联,$\vec{P}_i^{\vec{r}}$与$\mathcal{S}_i^\vec{r}$ 相关联,所以我们也称$\vec{P}_i^{\vec{r}}$与$\vec{P}_k$相关联。
198 |
199 | 上述说明了多项式之间的关联是存在的,下面我们希望把这种关联在固定在随机挑战值上,保证证明能被验证者接受,以此证明$\vec{P}_k$是合法的witness。
200 |
201 | 定义Good$(\vec{r},\mathsf{q})$ 为FRI协议接受概率大于$\epsilon_{\mathsf{FRI}}$的取值。
202 |
203 | **引理2** 对于Good$(\vec{r},\mathsf{q})$,存在:
204 | - AIR assignment $\vec{P}_k = \{P_{k,1},..., P_{k,w}\} \in \mathcal{P}$
205 | - 多项式序列$\vec{P}^{\vec{r}} = (P_0^{\vec{r}},..., P_{a-1}^{\vec{r}})$ 与$\vec{P}_k$ 相关联。
206 | - $S_{(\vec{r},\mathsf{q})} \subset S_k$
207 | 使得下列条件都成立:
208 | 1. $|S_{(\vec{r},\mathsf{q})}| > (\sqrt{\rho^+} + \eta) |\mathsf{D}|$
209 | 2. 每个$P_{k,i}$都与$f_i$在$S_{(\vec{r},\mathsf{q})}$ agree
210 | 3. $P_{k,i}$的取值与DEEP answer $\alpha_{i,j}$ 全部匹配。$P_{k,i}(\mathsf{q}g^j) = \alpha_{i,j}$
211 | 4. $P_{l}^{\vec{r}}$与$f_{l}^{\vec{r}}$ 在 $S_{(\vec{r},\mathsf{q})}$ agree
212 | 5. $P_{l}^{\vec{r}}$的取值与DEEP answer $\beta_{l}$ 全部匹配。
213 |
214 | 条件2-5保证了DEEP answer是可以验证有效的。
215 | 这条引理说明了Good$(\vec{r},\mathsf{q})$ 能让验证者接受FRI的证明,也保证DEEP的answer可以验证有效,这两点同时保证了验证者会接受STARK的证明。
216 |
217 | 下面,我们希望说明,满足Good$(\vec{r},\mathsf{q})$的随机值 $(\vec{r},\mathsf{q})$取值有足够多,这一点可以保证我们提取的$\vec{P}_k$是合法的。
218 |
219 | 定义Useful$(\vec{r})$为能保证$\mathsf{q}$ 的取值足够多,的$\vec{r}$的取值。
220 | - $\mathsf{q}$ 的取值指的是让Good$(\vec{r},\mathsf{q})$ 条件在$\vec{P}_k \in \mathcal{P}$成立的那些取值。
221 | - 足够多指的是,$>((a+1) \cdot |\mathsf{H}_0| + a) \cdot \ell= (d_{max} + 2^h + a) \cdot \ell$
222 |
223 | **引理3**对于Useful$(\vec{r})$,函数$Q^{\vec{r}}(X,Y) \circ \vec{P}_k$是有限域$\mathbb{K}$上的多项式。
224 |
225 | **引理4** 如果线性独立的随机值$({r}_1, ..., {r}_{2s}) \in \mathbb{K}^{2s}$都对于某个函数序列$\vec{P}_k$是useful,那么$\vec{P}_k$满足AIR实例$\mathsf{A}$。
226 |
227 | 引理3说明了$\vec{P}_k$是assignment,引理4则说明了$\vec{P}_k$满足我们要求的AIR实例$\mathsf{A}$。这样,我们基本完成了提取器的构造和说明,下面简单讨论soundness error的上界是如何得到的。
228 |
229 | 接下来,我们限制随机值$\vec{r}$ is not useful概率。如果$\vec{r}$ not useful,那么对于每组assignment $\vec{P}_k$,至多有$(d_{max} + 2^h + a) \cdot \ell$个$\mathsf{q}$的取值是Good$(\vec{r},\mathsf{q})$。
230 | 那么对于所有的assignment $\mathcal{P}$,总共有$(d_{max} + 2^h + a) \cdot \ell |\mathcal{P}| = ((a+1) \cdot 2^h + a) \cdot \ell^2$个$\mathsf{q}$的取值使得FRI的接受概率大于等于$\epsilon_{\mathsf{FRI}}$。
231 | 那么,STARK协议在条件为$\vec{r}$ is not useful的接受概率是$\frac{(d_{max} + 2^h + a) \cdot \ell^2}{|\mathbb{K}|-a|\mathsf{D}| + |\mathsf{H}_0|} + \epsilon_{\mathsf{FRI}}$.
232 |
233 | $\vec{r}$ is useful的概率是$\frac{\ell}{|\mathbb{K}|}$。假设$\vec{P}_k$是使得$\vec{r}$ is useful的概率最大的集合。这个概率一定严格大于$\frac{1}{|\mathbb{K}|}$,即从$\mathbb{K}$中随机选一个的概率。因此,useful的$\vec{r}$组成的集合中一定包含了能够张成$\mathbb{K}^{2s}$一组基(线性独立的一组随机值)。根据引理4,这个$\vec{P}_k$是满足AIR实例的assignment,也就是witness。
--------------------------------------------------------------------------------