Skip to content

Commit 8446753

Browse files
committed
add batch proofs
1 parent d43b406 commit 8446753

File tree

10 files changed

+847
-166
lines changed

10 files changed

+847
-166
lines changed

ffi/ffi_c/ffi_c_vcl/Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ crate-type = [ "cdylib", "staticlib" ]
1313
[dependencies]
1414
libc = "0.2.60"
1515
protobuf = "2.20.0"
16-
wedpr_s_verifiable_confidential_ledger = "1.3.0"
16+
wedpr_s_verifiable_confidential_ledger = { path = "../../../solution/verifiable_confidential_ledger"}
1717
wedpr_ffi_common = "1.0.0"
18-
wedpr_ffi_macros = "1.0.0"
19-
wedpr_s_protos = "1.3.0"
20-
wedpr_l_protos = "1.0.0"
18+
wedpr_ffi_macros = { path = "/Users/asher/WeDPR/WeDPR-Lab-Crypto/ffi/ffi_macros" }
19+
wedpr_s_protos = { path = "../../../protos"}
20+
wedpr_l_protos = { git = "https://github.com/WeBankBlockchain/WeDPR-Lab-Crypto.git", branch = "v1.1.0" }
2121
wedpr_l_macros = "1.0.0"
2222

2323
# This is required to generate C/C++ header files.

ffi/ffi_c/ffi_c_vcl/src/lib.rs

Lines changed: 149 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@ use wedpr_s_verifiable_confidential_ledger;
1818

1919
use wedpr_l_protos::generated::zkp::BalanceProof;
2020
use wedpr_s_protos::generated::vcl::{
21-
EncodedConfidentialCredit, EncodedOwnerSecret, VclResult,
21+
BatchProof, EncodedConfidentialCredit, EncodedOwnerSecret, VclResult,
2222
};
2323

2424
use libc::{c_char, c_ulong};
2525
use std::{ffi::CString, panic, ptr};
26+
use wedpr_s_verifiable_confidential_ledger::vcl::ConfidentialCredit;
2627

2728
// C/C++ FFI: C-style interfaces will be generated.
2829

