Skip to content

Deposit测试

wzysdu edited this page Dec 3, 2018 · 5 revisions

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


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

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

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

b/balance:转换前账户的明文余额


理想测试

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

结果: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);
uint64_t balance = uint64_t(30);

结果: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);
uint64_t balance = uint64_t(30);

结果: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);
uint64_t balance = uint64_t(30);

结果:Verifying mint proof successfully!


v_s=0

uint64_t value = uint64_t(13); 
uint64_t value_old = uint64_t(13); 
uint64_t value_s = uint64_t(0);
uint64_t balance = uint64_t(30);

结果:Verifying mint 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);
uint64_t balance = uint64_t(30);

结果:Verifying mint proof successfully!


v_s > b

uint64_t value = uint64_t(13); 
uint64_t value_old = uint64_t(6); 
uint64_t value_s = uint64_t(7);
uint64_t balance = uint64_t(1);

结果:generate mint proof fail!!!


v_s = b

uint64_t value = uint64_t(13); 
uint64_t value_old = uint64_t(6); 
uint64_t value_s = uint64_t(7);
uint64_t balance = uint64_t(7);

结果:generate mint proof fail!!!


对于负数情况,因为补码问题有时也会是对的

uint64_t value = uint64_t(8); 
uint64_t value_old = uint64_t(-18446744073709551610); 
uint64_t value_s = uint64_t(2);
uint64_t balance = uint64_t(-18446744073709551610);  

结果:Verifying mint proof successfully!

因为-18446744073709551610补码为6 且2<6,2+6=8

但是,由于value_s 和 balance为所有人都知道的参数变量,所以该问题可以避免。


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