在区块链网络中,交易经年不断积累,因此区块链的存储量不断无限增长。在Dusk Network中,自举时间线性增长,且受零知识证明验证计算量的限制。在适当的时候,这意味着自举可能需要几天甚至几周的时间。
这就是为什么我们正在研究一个全新的自举过程,使加入网络的新节点能够快速与最新状态同步。使用此过程,新节点不需要验证单个交易,这将导致自举时间为分钟/小时,而不是天/周。
为此,Dusk Network中设计了一个过程,使client能将相应交易证明的计算委托给某server,而不暴露相应的secret key。整个委托过程,使得我们能拥有超轻的类似Metamask的钱包,同时能使用协议所提供的所有功能。在具体实现过程中,将设定多个常量,如:
Dusk-network团队在PLOOKUP的实现上取得了重大进展,可将现有的gadgets与PLOOKUP集成,减少gadgets中门的数量。同时,Dusk-network团队也将致力于实现新的gadgets,这种新的gadgets必须依赖于PLOOKUP。
PLOOKUP的主要价值在于:
PLONK+PLOOKUP用于circuit证明,底层关键技术点涉及有:
1)PLONK的核心技术为:grand product check
2)PLOOKUP的核心技术为:multiset-equality check
3)circuit证明中常用到:permutation check
4)PLOOKUP中引入了:Table lookup
接下来将介绍这些底层关键技术之间的关系。
PLONK的核心技术为:
所谓grand product check,是指:
在PLONK论文中指出,当 H H H为a multiplicative subgroup时,可高效实现相应证明。
此文讨论的长为 n n n的vector a ⃗ \vec{a} a,在协议的实际实现中,均为Prover会对多项式 f f f进行commit,其中 f ( x i ) = a i f(x_i)=a_i f(xi)=ai。
PLOOKUP的核心技术为:
借助少量的randomness,可将grand product check 转换为更强大的primitive——the multiset equality check:
如 ( 1 , 1 , 2 , 3 ) (1,1,2,3) (1,1,2,3) 与 ( 2 , 1 , 1 , 3 ) (2,1,1,3) (2,1,1,3) 是multiset-equal的,但是与 ( 1 , 2 , 3 , 3 ) (1,2,3,3) (1,2,3,3)或 ( 1 , 1 , 2 , 4 ) (1,1,2,4) (1,1,2,4)都不是 multiset-equal的。
Verifier发送随机值 γ ∈ F \gamma\in\mathbb{F} γ∈F,然后run the grand product check on the randomly shifted vectors a ⃗ ′ = a ⃗ + γ , b ⃗ ′ = b ⃗ + γ \vec{a}'=\vec{a}+\gamma,\vec{b}'=\vec{b}+\gamma a′=a+γ,b′=b+γ(即对所有元素都加 γ \gamma γ。)
这样,就可将multiset-equality check转换为 如下grand product check:
∏ i ∈ [ n ] ( a i + γ ) = ∏ i ∈ [ n ] ( b i + γ ) \prod_{i\in[n]}(a_i+\gamma)=\prod_{i\in[n]}(b_i+\gamma) ∏i∈[n](ai+γ)=∏i∈[n](bi+γ)
Permutation是指:
关于为何permutation checks为SNARKs的核心组成,查看PLONK及其它SNARK论文便可知。
观察以下vectors of pairis:
( ( a i , i ) ) i ∈ [ n ] ((a_i,i))_{i\in[n]} ((ai,i))i∈[n] 和 ( b i , σ ( i ) ) i ∈ [ n ] (b_i, \sigma(i))_{i\in[n]} (bi,σ(i))i∈[n]
当且仅当 b ⃗ = σ ( a ⃗ ) \vec{b}=\sigma(\vec{a}) b=σ(a)时,以上两者为multiset-equal的。
但是,我们希望可reduce为multiset check on vectors of elements,而不是vectors of pairs。为此,引入随机值 β \beta β,定义新的vector a ⃗ ′ , b ⃗ ′ \vec{a}',\vec{b}' a′,b′ 为:
a i ′ = a i + β ⋅ i , b i ′ = b i + β ⋅ σ ( i ) a_i'=a_i+\beta\cdot i,b_i'=b_i+\beta\cdot \sigma(i) ai′=ai+β⋅i,bi′=bi+β⋅σ(i)
若以上vectors of pairs为 not multiset equal的,则大概率 a ⃗ ′ \vec{a}' a′和 b ⃗ ′ \vec{b}' b′也不是multiset equal的。
因此,仅需对 a ⃗ ′ \vec{a}' a′ 和 b ⃗ ′ \vec{b}' b′ 做multiset check就足够了。
在Stephanie Bayer和Jens Groth 2012年论文《Efficient Zero-Knowledge Argument for Correctness of a Shuffle》中,首次实现了 由permutation check 到 grand product check 的reduction,详细可参看系列博客:
table lookup 操作是 zk-SNARK实现中的一个非常有用的操作。
以XOR举例,假设有3个vectors of field elements a ⃗ = ( a 1 , ⋯ , a n ) , b ⃗ = ( b 1 , ⋯ , b n ) , c ⃗ = ( c 1 , ⋯ , c n ) \vec{a}=(a_1,\cdots,a_n),\vec{b}=(b_1,\cdots,b_n),\vec{c}=(c_1,\cdots,c_n) a=(a1,⋯,an),b=(b1,⋯,bn),c=(c1,⋯,cn),想要check:
对于每一个 i ∈ [ n ] i\in[n] i∈[n], a i , b i , c i a_i,b_i,c_i ai,bi,ci均为8-bit string,且 c i = a i ⊕ b i c_i=a_i\oplus b_i ci=ai⊕bi,其中 ⊕ \oplus ⊕为bitwise XOR。
传统的SNARK方案需要很多arithmetic constraints:
需要对于每一组tuple ( a i , b i , c i ) (a_i,b_i,c_i) (ai,bi,ci)分解为二进制位表示,然后再进行bitwise XOR。
而借助Lookup table,相应的解决方案变为:
/// Construct a Generic lookup table over a bi-variate function
pub struct Generic(HashMap<(Fr, Fr), Fr>); //以两个输入组合为Key,以输出结果为value
【注意,在SNARK上下文中, a ⃗ , b ⃗ , c ⃗ \vec{a},\vec{b},\vec{c} a,b,c通常对应的是witness polynomials for which only for some i i i's we wish to check a XOR relation。
具体实现可参见PLOOKUP论文section 4.1节的方法:
借助“selectors” 来combine different tables and gates。【借助selectors j j j,实际实现的就是按不同的门类型(不同的逻辑操作)统一归类。】
详细也可参看博客 PLOOKUP 中 “6. 扩展为多个多项式 f 1 , ⋯ , f w ∈ F < n [ X ] f_1,\cdots,f_w\in\mathbb{F}_{
其中的 j j j即为相应的selectors。
注意,在plookup论文中,selector j j j 被定义为public的,但是在实际做circuit证明时,selector j j j 应为private的。实际实现的规则,可参看ultra-plonk论文。(源自 Plonk cafe的 Strategies for integrating plookup with PLONK 中的讨论。)
】
2)Reduce tuples to single elements
为了证明每一个tuple ( a i , b i , c i ) (a_i,b_i,c_i) (ai,bi,ci) 对应为 T T T中的某一行:
借助randomness来reduce checking tuples to checking single elements。引入random α \alpha α,构建vector f i = a i + α ⋅ b i + α 2 ⋅ c i f_i=a_i+\alpha\cdot b_i+\alpha^2 \cdot c_i fi=ai+α⋅bi+α2⋅ci for each i ∈ [ n ] i\in[n] i∈[n]。类似的,也为truth table T T T构建相应的压缩版本 t t t,其中 t i = T 1 , i + α ⋅ T 2 , i + α 2 ⋅ T 3 , i t_i=T_{1,i}+\alpha\cdot T_{2,i}+\alpha^2\cdot T_{3,i} ti=T1,i+α⋅T2,i+α2⋅T3,i。
根据Schwartz-Zippel Lemma可知,若某tuple ( a i , b i , c i ) (a_i,b_i,c_i) (ai,bi,ci)不在 T T T中,则大概率 f i f_i fi不是 t t t中的元素。
3)plookup protocol中的sort and compare differences【reduce为2个multiset check】
至此,问题转换为了:
check that every element of f f f is an element of t t t。
将其表示为 f ⊂ t f\subset t f⊂t。
在plookup protocol中,可将其reduce为 one multiset equality check,reduce的核心思想在于:
若有2个vector的sorted version,且两者的第一个元素是一样的,则有:they contain the same distinct elements if and only if they contain the same sequence of non-zero differences between adjacent elements。
举个例子:有 f = ( 2 , 2 , 1 , 1 , 5 ) , t = ( 1 , 2 , 5 ) f=(2,2,1,1,5),t=(1,2,5) f=(2,2,1,1,5),t=(1,2,5),Prover构建 s = ( f , t ) s=(f,t) s=(f,t) sorted by t t t,此处有 s = ( 1 , 1 , 1 , 2 , 2 , 2 , 5 , 5 ) s=(1,1,1,2,2,2,5,5) s=(1,1,1,2,2,2,5,5)。【注意,sorted by t t t操作可保证 elements in s s s in the same order they appear in t t t。】
s , t s,t s,t对应的difference vector为: s ′ = ( 0 , 0 , 1 , 0 , 0 , 3 , 0 ) , t ′ = ( 1 , 3 ) s'=(0,0,1,0,0,3,0),t'=(1,3) s′=(0,0,1,0,0,3,0),t′=(1,3)。
由此可知,若 f ⊂ t f\subset t f⊂t,则 s ′ s' s′中的非零元素与 t ′ t' t′中的非零元素一一对应。
给 t ′ t' t′后面附加 ∣ f ∣ |f| ∣f∣个零,表示为 t ′ ′ = ( 1 , 3 , 0 , 0 , 0 , 0 , 0 ) t''=(1,3,0,0,0,0,0) t′′=(1,3,0,0,0,0,0)。
此时可简单reduce为2个multiset check:
<1> s s s和 ( f , t ) (f,t) (f,t)之间的multiset check;【可说明 f ⊂ s f\subset s f⊂s,以及 t ⊂ s t\subset s t⊂s。】
<2> s ′ s' s′和 t ′ ′ t'' t′′之间的multiset check。
条件<1>可说明 t ⊂ s t\subset s t⊂s,若 s s s中包含a value outside of t t t,则意味着 s s s中有more than ∣ t ∣ |t| ∣t∣ distinct values。但是,条件<2>可说明 s ′ s' s′有 at most ∣ t ∣ − 1 |t|-1 ∣t∣−1 non-zeros。因此,若条件<1>和条件<2>都满足,可说明 s s s有 at most ∣ t ∣ |t| ∣t∣ distinct values,从而可说明 s ⊂ t s\subset t s⊂t。由 f ⊂ s , s ⊂ t f\subset s,s\subset t f⊂s,s⊂t,从而有 f ⊂ t f\subset t f⊂t。
4)借助randomness,实现效率更高的版本【reduce为仅需1个multiset check】
Verifier选择random β \beta β。
s , t s,t s,t对应的randomized difference vectors s ′ , t ′ s',t' s′,t′为: s i ′ = s i + β s i + 1 , t i ′ = t i + β t i + 1 s_i'=s_i+\beta s_{i+1},t_i'=t_i+\beta t_{i+1} si′=si+βsi+1,ti′=ti+βti+1。
此时可reduce为一个multiset check:即 s ′ s' s′和 ( ( 1 + β ) f , t ′ ) ((1+\beta)f,t') ((1+β)f,t′)之间的multiset check。
为了更便于理解,可将每个元素看成是formal polynomial in β \beta β,而不是field elements。从而可知, s ′ s' s′中的元素为degree one polynomial s i + s i + 1 ⋅ β s_i+s_{i+1}\cdot \beta si+si+1⋅β。
a) 若 s i ≠ s i + 1 s_i\neq s_{i+1} si=si+1,则说明 s i + s i + 1 ⋅ β s_i+s_{i+1}\cdot \beta si+si+1⋅β应在 t ′ t' t′中,与某 t j + t j + 1 ⋅ β t_j+t_{j+1}\cdot \beta tj+tj+1⋅β相同。从而说明 s ⊂ t s\subset t s⊂t。
b) 每一个 f i + f i ⋅ β f_i+f_i\cdot \beta fi+fi⋅β 必须与 s ′ s' s′中的某值相同,即对应某 s j = s j + 1 s_{j}=s_{j+1} sj=sj+1。从而说明 f ⊂ s f\subset s f⊂s。
根据a) 和 b) ,从而证明了 f ⊂ t f\subset t f⊂t。
根据Schwartz-Zippel Lemma可知,这些comparisons between formal polynomials in β \beta β with high probability will not differ from the comparisons from the comparisons of the actual elements for the random choice of β \beta β。
Plonk和Plookup的共性是,均为:
但是,Plonk和Plookup使用sequence的方式不同:
Plonk和Plookup中均使用了:
Plonk为:
Plookup为:
Hash函数是可利用plookup来实现circuit简化的一个很棒的例子:
在computer架构下,大多数被认为安全的Hash函数运算都是快速的;其中的某些在软件实现上也运算很快。但是无论哪种情况,这些Hash函数都是基于binary strings来执行的。当encode为约256-bit的field elements时,存在以下问题:
借助Plookup,即使曲线不具备cycles属性,也将支持arithmetic over different fields运算,从而实现recursive SNARK。
SNARK中所使用到的大多数曲线,都是定义在域 Z p \mathbb{Z}_p Zp中的,其中每个point可表示为:
P = ( x , y ) P=(x,y) P=(x,y),其中 x , y ∈ Z p x,y\in\mathbb{Z}_p x,y∈Zp
point P P P具有的order为 q q q,即将相应的scalar field表示为 Z q \mathbb{Z}_q Zq。
在构建arithmetic circuit SNARK时,加法门和乘法门都是基于scalar field Z q \mathbb{Z}_q Zq来运算的,即 m o d q \mod q modq。其中 p , q p,q p,q为不同的素数。
因此,使用不具有cycles属性的曲线来构建recursive SNARK的难点在于:
[1] Plonk cafe的 Strategies for integrating plookup with PLONK
[2] Dmitry Khovratovich的hackmd笔记 Plonk and PLookup
[3] metastate的 On PLONK and plookup
[4] dusk network的 Audit Plookup Branch #358
[5] tezosagora的 On PLONK and plookup SNARKs
[6] aztec的研究论文系列
[7] Dusk的开发月报
[8] hackmd的 Multiset checks in PLONK and Plookup