Skip to content

Commit eeb2476

Browse files
committed
spend the receive note ok
1 parent fb3a621 commit eeb2476

File tree

2 files changed

+62
-38
lines changed

2 files changed

+62
-38
lines changed

privacy/zsl/main.cpp

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ bool shielding()
2222

2323
std::string proof;
2424
zsl_prove_shielding(rho, pk, value, proof);
25-
std::cout << "shielding proof:" << proof << std::endl;;
25+
//std::cout << "shielding proof:" << proof << std::endl;;
2626

2727
std::string send_nf = Note::computeSendNullifier(rho);
2828
std::cout << "send_nf:" << send_nf << std::endl;
@@ -53,7 +53,7 @@ bool unshielding()
5353
value = 2378237;
5454
std::string proof_u;
5555
zsl_prove_unshielding(rho, sk, value, index, uncles, proof_u);
56-
std::cout << "unshielding proof:" << proof_u << std::endl;
56+
//std::cout << "unshielding proof:" << proof_u << std::endl;
5757

5858
bool ret = zsl_verify_unshielding(proof_u, spend_nf, mt.root(), value);
5959
return ret;
@@ -83,22 +83,10 @@ bool shield_transfer()
8383
uint64_t index1 = 0;
8484
std::vector<std::string> auth_path1;
8585
mt.get_witness(input_cm1, index1, auth_path1);
86-
//std::vector<std::string> auth_path1 = mt.getWitness(intput_cm1);
87-
std::cout << "index1:" << index1 << std::endl;
88-
for(int i = 0; i < 29; i++) {
89-
//auth_path1.push_back("8000000000000000000000000000000000000000000000000000000000000100");
90-
std::cout << auth_path1[i] << std::endl;
91-
}
92-
std::cout << "===== auth path 2" << std::endl;
86+
9387
uint64_t index2 = 0;
9488
std::vector<std::string> auth_path2;
9589
mt.get_witness(input_cm2, index2, auth_path2);
96-
//std::vector<std::string> auth_path2 = mt.getWitness(intput_cm2);
97-
std::cout << "index2:" << index2 << std::endl;
98-
for(int i = 0; i < 29; i++) {
99-
//auth_path2.push_back("8000000000000000000000000000000000000000000000000000000000000100");
100-
std::cout << auth_path2[i] << std::endl;
101-
}
10290

10391
std::string output_pk;
10492
std::string output_sk;
@@ -114,25 +102,49 @@ bool shield_transfer()
114102
get_randomness(output_rho2, 32);
115103

116104
Note output_note1(output_pk, 150, output_rho1);
117-
Note output_note2(pk, 50, output_rho2);
105+
Note output_note2(output_pk1, 50, output_rho2);
118106

119107
std::string anchor = mt.root();
120-
//std::string anchor = "8610652739ac0c6bb6b5353649bb822b26543f0ebe88f32a489a56843cd04f03";
121108

122-
std::cout << "input_note1:" << std::endl;
109+
/*std::cout << "input_note1:" << std::endl;
123110
input_note1.debug_string();
124111
std::cout << "input_note2:" << std::endl;
125112
input_note2.debug_string();
126113
std::cout << "output_note1:" << std::endl;
127114
output_note1.debug_string();
128115
std::cout << "output_note1:" << std::endl;
129-
output_note2.debug_string();
116+
output_note2.debug_string();*/
130117

131118

132119
std::string proof_t;
133120
zsl_prove_transfer(proof_t, input_note1.rho, sk, input_note1.value, index1, auth_path1, input_note2.rho, sk1, input_note2.value, index2, auth_path2, output_note1.rho, output_note1.pk, output_note1.value, output_note2.rho, output_note2.pk, output_note2.value);
134121

135122
bool ret = zsl_verify_transfer(proof_t, anchor, input_note1.spend_nf(sk), input_note2.spend_nf(sk1), output_note1.send_nf(), output_note2.send_nf(), output_note1.cm(), output_note2.cm());
123+
if (ret) {
124+
std::cout << "spend the new output note test" << std::endl;
125+
std::string new_input_cm1 = output_note1.cm();
126+
mt.add_commitment(new_input_cm1);
127+
std::string new_input_cm2 = output_note2.cm();
128+
mt.add_commitment(new_input_cm2);
129+
130+
auth_path1.clear();
131+
auth_path2.clear();
132+
mt.get_witness(new_input_cm1, index1, auth_path1);
133+
mt.get_witness(new_input_cm2, index2, auth_path2);
134+
135+
get_randomness(output_rho1, 32);
136+
get_randomness(output_rho2, 32);
137+
138+
Note new_output_note1(pk, 190, output_rho1);
139+
Note new_output_note2(output_pk, 10, output_rho2);
140+
141+
std::string anchor = mt.root();
142+
143+
std::string new_proof;
144+
zsl_prove_transfer(new_proof, output_note1.rho, output_sk, output_note1.value, index1, auth_path1, output_note2.rho, output_sk1, output_note2.value, index2, auth_path2, new_output_note1.rho, new_output_note1.pk, new_output_note1.value, new_output_note2.rho, new_output_note2.pk, new_output_note2.value);
145+
146+
bool ret = zsl_verify_transfer(new_proof, anchor, output_note1.spend_nf(output_sk), output_note2.spend_nf(output_sk1), new_output_note1.send_nf(), new_output_note2.send_nf(), new_output_note1.cm(), new_output_note2.cm());
147+
}
136148
return ret;
137149
}
138150

