Arithmetic circuit

1. 引言

对于只有加法门和乘法门的arithmetic circuit,可将其理解为是“一系列的乘法门+一系列表示gate输入输出关系的linear consistency equations”。

一个 arithmetic circuit 可理解为是一个有向无环图,其中每个顶点称为gate。in-degree为0的gate为circuit的输入,可表示为 a i a_i ai或者a constant field element。其它的gate可标示为 + + + × \times ×

对于 fan-in 2 circuits,其所有 + + +门和 × \times ×门均具有 in-degree 2。

任何可表述为有向无环图的circuit均可转换为:
“一系列的乘法门+一系列表示gate输入输出关系的linear consistency equations”。

  • 首先,需要将arithmetic circuit A A A 中的加法门和常量乘法门替换为:
    bilinear consistency equations on the inputs and outputs of the remaining gates
    从而保证这些equations的satisfiability与原始circuit的satisfiability等同。
    假设 B B B A A A的sub-circuit, B B B中包含了一个乘法门之前的所有wires和gates。 B B B m m m 个input wires和 n n n 个output wires。这 m m m 个inputs可以单位向量表示 e ⃗ i = ( 0 , ⋯   , 1 , ⋯   , 0 ) \vec{e}_i=(0,\cdots,1,\cdots,0) e i=(0,,1,,0),其中 i ∈ [ 1 , m ] , ∣ e ⃗ i ∣ = m i\in[1,m],|\vec{e}_i|=m i[1,m],e i=m
    – 对于每个加法门,其input表示为 x ⃗ , y ⃗ \vec{x},\vec{y} x ,y ,其output表示为 x ⃗ + y ⃗ \vec{x}+\vec{y} x +y
    – 对于每个常量乘法门,其input表示为 x ⃗ \vec{x} x 和常量 c c c,其output表示为 c x ⃗ c\vec{x} cx
    以此执行, B B B n n n个output均可以length为 m m m的向量来表示linear combinations of the inputs。
    最多需要 m ∣ B ∣ m|B| mB 个arithmetic operations。注意, B B B的所有output均为linear combinations of the inputs,所以 B B B可表示为具有 n ( 2 m − 1 ) n(2m-1) n(2m1) 个 fan-in 2 gates,使得consistency equations可直接从circuit description中获取。
    注意,形如 ∑ i = 1 m a i x i \sum_{i=1}^{m}a_ix_i i=1maixi的linear combination,可由 m m m个常量乘法门和 m − 1 m-1 m1 个加法门组成。

  • 其次,将 B B B的gates 从 A A A 中移除,同时移除 any multiplication gates whose inputs are the inputs of the new circuit。

  • 重复以上过程,知道找出所有的consistency equations。repeat the process of finding consistency equations until we have considered the whole of A A A

注意,circuit A A A的第一个(input)和最后一个(output)sub-circuit需要增加额外操作。
以 output sub-circuit为例(input sub-circuit类似):

  • 假设 B B B为the output sub-circuit,其 m m m个input表示为 a ⃗ = ( a 1 , ⋯   , a m ) T \vec{a}=(a_1,\cdots,a_m)^T a =(a1,,am)T n n n个output表示为 b ⃗ = ( b 1 , ⋯   , b n ) T \vec{b}=(b_1,\cdots,b_n)^T b =(b1,,bn)T
    其中,每个output b i b_i bi均可表示为 ∑ j = 1 m q i j a j + p i \sum_{j=1}^{m}q_{ij}a_j+p_i j=1mqijaj+pi,所有的可表示为:
    b ⃗ = Q a ⃗ + p ⃗ \vec{b}=\mathbf{Q}\vec{a}+\vec{p} b =Qa +p
    其中 Q \mathbf{Q} Q n × m n\times m n×m矩阵, p ⃗ \vec{p} p 为size为 n n n的列向量。
    假设矩阵 Q \mathbf{Q} Q的rank为 r r r,则可将 Q \mathbf{Q} Q reduce 为 row echelon form R \mathbf{R} R,可表示为:
    b ⃗ ′ ′ = R a ⃗ \vec{b}''=\mathbf{R}\vec{a} b =Ra

2. 附注

附注:

  • 所谓matrix rank是指:通过行列式转换,非零行的数量。matrix的rank最大可能值为 m i n ( m , n ) min(m,n) min(m,n)
  • 所谓row echelon form matrix是指:通过行列式转换,将矩阵左下角的所有元素均表示为0的过程。
    在这里插入图片描述

3. Arithmetic circuit的constraint system表示