@@ -73,8 +74,7 @@ pub extern "C" fn wedpr_vcl_prove_sum_balance(
7374
c1_secret_cstring: *mut c_char,
7475
c2_secret_cstring: *mut c_char,
7576
c3_secret_cstring: *mut c_char,
76-
) -> *mut c_char
77-
{
77+
) -> *mut c_char {
7878
let result = panic::catch_unwind(|| {
7979
let c1_secret = decode_secret!(c_safe_c_char_pointer_to_proto!(
8080
c1_secret_cstring,
@@ -105,8 +105,7 @@ pub extern "C" fn wedpr_vcl_verify_sum_balance(
105105
c2_credit_cstring: *mut c_char,
106106
c3_credit_cstring: *mut c_char,
107107
proof_cstring: *mut c_char,
108-
) -> i8
109-
{
108+
) -> i8 {
110109
let result = panic::catch_unwind(|| {
111110
let proof = c_safe_c_char_pointer_to_proto_with_error_value!(
112111
proof_cstring,
@@ -146,14 +145,84 @@ pub extern "C" fn wedpr_vcl_verify_sum_balance(
146145
c_safe_return_with_error_value!(result, FAILURE)
147146
}
148147

148+
/// C interface for 'wedpr_vcl_verify_batch_sum_balance'.
149+
#[no_mangle]
150+
pub extern "C" fn wedpr_vcl_verify_batch_sum_balance(
151+
batch_proof_cstring: *mut c_char,
152+
) -> i8 {
153+
let result = panic::catch_unwind(|| {
154+
let batch_proofs = c_safe_c_char_pointer_to_proto_with_error_value!(
155+
batch_proof_cstring,
156+
BatchProof,
157+
FAILURE
158+
);
159+
let mut c1_credits: Vec<ConfidentialCredit> = vec![];
160+
let mut c2_credits: Vec<ConfidentialCredit> = vec![];
161+
let mut c3_credits: Vec<ConfidentialCredit> = vec![];
162+
let mut proofs: Vec<BalanceProof> = vec![];
163+
164+
for c_credit in batch_proofs.c1_credit {
165+
let c_bytes =
166+
c_safe_string_to_bytes_with_error_value!(c_credit, FAILURE);
167+
let c_credit_encode = c_safe_bytes_to_proto_with_error_value!(
168+
c_bytes,
169+
EncodedConfidentialCredit,
170+
FAILURE
171+
);
172+
c1_credits.push(decode_credit!(c_credit_encode));
173+
}
174+
for c_credit in batch_proofs.c2_credit {
175+
let c_bytes =
176+
c_safe_string_to_bytes_with_error_value!(c_credit, FAILURE);
177+
let c_credit_encode = c_safe_bytes_to_proto_with_error_value!(
178+
c_bytes,
179+
EncodedConfidentialCredit,
180+
FAILURE
181+
);
182+
c2_credits.push(decode_credit!(c_credit_encode));
183+
}
184+
for c_credit in batch_proofs.c3_credit {
185+
let c_bytes =
186+
c_safe_string_to_bytes_with_error_value!(c_credit, FAILURE);
187+
let c_credit_encode = c_safe_bytes_to_proto_with_error_value!(
188+
c_bytes,
189+
EncodedConfidentialCredit,
190+
FAILURE
191+
);
192+
c3_credits.push(decode_credit!(c_credit_encode));
193+
}
194+
for proof in batch_proofs.proof {
195+
let bytes =
196+
c_safe_string_to_bytes_with_error_value!(proof, FAILURE);
197+
let encode = c_safe_bytes_to_proto_with_error_value!(
198+
bytes,
199+
BalanceProof,
200+
FAILURE
201+
);
202+
proofs.push(encode);
203+
}
204+
205+
let result = match wedpr_s_verifiable_confidential_ledger::vcl::verify_batch_sum_balance(
206+
&c1_credits, &c2_credits, &c3_credits, &proofs,
207+
) {
208+
Ok(v) => v,
209+
Err(_) => return FAILURE,
210+
};
211+
match result {
212+
true => SUCCESS,
213+
false => FAILURE,
214+
}
215+
});
216+
c_safe_return_with_error_value!(result, FAILURE)
217+
}
218+
149219
/// C interface for 'wedpr_vcl_prove_product_balance'.
150220
#[no_mangle]
151221
pub extern "C" fn wedpr_vcl_prove_product_balance(
152222
c1_secret_cstring: *mut c_char,
153223
c2_secret_cstring: *mut c_char,
154224
c3_secret_cstring: *mut c_char,
155-
) -> *mut c_char
156-
{
225+
) -> *mut c_char {
157226
let result = panic::catch_unwind(|| {
158227
let c1_secret = decode_secret!(c_safe_c_char_pointer_to_proto!(
159228
c1_secret_cstring,
@@ -184,8 +253,7 @@ pub extern "C" fn wedpr_vcl_verify_product_balance(
184253
c2_credit_cstring: *mut c_char,
185254
c3_credit_cstring: *mut c_char,
186255
proof_cstring: *mut c_char,
187-
) -> i8
188-
{
256+
) -> i8 {
189257
let result = panic::catch_unwind(|| {
190258
let proof = c_safe_c_char_pointer_to_proto_with_error_value!(
191259
proof_cstring,
@@ -225,6 +293,77 @@ pub extern "C" fn wedpr_vcl_verify_product_balance(
225293
c_safe_return_with_error_value!(result, FAILURE)
226294
}
227295

296+
/// C interface for 'wedpr_vcl_verify_batch_product_balance'.
297+
#[no_mangle]
298+
pub extern "C" fn wedpr_vcl_verify_batch_product_balance(
299+
batch_proof_cstring: *mut c_char,
300+
) -> i8 {
301+
let result = panic::catch_unwind(|| {
302+
let batch_proofs = c_safe_c_char_pointer_to_proto_with_error_value!(
303+
batch_proof_cstring,
304+
BatchProof,
305+
FAILURE
306+
);
307+
let mut c1_credits: Vec<ConfidentialCredit> = vec![];
308+
let mut c2_credits: Vec<ConfidentialCredit> = vec![];
309+
let mut c3_credits: Vec<ConfidentialCredit> = vec![];
310+
let mut proofs: Vec<BalanceProof> = vec![];
311+
312+
for c_credit in batch_proofs.c1_credit {
313+
let c_bytes =
314+
c_safe_string_to_bytes_with_error_value!(c_credit, FAILURE);
315+
let c_credit_encode = c_safe_bytes_to_proto_with_error_value!(
316+
c_bytes,
317+
EncodedConfidentialCredit,
318+
FAILURE
319+
);
320+
c1_credits.push(decode_credit!(c_credit_encode));
321+
}
322+
for c_credit in batch_proofs.c2_credit {
323+
let c_bytes =
324+
c_safe_string_to_bytes_with_error_value!(c_credit, FAILURE);
325+
let c_credit_encode = c_safe_bytes_to_proto_with_error_value!(
326+
c_bytes,
327+
EncodedConfidentialCredit,
328+
FAILURE
329+
);
330+
c2_credits.push(decode_credit!(c_credit_encode));
331+
}
332+
for c_credit in batch_proofs.c3_credit {
333+
let c_bytes =
334+
c_safe_string_to_bytes_with_error_value!(c_credit, FAILURE);
335+
let c_credit_encode = c_safe_bytes_to_proto_with_error_value!(
336+
c_bytes,
337+
EncodedConfidentialCredit,
338+
FAILURE
339+
);
340+
c3_credits.push(decode_credit!(c_credit_encode));
341+
}
342+
for proof in batch_proofs.proof {
343+
let bytes =
344+
c_safe_string_to_bytes_with_error_value!(proof, FAILURE);
345+
let encode = c_safe_bytes_to_proto_with_error_value!(
346+
bytes,
347+
BalanceProof,
348+
FAILURE
349+
);
350+
proofs.push(encode);
351+
}
352+
353+
let result = match wedpr_s_verifiable_confidential_ledger::vcl::verify_batch_product_balance(
354+
&c1_credits, &c2_credits, &c3_credits, &proofs,
355+
) {
356+
Ok(v) => v,
357+
Err(_) => return FAILURE,
358+
};
359+
match result {
360+
true => SUCCESS,
361+
false => FAILURE,
362+
}
363+
});
364+
c_safe_return_with_error_value!(result, FAILURE)
365+
}
366+
228367
/// C interface for 'wedpr_vcl_prove_range'.
229368
#[no_mangle]
230369
pub extern "C" fn wedpr_vcl_prove_range(
@@ -248,8 +387,7 @@ pub extern "C" fn wedpr_vcl_prove_range(
248387
pub extern "C" fn wedpr_vcl_verify_range(
249388
credit_cstring: *mut c_char,
250389
proof_cstring: *mut c_char,
251-
) -> i8
252-
{
390+
) -> i8 {
253391
let result = panic::catch_unwind(|| {
254392
let proof_str = c_safe_c_char_pointer_to_string_with_error_value!(
255393
proof_cstring,

ffi/ffi_java/ffi_java_vcl/Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ crate-type = [ "cdylib", "staticlib" ]
1313
[dependencies]
1414
jni = "0.13.0"
1515
protobuf = "2.20.0"
16-
wedpr_s_verifiable_confidential_ledger = "1.3.0"
16+
wedpr_s_verifiable_confidential_ledger = { path = "../../../solution/verifiable_confidential_ledger"}
1717
wedpr_ffi_common = "1.0.0"
18-
wedpr_ffi_macros = "1.0.0"
19-
wedpr_s_protos = "1.3.0"
20-
wedpr_l_protos = "1.0.0"
18+
wedpr_ffi_macros = { path = "/Users/asher/WeDPR/WeDPR-Lab-Crypto/ffi/ffi_macros" }
19+
wedpr_s_protos = { path = "../../../protos"}
20+
wedpr_l_protos = { git = "https://github.com/WeBankBlockchain/WeDPR-Lab-Crypto.git", branch = "v1.1.0" }
2121

2222
[build-dependencies]
2323
cbindgen = "0.9.0"

0 commit comments

Comments
 (0)