Skip to content

Commit fe3fff6

Browse files
authored
adapt to the wedpr-lab-crypto v1.3.0 (#58)
1 parent a051184 commit fe3fff6

File tree

20 files changed

+1256
-99
lines changed

20 files changed

+1256
-99
lines changed

bounty/Cargo.toml

+1-3
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,13 @@ curve25519-dalek = { version = "1", features = [ "serde" ] }
1212
protobuf = "2.22.1"
1313
rand = "0.3.17"
1414
sha3 = "0.8"
15-
wedpr_l_crypto_zkp_discrete_logarithm_proof = "1.0.0"
15+
wedpr_l_crypto_zkp_discrete_logarithm_proof = {version = "1.3.0", git = "https://github.com/WeBankBlockchain/WeDPR-Lab-Crypto", branch = "dev-1.3.0"}
1616
wedpr_l_crypto_zkp_range_proof = "1.2.0"
1717
wedpr_l_crypto_zkp_utils = "1.0.0"
1818
wedpr_l_macros = "1.0.0"
19-
wedpr_l_protos = "1.0.0"
2019
wedpr_l_utils = "1.0.0"
2120
wedpr_s_protos = { path = "../protos" }
2221
wedpr_s_selective_certificate_disclosure = { path = "../solution/selective_certificate_disclosure" }
23-
2422
wedpr_s_verifiable_confidential_ledger = { path = "../solution/verifiable_confidential_ledger" }
2523

2624
[dev-dependencies]

bounty/src/vcl.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use super::utils;
66
extern crate wedpr_s_verifiable_confidential_ledger;
77
use wedpr_s_verifiable_confidential_ledger::vcl;
88
extern crate wedpr_l_crypto_zkp_range_proof;
9-
109
/// UI flow of VCL bounty playground.
1110
pub fn flow_vcl() {
1211
utils::print_highlight(
@@ -223,15 +222,16 @@ mod tests {
223222
};
224223
extern crate wedpr_l_common_coder_base64;
225224
extern crate wedpr_l_crypto_zkp_range_proof;
226-
extern crate wedpr_l_protos;
227225
extern crate wedpr_s_verifiable_confidential_ledger;
228226
use crate::vcl_data::{
229227
TARGET_SIZE, VCL_C1_VEC, VCL_C2_VEC, VCL_C3_VEC, VCL_PROOF_VEC,
230228
};
231229
use protobuf::Message;
232230
use wedpr_l_common_coder_base64::WedprBase64;
233-
use wedpr_l_protos::generated::zkp::BalanceProof;
234231
use wedpr_l_utils::traits::Coder;
232+
use wedpr_s_protos::{
233+
generated::zkp::PBBalanceProof, pb_to_arithmetric_proof,
234+
};
235235

236236
#[test]
237237
fn test_vcl_bounty_data_validity() {
@@ -249,16 +249,20 @@ mod tests {
249249
bytes_to_point(&base64.decode(&VCL_C3_VEC[i]).unwrap())
250250
.expect("failed to decode point");
251251

252-
let proof = <BalanceProof>::parse_from_bytes(
252+
let pb_proof = <PBBalanceProof>::parse_from_bytes(
253253
&base64.decode(&VCL_PROOF_VEC[i]).unwrap(),
254254
)
255255
.expect("failed to parse proof PB");
256-
256+
let arithmetric_proof_result = pb_to_arithmetric_proof(&pb_proof);
257+
let arithmetric_proof = match arithmetric_proof_result {
258+
Ok(v) => v,
259+
Err(_) => panic!("invalid arithmetric_proof"),
260+
};
257261
assert!(wedpr_l_crypto_zkp_discrete_logarithm_proof::verify_sum_relationship(
258262
&c1_point,
259263
&c2_point,
260264
&c3_point,
261-
&proof,
265+
&arithmetric_proof,
262266
&value_basepoint,
263267
&blinding_basepoint
264268
).unwrap());

ffi/ffi_c/ffi_c_vcl/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ protobuf = "2.22.1"
1616
wedpr_ffi_common = "1.0.0"
1717
wedpr_ffi_macros = "1.1.0"
1818
wedpr_l_macros = "1.0.0"
19-
wedpr_l_protos = "1.1.0"
2019
wedpr_s_protos = { path = "../../../protos" }
2120
wedpr_s_verifiable_confidential_ledger = { path = "../../../solution/verifiable_confidential_ledger" }
2221

ffi/ffi_c/ffi_c_vcl/src/lib.rs

+12-10
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ use wedpr_ffi_common::utils::{
1616
};
1717
use wedpr_s_verifiable_confidential_ledger;
1818

19-
use wedpr_l_protos::generated::zkp::BalanceProof;
20-
use wedpr_s_protos::generated::vcl::{
21-
BatchCreditBalanceProof, EncodedConfidentialCredit, EncodedOwnerSecret,
22-
VclResult,
19+
use wedpr_s_protos::generated::{
20+
vcl::{
21+
BatchCreditBalanceProof, EncodedConfidentialCredit, EncodedOwnerSecret,
22+
VclResult,
23+
},
24+
zkp::PBBalanceProof,
2325
};
2426

2527
use libc::{c_char, c_ulong};
@@ -110,7 +112,7 @@ pub extern "C" fn wedpr_vcl_verify_sum_balance(
110112
let result = panic::catch_unwind(|| {
111113
let proof = c_safe_c_char_pointer_to_proto_with_error_value!(
112114
proof_cstring,
113-
BalanceProof,
115+
PBBalanceProof,
114116
FAILURE
115117
);
116118
let c1_credit =
@@ -160,7 +162,7 @@ pub extern "C" fn wedpr_vcl_verify_sum_balance_in_batch(
160162
let mut c1_credits: Vec<ConfidentialCredit> = vec![];
161163
let mut c2_credits: Vec<ConfidentialCredit> = vec![];
162164
let mut c3_credits: Vec<ConfidentialCredit> = vec![];
163-
let mut proofs: Vec<BalanceProof> = vec![];
165+
let mut proofs: Vec<PBBalanceProof> = vec![];
164166
for credit_balance_proof in batch_proof.credit_balance_proof {
165167
c1_credits.push(decode_credit!(
166168
c_safe_bytes_to_proto_with_error_value!(
@@ -197,7 +199,7 @@ pub extern "C" fn wedpr_vcl_verify_sum_balance_in_batch(
197199
credit_balance_proof.proof,
198200
FAILURE
199201
),
200-
BalanceProof,
202+
PBBalanceProof,
201203
FAILURE
202204
));
203205
}
@@ -257,7 +259,7 @@ pub extern "C" fn wedpr_vcl_verify_product_balance(
257259
let result = panic::catch_unwind(|| {
258260
let proof = c_safe_c_char_pointer_to_proto_with_error_value!(
259261
proof_cstring,
260-
BalanceProof,
262+
PBBalanceProof,
261263
FAILURE
262264
);
263265
let c1_credit =
@@ -307,7 +309,7 @@ pub extern "C" fn wedpr_vcl_verify_product_balance_in_batch(
307309
let mut c1_credits: Vec<ConfidentialCredit> = vec![];
308310
let mut c2_credits: Vec<ConfidentialCredit> = vec![];
309311
let mut c3_credits: Vec<ConfidentialCredit> = vec![];
310-
let mut proofs: Vec<BalanceProof> = vec![];
312+
let mut proofs: Vec<PBBalanceProof> = vec![];
311313
for credit_balance_proof in batch_proof.credit_balance_proof {
312314
c1_credits.push(decode_credit!(
313315
c_safe_bytes_to_proto_with_error_value!(
@@ -344,7 +346,7 @@ pub extern "C" fn wedpr_vcl_verify_product_balance_in_batch(
344346
credit_balance_proof.proof,
345347
FAILURE
346348
),
347-
BalanceProof,
349+
PBBalanceProof,
348350
FAILURE
349351
));
350352
}

ffi/ffi_java/ffi_java_scd/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ jni = "0.13.0"
1414
protobuf = "2.22.1"
1515
wedpr_ffi_common = "1.0.0"
1616
wedpr_ffi_macros = "1.0.0"
17-
wedpr_l_protos = "1.0.0"
1817

1918
wedpr_s_protos = { path = "../../../protos" }
2019
wedpr_s_selective_certificate_disclosure = { path = "../../../solution/selective_certificate_disclosure" }

ffi/ffi_java/ffi_java_vcl/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ jni = "0.13.0"
1515
protobuf = "2.22.1"
1616
wedpr_ffi_common = "1.1.0"
1717
wedpr_ffi_macros = "1.1.0"
18-
wedpr_l_protos = "1.1.0"
1918

2019
wedpr_s_protos = { path = "../../../protos" }
2120
wedpr_s_verifiable_confidential_ledger = { path = "../../../solution/verifiable_confidential_ledger" }

ffi/ffi_java/ffi_java_vcl/src/lib.rs

+11-9
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ use wedpr_ffi_common::utils::{
2121
};
2222
use wedpr_s_verifiable_confidential_ledger;
2323

24-
use wedpr_l_protos::generated::zkp::BalanceProof;
25-
use wedpr_s_protos::generated::vcl::{
26-
BatchCreditBalanceProof, EncodedConfidentialCredit, EncodedOwnerSecret,
24+
use wedpr_s_protos::generated::{
25+
vcl::{
26+
BatchCreditBalanceProof, EncodedConfidentialCredit, EncodedOwnerSecret,
27+
},
28+
zkp::PBBalanceProof,
2729
};
2830
use wedpr_s_verifiable_confidential_ledger::vcl::ConfidentialCredit;
2931

@@ -178,7 +180,7 @@ pub extern "system" fn Java_com_webank_wedpr_vcl_NativeInterface_verifySumBalanc
178180
_env,
179181
result_jobject,
180182
proof_jstring,
181-
BalanceProof
183+
PBBalanceProof
182184
);
183185

184186
let c1_credit = decode_credit!(
@@ -254,7 +256,7 @@ pub extern "system" fn Java_com_webank_wedpr_vcl_NativeInterface_verifySumBalanc
254256
let mut c1_credits: Vec<ConfidentialCredit> = vec![];
255257
let mut c2_credits: Vec<ConfidentialCredit> = vec![];
256258
let mut c3_credits: Vec<ConfidentialCredit> = vec![];
257-
let mut proofs: Vec<BalanceProof> = vec![];
259+
let mut proofs: Vec<PBBalanceProof> = vec![];
258260
for credit_balance_proof in batch_proof.credit_balance_proof {
259261
c1_credits.push(decode_credit!(
260262
_env,
@@ -306,7 +308,7 @@ pub extern "system" fn Java_com_webank_wedpr_vcl_NativeInterface_verifySumBalanc
306308
result_jobject,
307309
credit_balance_proof.proof
308310
),
309-
BalanceProof
311+
PBBalanceProof
310312
));
311313
}
312314

@@ -404,7 +406,7 @@ pub extern "system" fn Java_com_webank_wedpr_vcl_NativeInterface_verifyProductBa
404406
_env,
405407
result_jobject,
406408
proof_jstring,
407-
BalanceProof
409+
PBBalanceProof
408410
);
409411

410412
let c1_credit = decode_credit!(
@@ -479,7 +481,7 @@ pub extern "system" fn Java_com_webank_wedpr_vcl_NativeInterface_verifyProductBa
479481
let mut c1_credits: Vec<ConfidentialCredit> = vec![];
480482
let mut c2_credits: Vec<ConfidentialCredit> = vec![];
481483
let mut c3_credits: Vec<ConfidentialCredit> = vec![];
482-
let mut proofs: Vec<BalanceProof> = vec![];
484+
let mut proofs: Vec<PBBalanceProof> = vec![];
483485
for credit_balance_proof in batch_proof.credit_balance_proof {
484486
c1_credits.push(decode_credit!(
485487
_env,
@@ -531,7 +533,7 @@ pub extern "system" fn Java_com_webank_wedpr_vcl_NativeInterface_verifyProductBa
531533
result_jobject,
532534
credit_balance_proof.proof
533535
),
534-
BalanceProof
536+
PBBalanceProof
535537
));
536538
}
537539

protos/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ description = "Library of WeDPR protobuf definitions and their generated code."
1111
[dependencies]
1212
protobuf = "2.22.1"
1313
protoc-rust = "2.22.1"
14+
wedpr_l_utils = "1.1.0"
15+
wedpr_l_crypto_zkp_utils = {version = "1.3.0", git = "https://github.com/WeBankBlockchain/WeDPR-Lab-Crypto", branch = "dev-1.3.0"}

protos/crypto/ot.proto

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Copyright 2021 WeDPR Lab Project Authors. Licensed under Apache-2.0.
2+
3+
syntax = "proto3";
4+
5+
package com.webank.wedpr.crypto.proto;
6+
option java_package = "com.webank.wedpr.crypto.proto";
7+
option java_multiple_files = true;
8+
9+
// Receiver's secret to decrypt the chosen messages during k-out-of-n OT.
10+
message ReceiverSecretKOutOfN {
11+
bytes scalar_b = 2;
12+
}
13+
14+
// Receiver's commitment for the chosen messages during k-out-of-n OT.
15+
message ReceiverCommitmentKOutOfN {
16+
bytes point_x = 1;
17+
bytes point_y = 2;
18+
repeated bytes point_z = 3;
19+
}
20+
21+
// Sender's ciphertext item for a single encrypted message of k-out-of-n OT.
22+
message OtCiphertextItemKOutOfN {
23+
bytes fingerprint = 1;
24+
bytes key_basepoint = 2;
25+
repeated bytes encrypted_message = 3;
26+
}
27+
28+
// Sender's ciphertext collection of k-out-of-n OT.
29+
message OtCiphertextsKOutOfN {
30+
repeated OtCiphertextItemKOutOfN ciphertext = 1;
31+
}
32+
33+
// Pair of id and message bytes.
34+
message BytesToBytesPair {
35+
bytes id = 1;
36+
bytes message = 2;
37+
}
38+
39+
// Dict of id and message bytes.
40+
message DataDict {
41+
repeated BytesToBytesPair pair = 1;
42+
}
43+
44+
// List of ids.
45+
message IdList {
46+
repeated bytes id = 1;
47+
}

protos/crypto/zkp.proto

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright 2020 WeDPR Lab Project Authors. Licensed under Apache-2.0.
2+
3+
syntax = "proto3";
4+
5+
package com.webank.wedpr.crypto.proto;
6+
option java_package = "com.webank.wedpr.crypto.proto";
7+
option java_multiple_files = true;
8+
9+
// ZKP data to verify the balance relationship among value commitments.
10+
// For example, given C(x), C(y), C(z), this proof data can be used to
11+
// verify whether x * y =? z.
12+
message PBBalanceProof {
13+
bytes t1 = 1;
14+
bytes t2 = 2;
15+
bytes t3 = 3;
16+
bytes m1 = 4;
17+
bytes m2 = 5;
18+
bytes m3 = 6;
19+
bytes m4 = 7;
20+
bytes m5 = 8;
21+
bytes m6 = 9;
22+
bytes check1 = 10;
23+
bytes check2 = 11;
24+
}
25+
26+
// ZKP data to verify the equality relationship among value commitments.
27+
// For example, given C(x), C(y), this proof data can be used to
28+
// verify whether x =? y.
29+
message PBEqualityProof {
30+
bytes m1 = 1;
31+
bytes t1 = 2;
32+
bytes t2 = 3;
33+
}

protos/src/generated/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ pub mod acv;
44
pub mod hdk;
55
pub mod scd;
66
pub mod vcl;
7+
pub mod zkp;

0 commit comments

Comments
 (0)