Maller等人2019年《Sonic: Zero-Knowledge SNARKs from linear-size universal and updatable Structured Reference Strings》论文第5章中,将只具有加法门和乘法门的Arithmetic circuit,其加法门和常量乘法门以linear constraints表示,其非常量乘法门以multiplication constraints表示。假设其存在 n n n个非常量乘法门,则整个constraint system可表示为:

  • Prover知道相应的 a ⃗ , b ⃗ , c ⃗ ∈ F n \vec{a},\vec{b},\vec{c}\in\mathbb{F} ^n a ,b ,c Fn,使得:(其中 a i , b i , c i a_i,b_i,c_i ai,bi,ci分别为第 i i i个非常量乘法门的左侧输入、右侧输入和输出。)
    a ⃗ ∘ b ⃗ = c ⃗ \vec{a}\circ \vec{b}=\vec{c} a b =c

  • 具有 Q Q Q个linear constraints来表示相应的加法门、常量乘法门以及circuit中wires所代表的其它内部约束,形如:
    a ⃗ ⋅ u ⃗ q + b ⃗ ⋅ v ⃗ q + c ⃗ ⋅ w ⃗ q = k q \vec{a}\cdot \vec{u}_q+\vec{b}\cdot \vec{v}_q+\vec{c}\cdot \vec{w}_q=k_q a u q+b v q+c w q=kq
    其中的 u q ⃗ , v ⃗ q , w ⃗ q ∈ F n \vec{u_q},\vec{v}_q,\vec{w}_q\in\mathbb{F}^n uq ,v q,w qFn为第 q q q-th linear constraint的fixed vectors, k q ∈ F p k_q\in\mathbb{F}_p kqFp为instance value。

举例,如为了表示 x 2 + y 2 = z x^2+y^2=z x2+y2=z,相应的constraint组成可为:

  • a ⃗ = ( x , y ) , b ⃗ = ( x , y ) , c ⃗ = ( x 2 , y 2 ) \vec{a}=(x,y),\vec{b}=(x,y),\vec{c}=(x^2,y^2) a =(x,y),b =(x,y),c =(x2,y2) 【multiplication constraints】
  • u ⃗ 1 = ( 1 , 0 ) , v ⃗ 1 = ( − 1 , 0 ) , w ⃗ 1 = ( 0 , 0 ) , k 1 = 0 \vec{u}_1=(1,0),\vec{v}_1=(-1,0),\vec{w}_1=(0,0),k_1=0 u 1=(1,0),v 1=(1,0),w 1=(0,0),k1=0 【linear constraints】
  • u ⃗ 2 = ( 0 , 1 ) , v ⃗ 2 = ( 0 , − 1 ) , w ⃗ 2 = ( 0 , 0 ) , k 2 = 0 \vec{u}_2=(0,1),\vec{v}_2=(0,-1),\vec{w}_2=(0,0),k_2=0 u 2=(0,1),v 2=(0,1),w 2=(0,0),k2=0 【linear constraints】
  • u ⃗ 3 = ( 0 , 0 ) , v ⃗ 3 = ( 0 , 0 ) , w ⃗ 3 = ( 1 , 1 ) , k 3 = z \vec{u}_3=(0,0),\vec{v}_3=(0,0),\vec{w}_3=(1,1),k_3=z u 3=(0,0),v 3=(0,0),w 3=(1,1),k3=z 【linear constraints】

