Skip to content

Deposit测试

wzysdu edited this page Dec 3, 2018 · 5 revisions

传入数据需满足:v = v_old + v_s


v_old/value_old:转换前零知识余额对应的明文余额

v_s/value_s:需要被转换的明文余额

v/value:转换后零知识余额对应的明文余额


理想测试

uint64_t value = uint64_t(264); 
uint64_t value_old = uint64_t(255); 
uint64_t value_s = uint64_t(9);

结果:Verifying deposit proof successfully!!!


v > v_old + v_s

uint64_t value = uint64_t(264); 
uint64_t value_old = uint64_t(250); 
uint64_t value_s = uint64_t(9);

结果:generate deposit proof fail!!!


v < v_old + v_s

uint64_t value = uint64_t(261); 
uint64_t value_old = uint64_t(255); 
uint64_t value_s = uint64_t(9);

结果:generate deposit proof fail!!!


v_old=0

uint64_t value = uint64_t(264); 
uint64_t value_old = uint64_t(0); 
uint64_t value_s = uint64_t(264);

结果:Verifying deposit proof successfully!!!


v_s=0

uint64_t value = uint64_t(264); 
uint64_t value_old = uint64_t(264); 
uint64_t value_s = uint64_t(0);

结果:generate deposit proof fail!!!


v_s = 0 v_old = 0 v=0

uint64_t value = uint64_t(0); 
uint64_t value_old = uint64_t(0); 
uint64_t value_s = uint64_t(0);

结果:generate deposit proof fail!!!


验证生成proof

auto proof = generate_proof<default_r1cs_ppzksnark_pp>(keypair.pk, 
                                                            note_s,
                                                            note_old,
                                                            note,
                                                            cmtS,
                                                            cmtB_old,
                                                            cmtB,
                                                            rt, 
                                                            path 
                                                            );

理想测试

uint256 cmtS = note_s.cm();
uint256 cmtB_old = note_old.cm();
uint256 cmtB = note.cm();
uint256 rt = wit.root();
auto path = wit.path();

结果:Verifying deposit proof successfully!!!


现改变cmtS为wrong_cmtS,

uint256 wrong_cmtS = note_old.cm();
uint256 cmtB_old = note_old.cm();
uint256 cmtB = note.cm();
uint256 rt = wit.root();
auto path = wit.path();

结果:generate deposit proof fail!!!


现改变cmtB_old为wrong_cmtB_old,

uint256 cmtS = note_s.cm();
uint256 wrong_cmtB_old = note.cm();
uint256 cmtB = note.cm();
uint256 rt = wit.root();
auto path = wit.path();

结果:generate deposit proof fail!!!


现改变cmtB为wrong_cmtB,

uint256 cmtS = note_s.cm();
uint256 cmtB_old = note_old.cm();
uint256 wrong_cmtB = note_old.cm();
uint256 rt = wit.root();
auto path = wit.path();

结果:generate deposit proof fail!!!


现改变rt为wrong_rt,

uint256 cmtS = note_s.cm();
uint256 cmtB_old = note_old.cm();
uint256 cmtB = note.cm();
uint256 wrong_rt = wrong_wit.root();
auto path = wit.path();

结果:generate deposit proof fail!!!


现改变path为wrong_path,

uint256 cmtS = note_s.cm();
uint256 cmtB_old = note_old.cm();
uint256 cmtB = note.cm();
uint256 rt = wit.root();
auto wrong_path = wrong_wit.path();

结果:generate deposit proof fail!!!


现改变rt为wrong_rt,path为wrong_path,

uint256 cmtS = note_s.cm();
uint256 cmtB_old = note_old.cm();
uint256 cmtB = note.cm();
uint256 wrong_rt = wrong_wit.root();
auto wrong_path = wrong_wit.path();

结果:generate deposit proof fail!!!


正常产生proof时,验证proof

bool result = verify_proof(keypair.vk, 
                                    *proof, 
                                    rt, 
                                    pk_recv,
                                    cmtB_old,
                                    sn_old,
                                    cmtB
                                   );


理想测试

uint160 pk_recv = uint160S("123");
uint256 sn_old = uint256S("123456");
uint256 rt = wit.root();
uint256 cmtB_old = note_old.cm();
uint256 cmtB = note.cm();

结果:Verifying deposit proof successfully!!!


现改变pk_recv为wrong_pk_recv,

uint160 wrong_pk_recv = uint160S("333");
uint256 sn_old = uint256S("123456");
uint256 rt = wit.root();
uint256 cmtB_old = note_old.cm();
uint256 cmtB = note.cm();

结果:Verifying deposit proof unsuccessfully!!!


现改变sn_old为wrong_sn_old,

uint160 pk_recv = uint160S("123");
uint256 wrong_sn_old = uint256S("666");
uint256 rt = wit.root();
uint256 cmtB_old = note_old.cm();
uint256 cmtB = note.cm();

结果:Verifying deposit proof unsuccessfully!!!


1. 方案设计

VNT零知识设计方案

方案设计图

2. 方案实现

实现细节思考

2.1 libsnark模块实现

2.2 ethereum模块实现

2.3 cgo模块实现

3. 方案测试

部分问题

整体测试出的问题

3.1 libsnark模块测试

3.2 整体测试

4. 修改汇总

4.1 libsnark模块修改汇总

4.2 ethereum模块修改汇总

4.3 cgo模块修改汇总

5. 开发技巧

修改并编译web3.js文件

libsnark遇到的大“坑”

FZQA

CGO

MPT trie

transaction 部分修改

简易以太坊测试

Clone this wiki locally