diff --git a/Cargo.toml b/Cargo.toml index d15399f..2840892 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,4 @@ [workspace] - members = [ "bounty", "ffi/ffi_c/ffi_c_ktb", @@ -8,6 +7,7 @@ members = [ "ffi/ffi_java/ffi_java_ktb", "ffi/ffi_java/ffi_java_scd", "ffi/ffi_java/ffi_java_vcl", + "ffi/ffi_java/ffi_java_acv", "protos", "solution/key_tool_box/hierarchical_deterministic_key", "solution/selective_certificate_disclosure", diff --git a/ffi/ffi_java/ffi_java_acv/Cargo.toml b/ffi/ffi_java/ffi_java_acv/Cargo.toml new file mode 100644 index 0000000..bc5d9a8 --- /dev/null +++ b/ffi/ffi_java/ffi_java_acv/Cargo.toml @@ -0,0 +1,27 @@ +[package] +name = "ffi_java_acv" +version = "1.5.0" +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[lib] +name = "ffi_java_acv" +crate-type = [ "cdylib", "staticlib" ] + +[dependencies] +jni = "0.13.0" +protobuf = "2.22.1" +wedpr_ffi_common = "1.1.0" +wedpr_ffi_macros = "1.1.0" + +wedpr_l_crypto_zkp_utils = {version = "1.3.0", git = "https://github.com/WeBankBlockchain/WeDPR-Lab-Crypto", branch = "dev-1.3.0"} +wedpr_s_protos = { path = "../../../protos" } +wedpr_s_anonymous_ciphertext_voting = { path = "../../../solution/anonymous_ciphertext_voting" } + +# This is required to generate C/C++ header files. +[build-dependencies] +cbindgen = "0.9.0" + +[target.'cfg(target_os = "android")'.dependencies] +jni = { version = "0.13.1", default-features = false } diff --git a/ffi/ffi_java/ffi_java_acv/src/coordinator.rs b/ffi/ffi_java/ffi_java_acv/src/coordinator.rs new file mode 100644 index 0000000..d6d788b --- /dev/null +++ b/ffi/ffi_java/ffi_java_acv/src/coordinator.rs @@ -0,0 +1,494 @@ +// Copyright 2022 WeDPR Lab Project Authors. Licensed under Apache-2.0. + +//! Library of macros and functions for FFI of ACV solution, targeting +//! Java-compatible architectures (including Android). +use jni::{ + objects::{JClass, JObject, JString, JValue}, + sys::{jint, jlong, jobject}, + JNIEnv, +}; + +use protobuf::{self, Message}; +use wedpr_ffi_common::utils::{ + bytes_to_string, java_jstring_to_bytes, java_new_jobject, + java_set_error_field_and_extract_jobject, +}; + +use wedpr_s_anonymous_ciphertext_voting; +use wedpr_s_protos::generated::acv::{ + CandidateList, CounterParametersStorage, DecryptedResultPartStorage, + PollParametersStorage, RegistrationRequest, VoteStorage, +}; + +// Java FFI: Java interfaces will be generated under +// package name 'com.webank.wedpr.acv'. + +// Result class name is 'com.webank.wedpr.acv.CoordinatorResult'. +const RESULT_JAVA_CLASS_NAME: &str = "com/webank/wedpr/acv/CoordinatorResult"; +fn get_result_jobject<'a>(_env: &'a JNIEnv) -> JObject<'a> { + java_new_jobject(_env, RESULT_JAVA_CLASS_NAME) +} + +// Java interface section. +// All functions are under class name 'com.webank.wedpr.acv.NativeInterface'. +/// Java interface for +/// 'com.webank.wedpr.acv.NativeInterface->makePollParameters'. +#[no_mangle] +pub extern "system" fn Java_com_webank_wedpr_acv_NativeInterface_makePollParameters( + _env: JNIEnv, + _class: JClass, + candidate_list: JString, + counter_parameters: JString, +) -> jobject { + // get the result object + let result_jobject = get_result_jobject(&_env); + let pb_candidate_list = java_safe_jstring_to_pb!( + _env, + result_jobject, + candidate_list, + CandidateList + ); + let pb_counter_parameters = java_safe_jstring_to_pb!( + _env, + result_jobject, + counter_parameters, + CounterParametersStorage + ); + let poll_parameters = + match wedpr_s_anonymous_ciphertext_voting::coordinator::make_poll_parameters( + &pb_candidate_list, + &pb_counter_parameters, + ) { + Ok(v) => v, + Err(e) => { + return java_set_error_field_and_extract_jobject( + &_env, + &result_jobject, + &format!("make_poll_parameters failed, err = {:?}", e), + ) + }, + }; + java_safe_set_encoded_pb_field!( + _env, + result_jobject, + poll_parameters, + "poll_parameters" + ); + result_jobject.into_inner() +} + +/// Java interface for 'com.webank.wedpr.acv.NativeInterface->certifyVoter'. +#[no_mangle] +pub extern "system" fn Java_com_webank_wedpr_acv_NativeInterface_certifyVoter( + _env: JNIEnv, + _class: JClass, + secret_key_data: JString, + registration_request: JString, + voter_weight: jint, +) -> jobject { + let result_jobject = get_result_jobject(&_env); + let certify_result = + match wedpr_s_anonymous_ciphertext_voting::coordinator::certify_voter( + &java_safe_jstring_to_bytes!(_env, result_jobject, secret_key_data), + &java_safe_jstring_to_pb!( + _env, + result_jobject, + registration_request, + RegistrationRequest + ), + voter_weight as u32, + ) { + Ok(v) => v, + Err(e) => { + return java_set_error_field_and_extract_jobject( + &_env, + &result_jobject, + &format!("certifyVoter failed, err = {:?}", e), + ) + }, + }; + java_safe_set_encoded_pb_field!( + _env, + result_jobject, + certify_result, + "registration_response" + ); + result_jobject.into_inner() +} + +/// Java interface for +/// 'com.webank.wedpr.acv.NativeInterface->certifyUnboundedVoter'. +#[no_mangle] +pub extern "system" fn Java_com_webank_wedpr_acv_NativeInterface_certifyUnboundedVoter( + _env: JNIEnv, + _class: JClass, + secret_key_data: JString, + registration_request: JString, + voter_weight: jint, +) -> jobject { + let result_jobject = get_result_jobject(&_env); + let certify_result = + match wedpr_s_anonymous_ciphertext_voting::coordinator::certify_unbounded_voter( + &java_safe_jstring_to_bytes!(_env, result_jobject, secret_key_data), + &java_safe_jstring_to_pb!( + _env, + result_jobject, + registration_request, + RegistrationRequest + ), + voter_weight as u32, + ) { + Ok(v) => v, + Err(e) => { + return java_set_error_field_and_extract_jobject( + &_env, + &result_jobject, + &format!("certifyUnboundedVoter failed, err = {:?}", e), + ) + }, + }; + java_safe_set_encoded_pb_field!( + _env, + result_jobject, + certify_result, + "registration_response" + ); + result_jobject.into_inner() +} + +/// Java interface for +/// 'com.webank.wedpr.acv.NativeInterface->aggregateVoteSumResponse'. +#[no_mangle] +pub extern "system" fn Java_com_webank_wedpr_acv_NativeInterface_aggregateVoteSumResponse( + _env: JNIEnv, + _class: JClass, + poll_parameters: JString, + vote_part: JString, + vote_sum: JString, +) -> jobject { + let result_jobject = get_result_jobject(&_env); + let pb_poll_parameters = java_safe_jstring_to_pb!( + _env, + result_jobject, + poll_parameters, + PollParametersStorage + ); + let pb_vote_part = + java_safe_jstring_to_pb!(_env, result_jobject, vote_part, VoteStorage); + let mut pb_vote_sum = + java_safe_jstring_to_pb!(_env, result_jobject, vote_sum, VoteStorage); + // aggregate_vote_sum_response + let ret = + match wedpr_s_anonymous_ciphertext_voting::coordinator::aggregate_vote_sum_response( + &pb_poll_parameters, + &pb_vote_part, + &mut pb_vote_sum, + ) { + Ok(v) => v, + Err(e) => { + return java_set_error_field_and_extract_jobject( + &_env, + &result_jobject, + &format!("aggregateVoteSumResponse failed, err = {:?}", e), + ) + }, + }; + if !ret { + return java_set_error_field_and_extract_jobject( + &_env, + &result_jobject, + &format!("aggregateVoteSumResponse failed"), + ); + } + // write back pb_vote_sum + java_safe_set_encoded_pb_field!( + _env, + result_jobject, + pb_vote_sum, + "vote_sum" + ); + result_jobject.into_inner() +} + +/// Java interface for +/// 'com.webank.wedpr.acv.NativeInterface->aggregateVoteSumResponseUnlisted'. +#[no_mangle] +pub extern "system" fn Java_com_webank_wedpr_acv_NativeInterface_aggregateVoteSumResponseUnlisted( + _env: JNIEnv, + _class: JClass, + poll_parameters: JString, + vote_part: JString, + vote_sum: JString, +) -> jobject { + let result_jobject = get_result_jobject(&_env); + let pb_poll_parameters = java_safe_jstring_to_pb!( + _env, + result_jobject, + poll_parameters, + PollParametersStorage + ); + let pb_vote_part = + java_safe_jstring_to_pb!(_env, result_jobject, vote_part, VoteStorage); + let mut pb_vote_sum = + java_safe_jstring_to_pb!(_env, result_jobject, vote_sum, VoteStorage); + // aggregate_vote_sum_response + let ret = match wedpr_s_anonymous_ciphertext_voting::coordinator::aggregate_vote_sum_response_unlisted( + &pb_poll_parameters, + &pb_vote_part, + &mut pb_vote_sum, + ) { + Ok(v) => v, + Err(e) => { + return java_set_error_field_and_extract_jobject( + &_env, + &result_jobject, + &format!("aggregateVoteSumResponse failed, err = {:?}", e), + ) + }, + }; + if !ret { + return java_set_error_field_and_extract_jobject( + &_env, + &result_jobject, + &format!("aggregateVoteSumResponse failed"), + ); + } + // write back pb_vote_sum + java_safe_set_encoded_pb_field!( + _env, + result_jobject, + pb_vote_sum, + "vote_sum" + ); + result_jobject.into_inner() +} + +/// Java interface for +/// 'com.webank.wedpr.acv.NativeInterface->aggregateDecryptedPartSum'. +#[no_mangle] +pub extern "system" fn Java_com_webank_wedpr_acv_NativeInterface_aggregateDecryptedPartSum( + _env: JNIEnv, + _class: JClass, + poll_parameters: JString, + partially_decrypted_result: JString, + aggregated_decrypted_result: JString, +) -> jobject { + let result_jobject = get_result_jobject(&_env); + let pb_poll_parameters = java_safe_jstring_to_pb!( + _env, + result_jobject, + poll_parameters, + PollParametersStorage + ); + let pb_partially_decrypted_result = java_safe_jstring_to_pb!( + _env, + result_jobject, + partially_decrypted_result, + DecryptedResultPartStorage + ); + let mut pb_aggregated_decrypted_result = java_safe_jstring_to_pb!( + _env, + result_jobject, + aggregated_decrypted_result, + DecryptedResultPartStorage + ); + let result = + match wedpr_s_anonymous_ciphertext_voting::coordinator::aggregate_decrypted_part_sum( + &pb_poll_parameters, + &pb_partially_decrypted_result, + &mut pb_aggregated_decrypted_result, + ) { + Ok(v) => v, + Err(e) => { + return java_set_error_field_and_extract_jobject( + &_env, + &result_jobject, + &format!("aggregateDecryptedPartSum failed, err = {:?}", e), + ) + }, + }; + if !result { + return java_set_error_field_and_extract_jobject( + &_env, + &result_jobject, + &format!("aggregateDecryptedPartSum failed"), + ); + } + // write back pb_aggregated_decrypted_result + java_safe_set_encoded_pb_field!( + _env, + result_jobject, + pb_aggregated_decrypted_result, + "aggregated_decrypted_result" + ); + result_jobject.into_inner() +} + +/// Java interface for +/// 'com.webank.wedpr.acv.NativeInterface->aggregateDecryptedPartSumUnlisted'. +#[no_mangle] +pub extern "system" fn Java_com_webank_wedpr_acv_NativeInterface_aggregateDecryptedPartSumUnlisted( + _env: JNIEnv, + _class: JClass, + poll_parameters: JString, + partially_decrypted_result: JString, + aggregated_decrypted_result: JString, +) -> jobject { + let result_jobject = get_result_jobject(&_env); + let pb_poll_parameters = java_safe_jstring_to_pb!( + _env, + result_jobject, + poll_parameters, + PollParametersStorage + ); + let pb_partially_decrypted_result = java_safe_jstring_to_pb!( + _env, + result_jobject, + partially_decrypted_result, + DecryptedResultPartStorage + ); + let mut pb_aggregated_decrypted_result = java_safe_jstring_to_pb!( + _env, + result_jobject, + aggregated_decrypted_result, + DecryptedResultPartStorage + ); + let result = match wedpr_s_anonymous_ciphertext_voting::coordinator::aggregate_decrypted_part_sum_unlisted( + &pb_poll_parameters, + &pb_partially_decrypted_result, + &mut pb_aggregated_decrypted_result, + ) { + Ok(v) => v, + Err(e) => { + return java_set_error_field_and_extract_jobject( + &_env, + &result_jobject, + &format!( + "aggregateDecryptedPartSumUnlisted failed, err = {:?}", + e + ), + ) + }, + }; + if !result { + return java_set_error_field_and_extract_jobject( + &_env, + &result_jobject, + &format!("aggregateDecryptedPartSumUnlisted failed"), + ); + } + // write back pb_aggregated_decrypted_result + java_safe_set_encoded_pb_field!( + _env, + result_jobject, + pb_aggregated_decrypted_result, + "aggregated_decrypted_result" + ); + result_jobject.into_inner() +} + +/// Java interface for +/// 'com.webank.wedpr.acv.NativeInterface->finalizeVoteResult'. +#[no_mangle] +pub extern "system" fn Java_com_webank_wedpr_acv_NativeInterface_finalizeVoteResult( + _env: JNIEnv, + _class: JClass, + poll_parameters: JString, + vote_sum: JString, + aggregated_decrypted_result: JString, + max_vote_limit: jlong, +) -> jobject { + let result_jobject = get_result_jobject(&_env); + let pb_poll_parameters = java_safe_jstring_to_pb!( + _env, + result_jobject, + poll_parameters, + PollParametersStorage + ); + let pb_vote_sum = + java_safe_jstring_to_pb!(_env, result_jobject, vote_sum, VoteStorage); + let pb_aggregated_decrypted_result = java_safe_jstring_to_pb!( + _env, + result_jobject, + aggregated_decrypted_result, + DecryptedResultPartStorage + ); + let vote_result = + match wedpr_s_anonymous_ciphertext_voting::coordinator::finalize_vote_result( + &pb_poll_parameters, + &pb_vote_sum, + &pb_aggregated_decrypted_result, + max_vote_limit as i64 + ) { + Ok(v) => v, + Err(e) => { + return java_set_error_field_and_extract_jobject( + &_env, + &result_jobject, + &format!("finalizeVoteResult failed, err = {:?}", e), + ) + }, + }; + // write vote_result + java_safe_set_encoded_pb_field!( + _env, + result_jobject, + vote_result, + "vote_result" + ); + result_jobject.into_inner() +} + +/// Java interface for +/// 'com.webank.wedpr.acv.NativeInterface->finalizeVoteResultUnlisted'. +#[no_mangle] +pub extern "system" fn Java_com_webank_wedpr_acv_NativeInterface_finalizeVoteResultUnlisted( + _env: JNIEnv, + _class: JClass, + poll_parameters: JString, + vote_sum: JString, + aggregated_decrypted_result: JString, + max_vote_limit: jlong, + max_candidate_num: jlong, +) -> jobject { + let result_jobject = get_result_jobject(&_env); + let pb_poll_parameters = java_safe_jstring_to_pb!( + _env, + result_jobject, + poll_parameters, + PollParametersStorage + ); + let pb_vote_sum = + java_safe_jstring_to_pb!(_env, result_jobject, vote_sum, VoteStorage); + let mut pb_aggregated_decrypted_result = java_safe_jstring_to_pb!( + _env, + result_jobject, + aggregated_decrypted_result, + DecryptedResultPartStorage + ); + let vote_result = + match wedpr_s_anonymous_ciphertext_voting::coordinator::finalize_vote_result_unlisted( + &pb_poll_parameters, + &pb_vote_sum, + &mut pb_aggregated_decrypted_result, + max_vote_limit as i64, + max_candidate_num as i64, + ) { + Ok(v) => v, + Err(e) => { + return java_set_error_field_and_extract_jobject( + &_env, + &result_jobject, + &format!("finalizeVoteResult failed, err = {:?}", e), + ) + }, + }; + // write vote_result + java_safe_set_encoded_pb_field!( + _env, + result_jobject, + vote_result, + "vote_result" + ); + result_jobject.into_inner() +} diff --git a/ffi/ffi_java/ffi_java_acv/src/counter.rs b/ffi/ffi_java/ffi_java_acv/src/counter.rs new file mode 100644 index 0000000..6316d7a --- /dev/null +++ b/ffi/ffi_java/ffi_java_acv/src/counter.rs @@ -0,0 +1,187 @@ +// Copyright 2022 WeDPR Lab Project Authors. Licensed under Apache-2.0. + +//! Library of macros and functions for FFI of ACV solution, targeting +//! Java-compatible architectures (including Android). +use jni::{ + objects::{JClass, JObject, JString, JValue}, + sys::jobject, + JNIEnv, +}; + +use protobuf::{self, Message}; +use wedpr_ffi_common::utils::{ + bytes_to_string, java_jstring_to_bytes, java_jstring_to_string, + java_new_jobject, java_set_error_field_and_extract_jobject, +}; + +use wedpr_s_anonymous_ciphertext_voting; + +use wedpr_s_protos::generated::acv::{CounterSecret, VoteStorage}; + +// Java FFI: Java interfaces will be generated under +// package name 'com.webank.wedpr.acv'. + +// Result class name is 'com.webank.wedpr.acv.CoordinatorResult'. +const RESULT_JAVA_CLASS_NAME: &str = "com/webank/wedpr/acv/CounterResult"; +fn get_result_jobject<'a>(_env: &'a JNIEnv) -> JObject<'a> { + java_new_jobject(_env, RESULT_JAVA_CLASS_NAME) +} + +// Java interface section. +// All functions are under class name 'com.webank.wedpr.acv.NativeInterface'. +/// Java interface for +/// 'com.webank.wedpr.acv.NativeInterface->makeCounterSecret'. +#[no_mangle] +pub extern "system" fn Java_com_webank_wedpr_acv_NativeInterface_makeCounterSecret( + _env: JNIEnv, + _class: JClass, +) -> jobject { + let result_jobject = get_result_jobject(&_env); + let secret = + wedpr_s_anonymous_ciphertext_voting::counter::make_counter_secret(); + // write the secret + java_safe_set_encoded_pb_field!( + _env, + result_jobject, + secret, + "counter_secret" + ); + result_jobject.into_inner() +} + +/// Java interface for +/// 'com.webank.wedpr.acv.NativeInterface->makeCounterParametersShare'. +#[no_mangle] +pub extern "system" fn Java_com_webank_wedpr_acv_NativeInterface_makeCounterParametersShare( + _env: JNIEnv, + _class: JClass, + counter_id_str: JString, + counter_secret: JString, +) -> jobject { + let result_jobject = get_result_jobject(&_env); + let counter_id = + java_safe_jstring_to_string!(_env, result_jobject, counter_id_str); + let pb_counter_secret = java_safe_jstring_to_pb!( + _env, + result_jobject, + counter_secret, + CounterSecret + ); + let counter_parameters_share = match wedpr_s_anonymous_ciphertext_voting::counter::make_parameters_share(&counter_id, &pb_counter_secret) + { + Ok(v) => v, + Err(e)=>{ + return java_set_error_field_and_extract_jobject( + &_env, + &result_jobject, + &format!("makeCounterParametersShare failed, err = {:?}", e), + ) + }, + }; + // write the counter_parameters_share + java_safe_set_encoded_pb_field!( + _env, + result_jobject, + counter_parameters_share, + "counter_parameters_share" + ); + result_jobject.into_inner() +} + +/// Java interface for 'com.webank.wedpr.acv.NativeInterface->count'. +#[no_mangle] +pub extern "system" fn Java_com_webank_wedpr_acv_NativeInterface_count( + _env: JNIEnv, + _class: JClass, + counter_id_str: JString, + counter_secret: JString, + encrypted_vote_sum: JString, +) -> jobject { + let result_jobject = get_result_jobject(&_env); + let counter_id = + java_safe_jstring_to_string!(_env, result_jobject, counter_id_str); + let pb_counter_secret = java_safe_jstring_to_pb!( + _env, + result_jobject, + counter_secret, + CounterSecret + ); + let pb_encrypted_vote_sum = java_safe_jstring_to_pb!( + _env, + result_jobject, + encrypted_vote_sum, + VoteStorage + ); + let decrypted_result_part = + match wedpr_s_anonymous_ciphertext_voting::counter::count( + &counter_id, + &pb_counter_secret, + &pb_encrypted_vote_sum, + ) { + Ok(v) => v, + Err(e) => { + return java_set_error_field_and_extract_jobject( + &_env, + &result_jobject, + &format!("count failed, err = {:?}", e), + ) + }, + }; + // write the decrypted_result_part + java_safe_set_encoded_pb_field!( + _env, + result_jobject, + decrypted_result_part, + "counter_decrypted_result" + ); + result_jobject.into_inner() +} + +/// Java interface for 'com.webank.wedpr.acv.NativeInterface->countUnlisted'. +#[no_mangle] +pub extern "system" fn Java_com_webank_wedpr_acv_NativeInterface_countUnlisted( + _env: JNIEnv, + _class: JClass, + counter_id_str: JString, + counter_secret: JString, + encrypted_vote_sum: JString, +) -> jobject { + let result_jobject = get_result_jobject(&_env); + let counter_id = + java_safe_jstring_to_string!(_env, result_jobject, counter_id_str); + let pb_counter_secret = java_safe_jstring_to_pb!( + _env, + result_jobject, + counter_secret, + CounterSecret + ); + let pb_encrypted_vote_sum = java_safe_jstring_to_pb!( + _env, + result_jobject, + encrypted_vote_sum, + VoteStorage + ); + let decrypted_result_part = + match wedpr_s_anonymous_ciphertext_voting::counter::count_unlisted( + &counter_id, + &pb_counter_secret, + &pb_encrypted_vote_sum, + ) { + Ok(v) => v, + Err(e) => { + return java_set_error_field_and_extract_jobject( + &_env, + &result_jobject, + &format!("countUnlisted failed, err = {:?}", e), + ) + }, + }; + // write the decrypted_result_part + java_safe_set_encoded_pb_field!( + _env, + result_jobject, + decrypted_result_part, + "counter_decrypted_result" + ); + result_jobject.into_inner() +} diff --git a/ffi/ffi_java/ffi_java_acv/src/lib.rs b/ffi/ffi_java/ffi_java_acv/src/lib.rs new file mode 100644 index 0000000..23d9aa5 --- /dev/null +++ b/ffi/ffi_java/ffi_java_acv/src/lib.rs @@ -0,0 +1,14 @@ +// Copyright 2022 WeDPR Lab Project Authors. Licensed under Apache-2.0. + +//! Library of macros and functions for FFI of ACV solution, targeting +//! Java-compatible architectures (including Android). + +extern crate jni; + +#[macro_use] +extern crate wedpr_ffi_macros; + +pub mod coordinator; +pub mod counter; +pub mod verifier; +pub mod voter; diff --git a/ffi/ffi_java/ffi_java_acv/src/verifier.rs b/ffi/ffi_java/ffi_java_acv/src/verifier.rs new file mode 100644 index 0000000..827b61b --- /dev/null +++ b/ffi/ffi_java/ffi_java_acv/src/verifier.rs @@ -0,0 +1,368 @@ +// Copyright 2022 WeDPR Lab Project Authors. Licensed under Apache-2.0. + +//! Library of macros and functions for FFI of ACV solution, targeting +//! Java-compatible architectures (including Android). +use jni::{ + objects::{JClass, JObject, JString, JValue}, + sys::jobject, + JNIEnv, +}; + +use protobuf::{self, Message}; +use wedpr_ffi_common::utils::{ + java_jstring_to_bytes, java_new_jobject, + java_set_error_field_and_extract_jobject, +}; + +use wedpr_l_crypto_zkp_utils::bytes_to_point; + +use wedpr_s_anonymous_ciphertext_voting; + +use wedpr_s_protos::generated::acv::{ + DecryptedResultPartStorage, PollParametersStorage, VoteRequest, + VoteResultStorage, VoteStorage, +}; + +// Java FFI: Java interfaces will be generated under +// package name 'com.webank.wedpr.acv'. + +// Result class name is 'com.webank.wedpr.acv.CoordinatorResult'. +const RESULT_JAVA_CLASS_NAME: &str = "com/webank/wedpr/acv/VerifierResult"; +fn get_result_jobject<'a>(_env: &'a JNIEnv) -> JObject<'a> { + java_new_jobject(_env, RESULT_JAVA_CLASS_NAME) +} + +// Java interface section. +// All functions are under class name 'com.webank.wedpr.acv.NativeInterface'. +/// Java interface for +/// 'com.webank.wedpr.acv.NativeInterface->verifyVoteRequest'. +#[no_mangle] +pub extern "system" fn Java_com_webank_wedpr_acv_NativeInterface_verifyVoteRequest( + _env: JNIEnv, + _class: JClass, + poll_parameters: JString, + vote_request: JString, + public_key_str: JString, +) -> jobject { + let result_jobject = get_result_jobject(&_env); + let pb_poll_parameters = java_safe_jstring_to_pb!( + _env, + result_jobject, + poll_parameters, + PollParametersStorage + ); + let pb_vote_request = java_safe_jstring_to_pb!( + _env, + result_jobject, + vote_request, + VoteRequest + ); + let public_key = + java_safe_jstring_to_bytes!(_env, result_jobject, public_key_str); + let verify_result = + match wedpr_s_anonymous_ciphertext_voting::verifier::verify_vote_request( + &pb_poll_parameters, + &pb_vote_request, + &public_key, + ) { + Ok(v) => v, + Err(e) => { + return java_set_error_field_and_extract_jobject( + &_env, + &result_jobject, + &format!("verifyVoteRequest failed, err = {:?}", e), + ) + }, + }; + java_safe_set_boolean_field!( + _env, + result_jobject, + verify_result, + "verifyResult" + ); + result_jobject.into_inner() +} + +/// Java interface for +/// 'com.webank.wedpr.acv.NativeInterface->verifyUnboundedVoteRequest'. +#[no_mangle] +pub extern "system" fn Java_com_webank_wedpr_acv_NativeInterface_verifyUnboundedVoteRequest( + _env: JNIEnv, + _class: JClass, + poll_parameters: JString, + vote_request: JString, + public_key_str: JString, +) -> jobject { + let result_jobject = get_result_jobject(&_env); + let pb_poll_parameters = java_safe_jstring_to_pb!( + _env, + result_jobject, + poll_parameters, + PollParametersStorage + ); + let pb_vote_request = java_safe_jstring_to_pb!( + _env, + result_jobject, + vote_request, + VoteRequest + ); + let public_key = + java_safe_jstring_to_bytes!(_env, result_jobject, public_key_str); + let verify_result = match wedpr_s_anonymous_ciphertext_voting::verifier::verify_unbounded_vote_request(&pb_poll_parameters, + &pb_vote_request, &public_key) + { + Ok(v) => v, + Err(e)=>{ + return java_set_error_field_and_extract_jobject( + &_env, + &result_jobject, + &format!("verifyUnboundedVoteRequest failed, err = {:?}", e), + ) + }, + }; + java_safe_set_boolean_field!( + _env, + result_jobject, + verify_result, + "verifyResult" + ); + result_jobject.into_inner() +} + +/// Java interface for +/// 'com.webank.wedpr.acv.NativeInterface->verifyUnboundedVoteRequestUnlisted'. +#[no_mangle] +pub extern "system" fn Java_com_webank_wedpr_acv_NativeInterface_verifyUnboundedVoteRequestUnlisted( + _env: JNIEnv, + _class: JClass, + poll_parameters: JString, + vote_request: JString, + public_key_str: JString, +) -> jobject { + let result_jobject = get_result_jobject(&_env); + let pb_poll_parameters = java_safe_jstring_to_pb!( + _env, + result_jobject, + poll_parameters, + PollParametersStorage + ); + let pb_vote_request = java_safe_jstring_to_pb!( + _env, + result_jobject, + vote_request, + VoteRequest + ); + let public_key = + java_safe_jstring_to_bytes!(_env, result_jobject, public_key_str); + let verify_result = match wedpr_s_anonymous_ciphertext_voting::verifier::verify_unbounded_vote_request(&pb_poll_parameters, + &pb_vote_request, &public_key) + { + Ok(v) => v, + Err(e)=>{ + return java_set_error_field_and_extract_jobject( + &_env, + &result_jobject, + &format!("verifyUnboundedVoteRequestUnlisted failed, err = {:?}", e), + ) + }, + }; + java_safe_set_boolean_field!( + _env, + result_jobject, + verify_result, + "verifyResult" + ); + result_jobject.into_inner() +} + +/// Java interface for +/// 'com.webank.wedpr.acv.NativeInterface->verifyCountRequest'. +#[no_mangle] +pub extern "system" fn Java_com_webank_wedpr_acv_NativeInterface_verifyCountRequest( + _env: JNIEnv, + _class: JClass, + poll_parameters: JString, + encrypted_vote_sum: JString, + counter_share: JString, + partially_decrypted_result: JString, +) -> jobject { + let result_jobject = get_result_jobject(&_env); + let pb_poll_parameters = java_safe_jstring_to_pb!( + _env, + result_jobject, + poll_parameters, + PollParametersStorage + ); + let pb_encrypted_vote_sum = java_safe_jstring_to_pb!( + _env, + result_jobject, + encrypted_vote_sum, + VoteStorage + ); + let pb_partially_decrypted_result = java_safe_jstring_to_pb!( + _env, + result_jobject, + partially_decrypted_result, + DecryptedResultPartStorage + ); + let counter_share_bytes = + java_safe_jstring_to_bytes!(_env, result_jobject, counter_share); + let counter_share_point = + match bytes_to_point(&counter_share_bytes.to_vec()) { + Ok(v) => v, + Err(e) => { + return java_set_error_field_and_extract_jobject( + &_env, + &result_jobject, + &format!( + "verifyCountRequestUnlisted failed for covert \ + counter_share error, err = {:?}", + e + ), + ) + }, + }; + let verify_result = match wedpr_s_anonymous_ciphertext_voting::verifier::verify_count_request(&pb_poll_parameters, + &pb_encrypted_vote_sum, &counter_share_point, &pb_partially_decrypted_result) + { + Ok(v) => v, + Err(e)=>{ + return java_set_error_field_and_extract_jobject( + &_env, + &result_jobject, + &format!("verifyCountRequest failed, err = {:?}", e), + ) + }, + }; + java_safe_set_boolean_field!( + _env, + result_jobject, + verify_result, + "verifyResult" + ); + result_jobject.into_inner() +} + +/// Java interface for +/// 'com.webank.wedpr.acv.NativeInterface->verifyCountRequestUnlisted'. +#[no_mangle] +pub extern "system" fn Java_com_webank_wedpr_acv_NativeInterface_verifyCountRequestUnlisted( + _env: JNIEnv, + _class: JClass, + poll_parameters: JString, + encrypted_vote_sum: JString, + counter_share: JString, + partially_decrypted_result: JString, +) -> jobject { + let result_jobject = get_result_jobject(&_env); + let pb_poll_parameters = java_safe_jstring_to_pb!( + _env, + result_jobject, + poll_parameters, + PollParametersStorage + ); + let pb_encrypted_vote_sum = java_safe_jstring_to_pb!( + _env, + result_jobject, + encrypted_vote_sum, + VoteStorage + ); + let pb_partially_decrypted_result = java_safe_jstring_to_pb!( + _env, + result_jobject, + partially_decrypted_result, + DecryptedResultPartStorage + ); + let counter_share_bytes = + java_safe_jstring_to_bytes!(_env, result_jobject, counter_share); + let counter_share_point = + match bytes_to_point(&counter_share_bytes.to_vec()) { + Ok(v) => v, + Err(e) => { + return java_set_error_field_and_extract_jobject( + &_env, + &result_jobject, + &format!( + "verifyCountRequestUnlisted failed for covert \ + counter_share error, err = {:?}", + e + ), + ) + }, + }; + let verify_result = match wedpr_s_anonymous_ciphertext_voting::verifier::verify_count_request_unlisted(&pb_poll_parameters, + &counter_share_point, &pb_encrypted_vote_sum, &pb_partially_decrypted_result) + { + Ok(v) => v, + Err(e)=>{ + return java_set_error_field_and_extract_jobject( + &_env, + &result_jobject, + &format!("verifyCountRequestUnlisted failed, err = {:?}", e), + ) + }, + }; + java_safe_set_boolean_field!( + _env, + result_jobject, + verify_result, + "verifyResult" + ); + result_jobject.into_inner() +} + +/// Java interface for 'com.webank.wedpr.acv.NativeInterface->verifyVoteResult'. +#[no_mangle] +pub extern "system" fn Java_com_webank_wedpr_acv_NativeInterface_verifyVoteResult( + _env: JNIEnv, + _class: JClass, + poll_parameters: JString, + vote_sum: JString, + aggregated_decrypted_result: JString, + vote_result: JString, +) -> jobject { + let result_jobject = get_result_jobject(&_env); + let pb_poll_parameters = java_safe_jstring_to_pb!( + _env, + result_jobject, + poll_parameters, + PollParametersStorage + ); + let pb_vote_sum = + java_safe_jstring_to_pb!(_env, result_jobject, vote_sum, VoteStorage); + let pb_aggregated_decrypted_result = java_safe_jstring_to_pb!( + _env, + result_jobject, + aggregated_decrypted_result, + DecryptedResultPartStorage + ); + let pb_vote_result = java_safe_jstring_to_pb!( + _env, + result_jobject, + vote_result, + VoteResultStorage + ); + let verify_result = + match wedpr_s_anonymous_ciphertext_voting::verifier::verify_vote_result( + &pb_poll_parameters, + &pb_vote_sum, + &pb_aggregated_decrypted_result, + &pb_vote_result, + ) { + Ok(v) => v, + Err(e) => { + return java_set_error_field_and_extract_jobject( + &_env, + &result_jobject, + &format!("verifyVoteResult failed, err = {:?}", e), + ) + }, + }; + java_safe_set_boolean_field!( + _env, + result_jobject, + verify_result, + "verifyResult" + ); + result_jobject.into_inner() +} diff --git a/ffi/ffi_java/ffi_java_acv/src/voter.rs b/ffi/ffi_java/ffi_java_acv/src/voter.rs new file mode 100644 index 0000000..dfe1255 --- /dev/null +++ b/ffi/ffi_java/ffi_java_acv/src/voter.rs @@ -0,0 +1,347 @@ +// Copyright 2022 WeDPR Lab Project Authors. Licensed under Apache-2.0. + +//! Library of macros and functions for FFI of ACV solution, targeting +//! Java-compatible architectures (including Android). +use jni::{ + objects::{JClass, JObject, JString, JValue}, + sys::jobject, + JNIEnv, +}; + +use protobuf::{self, Message}; +use wedpr_ffi_common::utils::{ + bytes_to_string, java_jstring_to_bytes, java_new_jobject, + java_set_error_field_and_extract_jobject, +}; + +use wedpr_s_anonymous_ciphertext_voting; + +use wedpr_s_protos::generated::acv::{ + PollParametersStorage, RegistrationResponse, VoteChoices, VoterSecret, +}; + +// Java FFI: Java interfaces will be generated under +// package name 'com.webank.wedpr.acv'. + +// Result class name is 'com.webank.wedpr.acv.CoordinatorResult'. +const RESULT_JAVA_CLASS_NAME: &str = "com/webank/wedpr/acv/VoterResult"; +fn get_result_jobject<'a>(_env: &'a JNIEnv) -> JObject<'a> { + java_new_jobject(_env, RESULT_JAVA_CLASS_NAME) +} + +// Java interface section. +// All functions are under class name 'com.webank.wedpr.acv.NativeInterface'. +/// Java interface for 'com.webank.wedpr.acv.NativeInterface->makeVoterSecret'. +#[no_mangle] +pub extern "system" fn Java_com_webank_wedpr_acv_NativeInterface_makeVoterSecret( + _env: JNIEnv, + _class: JClass, +) -> jobject { + let result_jobject = get_result_jobject(&_env); + let secret = + wedpr_s_anonymous_ciphertext_voting::voter::make_voter_secret(); + // write the secret + java_safe_set_encoded_pb_field!( + _env, + result_jobject, + secret, + "voter_secret" + ); + result_jobject.into_inner() +} + +/// Java interface for +/// 'com.webank.wedpr.acv.NativeInterface->generateRegistrationBlindingPoint'. +#[no_mangle] +pub extern "system" fn Java_com_webank_wedpr_acv_NativeInterface_generateRegistrationBlindingPoint( + _env: JNIEnv, + _class: JClass, + vote_secret: JString, + poll_parameters: JString, +) -> jobject { + let result_jobject = get_result_jobject(&_env); + let pb_vote_secret = java_safe_jstring_to_pb!( + _env, + result_jobject, + vote_secret, + VoterSecret + ); + let pb_poll_parameters = java_safe_jstring_to_pb!( + _env, + result_jobject, + poll_parameters, + PollParametersStorage + ); + let registration_blinding_point = match wedpr_s_anonymous_ciphertext_voting::voter::generate_registration_blinding_point( + &pb_vote_secret, &pb_poll_parameters + ) + { + Ok(v) => v, + Err(e)=>{ + return java_set_error_field_and_extract_jobject( + &_env, + &result_jobject, + &format!("generateRegistrationBlindingPoint failed, err = {:?}", e), + ) + }, + }; + // write registration_blinding_point + java_safe_set_encoded_pb_field!( + _env, + result_jobject, + registration_blinding_point, + "registration_blinding_point" + ); + result_jobject.into_inner() +} + +/// Java interface for +/// 'com.webank.wedpr.acv.NativeInterface->makeUnboundedRegistrationRequest'. +#[no_mangle] +pub extern "system" fn Java_com_webank_wedpr_acv_NativeInterface_makeUnboundedRegistrationRequest( + _env: JNIEnv, + _class: JClass, + zero_secret: JString, + vote_secret: JString, + poll_parameters: JString, +) -> jobject { + let result_jobject = get_result_jobject(&_env); + let pb_zero_secret = java_safe_jstring_to_pb!( + _env, + result_jobject, + zero_secret, + VoterSecret + ); + let pb_vote_secret = java_safe_jstring_to_pb!( + _env, + result_jobject, + vote_secret, + VoterSecret + ); + let pb_poll_parameters = java_safe_jstring_to_pb!( + _env, + result_jobject, + poll_parameters, + PollParametersStorage + ); + let registration_request = match wedpr_s_anonymous_ciphertext_voting::voter::make_unbounded_registration_request( + &pb_zero_secret, &pb_vote_secret, &pb_poll_parameters + ) + { + Ok(v) => v, + Err(e)=>{ + return java_set_error_field_and_extract_jobject( + &_env, + &result_jobject, + &format!("makeUnboundedRegistrationRequest failed, err = {:?}", e), + ) + }, + }; + // write the registration_request + java_safe_set_encoded_pb_field!( + _env, + result_jobject, + registration_request, + "registration_request" + ); + result_jobject.into_inner() +} + +/// Java interface for 'com.webank.wedpr.acv.NativeInterface->vote'. +#[no_mangle] +pub extern "system" fn Java_com_webank_wedpr_acv_NativeInterface_vote( + _env: JNIEnv, + _class: JClass, + voter_secret: JString, + vote_choices: JString, + registration_response: JString, + poll_parameters: JString, +) -> jobject { + let result_jobject = get_result_jobject(&_env); + let pb_voter_secret = java_safe_jstring_to_pb!( + _env, + result_jobject, + voter_secret, + VoterSecret + ); + let pb_vote_choices = java_safe_jstring_to_pb!( + _env, + result_jobject, + vote_choices, + VoteChoices + ); + let pb_registration_response = java_safe_jstring_to_pb!( + _env, + result_jobject, + registration_response, + RegistrationResponse + ); + let pb_poll_parameters = java_safe_jstring_to_pb!( + _env, + result_jobject, + poll_parameters, + PollParametersStorage + ); + let vote_request = match wedpr_s_anonymous_ciphertext_voting::voter::vote( + &pb_voter_secret, + &pb_vote_choices, + &pb_registration_response, + &pb_poll_parameters, + ) { + Ok(v) => v, + Err(e) => { + return java_set_error_field_and_extract_jobject( + &_env, + &result_jobject, + &format!("vote failed, err = {:?}", e), + ) + }, + }; + // write the vote request + java_safe_set_encoded_pb_field!( + _env, + result_jobject, + vote_request, + "vote_request" + ); + result_jobject.into_inner() +} + +/// Java interface for 'com.webank.wedpr.acv.NativeInterface->voteUnbounded'. +#[no_mangle] +pub extern "system" fn Java_com_webank_wedpr_acv_NativeInterface_voteUnbounded( + _env: JNIEnv, + _class: JClass, + voter_secret: JString, + zero_secret: JString, + vote_choices: JString, + registration_response: JString, + poll_parameters: JString, +) -> jobject { + let result_jobject = get_result_jobject(&_env); + let pb_voter_secret = java_safe_jstring_to_pb!( + _env, + result_jobject, + voter_secret, + VoterSecret + ); + let pb_zero_secret = java_safe_jstring_to_pb!( + _env, + result_jobject, + zero_secret, + VoterSecret + ); + let pb_vote_choices = java_safe_jstring_to_pb!( + _env, + result_jobject, + vote_choices, + VoteChoices + ); + let pb_registration_response = java_safe_jstring_to_pb!( + _env, + result_jobject, + registration_response, + RegistrationResponse + ); + let pb_poll_parameters = java_safe_jstring_to_pb!( + _env, + result_jobject, + poll_parameters, + PollParametersStorage + ); + let vote_request = + match wedpr_s_anonymous_ciphertext_voting::voter::vote_unbounded( + &pb_voter_secret, + &pb_zero_secret, + &pb_vote_choices, + &pb_registration_response, + &pb_poll_parameters, + ) { + Ok(v) => v, + Err(e) => { + return java_set_error_field_and_extract_jobject( + &_env, + &result_jobject, + &format!("voteUnbounded failed, err = {:?}", e), + ) + }, + }; + // write the vote request + java_safe_set_encoded_pb_field!( + _env, + result_jobject, + vote_request, + "vote_request" + ); + result_jobject.into_inner() +} + +/// Java interface for +/// 'com.webank.wedpr.acv.NativeInterface->voteUnboundedUnlisted'. +#[no_mangle] +pub extern "system" fn Java_com_webank_wedpr_acv_NativeInterface_voteUnboundedUnlisted( + _env: JNIEnv, + _class: JClass, + voter_secret: JString, + zero_secret: JString, + vote_choices: JString, + registration_response: JString, + poll_parameters: JString, +) -> jobject { + let result_jobject = get_result_jobject(&_env); + let pb_voter_secret = java_safe_jstring_to_pb!( + _env, + result_jobject, + voter_secret, + VoterSecret + ); + let pb_zero_secret = java_safe_jstring_to_pb!( + _env, + result_jobject, + zero_secret, + VoterSecret + ); + let pb_vote_choices = java_safe_jstring_to_pb!( + _env, + result_jobject, + vote_choices, + VoteChoices + ); + let pb_registration_response = java_safe_jstring_to_pb!( + _env, + result_jobject, + registration_response, + RegistrationResponse + ); + let pb_poll_parameters = java_safe_jstring_to_pb!( + _env, + result_jobject, + poll_parameters, + PollParametersStorage + ); + let vote_request = + match wedpr_s_anonymous_ciphertext_voting::voter::vote_unbounded_unlisted( + &pb_voter_secret, + &pb_zero_secret, + &pb_vote_choices, + &pb_registration_response, + &pb_poll_parameters, + ) { + Ok(v) => v, + Err(e) => { + return java_set_error_field_and_extract_jobject( + &_env, + &result_jobject, + &format!("voteUnboundedUnlisted failed, err = {:?}", e), + ) + }, + }; + // write the vote request + java_safe_set_encoded_pb_field!( + _env, + result_jobject, + vote_request, + "vote_request" + ); + result_jobject.into_inner() +} diff --git a/protos/Cargo.toml b/protos/Cargo.toml index 78bf691..3a58817 100644 --- a/protos/Cargo.toml +++ b/protos/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "wedpr_s_protos" -version = "1.5.0" +version = "1.6.0" authors = [ "WeDPR " ] edition = "2018" license = "Apache-2.0" @@ -9,7 +9,10 @@ description = "Library of WeDPR protobuf definitions and their generated code." # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +lazy_static = "1.4.0" protobuf = "2.22.1" protoc-rust = "2.22.1" wedpr_l_utils = "1.1.0" wedpr_l_crypto_zkp_utils = {version = "1.3.0", git = "https://github.com/WeBankBlockchain/WeDPR-Lab-Crypto", branch = "dev-1.3.0"} +wedpr_l_crypto_hash_keccak256 = "1.1.0" +wedpr_l_crypto_signature_secp256k1 = "1.1.0" diff --git a/protos/solution/acv/acv.proto b/protos/solution/acv/acv.proto index fa06820..3b59819 100644 --- a/protos/solution/acv/acv.proto +++ b/protos/solution/acv/acv.proto @@ -30,6 +30,8 @@ message VoterSecret { // Request of registering a voter. message RegistrationRequest { RegistrationBlindingPoint weight_point = 1; + // In a restricted voting scenario, the voting weight must be 0 or weight + RegistrationBlindingPoint zero_point = 2; } // Blinding points for a voter registration. @@ -43,6 +45,7 @@ message RegistrationResponse { uint32 voter_weight = 1; Ballot ballot = 2; bytes signature = 3; + Ballot zero_ballot = 4; } // Ciphertext ballot. @@ -68,9 +71,20 @@ message VoteChoice { uint32 value = 2; } +// pick other candidates from outside the given candidate list +message UnlistedVoteChoice +{ + // the unlisted candidate id + uint32 candidate_id = 1; + // the vote weight + uint32 value = 2; +} + // Choice list for all candidates. message VoteChoices { repeated VoteChoice choice = 1; + // Choose unlisted candidates + repeated UnlistedVoteChoice unlisted_choice = 2; } // Ciphertext ballot for a candidate. @@ -82,6 +96,8 @@ message CandidateBallot { // ZKP data to verify the format of ciphertext ballot. message BallotProof { bytes format_proof = 1; + // proof for unbounded vote scenes + bytes either_equality_proof = 2; } // Pair of string (candidate id) and BallotProof. @@ -96,6 +112,8 @@ message VoteRequest { repeated StringToBallotProofPair ballot_proof = 2; bytes range_proof = 3; bytes sum_balance_proof = 4; + // the ballot proof for unlisted-candidates + repeated CipherPointsToBallotProofPair unlisted_ballot_proof = 5; } // Ciphertext ballot for all candidates. @@ -104,6 +122,32 @@ message VoteStorage { Ballot blank_ballot = 2; Ballot rest_ballot = 3; repeated CandidateBallot voted_ballot = 4; + // the ballot for unlisted-candidates + repeated CipherPointsToBallotPair voted_ballot_unlisted = 6; + Ballot zero_ballot = 7; +} + +// the ballot for the unlisted-candidate +message CipherPointsToBallotPair +{ + // the unlisted-candidate cipher + CipherPoints key = 1; + // the ballot for the unlisted-candidate + Ballot ballot = 3; +} + +// CipherPointsToBallotPair and CipherPointsToBallotProofPair associated by candidate cipher(CipherPoints) +message CipherPointsToBallotProofPair { + // the unlisted-candidate cipher + CipherPoints key = 1; + // the ballot proof for given ulisted-candidate + BallotProof value = 2; +} + +// the cipher for the unlisted-candidate +message CipherPoints { + bytes ciphertext1 = 1; + bytes ciphertext2 = 2; } // Partially decrypted ballot and associated ZKP data for a candidate. @@ -123,11 +167,29 @@ message StringToCountingPartPair { message DecryptedResultPartStorage { CountingPart blank_part = 1; repeated StringToCountingPartPair candidate_part = 2; + // the decrypted part for the unlisted-candidate + repeated UnlistedBallotDecryptedResult unlisted_candidate_part = 3; +} + +// the decrypted result for the unlisted-candidate +message UnlistedBallotDecryptedResult +{ + // the unlisted candidate id + int64 candidate = 1; + CipherPoints candidate_cipher = 2; + // the decrypted unlisted candidate + CountingPart decrypted_unlisted_candidate = 4; + // the decrypted unlisted candidate ballot + // here use vector for aggregate_decrypted_part_sum_unlisted + repeated CountingPart decrypted_unlisted_candidate_ballot = 5; } // Fully decrypted result of a poll. message VoteResultStorage { + // the vote result for candidate list repeated StringToInt64Pair result = 1; + // the vote result for the unlisted candidate list + repeated UnlistedVoteChoice unlisted_result = 2; } // Pair of string (candidate id) and number. diff --git a/protos/src/config.rs b/protos/src/config.rs new file mode 100644 index 0000000..aa9604a --- /dev/null +++ b/protos/src/config.rs @@ -0,0 +1,14 @@ +// Copyright 2020 WeDPR Lab Project Authors. Licensed under Apache-2.0. + +//! Config of anonymous ciphertext voting (ACV) solution. +use wedpr_l_crypto_hash_keccak256::WedprKeccak256; +use wedpr_l_crypto_signature_secp256k1::WedprSecp256k1Recover; + +// TODO: support sm-crypto +lazy_static! { + /// Shared signature algorithm reference for quick implementation replacement. + pub static ref SIGNATURE: WedprSecp256k1Recover = + WedprSecp256k1Recover::default(); + /// Shared hash algorithm reference for quick implementation replacement. + pub static ref HASH: WedprKeccak256 = WedprKeccak256::default(); +} diff --git a/protos/src/generated/acv.rs b/protos/src/generated/acv.rs index 0d93ea2..b45d694 100644 --- a/protos/src/generated/acv.rs +++ b/protos/src/generated/acv.rs @@ -1,6 +1,4 @@ -// Copyright 2021 WeDPR Lab Project Authors. Licensed under Apache-2.0. - -// This file is generated by rust-protobuf 2.22.1. Do not edit +// This file is generated by rust-protobuf 2.27.1. Do not edit // @generated // https://github.com/rust-lang/rust-clippy/issues/702 @@ -23,7 +21,7 @@ /// Generated files are compatible only with the same version /// of protobuf runtime. -// const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_22_1; +// const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_27_1; #[derive(PartialEq,Clone,Default)] pub struct CandidateList { @@ -721,6 +719,7 @@ impl ::protobuf::reflect::ProtobufValue for VoterSecret { pub struct RegistrationRequest { // message fields pub weight_point: ::protobuf::SingularPtrField, + pub zero_point: ::protobuf::SingularPtrField, // special fields pub unknown_fields: ::protobuf::UnknownFields, pub cached_size: ::protobuf::CachedSize, @@ -769,6 +768,39 @@ impl RegistrationRequest { pub fn take_weight_point(&mut self) -> RegistrationBlindingPoint { self.weight_point.take().unwrap_or_else(|| RegistrationBlindingPoint::new()) } + + // .com.webank.wedpr.acv.proto.RegistrationBlindingPoint zero_point = 2; + + + pub fn get_zero_point(&self) -> &RegistrationBlindingPoint { + self.zero_point.as_ref().unwrap_or_else(|| ::default_instance()) + } + pub fn clear_zero_point(&mut self) { + self.zero_point.clear(); + } + + pub fn has_zero_point(&self) -> bool { + self.zero_point.is_some() + } + + // Param is passed by value, moved + pub fn set_zero_point(&mut self, v: RegistrationBlindingPoint) { + self.zero_point = ::protobuf::SingularPtrField::some(v); + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_zero_point(&mut self) -> &mut RegistrationBlindingPoint { + if self.zero_point.is_none() { + self.zero_point.set_default(); + } + self.zero_point.as_mut().unwrap() + } + + // Take field + pub fn take_zero_point(&mut self) -> RegistrationBlindingPoint { + self.zero_point.take().unwrap_or_else(|| RegistrationBlindingPoint::new()) + } } impl ::protobuf::Message for RegistrationRequest { @@ -778,6 +810,11 @@ impl ::protobuf::Message for RegistrationRequest { return false; } }; + for v in &self.zero_point { + if !v.is_initialized() { + return false; + } + }; true } @@ -788,6 +825,9 @@ impl ::protobuf::Message for RegistrationRequest { 1 => { ::protobuf::rt::read_singular_message_into(wire_type, is, &mut self.weight_point)?; }, + 2 => { + ::protobuf::rt::read_singular_message_into(wire_type, is, &mut self.zero_point)?; + }, _ => { ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; }, @@ -804,6 +844,10 @@ impl ::protobuf::Message for RegistrationRequest { let len = v.compute_size(); my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; } + if let Some(ref v) = self.zero_point.as_ref() { + let len = v.compute_size(); + my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; + } my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); self.cached_size.set(my_size); my_size @@ -815,6 +859,11 @@ impl ::protobuf::Message for RegistrationRequest { os.write_raw_varint32(v.get_cached_size())?; v.write_to_with_cached_sizes(os)?; } + if let Some(ref v) = self.zero_point.as_ref() { + os.write_tag(2, ::protobuf::wire_format::WireTypeLengthDelimited)?; + os.write_raw_varint32(v.get_cached_size())?; + v.write_to_with_cached_sizes(os)?; + } os.write_unknown_fields(self.get_unknown_fields())?; ::std::result::Result::Ok(()) } @@ -858,6 +907,11 @@ impl ::protobuf::Message for RegistrationRequest { |m: &RegistrationRequest| { &m.weight_point }, |m: &mut RegistrationRequest| { &mut m.weight_point }, )); + fields.push(::protobuf::reflect::accessor::make_singular_ptr_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( + "zero_point", + |m: &RegistrationRequest| { &m.zero_point }, + |m: &mut RegistrationRequest| { &mut m.zero_point }, + )); ::protobuf::reflect::MessageDescriptor::new_pb_name::( "RegistrationRequest", fields, @@ -875,6 +929,7 @@ impl ::protobuf::Message for RegistrationRequest { impl ::protobuf::Clear for RegistrationRequest { fn clear(&mut self) { self.weight_point.clear(); + self.zero_point.clear(); self.unknown_fields.clear(); } } @@ -1098,6 +1153,7 @@ pub struct RegistrationResponse { pub voter_weight: u32, pub ballot: ::protobuf::SingularPtrField, pub signature: ::std::vec::Vec, + pub zero_ballot: ::protobuf::SingularPtrField, // special fields pub unknown_fields: ::protobuf::UnknownFields, pub cached_size: ::protobuf::CachedSize, @@ -1187,6 +1243,39 @@ impl RegistrationResponse { pub fn take_signature(&mut self) -> ::std::vec::Vec { ::std::mem::replace(&mut self.signature, ::std::vec::Vec::new()) } + + // .com.webank.wedpr.acv.proto.Ballot zero_ballot = 4; + + + pub fn get_zero_ballot(&self) -> &Ballot { + self.zero_ballot.as_ref().unwrap_or_else(|| ::default_instance()) + } + pub fn clear_zero_ballot(&mut self) { + self.zero_ballot.clear(); + } + + pub fn has_zero_ballot(&self) -> bool { + self.zero_ballot.is_some() + } + + // Param is passed by value, moved + pub fn set_zero_ballot(&mut self, v: Ballot) { + self.zero_ballot = ::protobuf::SingularPtrField::some(v); + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_zero_ballot(&mut self) -> &mut Ballot { + if self.zero_ballot.is_none() { + self.zero_ballot.set_default(); + } + self.zero_ballot.as_mut().unwrap() + } + + // Take field + pub fn take_zero_ballot(&mut self) -> Ballot { + self.zero_ballot.take().unwrap_or_else(|| Ballot::new()) + } } impl ::protobuf::Message for RegistrationResponse { @@ -1196,6 +1285,11 @@ impl ::protobuf::Message for RegistrationResponse { return false; } }; + for v in &self.zero_ballot { + if !v.is_initialized() { + return false; + } + }; true } @@ -1216,6 +1310,9 @@ impl ::protobuf::Message for RegistrationResponse { 3 => { ::protobuf::rt::read_singular_proto3_bytes_into(wire_type, is, &mut self.signature)?; }, + 4 => { + ::protobuf::rt::read_singular_message_into(wire_type, is, &mut self.zero_ballot)?; + }, _ => { ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; }, @@ -1238,6 +1335,10 @@ impl ::protobuf::Message for RegistrationResponse { if !self.signature.is_empty() { my_size += ::protobuf::rt::bytes_size(3, &self.signature); } + if let Some(ref v) = self.zero_ballot.as_ref() { + let len = v.compute_size(); + my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; + } my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); self.cached_size.set(my_size); my_size @@ -1255,6 +1356,11 @@ impl ::protobuf::Message for RegistrationResponse { if !self.signature.is_empty() { os.write_bytes(3, &self.signature)?; } + if let Some(ref v) = self.zero_ballot.as_ref() { + os.write_tag(4, ::protobuf::wire_format::WireTypeLengthDelimited)?; + os.write_raw_varint32(v.get_cached_size())?; + v.write_to_with_cached_sizes(os)?; + } os.write_unknown_fields(self.get_unknown_fields())?; ::std::result::Result::Ok(()) } @@ -1308,6 +1414,11 @@ impl ::protobuf::Message for RegistrationResponse { |m: &RegistrationResponse| { &m.signature }, |m: &mut RegistrationResponse| { &mut m.signature }, )); + fields.push(::protobuf::reflect::accessor::make_singular_ptr_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( + "zero_ballot", + |m: &RegistrationResponse| { &m.zero_ballot }, + |m: &mut RegistrationResponse| { &mut m.zero_ballot }, + )); ::protobuf::reflect::MessageDescriptor::new_pb_name::( "RegistrationResponse", fields, @@ -1327,6 +1438,7 @@ impl ::protobuf::Clear for RegistrationResponse { self.voter_weight = 0; self.ballot.clear(); self.signature.clear(); + self.zero_ballot.clear(); self.unknown_fields.clear(); } } @@ -2105,10 +2217,198 @@ impl ::protobuf::reflect::ProtobufValue for VoteChoice { } } +#[derive(PartialEq,Clone,Default)] +pub struct UnlistedVoteChoice { + // message fields + pub candidate_id: u32, + pub value: u32, + // special fields + pub unknown_fields: ::protobuf::UnknownFields, + pub cached_size: ::protobuf::CachedSize, +} + +impl<'a> ::std::default::Default for &'a UnlistedVoteChoice { + fn default() -> &'a UnlistedVoteChoice { + ::default_instance() + } +} + +impl UnlistedVoteChoice { + pub fn new() -> UnlistedVoteChoice { + ::std::default::Default::default() + } + + // uint32 candidate_id = 1; + + + pub fn get_candidate_id(&self) -> u32 { + self.candidate_id + } + pub fn clear_candidate_id(&mut self) { + self.candidate_id = 0; + } + + // Param is passed by value, moved + pub fn set_candidate_id(&mut self, v: u32) { + self.candidate_id = v; + } + + // uint32 value = 2; + + + pub fn get_value(&self) -> u32 { + self.value + } + pub fn clear_value(&mut self) { + self.value = 0; + } + + // Param is passed by value, moved + pub fn set_value(&mut self, v: u32) { + self.value = v; + } +} + +impl ::protobuf::Message for UnlistedVoteChoice { + fn is_initialized(&self) -> bool { + true + } + + fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { + while !is.eof()? { + let (field_number, wire_type) = is.read_tag_unpack()?; + match field_number { + 1 => { + if wire_type != ::protobuf::wire_format::WireTypeVarint { + return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); + } + let tmp = is.read_uint32()?; + self.candidate_id = tmp; + }, + 2 => { + if wire_type != ::protobuf::wire_format::WireTypeVarint { + return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); + } + let tmp = is.read_uint32()?; + self.value = tmp; + }, + _ => { + ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; + }, + }; + } + ::std::result::Result::Ok(()) + } + + // Compute sizes of nested messages + #[allow(unused_variables)] + fn compute_size(&self) -> u32 { + let mut my_size = 0; + if self.candidate_id != 0 { + my_size += ::protobuf::rt::value_size(1, self.candidate_id, ::protobuf::wire_format::WireTypeVarint); + } + if self.value != 0 { + my_size += ::protobuf::rt::value_size(2, self.value, ::protobuf::wire_format::WireTypeVarint); + } + my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); + self.cached_size.set(my_size); + my_size + } + + fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { + if self.candidate_id != 0 { + os.write_uint32(1, self.candidate_id)?; + } + if self.value != 0 { + os.write_uint32(2, self.value)?; + } + os.write_unknown_fields(self.get_unknown_fields())?; + ::std::result::Result::Ok(()) + } + + fn get_cached_size(&self) -> u32 { + self.cached_size.get() + } + + fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { + &self.unknown_fields + } + + fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { + &mut self.unknown_fields + } + + fn as_any(&self) -> &dyn (::std::any::Any) { + self as &dyn (::std::any::Any) + } + fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { + self as &mut dyn (::std::any::Any) + } + fn into_any(self: ::std::boxed::Box) -> ::std::boxed::Box { + self + } + + fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { + Self::descriptor_static() + } + + fn new() -> UnlistedVoteChoice { + UnlistedVoteChoice::new() + } + + fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { + static descriptor: ::protobuf::rt::LazyV2<::protobuf::reflect::MessageDescriptor> = ::protobuf::rt::LazyV2::INIT; + descriptor.get(|| { + let mut fields = ::std::vec::Vec::new(); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeUint32>( + "candidate_id", + |m: &UnlistedVoteChoice| { &m.candidate_id }, + |m: &mut UnlistedVoteChoice| { &mut m.candidate_id }, + )); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeUint32>( + "value", + |m: &UnlistedVoteChoice| { &m.value }, + |m: &mut UnlistedVoteChoice| { &mut m.value }, + )); + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "UnlistedVoteChoice", + fields, + file_descriptor_proto() + ) + }) + } + + fn default_instance() -> &'static UnlistedVoteChoice { + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(UnlistedVoteChoice::new) + } +} + +impl ::protobuf::Clear for UnlistedVoteChoice { + fn clear(&mut self) { + self.candidate_id = 0; + self.value = 0; + self.unknown_fields.clear(); + } +} + +impl ::std::fmt::Debug for UnlistedVoteChoice { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + ::protobuf::text_format::fmt(self, f) + } +} + +impl ::protobuf::reflect::ProtobufValue for UnlistedVoteChoice { + fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { + ::protobuf::reflect::ReflectValueRef::Message(self) + } +} + #[derive(PartialEq,Clone,Default)] pub struct VoteChoices { // message fields pub choice: ::protobuf::RepeatedField, + pub unlisted_choice: ::protobuf::RepeatedField, // special fields pub unknown_fields: ::protobuf::UnknownFields, pub cached_size: ::protobuf::CachedSize, @@ -2149,6 +2449,31 @@ impl VoteChoices { pub fn take_choice(&mut self) -> ::protobuf::RepeatedField { ::std::mem::replace(&mut self.choice, ::protobuf::RepeatedField::new()) } + + // repeated .com.webank.wedpr.acv.proto.UnlistedVoteChoice unlisted_choice = 2; + + + pub fn get_unlisted_choice(&self) -> &[UnlistedVoteChoice] { + &self.unlisted_choice + } + pub fn clear_unlisted_choice(&mut self) { + self.unlisted_choice.clear(); + } + + // Param is passed by value, moved + pub fn set_unlisted_choice(&mut self, v: ::protobuf::RepeatedField) { + self.unlisted_choice = v; + } + + // Mutable pointer to the field. + pub fn mut_unlisted_choice(&mut self) -> &mut ::protobuf::RepeatedField { + &mut self.unlisted_choice + } + + // Take field + pub fn take_unlisted_choice(&mut self) -> ::protobuf::RepeatedField { + ::std::mem::replace(&mut self.unlisted_choice, ::protobuf::RepeatedField::new()) + } } impl ::protobuf::Message for VoteChoices { @@ -2158,6 +2483,11 @@ impl ::protobuf::Message for VoteChoices { return false; } }; + for v in &self.unlisted_choice { + if !v.is_initialized() { + return false; + } + }; true } @@ -2168,6 +2498,9 @@ impl ::protobuf::Message for VoteChoices { 1 => { ::protobuf::rt::read_repeated_message_into(wire_type, is, &mut self.choice)?; }, + 2 => { + ::protobuf::rt::read_repeated_message_into(wire_type, is, &mut self.unlisted_choice)?; + }, _ => { ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; }, @@ -2184,6 +2517,10 @@ impl ::protobuf::Message for VoteChoices { let len = value.compute_size(); my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; }; + for value in &self.unlisted_choice { + let len = value.compute_size(); + my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; + }; my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); self.cached_size.set(my_size); my_size @@ -2195,6 +2532,11 @@ impl ::protobuf::Message for VoteChoices { os.write_raw_varint32(v.get_cached_size())?; v.write_to_with_cached_sizes(os)?; }; + for v in &self.unlisted_choice { + os.write_tag(2, ::protobuf::wire_format::WireTypeLengthDelimited)?; + os.write_raw_varint32(v.get_cached_size())?; + v.write_to_with_cached_sizes(os)?; + }; os.write_unknown_fields(self.get_unknown_fields())?; ::std::result::Result::Ok(()) } @@ -2238,6 +2580,11 @@ impl ::protobuf::Message for VoteChoices { |m: &VoteChoices| { &m.choice }, |m: &mut VoteChoices| { &mut m.choice }, )); + fields.push(::protobuf::reflect::accessor::make_repeated_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( + "unlisted_choice", + |m: &VoteChoices| { &m.unlisted_choice }, + |m: &mut VoteChoices| { &mut m.unlisted_choice }, + )); ::protobuf::reflect::MessageDescriptor::new_pb_name::( "VoteChoices", fields, @@ -2255,6 +2602,7 @@ impl ::protobuf::Message for VoteChoices { impl ::protobuf::Clear for VoteChoices { fn clear(&mut self) { self.choice.clear(); + self.unlisted_choice.clear(); self.unknown_fields.clear(); } } @@ -2491,6 +2839,7 @@ impl ::protobuf::reflect::ProtobufValue for CandidateBallot { pub struct BallotProof { // message fields pub format_proof: ::std::vec::Vec, + pub either_equality_proof: ::std::vec::Vec, // special fields pub unknown_fields: ::protobuf::UnknownFields, pub cached_size: ::protobuf::CachedSize, @@ -2532,20 +2881,49 @@ impl BallotProof { pub fn take_format_proof(&mut self) -> ::std::vec::Vec { ::std::mem::replace(&mut self.format_proof, ::std::vec::Vec::new()) } -} -impl ::protobuf::Message for BallotProof { - fn is_initialized(&self) -> bool { - true + // bytes either_equality_proof = 2; + + + pub fn get_either_equality_proof(&self) -> &[u8] { + &self.either_equality_proof + } + pub fn clear_either_equality_proof(&mut self) { + self.either_equality_proof.clear(); } - fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { - while !is.eof()? { - let (field_number, wire_type) = is.read_tag_unpack()?; + // Param is passed by value, moved + pub fn set_either_equality_proof(&mut self, v: ::std::vec::Vec) { + self.either_equality_proof = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_either_equality_proof(&mut self) -> &mut ::std::vec::Vec { + &mut self.either_equality_proof + } + + // Take field + pub fn take_either_equality_proof(&mut self) -> ::std::vec::Vec { + ::std::mem::replace(&mut self.either_equality_proof, ::std::vec::Vec::new()) + } +} + +impl ::protobuf::Message for BallotProof { + fn is_initialized(&self) -> bool { + true + } + + fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { + while !is.eof()? { + let (field_number, wire_type) = is.read_tag_unpack()?; match field_number { 1 => { ::protobuf::rt::read_singular_proto3_bytes_into(wire_type, is, &mut self.format_proof)?; }, + 2 => { + ::protobuf::rt::read_singular_proto3_bytes_into(wire_type, is, &mut self.either_equality_proof)?; + }, _ => { ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; }, @@ -2561,6 +2939,9 @@ impl ::protobuf::Message for BallotProof { if !self.format_proof.is_empty() { my_size += ::protobuf::rt::bytes_size(1, &self.format_proof); } + if !self.either_equality_proof.is_empty() { + my_size += ::protobuf::rt::bytes_size(2, &self.either_equality_proof); + } my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); self.cached_size.set(my_size); my_size @@ -2570,6 +2951,9 @@ impl ::protobuf::Message for BallotProof { if !self.format_proof.is_empty() { os.write_bytes(1, &self.format_proof)?; } + if !self.either_equality_proof.is_empty() { + os.write_bytes(2, &self.either_equality_proof)?; + } os.write_unknown_fields(self.get_unknown_fields())?; ::std::result::Result::Ok(()) } @@ -2613,6 +2997,11 @@ impl ::protobuf::Message for BallotProof { |m: &BallotProof| { &m.format_proof }, |m: &mut BallotProof| { &mut m.format_proof }, )); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( + "either_equality_proof", + |m: &BallotProof| { &m.either_equality_proof }, + |m: &mut BallotProof| { &mut m.either_equality_proof }, + )); ::protobuf::reflect::MessageDescriptor::new_pb_name::( "BallotProof", fields, @@ -2630,6 +3019,7 @@ impl ::protobuf::Message for BallotProof { impl ::protobuf::Clear for BallotProof { fn clear(&mut self) { self.format_proof.clear(); + self.either_equality_proof.clear(); self.unknown_fields.clear(); } } @@ -2869,6 +3259,7 @@ pub struct VoteRequest { pub ballot_proof: ::protobuf::RepeatedField, pub range_proof: ::std::vec::Vec, pub sum_balance_proof: ::std::vec::Vec, + pub unlisted_ballot_proof: ::protobuf::RepeatedField, // special fields pub unknown_fields: ::protobuf::UnknownFields, pub cached_size: ::protobuf::CachedSize, @@ -2994,6 +3385,31 @@ impl VoteRequest { pub fn take_sum_balance_proof(&mut self) -> ::std::vec::Vec { ::std::mem::replace(&mut self.sum_balance_proof, ::std::vec::Vec::new()) } + + // repeated .com.webank.wedpr.acv.proto.CipherPointsToBallotProofPair unlisted_ballot_proof = 5; + + + pub fn get_unlisted_ballot_proof(&self) -> &[CipherPointsToBallotProofPair] { + &self.unlisted_ballot_proof + } + pub fn clear_unlisted_ballot_proof(&mut self) { + self.unlisted_ballot_proof.clear(); + } + + // Param is passed by value, moved + pub fn set_unlisted_ballot_proof(&mut self, v: ::protobuf::RepeatedField) { + self.unlisted_ballot_proof = v; + } + + // Mutable pointer to the field. + pub fn mut_unlisted_ballot_proof(&mut self) -> &mut ::protobuf::RepeatedField { + &mut self.unlisted_ballot_proof + } + + // Take field + pub fn take_unlisted_ballot_proof(&mut self) -> ::protobuf::RepeatedField { + ::std::mem::replace(&mut self.unlisted_ballot_proof, ::protobuf::RepeatedField::new()) + } } impl ::protobuf::Message for VoteRequest { @@ -3008,6 +3424,11 @@ impl ::protobuf::Message for VoteRequest { return false; } }; + for v in &self.unlisted_ballot_proof { + if !v.is_initialized() { + return false; + } + }; true } @@ -3027,6 +3448,9 @@ impl ::protobuf::Message for VoteRequest { 4 => { ::protobuf::rt::read_singular_proto3_bytes_into(wire_type, is, &mut self.sum_balance_proof)?; }, + 5 => { + ::protobuf::rt::read_repeated_message_into(wire_type, is, &mut self.unlisted_ballot_proof)?; + }, _ => { ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; }, @@ -3053,6 +3477,10 @@ impl ::protobuf::Message for VoteRequest { if !self.sum_balance_proof.is_empty() { my_size += ::protobuf::rt::bytes_size(4, &self.sum_balance_proof); } + for value in &self.unlisted_ballot_proof { + let len = value.compute_size(); + my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; + }; my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); self.cached_size.set(my_size); my_size @@ -3075,6 +3503,11 @@ impl ::protobuf::Message for VoteRequest { if !self.sum_balance_proof.is_empty() { os.write_bytes(4, &self.sum_balance_proof)?; } + for v in &self.unlisted_ballot_proof { + os.write_tag(5, ::protobuf::wire_format::WireTypeLengthDelimited)?; + os.write_raw_varint32(v.get_cached_size())?; + v.write_to_with_cached_sizes(os)?; + }; os.write_unknown_fields(self.get_unknown_fields())?; ::std::result::Result::Ok(()) } @@ -3133,6 +3566,11 @@ impl ::protobuf::Message for VoteRequest { |m: &VoteRequest| { &m.sum_balance_proof }, |m: &mut VoteRequest| { &mut m.sum_balance_proof }, )); + fields.push(::protobuf::reflect::accessor::make_repeated_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( + "unlisted_ballot_proof", + |m: &VoteRequest| { &m.unlisted_ballot_proof }, + |m: &mut VoteRequest| { &mut m.unlisted_ballot_proof }, + )); ::protobuf::reflect::MessageDescriptor::new_pb_name::( "VoteRequest", fields, @@ -3153,6 +3591,7 @@ impl ::protobuf::Clear for VoteRequest { self.ballot_proof.clear(); self.range_proof.clear(); self.sum_balance_proof.clear(); + self.unlisted_ballot_proof.clear(); self.unknown_fields.clear(); } } @@ -3176,6 +3615,8 @@ pub struct VoteStorage { pub blank_ballot: ::protobuf::SingularPtrField, pub rest_ballot: ::protobuf::SingularPtrField, pub voted_ballot: ::protobuf::RepeatedField, + pub voted_ballot_unlisted: ::protobuf::RepeatedField, + pub zero_ballot: ::protobuf::SingularPtrField, // special fields pub unknown_fields: ::protobuf::UnknownFields, pub cached_size: ::protobuf::CachedSize, @@ -3308,6 +3749,64 @@ impl VoteStorage { pub fn take_voted_ballot(&mut self) -> ::protobuf::RepeatedField { ::std::mem::replace(&mut self.voted_ballot, ::protobuf::RepeatedField::new()) } + + // repeated .com.webank.wedpr.acv.proto.CipherPointsToBallotPair voted_ballot_unlisted = 6; + + + pub fn get_voted_ballot_unlisted(&self) -> &[CipherPointsToBallotPair] { + &self.voted_ballot_unlisted + } + pub fn clear_voted_ballot_unlisted(&mut self) { + self.voted_ballot_unlisted.clear(); + } + + // Param is passed by value, moved + pub fn set_voted_ballot_unlisted(&mut self, v: ::protobuf::RepeatedField) { + self.voted_ballot_unlisted = v; + } + + // Mutable pointer to the field. + pub fn mut_voted_ballot_unlisted(&mut self) -> &mut ::protobuf::RepeatedField { + &mut self.voted_ballot_unlisted + } + + // Take field + pub fn take_voted_ballot_unlisted(&mut self) -> ::protobuf::RepeatedField { + ::std::mem::replace(&mut self.voted_ballot_unlisted, ::protobuf::RepeatedField::new()) + } + + // .com.webank.wedpr.acv.proto.Ballot zero_ballot = 7; + + + pub fn get_zero_ballot(&self) -> &Ballot { + self.zero_ballot.as_ref().unwrap_or_else(|| ::default_instance()) + } + pub fn clear_zero_ballot(&mut self) { + self.zero_ballot.clear(); + } + + pub fn has_zero_ballot(&self) -> bool { + self.zero_ballot.is_some() + } + + // Param is passed by value, moved + pub fn set_zero_ballot(&mut self, v: Ballot) { + self.zero_ballot = ::protobuf::SingularPtrField::some(v); + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_zero_ballot(&mut self) -> &mut Ballot { + if self.zero_ballot.is_none() { + self.zero_ballot.set_default(); + } + self.zero_ballot.as_mut().unwrap() + } + + // Take field + pub fn take_zero_ballot(&mut self) -> Ballot { + self.zero_ballot.take().unwrap_or_else(|| Ballot::new()) + } } impl ::protobuf::Message for VoteStorage { @@ -3327,6 +3826,16 @@ impl ::protobuf::Message for VoteStorage { return false; } }; + for v in &self.voted_ballot_unlisted { + if !v.is_initialized() { + return false; + } + }; + for v in &self.zero_ballot { + if !v.is_initialized() { + return false; + } + }; true } @@ -3346,6 +3855,12 @@ impl ::protobuf::Message for VoteStorage { 4 => { ::protobuf::rt::read_repeated_message_into(wire_type, is, &mut self.voted_ballot)?; }, + 6 => { + ::protobuf::rt::read_repeated_message_into(wire_type, is, &mut self.voted_ballot_unlisted)?; + }, + 7 => { + ::protobuf::rt::read_singular_message_into(wire_type, is, &mut self.zero_ballot)?; + }, _ => { ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; }, @@ -3373,6 +3888,14 @@ impl ::protobuf::Message for VoteStorage { let len = value.compute_size(); my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; }; + for value in &self.voted_ballot_unlisted { + let len = value.compute_size(); + my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; + }; + if let Some(ref v) = self.zero_ballot.as_ref() { + let len = v.compute_size(); + my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; + } my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); self.cached_size.set(my_size); my_size @@ -3397,6 +3920,16 @@ impl ::protobuf::Message for VoteStorage { os.write_raw_varint32(v.get_cached_size())?; v.write_to_with_cached_sizes(os)?; }; + for v in &self.voted_ballot_unlisted { + os.write_tag(6, ::protobuf::wire_format::WireTypeLengthDelimited)?; + os.write_raw_varint32(v.get_cached_size())?; + v.write_to_with_cached_sizes(os)?; + }; + if let Some(ref v) = self.zero_ballot.as_ref() { + os.write_tag(7, ::protobuf::wire_format::WireTypeLengthDelimited)?; + os.write_raw_varint32(v.get_cached_size())?; + v.write_to_with_cached_sizes(os)?; + } os.write_unknown_fields(self.get_unknown_fields())?; ::std::result::Result::Ok(()) } @@ -3455,6 +3988,16 @@ impl ::protobuf::Message for VoteStorage { |m: &VoteStorage| { &m.voted_ballot }, |m: &mut VoteStorage| { &mut m.voted_ballot }, )); + fields.push(::protobuf::reflect::accessor::make_repeated_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( + "voted_ballot_unlisted", + |m: &VoteStorage| { &m.voted_ballot_unlisted }, + |m: &mut VoteStorage| { &mut m.voted_ballot_unlisted }, + )); + fields.push(::protobuf::reflect::accessor::make_singular_ptr_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( + "zero_ballot", + |m: &VoteStorage| { &m.zero_ballot }, + |m: &mut VoteStorage| { &mut m.zero_ballot }, + )); ::protobuf::reflect::MessageDescriptor::new_pb_name::( "VoteStorage", fields, @@ -3475,6 +4018,8 @@ impl ::protobuf::Clear for VoteStorage { self.blank_ballot.clear(); self.rest_ballot.clear(); self.voted_ballot.clear(); + self.voted_ballot_unlisted.clear(); + self.zero_ballot.clear(); self.unknown_fields.clear(); } } @@ -3492,108 +4037,105 @@ impl ::protobuf::reflect::ProtobufValue for VoteStorage { } #[derive(PartialEq,Clone,Default)] -pub struct CountingPart { +pub struct CipherPointsToBallotPair { // message fields - pub counter_id: ::std::string::String, - pub blinding_c2: ::std::vec::Vec, - pub equality_proof: ::std::vec::Vec, + pub key: ::protobuf::SingularPtrField, + pub ballot: ::protobuf::SingularPtrField, // special fields pub unknown_fields: ::protobuf::UnknownFields, pub cached_size: ::protobuf::CachedSize, } -impl<'a> ::std::default::Default for &'a CountingPart { - fn default() -> &'a CountingPart { - ::default_instance() +impl<'a> ::std::default::Default for &'a CipherPointsToBallotPair { + fn default() -> &'a CipherPointsToBallotPair { + ::default_instance() } } -impl CountingPart { - pub fn new() -> CountingPart { +impl CipherPointsToBallotPair { + pub fn new() -> CipherPointsToBallotPair { ::std::default::Default::default() } - // string counter_id = 1; - + // .com.webank.wedpr.acv.proto.CipherPoints key = 1; - pub fn get_counter_id(&self) -> &str { - &self.counter_id - } - pub fn clear_counter_id(&mut self) { - self.counter_id.clear(); - } - - // Param is passed by value, moved - pub fn set_counter_id(&mut self, v: ::std::string::String) { - self.counter_id = v; - } - // Mutable pointer to the field. - // If field is not initialized, it is initialized with default value first. - pub fn mut_counter_id(&mut self) -> &mut ::std::string::String { - &mut self.counter_id + pub fn get_key(&self) -> &CipherPoints { + self.key.as_ref().unwrap_or_else(|| ::default_instance()) } - - // Take field - pub fn take_counter_id(&mut self) -> ::std::string::String { - ::std::mem::replace(&mut self.counter_id, ::std::string::String::new()) + pub fn clear_key(&mut self) { + self.key.clear(); } - // bytes blinding_c2 = 2; - - - pub fn get_blinding_c2(&self) -> &[u8] { - &self.blinding_c2 - } - pub fn clear_blinding_c2(&mut self) { - self.blinding_c2.clear(); + pub fn has_key(&self) -> bool { + self.key.is_some() } // Param is passed by value, moved - pub fn set_blinding_c2(&mut self, v: ::std::vec::Vec) { - self.blinding_c2 = v; + pub fn set_key(&mut self, v: CipherPoints) { + self.key = ::protobuf::SingularPtrField::some(v); } // Mutable pointer to the field. // If field is not initialized, it is initialized with default value first. - pub fn mut_blinding_c2(&mut self) -> &mut ::std::vec::Vec { - &mut self.blinding_c2 + pub fn mut_key(&mut self) -> &mut CipherPoints { + if self.key.is_none() { + self.key.set_default(); + } + self.key.as_mut().unwrap() } // Take field - pub fn take_blinding_c2(&mut self) -> ::std::vec::Vec { - ::std::mem::replace(&mut self.blinding_c2, ::std::vec::Vec::new()) + pub fn take_key(&mut self) -> CipherPoints { + self.key.take().unwrap_or_else(|| CipherPoints::new()) } - // bytes equality_proof = 3; + // .com.webank.wedpr.acv.proto.Ballot ballot = 3; - pub fn get_equality_proof(&self) -> &[u8] { - &self.equality_proof + pub fn get_ballot(&self) -> &Ballot { + self.ballot.as_ref().unwrap_or_else(|| ::default_instance()) } - pub fn clear_equality_proof(&mut self) { - self.equality_proof.clear(); + pub fn clear_ballot(&mut self) { + self.ballot.clear(); + } + + pub fn has_ballot(&self) -> bool { + self.ballot.is_some() } // Param is passed by value, moved - pub fn set_equality_proof(&mut self, v: ::std::vec::Vec) { - self.equality_proof = v; + pub fn set_ballot(&mut self, v: Ballot) { + self.ballot = ::protobuf::SingularPtrField::some(v); } // Mutable pointer to the field. // If field is not initialized, it is initialized with default value first. - pub fn mut_equality_proof(&mut self) -> &mut ::std::vec::Vec { - &mut self.equality_proof + pub fn mut_ballot(&mut self) -> &mut Ballot { + if self.ballot.is_none() { + self.ballot.set_default(); + } + self.ballot.as_mut().unwrap() } // Take field - pub fn take_equality_proof(&mut self) -> ::std::vec::Vec { - ::std::mem::replace(&mut self.equality_proof, ::std::vec::Vec::new()) + pub fn take_ballot(&mut self) -> Ballot { + self.ballot.take().unwrap_or_else(|| Ballot::new()) } } -impl ::protobuf::Message for CountingPart { +impl ::protobuf::Message for CipherPointsToBallotPair { fn is_initialized(&self) -> bool { + for v in &self.key { + if !v.is_initialized() { + return false; + } + }; + for v in &self.ballot { + if !v.is_initialized() { + return false; + } + }; true } @@ -3602,13 +4144,10 @@ impl ::protobuf::Message for CountingPart { let (field_number, wire_type) = is.read_tag_unpack()?; match field_number { 1 => { - ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.counter_id)?; - }, - 2 => { - ::protobuf::rt::read_singular_proto3_bytes_into(wire_type, is, &mut self.blinding_c2)?; + ::protobuf::rt::read_singular_message_into(wire_type, is, &mut self.key)?; }, 3 => { - ::protobuf::rt::read_singular_proto3_bytes_into(wire_type, is, &mut self.equality_proof)?; + ::protobuf::rt::read_singular_message_into(wire_type, is, &mut self.ballot)?; }, _ => { ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; @@ -3622,14 +4161,13 @@ impl ::protobuf::Message for CountingPart { #[allow(unused_variables)] fn compute_size(&self) -> u32 { let mut my_size = 0; - if !self.counter_id.is_empty() { - my_size += ::protobuf::rt::string_size(1, &self.counter_id); - } - if !self.blinding_c2.is_empty() { - my_size += ::protobuf::rt::bytes_size(2, &self.blinding_c2); + if let Some(ref v) = self.key.as_ref() { + let len = v.compute_size(); + my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; } - if !self.equality_proof.is_empty() { - my_size += ::protobuf::rt::bytes_size(3, &self.equality_proof); + if let Some(ref v) = self.ballot.as_ref() { + let len = v.compute_size(); + my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; } my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); self.cached_size.set(my_size); @@ -3637,14 +4175,15 @@ impl ::protobuf::Message for CountingPart { } fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { - if !self.counter_id.is_empty() { - os.write_string(1, &self.counter_id)?; - } - if !self.blinding_c2.is_empty() { - os.write_bytes(2, &self.blinding_c2)?; + if let Some(ref v) = self.key.as_ref() { + os.write_tag(1, ::protobuf::wire_format::WireTypeLengthDelimited)?; + os.write_raw_varint32(v.get_cached_size())?; + v.write_to_with_cached_sizes(os)?; } - if !self.equality_proof.is_empty() { - os.write_bytes(3, &self.equality_proof)?; + if let Some(ref v) = self.ballot.as_ref() { + os.write_tag(3, ::protobuf::wire_format::WireTypeLengthDelimited)?; + os.write_raw_varint32(v.get_cached_size())?; + v.write_to_with_cached_sizes(os)?; } os.write_unknown_fields(self.get_unknown_fields())?; ::std::result::Result::Ok(()) @@ -3676,53 +4215,722 @@ impl ::protobuf::Message for CountingPart { Self::descriptor_static() } - fn new() -> CountingPart { - CountingPart::new() + fn new() -> CipherPointsToBallotPair { + CipherPointsToBallotPair::new() } fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { static descriptor: ::protobuf::rt::LazyV2<::protobuf::reflect::MessageDescriptor> = ::protobuf::rt::LazyV2::INIT; descriptor.get(|| { let mut fields = ::std::vec::Vec::new(); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( - "counter_id", - |m: &CountingPart| { &m.counter_id }, - |m: &mut CountingPart| { &mut m.counter_id }, - )); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( - "blinding_c2", - |m: &CountingPart| { &m.blinding_c2 }, - |m: &mut CountingPart| { &mut m.blinding_c2 }, + fields.push(::protobuf::reflect::accessor::make_singular_ptr_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( + "key", + |m: &CipherPointsToBallotPair| { &m.key }, + |m: &mut CipherPointsToBallotPair| { &mut m.key }, )); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( - "equality_proof", - |m: &CountingPart| { &m.equality_proof }, - |m: &mut CountingPart| { &mut m.equality_proof }, + fields.push(::protobuf::reflect::accessor::make_singular_ptr_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( + "ballot", + |m: &CipherPointsToBallotPair| { &m.ballot }, + |m: &mut CipherPointsToBallotPair| { &mut m.ballot }, )); - ::protobuf::reflect::MessageDescriptor::new_pb_name::( - "CountingPart", + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "CipherPointsToBallotPair", fields, file_descriptor_proto() ) }) } - fn default_instance() -> &'static CountingPart { - static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; - instance.get(CountingPart::new) + fn default_instance() -> &'static CipherPointsToBallotPair { + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(CipherPointsToBallotPair::new) } } -impl ::protobuf::Clear for CountingPart { +impl ::protobuf::Clear for CipherPointsToBallotPair { fn clear(&mut self) { - self.counter_id.clear(); - self.blinding_c2.clear(); - self.equality_proof.clear(); + self.key.clear(); + self.ballot.clear(); self.unknown_fields.clear(); } } -impl ::std::fmt::Debug for CountingPart { +impl ::std::fmt::Debug for CipherPointsToBallotPair { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + ::protobuf::text_format::fmt(self, f) + } +} + +impl ::protobuf::reflect::ProtobufValue for CipherPointsToBallotPair { + fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { + ::protobuf::reflect::ReflectValueRef::Message(self) + } +} + +#[derive(PartialEq,Clone,Default)] +pub struct CipherPointsToBallotProofPair { + // message fields + pub key: ::protobuf::SingularPtrField, + pub value: ::protobuf::SingularPtrField, + // special fields + pub unknown_fields: ::protobuf::UnknownFields, + pub cached_size: ::protobuf::CachedSize, +} + +impl<'a> ::std::default::Default for &'a CipherPointsToBallotProofPair { + fn default() -> &'a CipherPointsToBallotProofPair { + ::default_instance() + } +} + +impl CipherPointsToBallotProofPair { + pub fn new() -> CipherPointsToBallotProofPair { + ::std::default::Default::default() + } + + // .com.webank.wedpr.acv.proto.CipherPoints key = 1; + + + pub fn get_key(&self) -> &CipherPoints { + self.key.as_ref().unwrap_or_else(|| ::default_instance()) + } + pub fn clear_key(&mut self) { + self.key.clear(); + } + + pub fn has_key(&self) -> bool { + self.key.is_some() + } + + // Param is passed by value, moved + pub fn set_key(&mut self, v: CipherPoints) { + self.key = ::protobuf::SingularPtrField::some(v); + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_key(&mut self) -> &mut CipherPoints { + if self.key.is_none() { + self.key.set_default(); + } + self.key.as_mut().unwrap() + } + + // Take field + pub fn take_key(&mut self) -> CipherPoints { + self.key.take().unwrap_or_else(|| CipherPoints::new()) + } + + // .com.webank.wedpr.acv.proto.BallotProof value = 2; + + + pub fn get_value(&self) -> &BallotProof { + self.value.as_ref().unwrap_or_else(|| ::default_instance()) + } + pub fn clear_value(&mut self) { + self.value.clear(); + } + + pub fn has_value(&self) -> bool { + self.value.is_some() + } + + // Param is passed by value, moved + pub fn set_value(&mut self, v: BallotProof) { + self.value = ::protobuf::SingularPtrField::some(v); + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_value(&mut self) -> &mut BallotProof { + if self.value.is_none() { + self.value.set_default(); + } + self.value.as_mut().unwrap() + } + + // Take field + pub fn take_value(&mut self) -> BallotProof { + self.value.take().unwrap_or_else(|| BallotProof::new()) + } +} + +impl ::protobuf::Message for CipherPointsToBallotProofPair { + fn is_initialized(&self) -> bool { + for v in &self.key { + if !v.is_initialized() { + return false; + } + }; + for v in &self.value { + if !v.is_initialized() { + return false; + } + }; + true + } + + fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { + while !is.eof()? { + let (field_number, wire_type) = is.read_tag_unpack()?; + match field_number { + 1 => { + ::protobuf::rt::read_singular_message_into(wire_type, is, &mut self.key)?; + }, + 2 => { + ::protobuf::rt::read_singular_message_into(wire_type, is, &mut self.value)?; + }, + _ => { + ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; + }, + }; + } + ::std::result::Result::Ok(()) + } + + // Compute sizes of nested messages + #[allow(unused_variables)] + fn compute_size(&self) -> u32 { + let mut my_size = 0; + if let Some(ref v) = self.key.as_ref() { + let len = v.compute_size(); + my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; + } + if let Some(ref v) = self.value.as_ref() { + let len = v.compute_size(); + my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; + } + my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); + self.cached_size.set(my_size); + my_size + } + + fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { + if let Some(ref v) = self.key.as_ref() { + os.write_tag(1, ::protobuf::wire_format::WireTypeLengthDelimited)?; + os.write_raw_varint32(v.get_cached_size())?; + v.write_to_with_cached_sizes(os)?; + } + if let Some(ref v) = self.value.as_ref() { + os.write_tag(2, ::protobuf::wire_format::WireTypeLengthDelimited)?; + os.write_raw_varint32(v.get_cached_size())?; + v.write_to_with_cached_sizes(os)?; + } + os.write_unknown_fields(self.get_unknown_fields())?; + ::std::result::Result::Ok(()) + } + + fn get_cached_size(&self) -> u32 { + self.cached_size.get() + } + + fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { + &self.unknown_fields + } + + fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { + &mut self.unknown_fields + } + + fn as_any(&self) -> &dyn (::std::any::Any) { + self as &dyn (::std::any::Any) + } + fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { + self as &mut dyn (::std::any::Any) + } + fn into_any(self: ::std::boxed::Box) -> ::std::boxed::Box { + self + } + + fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { + Self::descriptor_static() + } + + fn new() -> CipherPointsToBallotProofPair { + CipherPointsToBallotProofPair::new() + } + + fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { + static descriptor: ::protobuf::rt::LazyV2<::protobuf::reflect::MessageDescriptor> = ::protobuf::rt::LazyV2::INIT; + descriptor.get(|| { + let mut fields = ::std::vec::Vec::new(); + fields.push(::protobuf::reflect::accessor::make_singular_ptr_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( + "key", + |m: &CipherPointsToBallotProofPair| { &m.key }, + |m: &mut CipherPointsToBallotProofPair| { &mut m.key }, + )); + fields.push(::protobuf::reflect::accessor::make_singular_ptr_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( + "value", + |m: &CipherPointsToBallotProofPair| { &m.value }, + |m: &mut CipherPointsToBallotProofPair| { &mut m.value }, + )); + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "CipherPointsToBallotProofPair", + fields, + file_descriptor_proto() + ) + }) + } + + fn default_instance() -> &'static CipherPointsToBallotProofPair { + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(CipherPointsToBallotProofPair::new) + } +} + +impl ::protobuf::Clear for CipherPointsToBallotProofPair { + fn clear(&mut self) { + self.key.clear(); + self.value.clear(); + self.unknown_fields.clear(); + } +} + +impl ::std::fmt::Debug for CipherPointsToBallotProofPair { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + ::protobuf::text_format::fmt(self, f) + } +} + +impl ::protobuf::reflect::ProtobufValue for CipherPointsToBallotProofPair { + fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { + ::protobuf::reflect::ReflectValueRef::Message(self) + } +} + +#[derive(PartialEq,Clone,Default)] +pub struct CipherPoints { + // message fields + pub ciphertext1: ::std::vec::Vec, + pub ciphertext2: ::std::vec::Vec, + // special fields + pub unknown_fields: ::protobuf::UnknownFields, + pub cached_size: ::protobuf::CachedSize, +} + +impl<'a> ::std::default::Default for &'a CipherPoints { + fn default() -> &'a CipherPoints { + ::default_instance() + } +} + +impl CipherPoints { + pub fn new() -> CipherPoints { + ::std::default::Default::default() + } + + // bytes ciphertext1 = 1; + + + pub fn get_ciphertext1(&self) -> &[u8] { + &self.ciphertext1 + } + pub fn clear_ciphertext1(&mut self) { + self.ciphertext1.clear(); + } + + // Param is passed by value, moved + pub fn set_ciphertext1(&mut self, v: ::std::vec::Vec) { + self.ciphertext1 = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_ciphertext1(&mut self) -> &mut ::std::vec::Vec { + &mut self.ciphertext1 + } + + // Take field + pub fn take_ciphertext1(&mut self) -> ::std::vec::Vec { + ::std::mem::replace(&mut self.ciphertext1, ::std::vec::Vec::new()) + } + + // bytes ciphertext2 = 2; + + + pub fn get_ciphertext2(&self) -> &[u8] { + &self.ciphertext2 + } + pub fn clear_ciphertext2(&mut self) { + self.ciphertext2.clear(); + } + + // Param is passed by value, moved + pub fn set_ciphertext2(&mut self, v: ::std::vec::Vec) { + self.ciphertext2 = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_ciphertext2(&mut self) -> &mut ::std::vec::Vec { + &mut self.ciphertext2 + } + + // Take field + pub fn take_ciphertext2(&mut self) -> ::std::vec::Vec { + ::std::mem::replace(&mut self.ciphertext2, ::std::vec::Vec::new()) + } +} + +impl ::protobuf::Message for CipherPoints { + fn is_initialized(&self) -> bool { + true + } + + fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { + while !is.eof()? { + let (field_number, wire_type) = is.read_tag_unpack()?; + match field_number { + 1 => { + ::protobuf::rt::read_singular_proto3_bytes_into(wire_type, is, &mut self.ciphertext1)?; + }, + 2 => { + ::protobuf::rt::read_singular_proto3_bytes_into(wire_type, is, &mut self.ciphertext2)?; + }, + _ => { + ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; + }, + }; + } + ::std::result::Result::Ok(()) + } + + // Compute sizes of nested messages + #[allow(unused_variables)] + fn compute_size(&self) -> u32 { + let mut my_size = 0; + if !self.ciphertext1.is_empty() { + my_size += ::protobuf::rt::bytes_size(1, &self.ciphertext1); + } + if !self.ciphertext2.is_empty() { + my_size += ::protobuf::rt::bytes_size(2, &self.ciphertext2); + } + my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); + self.cached_size.set(my_size); + my_size + } + + fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { + if !self.ciphertext1.is_empty() { + os.write_bytes(1, &self.ciphertext1)?; + } + if !self.ciphertext2.is_empty() { + os.write_bytes(2, &self.ciphertext2)?; + } + os.write_unknown_fields(self.get_unknown_fields())?; + ::std::result::Result::Ok(()) + } + + fn get_cached_size(&self) -> u32 { + self.cached_size.get() + } + + fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { + &self.unknown_fields + } + + fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { + &mut self.unknown_fields + } + + fn as_any(&self) -> &dyn (::std::any::Any) { + self as &dyn (::std::any::Any) + } + fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { + self as &mut dyn (::std::any::Any) + } + fn into_any(self: ::std::boxed::Box) -> ::std::boxed::Box { + self + } + + fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { + Self::descriptor_static() + } + + fn new() -> CipherPoints { + CipherPoints::new() + } + + fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { + static descriptor: ::protobuf::rt::LazyV2<::protobuf::reflect::MessageDescriptor> = ::protobuf::rt::LazyV2::INIT; + descriptor.get(|| { + let mut fields = ::std::vec::Vec::new(); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( + "ciphertext1", + |m: &CipherPoints| { &m.ciphertext1 }, + |m: &mut CipherPoints| { &mut m.ciphertext1 }, + )); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( + "ciphertext2", + |m: &CipherPoints| { &m.ciphertext2 }, + |m: &mut CipherPoints| { &mut m.ciphertext2 }, + )); + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "CipherPoints", + fields, + file_descriptor_proto() + ) + }) + } + + fn default_instance() -> &'static CipherPoints { + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(CipherPoints::new) + } +} + +impl ::protobuf::Clear for CipherPoints { + fn clear(&mut self) { + self.ciphertext1.clear(); + self.ciphertext2.clear(); + self.unknown_fields.clear(); + } +} + +impl ::std::fmt::Debug for CipherPoints { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + ::protobuf::text_format::fmt(self, f) + } +} + +impl ::protobuf::reflect::ProtobufValue for CipherPoints { + fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { + ::protobuf::reflect::ReflectValueRef::Message(self) + } +} + +#[derive(PartialEq,Clone,Default)] +pub struct CountingPart { + // message fields + pub counter_id: ::std::string::String, + pub blinding_c2: ::std::vec::Vec, + pub equality_proof: ::std::vec::Vec, + // special fields + pub unknown_fields: ::protobuf::UnknownFields, + pub cached_size: ::protobuf::CachedSize, +} + +impl<'a> ::std::default::Default for &'a CountingPart { + fn default() -> &'a CountingPart { + ::default_instance() + } +} + +impl CountingPart { + pub fn new() -> CountingPart { + ::std::default::Default::default() + } + + // string counter_id = 1; + + + pub fn get_counter_id(&self) -> &str { + &self.counter_id + } + pub fn clear_counter_id(&mut self) { + self.counter_id.clear(); + } + + // Param is passed by value, moved + pub fn set_counter_id(&mut self, v: ::std::string::String) { + self.counter_id = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_counter_id(&mut self) -> &mut ::std::string::String { + &mut self.counter_id + } + + // Take field + pub fn take_counter_id(&mut self) -> ::std::string::String { + ::std::mem::replace(&mut self.counter_id, ::std::string::String::new()) + } + + // bytes blinding_c2 = 2; + + + pub fn get_blinding_c2(&self) -> &[u8] { + &self.blinding_c2 + } + pub fn clear_blinding_c2(&mut self) { + self.blinding_c2.clear(); + } + + // Param is passed by value, moved + pub fn set_blinding_c2(&mut self, v: ::std::vec::Vec) { + self.blinding_c2 = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_blinding_c2(&mut self) -> &mut ::std::vec::Vec { + &mut self.blinding_c2 + } + + // Take field + pub fn take_blinding_c2(&mut self) -> ::std::vec::Vec { + ::std::mem::replace(&mut self.blinding_c2, ::std::vec::Vec::new()) + } + + // bytes equality_proof = 3; + + + pub fn get_equality_proof(&self) -> &[u8] { + &self.equality_proof + } + pub fn clear_equality_proof(&mut self) { + self.equality_proof.clear(); + } + + // Param is passed by value, moved + pub fn set_equality_proof(&mut self, v: ::std::vec::Vec) { + self.equality_proof = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_equality_proof(&mut self) -> &mut ::std::vec::Vec { + &mut self.equality_proof + } + + // Take field + pub fn take_equality_proof(&mut self) -> ::std::vec::Vec { + ::std::mem::replace(&mut self.equality_proof, ::std::vec::Vec::new()) + } +} + +impl ::protobuf::Message for CountingPart { + fn is_initialized(&self) -> bool { + true + } + + fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { + while !is.eof()? { + let (field_number, wire_type) = is.read_tag_unpack()?; + match field_number { + 1 => { + ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.counter_id)?; + }, + 2 => { + ::protobuf::rt::read_singular_proto3_bytes_into(wire_type, is, &mut self.blinding_c2)?; + }, + 3 => { + ::protobuf::rt::read_singular_proto3_bytes_into(wire_type, is, &mut self.equality_proof)?; + }, + _ => { + ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; + }, + }; + } + ::std::result::Result::Ok(()) + } + + // Compute sizes of nested messages + #[allow(unused_variables)] + fn compute_size(&self) -> u32 { + let mut my_size = 0; + if !self.counter_id.is_empty() { + my_size += ::protobuf::rt::string_size(1, &self.counter_id); + } + if !self.blinding_c2.is_empty() { + my_size += ::protobuf::rt::bytes_size(2, &self.blinding_c2); + } + if !self.equality_proof.is_empty() { + my_size += ::protobuf::rt::bytes_size(3, &self.equality_proof); + } + my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); + self.cached_size.set(my_size); + my_size + } + + fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { + if !self.counter_id.is_empty() { + os.write_string(1, &self.counter_id)?; + } + if !self.blinding_c2.is_empty() { + os.write_bytes(2, &self.blinding_c2)?; + } + if !self.equality_proof.is_empty() { + os.write_bytes(3, &self.equality_proof)?; + } + os.write_unknown_fields(self.get_unknown_fields())?; + ::std::result::Result::Ok(()) + } + + fn get_cached_size(&self) -> u32 { + self.cached_size.get() + } + + fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { + &self.unknown_fields + } + + fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { + &mut self.unknown_fields + } + + fn as_any(&self) -> &dyn (::std::any::Any) { + self as &dyn (::std::any::Any) + } + fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { + self as &mut dyn (::std::any::Any) + } + fn into_any(self: ::std::boxed::Box) -> ::std::boxed::Box { + self + } + + fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { + Self::descriptor_static() + } + + fn new() -> CountingPart { + CountingPart::new() + } + + fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { + static descriptor: ::protobuf::rt::LazyV2<::protobuf::reflect::MessageDescriptor> = ::protobuf::rt::LazyV2::INIT; + descriptor.get(|| { + let mut fields = ::std::vec::Vec::new(); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( + "counter_id", + |m: &CountingPart| { &m.counter_id }, + |m: &mut CountingPart| { &mut m.counter_id }, + )); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( + "blinding_c2", + |m: &CountingPart| { &m.blinding_c2 }, + |m: &mut CountingPart| { &mut m.blinding_c2 }, + )); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( + "equality_proof", + |m: &CountingPart| { &m.equality_proof }, + |m: &mut CountingPart| { &mut m.equality_proof }, + )); + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "CountingPart", + fields, + file_descriptor_proto() + ) + }) + } + + fn default_instance() -> &'static CountingPart { + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(CountingPart::new) + } +} + +impl ::protobuf::Clear for CountingPart { + fn clear(&mut self) { + self.counter_id.clear(); + self.blinding_c2.clear(); + self.equality_proof.clear(); + self.unknown_fields.clear(); + } +} + +impl ::std::fmt::Debug for CountingPart { fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { ::protobuf::text_format::fmt(self, f) } @@ -3777,47 +4985,298 @@ impl StringToCountingPartPair { } // Take field - pub fn take_key(&mut self) -> ::std::string::String { - ::std::mem::replace(&mut self.key, ::std::string::String::new()) + pub fn take_key(&mut self) -> ::std::string::String { + ::std::mem::replace(&mut self.key, ::std::string::String::new()) + } + + // .com.webank.wedpr.acv.proto.CountingPart value = 2; + + + pub fn get_value(&self) -> &CountingPart { + self.value.as_ref().unwrap_or_else(|| ::default_instance()) + } + pub fn clear_value(&mut self) { + self.value.clear(); + } + + pub fn has_value(&self) -> bool { + self.value.is_some() + } + + // Param is passed by value, moved + pub fn set_value(&mut self, v: CountingPart) { + self.value = ::protobuf::SingularPtrField::some(v); + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_value(&mut self) -> &mut CountingPart { + if self.value.is_none() { + self.value.set_default(); + } + self.value.as_mut().unwrap() + } + + // Take field + pub fn take_value(&mut self) -> CountingPart { + self.value.take().unwrap_or_else(|| CountingPart::new()) + } +} + +impl ::protobuf::Message for StringToCountingPartPair { + fn is_initialized(&self) -> bool { + for v in &self.value { + if !v.is_initialized() { + return false; + } + }; + true + } + + fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { + while !is.eof()? { + let (field_number, wire_type) = is.read_tag_unpack()?; + match field_number { + 1 => { + ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.key)?; + }, + 2 => { + ::protobuf::rt::read_singular_message_into(wire_type, is, &mut self.value)?; + }, + _ => { + ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; + }, + }; + } + ::std::result::Result::Ok(()) + } + + // Compute sizes of nested messages + #[allow(unused_variables)] + fn compute_size(&self) -> u32 { + let mut my_size = 0; + if !self.key.is_empty() { + my_size += ::protobuf::rt::string_size(1, &self.key); + } + if let Some(ref v) = self.value.as_ref() { + let len = v.compute_size(); + my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; + } + my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); + self.cached_size.set(my_size); + my_size + } + + fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { + if !self.key.is_empty() { + os.write_string(1, &self.key)?; + } + if let Some(ref v) = self.value.as_ref() { + os.write_tag(2, ::protobuf::wire_format::WireTypeLengthDelimited)?; + os.write_raw_varint32(v.get_cached_size())?; + v.write_to_with_cached_sizes(os)?; + } + os.write_unknown_fields(self.get_unknown_fields())?; + ::std::result::Result::Ok(()) + } + + fn get_cached_size(&self) -> u32 { + self.cached_size.get() + } + + fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { + &self.unknown_fields + } + + fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { + &mut self.unknown_fields + } + + fn as_any(&self) -> &dyn (::std::any::Any) { + self as &dyn (::std::any::Any) + } + fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { + self as &mut dyn (::std::any::Any) + } + fn into_any(self: ::std::boxed::Box) -> ::std::boxed::Box { + self + } + + fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { + Self::descriptor_static() + } + + fn new() -> StringToCountingPartPair { + StringToCountingPartPair::new() + } + + fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { + static descriptor: ::protobuf::rt::LazyV2<::protobuf::reflect::MessageDescriptor> = ::protobuf::rt::LazyV2::INIT; + descriptor.get(|| { + let mut fields = ::std::vec::Vec::new(); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( + "key", + |m: &StringToCountingPartPair| { &m.key }, + |m: &mut StringToCountingPartPair| { &mut m.key }, + )); + fields.push(::protobuf::reflect::accessor::make_singular_ptr_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( + "value", + |m: &StringToCountingPartPair| { &m.value }, + |m: &mut StringToCountingPartPair| { &mut m.value }, + )); + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "StringToCountingPartPair", + fields, + file_descriptor_proto() + ) + }) + } + + fn default_instance() -> &'static StringToCountingPartPair { + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(StringToCountingPartPair::new) + } +} + +impl ::protobuf::Clear for StringToCountingPartPair { + fn clear(&mut self) { + self.key.clear(); + self.value.clear(); + self.unknown_fields.clear(); + } +} + +impl ::std::fmt::Debug for StringToCountingPartPair { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + ::protobuf::text_format::fmt(self, f) + } +} + +impl ::protobuf::reflect::ProtobufValue for StringToCountingPartPair { + fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { + ::protobuf::reflect::ReflectValueRef::Message(self) + } +} + +#[derive(PartialEq,Clone,Default)] +pub struct DecryptedResultPartStorage { + // message fields + pub blank_part: ::protobuf::SingularPtrField, + pub candidate_part: ::protobuf::RepeatedField, + pub unlisted_candidate_part: ::protobuf::RepeatedField, + // special fields + pub unknown_fields: ::protobuf::UnknownFields, + pub cached_size: ::protobuf::CachedSize, +} + +impl<'a> ::std::default::Default for &'a DecryptedResultPartStorage { + fn default() -> &'a DecryptedResultPartStorage { + ::default_instance() + } +} + +impl DecryptedResultPartStorage { + pub fn new() -> DecryptedResultPartStorage { + ::std::default::Default::default() + } + + // .com.webank.wedpr.acv.proto.CountingPart blank_part = 1; + + + pub fn get_blank_part(&self) -> &CountingPart { + self.blank_part.as_ref().unwrap_or_else(|| ::default_instance()) + } + pub fn clear_blank_part(&mut self) { + self.blank_part.clear(); + } + + pub fn has_blank_part(&self) -> bool { + self.blank_part.is_some() + } + + // Param is passed by value, moved + pub fn set_blank_part(&mut self, v: CountingPart) { + self.blank_part = ::protobuf::SingularPtrField::some(v); + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_blank_part(&mut self) -> &mut CountingPart { + if self.blank_part.is_none() { + self.blank_part.set_default(); + } + self.blank_part.as_mut().unwrap() + } + + // Take field + pub fn take_blank_part(&mut self) -> CountingPart { + self.blank_part.take().unwrap_or_else(|| CountingPart::new()) + } + + // repeated .com.webank.wedpr.acv.proto.StringToCountingPartPair candidate_part = 2; + + + pub fn get_candidate_part(&self) -> &[StringToCountingPartPair] { + &self.candidate_part + } + pub fn clear_candidate_part(&mut self) { + self.candidate_part.clear(); + } + + // Param is passed by value, moved + pub fn set_candidate_part(&mut self, v: ::protobuf::RepeatedField) { + self.candidate_part = v; + } + + // Mutable pointer to the field. + pub fn mut_candidate_part(&mut self) -> &mut ::protobuf::RepeatedField { + &mut self.candidate_part + } + + // Take field + pub fn take_candidate_part(&mut self) -> ::protobuf::RepeatedField { + ::std::mem::replace(&mut self.candidate_part, ::protobuf::RepeatedField::new()) } - // .com.webank.wedpr.acv.proto.CountingPart value = 2; + // repeated .com.webank.wedpr.acv.proto.UnlistedBallotDecryptedResult unlisted_candidate_part = 3; - pub fn get_value(&self) -> &CountingPart { - self.value.as_ref().unwrap_or_else(|| ::default_instance()) - } - pub fn clear_value(&mut self) { - self.value.clear(); + pub fn get_unlisted_candidate_part(&self) -> &[UnlistedBallotDecryptedResult] { + &self.unlisted_candidate_part } - - pub fn has_value(&self) -> bool { - self.value.is_some() + pub fn clear_unlisted_candidate_part(&mut self) { + self.unlisted_candidate_part.clear(); } // Param is passed by value, moved - pub fn set_value(&mut self, v: CountingPart) { - self.value = ::protobuf::SingularPtrField::some(v); + pub fn set_unlisted_candidate_part(&mut self, v: ::protobuf::RepeatedField) { + self.unlisted_candidate_part = v; } // Mutable pointer to the field. - // If field is not initialized, it is initialized with default value first. - pub fn mut_value(&mut self) -> &mut CountingPart { - if self.value.is_none() { - self.value.set_default(); - } - self.value.as_mut().unwrap() + pub fn mut_unlisted_candidate_part(&mut self) -> &mut ::protobuf::RepeatedField { + &mut self.unlisted_candidate_part } // Take field - pub fn take_value(&mut self) -> CountingPart { - self.value.take().unwrap_or_else(|| CountingPart::new()) + pub fn take_unlisted_candidate_part(&mut self) -> ::protobuf::RepeatedField { + ::std::mem::replace(&mut self.unlisted_candidate_part, ::protobuf::RepeatedField::new()) } } -impl ::protobuf::Message for StringToCountingPartPair { +impl ::protobuf::Message for DecryptedResultPartStorage { fn is_initialized(&self) -> bool { - for v in &self.value { + for v in &self.blank_part { + if !v.is_initialized() { + return false; + } + }; + for v in &self.candidate_part { + if !v.is_initialized() { + return false; + } + }; + for v in &self.unlisted_candidate_part { if !v.is_initialized() { return false; } @@ -3830,10 +5289,13 @@ impl ::protobuf::Message for StringToCountingPartPair { let (field_number, wire_type) = is.read_tag_unpack()?; match field_number { 1 => { - ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.key)?; + ::protobuf::rt::read_singular_message_into(wire_type, is, &mut self.blank_part)?; }, 2 => { - ::protobuf::rt::read_singular_message_into(wire_type, is, &mut self.value)?; + ::protobuf::rt::read_repeated_message_into(wire_type, is, &mut self.candidate_part)?; + }, + 3 => { + ::protobuf::rt::read_repeated_message_into(wire_type, is, &mut self.unlisted_candidate_part)?; }, _ => { ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; @@ -3847,27 +5309,39 @@ impl ::protobuf::Message for StringToCountingPartPair { #[allow(unused_variables)] fn compute_size(&self) -> u32 { let mut my_size = 0; - if !self.key.is_empty() { - my_size += ::protobuf::rt::string_size(1, &self.key); - } - if let Some(ref v) = self.value.as_ref() { + if let Some(ref v) = self.blank_part.as_ref() { let len = v.compute_size(); my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; } + for value in &self.candidate_part { + let len = value.compute_size(); + my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; + }; + for value in &self.unlisted_candidate_part { + let len = value.compute_size(); + my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; + }; my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); self.cached_size.set(my_size); my_size } fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { - if !self.key.is_empty() { - os.write_string(1, &self.key)?; + if let Some(ref v) = self.blank_part.as_ref() { + os.write_tag(1, ::protobuf::wire_format::WireTypeLengthDelimited)?; + os.write_raw_varint32(v.get_cached_size())?; + v.write_to_with_cached_sizes(os)?; } - if let Some(ref v) = self.value.as_ref() { + for v in &self.candidate_part { os.write_tag(2, ::protobuf::wire_format::WireTypeLengthDelimited)?; os.write_raw_varint32(v.get_cached_size())?; v.write_to_with_cached_sizes(os)?; - } + }; + for v in &self.unlisted_candidate_part { + os.write_tag(3, ::protobuf::wire_format::WireTypeLengthDelimited)?; + os.write_raw_varint32(v.get_cached_size())?; + v.write_to_with_cached_sizes(os)?; + }; os.write_unknown_fields(self.get_unknown_fields())?; ::std::result::Result::Ok(()) } @@ -3898,146 +5372,207 @@ impl ::protobuf::Message for StringToCountingPartPair { Self::descriptor_static() } - fn new() -> StringToCountingPartPair { - StringToCountingPartPair::new() + fn new() -> DecryptedResultPartStorage { + DecryptedResultPartStorage::new() } fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { static descriptor: ::protobuf::rt::LazyV2<::protobuf::reflect::MessageDescriptor> = ::protobuf::rt::LazyV2::INIT; descriptor.get(|| { let mut fields = ::std::vec::Vec::new(); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( - "key", - |m: &StringToCountingPartPair| { &m.key }, - |m: &mut StringToCountingPartPair| { &mut m.key }, - )); fields.push(::protobuf::reflect::accessor::make_singular_ptr_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( - "value", - |m: &StringToCountingPartPair| { &m.value }, - |m: &mut StringToCountingPartPair| { &mut m.value }, + "blank_part", + |m: &DecryptedResultPartStorage| { &m.blank_part }, + |m: &mut DecryptedResultPartStorage| { &mut m.blank_part }, )); - ::protobuf::reflect::MessageDescriptor::new_pb_name::( - "StringToCountingPartPair", + fields.push(::protobuf::reflect::accessor::make_repeated_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( + "candidate_part", + |m: &DecryptedResultPartStorage| { &m.candidate_part }, + |m: &mut DecryptedResultPartStorage| { &mut m.candidate_part }, + )); + fields.push(::protobuf::reflect::accessor::make_repeated_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( + "unlisted_candidate_part", + |m: &DecryptedResultPartStorage| { &m.unlisted_candidate_part }, + |m: &mut DecryptedResultPartStorage| { &mut m.unlisted_candidate_part }, + )); + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "DecryptedResultPartStorage", fields, file_descriptor_proto() ) }) } - fn default_instance() -> &'static StringToCountingPartPair { - static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; - instance.get(StringToCountingPartPair::new) + fn default_instance() -> &'static DecryptedResultPartStorage { + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(DecryptedResultPartStorage::new) } } -impl ::protobuf::Clear for StringToCountingPartPair { +impl ::protobuf::Clear for DecryptedResultPartStorage { fn clear(&mut self) { - self.key.clear(); - self.value.clear(); + self.blank_part.clear(); + self.candidate_part.clear(); + self.unlisted_candidate_part.clear(); self.unknown_fields.clear(); } } -impl ::std::fmt::Debug for StringToCountingPartPair { +impl ::std::fmt::Debug for DecryptedResultPartStorage { fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { ::protobuf::text_format::fmt(self, f) } } -impl ::protobuf::reflect::ProtobufValue for StringToCountingPartPair { +impl ::protobuf::reflect::ProtobufValue for DecryptedResultPartStorage { fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { ::protobuf::reflect::ReflectValueRef::Message(self) } } #[derive(PartialEq,Clone,Default)] -pub struct DecryptedResultPartStorage { +pub struct UnlistedBallotDecryptedResult { // message fields - pub blank_part: ::protobuf::SingularPtrField, - pub candidate_part: ::protobuf::RepeatedField, + pub candidate: i64, + pub candidate_cipher: ::protobuf::SingularPtrField, + pub decrypted_unlisted_candidate: ::protobuf::SingularPtrField, + pub decrypted_unlisted_candidate_ballot: ::protobuf::RepeatedField, // special fields pub unknown_fields: ::protobuf::UnknownFields, pub cached_size: ::protobuf::CachedSize, } -impl<'a> ::std::default::Default for &'a DecryptedResultPartStorage { - fn default() -> &'a DecryptedResultPartStorage { - ::default_instance() +impl<'a> ::std::default::Default for &'a UnlistedBallotDecryptedResult { + fn default() -> &'a UnlistedBallotDecryptedResult { + ::default_instance() } } -impl DecryptedResultPartStorage { - pub fn new() -> DecryptedResultPartStorage { +impl UnlistedBallotDecryptedResult { + pub fn new() -> UnlistedBallotDecryptedResult { ::std::default::Default::default() } - // .com.webank.wedpr.acv.proto.CountingPart blank_part = 1; + // int64 candidate = 1; - pub fn get_blank_part(&self) -> &CountingPart { - self.blank_part.as_ref().unwrap_or_else(|| ::default_instance()) + pub fn get_candidate(&self) -> i64 { + self.candidate } - pub fn clear_blank_part(&mut self) { - self.blank_part.clear(); + pub fn clear_candidate(&mut self) { + self.candidate = 0; } - pub fn has_blank_part(&self) -> bool { - self.blank_part.is_some() + // Param is passed by value, moved + pub fn set_candidate(&mut self, v: i64) { + self.candidate = v; + } + + // .com.webank.wedpr.acv.proto.CipherPoints candidate_cipher = 2; + + + pub fn get_candidate_cipher(&self) -> &CipherPoints { + self.candidate_cipher.as_ref().unwrap_or_else(|| ::default_instance()) + } + pub fn clear_candidate_cipher(&mut self) { + self.candidate_cipher.clear(); + } + + pub fn has_candidate_cipher(&self) -> bool { + self.candidate_cipher.is_some() } // Param is passed by value, moved - pub fn set_blank_part(&mut self, v: CountingPart) { - self.blank_part = ::protobuf::SingularPtrField::some(v); + pub fn set_candidate_cipher(&mut self, v: CipherPoints) { + self.candidate_cipher = ::protobuf::SingularPtrField::some(v); } // Mutable pointer to the field. // If field is not initialized, it is initialized with default value first. - pub fn mut_blank_part(&mut self) -> &mut CountingPart { - if self.blank_part.is_none() { - self.blank_part.set_default(); + pub fn mut_candidate_cipher(&mut self) -> &mut CipherPoints { + if self.candidate_cipher.is_none() { + self.candidate_cipher.set_default(); } - self.blank_part.as_mut().unwrap() + self.candidate_cipher.as_mut().unwrap() } // Take field - pub fn take_blank_part(&mut self) -> CountingPart { - self.blank_part.take().unwrap_or_else(|| CountingPart::new()) + pub fn take_candidate_cipher(&mut self) -> CipherPoints { + self.candidate_cipher.take().unwrap_or_else(|| CipherPoints::new()) } - // repeated .com.webank.wedpr.acv.proto.StringToCountingPartPair candidate_part = 2; + // .com.webank.wedpr.acv.proto.CountingPart decrypted_unlisted_candidate = 4; - pub fn get_candidate_part(&self) -> &[StringToCountingPartPair] { - &self.candidate_part + pub fn get_decrypted_unlisted_candidate(&self) -> &CountingPart { + self.decrypted_unlisted_candidate.as_ref().unwrap_or_else(|| ::default_instance()) } - pub fn clear_candidate_part(&mut self) { - self.candidate_part.clear(); + pub fn clear_decrypted_unlisted_candidate(&mut self) { + self.decrypted_unlisted_candidate.clear(); + } + + pub fn has_decrypted_unlisted_candidate(&self) -> bool { + self.decrypted_unlisted_candidate.is_some() } // Param is passed by value, moved - pub fn set_candidate_part(&mut self, v: ::protobuf::RepeatedField) { - self.candidate_part = v; + pub fn set_decrypted_unlisted_candidate(&mut self, v: CountingPart) { + self.decrypted_unlisted_candidate = ::protobuf::SingularPtrField::some(v); } // Mutable pointer to the field. - pub fn mut_candidate_part(&mut self) -> &mut ::protobuf::RepeatedField { - &mut self.candidate_part + // If field is not initialized, it is initialized with default value first. + pub fn mut_decrypted_unlisted_candidate(&mut self) -> &mut CountingPart { + if self.decrypted_unlisted_candidate.is_none() { + self.decrypted_unlisted_candidate.set_default(); + } + self.decrypted_unlisted_candidate.as_mut().unwrap() } // Take field - pub fn take_candidate_part(&mut self) -> ::protobuf::RepeatedField { - ::std::mem::replace(&mut self.candidate_part, ::protobuf::RepeatedField::new()) + pub fn take_decrypted_unlisted_candidate(&mut self) -> CountingPart { + self.decrypted_unlisted_candidate.take().unwrap_or_else(|| CountingPart::new()) + } + + // repeated .com.webank.wedpr.acv.proto.CountingPart decrypted_unlisted_candidate_ballot = 5; + + + pub fn get_decrypted_unlisted_candidate_ballot(&self) -> &[CountingPart] { + &self.decrypted_unlisted_candidate_ballot + } + pub fn clear_decrypted_unlisted_candidate_ballot(&mut self) { + self.decrypted_unlisted_candidate_ballot.clear(); + } + + // Param is passed by value, moved + pub fn set_decrypted_unlisted_candidate_ballot(&mut self, v: ::protobuf::RepeatedField) { + self.decrypted_unlisted_candidate_ballot = v; + } + + // Mutable pointer to the field. + pub fn mut_decrypted_unlisted_candidate_ballot(&mut self) -> &mut ::protobuf::RepeatedField { + &mut self.decrypted_unlisted_candidate_ballot + } + + // Take field + pub fn take_decrypted_unlisted_candidate_ballot(&mut self) -> ::protobuf::RepeatedField { + ::std::mem::replace(&mut self.decrypted_unlisted_candidate_ballot, ::protobuf::RepeatedField::new()) } } -impl ::protobuf::Message for DecryptedResultPartStorage { +impl ::protobuf::Message for UnlistedBallotDecryptedResult { fn is_initialized(&self) -> bool { - for v in &self.blank_part { + for v in &self.candidate_cipher { if !v.is_initialized() { return false; } }; - for v in &self.candidate_part { + for v in &self.decrypted_unlisted_candidate { + if !v.is_initialized() { + return false; + } + }; + for v in &self.decrypted_unlisted_candidate_ballot { if !v.is_initialized() { return false; } @@ -4050,10 +5585,20 @@ impl ::protobuf::Message for DecryptedResultPartStorage { let (field_number, wire_type) = is.read_tag_unpack()?; match field_number { 1 => { - ::protobuf::rt::read_singular_message_into(wire_type, is, &mut self.blank_part)?; + if wire_type != ::protobuf::wire_format::WireTypeVarint { + return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); + } + let tmp = is.read_int64()?; + self.candidate = tmp; }, 2 => { - ::protobuf::rt::read_repeated_message_into(wire_type, is, &mut self.candidate_part)?; + ::protobuf::rt::read_singular_message_into(wire_type, is, &mut self.candidate_cipher)?; + }, + 4 => { + ::protobuf::rt::read_singular_message_into(wire_type, is, &mut self.decrypted_unlisted_candidate)?; + }, + 5 => { + ::protobuf::rt::read_repeated_message_into(wire_type, is, &mut self.decrypted_unlisted_candidate_ballot)?; }, _ => { ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; @@ -4067,11 +5612,18 @@ impl ::protobuf::Message for DecryptedResultPartStorage { #[allow(unused_variables)] fn compute_size(&self) -> u32 { let mut my_size = 0; - if let Some(ref v) = self.blank_part.as_ref() { + if self.candidate != 0 { + my_size += ::protobuf::rt::value_size(1, self.candidate, ::protobuf::wire_format::WireTypeVarint); + } + if let Some(ref v) = self.candidate_cipher.as_ref() { let len = v.compute_size(); my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; } - for value in &self.candidate_part { + if let Some(ref v) = self.decrypted_unlisted_candidate.as_ref() { + let len = v.compute_size(); + my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; + } + for value in &self.decrypted_unlisted_candidate_ballot { let len = value.compute_size(); my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; }; @@ -4081,13 +5633,21 @@ impl ::protobuf::Message for DecryptedResultPartStorage { } fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { - if let Some(ref v) = self.blank_part.as_ref() { - os.write_tag(1, ::protobuf::wire_format::WireTypeLengthDelimited)?; + if self.candidate != 0 { + os.write_int64(1, self.candidate)?; + } + if let Some(ref v) = self.candidate_cipher.as_ref() { + os.write_tag(2, ::protobuf::wire_format::WireTypeLengthDelimited)?; os.write_raw_varint32(v.get_cached_size())?; v.write_to_with_cached_sizes(os)?; } - for v in &self.candidate_part { - os.write_tag(2, ::protobuf::wire_format::WireTypeLengthDelimited)?; + if let Some(ref v) = self.decrypted_unlisted_candidate.as_ref() { + os.write_tag(4, ::protobuf::wire_format::WireTypeLengthDelimited)?; + os.write_raw_varint32(v.get_cached_size())?; + v.write_to_with_cached_sizes(os)?; + } + for v in &self.decrypted_unlisted_candidate_ballot { + os.write_tag(5, ::protobuf::wire_format::WireTypeLengthDelimited)?; os.write_raw_varint32(v.get_cached_size())?; v.write_to_with_cached_sizes(os)?; }; @@ -4121,53 +5681,65 @@ impl ::protobuf::Message for DecryptedResultPartStorage { Self::descriptor_static() } - fn new() -> DecryptedResultPartStorage { - DecryptedResultPartStorage::new() + fn new() -> UnlistedBallotDecryptedResult { + UnlistedBallotDecryptedResult::new() } fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { static descriptor: ::protobuf::rt::LazyV2<::protobuf::reflect::MessageDescriptor> = ::protobuf::rt::LazyV2::INIT; descriptor.get(|| { let mut fields = ::std::vec::Vec::new(); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeInt64>( + "candidate", + |m: &UnlistedBallotDecryptedResult| { &m.candidate }, + |m: &mut UnlistedBallotDecryptedResult| { &mut m.candidate }, + )); + fields.push(::protobuf::reflect::accessor::make_singular_ptr_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( + "candidate_cipher", + |m: &UnlistedBallotDecryptedResult| { &m.candidate_cipher }, + |m: &mut UnlistedBallotDecryptedResult| { &mut m.candidate_cipher }, + )); fields.push(::protobuf::reflect::accessor::make_singular_ptr_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( - "blank_part", - |m: &DecryptedResultPartStorage| { &m.blank_part }, - |m: &mut DecryptedResultPartStorage| { &mut m.blank_part }, + "decrypted_unlisted_candidate", + |m: &UnlistedBallotDecryptedResult| { &m.decrypted_unlisted_candidate }, + |m: &mut UnlistedBallotDecryptedResult| { &mut m.decrypted_unlisted_candidate }, )); - fields.push(::protobuf::reflect::accessor::make_repeated_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( - "candidate_part", - |m: &DecryptedResultPartStorage| { &m.candidate_part }, - |m: &mut DecryptedResultPartStorage| { &mut m.candidate_part }, + fields.push(::protobuf::reflect::accessor::make_repeated_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( + "decrypted_unlisted_candidate_ballot", + |m: &UnlistedBallotDecryptedResult| { &m.decrypted_unlisted_candidate_ballot }, + |m: &mut UnlistedBallotDecryptedResult| { &mut m.decrypted_unlisted_candidate_ballot }, )); - ::protobuf::reflect::MessageDescriptor::new_pb_name::( - "DecryptedResultPartStorage", + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "UnlistedBallotDecryptedResult", fields, file_descriptor_proto() ) }) } - fn default_instance() -> &'static DecryptedResultPartStorage { - static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; - instance.get(DecryptedResultPartStorage::new) + fn default_instance() -> &'static UnlistedBallotDecryptedResult { + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(UnlistedBallotDecryptedResult::new) } } -impl ::protobuf::Clear for DecryptedResultPartStorage { +impl ::protobuf::Clear for UnlistedBallotDecryptedResult { fn clear(&mut self) { - self.blank_part.clear(); - self.candidate_part.clear(); + self.candidate = 0; + self.candidate_cipher.clear(); + self.decrypted_unlisted_candidate.clear(); + self.decrypted_unlisted_candidate_ballot.clear(); self.unknown_fields.clear(); } } -impl ::std::fmt::Debug for DecryptedResultPartStorage { +impl ::std::fmt::Debug for UnlistedBallotDecryptedResult { fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { ::protobuf::text_format::fmt(self, f) } } -impl ::protobuf::reflect::ProtobufValue for DecryptedResultPartStorage { +impl ::protobuf::reflect::ProtobufValue for UnlistedBallotDecryptedResult { fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { ::protobuf::reflect::ReflectValueRef::Message(self) } @@ -4177,6 +5749,7 @@ impl ::protobuf::reflect::ProtobufValue for DecryptedResultPartStorage { pub struct VoteResultStorage { // message fields pub result: ::protobuf::RepeatedField, + pub unlisted_result: ::protobuf::RepeatedField, // special fields pub unknown_fields: ::protobuf::UnknownFields, pub cached_size: ::protobuf::CachedSize, @@ -4217,6 +5790,31 @@ impl VoteResultStorage { pub fn take_result(&mut self) -> ::protobuf::RepeatedField { ::std::mem::replace(&mut self.result, ::protobuf::RepeatedField::new()) } + + // repeated .com.webank.wedpr.acv.proto.UnlistedVoteChoice unlisted_result = 2; + + + pub fn get_unlisted_result(&self) -> &[UnlistedVoteChoice] { + &self.unlisted_result + } + pub fn clear_unlisted_result(&mut self) { + self.unlisted_result.clear(); + } + + // Param is passed by value, moved + pub fn set_unlisted_result(&mut self, v: ::protobuf::RepeatedField) { + self.unlisted_result = v; + } + + // Mutable pointer to the field. + pub fn mut_unlisted_result(&mut self) -> &mut ::protobuf::RepeatedField { + &mut self.unlisted_result + } + + // Take field + pub fn take_unlisted_result(&mut self) -> ::protobuf::RepeatedField { + ::std::mem::replace(&mut self.unlisted_result, ::protobuf::RepeatedField::new()) + } } impl ::protobuf::Message for VoteResultStorage { @@ -4226,6 +5824,11 @@ impl ::protobuf::Message for VoteResultStorage { return false; } }; + for v in &self.unlisted_result { + if !v.is_initialized() { + return false; + } + }; true } @@ -4236,6 +5839,9 @@ impl ::protobuf::Message for VoteResultStorage { 1 => { ::protobuf::rt::read_repeated_message_into(wire_type, is, &mut self.result)?; }, + 2 => { + ::protobuf::rt::read_repeated_message_into(wire_type, is, &mut self.unlisted_result)?; + }, _ => { ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; }, @@ -4252,6 +5858,10 @@ impl ::protobuf::Message for VoteResultStorage { let len = value.compute_size(); my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; }; + for value in &self.unlisted_result { + let len = value.compute_size(); + my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; + }; my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); self.cached_size.set(my_size); my_size @@ -4263,6 +5873,11 @@ impl ::protobuf::Message for VoteResultStorage { os.write_raw_varint32(v.get_cached_size())?; v.write_to_with_cached_sizes(os)?; }; + for v in &self.unlisted_result { + os.write_tag(2, ::protobuf::wire_format::WireTypeLengthDelimited)?; + os.write_raw_varint32(v.get_cached_size())?; + v.write_to_with_cached_sizes(os)?; + }; os.write_unknown_fields(self.get_unknown_fields())?; ::std::result::Result::Ok(()) } @@ -4306,6 +5921,11 @@ impl ::protobuf::Message for VoteResultStorage { |m: &VoteResultStorage| { &m.result }, |m: &mut VoteResultStorage| { &mut m.result }, )); + fields.push(::protobuf::reflect::accessor::make_repeated_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( + "unlisted_result", + |m: &VoteResultStorage| { &m.unlisted_result }, + |m: &mut VoteResultStorage| { &mut m.unlisted_result }, + )); ::protobuf::reflect::MessageDescriptor::new_pb_name::( "VoteResultStorage", fields, @@ -4323,6 +5943,7 @@ impl ::protobuf::Message for VoteResultStorage { impl ::protobuf::Clear for VoteResultStorage { fn clear(&mut self) { self.result.clear(); + self.unlisted_result.clear(); self.unknown_fields.clear(); } } @@ -4540,54 +6161,85 @@ static file_descriptor_proto_data: &'static [u8] = b"\ \tpollPoint\x12I\n\ncandidates\x18\x02\x20\x01(\x0b2).com.webank.wedpr.a\ cv.proto.CandidateListR\ncandidates\";\n\rCounterSecret\x12*\n\x11poll_s\ ecret_share\x18\x01\x20\x01(\x0cR\x0fpollSecretShare\"0\n\x0bVoterSecret\ - \x12!\n\x0cvoter_secret\x18\x01\x20\x01(\x0cR\x0bvoterSecret\"o\n\x13Reg\ - istrationRequest\x12X\n\x0cweight_point\x18\x01\x20\x01(\x0b25.com.weban\ - k.wedpr.acv.proto.RegistrationBlindingPointR\x0bweightPoint\"\x7f\n\x19R\ - egistrationBlindingPoint\x12.\n\x13blinding_poll_point\x18\x01\x20\x01(\ - \x0cR\x11blindingPollPoint\x122\n\x15blinding_basepoint_g2\x18\x02\x20\ - \x01(\x0cR\x13blindingBasepointG2\"\x93\x01\n\x14RegistrationResponse\ - \x12!\n\x0cvoter_weight\x18\x01\x20\x01(\rR\x0bvoterWeight\x12:\n\x06bal\ - lot\x18\x02\x20\x01(\x0b2\".com.webank.wedpr.acv.proto.BallotR\x06ballot\ - \x12\x1c\n\tsignature\x18\x03\x20\x01(\x0cR\tsignature\"L\n\x06Ballot\ - \x12\x20\n\x0bciphertext1\x18\x01\x20\x01(\x0cR\x0bciphertext1\x12\x20\n\ - \x0bciphertext2\x18\x02\x20\x01(\x0cR\x0bciphertext2\"h\n\x1dCounterPara\ - metersShareRequest\x12\x1d\n\ncounter_id\x18\x01\x20\x01(\tR\tcounterId\ - \x12(\n\x10poll_point_share\x18\x02\x20\x01(\x0cR\x0epollPointShare\"\ - \x8f\x01\n\x18CounterParametersStorage\x12s\n\x18counter_parameters_shar\ - e\x18\x01\x20\x03(\x0b29.com.webank.wedpr.acv.proto.CounterParametersSha\ - reRequestR\x16counterParametersShare\"@\n\nVoteChoice\x12\x1c\n\tcandida\ - te\x18\x01\x20\x01(\tR\tcandidate\x12\x14\n\x05value\x18\x02\x20\x01(\rR\ - \x05value\"M\n\x0bVoteChoices\x12>\n\x06choice\x18\x01\x20\x03(\x0b2&.co\ - m.webank.wedpr.acv.proto.VoteChoiceR\x06choice\"k\n\x0fCandidateBallot\ - \x12\x1c\n\tcandidate\x18\x01\x20\x01(\tR\tcandidate\x12:\n\x06ballot\ - \x18\x02\x20\x01(\x0b2\".com.webank.wedpr.acv.proto.BallotR\x06ballot\"0\ - \n\x0bBallotProof\x12!\n\x0cformat_proof\x18\x01\x20\x01(\x0cR\x0bformat\ - Proof\"j\n\x17StringToBallotProofPair\x12\x10\n\x03key\x18\x01\x20\x01(\ - \tR\x03key\x12=\n\x05value\x18\x02\x20\x01(\x0b2'.com.webank.wedpr.acv.p\ - roto.BallotProofR\x05value\"\xef\x01\n\x0bVoteRequest\x12;\n\x04vote\x18\ - \x01\x20\x01(\x0b2'.com.webank.wedpr.acv.proto.VoteStorageR\x04vote\x12V\ - \n\x0cballot_proof\x18\x02\x20\x03(\x0b23.com.webank.wedpr.acv.proto.Str\ - ingToBallotProofPairR\x0bballotProof\x12\x1f\n\x0brange_proof\x18\x03\ - \x20\x01(\x0cR\nrangeProof\x12*\n\x11sum_balance_proof\x18\x04\x20\x01(\ - \x0cR\x0fsumBalanceProof\"\x87\x02\n\x0bVoteStorage\x12\x1c\n\tsignature\ - \x18\x01\x20\x01(\x0cR\tsignature\x12E\n\x0cblank_ballot\x18\x02\x20\x01\ - (\x0b2\".com.webank.wedpr.acv.proto.BallotR\x0bblankBallot\x12C\n\x0bres\ - t_ballot\x18\x03\x20\x01(\x0b2\".com.webank.wedpr.acv.proto.BallotR\nres\ - tBallot\x12N\n\x0cvoted_ballot\x18\x04\x20\x03(\x0b2+.com.webank.wedpr.a\ - cv.proto.CandidateBallotR\x0bvotedBallot\"u\n\x0cCountingPart\x12\x1d\n\ - \ncounter_id\x18\x01\x20\x01(\tR\tcounterId\x12\x1f\n\x0bblinding_c2\x18\ - \x02\x20\x01(\x0cR\nblindingC2\x12%\n\x0eequality_proof\x18\x03\x20\x01(\ - \x0cR\requalityProof\"l\n\x18StringToCountingPartPair\x12\x10\n\x03key\ - \x18\x01\x20\x01(\tR\x03key\x12>\n\x05value\x18\x02\x20\x01(\x0b2(.com.w\ - ebank.wedpr.acv.proto.CountingPartR\x05value\"\xc2\x01\n\x1aDecryptedRes\ - ultPartStorage\x12G\n\nblank_part\x18\x01\x20\x01(\x0b2(.com.webank.wedp\ - r.acv.proto.CountingPartR\tblankPart\x12[\n\x0ecandidate_part\x18\x02\ - \x20\x03(\x0b24.com.webank.wedpr.acv.proto.StringToCountingPartPairR\rca\ - ndidatePart\"Z\n\x11VoteResultStorage\x12E\n\x06result\x18\x01\x20\x03(\ - \x0b2-.com.webank.wedpr.acv.proto.StringToInt64PairR\x06result\";\n\x11S\ - tringToInt64Pair\x12\x10\n\x03key\x18\x01\x20\x01(\tR\x03key\x12\x14\n\ - \x05value\x18\x02\x20\x01(\x03R\x05valueB\x1e\n\x1acom.webank.wedpr.acv.\ - protoP\x01b\x06proto3\ + \x12!\n\x0cvoter_secret\x18\x01\x20\x01(\x0cR\x0bvoterSecret\"\xc5\x01\n\ + \x13RegistrationRequest\x12X\n\x0cweight_point\x18\x01\x20\x01(\x0b25.co\ + m.webank.wedpr.acv.proto.RegistrationBlindingPointR\x0bweightPoint\x12T\ + \n\nzero_point\x18\x02\x20\x01(\x0b25.com.webank.wedpr.acv.proto.Registr\ + ationBlindingPointR\tzeroPoint\"\x7f\n\x19RegistrationBlindingPoint\x12.\ + \n\x13blinding_poll_point\x18\x01\x20\x01(\x0cR\x11blindingPollPoint\x12\ + 2\n\x15blinding_basepoint_g2\x18\x02\x20\x01(\x0cR\x13blindingBasepointG\ + 2\"\xd8\x01\n\x14RegistrationResponse\x12!\n\x0cvoter_weight\x18\x01\x20\ + \x01(\rR\x0bvoterWeight\x12:\n\x06ballot\x18\x02\x20\x01(\x0b2\".com.web\ + ank.wedpr.acv.proto.BallotR\x06ballot\x12\x1c\n\tsignature\x18\x03\x20\ + \x01(\x0cR\tsignature\x12C\n\x0bzero_ballot\x18\x04\x20\x01(\x0b2\".com.\ + webank.wedpr.acv.proto.BallotR\nzeroBallot\"L\n\x06Ballot\x12\x20\n\x0bc\ + iphertext1\x18\x01\x20\x01(\x0cR\x0bciphertext1\x12\x20\n\x0bciphertext2\ + \x18\x02\x20\x01(\x0cR\x0bciphertext2\"h\n\x1dCounterParametersShareRequ\ + est\x12\x1d\n\ncounter_id\x18\x01\x20\x01(\tR\tcounterId\x12(\n\x10poll_\ + point_share\x18\x02\x20\x01(\x0cR\x0epollPointShare\"\x8f\x01\n\x18Count\ + erParametersStorage\x12s\n\x18counter_parameters_share\x18\x01\x20\x03(\ + \x0b29.com.webank.wedpr.acv.proto.CounterParametersShareRequestR\x16coun\ + terParametersShare\"@\n\nVoteChoice\x12\x1c\n\tcandidate\x18\x01\x20\x01\ + (\tR\tcandidate\x12\x14\n\x05value\x18\x02\x20\x01(\rR\x05value\"M\n\x12\ + UnlistedVoteChoice\x12!\n\x0ccandidate_id\x18\x01\x20\x01(\rR\x0bcandida\ + teId\x12\x14\n\x05value\x18\x02\x20\x01(\rR\x05value\"\xa6\x01\n\x0bVote\ + Choices\x12>\n\x06choice\x18\x01\x20\x03(\x0b2&.com.webank.wedpr.acv.pro\ + to.VoteChoiceR\x06choice\x12W\n\x0funlisted_choice\x18\x02\x20\x03(\x0b2\ + ..com.webank.wedpr.acv.proto.UnlistedVoteChoiceR\x0eunlistedChoice\"k\n\ + \x0fCandidateBallot\x12\x1c\n\tcandidate\x18\x01\x20\x01(\tR\tcandidate\ + \x12:\n\x06ballot\x18\x02\x20\x01(\x0b2\".com.webank.wedpr.acv.proto.Bal\ + lotR\x06ballot\"d\n\x0bBallotProof\x12!\n\x0cformat_proof\x18\x01\x20\ + \x01(\x0cR\x0bformatProof\x122\n\x15either_equality_proof\x18\x02\x20\ + \x01(\x0cR\x13eitherEqualityProof\"j\n\x17StringToBallotProofPair\x12\ + \x10\n\x03key\x18\x01\x20\x01(\tR\x03key\x12=\n\x05value\x18\x02\x20\x01\ + (\x0b2'.com.webank.wedpr.acv.proto.BallotProofR\x05value\"\xde\x02\n\x0b\ + VoteRequest\x12;\n\x04vote\x18\x01\x20\x01(\x0b2'.com.webank.wedpr.acv.p\ + roto.VoteStorageR\x04vote\x12V\n\x0cballot_proof\x18\x02\x20\x03(\x0b23.\ + com.webank.wedpr.acv.proto.StringToBallotProofPairR\x0bballotProof\x12\ + \x1f\n\x0brange_proof\x18\x03\x20\x01(\x0cR\nrangeProof\x12*\n\x11sum_ba\ + lance_proof\x18\x04\x20\x01(\x0cR\x0fsumBalanceProof\x12m\n\x15unlisted_\ + ballot_proof\x18\x05\x20\x03(\x0b29.com.webank.wedpr.acv.proto.CipherPoi\ + ntsToBallotProofPairR\x13unlistedBallotProof\"\xb6\x03\n\x0bVoteStorage\ + \x12\x1c\n\tsignature\x18\x01\x20\x01(\x0cR\tsignature\x12E\n\x0cblank_b\ + allot\x18\x02\x20\x01(\x0b2\".com.webank.wedpr.acv.proto.BallotR\x0bblan\ + kBallot\x12C\n\x0brest_ballot\x18\x03\x20\x01(\x0b2\".com.webank.wedpr.a\ + cv.proto.BallotR\nrestBallot\x12N\n\x0cvoted_ballot\x18\x04\x20\x03(\x0b\ + 2+.com.webank.wedpr.acv.proto.CandidateBallotR\x0bvotedBallot\x12h\n\x15\ + voted_ballot_unlisted\x18\x06\x20\x03(\x0b24.com.webank.wedpr.acv.proto.\ + CipherPointsToBallotPairR\x13votedBallotUnlisted\x12C\n\x0bzero_ballot\ + \x18\x07\x20\x01(\x0b2\".com.webank.wedpr.acv.proto.BallotR\nzeroBallot\ + \"\x92\x01\n\x18CipherPointsToBallotPair\x12:\n\x03key\x18\x01\x20\x01(\ + \x0b2(.com.webank.wedpr.acv.proto.CipherPointsR\x03key\x12:\n\x06ballot\ + \x18\x03\x20\x01(\x0b2\".com.webank.wedpr.acv.proto.BallotR\x06ballot\"\ + \x9a\x01\n\x1dCipherPointsToBallotProofPair\x12:\n\x03key\x18\x01\x20\ + \x01(\x0b2(.com.webank.wedpr.acv.proto.CipherPointsR\x03key\x12=\n\x05va\ + lue\x18\x02\x20\x01(\x0b2'.com.webank.wedpr.acv.proto.BallotProofR\x05va\ + lue\"R\n\x0cCipherPoints\x12\x20\n\x0bciphertext1\x18\x01\x20\x01(\x0cR\ + \x0bciphertext1\x12\x20\n\x0bciphertext2\x18\x02\x20\x01(\x0cR\x0bcipher\ + text2\"u\n\x0cCountingPart\x12\x1d\n\ncounter_id\x18\x01\x20\x01(\tR\tco\ + unterId\x12\x1f\n\x0bblinding_c2\x18\x02\x20\x01(\x0cR\nblindingC2\x12%\ + \n\x0eequality_proof\x18\x03\x20\x01(\x0cR\requalityProof\"l\n\x18String\ + ToCountingPartPair\x12\x10\n\x03key\x18\x01\x20\x01(\tR\x03key\x12>\n\ + \x05value\x18\x02\x20\x01(\x0b2(.com.webank.wedpr.acv.proto.CountingPart\ + R\x05value\"\xb5\x02\n\x1aDecryptedResultPartStorage\x12G\n\nblank_part\ + \x18\x01\x20\x01(\x0b2(.com.webank.wedpr.acv.proto.CountingPartR\tblankP\ + art\x12[\n\x0ecandidate_part\x18\x02\x20\x03(\x0b24.com.webank.wedpr.acv\ + .proto.StringToCountingPartPairR\rcandidatePart\x12q\n\x17unlisted_candi\ + date_part\x18\x03\x20\x03(\x0b29.com.webank.wedpr.acv.proto.UnlistedBall\ + otDecryptedResultR\x15unlistedCandidatePart\"\xf7\x02\n\x1dUnlistedBallo\ + tDecryptedResult\x12\x1c\n\tcandidate\x18\x01\x20\x01(\x03R\tcandidate\ + \x12S\n\x10candidate_cipher\x18\x02\x20\x01(\x0b2(.com.webank.wedpr.acv.\ + proto.CipherPointsR\x0fcandidateCipher\x12j\n\x1cdecrypted_unlisted_cand\ + idate\x18\x04\x20\x01(\x0b2(.com.webank.wedpr.acv.proto.CountingPartR\ + \x1adecryptedUnlistedCandidate\x12w\n#decrypted_unlisted_candidate_ballo\ + t\x18\x05\x20\x03(\x0b2(.com.webank.wedpr.acv.proto.CountingPartR\x20dec\ + ryptedUnlistedCandidateBallot\"\xb3\x01\n\x11VoteResultStorage\x12E\n\ + \x06result\x18\x01\x20\x03(\x0b2-.com.webank.wedpr.acv.proto.StringToInt\ + 64PairR\x06result\x12W\n\x0funlisted_result\x18\x02\x20\x03(\x0b2..com.w\ + ebank.wedpr.acv.proto.UnlistedVoteChoiceR\x0eunlistedResult\";\n\x11Stri\ + ngToInt64Pair\x12\x10\n\x03key\x18\x01\x20\x01(\tR\x03key\x12\x14\n\x05v\ + alue\x18\x02\x20\x01(\x03R\x05valueB\x1e\n\x1acom.webank.wedpr.acv.proto\ + P\x01b\x06proto3\ "; static file_descriptor_proto_lazy: ::protobuf::rt::LazyV2<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::rt::LazyV2::INIT; diff --git a/protos/src/generated/hdk.rs b/protos/src/generated/hdk.rs index aa0f428..0b2d19c 100644 --- a/protos/src/generated/hdk.rs +++ b/protos/src/generated/hdk.rs @@ -1,6 +1,4 @@ -// Copyright 2021 WeDPR Lab Project Authors. Licensed under Apache-2.0. - -// This file is generated by rust-protobuf 2.22.1. Do not edit +// This file is generated by rust-protobuf 2.27.1. Do not edit // @generated // https://github.com/rust-lang/rust-clippy/issues/702 @@ -23,7 +21,7 @@ /// Generated files are compatible only with the same version /// of protobuf runtime. -// const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_22_1; +// const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_27_1; #[derive(PartialEq,Clone,Default)] pub struct HdkResult { diff --git a/protos/src/generated/scd.rs b/protos/src/generated/scd.rs index d9bd149..b0bd0c1 100644 --- a/protos/src/generated/scd.rs +++ b/protos/src/generated/scd.rs @@ -1,6 +1,4 @@ -// Copyright 2020 WeDPR Lab Project Authors. Licensed under Apache-2.0. - -// This file is generated by rust-protobuf 2.22.1. Do not edit +// This file is generated by rust-protobuf 2.27.1. Do not edit // @generated // https://github.com/rust-lang/rust-clippy/issues/702 @@ -23,7 +21,7 @@ /// Generated files are compatible only with the same version /// of protobuf runtime. -// const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_22_1; +// const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_27_1; #[derive(PartialEq,Clone,Default)] pub struct CertificateSchema { diff --git a/protos/src/generated/vcl.rs b/protos/src/generated/vcl.rs index e086e05..3d5325c 100644 --- a/protos/src/generated/vcl.rs +++ b/protos/src/generated/vcl.rs @@ -1,6 +1,4 @@ -// Copyright 2020 WeDPR Lab Project Authors. Licensed under Apache-2.0. - -// This file is generated by rust-protobuf 2.22.1. Do not edit +// This file is generated by rust-protobuf 2.27.1. Do not edit // @generated // https://github.com/rust-lang/rust-clippy/issues/702 @@ -23,7 +21,7 @@ /// Generated files are compatible only with the same version /// of protobuf runtime. -// const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_22_1; +// const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_27_1; #[derive(PartialEq,Clone,Default)] pub struct EncodedOwnerSecret { diff --git a/protos/src/lib.rs b/protos/src/lib.rs index 806e8a9..52afeee 100644 --- a/protos/src/lib.rs +++ b/protos/src/lib.rs @@ -1,16 +1,27 @@ // Copyright 2020 WeDPR Lab Project Authors. Licensed under Apache-2.0. //! Library of protobuf definitions and their generated code. -use crate::generated::zkp::{PBBalanceProof, PBEqualityProof}; +#[macro_use] +extern crate lazy_static; +use crate::{ + config::{HASH, SIGNATURE}, + generated::{ + acv::Ballot, + zkp::{PBBalanceProof, PBEqualityProof}, + }, +}; +use wedpr_l_utils::{ + error::WedprError, + traits::{Hash, Signature}, +}; +pub mod config; +pub mod generated; + use protobuf::Message; use wedpr_l_crypto_zkp_utils::{ bytes_to_point, bytes_to_scalar, point_to_bytes, scalar_to_bytes, ArithmeticProof, BalanceProof, EqualityProof, FormatProof, KnowledgeProof, }; -pub mod generated; - -#[cfg(not(tarpaulin_include))] -use wedpr_l_utils::error::WedprError; pub fn proto_to_bytes(proto: &T) -> Result, WedprError> { return match proto.write_to_bytes() { @@ -152,6 +163,67 @@ pub fn pb_to_equality_proof( }) } +// generate signature for the ballot +pub fn generate_ballot_signature( + secret_key: &[u8], + ballot: &Ballot, +) -> Result, WedprError> { + let mut hash_vec = Vec::new(); + hash_vec.append(&mut ballot.get_ciphertext1().to_vec()); + hash_vec.append(&mut ballot.get_ciphertext2().to_vec()); + let message_hash = HASH.hash(&hash_vec); + SIGNATURE.sign(secret_key, &message_hash) +} + +pub fn generate_ballots_signature( + secret_key: &[u8], + weight_ballot: &Ballot, + zero_ballot: &Ballot, +) -> Result, WedprError> { + let mut hash_vec = Vec::new(); + hash_vec.append(&mut weight_ballot.get_ciphertext1().to_vec()); + hash_vec.append(&mut weight_ballot.get_ciphertext2().to_vec()); + hash_vec.append(&mut zero_ballot.get_ciphertext1().to_vec()); + hash_vec.append(&mut zero_ballot.get_ciphertext2().to_vec()); + let message_hash = HASH.hash(&hash_vec); + SIGNATURE.sign(secret_key, &message_hash) +} + +pub fn verify_ballot_signature( + public_key: &[u8], + ballot: &Ballot, + signature: &Vec, +) -> Result { + let mut hash_vec = Vec::new(); + hash_vec.append(&mut ballot.get_ciphertext1().to_vec()); + hash_vec.append(&mut ballot.get_ciphertext2().to_vec()); + let message_hash: Vec = HASH.hash(&hash_vec); + Ok(SIGNATURE.verify( + &public_key, + &message_hash.as_ref(), + &signature.as_slice(), + )) +} + +pub fn verify_ballots_signature( + public_key: &[u8], + weight_ballot: &Ballot, + zero_ballot: &Ballot, + signature: &Vec, +) -> Result { + let mut hash_vec = Vec::new(); + hash_vec.append(&mut weight_ballot.get_ciphertext1().to_vec()); + hash_vec.append(&mut weight_ballot.get_ciphertext2().to_vec()); + hash_vec.append(&mut zero_ballot.get_ciphertext1().to_vec()); + hash_vec.append(&mut zero_ballot.get_ciphertext2().to_vec()); + let message_hash: Vec = HASH.hash(&hash_vec); + Ok(SIGNATURE.verify( + &public_key, + &message_hash.as_ref(), + &signature.as_slice(), + )) +} + #[cfg(test)] mod tests { use super::*; diff --git a/solution/anonymous_ciphertext_voting/Cargo.toml b/solution/anonymous_ciphertext_voting/Cargo.toml index ab49af4..720f278 100644 --- a/solution/anonymous_ciphertext_voting/Cargo.toml +++ b/solution/anonymous_ciphertext_voting/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "wedpr_s_anonymous_ciphertext_voting" -version = "1.5.0" +version = "1.6.0" authors = [ "WeDPR " ] edition = "2018" license = "Apache-2.0" diff --git a/solution/anonymous_ciphertext_voting/src/coordinator.rs b/solution/anonymous_ciphertext_voting/src/coordinator.rs index fef77ac..ef2facf 100644 --- a/solution/anonymous_ciphertext_voting/src/coordinator.rs +++ b/solution/anonymous_ciphertext_voting/src/coordinator.rs @@ -4,23 +4,26 @@ use curve25519_dalek::{ristretto::RistrettoPoint, scalar::Scalar}; use wedpr_l_crypto_zkp_utils::{bytes_to_point, point_to_bytes, BASEPOINT_G1}; -use wedpr_l_utils::{ - error::WedprError, - traits::{Hash, Signature}, -}; +use wedpr_l_utils::error::WedprError; -use wedpr_s_protos::generated::acv::{ - Ballot, CandidateBallot, CandidateList, CounterParametersStorage, - CountingPart, DecryptedResultPartStorage, PollParametersStorage, - RegistrationRequest, RegistrationResponse, StringToCountingPartPair, - StringToInt64Pair, VoteResultStorage, VoteStorage, +use wedpr_s_protos::{ + generate_ballot_signature, generate_ballots_signature, + generated::acv::{ + Ballot, CandidateBallot, CandidateList, CounterParametersStorage, + CountingPart, DecryptedResultPartStorage, PollParametersStorage, + RegistrationRequest, RegistrationResponse, StringToCountingPartPair, + StringToInt64Pair, UnlistedBallotDecryptedResult, UnlistedVoteChoice, + VoteResultStorage, VoteStorage, + }, }; use crate::{ - config::{HASH, POLL_RESULT_KEY_TOTAL_BALLOTS, SIGNATURE}, + config::POLL_RESULT_KEY_TOTAL_BALLOTS, utils::{get_ballot_by_candidate, get_counting_part_by_candidate}, }; +use std::collections::BTreeMap; + /// Makes system parameters for a new poll. pub fn make_poll_parameters( candidate_list: &CandidateList, @@ -59,17 +62,59 @@ pub fn certify_voter( .get_blinding_basepoint_g2() .to_vec(), ); + let mut response = RegistrationResponse::new(); // Sign the above data. - let mut hash_vec = Vec::new(); - hash_vec.append(&mut ballot.get_ciphertext1().to_vec()); - hash_vec.append(&mut ballot.get_ciphertext2().to_vec()); - let message_hash = HASH.hash(&hash_vec); - let signature = SIGNATURE.sign(secret_key, &message_hash)?; + response.set_signature(generate_ballot_signature(secret_key, &ballot)?); + response.set_ballot(ballot); + response.set_voter_weight(voter_weight as u32); + Ok(response) +} + +pub fn certify_unbounded_voter( + secret_key: &[u8], + registration_request: &RegistrationRequest, + value: u32, +) -> Result { + // generate weight ballot + let blinding_poll_point = bytes_to_point( + registration_request + .get_weight_point() + .get_blinding_poll_point(), + )?; + let weight_ciphertext1 = + blinding_poll_point + (*BASEPOINT_G1 * (Scalar::from(value as u64))); + let mut weight_ballot = Ballot::new(); + weight_ballot.set_ciphertext1(point_to_bytes(&weight_ciphertext1)); + weight_ballot.set_ciphertext2( + registration_request + .get_weight_point() + .get_blinding_basepoint_g2() + .to_vec(), + ); + // generate zero ballot + let mut zero_ballot = Ballot::new(); + zero_ballot.set_ciphertext1( + registration_request + .get_zero_point() + .get_blinding_poll_point() + .to_vec(), + ); + zero_ballot.set_ciphertext2( + registration_request + .get_zero_point() + .get_blinding_basepoint_g2() + .to_vec(), + ); let mut response = RegistrationResponse::new(); - response.set_signature(signature); - response.set_ballot(ballot); - response.set_voter_weight(voter_weight); + response.set_signature(generate_ballots_signature( + secret_key, + &weight_ballot, + &zero_ballot, + )?); + response.set_ballot(weight_ballot); + response.set_zero_ballot(zero_ballot); + response.set_voter_weight(value); Ok(response) } @@ -135,6 +180,21 @@ pub fn aggregate_vote_sum_response( Ok(true) } +pub fn aggregate_vote_sum_response_unlisted( + poll_parameters: &PollParametersStorage, + vote_part: &VoteStorage, + vote_sum: &mut VoteStorage, +) -> Result { + aggregate_vote_sum_response(poll_parameters, vote_part, vote_sum)?; + // aggregate all unlisted voting cipher ballot in vote_part + for unlisted_ballot in vote_part.get_voted_ballot_unlisted() { + vote_sum + .mut_voted_ballot_unlisted() + .push(unlisted_ballot.clone()); + } + Ok(true) +} + /// Aggregates a partially decrypted result from a counter. pub fn aggregate_decrypted_part_sum( poll_parameters: &PollParametersStorage, @@ -201,6 +261,78 @@ pub fn aggregate_decrypted_part_sum( Ok(true) } +pub fn aggregate_decrypted_part_for_specify_unlisted_candidate( + decrypted_part: &UnlistedBallotDecryptedResult, + aggregated_decrypted_part: &mut UnlistedBallotDecryptedResult, +) -> Result { + // counting for the unlisted candidate + let current_aggregated_unlisted_candidate = + aggregated_decrypted_part.get_decrypted_unlisted_candidate(); + let decrypted_part_unlisted_candidate = + decrypted_part.get_decrypted_unlisted_candidate(); + let aggregated_unlisted_candidate = bytes_to_point( + current_aggregated_unlisted_candidate.get_blinding_c2(), + )? + bytes_to_point( + decrypted_part_unlisted_candidate.get_blinding_c2(), + )?; + // update the aggregated_decrypt_result for ulisted candidate + aggregated_decrypted_part + .mut_decrypted_unlisted_candidate() + .set_blinding_c2(point_to_bytes(&aggregated_unlisted_candidate)); + + // push the cipher unlisted candidate ballot into aggregated_decrypted_part + let unlisted_candidate_ballot = + decrypted_part.get_decrypted_unlisted_candidate_ballot(); + // invalid decrypted_part + if unlisted_candidate_ballot.len() < 1 { + return Ok(false); + } + aggregated_decrypted_part + .mut_decrypted_unlisted_candidate_ballot() + .push((unlisted_candidate_ballot[0]).clone()); + Ok(true) +} + +pub fn aggregate_decrypted_part_sum_unlisted( + poll_parameters: &PollParametersStorage, + partially_decrypted_result: &DecryptedResultPartStorage, + aggregated_decrypted_result: &mut DecryptedResultPartStorage, +) -> Result { + aggregate_decrypted_part_sum( + poll_parameters, + partially_decrypted_result, + aggregated_decrypted_result, + )?; + // aggregate unlisted candidate + for unlisted_candidate_decrypt_part in + partially_decrypted_result.get_unlisted_candidate_part() + { + let mut match_candidate = false; + // find the aggregated_decrypted_part for the partially_decrypted_result + for mut aggregated_decrypted_part in + aggregated_decrypted_result.mut_unlisted_candidate_part() + { + if aggregated_decrypted_part.get_candidate_cipher() + == unlisted_candidate_decrypt_part.get_candidate_cipher() + { + match_candidate = + aggregate_decrypted_part_for_specify_unlisted_candidate( + unlisted_candidate_decrypt_part, + &mut aggregated_decrypted_part, + )?; + break; + } + } + // insert a new item + if !match_candidate { + aggregated_decrypted_result + .mut_unlisted_candidate_part() + .push(unlisted_candidate_decrypt_part.clone()); + } + } + Ok(true) +} + /// Computes the final vote result from aggregated partially decrypted results. pub fn finalize_vote_result( poll_parameters: &PollParametersStorage, @@ -253,3 +385,121 @@ pub fn finalize_vote_result( } Ok(result) } + +pub fn decrypt_unlisted_candidate_ballot( + decrypted_unlisted_candidate_ballot_result: &mut BTreeMap, + unlisted_candidate_part: &mut UnlistedBallotDecryptedResult, + vote_sum: &VoteStorage, + max_vote_limit: i64, + max_candidate_number: i64, +) -> Result { + let candidate_cipher = unlisted_candidate_part.get_candidate_cipher(); + let aggregated_candidate_blinding_c2 = bytes_to_point( + unlisted_candidate_part + .get_decrypted_unlisted_candidate() + .get_blinding_c2(), + )?; + // find the candidate id according to the candidate_cipher + let target_total = bytes_to_point(candidate_cipher.get_ciphertext1())? + - aggregated_candidate_blinding_c2; + let mut decrypt_candidate_success = false; + for i in 0..=max_candidate_number { + let try_num = Scalar::from(i as u64); + if target_total.eq(&((*BASEPOINT_G1) * (try_num))) { + // find the candidate, update the candidate field of + // unlisted_candidate_part + unlisted_candidate_part.set_candidate(i); + decrypt_candidate_success = true; + break; + } + } + if !decrypt_candidate_success { + return Ok(false); + } + // decrypt the unlisted candidate ballot value when decrypt candidate + // success + for unlisted_vote_ballot in vote_sum.get_voted_ballot_unlisted() { + if unlisted_candidate_part.get_candidate_cipher() + != unlisted_vote_ballot.get_key() + { + continue; + } + // find out the unlisted vote ballot for the candidate + // aggregate blinding_c2 decrypted cipher ballot unlisted + let mut blinding_c2_sum = RistrettoPoint::default(); + for decrypted_unlisted_candidate_blinding_c2 in + unlisted_candidate_part.get_decrypted_unlisted_candidate_ballot() + { + blinding_c2_sum += bytes_to_point( + decrypted_unlisted_candidate_blinding_c2.get_blinding_c2(), + )?; + } + // try to find out + let c1 = bytes_to_point( + unlisted_vote_ballot.get_ballot().get_ciphertext1(), + )?; + let target_total = c1 - blinding_c2_sum; + // decrypt the ballot value + for i in 0..max_vote_limit { + let try_num = Scalar::from(i as u64); + if !target_total.eq(&(*BASEPOINT_G1 * try_num)) { + continue; + } + // merge the candidate unlisted value + let candidate = unlisted_candidate_part.get_candidate() as u64; + if decrypted_unlisted_candidate_ballot_result + .contains_key(&candidate) + { + let result_sum = decrypted_unlisted_candidate_ballot_result + .get(&candidate) + .unwrap() + + (i as u64); + decrypted_unlisted_candidate_ballot_result + .insert(candidate, result_sum); + } else { + decrypted_unlisted_candidate_ballot_result + .insert(candidate, i as u64); + } + } + } + Ok(true) +} + +pub fn finalize_vote_result_unlisted( + poll_parameters: &PollParametersStorage, + vote_sum: &VoteStorage, + aggregated_decrypted_result: &mut DecryptedResultPartStorage, + max_vote_limit: i64, + max_candidate_number: i64, +) -> Result { + let mut vote_result = finalize_vote_result( + poll_parameters, + vote_sum, + aggregated_decrypted_result, + max_vote_limit, + )?; + // finalize the vote result for the unlisted-candidates + let mut aggregated_unlisted_candidate_ballot_result = BTreeMap::new(); + for mut unlisted_candidate in + aggregated_decrypted_result.mut_unlisted_candidate_part() + { + decrypt_unlisted_candidate_ballot( + &mut aggregated_unlisted_candidate_ballot_result, + &mut unlisted_candidate, + &vote_sum, + max_vote_limit, + max_candidate_number, + )?; + } + // push the aggregated_unlisted_candidate_ballot_result into + // aggregated_decrypted_result + for (key, value) in aggregated_unlisted_candidate_ballot_result { + let mut unlisted_candidate_ballot_result = UnlistedVoteChoice::new(); + unlisted_candidate_ballot_result.set_candidate_id(key as u32); + unlisted_candidate_ballot_result.set_value(value as u32); + vote_result + .mut_unlisted_result() + .push(unlisted_candidate_ballot_result); + } + Ok(vote_result) +} diff --git a/solution/anonymous_ciphertext_voting/src/counter.rs b/solution/anonymous_ciphertext_voting/src/counter.rs index 79071de..2557b07 100644 --- a/solution/anonymous_ciphertext_voting/src/counter.rs +++ b/solution/anonymous_ciphertext_voting/src/counter.rs @@ -12,7 +12,8 @@ use wedpr_l_utils::error::WedprError; use wedpr_s_protos::{ generated::acv::{ CounterParametersShareRequest, CounterSecret, CountingPart, - DecryptedResultPartStorage, StringToCountingPartPair, VoteStorage, + DecryptedResultPartStorage, StringToCountingPartPair, + UnlistedBallotDecryptedResult, VoteStorage, }, proto_to_bytes, }; @@ -103,3 +104,74 @@ pub fn count( blank_part.set_counter_id(counter_id.to_string()); Ok(partially_decrypted_result) } + +pub fn count_unlisted( + counter_id: &str, + counter_secret: &CounterSecret, + encrypted_vote_sum: &VoteStorage, +) -> Result { + let mut partially_decrypted_result = + count(counter_id, counter_secret, encrypted_vote_sum)?; + // count unlisted ballot + let secret_share = + bytes_to_scalar(&counter_secret.get_poll_secret_share())?; + for unlisted_ballot in encrypted_vote_sum.get_voted_ballot_unlisted() { + let unlisted_candidate_cipher = unlisted_ballot.get_key(); + let unlisted_candidate_part_share = + bytes_to_point(unlisted_candidate_cipher.get_ciphertext2())?; + // generate equality proof + let equality_proof = prove_equality_relationship_proof( + &secret_share, + &BASEPOINT_G2, + &unlisted_candidate_part_share, + ); + // decrypt and generate the equality proof for unlisted candidate + let mut decrypted_unlisted_candidate = CountingPart::new(); + decrypted_unlisted_candidate.set_blinding_c2(point_to_bytes( + &(unlisted_candidate_part_share * secret_share), + )); + decrypted_unlisted_candidate.set_equality_proof(proto_to_bytes( + &equality_proof_to_pb(&equality_proof), + )?); + + // decrypt and generaate the equality proof for unlisted candidate + // ballot + let unlisted_candidate_ballot = unlisted_ballot.get_ballot(); + let unlisted_candidate_ballot_part_share = + bytes_to_point(unlisted_candidate_ballot.get_ciphertext2())?; + let equality_proof = prove_equality_relationship_proof( + &secret_share, + &BASEPOINT_G2, + &unlisted_candidate_ballot_part_share, + ); + let mut decrypted_ulisted_candidate_ballot = CountingPart::new(); + decrypted_ulisted_candidate_ballot.set_blinding_c2(point_to_bytes( + &(unlisted_candidate_ballot_part_share * secret_share), + )); + decrypted_ulisted_candidate_ballot.set_equality_proof(proto_to_bytes( + &equality_proof_to_pb(&equality_proof), + )?); + + let mut unlisted_candidate_part_item = + UnlistedBallotDecryptedResult::new(); + unlisted_candidate_part_item + .set_decrypted_unlisted_candidate(decrypted_unlisted_candidate); + unlisted_candidate_part_item + .mut_decrypted_unlisted_candidate_ballot() + .push(decrypted_ulisted_candidate_ballot); + unlisted_candidate_part_item + .mut_candidate_cipher() + .set_ciphertext1( + unlisted_candidate_cipher.get_ciphertext1().to_vec(), + ); + unlisted_candidate_part_item + .mut_candidate_cipher() + .set_ciphertext2( + unlisted_candidate_cipher.get_ciphertext2().to_vec(), + ); + partially_decrypted_result + .mut_unlisted_candidate_part() + .push(unlisted_candidate_part_item); + } + Ok(partially_decrypted_result) +} diff --git a/solution/anonymous_ciphertext_voting/src/lib.rs b/solution/anonymous_ciphertext_voting/src/lib.rs index 586ced7..dfa5cf3 100644 --- a/solution/anonymous_ciphertext_voting/src/lib.rs +++ b/solution/anonymous_ciphertext_voting/src/lib.rs @@ -19,11 +19,14 @@ pub mod voter; mod tests { use super::*; use crate::{config::SIGNATURE, coordinator}; - use wedpr_l_crypto_zkp_utils::bytes_to_point; + use wedpr_l_crypto_zkp_utils::{ + bytes_to_point, get_random_scalar, scalar_to_bytes, + }; use wedpr_l_utils::traits::Signature; use wedpr_s_protos::generated::acv::{ CandidateList, CounterParametersStorage, CounterSecret, - DecryptedResultPartStorage, VoteStorage, VoterSecret, + DecryptedResultPartStorage, UnlistedVoteChoice, VoteChoice, + VoteChoices, VoteStorage, VoterSecret, }; #[test] @@ -180,4 +183,673 @@ mod tests { ) .unwrap()); } + + #[test] + fn test_unbounded_voting() { + let candidate_list: Vec = vec!["Alice", "Bob", "charlie"] + .iter() + .map(|i| i.to_string()) + .collect(); + let counter_id_list = vec!["10086", "10010", "10000"]; + let blank_ballot_count = vec![10, 20, 30]; + let voting_ballot_weight = + vec![vec![10, 0, 10], vec![0, 20, 20], vec![30, 30, 30]]; + let max_vote_number = 60; + let init_counter = || { + let counter_secret = counter::make_counter_secret(); + counter_secret + }; + + let counter1 = init_counter(); + let counter2 = init_counter(); + let counter3 = init_counter(); + + let counter_share1 = + counter::make_parameters_share(&counter_id_list[0], &counter1) + .unwrap(); + let counter_share2 = + counter::make_parameters_share(&counter_id_list[1], &counter2) + .unwrap(); + let counter_share3 = + counter::make_parameters_share(&counter_id_list[2], &counter3) + .unwrap(); + + // generate the candidate list + let mut pb_candidate_list = CandidateList::new(); + for i in candidate_list.iter() { + pb_candidate_list.mut_candidate().push(i.to_string()); + } + // generate the CounterParametersStorage + let mut counter_parameters = CounterParametersStorage::new(); + counter_parameters + .mut_counter_parameters_share() + .push(counter_share1.clone()); + counter_parameters + .mut_counter_parameters_share() + .push(counter_share2.clone()); + counter_parameters + .mut_counter_parameters_share() + .push(counter_share3.clone()); + let poll_parameters = coordinator::make_poll_parameters( + &pb_candidate_list, + &counter_parameters, + ) + .unwrap(); + pub struct VoterSecretPair { + pub weight_secret: VoterSecret, + pub zero_sercret: VoterSecret, + } + let init_voter = || { + let mut pb_secret_r = VoterSecret::new(); + pb_secret_r.set_voter_secret(scalar_to_bytes(&get_random_scalar())); + let mut pb_zero_secret_r = VoterSecret::new(); + pb_zero_secret_r + .set_voter_secret(scalar_to_bytes(&get_random_scalar())); + VoterSecretPair { + weight_secret: pb_secret_r, + zero_sercret: pb_zero_secret_r, + } + }; + + let voter1_secret_pair = init_voter(); + let registration_request1 = voter::make_unbounded_registration_request( + &voter1_secret_pair.zero_sercret, + &voter1_secret_pair.weight_secret, + &poll_parameters, + ) + .unwrap(); + + let voter2_secret_pair = init_voter(); + let registration_request2 = voter::make_unbounded_registration_request( + &voter2_secret_pair.zero_sercret, + &voter2_secret_pair.weight_secret, + &poll_parameters, + ) + .unwrap(); + + let voter3_secret_pair = init_voter(); + let registration_request3 = voter::make_unbounded_registration_request( + &voter3_secret_pair.zero_sercret, + &voter3_secret_pair.weight_secret, + &poll_parameters, + ) + .unwrap(); + + // certify_unbounded_voter + let coordinator_key_pair = SIGNATURE.generate_keypair(); + let response1 = coordinator::certify_unbounded_voter( + &coordinator_key_pair.1, + ®istration_request1, + blank_ballot_count[0], + ) + .unwrap(); + + let response2 = coordinator::certify_unbounded_voter( + &coordinator_key_pair.1, + ®istration_request2, + blank_ballot_count[1], + ) + .unwrap(); + + let response3 = coordinator::certify_unbounded_voter( + &coordinator_key_pair.1, + ®istration_request3, + blank_ballot_count[2], + ) + .unwrap(); + + // begin vote + let mut encrypted_vote_sum = VoteStorage::new(); + let make_choice = |x: &Vec| { + let mut choices = VoteChoices::new(); + for i in 0..candidate_list.len() { + let mut choice = VoteChoice::new(); + choice.set_candidate(candidate_list[i].clone()); + choice.set_value(x[i] as u32); + choices.mut_choice().push(choice); + } + choices + }; + // voter1 vote + let choice1 = make_choice(&voting_ballot_weight[0]); + let vote_request1 = voter::vote_unbounded( + &voter1_secret_pair.weight_secret, + &voter1_secret_pair.zero_sercret, + &choice1, + &response1, + &poll_parameters, + ) + .unwrap(); + // verify the vote + assert_eq!( + true, + verifier::verify_unbounded_vote_request( + &poll_parameters, + &vote_request1, + &coordinator_key_pair.0 + ) + .unwrap() + ); + wedpr_println!("vote_request1 = {:?}", vote_request1); + // aggregate the vote + assert_eq!( + true, + coordinator::aggregate_vote_sum_response( + &poll_parameters, + &vote_request1.get_vote(), + &mut encrypted_vote_sum + ) + .unwrap() + ); + + // voter2 vote + let choice2 = make_choice(&voting_ballot_weight[1]); + let vote_request2 = voter::vote_unbounded( + &voter2_secret_pair.weight_secret, + &voter2_secret_pair.zero_sercret, + &choice2, + &response2, + &poll_parameters, + ) + .unwrap(); + // verify the vote request + assert_eq!( + true, + verifier::verify_unbounded_vote_request( + &poll_parameters, + &vote_request2, + &coordinator_key_pair.0 + ) + .unwrap() + ); + // aggregate the vote + assert_eq!( + true, + coordinator::aggregate_vote_sum_response( + &poll_parameters, + &vote_request2.get_vote(), + &mut encrypted_vote_sum + ) + .unwrap() + ); + + // voter3 vote + let choice3 = make_choice(&voting_ballot_weight[2]); + let vote_request3 = voter::vote_unbounded( + &voter3_secret_pair.weight_secret, + &voter3_secret_pair.zero_sercret, + &choice3, + &response3, + &poll_parameters, + ) + .unwrap(); + // verify the vote request + assert_eq!( + true, + verifier::verify_unbounded_vote_request( + &poll_parameters, + &vote_request3, + &coordinator_key_pair.0 + ) + .unwrap() + ); + // aggregate the vote_request3 + // aggregate the vote + assert_eq!( + true, + coordinator::aggregate_vote_sum_response( + &poll_parameters, + &vote_request3.get_vote(), + &mut encrypted_vote_sum + ) + .unwrap() + ); + wedpr_println!("encrypted_vote_sum: {:?}", encrypted_vote_sum); + + // count the encrypted_vote_sum + let mut vote_sum_total = DecryptedResultPartStorage::new(); + let decrypt_request1 = + counter::count(counter_id_list[0], &counter1, &encrypted_vote_sum) + .unwrap(); + // verify the count request + assert_eq!( + true, + verifier::verify_count_request( + &poll_parameters, + &encrypted_vote_sum, + &bytes_to_point(&counter_share1.get_poll_point_share()) + .unwrap(), + &decrypt_request1 + ) + .unwrap() + ); + assert_eq!( + true, + coordinator::aggregate_decrypted_part_sum( + &poll_parameters, + &decrypt_request1, + &mut vote_sum_total, + ) + .unwrap() + ); + + let decrypt_request2 = + counter::count(counter_id_list[1], &counter2, &encrypted_vote_sum) + .unwrap(); + // verify the count request + assert_eq!( + true, + verifier::verify_count_request( + &poll_parameters, + &encrypted_vote_sum, + &bytes_to_point(&counter_share2.get_poll_point_share()) + .unwrap(), + &decrypt_request2 + ) + .unwrap() + ); + assert_eq!( + true, + coordinator::aggregate_decrypted_part_sum( + &poll_parameters, + &decrypt_request2, + &mut vote_sum_total, + ) + .unwrap() + ); + // count3 + let decrypt_request3 = + counter::count(counter_id_list[2], &counter3, &encrypted_vote_sum) + .unwrap(); + // verify the count request + assert_eq!( + true, + verifier::verify_count_request( + &poll_parameters, + &encrypted_vote_sum, + &bytes_to_point(&counter_share3.get_poll_point_share()) + .unwrap(), + &decrypt_request3 + ) + .unwrap() + ); + assert_eq!( + true, + coordinator::aggregate_decrypted_part_sum( + &poll_parameters, + &decrypt_request3, + &mut vote_sum_total, + ) + .unwrap() + ); + + // finalize_vote_result + let final_result_request = coordinator::finalize_vote_result( + &poll_parameters, + &encrypted_vote_sum, + &vote_sum_total, + max_vote_number, + ) + .unwrap(); + wedpr_println!("final result is : {:?}", final_result_request); + let result = verifier::verify_vote_result( + &poll_parameters, + &encrypted_vote_sum, + &vote_sum_total, + &final_result_request, + ) + .unwrap(); + assert!(result); + } + + #[test] + fn test_unbounded_voting_unlisted() { + let candidate_list: Vec = vec!["Alice", "Bob", "charlie"] + .iter() + .map(|i| i.to_string()) + .collect(); + let candidate_list_unlisted: Vec = vec![1, 2, 3, 4, 5]; + let counter_id_list = vec!["10086", "10010", "10000"]; + let blank_ballot_count = vec![10, 20, 30]; + let voting_ballot_weight = + vec![vec![10, 0, 10], vec![0, 20, 20], vec![30, 30, 30]]; + let max_vote_number = 60; + let max_candidate_number = 10; + + let init_counter = || { + let counter_secret = counter::make_counter_secret(); + counter_secret + }; + let counter1 = init_counter(); + let counter2 = init_counter(); + let counter3 = init_counter(); + let counter_share1 = + counter::make_parameters_share(&counter_id_list[0], &counter1) + .unwrap(); + let counter_share2 = + counter::make_parameters_share(&counter_id_list[1], &counter2) + .unwrap(); + let counter_share3 = + counter::make_parameters_share(&counter_id_list[2], &counter3) + .unwrap(); + + // generate the candidate list + let mut pb_candidate_list = CandidateList::new(); + for i in candidate_list.iter() { + pb_candidate_list.mut_candidate().push(i.to_string()); + } + // generate the CounterParametersStorage + let mut counter_parameters = CounterParametersStorage::new(); + counter_parameters + .mut_counter_parameters_share() + .push(counter_share1.clone()); + counter_parameters + .mut_counter_parameters_share() + .push(counter_share2.clone()); + counter_parameters + .mut_counter_parameters_share() + .push(counter_share3.clone()); + let poll_parameters = coordinator::make_poll_parameters( + &pb_candidate_list, + &counter_parameters, + ) + .unwrap(); + pub struct VoterSecretPair { + pub weight_secret: VoterSecret, + pub zero_sercret: VoterSecret, + } + let init_voter = || { + let mut pb_secret_r = VoterSecret::new(); + pb_secret_r.set_voter_secret(scalar_to_bytes(&get_random_scalar())); + let mut pb_zero_secret_r = VoterSecret::new(); + pb_zero_secret_r + .set_voter_secret(scalar_to_bytes(&get_random_scalar())); + VoterSecretPair { + weight_secret: pb_secret_r, + zero_sercret: pb_zero_secret_r, + } + }; + let voter1_secret_pair = init_voter(); + let registration_request1 = voter::make_unbounded_registration_request( + &voter1_secret_pair.zero_sercret, + &voter1_secret_pair.weight_secret, + &poll_parameters, + ) + .unwrap(); + + let voter2_secret_pair = init_voter(); + let registration_request2 = voter::make_unbounded_registration_request( + &voter2_secret_pair.zero_sercret, + &voter2_secret_pair.weight_secret, + &poll_parameters, + ) + .unwrap(); + + let voter3_secret_pair = init_voter(); + let registration_request3 = voter::make_unbounded_registration_request( + &voter3_secret_pair.zero_sercret, + &voter3_secret_pair.weight_secret, + &poll_parameters, + ) + .unwrap(); + + let coordinator_key_pair = SIGNATURE.generate_keypair(); + let response1 = coordinator::certify_unbounded_voter( + &coordinator_key_pair.1, + ®istration_request1, + blank_ballot_count[0], + ) + .unwrap(); + + let response2 = coordinator::certify_unbounded_voter( + &coordinator_key_pair.1, + ®istration_request2, + blank_ballot_count[1], + ) + .unwrap(); + + let response3 = coordinator::certify_unbounded_voter( + &coordinator_key_pair.1, + ®istration_request3, + blank_ballot_count[2], + ) + .unwrap(); + + let mut encrypted_vote_sum = VoteStorage::new(); + + let make_choice = |x: &Vec, y: &Vec| { + let mut choices = VoteChoices::new(); + for i in 0..candidate_list.len() { + let mut choice = VoteChoice::new(); + choice.set_candidate(candidate_list[i].clone()); + choice.set_value(x[i] as u32); + choices.mut_choice().push(choice); + } + // unlisted + for j in 0..y.len() { + let mut pair_unlisted = UnlistedVoteChoice::new(); + pair_unlisted.set_candidate_id(y[j] as u32); + pair_unlisted.set_value(x[j] as u32); + choices.mut_unlisted_choice().push(pair_unlisted); + } + choices + }; + + // make unlisted choice + let choice_candidate_unlisted1 = + &candidate_list_unlisted[0..3].to_vec(); + let choice1 = + make_choice(&voting_ballot_weight[0], choice_candidate_unlisted1); + wedpr_println!("choice1:{:?}", choice1); + + let vote_request1 = voter::vote_unbounded_unlisted( + &voter1_secret_pair.weight_secret, + &voter1_secret_pair.zero_sercret, + &choice1, + &response1, + &poll_parameters, + ) + .unwrap(); + // verify + assert_eq!( + true, + verifier::verify_unbounded_vote_request_unlisted( + &poll_parameters, + &vote_request1, + &coordinator_key_pair.0 + ) + .unwrap() + ); + // aggregate + assert_eq!( + true, + coordinator::aggregate_vote_sum_response_unlisted( + &poll_parameters, + &vote_request1.get_vote(), + &mut encrypted_vote_sum + ) + .unwrap() + ); + // vote2 + let choice_candidate_unlisted2 = + &candidate_list_unlisted[1..3].to_vec(); + let choice2 = + make_choice(&voting_ballot_weight[1], choice_candidate_unlisted2); + wedpr_println!("choice2:{:?}", choice2); + let vote_request2 = voter::vote_unbounded_unlisted( + &voter2_secret_pair.weight_secret, + &voter2_secret_pair.zero_sercret, + &choice2, + &response2, + &poll_parameters, + ) + .unwrap(); + assert_eq!( + true, + verifier::verify_unbounded_vote_request_unlisted( + &poll_parameters, + &vote_request2, + &coordinator_key_pair.0 + ) + .unwrap() + ); + assert_eq!( + true, + coordinator::aggregate_vote_sum_response_unlisted( + &poll_parameters, + &vote_request2.get_vote(), + &mut encrypted_vote_sum + ) + .unwrap() + ); + // vote3 + let choice_candidate_unlisted3 = + &candidate_list_unlisted[2..3].to_vec(); + let choice3 = + make_choice(&voting_ballot_weight[2], choice_candidate_unlisted3); + wedpr_println!("choice3:{:?}", choice3); + let vote_request3 = voter::vote_unbounded_unlisted( + &voter3_secret_pair.weight_secret, + &voter3_secret_pair.zero_sercret, + &choice3, + &response3, + &poll_parameters, + ) + .unwrap(); + assert_eq!( + true, + verifier::verify_unbounded_vote_request_unlisted( + &poll_parameters, + &vote_request3, + &coordinator_key_pair.0 + ) + .unwrap() + ); + assert_eq!( + true, + coordinator::aggregate_vote_sum_response_unlisted( + &poll_parameters, + &vote_request3.get_vote(), + &mut encrypted_vote_sum + ) + .unwrap() + ); + wedpr_println!("encrypted_vote_sum: {:?}", encrypted_vote_sum); + + let mut vote_sum_total = DecryptedResultPartStorage::new(); + + let decrypt_request1 = counter::count_unlisted( + counter_id_list[0], + &counter1, + &encrypted_vote_sum, + ) + .unwrap(); + // wedpr_println!("decrypt_request1=========================:{:? + // }", decrypt_request1); + assert_eq!( + true, + verifier::verify_count_request_unlisted( + &poll_parameters, + &bytes_to_point(&counter_share1.get_poll_point_share()) + .unwrap(), + &encrypted_vote_sum, + &decrypt_request1 + ) + .unwrap() + ); + + assert_eq!( + true, + coordinator::aggregate_decrypted_part_sum_unlisted( + &poll_parameters, + &decrypt_request1, + &mut vote_sum_total, + ) + .unwrap() + ); + let decrypt_request2 = counter::count_unlisted( + counter_id_list[1], + &counter2, + &encrypted_vote_sum, + ) + .unwrap(); + // wedpr_println!("decrypt_request2=========================:{:? + // }", decrypt_request2); + assert_eq!( + true, + verifier::verify_count_request_unlisted( + &poll_parameters, + &bytes_to_point(&counter_share2.get_poll_point_share()) + .unwrap(), + &encrypted_vote_sum, + &decrypt_request2 + ) + .unwrap() + ); + + assert_eq!( + true, + coordinator::aggregate_decrypted_part_sum_unlisted( + &poll_parameters, + &decrypt_request2, + &mut vote_sum_total, + ) + .unwrap() + ); + + let decrypt_request3 = counter::count_unlisted( + counter_id_list[2], + &counter3, + &encrypted_vote_sum, + ) + .unwrap(); + // wedpr_println!("decrypt_request3=========================:{:? + // }", decrypt_request3); + assert_eq!( + true, + verifier::verify_count_request_unlisted( + &poll_parameters, + &bytes_to_point(&counter_share3.get_poll_point_share()) + .unwrap(), + &encrypted_vote_sum, + &decrypt_request3 + ) + .unwrap() + ); + + assert_eq!( + true, + coordinator::aggregate_decrypted_part_sum_unlisted( + &poll_parameters, + &decrypt_request3, + &mut vote_sum_total, + ) + .unwrap() + ); + // wedpr_println!("vote_sum_total:{:?}", vote_sum_total); + + let final_result_request_unlisted = + coordinator::finalize_vote_result_unlisted( + &poll_parameters, + &encrypted_vote_sum, + &mut vote_sum_total, + max_vote_number, + max_candidate_number, + ) + .unwrap(); + + wedpr_println!( + "final result unlisted is : {:?}", + final_result_request_unlisted + ); + + let result = verifier::verify_vote_result( + &poll_parameters, + &encrypted_vote_sum, + &vote_sum_total, + &final_result_request_unlisted, + ) + .unwrap(); + assert!(result); + } } diff --git a/solution/anonymous_ciphertext_voting/src/verifier.rs b/solution/anonymous_ciphertext_voting/src/verifier.rs index 80fbfb2..9110b3c 100644 --- a/solution/anonymous_ciphertext_voting/src/verifier.rs +++ b/solution/anonymous_ciphertext_voting/src/verifier.rs @@ -4,34 +4,38 @@ use curve25519_dalek::{ristretto::RistrettoPoint, scalar::Scalar}; use wedpr_l_crypto_zkp_discrete_logarithm_proof::{ + verify_either_equality_relationship_proof, verify_equality_relationship_proof, verify_format_proof, verify_sum_relationship, }; use wedpr_l_crypto_zkp_range_proof::verify_value_range_in_batch; use wedpr_l_crypto_zkp_utils::{bytes_to_point, BASEPOINT_G1, BASEPOINT_G2}; -use wedpr_l_utils::{ - error::WedprError, - traits::{Hash, Signature}, -}; +use wedpr_l_utils::error::WedprError; use wedpr_s_protos::{ bytes_to_proto, - generated::zkp::{PBBalanceProof, PBEqualityProof}, + generated::{ + acv::BallotProof, + zkp::{PBBalanceProof, PBEqualityProof}, + }, + verify_ballot_signature, verify_ballots_signature, }; use wedpr_s_protos::generated::acv::{ - DecryptedResultPartStorage, PollParametersStorage, VoteRequest, - VoteResultStorage, VoteStorage, + Ballot, CipherPointsToBallotPair, CipherPointsToBallotProofPair, + DecryptedResultPartStorage, PollParametersStorage, StringToBallotProofPair, + UnlistedBallotDecryptedResult, VoteRequest, VoteResultStorage, VoteStorage, }; use crate::{ - config::{HASH, POLL_RESULT_KEY_TOTAL_BALLOTS, SIGNATURE}, + config::POLL_RESULT_KEY_TOTAL_BALLOTS, utils::{ align_commitment_list_if_needed, get_ballot_by_candidate, get_counting_part_by_candidate, get_int64_by_candidate, }, }; use wedpr_s_protos::{ - pb_to_arithmetric_proof, pb_to_equality_proof, pb_to_format_proof, + pb_to_arithmetric_proof, pb_to_balance_proof, pb_to_equality_proof, + pb_to_format_proof, }; /// Verifies whether ciphertext ballots from a certified voter are valid. @@ -42,12 +46,11 @@ pub fn verify_vote_request( ) -> Result { let poll_point = bytes_to_point(poll_parameters.get_poll_point())?; let signature = vote_request.get_vote().get_signature(); + let blank_ballot = vote_request.get_vote().get_blank_ballot(); - let mut hash_vec = Vec::new(); - hash_vec.append(&mut blank_ballot.get_ciphertext1().to_vec()); - hash_vec.append(&mut blank_ballot.get_ciphertext2().to_vec()); - let message_hash: Vec = HASH.hash(&hash_vec); - if !SIGNATURE.verify(&public_key, &message_hash.as_ref(), &signature) { + let verify_result = + verify_ballot_signature(public_key, blank_ballot, &signature.to_vec())?; + if !verify_result { return Err(WedprError::VerificationError); } @@ -66,7 +69,6 @@ pub fn verify_vote_request( align_commitment_list_if_needed(&mut commitments); let range_proof = vote_request.get_range_proof(); if !verify_value_range_in_batch(&commitments, range_proof, &poll_point) { - wedpr_println!("verify range proof failed!"); return Err(WedprError::VerificationError); } @@ -88,7 +90,6 @@ pub fn verify_vote_request( &*BASEPOINT_G2, &poll_point, )? { - wedpr_println!("verify_format failed!"); return Err(WedprError::VerificationError); } } @@ -189,7 +190,6 @@ pub fn verify_vote_result( if expected_blank_ballot_result .ne(&(*BASEPOINT_G1 * (Scalar::from(blank_result as u64)))) { - wedpr_println!("verify blank_ballot_result failed!"); return Ok(false); } @@ -214,3 +214,319 @@ pub fn verify_vote_result( } Ok(true) } + +fn verify_count_request_for_unlisted_candidate( + counter_share: &RistrettoPoint, + candidate_vote_sum: &CipherPointsToBallotPair, + candidate_aggregated_unlisted_decrypted_result: &UnlistedBallotDecryptedResult, +) -> Result { + let unlisted_candidate_cipher = candidate_vote_sum.get_key(); + let unlisted_candidate_basepoint2 = + bytes_to_point(unlisted_candidate_cipher.get_ciphertext2())?; + let decrypted_unlisted_candidate = + candidate_aggregated_unlisted_decrypted_result + .get_decrypted_unlisted_candidate(); + let equality_proof = pb_to_equality_proof(&bytes_to_proto( + &decrypted_unlisted_candidate.get_equality_proof(), + )?)?; + // verify the equality proof for unlisted candidate + if !verify_equality_relationship_proof( + &counter_share, + &bytes_to_point(decrypted_unlisted_candidate.get_blinding_c2())?, + &equality_proof, + &BASEPOINT_G2, + &unlisted_candidate_basepoint2, + )? { + return Ok(false); + } + // verify the equality proof for unlisted candidate ballot + let unlisted_candidate_ballot = candidate_vote_sum.get_ballot(); + let decrypted_unlisted_candidate_ballot_list = + candidate_aggregated_unlisted_decrypted_result + .get_decrypted_unlisted_candidate_ballot(); + // without candidate ballot + if decrypted_unlisted_candidate_ballot_list.is_empty() { + return Ok(false); + } + // verify equality proof for the candidate ballot + let unlisted_candidate_ballot_basepoint2 = + bytes_to_point(unlisted_candidate_ballot.get_ciphertext2())?; + let equality_proof = pb_to_equality_proof(&bytes_to_proto( + decrypted_unlisted_candidate_ballot_list[0].get_equality_proof(), + )?)?; + let c2_point = bytes_to_point( + decrypted_unlisted_candidate_ballot_list[0].get_blinding_c2(), + )?; + if !verify_equality_relationship_proof( + &counter_share, + &c2_point, + &equality_proof, + &BASEPOINT_G2, + &unlisted_candidate_ballot_basepoint2, + )? { + return Ok(false); + } + Ok(true) +} + +fn verify_count_request_for_candidate( + counter_share: &RistrettoPoint, + candidate_id: &str, + vote_sum: &VoteStorage, + aggregated_decrypted_result: &DecryptedResultPartStorage, +) -> Result { + let candidate_ballot = get_ballot_by_candidate(vote_sum, candidate_id)?; + let decrypted_candidate_part = get_counting_part_by_candidate( + aggregated_decrypted_result, + candidate_id, + )?; + let proof = pb_to_equality_proof(&bytes_to_proto( + &decrypted_candidate_part.get_equality_proof(), + )?)?; + // verify equality from vote_sum to counting_sum + if !verify_equality_relationship_proof( + &counter_share, + &(bytes_to_point(decrypted_candidate_part.get_blinding_c2())?), + &proof, + &BASEPOINT_G2, + &(bytes_to_point(candidate_ballot.get_ciphertext2())?), + )? { + return Ok(false); + } + Ok(true) +} + +pub fn verify_count_request_unlisted( + poll_parameters: &PollParametersStorage, + counter_share: &RistrettoPoint, + vote_sum: &VoteStorage, + aggregated_decrypted_result: &DecryptedResultPartStorage, +) -> Result { + // verify equality for blank_ballot + let blank_blinding_c2_sum = + bytes_to_point(vote_sum.get_blank_ballot().get_ciphertext2())?; + let blank_blinding_c2 = bytes_to_point( + &aggregated_decrypted_result + .get_blank_part() + .get_blinding_c2(), + )?; + let blank_equality_proof = pb_to_equality_proof(&bytes_to_proto( + &aggregated_decrypted_result + .get_blank_part() + .get_equality_proof(), + )?)?; + if !verify_equality_relationship_proof( + &counter_share, + &blank_blinding_c2, + &blank_equality_proof, + &BASEPOINT_G2, + &blank_blinding_c2_sum, + )? { + return Ok(false); + } + // verify the candidate list + for candidate in poll_parameters.get_candidates().get_candidate() { + // verify the counter request for given candidate failed + if !verify_count_request_for_candidate( + &counter_share, + &candidate, + &vote_sum, + &aggregated_decrypted_result, + )? { + return Ok(false); + } + } + // verify the unlisted-candidate and the unlisted-candidate-ballot + for unlisted_candidate_ballot in vote_sum.get_voted_ballot_unlisted() { + // try to find the corresponding decrypted unlisted-candidate-ballot + // from aggregated_decrypted_result + let mut find_out_decrypted_result = false; + for unlisted_candidate_part in + aggregated_decrypted_result.get_unlisted_candidate_part() + { + if unlisted_candidate_ballot.get_key() + != unlisted_candidate_part.get_candidate_cipher() + { + continue; + } + find_out_decrypted_result = true; + // verify the unlisted-candidate + if !verify_count_request_for_unlisted_candidate( + &counter_share, + &unlisted_candidate_ballot, + &unlisted_candidate_part, + )? { + return Ok(false); + } + break; + } + // some unlisted-candidate-ballot without decrypted result, verify + // failed + if !find_out_decrypted_result { + return Ok(false); + } + } + Ok(true) +} + +fn verify_ballot_proof( + poll_parameters: &PollParametersStorage, + ballot_proof: &BallotProof, + candiate_ballot: &Ballot, + weight_ballot: &Ballot, + zero_ballot: &Ballot, +) -> Result { + // verify the format proof + let format_proof = + pb_to_format_proof(&bytes_to_proto(&ballot_proof.get_format_proof())?)?; + let polling_point = bytes_to_point(&poll_parameters.get_poll_point())?; + let ret = verify_format_proof( + &bytes_to_point(candiate_ballot.get_ciphertext1())?, + &bytes_to_point(candiate_ballot.get_ciphertext2())?, + &format_proof, + &BASEPOINT_G1, + &BASEPOINT_G2, + &polling_point, + )?; + if !ret { + return Err(WedprError::VerificationError); + } + // verify either_equality_proof + let either_equality_proof = pb_to_balance_proof(&bytes_to_proto( + &ballot_proof.get_either_equality_proof(), + )?)?; + let verify_ret = verify_either_equality_relationship_proof( + &bytes_to_point(candiate_ballot.get_ciphertext1())?, + &bytes_to_point(weight_ballot.get_ciphertext1())?, + &bytes_to_point(zero_ballot.get_ciphertext1())?, + &either_equality_proof, + &BASEPOINT_G1, + &polling_point, + )?; + if !verify_ret { + return Err(WedprError::VerificationError); + } + Ok(verify_ret) +} + +fn batch_verify_ballot_proof( + poll_parameters: &PollParametersStorage, + vote_request: &VoteRequest, + ballot_proof_infos: &Vec, +) -> Result { + let weight_ballot = vote_request.get_vote().get_blank_ballot(); + let zero_ballot = vote_request.get_vote().get_zero_ballot(); + for ballot_proof_info in ballot_proof_infos { + let candidate = ballot_proof_info.get_key(); + let ballot_proof = ballot_proof_info.get_value(); + // find the candiate ballot + let candidate_ballot = + get_ballot_by_candidate(&vote_request.get_vote(), candidate)?; + // verify the ballot proof + let verify_result = verify_ballot_proof( + &poll_parameters, + &ballot_proof, + &candidate_ballot, + &weight_ballot, + &zero_ballot, + )?; + if !verify_result { + return Err(WedprError::VerificationError); + } + } + Ok(true) +} + +fn batch_verify_unlisted_candidate_ballot_proof( + poll_parameters: &PollParametersStorage, + vote_request: &VoteRequest, + unlisted_ballot_proof_infos: &Vec, +) -> Result { + let weight_ballot = vote_request.get_vote().get_blank_ballot(); + let zero_ballot = vote_request.get_vote().get_zero_ballot(); + for unlisted_ballot_proof_info in unlisted_ballot_proof_infos { + let candidate = unlisted_ballot_proof_info.get_key(); + let ballot_proof = unlisted_ballot_proof_info.get_value(); + let mut find_unlisted_candidate = false; + // find the unlisted candiate ballot + for unlisted_vote_ballot in + vote_request.get_vote().get_voted_ballot_unlisted() + { + if unlisted_vote_ballot.get_key() != candidate { + continue; + } + find_unlisted_candidate = true; + // verify the found unlisted candidate ballot + let verify_result = verify_ballot_proof( + &poll_parameters, + &ballot_proof, + &unlisted_vote_ballot.get_ballot(), + &weight_ballot, + &zero_ballot, + )?; + if !verify_result { + return Err(WedprError::VerificationError); + } + } + if !find_unlisted_candidate { + return Err(WedprError::VerificationError); + } + } + Ok(true) +} + +pub fn verify_unbounded_vote_request( + poll_parameters: &PollParametersStorage, + vote_request: &VoteRequest, + public_key: &[u8], +) -> Result { + // check signature for the ballot with public key + let signature = vote_request.get_vote().get_signature(); + let weight_ballot = vote_request.get_vote().get_blank_ballot(); + let zero_ballot = vote_request.get_vote().get_zero_ballot(); + let verify_result = verify_ballots_signature( + public_key, + weight_ballot, + zero_ballot, + &signature.to_vec(), + )?; + if !verify_result { + return Err(WedprError::VerificationError); + } + // verify the ballot proof + let result = batch_verify_ballot_proof( + &poll_parameters, + &vote_request, + &(vote_request.get_ballot_proof()).to_vec(), + )?; + if !result { + return Err(WedprError::VerificationError); + } + Ok(true) +} + +pub fn verify_unbounded_vote_request_unlisted( + poll_parameters: &PollParametersStorage, + vote_request: &VoteRequest, + public_key: &[u8], +) -> Result { + // verify the listed unbounded vote request + let verify_result = verify_unbounded_vote_request( + &poll_parameters, + &vote_request, + public_key, + )?; + if !verify_result { + return Err(WedprError::VerificationError); + } + // verify the unlisted unbouded vote request + let result = batch_verify_unlisted_candidate_ballot_proof( + &poll_parameters, + &vote_request, + &(vote_request.get_unlisted_ballot_proof()).to_vec(), + )?; + if !result { + return Err(WedprError::VerificationError); + } + Ok(true) +} diff --git a/solution/anonymous_ciphertext_voting/src/voter.rs b/solution/anonymous_ciphertext_voting/src/voter.rs index f791c28..6d4cae9 100644 --- a/solution/anonymous_ciphertext_voting/src/voter.rs +++ b/solution/anonymous_ciphertext_voting/src/voter.rs @@ -3,13 +3,17 @@ //! Library for a poll voter. use crate::utils::{align_scalar_list_if_needed, align_u64_list_if_needed}; -use wedpr_s_protos::{arithmetric_proof_to_pb, format_proof_to_pb}; +use wedpr_s_protos::{ + arithmetric_proof_to_pb, balance_proof_to_pb, format_proof_to_pb, + generated::acv::CipherPoints, +}; use curve25519_dalek::{ ristretto::RistrettoPoint, scalar::Scalar, traits::MultiscalarMul, }; use wedpr_l_crypto_zkp_discrete_logarithm_proof::{ - prove_format_proof, prove_sum_relationship, + prove_either_equality_relationship_proof, prove_format_proof, + prove_sum_relationship, }; use wedpr_l_crypto_zkp_range_proof::prove_value_range_in_batch; use wedpr_l_crypto_zkp_utils::{ @@ -20,9 +24,10 @@ use wedpr_l_utils::error::WedprError; use wedpr_s_protos::{ generated::acv::{ Ballot, BallotProof, CandidateBallot, CandidateList, - PollParametersStorage, RegistrationRequest, RegistrationResponse, - StringToBallotProofPair, VoteChoice, VoteChoices, VoteRequest, - VoterSecret, + CipherPointsToBallotPair, CipherPointsToBallotProofPair, + PollParametersStorage, RegistrationBlindingPoint, RegistrationRequest, + RegistrationResponse, StringToBallotProofPair, VoteChoice, VoteChoices, + VoteRequest, VoterSecret, }, proto_to_bytes, }; @@ -37,20 +42,49 @@ pub fn make_voter_secret() -> VoterSecret { } } -/// Makes a request for voter registration. -pub fn make_registration_request( +pub fn generate_registration_blinding_point( secret: &VoterSecret, poll_parameters: &PollParametersStorage, -) -> Result { +) -> Result { let voter_secret = bytes_to_scalar(secret.get_voter_secret())?; let blinding_basepoint_g2 = voter_secret * *BASEPOINT_G2; let poll_point = bytes_to_point(poll_parameters.get_poll_point())?; let blinding_poll_point = voter_secret * poll_point; - let mut request = RegistrationRequest::new(); - let weight_point = request.mut_weight_point(); - weight_point + let mut registration_blinding_point = RegistrationBlindingPoint::new(); + registration_blinding_point .set_blinding_basepoint_g2(point_to_bytes(&blinding_basepoint_g2)); - weight_point.set_blinding_poll_point(point_to_bytes(&blinding_poll_point)); + registration_blinding_point + .set_blinding_poll_point(point_to_bytes(&blinding_poll_point)); + Ok(registration_blinding_point) +} + +/// Makes a request for voter registration. +pub fn make_registration_request( + secret: &VoterSecret, + poll_parameters: &PollParametersStorage, +) -> Result { + let mut request = RegistrationRequest::new(); + request.set_weight_point(generate_registration_blinding_point( + secret, + poll_parameters, + )?); + Ok(request) +} + +pub fn make_unbounded_registration_request( + zero_secret: &VoterSecret, + weight_secret: &VoterSecret, + poll_parameters: &PollParametersStorage, +) -> Result { + let mut request = RegistrationRequest::new(); + request.set_weight_point(generate_registration_blinding_point( + weight_secret, + poll_parameters, + )?); + request.set_zero_point(generate_registration_blinding_point( + zero_secret, + poll_parameters, + )?); Ok(request) } @@ -197,3 +231,158 @@ pub fn vote( vote.set_blank_ballot(registration_response.get_ballot().clone()); Ok(vote_request) } + +pub fn generate_ballot_proof( + vote_value: u64, + registration_response: &RegistrationResponse, + poll_point: &RistrettoPoint, + voter_secret: &VoterSecret, + zero_secret: &VoterSecret, + ballot_proof: &mut BallotProof, + vote_ballot: &mut Ballot, +) -> Result { + let blinding = get_random_scalar(); + let c1_blinding = RistrettoPoint::multiscalar_mul( + &[Scalar::from(vote_value), blinding], + &[*BASEPOINT_G1, *poll_point], + ); + // generate either-equality proof + let either_equality_proof = prove_either_equality_relationship_proof( + vote_value, + registration_response.get_voter_weight() as u64, + &blinding, + &bytes_to_scalar(voter_secret.get_voter_secret())?, + &bytes_to_scalar(zero_secret.get_voter_secret())?, + &BASEPOINT_G1, + &poll_point, + ); + + // generate format proof + let format_proof = prove_format_proof( + vote_value, + &blinding, + &BASEPOINT_G1, + &BASEPOINT_G2, + &poll_point, + ); + let ciphertext2 = *BASEPOINT_G2 * blinding; + vote_ballot.set_ciphertext1(point_to_bytes(&c1_blinding)); + vote_ballot.set_ciphertext2(point_to_bytes(&ciphertext2)); + // set proofs + ballot_proof.set_either_equality_proof(proto_to_bytes( + &balance_proof_to_pb(&either_equality_proof), + )?); + ballot_proof + .set_format_proof(proto_to_bytes(&format_proof_to_pb(&format_proof))?); + Ok(true) +} + +pub fn vote_unbounded( + voter_secret: &VoterSecret, + zero_secret: &VoterSecret, + vote_choices: &VoteChoices, + registration_response: &RegistrationResponse, + poll_parameters: &PollParametersStorage, +) -> Result { + let mut vote_request = VoteRequest::new(); + let poll_point = bytes_to_point(poll_parameters.get_poll_point())?; + // generate ballot for every vote choice + for vote_choice in vote_choices.get_choice() { + let mut ballot_proof = BallotProof::new(); + let mut vote_ballot = Ballot::new(); + generate_ballot_proof( + vote_choice.get_value() as u64, + registration_response, + &poll_point, + voter_secret, + zero_secret, + &mut ballot_proof, + &mut vote_ballot, + )?; + // push ballot_proof + let mut proof_pair = StringToBallotProofPair::new(); + proof_pair.set_key(vote_choice.get_candidate().to_owned()); + proof_pair.set_value(ballot_proof); + vote_request.mut_ballot_proof().push(proof_pair); + // set ballot info + let mut ballot_pair = CandidateBallot::new(); + ballot_pair.set_candidate(vote_choice.get_candidate().to_owned()); + ballot_pair.set_ballot(vote_ballot); + vote_request.mut_vote().mut_voted_ballot().push(ballot_pair); + } + vote_request + .mut_vote() + .set_blank_ballot(registration_response.get_ballot().clone()); + vote_request + .mut_vote() + .set_zero_ballot(registration_response.get_zero_ballot().clone()); + vote_request + .mut_vote() + .set_signature(registration_response.get_signature().to_vec()); + Ok(vote_request) +} + +pub fn generate_candidate_cipher( + value: u64, + poll_point: &RistrettoPoint, +) -> Result { + let mut cipher_point = CipherPoints::new(); + let blinding = get_random_scalar(); + let ciphertext1 = RistrettoPoint::multiscalar_mul( + &[Scalar::from(value as u64), blinding], + &[*BASEPOINT_G2, *poll_point], + ); + let ciphertext2 = *BASEPOINT_G2 * blinding; + cipher_point.set_ciphertext1(point_to_bytes(&ciphertext1)); + cipher_point.set_ciphertext2(point_to_bytes(&ciphertext2)); + Ok(cipher_point) +} + +pub fn vote_unbounded_unlisted( + voter_secret: &VoterSecret, + zero_secret: &VoterSecret, + vote_choices: &VoteChoices, + registration_response: &RegistrationResponse, + poll_parameters: &PollParametersStorage, +) -> Result { + let mut vote_request = vote_unbounded( + voter_secret, + zero_secret, + vote_choices, + registration_response, + poll_parameters, + )?; + let poll_point = bytes_to_point(poll_parameters.get_poll_point())?; + for unlisted_vote_choice in vote_choices.get_unlisted_choice() { + let mut ballot_proof = BallotProof::new(); + let mut vote_ballot = Ballot::new(); + generate_ballot_proof( + unlisted_vote_choice.get_value() as u64, + registration_response, + &poll_point, + voter_secret, + zero_secret, + &mut ballot_proof, + &mut vote_ballot, + )?; + // update the vote_request + // push ballot_proof + let mut proof_pair = CipherPointsToBallotProofPair::new(); + let candidate_cipher = generate_candidate_cipher( + unlisted_vote_choice.get_candidate_id() as u64, + &poll_point, + )?; + proof_pair.set_key(candidate_cipher.clone()); + proof_pair.set_value(ballot_proof); + vote_request.mut_unlisted_ballot_proof().push(proof_pair); + // set the unlisted ballot info + let mut unlisted_ballot = CipherPointsToBallotPair::new(); + unlisted_ballot.set_key(candidate_cipher.clone()); + unlisted_ballot.set_ballot(vote_ballot); + vote_request + .mut_vote() + .mut_voted_ballot_unlisted() + .push(unlisted_ballot); + } + Ok(vote_request) +}