nil Foundation的in-EVM Full Mina State Verification

1. 引言

nil Foundation系列博客有:

2021年2月,Mina Foundation和Ethereum Foundation发表联合request for proposals (RFP),以在以太坊上支持recursive SNARK application。

该RFP会开放6周,欢迎在以太坊虚拟机上实现Pickles SNARK verification的设计和实现机制 proposals。以太坊基金会希望在以太坊上构建a verifier for Pickles SNARK,从而使得mina可be verified on Ethereum,从而可实现以太坊与mina之间的bridge。

经过严格筛选,nil Foundation赢得了120万美金的项目资金

由于整个Mina Protocol state(archive nodes除外)都packed with the single Pickles SNARK proof (仅约22KB),因此,可将整个Mina Protocol state放入以太坊,从而可 以合理的gas cost在EVM中验证整个Mina Protocol state。
在这里插入图片描述
A full Mina Protocol state in-EVM verification意味着,可将所有发生在Mina链上的信息 带入到 以太坊链上,包括financial应用、provable computations等等。

2. 核心问题

核心问题在于:在EVM中直接验证Pickles SNARK非常昂贵。但是,可设计一种系统来对Pickles SNARK做某些预计算(如,计算a STARK that verifies the Pickles SNARK which itself may be efficiently verified on the EVM)。

Mina中的Pickles SNARK verifier的verification算法由以下元素组成:

  • 1)根据the data of the proof,计算多个hash值。这包括了使用Poseidon hash函数 with 63 full rounds both over F p \mathbb{F}_p Fp and F q \mathbb{F}_q Fq with round constants,以及 基于 F p \mathbb{F}_p Fp的MDS matrix基于 F q \mathbb{F}_q Fq的MDS Matrix。这一步非常便宜,可在EVM中以合理的gas实现。
  • 2)检查多个arithmetic equations。这一步也很便宜,可在EVM中直接实现。
  • 3)运行一个size 为 2 n 2 + 4 + ( 2 + 25 ) = 63 2n_2+4+(2+25)=63 2n2+4+(2+25)=63的multi-scalar multiplication(MSM)运算,某些bases为fixed,某些bases为variable。这一步似乎可在EVM上以合理的效率实现,尽管要比第一步和第二步要贵。
  • 4)对于每个 i i i,运行a multi-scalar multiplication over G i G_i Gi of size 2 n i 2^{n_i} 2ni with a fixed array of bases, and with scalars that can be very efficiently computed from the proof。

第4)步貌似无法直接在EVM中高效实现,除非可将计算切分为多块。

3. 引入Auxiliary STARK-based proof

Mina state verification的threshold cost为500万gas。因此,直接进行Pickles proof verification的gas不会超过500万。在Full verification of the Mina blockchain on EVM 中提出可向EVM额外提交一个STARK proof来证明a successful Pickles SNARK proof part verification,从而实现a valid in-EVM confirmation of everything what happened inside Mina。这种提交proof of successful proof verification的方法,似乎可控制在500万gas以内。

基于STARK的auxiliary proof的基本circuit中,包含的basic constraints(对应以上verification算法的第4)步)有:
令:

  • 1) P 1 , P 2 P_1,P_2 P1,P2为MSM results。
  • 2) n 1 , n 2 n_1,n_2 n1,n2为MSM sizes。
  • 3) G 1 = [ G 1 , 0 , ⋯   , G 1 , n 1 − 1 ] , G 2 = [ G 2 , 0 , ⋯   , G 2 , n 2 − 1 ] G_1=[G_{1,0},\cdots,G_{1,n_1-1}], G_2=[G_{2,0}, \cdots, G_{2,n_2-1}] G1=[G1,0,,G1,n11],G2=[G2,0,,G2,n21]为the sets of fixed points。

