Skip to content

Update测试

Agzs edited this page Dec 3, 2018 · 3 revisions

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


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

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

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


理想测试:

uint64_t value = uint64_t(13); 
uint64_t value_old = uint64_t(20); 
uint64_t value_s = uint64_t(7);

结果:Verifying redeem proof successfully!


v > v_old - v_s

uint64_t value = uint64_t(14); 
uint64_t value_old = uint64_t(20); 
uint64_t value_s = uint64_t(7);

结果:generate redeem proof fail!


v < v_old - v_s

uint64_t value = uint64_t(12); 
uint64_t value_old = uint64_t(20); 
uint64_t value_s = uint64_t(7);

结果:generate redeem proof fail!


v_s = 0

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

结果:Verifying redeem proof successfully!


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 redeem proof fail!


v_s = v_old

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

结果:generate redeem proof fail!


v_s > v_old

uint64_t value = uint64_t(-1); 
uint64_t value_old = uint64_t(12); 
uint64_t value_s = uint64_t(13);

结果:generate redeem proof fail!


验证能否产生proof及产生proof之后验证能否成功

验证能否产生proof:

auto proof = generate_proof<default_r1cs_ppzksnark_pp>(keypair.pk, 
                                                            note_s,
                                                            note_old,
                                                            note,
                                                            cmtS,
                                                            cmtA_old,
                                                            cmtA,
                                                            rt, //wrong_rt
                                                            path //wrong_path
                                                            );

验证产生Proof之后验证能否成功:

bool result = verify_proof(keypair.vk, 
                                   *proof, 
                                   rt, //wrong_rt
                                   cmtA_old,
                                   cmtA
                                   );

以不同情况改变 rt, path, cmtS, cmtA_old, cmtA 5个变量,检查测试结果。


通过 auto proof 中验证改变变量之后能否产生proof:

(1)rt, path, cmtS, cmtA_old, cmtA 为可以产生proof时的正确参数:

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

验证可以产生proof,结果为:

verify result = 1

Verifying update proof successfully!!!


(2) path, cmtS, cmtA_old, cmtA 为可以产生proof时的正确参数,rt 为错误参数:

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

验证无法产生proof, 结果为:

pb.is_satisfied() is 0

generate update proof fail!!!


(3) rt, cmtS, cmtA_old, cmtA 为可以产生proof时的正确参数, path 为错误参数:

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

验证无法产生proof, 结果为:

pb.is_satisfied() is 0

generate update proof fail!!!


(4) rt, path, cmtA_old, cmtA 为可以产生proof时的正确参数,cmtS 为错误参数:

uint256 rt = wit.root();
auto path = wit.path();
uint256 wrong_cmtS = note_old.cm();
uint256 cmtA_old = note_old.cm();
uint256 cmtA = note.cm();

验证无法产生proof, 结果为:

pb.is_satisfied() is 0

generate update proof fail!!!


(5) rt, path, cmtS, cmtA 为可以产生proof时的正确参数,cmtA_old 为错误参数:

uint256 rt = wit.root();
auto path = wit.path();
uint256 cmtS = note_s.cm();
uint256 wrong_cmtA_old = note.cm();
uint256 cmtA = note.cm();

验证无法产生proof, 结果为:

pb.is_satisfied() is 0

generate update proof fail!!!


(6) rt, path, cmtS, cmtA_old 为可以产生proof时的正确参数,cmtA 为错误参数:


uint256 rt = wit.root();
auto path = wit.path();
uint256 cmtS = note_s.cm();
uint256 cmtA_old = note_old.cm();
uint256 wrong_cmtA = note_old.cm();

验证无法产生proof, 结果为:

pb.is_satisfied() is 0

generate update proof fail!!!


(7)cmtA_old, cmtA, cmtS 为可以产生proof时的正确参数,rt, path为错误参数:

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

验证无法产生proof, 结果为:

pb.is_satisfied() is 0

generate update proof fail!!!


通过 bool result 验证生成 proof 之后,能否成功验证proof

(1) rt, cmtA_old, cmtA 为产生 proof 之后可以验证成功的正确参数:

uint256 rt = wit.root();
uint256 cmtA_old = note_old.cm();
uint256 cmtA = note.cm();

产生proof之后验证成功,结果为:

verify result = 1

Verifying update proof successfully!!!


(2) rt, cmtA_old 为产生 proof 之后可以验证成功的正确参数,cmtA 为错误参数:

uint256 rt = wit.root();
uint256 cmtA_old = note_old.cm();
uint256 wrong_cmtA = note_old.cm();

产生proof之后验证不成功,结果为:

verify result = 0

Verifying update proof unsuccessfully!!!


(3) rt, cmtA 为产生 proof 之后可以验证成功的正确参数, cmtA_old 为错误参数:

uint256 rt = wit.root();
uint256 wrong_cmtA_old = note.cm();
uint256 cmtA = note.cm();

产生proof之后验证不成功,结果为:

verify result = 0

Verifying update proof unsuccessfully!!!


(4) cmtA_old, cmtA 为产生 proof 之后可以验证成功的正确参数, rt 为错误参数:

uint256 wrong_rt = wrong_wit.root();
uint256 cmtA_old = note_old.cm();
uint256 cmtA = note.cm();

产生proof之后验证不成功,结果为:

verify result = 0

Verifying update 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