privacy/zsl/test.cpp

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ bool shielding()
2222

2323
std::string proof;
2424
zsl_prove_shielding(rho, pk, value, proof);
25-
std::cout << "shielding proof:" << proof << std::endl;;
25+
//std::cout << "shielding proof:" << proof << std::endl;;
2626

2727
std::string send_nf = Note::computeSendNullifier(rho);
2828
std::cout << "send_nf:" << send_nf << std::endl;
@@ -53,7 +53,7 @@ bool unshielding()
5353
value = 2378237;
5454
std::string proof_u;
5555
zsl_prove_unshielding(rho, sk, value, index, uncles, proof_u);
56-
std::cout << "unshielding proof:" << proof_u << std::endl;
56+
//std::cout << "unshielding proof:" << proof_u << std::endl;
5757

5858
bool ret = zsl_verify_unshielding(proof_u, spend_nf, mt.root(), value);
5959
return ret;
@@ -83,22 +83,10 @@ bool shield_transfer()
8383
uint64_t index1 = 0;
8484
std::vector<std::string> auth_path1;
8585
mt.get_witness(input_cm1, index1, auth_path1);
86-
//std::vector<std::string> auth_path1 = mt.getWitness(intput_cm1);
87-
std::cout << "index1:" << index1 << std::endl;
88-
for(int i = 0; i < 29; i++) {
89-
//auth_path1.push_back("8000000000000000000000000000000000000000000000000000000000000100");
90-
std::cout << auth_path1[i] << std::endl;
91-
}
92-
std::cout << "===== auth path 2" << std::endl;
86+
9387
uint64_t index2 = 0;
9488
std::vector<std::string> auth_path2;
9589
mt.get_witness(input_cm2, index2, auth_path2);
96-
//std::vector<std::string> auth_path2 = mt.getWitness(intput_cm2);
97-
std::cout << "index2:" << index2 << std::endl;
98-
for(int i = 0; i < 29; i++) {
99-
//auth_path2.push_back("8000000000000000000000000000000000000000000000000000000000000100");
100-
std::cout << auth_path2[i] << std::endl;
101-
}
10290

10391
std::string output_pk;
10492
std::string output_sk;
@@ -114,25 +102,49 @@ bool shield_transfer()
114102
get_randomness(output_rho2, 32);
115103

116104
Note output_note1(output_pk, 150, output_rho1);
117-
Note output_note2(pk, 50, output_rho2);
105+
Note output_note2(output_pk1, 50, output_rho2);
118106

119107
std::string anchor = mt.root();
120-
//std::string anchor = "8610652739ac0c6bb6b5353649bb822b26543f0ebe88f32a489a56843cd04f03";
121108

122-
std::cout << "input_note1:" << std::endl;
109+
/*std::cout << "input_note1:" << std::endl;
123110
input_note1.debug_string();
124111
std::cout << "input_note2:" << std::endl;
125112
input_note2.debug_string();
126113
std::cout << "output_note1:" << std::endl;
127114
output_note1.debug_string();
128115
std::cout << "output_note1:" << std::endl;
129-
output_note2.debug_string();
116+
output_note2.debug_string();*/
130117

131118

132119
std::string proof_t;
133120
zsl_prove_transfer(proof_t, input_note1.rho, sk, input_note1.value, index1, auth_path1, input_note2.rho, sk1, input_note2.value, index2, auth_path2, output_note1.rho, output_note1.pk, output_note1.value, output_note2.rho, output_note2.pk, output_note2.value);
134121

135122
bool ret = zsl_verify_transfer(proof_t, anchor, input_note1.spend_nf(sk), input_note2.spend_nf(sk1), output_note1.send_nf(), output_note2.send_nf(), output_note1.cm(), output_note2.cm());
123+
if (ret) {
124+
std::cout << "spend the new output note test" << std::endl;
125+
std::string new_input_cm1 = output_note1.cm();
126+
mt.add_commitment(new_input_cm1);
127+
std::string new_input_cm2 = output_note2.cm();
128+
mt.add_commitment(new_input_cm2);
129+
130+
auth_path1.clear();
131+
auth_path2.clear();
132+
mt.get_witness(new_input_cm1, index1, auth_path1);
133+
mt.get_witness(new_input_cm2, index2, auth_path2);
134+
135+
get_randomness(output_rho1, 32);
136+
get_randomness(output_rho2, 32);
137+
138+
Note new_output_note1(pk, 190, output_rho1);
139+
Note new_output_note2(output_pk, 10, output_rho2);
140+
141+
std::string anchor = mt.root();
142+
143+
std::string new_proof;
144+
zsl_prove_transfer(new_proof, output_note1.rho, output_sk, output_note1.value, index1, auth_path1, output_note2.rho, output_sk1, output_note2.value, index2, auth_path2, new_output_note1.rho, new_output_note1.pk, new_output_note1.value, new_output_note2.rho, new_output_note2.pk, new_output_note2.value);
145+
146+
bool ret = zsl_verify_transfer(new_proof, anchor, output_note1.spend_nf(output_sk), output_note2.spend_nf(output_sk1), new_output_note1.send_nf(), new_output_note2.send_nf(), new_output_note1.cm(), new_output_note2.cm());
147+
}
136148
return ret;
137149
}
138150

0 commit comments

Comments
 (0)