则对于 k = 1 , 2 k=1,2 k=1,2 有:

  • 1) R 0 = ( 0 : 1 : 0 ) R_0=(0:1:0) R0=(0:1:0)
  • 2) ∀ 0 ≤ i < n k : R i + 1 = R i + f ( s i , G k , i + 1 ) \forall 0\leq i < n_k: R_{i+1}=R_i+f(s_i, G_{k,i+1}) 0i<nk:Ri+1=Ri+f(si,Gk,i+1),其中 f ( s i , G k , i + 1 ) f(s_i,G_{k,i+1}) f(si,Gk,i+1)的结果 s i + 1 s_{i+1} si+1是根据 s i ∗ G k , i + 1 s_i*G_{k,i+1} siGk,i+1计算而来的。
  • 3) R n k − 1 − P k = ( 0 : 1 : 0 ) R_{n_k-1}-P_k=(0:1:0) Rnk1Pk=(0:1:0)

以上basic constraints可使用addition chains、Pippenger算法、STARK-friendly math等来优化,为Prover提供更好的性能,使Verifier需要更少的gas-cost。

额外还会研究,是将以上verification算法的第3)步包含在auxiliary proof中,还是直接在以太坊智能合约中进行验证。

不过,500万的gas确实太贵了。

4. 使gas更便宜

基于STARK的auxiliary proof verification所需gas仍然太昂贵,需要在auxiliary proof中寻找一种不同的SNARK方案。

R1CS(Rank-1 Constraint System-based) SNARK太昂贵了,已排除在外。

Spartan是transparent且有前途的,可在无需信任任何actor的情况下为以太坊生成所需提交的proof。如果需要信任a group of people来进行trusted setup,然后任何人都可基于trusted setup来生成Mina state proof?需要太多trust了。这也是为何SNARK transparency不是可选项,而是必选项。

基于PLONK proof scheme被认为是具有更便宜的verification cost。但是,大多数采用了Kate commitment scheme,需要trusted setup。

4.1 为何R1CS太贵?

需要a multiexp of size 2 18 2^{18} 218 and one of size 2 17 2^{17} 217 in a different curve。

R1CS system中最好的constraint cost per bit为:1 bit of scalar multiplication in 6 constraints,于是有:
2 18 2^{18} 218 scalar multiplications × \times × (255 bits per scalar multiplication × \times × (6 constraints/ 1bit)) = 401080320 constraints。

因此,若使用 sqrt(N)-cost DLOG-based polynomial commitment scheme,则Verifier需要do a multiexp of size 401080320 = 20026 \sqrt{401080320}=20026 401080320 =20026

以上采用的是naive multiexp 算法。若使用Pippenger算法,约需要 2 × s × n / log ⁡ 2 ( s × n ) 2\times s\times n/\log_2{(s\times n)} 2×s×n/log2(s×n)次group operation运算,其中 n n n为multiexp size,在此处等于 20026 20026 20026 s s s为scalar size,在此处为 255 255 255。采用Jacobian坐标系,每次group operation约需要 16 16 16次field multiplication,在EVM中,每次filed operation需要约8 gas。

因此,总的EVM cost约为:
2 × 255 × 20026 / log ⁡ 2 ( 255 × 20026 ) × 16 × 8 = 58 , 665 , 445 2\times 255\times 20026/\log_2{(255\times 20026)}\times 16\times 8=58,665,445 2×255×20026/log2(255×20026)×16×8=58,665,445 gas

对于另一个size为 2 17 2^{17} 217的multiexp,对应constraints数为14161,需要的EVM cost约为:
2 × 255 × 14161 / log ⁡ 2 ( 255 × 14161 ) × 16 × 8 = 42 , 436 , 216 2\times 255\times 14161/\log_2{(255\times 14161)}\times 16\times 8=42,436,216 2×255×14161/log2(255×14161)×16×8=42,436,216 gas

因此,总的cost约为101,101,661 gas。
因此,R1CS-based system并不适合此任务场景。

5. 如何让bridge为trustless且cheap?