需要对所有的multiplication constraints和linear constraints进行合并表示:

  • 1)可引入随机变量 Y Y Y n n n个multiplication constraints合并为一个方程式,通常形式为:
    ∑ i = 1 n ( a i b i − c i ) Y i = 0 \sum_{i=1}^{n}(a_ib_i-c_i)Y^i=0 i=1n(aibici)Yi=0
    不过,为了匹配后续的证明,可使用 Y Y Y的负数次幂来组合,形式为:
    ∑ i = 1 n ( a i b i − c i ) Y − i = 0 \sum_{i=1}^{n}(a_ib_i-c_i)Y^{-i}=0 i=1n(aibici)Yi=0……(a)
  • 2)对于 Q Q Q个linear constraints,可使用1)中相同的随机变量,同时都偏移 Y n Y^n Yn来进行合并:
    ∑ q = 1 Q ( a ⃗ ⋅ u ⃗ q + b ⃗ ⋅ v ⃗ q + c ⃗ ⋅ w ⃗ q − k q ) Y q + n = 0 \sum_{q=1}^{Q}(\vec{a}\cdot \vec{u}_q+\vec{b}\cdot \vec{v}_q+\vec{c}\cdot \vec{w}_q-k_q)Y^{q+n}=0 q=1Q(a u q+b v q+c w qkq)Yq+n=0……(b)
  • 3)基于1)和2),定义多项式:
    u i ( Y ) = ∑ q = 1 Q Y q + n u q , i u_i(Y)=\sum_{q=1}^{Q}Y^{q+n}u_{q,i} ui(Y)=q=1QYq+nuq,i
    v i ( Y ) = ∑ q = 1 Q Y q + n v q , i v_i(Y)=\sum_{q=1}^{Q}Y^{q+n}v_{q,i} vi(Y)=q=1QYq+nvq,i
    w i ( Y ) = − Y i − Y − i + ∑ q = 1 Q Y q + n w q , i w_i(Y)=-Y^i-Y^{-i}+\sum_{q=1}^{Q}Y^{q+n}w_{q,i} wi(Y)=YiYi+q=1QYq+nwq,i
    k ( Y ) = ∑ q = 1 Q Y q + n k q k(Y)=\sum_{q=1}^{Q}Y^{q+n}k_q k(Y)=q=1QYq+nkq
    于是(a)+(b)可表示为:
    a ⃗ ⋅ u ⃗ ( Y ) + b ⃗ ⋅ v ⃗ ( Y ) + c ⃗ ⋅ w ⃗ ( Y ) + ∑ i = 1 n a i b i ( Y i + Y − i ) − k ( Y ) = 0 \vec{a}\cdot \vec{u}(Y)+\vec{b}\cdot \vec{v}(Y)+\vec{c}\cdot\vec{w}(Y)+\sum_{i=1}^{n}a_ib_i(Y^i+Y^{-i})-k(Y)=0 a u (Y)+b v (Y)+c w (Y)+i=1naibi(Yi+Yi)k(Y)=0……(1)
    Given a choice of ( a ⃗ , b ⃗ , c ⃗ , k ( Y ) ) (\vec{a},\vec{b},\vec{c},k(Y)) (a ,b ,c ,k(Y)), we have that Equation 1 will hold at all points if the constraint system is satisfied. If the constraint system is not satisfied the equation will fail to hold with high probability, given a large enough field.
    借鉴Bootle等人2016年论文《Efficient Zero-Knowledge Arguments for Arithmetic Circuits in the Discrete Log Setting》中的Laurent polynomial commitment scheme,其中要求Laurent polynomial的constant term为0(即 t 0 = 0 t_0=0 t0=0),相应思路为:(详细参见博客 Efficient Zero-Knowledge Arguments for Arithmetic Circuits in the Discrete Log Setting学习笔记
    引入变量 X X X, 构建一个Laurent polynomial t ( X , Y ) t(X,Y) t(X,Y),将上述公式(1)的左侧作为其constant term,即the coefficient of X 0 X^0 X0 in t ( X , Y ) t(X,Y) t(X,Y)即为公式(1)的左侧。Sonic若能证明the constant term of t ( X , Y ) t(X,Y) t(X,Y)为0,则说明our constraint system is satisfied。
    具体的实现为:
    r ( X , Y ) = ∑ i = 1 n ( a i X i Y i + b i X − i Y − i + c i X − i − n Y − i − n ) r(X,Y)=\sum_{i=1}^{n}(a_iX^iY^i+b_iX^{-i}Y^{-i}+c_iX^{-i-n}Y^{-i-n}) r(X,Y)=i=1n(aiXiYi+biXiYi+ciXinYin)
    s ( X , Y ) = ∑ i = 1 n ( u i ( Y ) X − i + v i ( Y ) X i + w i ( Y ) X i + n ) s(X,Y)=\sum_{i=1}^{n}(u_i(Y)X^{-i}+v_i(Y)X^i+w_i(Y)X^{i+n}) s(X,Y)=i=1n(ui(Y)Xi+vi(Y)Xi+wi(Y)Xi+n)
    r ′ ( X , Y ) = r ( X , Y ) + s ( X , Y ) r'(X,Y)=r(X,Y)+s(X,Y) r(X,Y)=r(X,Y)+s(X,Y)
    t ( X , Y ) = r ( X , 1 ) r ′ ( X , Y ) − k ( Y ) t(X,Y)=r(X,1)r'(X,Y)-k(Y) t(X,Y)=r(X,1)r(X,Y)k(Y)

参见博客 Linear-time zero-knowledge proofs for arithmetic circuit satisfiability 学习笔记 “4. zero-knowledge proofs for arithmetic circuit satisfiability in the ideal linear commitment model” 中指出:
arithmetic circuit satisfiability proof 中主要包含以下任务:【即存在以下4类constraints。】

  • Prove for each value specified in the instance that this is indeed the value the prover has committed to。
  • Prove for each addition gate that the committed output is the sum of the committed input。
  • Prove for each multiplication gate that the committed output is the product of the committed input。
  • Prove for each wire that all committed values corresponding to this wire are the same。

参考资料:
[1] How to Reduce a Matrix to Row Echelon Form
[2] Bootle和Groth等人2016年论文《Efficient Zero-Knowledge Arguments for Arithmetic Circuits in the Discrete Log Setting
[3] matrix rank

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值