Vitalik Buterin Quardratic Arithmetic Programs: from Zero to Hero 实现

https://github.com/christianlundkvist/libsnark-tutorialhttps://github.com/matter-labs/bellman-examples 中含对Vitalik Buterin博客Quardratic Arithmetic Programs: from Zero to Hero 中举例的实现,在该例子中,primary_input(也称为public_input) size为1(即n=1),因此对应的VKic数组有两个0~1。(可结合论文《Succinct Non-Interactive Zero Knowledge for a von Neumann Architecture》中P25页的算法细节来理解,对应其中的n为primary_input size, h 为auxiliary_input(亦称为private_input,或称为witness) size)。
在这里插入图片描述

In the libsnark tool, the protoboard is where our “circuits” (i.e. R1CS and gadgets) will be collected.

在christianlundkvist代码仓库中,有对verification_key和proof分别解析写入vk_data和proof_data文件中。

print_vk_to_file<default_r1cs_ppzksnark_pp>(vk, "../build/vk_data"); 
print_proof_to_file<default_r1cs_ppzksnark_pp>(proof, "../build/proof_data");

根据《Succinct Non-Interactive Zero Knowledge for a von Neumann Architecture》论文可知,verification_key由(n+3)个G1-elements和5个G2-elements组成,Proof由7个G1-elements和1个G2-element组成,对应的结构信息类似如下(借用之前博客中的以太坊智能合约verfier.sol中的结构来说明):

 struct VerifyingKey {
        Pairing.G2Point A;
        Pairing.G1Point B;
        Pairing.G2Point C;
        Pairing.G2Point gamma;
        Pairing.G1Point gammaBeta1;
        Pairing.G2Point gammaBeta2;
        Pairing.G2Point Z;
        Pairing.G1Point[] IC;
    }
3072469466092379324829297367653262340604043388062051954399809154370186007490 15751916618085453414666736770269656577717888906642212660178481547070214230884
14026003991233422516008635579711885034293301372755769893013247275252675017551 7121756170117633080354229603062711119447151560138672739359656594200197675370
15537870672644107910591301612515750578586698199433168003247909187287579900687
17906112681032849290762321924901496037617325323977896000125560181370016892106
10129424257992752528420248367101749769872778217522451596524132175551576211895 18539966977040862275609842904135900819709842334361192568330714683383232475161
21613449517714745858399706871986571392717137643214973335447874984328615052916 5789393702198645743158038400382098777680645394122040411067619559441541911199
196053008185180289520590736715686581337793134778701059891062629241300460533 9647411950151529555008725809957770908253037286070936331912333430368031449146
13127493051864925855402141777391346456238194167601844202532524826806339531456 9650075263768063858569055787004377006709221158063227073504801536363503056037
11938203411376318809384723618725754420191709797762860447427691442819399340251
3174465203588925261654544634342532455927661654656062922623235939320239344756
13612403894237648647403412588656361183324686922278103155556090728061084946495 19354854979160458938373807707905358177616975350923393752151454943331170608223
12296716190892559200975571135403906526819842088498873483744862428348463254195 3828104226727768526252179934423152864751137808443223891318466256139959669350
11366218312880285089894549203417640146280466585892997002549089854548926445624 6721343109989013397367267503019713272172508453613543224766378052051591130756
20665402411596684554508277750211057977528290764621512307700480059144582583466 17863934525613130398322943884504576448868715013505206210392356010919971834102
4351236568605261616251436071694094679577956017706261326058113028111291953463
15736102388870615983293210071195191316837948730788671268105363359516206876158
5893729468515196244379523054584236118565419609928271179532195768525770384665
2275557594312953342727236748773419113678296393590686068599779353473764173048

    struct Proof {
        Pairing.G1Point A;
        Pairing.G1Point A_p;
        Pairing.G2Point B;
        Pairing.G1Point B_p;
        Pairing.G1Point C;
        Pairing.G1Point C_p;
        Pairing.G1Point K;
        Pairing.G1Point H;
    }
13156395390306249942518599127773907232687248156314848060142204794485101658495
11658998997847489741629937033875452739852189399376943824547466785607485870107
21188542283208324950604935641086567127505150218341288197872978207697359355331
16231897080313018182578313710734605316314961838942186557455422778642292520310
5267889906632163010002445943972035598621598265129316903073691544789334744790 16712079683368966367458502938191927992808860186773252436785408120009911812673
18404103406904852108776631079180887524797514696905176371652200709744567576302 18025015753551988762992220821200946269263647743817434998641837541607275811722
19314850241633645343358261539369241744733097828576634194325553710791081707486
4075617152183517003497035259250766684468437098900673500413680014553188008759
9366006398094358391276135811689678342053764719247431324319828905331788441044
4221861960334035637644411738049879107991243619334651128927678147040106834815
4703908125713173233777341145102690385786443114315847876024661723484711243506
14658703613077221634393935955377903427148447470112989650871351721417827387633
8660949833615967970964416237445925509938177304814619571590729714108848773053
18280495004764910116296484296183492160899739279509314621035533686423620051819
6583128845407129121034230769615201618474170060076233152255765944142870339768
18182734356277341932992640607401417666503008441559314745845220555829840304761

利用以上verification_key参数,以及根据所选择曲线(CMakelists.txt中的CURVE参数,christianlundkvist仓库中选择的为ALT_BN128)的public参数来确定G1 generator、G2 generator、F_q等值,可手工写出类似于之前博客中的智能合约,并利用proof参数进行on-chain测试验证。
在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值