Halo2学习笔记——设计之Proof和Field实现
Posted mutourend
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Halo2学习笔记——设计之Proof和Field实现相关的知识,希望对你有一定的参考价值。
1. Halo2中的Proof实现
1.1 Proof以opaque byte stream表示
与bellman proving system实现不同,bellman中有明确的Proof
结构体封装可proof data,该结构体由Prover返回,并传送给Verifier。
而Halo2中并不包含类似的proof的结构体,基于以下原因:
- Proof结构体中将包含vectors of (vectors of) curve points and scalars。这将使proof的序列化和反序列化变复杂,因为这些vectors的长度将取决于circuit的配置。但是,我们并不想在proof中encode the lengths of vectors,因为at runtime the circuit is fixed, and thus so are the proof sizes。
- 很容易意外地将内容放入一个Proof结构中,而并没有放在transcript中,这在开发和实施proving system时是一种危险。
- 需要能同时创建多个PLONK proofs,对于同一circuit,这些proofs共享很多不同的子结构体。
相反,Halo2中将proof objects当成opaque byte streams。通过transcript来创建和消费这些byte streams:
TranscriptWrite
trait表示something that we can write proof components to (at proving time)。TranscriptRead
trait表示something that we can read proof components from (at verifying time)。
最关键的是,TranscriptWrite
的实现应负责支持同时写入some std::io::Write
buffer that they hash things into the transcript,TranscriptRead
的实现应负责支持同时读取some std::io::Read
buffer。
将proofs以opaque byte streams表示,可确保verification时会考虑到反序列化的开销,由于point compression,这种开销不可忽略。
1.2 Proof encoding
Halo2 proof,基于curve E ( F p ) E(\\mathbb{F}_p) E(Fp)构建的,encode为a stream of:
- Points P ∈ E ( F p ) P\\in E(\\mathbb{F}_p) P∈E(Fp) (for commitments to polynomials)
- Scalars s ∈ F q s\\in\\mathbb{F}_q s∈Fq(for evaluations of polynomials以及blinding values)
对于Pallas和Vesta curves,points和scalars均具有32-byte encodings,即意味着proof的大小总为32 bytes的倍数。
halo2
crate支持同时对同一circuit的多个instance进行证明,可共享共同的proof components和protocol logic。
实际encoding过程中,使用了如下circuit-specific constants:
- k k k - the size parameter of the circuit (which has 2 k 2^k 2k rows).
- A A A - the number of advice columns.
- F F F - the number of fixed columns.
- I I I - the number of instance columns.
- L L L - the number of lookup arguments.
- P P P - the number of permutation arguments.
- Col P \\textsf{Col}_P ColP - the number of columns involved in permutation argument P P P.
- D D D - the maximum degree for the quotient polynomial.
- Q A Q_A QA - the number of advice column queries.
- Q F Q_F QF - the number of fixed column queries.
- Q I Q_I QI - the number of instance column queries.
- M M M - the number of instances of the circuit that are being proven simultaneously.
由于proof encoding 直接follow the transcript,可将encoding切分为以下sections来匹配Halo2 协议:
-
PLONK commitments:
- A A A points (repeated M M M times).
- 2 L 2L 2L points (repeated M M M times).
- P P P points (repeated M M M times).
- L L L points (repeated M M M times).
-
Vanishing argument:
- D − 1 D - 1 D−1 points.
- Q I Q_I QI scalars (repeated M M M times).
- Q A Q_A QA scalars (repeated M M M times).
- Q F Q_F QF scalars.
- D − 1 D - 1 D−1 scalars.
-
PLONK evaluations:
- ( 2 + Col P ) × P (2 + \\textsf{Col}_P) \\times P (2+ColP)×P scalars (repeated M M M times).
- 5 L 5L 5L scalars (repeated M M M times).
-
Multiopening argument:
- 1 point.
- 1 scalar per set of points in the multiopening argument.
-
Polynomial commitment scheme:
- 1 + 2 k 1 + 2k 1+2k points.
- 2 2 2 scalars.
2. Halo2中的Fields实现
Halo2中使用的Pasta curves,特意设计为具有high 2-adic,即在每个field都有large
2
S
2^S
2S multiplicative subgroup 存在。
p
−
1
≡
2
S
⋅
T
p-1\\equiv2^S\\cdot T
p−1≡2S⋅T,其中
T
T
T为奇数。
对于Halo2中使用Pallas和Vesta curve,其 S = 32 S=32 S=32。
2.1 采用Sarkar square-root算法(table-based variant)
Halo2中使用 Sarkar2020中的算法 来计算 square roots平方根。
使用该算法的原因是,可split the task into computing square roots in each multiplicative subgroup。
假设我们需找到
u
u
u modulo one of the Pasta primes
p
p
p 的平方根,其中
u
u
u为a non-zero square in
Z
p
×
\\mathbb{Z}_p^{\\times}
Zp×。
定义a
2
S
2^S
2S root of unity
g
=
z
T
g=z^T
g=zT,其中
z
z
z为a non-square in
Z
p
×
\\mathbb{Z}_p^{\\times}
Zp×,然后预计算出如下tables:
g
t
a
b
=
[
g
0
g
1
.
.
.
g
2
8
−
1
(
g
2
8
)
0
(
g
2
8
)
1
.
.
.
(
g
2
8
)
2
8
−
1
(
g
2
16
)
0
(
g
2
16
)
1
.
.
.
(
g
2
16
)
2
8
−
1
(
g
2
24
)
0
(
g
2
24
)
1
.
.
.
(
g
2
24
)
2
8
−
1
]
gtab = \\begin{bmatrix} g^0 & g^1 & ... & g^{2^8 - 1} \\\\ (g^{2^8})^0 & (g^{2^8})^1 & ... & (g^{2^8})^{2^8 - 1} \\\\ (g^{2^{16}})^0 & (g^{2^{16}})^1 & ... & (g^{2^{16}})^{2^8 - 1} \\\\ (g^{2^{24}})^0 & (g^{2^{24}})^1 & ... & (g^{2^{24}})^{2^8 - 1} \\end{bmatrix}
gtab=⎣⎢⎢⎢⎡g0(g28)0(g216)0(g224)0g1(g28)1(g216)1(g224)1............g28−1(g28)28−1以上是关于Halo2学习笔记——设计之Proof和Field实现的主要内容,如果未能解决你的问题,请参考以下文章
Halo2 学习笔记——设计之Proving system之Circuit commitments
Halo2学习笔记——设计之Protocol Description
Halo2 学习笔记——设计之Proving system之Permutation argument