最终,选择了类似RedShift的方案(PLONK-based syntax over FRI commitment scheme)。FRI commitment scheme为auxiliary SNARK proof提供了transparency,使用PLONK-based syntax可reduce the resulting circuit。

最终仅需要约:3, 594, 270 gas for a single verification。

其中,Verifier的主要cost来源于:

  • Merkle proof verification ( log ⁡ 2 n + 2 ⋅ log ⁡ 2 n ) (\log^2n+2\cdot \log{2n}) (log2n+2log2n)
  • low-degree testing ( log ⁡ n ) (\log n) (logn)

其中 n n n为committed polynomial 的degree。根据2019年论文 REDSHIFT: Transparent SNARKs from List Polynomial Commitment IOPs 可知, n = r o w s ⋅ ( w i r e s + 1 ) n=rows\cdot(wires+1) n=rows(wires+1)。low degree test中的主要cost在于2次基于有限域的倒数运算(约需要30,000 gas)。Keccak256运算需要30 gas。

以上2个元素中,scalar multiplication仍是最贵的部分,需要构建合适的PLONK gate来降低。

根据Daira的[Orchard] EC scalar multiplication using PLONK / Halo 2 custom gates #4254 可知,可采用3个PLONK gate(相应的polynomial constraints为degree 3) per scalar bit(每个multiplication对应3行3列)来实现a single scalar multiplication round。

对于size为 2 18 2^{18} 218的multiexp:

  • 总行数为: 2 18 × 255 × 3 × 4 = 802160640 2^{18}\times 255\times 3\times 4=802160640 218×255×3×4=802160640
  • Low degree tests: log ⁡ ( 802160640 ) = 30 \log(802160640)=30 log(802160640)=30
  • Merkle tree operations: log ⁡ 2 ( 802160640 ) + 2 ∗ log ⁡ ( 802160640 ) = 935 \log^2(802160640)+2*\log(802160640)=935 log2(802160640)+2log(802160640)=935
  • 总gas cost为: 2 × 30 × 30000 + 935 ∗ 30 = 1 , 828 , 050 2\times 30\times 30000+935*30=1,828,050 2×30×30000+93530=1,828,050 gas。

对于size为 2 17 2^{17} 217的multiexp:

  • 总行数为: 2 17 × 255 × 3 × 4 = 401080320 2^{17}\times 255\times 3\times 4=401080320 217×255×3×4=401080320
  • Low degree tests: log ⁡ ( 401080320 ) = 29 \log(401080320)=29 log(401080320)=29
  • Merkle tree operations: log ⁡ 2 ( 401080320 ) + 2 ∗ log ⁡ ( 401080320 ) = 874 \log^2(401080320)+2*\log(401080320)=874 log2(401080320)+2log(401080320)=874
  • 总gas cost为: 2 × 29 × 30000 + 874 ∗ 30 = 1 , 766 , 220 2\times 29\times 30000+874*30=1,766,220 2×29×30000+87430=1,766,220 gas。

verification cost的主要开销在于以上2个MSM,总的cost约为 1 , 828 , 050 + 1 , 766 , 220 = 3 , 594 , 270 1,828,050+1,766,220=3,594,270 1,828,050+1,766,220=3,594,270 gas。

由于上限为500万gas,因此仍有空间。其他cost主要来源于Poseidon hash计算以及a linear size MSM calculation。

6. 时间表

计划于2021年Q4完成 auxiliary proof circuit设计。
计划于2022年Q1上线production version。

参考资料

[1] =nil; Foundation’s in-EVM Full Mina State Verification.
[2] The Mina Foundation and Ethereum Foundation have announced a joint request for proposals (RFP), to enable recursive SNARK applications, on the Ethereum blockchain.
[3] Meet Pickles SNARK: Enabling Smart Contracts on Mina Protocol
[4] Full verification of the Mina blockchain on EVM

猜你喜欢

转载自blog.csdn.net/mutourend/article/details/123336311