From 58a35d1baf1c3bcb106ec9ea284946cc3e2da9d2 Mon Sep 17 00:00:00 2001 From: HaoXuan40404 <444649358@qq.com> Date: Mon, 30 Aug 2021 17:34:54 +0800 Subject: [PATCH 01/15] add abv --- Cargo.toml | 1 + protos/solution/abv/abv.proto | 120 + protos/src/generated/abv.rs | 4702 +++++++++++++++++ protos/src/generated/hdk.rs | 6 +- protos/src/generated/mod.rs | 1 + protos/src/generated/scd.rs | 6 +- protos/src/generated/vcl.rs | 6 +- protos/src/main.rs | 2 +- solution/anonymous_bounded_voting/Cargo.toml | 22 + .../anonymous_bounded_voting/src/config.rs | 8 + .../src/coordinator.rs | 126 + .../anonymous_bounded_voting/src/counter.rs | 148 + solution/anonymous_bounded_voting/src/lib.rs | 189 + .../anonymous_bounded_voting/src/verifier.rs | 325 ++ .../anonymous_bounded_voting/src/voter.rs | 193 + 15 files changed, 5842 insertions(+), 13 deletions(-) create mode 100644 protos/solution/abv/abv.proto create mode 100644 protos/src/generated/abv.rs create mode 100644 solution/anonymous_bounded_voting/Cargo.toml create mode 100644 solution/anonymous_bounded_voting/src/config.rs create mode 100644 solution/anonymous_bounded_voting/src/coordinator.rs create mode 100644 solution/anonymous_bounded_voting/src/counter.rs create mode 100644 solution/anonymous_bounded_voting/src/lib.rs create mode 100644 solution/anonymous_bounded_voting/src/verifier.rs create mode 100644 solution/anonymous_bounded_voting/src/voter.rs diff --git a/Cargo.toml b/Cargo.toml index 330e473..9c8d152 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,4 +12,5 @@ members = [ "solution/key_tool_box/hierarchical_deterministic_key", "solution/selective_certificate_disclosure", "solution/verifiable_confidential_ledger", + "solution/anonymous_bounded_voting", ] diff --git a/protos/solution/abv/abv.proto b/protos/solution/abv/abv.proto new file mode 100644 index 0000000..4ef877d --- /dev/null +++ b/protos/solution/abv/abv.proto @@ -0,0 +1,120 @@ +// Copyright 2020 WeDPR Lab Project Authors. Licensed under Apache-2.0. + +syntax = "proto3"; + +package com.webank.wedpr.abv.proto; +option java_package = "com.webank.wedpr.abv.proto"; +option java_multiple_files = true; + +// Counter Secret value +message CounterSecret { + bytes poll_secret_share = 1; +} + +message CounterSystemParametersShareRequest { + string counter_id = 1; + bytes poll_point_share = 2; +} + +message CounterSystemParametersStorage { + repeated CounterSystemParametersShareRequest counter_parameters_request = 1; +} + +// Voter Secret value +message VoterSecret { + bytes vote_secret = 1; +} + +message RegistrationRequest { + RegistrationBlindingPoint weight_point = 1; +} + +message RegistrationBlindingPoint { + bytes blinding_poll_point = 1; + bytes blinding_basepoint_g2 = 2; +} + +message RegistrationResponse { + uint32 voter_weight = 1; + Ballot ballot = 2; + bytes signature = 3; + Ballot zero_ballot = 4; +} + +message Ballot { + bytes ciphertext1 = 1; + bytes ciphertext2 = 2; +} + +message VoteChoice { + string candidate = 1; + uint32 value = 2; +} + +message VoteChoices { + repeated VoteChoice choice = 1; +} + +message CandidateBallot { + string candidate = 1; + Ballot ballot = 2; +} + +message VoteStorage { + bytes signature = 1; + Ballot blank_ballot = 2; + Ballot rest_ballot = 3; + repeated CandidateBallot voted_ballot = 4; +} + +message CandidateList { + repeated string candidate = 1; +} + +message SystemParametersStorage { + bytes poll_point = 1; + CandidateList candidates = 2; +} + +message BallotProof { + bytes format_proof = 1; + bytes either_equality_proof = 2; +} + +message CandidateBallotProofPair { + string candidate = 1; + BallotProof value = 2; +} + +// Do not use Map, cause unordered in blockchain +message VoteRequest { + VoteStorage vote = 1; + repeated CandidateBallotProofPair ballot_proof = 2; + bytes range_proof = 3; + bytes sum_balance_proof = 4; +} + +message DecryptedResultPartStorage { + CountingPart blank_part = 1; + repeated StringToCountingPartPair candidate_part = 2; +} + +message StringToCountingPartPair { + string key = 1; + CountingPart value = 2; +} + +message CountingPart { + string counter_id = 1; + bytes c2_r = 2; + bytes equality_proof = 3; +} + +message VoteResultStorage { + repeated StringToInt64Pair result = 1; +} + +message StringToInt64Pair { + string key = 1; + int64 value = 2; +} \ No newline at end of file diff --git a/protos/src/generated/abv.rs b/protos/src/generated/abv.rs new file mode 100644 index 0000000..aaf69b5 --- /dev/null +++ b/protos/src/generated/abv.rs @@ -0,0 +1,4702 @@ +// This file is generated by rust-protobuf 2.25.1. Do not edit +// @generated + +// https://github.com/rust-lang/rust-clippy/issues/702 +#![allow(unknown_lints)] +#![allow(clippy::all)] + +#![allow(unused_attributes)] +#![cfg_attr(rustfmt, rustfmt::skip)] + +#![allow(box_pointers)] +#![allow(dead_code)] +#![allow(missing_docs)] +#![allow(non_camel_case_types)] +#![allow(non_snake_case)] +#![allow(non_upper_case_globals)] +#![allow(trivial_casts)] +#![allow(unused_imports)] +#![allow(unused_results)] +//! Generated file from `solution/abv/abv.proto` + +/// Generated files are compatible only with the same version +/// of protobuf runtime. +// const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_25_1; + +#[derive(PartialEq,Clone,Default)] +pub struct CounterSecret { + // message fields + pub poll_secret_share: ::std::vec::Vec, + // special fields + pub unknown_fields: ::protobuf::UnknownFields, + pub cached_size: ::protobuf::CachedSize, +} + +impl<'a> ::std::default::Default for &'a CounterSecret { + fn default() -> &'a CounterSecret { + ::default_instance() + } +} + +impl CounterSecret { + pub fn new() -> CounterSecret { + ::std::default::Default::default() + } + + // bytes poll_secret_share = 1; + + + pub fn get_poll_secret_share(&self) -> &[u8] { + &self.poll_secret_share + } + pub fn clear_poll_secret_share(&mut self) { + self.poll_secret_share.clear(); + } + + // Param is passed by value, moved + pub fn set_poll_secret_share(&mut self, v: ::std::vec::Vec) { + self.poll_secret_share = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_poll_secret_share(&mut self) -> &mut ::std::vec::Vec { + &mut self.poll_secret_share + } + + // Take field + pub fn take_poll_secret_share(&mut self) -> ::std::vec::Vec { + ::std::mem::replace(&mut self.poll_secret_share, ::std::vec::Vec::new()) + } +} + +impl ::protobuf::Message for CounterSecret { + 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.poll_secret_share)?; + }, + _ => { + ::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.poll_secret_share.is_empty() { + my_size += ::protobuf::rt::bytes_size(1, &self.poll_secret_share); + } + 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.poll_secret_share.is_empty() { + os.write_bytes(1, &self.poll_secret_share)?; + } + 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() -> CounterSecret { + CounterSecret::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>( + "poll_secret_share", + |m: &CounterSecret| { &m.poll_secret_share }, + |m: &mut CounterSecret| { &mut m.poll_secret_share }, + )); + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "CounterSecret", + fields, + file_descriptor_proto() + ) + }) + } + + fn default_instance() -> &'static CounterSecret { + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(CounterSecret::new) + } +} + +impl ::protobuf::Clear for CounterSecret { + fn clear(&mut self) { + self.poll_secret_share.clear(); + self.unknown_fields.clear(); + } +} + +impl ::std::fmt::Debug for CounterSecret { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + ::protobuf::text_format::fmt(self, f) + } +} + +impl ::protobuf::reflect::ProtobufValue for CounterSecret { + fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { + ::protobuf::reflect::ReflectValueRef::Message(self) + } +} + +#[derive(PartialEq,Clone,Default)] +pub struct CounterSystemParametersShareRequest { + // message fields + pub counter_id: ::std::string::String, + pub poll_point_share: ::std::vec::Vec, + // special fields + pub unknown_fields: ::protobuf::UnknownFields, + pub cached_size: ::protobuf::CachedSize, +} + +impl<'a> ::std::default::Default for &'a CounterSystemParametersShareRequest { + fn default() -> &'a CounterSystemParametersShareRequest { + ::default_instance() + } +} + +impl CounterSystemParametersShareRequest { + pub fn new() -> CounterSystemParametersShareRequest { + ::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 poll_point_share = 2; + + + pub fn get_poll_point_share(&self) -> &[u8] { + &self.poll_point_share + } + pub fn clear_poll_point_share(&mut self) { + self.poll_point_share.clear(); + } + + // Param is passed by value, moved + pub fn set_poll_point_share(&mut self, v: ::std::vec::Vec) { + self.poll_point_share = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_poll_point_share(&mut self) -> &mut ::std::vec::Vec { + &mut self.poll_point_share + } + + // Take field + pub fn take_poll_point_share(&mut self) -> ::std::vec::Vec { + ::std::mem::replace(&mut self.poll_point_share, ::std::vec::Vec::new()) + } +} + +impl ::protobuf::Message for CounterSystemParametersShareRequest { + 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.poll_point_share)?; + }, + _ => { + ::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.poll_point_share.is_empty() { + my_size += ::protobuf::rt::bytes_size(2, &self.poll_point_share); + } + 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.poll_point_share.is_empty() { + os.write_bytes(2, &self.poll_point_share)?; + } + 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() -> CounterSystemParametersShareRequest { + CounterSystemParametersShareRequest::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: &CounterSystemParametersShareRequest| { &m.counter_id }, + |m: &mut CounterSystemParametersShareRequest| { &mut m.counter_id }, + )); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( + "poll_point_share", + |m: &CounterSystemParametersShareRequest| { &m.poll_point_share }, + |m: &mut CounterSystemParametersShareRequest| { &mut m.poll_point_share }, + )); + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "CounterSystemParametersShareRequest", + fields, + file_descriptor_proto() + ) + }) + } + + fn default_instance() -> &'static CounterSystemParametersShareRequest { + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(CounterSystemParametersShareRequest::new) + } +} + +impl ::protobuf::Clear for CounterSystemParametersShareRequest { + fn clear(&mut self) { + self.counter_id.clear(); + self.poll_point_share.clear(); + self.unknown_fields.clear(); + } +} + +impl ::std::fmt::Debug for CounterSystemParametersShareRequest { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + ::protobuf::text_format::fmt(self, f) + } +} + +impl ::protobuf::reflect::ProtobufValue for CounterSystemParametersShareRequest { + fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { + ::protobuf::reflect::ReflectValueRef::Message(self) + } +} + +#[derive(PartialEq,Clone,Default)] +pub struct CounterSystemParametersStorage { + // message fields + pub counter_parameters_request: ::protobuf::RepeatedField, + // special fields + pub unknown_fields: ::protobuf::UnknownFields, + pub cached_size: ::protobuf::CachedSize, +} + +impl<'a> ::std::default::Default for &'a CounterSystemParametersStorage { + fn default() -> &'a CounterSystemParametersStorage { + ::default_instance() + } +} + +impl CounterSystemParametersStorage { + pub fn new() -> CounterSystemParametersStorage { + ::std::default::Default::default() + } + + // repeated .com.webank.wedpr.abv.proto.CounterSystemParametersShareRequest counter_parameters_request = 1; + + + pub fn get_counter_parameters_request(&self) -> &[CounterSystemParametersShareRequest] { + &self.counter_parameters_request + } + pub fn clear_counter_parameters_request(&mut self) { + self.counter_parameters_request.clear(); + } + + // Param is passed by value, moved + pub fn set_counter_parameters_request(&mut self, v: ::protobuf::RepeatedField) { + self.counter_parameters_request = v; + } + + // Mutable pointer to the field. + pub fn mut_counter_parameters_request(&mut self) -> &mut ::protobuf::RepeatedField { + &mut self.counter_parameters_request + } + + // Take field + pub fn take_counter_parameters_request(&mut self) -> ::protobuf::RepeatedField { + ::std::mem::replace(&mut self.counter_parameters_request, ::protobuf::RepeatedField::new()) + } +} + +impl ::protobuf::Message for CounterSystemParametersStorage { + fn is_initialized(&self) -> bool { + for v in &self.counter_parameters_request { + 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_repeated_message_into(wire_type, is, &mut self.counter_parameters_request)?; + }, + _ => { + ::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; + for value in &self.counter_parameters_request { + 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<()> { + for v in &self.counter_parameters_request { + os.write_tag(1, ::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() -> CounterSystemParametersStorage { + CounterSystemParametersStorage::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_repeated_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( + "counter_parameters_request", + |m: &CounterSystemParametersStorage| { &m.counter_parameters_request }, + |m: &mut CounterSystemParametersStorage| { &mut m.counter_parameters_request }, + )); + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "CounterSystemParametersStorage", + fields, + file_descriptor_proto() + ) + }) + } + + fn default_instance() -> &'static CounterSystemParametersStorage { + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(CounterSystemParametersStorage::new) + } +} + +impl ::protobuf::Clear for CounterSystemParametersStorage { + fn clear(&mut self) { + self.counter_parameters_request.clear(); + self.unknown_fields.clear(); + } +} + +impl ::std::fmt::Debug for CounterSystemParametersStorage { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + ::protobuf::text_format::fmt(self, f) + } +} + +impl ::protobuf::reflect::ProtobufValue for CounterSystemParametersStorage { + fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { + ::protobuf::reflect::ReflectValueRef::Message(self) + } +} + +#[derive(PartialEq,Clone,Default)] +pub struct VoterSecret { + // message fields + pub vote_secret: ::std::vec::Vec, + // special fields + pub unknown_fields: ::protobuf::UnknownFields, + pub cached_size: ::protobuf::CachedSize, +} + +impl<'a> ::std::default::Default for &'a VoterSecret { + fn default() -> &'a VoterSecret { + ::default_instance() + } +} + +impl VoterSecret { + pub fn new() -> VoterSecret { + ::std::default::Default::default() + } + + // bytes vote_secret = 1; + + + pub fn get_vote_secret(&self) -> &[u8] { + &self.vote_secret + } + pub fn clear_vote_secret(&mut self) { + self.vote_secret.clear(); + } + + // Param is passed by value, moved + pub fn set_vote_secret(&mut self, v: ::std::vec::Vec) { + self.vote_secret = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_vote_secret(&mut self) -> &mut ::std::vec::Vec { + &mut self.vote_secret + } + + // Take field + pub fn take_vote_secret(&mut self) -> ::std::vec::Vec { + ::std::mem::replace(&mut self.vote_secret, ::std::vec::Vec::new()) + } +} + +impl ::protobuf::Message for VoterSecret { + 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.vote_secret)?; + }, + _ => { + ::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.vote_secret.is_empty() { + my_size += ::protobuf::rt::bytes_size(1, &self.vote_secret); + } + 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.vote_secret.is_empty() { + os.write_bytes(1, &self.vote_secret)?; + } + 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() -> VoterSecret { + VoterSecret::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>( + "vote_secret", + |m: &VoterSecret| { &m.vote_secret }, + |m: &mut VoterSecret| { &mut m.vote_secret }, + )); + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "VoterSecret", + fields, + file_descriptor_proto() + ) + }) + } + + fn default_instance() -> &'static VoterSecret { + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(VoterSecret::new) + } +} + +impl ::protobuf::Clear for VoterSecret { + fn clear(&mut self) { + self.vote_secret.clear(); + self.unknown_fields.clear(); + } +} + +impl ::std::fmt::Debug for VoterSecret { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + ::protobuf::text_format::fmt(self, f) + } +} + +impl ::protobuf::reflect::ProtobufValue for VoterSecret { + fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { + ::protobuf::reflect::ReflectValueRef::Message(self) + } +} + +#[derive(PartialEq,Clone,Default)] +pub struct RegistrationRequest { + // message fields + pub weight_point: ::protobuf::SingularPtrField, + // special fields + pub unknown_fields: ::protobuf::UnknownFields, + pub cached_size: ::protobuf::CachedSize, +} + +impl<'a> ::std::default::Default for &'a RegistrationRequest { + fn default() -> &'a RegistrationRequest { + ::default_instance() + } +} + +impl RegistrationRequest { + pub fn new() -> RegistrationRequest { + ::std::default::Default::default() + } + + // .com.webank.wedpr.abv.proto.RegistrationBlindingPoint weight_point = 1; + + + pub fn get_weight_point(&self) -> &RegistrationBlindingPoint { + self.weight_point.as_ref().unwrap_or_else(|| ::default_instance()) + } + pub fn clear_weight_point(&mut self) { + self.weight_point.clear(); + } + + pub fn has_weight_point(&self) -> bool { + self.weight_point.is_some() + } + + // Param is passed by value, moved + pub fn set_weight_point(&mut self, v: RegistrationBlindingPoint) { + self.weight_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_weight_point(&mut self) -> &mut RegistrationBlindingPoint { + if self.weight_point.is_none() { + self.weight_point.set_default(); + } + self.weight_point.as_mut().unwrap() + } + + // Take field + pub fn take_weight_point(&mut self) -> RegistrationBlindingPoint { + self.weight_point.take().unwrap_or_else(|| RegistrationBlindingPoint::new()) + } +} + +impl ::protobuf::Message for RegistrationRequest { + fn is_initialized(&self) -> bool { + for v in &self.weight_point { + 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.weight_point)?; + }, + _ => { + ::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.weight_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 + } + + fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { + if let Some(ref v) = self.weight_point.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)?; + } + 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() -> RegistrationRequest { + RegistrationRequest::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>( + "weight_point", + |m: &RegistrationRequest| { &m.weight_point }, + |m: &mut RegistrationRequest| { &mut m.weight_point }, + )); + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "RegistrationRequest", + fields, + file_descriptor_proto() + ) + }) + } + + fn default_instance() -> &'static RegistrationRequest { + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(RegistrationRequest::new) + } +} + +impl ::protobuf::Clear for RegistrationRequest { + fn clear(&mut self) { + self.weight_point.clear(); + self.unknown_fields.clear(); + } +} + +impl ::std::fmt::Debug for RegistrationRequest { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + ::protobuf::text_format::fmt(self, f) + } +} + +impl ::protobuf::reflect::ProtobufValue for RegistrationRequest { + fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { + ::protobuf::reflect::ReflectValueRef::Message(self) + } +} + +#[derive(PartialEq,Clone,Default)] +pub struct RegistrationBlindingPoint { + // message fields + pub blinding_poll_point: ::std::vec::Vec, + pub blinding_basepoint_g2: ::std::vec::Vec, + // special fields + pub unknown_fields: ::protobuf::UnknownFields, + pub cached_size: ::protobuf::CachedSize, +} + +impl<'a> ::std::default::Default for &'a RegistrationBlindingPoint { + fn default() -> &'a RegistrationBlindingPoint { + ::default_instance() + } +} + +impl RegistrationBlindingPoint { + pub fn new() -> RegistrationBlindingPoint { + ::std::default::Default::default() + } + + // bytes blinding_poll_point = 1; + + + pub fn get_blinding_poll_point(&self) -> &[u8] { + &self.blinding_poll_point + } + pub fn clear_blinding_poll_point(&mut self) { + self.blinding_poll_point.clear(); + } + + // Param is passed by value, moved + pub fn set_blinding_poll_point(&mut self, v: ::std::vec::Vec) { + self.blinding_poll_point = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_blinding_poll_point(&mut self) -> &mut ::std::vec::Vec { + &mut self.blinding_poll_point + } + + // Take field + pub fn take_blinding_poll_point(&mut self) -> ::std::vec::Vec { + ::std::mem::replace(&mut self.blinding_poll_point, ::std::vec::Vec::new()) + } + + // bytes blinding_basepoint_g2 = 2; + + + pub fn get_blinding_basepoint_g2(&self) -> &[u8] { + &self.blinding_basepoint_g2 + } + pub fn clear_blinding_basepoint_g2(&mut self) { + self.blinding_basepoint_g2.clear(); + } + + // Param is passed by value, moved + pub fn set_blinding_basepoint_g2(&mut self, v: ::std::vec::Vec) { + self.blinding_basepoint_g2 = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_blinding_basepoint_g2(&mut self) -> &mut ::std::vec::Vec { + &mut self.blinding_basepoint_g2 + } + + // Take field + pub fn take_blinding_basepoint_g2(&mut self) -> ::std::vec::Vec { + ::std::mem::replace(&mut self.blinding_basepoint_g2, ::std::vec::Vec::new()) + } +} + +impl ::protobuf::Message for RegistrationBlindingPoint { + 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.blinding_poll_point)?; + }, + 2 => { + ::protobuf::rt::read_singular_proto3_bytes_into(wire_type, is, &mut self.blinding_basepoint_g2)?; + }, + _ => { + ::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.blinding_poll_point.is_empty() { + my_size += ::protobuf::rt::bytes_size(1, &self.blinding_poll_point); + } + if !self.blinding_basepoint_g2.is_empty() { + my_size += ::protobuf::rt::bytes_size(2, &self.blinding_basepoint_g2); + } + 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.blinding_poll_point.is_empty() { + os.write_bytes(1, &self.blinding_poll_point)?; + } + if !self.blinding_basepoint_g2.is_empty() { + os.write_bytes(2, &self.blinding_basepoint_g2)?; + } + 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() -> RegistrationBlindingPoint { + RegistrationBlindingPoint::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>( + "blinding_poll_point", + |m: &RegistrationBlindingPoint| { &m.blinding_poll_point }, + |m: &mut RegistrationBlindingPoint| { &mut m.blinding_poll_point }, + )); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( + "blinding_basepoint_g2", + |m: &RegistrationBlindingPoint| { &m.blinding_basepoint_g2 }, + |m: &mut RegistrationBlindingPoint| { &mut m.blinding_basepoint_g2 }, + )); + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "RegistrationBlindingPoint", + fields, + file_descriptor_proto() + ) + }) + } + + fn default_instance() -> &'static RegistrationBlindingPoint { + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(RegistrationBlindingPoint::new) + } +} + +impl ::protobuf::Clear for RegistrationBlindingPoint { + fn clear(&mut self) { + self.blinding_poll_point.clear(); + self.blinding_basepoint_g2.clear(); + self.unknown_fields.clear(); + } +} + +impl ::std::fmt::Debug for RegistrationBlindingPoint { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + ::protobuf::text_format::fmt(self, f) + } +} + +impl ::protobuf::reflect::ProtobufValue for RegistrationBlindingPoint { + fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { + ::protobuf::reflect::ReflectValueRef::Message(self) + } +} + +#[derive(PartialEq,Clone,Default)] +pub struct RegistrationResponse { + // message fields + 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, +} + +impl<'a> ::std::default::Default for &'a RegistrationResponse { + fn default() -> &'a RegistrationResponse { + ::default_instance() + } +} + +impl RegistrationResponse { + pub fn new() -> RegistrationResponse { + ::std::default::Default::default() + } + + // uint32 voter_weight = 1; + + + pub fn get_voter_weight(&self) -> u32 { + self.voter_weight + } + pub fn clear_voter_weight(&mut self) { + self.voter_weight = 0; + } + + // Param is passed by value, moved + pub fn set_voter_weight(&mut self, v: u32) { + self.voter_weight = v; + } + + // .com.webank.wedpr.abv.proto.Ballot ballot = 2; + + + pub fn get_ballot(&self) -> &Ballot { + self.ballot.as_ref().unwrap_or_else(|| ::default_instance()) + } + 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_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_ballot(&mut self) -> &mut Ballot { + if self.ballot.is_none() { + self.ballot.set_default(); + } + self.ballot.as_mut().unwrap() + } + + // Take field + pub fn take_ballot(&mut self) -> Ballot { + self.ballot.take().unwrap_or_else(|| Ballot::new()) + } + + // bytes signature = 3; + + + pub fn get_signature(&self) -> &[u8] { + &self.signature + } + pub fn clear_signature(&mut self) { + self.signature.clear(); + } + + // Param is passed by value, moved + pub fn set_signature(&mut self, v: ::std::vec::Vec) { + self.signature = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_signature(&mut self) -> &mut ::std::vec::Vec { + &mut self.signature + } + + // Take field + pub fn take_signature(&mut self) -> ::std::vec::Vec { + ::std::mem::replace(&mut self.signature, ::std::vec::Vec::new()) + } + + // .com.webank.wedpr.abv.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 { + fn is_initialized(&self) -> bool { + for v in &self.ballot { + if !v.is_initialized() { + return false; + } + }; + for v in &self.zero_ballot { + 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 => { + 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.voter_weight = tmp; + }, + 2 => { + ::protobuf::rt::read_singular_message_into(wire_type, is, &mut self.ballot)?; + }, + 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())?; + }, + }; + } + ::std::result::Result::Ok(()) + } + + // Compute sizes of nested messages + #[allow(unused_variables)] + fn compute_size(&self) -> u32 { + let mut my_size = 0; + if self.voter_weight != 0 { + my_size += ::protobuf::rt::value_size(1, self.voter_weight, ::protobuf::wire_format::WireTypeVarint); + } + 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; + } + 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 + } + + fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { + if self.voter_weight != 0 { + os.write_uint32(1, self.voter_weight)?; + } + if let Some(ref v) = self.ballot.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)?; + } + 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(()) + } + + 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() -> RegistrationResponse { + RegistrationResponse::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>( + "voter_weight", + |m: &RegistrationResponse| { &m.voter_weight }, + |m: &mut RegistrationResponse| { &mut m.voter_weight }, + )); + fields.push(::protobuf::reflect::accessor::make_singular_ptr_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( + "ballot", + |m: &RegistrationResponse| { &m.ballot }, + |m: &mut RegistrationResponse| { &mut m.ballot }, + )); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( + "signature", + |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, + file_descriptor_proto() + ) + }) + } + + fn default_instance() -> &'static RegistrationResponse { + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(RegistrationResponse::new) + } +} + +impl ::protobuf::Clear for RegistrationResponse { + fn clear(&mut self) { + self.voter_weight = 0; + self.ballot.clear(); + self.signature.clear(); + self.zero_ballot.clear(); + self.unknown_fields.clear(); + } +} + +impl ::std::fmt::Debug for RegistrationResponse { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + ::protobuf::text_format::fmt(self, f) + } +} + +impl ::protobuf::reflect::ProtobufValue for RegistrationResponse { + fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { + ::protobuf::reflect::ReflectValueRef::Message(self) + } +} + +#[derive(PartialEq,Clone,Default)] +pub struct Ballot { + // 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 Ballot { + fn default() -> &'a Ballot { + ::default_instance() + } +} + +impl Ballot { + pub fn new() -> Ballot { + ::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 Ballot { + 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() -> Ballot { + Ballot::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: &Ballot| { &m.ciphertext1 }, + |m: &mut Ballot| { &mut m.ciphertext1 }, + )); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( + "ciphertext2", + |m: &Ballot| { &m.ciphertext2 }, + |m: &mut Ballot| { &mut m.ciphertext2 }, + )); + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "Ballot", + fields, + file_descriptor_proto() + ) + }) + } + + fn default_instance() -> &'static Ballot { + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(Ballot::new) + } +} + +impl ::protobuf::Clear for Ballot { + fn clear(&mut self) { + self.ciphertext1.clear(); + self.ciphertext2.clear(); + self.unknown_fields.clear(); + } +} + +impl ::std::fmt::Debug for Ballot { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + ::protobuf::text_format::fmt(self, f) + } +} + +impl ::protobuf::reflect::ProtobufValue for Ballot { + fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { + ::protobuf::reflect::ReflectValueRef::Message(self) + } +} + +#[derive(PartialEq,Clone,Default)] +pub struct VoteChoice { + // message fields + pub candidate: ::std::string::String, + pub value: u32, + // special fields + pub unknown_fields: ::protobuf::UnknownFields, + pub cached_size: ::protobuf::CachedSize, +} + +impl<'a> ::std::default::Default for &'a VoteChoice { + fn default() -> &'a VoteChoice { + ::default_instance() + } +} + +impl VoteChoice { + pub fn new() -> VoteChoice { + ::std::default::Default::default() + } + + // string candidate = 1; + + + pub fn get_candidate(&self) -> &str { + &self.candidate + } + pub fn clear_candidate(&mut self) { + self.candidate.clear(); + } + + // Param is passed by value, moved + pub fn set_candidate(&mut self, v: ::std::string::String) { + self.candidate = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_candidate(&mut self) -> &mut ::std::string::String { + &mut self.candidate + } + + // Take field + pub fn take_candidate(&mut self) -> ::std::string::String { + ::std::mem::replace(&mut self.candidate, ::std::string::String::new()) + } + + // 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 VoteChoice { + 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.candidate)?; + }, + 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.is_empty() { + my_size += ::protobuf::rt::string_size(1, &self.candidate); + } + 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.is_empty() { + os.write_string(1, &self.candidate)?; + } + 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() -> VoteChoice { + VoteChoice::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>( + "candidate", + |m: &VoteChoice| { &m.candidate }, + |m: &mut VoteChoice| { &mut m.candidate }, + )); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeUint32>( + "value", + |m: &VoteChoice| { &m.value }, + |m: &mut VoteChoice| { &mut m.value }, + )); + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "VoteChoice", + fields, + file_descriptor_proto() + ) + }) + } + + fn default_instance() -> &'static VoteChoice { + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(VoteChoice::new) + } +} + +impl ::protobuf::Clear for VoteChoice { + fn clear(&mut self) { + self.candidate.clear(); + self.value = 0; + self.unknown_fields.clear(); + } +} + +impl ::std::fmt::Debug for VoteChoice { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + ::protobuf::text_format::fmt(self, f) + } +} + +impl ::protobuf::reflect::ProtobufValue for VoteChoice { + 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, + // special fields + pub unknown_fields: ::protobuf::UnknownFields, + pub cached_size: ::protobuf::CachedSize, +} + +impl<'a> ::std::default::Default for &'a VoteChoices { + fn default() -> &'a VoteChoices { + ::default_instance() + } +} + +impl VoteChoices { + pub fn new() -> VoteChoices { + ::std::default::Default::default() + } + + // repeated .com.webank.wedpr.abv.proto.VoteChoice choice = 1; + + + pub fn get_choice(&self) -> &[VoteChoice] { + &self.choice + } + pub fn clear_choice(&mut self) { + self.choice.clear(); + } + + // Param is passed by value, moved + pub fn set_choice(&mut self, v: ::protobuf::RepeatedField) { + self.choice = v; + } + + // Mutable pointer to the field. + pub fn mut_choice(&mut self) -> &mut ::protobuf::RepeatedField { + &mut self.choice + } + + // Take field + pub fn take_choice(&mut self) -> ::protobuf::RepeatedField { + ::std::mem::replace(&mut self.choice, ::protobuf::RepeatedField::new()) + } +} + +impl ::protobuf::Message for VoteChoices { + fn is_initialized(&self) -> bool { + for v in &self.choice { + 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_repeated_message_into(wire_type, is, &mut self.choice)?; + }, + _ => { + ::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; + for value in &self.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 + } + + fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { + for v in &self.choice { + os.write_tag(1, ::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() -> VoteChoices { + VoteChoices::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_repeated_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( + "choice", + |m: &VoteChoices| { &m.choice }, + |m: &mut VoteChoices| { &mut m.choice }, + )); + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "VoteChoices", + fields, + file_descriptor_proto() + ) + }) + } + + fn default_instance() -> &'static VoteChoices { + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(VoteChoices::new) + } +} + +impl ::protobuf::Clear for VoteChoices { + fn clear(&mut self) { + self.choice.clear(); + self.unknown_fields.clear(); + } +} + +impl ::std::fmt::Debug for VoteChoices { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + ::protobuf::text_format::fmt(self, f) + } +} + +impl ::protobuf::reflect::ProtobufValue for VoteChoices { + fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { + ::protobuf::reflect::ReflectValueRef::Message(self) + } +} + +#[derive(PartialEq,Clone,Default)] +pub struct CandidateBallot { + // message fields + pub candidate: ::std::string::String, + pub ballot: ::protobuf::SingularPtrField, + // special fields + pub unknown_fields: ::protobuf::UnknownFields, + pub cached_size: ::protobuf::CachedSize, +} + +impl<'a> ::std::default::Default for &'a CandidateBallot { + fn default() -> &'a CandidateBallot { + ::default_instance() + } +} + +impl CandidateBallot { + pub fn new() -> CandidateBallot { + ::std::default::Default::default() + } + + // string candidate = 1; + + + pub fn get_candidate(&self) -> &str { + &self.candidate + } + pub fn clear_candidate(&mut self) { + self.candidate.clear(); + } + + // Param is passed by value, moved + pub fn set_candidate(&mut self, v: ::std::string::String) { + self.candidate = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_candidate(&mut self) -> &mut ::std::string::String { + &mut self.candidate + } + + // Take field + pub fn take_candidate(&mut self) -> ::std::string::String { + ::std::mem::replace(&mut self.candidate, ::std::string::String::new()) + } + + // .com.webank.wedpr.abv.proto.Ballot ballot = 2; + + + pub fn get_ballot(&self) -> &Ballot { + self.ballot.as_ref().unwrap_or_else(|| ::default_instance()) + } + 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_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_ballot(&mut self) -> &mut Ballot { + if self.ballot.is_none() { + self.ballot.set_default(); + } + self.ballot.as_mut().unwrap() + } + + // Take field + pub fn take_ballot(&mut self) -> Ballot { + self.ballot.take().unwrap_or_else(|| Ballot::new()) + } +} + +impl ::protobuf::Message for CandidateBallot { + fn is_initialized(&self) -> bool { + for v in &self.ballot { + 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.candidate)?; + }, + 2 => { + ::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())?; + }, + }; + } + ::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.is_empty() { + my_size += ::protobuf::rt::string_size(1, &self.candidate); + } + 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); + my_size + } + + fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { + if !self.candidate.is_empty() { + os.write_string(1, &self.candidate)?; + } + if let Some(ref v) = self.ballot.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() -> CandidateBallot { + CandidateBallot::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>( + "candidate", + |m: &CandidateBallot| { &m.candidate }, + |m: &mut CandidateBallot| { &mut m.candidate }, + )); + fields.push(::protobuf::reflect::accessor::make_singular_ptr_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( + "ballot", + |m: &CandidateBallot| { &m.ballot }, + |m: &mut CandidateBallot| { &mut m.ballot }, + )); + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "CandidateBallot", + fields, + file_descriptor_proto() + ) + }) + } + + fn default_instance() -> &'static CandidateBallot { + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(CandidateBallot::new) + } +} + +impl ::protobuf::Clear for CandidateBallot { + fn clear(&mut self) { + self.candidate.clear(); + self.ballot.clear(); + self.unknown_fields.clear(); + } +} + +impl ::std::fmt::Debug for CandidateBallot { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + ::protobuf::text_format::fmt(self, f) + } +} + +impl ::protobuf::reflect::ProtobufValue for CandidateBallot { + fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { + ::protobuf::reflect::ReflectValueRef::Message(self) + } +} + +#[derive(PartialEq,Clone,Default)] +pub struct VoteStorage { + // message fields + pub signature: ::std::vec::Vec, + pub blank_ballot: ::protobuf::SingularPtrField, + pub rest_ballot: ::protobuf::SingularPtrField, + pub voted_ballot: ::protobuf::RepeatedField, + // special fields + pub unknown_fields: ::protobuf::UnknownFields, + pub cached_size: ::protobuf::CachedSize, +} + +impl<'a> ::std::default::Default for &'a VoteStorage { + fn default() -> &'a VoteStorage { + ::default_instance() + } +} + +impl VoteStorage { + pub fn new() -> VoteStorage { + ::std::default::Default::default() + } + + // bytes signature = 1; + + + pub fn get_signature(&self) -> &[u8] { + &self.signature + } + pub fn clear_signature(&mut self) { + self.signature.clear(); + } + + // Param is passed by value, moved + pub fn set_signature(&mut self, v: ::std::vec::Vec) { + self.signature = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_signature(&mut self) -> &mut ::std::vec::Vec { + &mut self.signature + } + + // Take field + pub fn take_signature(&mut self) -> ::std::vec::Vec { + ::std::mem::replace(&mut self.signature, ::std::vec::Vec::new()) + } + + // .com.webank.wedpr.abv.proto.Ballot blank_ballot = 2; + + + pub fn get_blank_ballot(&self) -> &Ballot { + self.blank_ballot.as_ref().unwrap_or_else(|| ::default_instance()) + } + pub fn clear_blank_ballot(&mut self) { + self.blank_ballot.clear(); + } + + pub fn has_blank_ballot(&self) -> bool { + self.blank_ballot.is_some() + } + + // Param is passed by value, moved + pub fn set_blank_ballot(&mut self, v: Ballot) { + self.blank_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_blank_ballot(&mut self) -> &mut Ballot { + if self.blank_ballot.is_none() { + self.blank_ballot.set_default(); + } + self.blank_ballot.as_mut().unwrap() + } + + // Take field + pub fn take_blank_ballot(&mut self) -> Ballot { + self.blank_ballot.take().unwrap_or_else(|| Ballot::new()) + } + + // .com.webank.wedpr.abv.proto.Ballot rest_ballot = 3; + + + pub fn get_rest_ballot(&self) -> &Ballot { + self.rest_ballot.as_ref().unwrap_or_else(|| ::default_instance()) + } + pub fn clear_rest_ballot(&mut self) { + self.rest_ballot.clear(); + } + + pub fn has_rest_ballot(&self) -> bool { + self.rest_ballot.is_some() + } + + // Param is passed by value, moved + pub fn set_rest_ballot(&mut self, v: Ballot) { + self.rest_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_rest_ballot(&mut self) -> &mut Ballot { + if self.rest_ballot.is_none() { + self.rest_ballot.set_default(); + } + self.rest_ballot.as_mut().unwrap() + } + + // Take field + pub fn take_rest_ballot(&mut self) -> Ballot { + self.rest_ballot.take().unwrap_or_else(|| Ballot::new()) + } + + // repeated .com.webank.wedpr.abv.proto.CandidateBallot voted_ballot = 4; + + + pub fn get_voted_ballot(&self) -> &[CandidateBallot] { + &self.voted_ballot + } + pub fn clear_voted_ballot(&mut self) { + self.voted_ballot.clear(); + } + + // Param is passed by value, moved + pub fn set_voted_ballot(&mut self, v: ::protobuf::RepeatedField) { + self.voted_ballot = v; + } + + // Mutable pointer to the field. + pub fn mut_voted_ballot(&mut self) -> &mut ::protobuf::RepeatedField { + &mut self.voted_ballot + } + + // Take field + pub fn take_voted_ballot(&mut self) -> ::protobuf::RepeatedField { + ::std::mem::replace(&mut self.voted_ballot, ::protobuf::RepeatedField::new()) + } +} + +impl ::protobuf::Message for VoteStorage { + fn is_initialized(&self) -> bool { + for v in &self.blank_ballot { + if !v.is_initialized() { + return false; + } + }; + for v in &self.rest_ballot { + if !v.is_initialized() { + return false; + } + }; + for v in &self.voted_ballot { + 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_bytes_into(wire_type, is, &mut self.signature)?; + }, + 2 => { + ::protobuf::rt::read_singular_message_into(wire_type, is, &mut self.blank_ballot)?; + }, + 3 => { + ::protobuf::rt::read_singular_message_into(wire_type, is, &mut self.rest_ballot)?; + }, + 4 => { + ::protobuf::rt::read_repeated_message_into(wire_type, is, &mut self.voted_ballot)?; + }, + _ => { + ::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.signature.is_empty() { + my_size += ::protobuf::rt::bytes_size(1, &self.signature); + } + if let Some(ref v) = self.blank_ballot.as_ref() { + let len = v.compute_size(); + my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; + } + if let Some(ref v) = self.rest_ballot.as_ref() { + let len = v.compute_size(); + my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; + } + for value in &self.voted_ballot { + 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.signature.is_empty() { + os.write_bytes(1, &self.signature)?; + } + if let Some(ref v) = self.blank_ballot.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)?; + } + if let Some(ref v) = self.rest_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)?; + } + for v in &self.voted_ballot { + 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(()) + } + + 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() -> VoteStorage { + VoteStorage::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>( + "signature", + |m: &VoteStorage| { &m.signature }, + |m: &mut VoteStorage| { &mut m.signature }, + )); + fields.push(::protobuf::reflect::accessor::make_singular_ptr_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( + "blank_ballot", + |m: &VoteStorage| { &m.blank_ballot }, + |m: &mut VoteStorage| { &mut m.blank_ballot }, + )); + fields.push(::protobuf::reflect::accessor::make_singular_ptr_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( + "rest_ballot", + |m: &VoteStorage| { &m.rest_ballot }, + |m: &mut VoteStorage| { &mut m.rest_ballot }, + )); + fields.push(::protobuf::reflect::accessor::make_repeated_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( + "voted_ballot", + |m: &VoteStorage| { &m.voted_ballot }, + |m: &mut VoteStorage| { &mut m.voted_ballot }, + )); + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "VoteStorage", + fields, + file_descriptor_proto() + ) + }) + } + + fn default_instance() -> &'static VoteStorage { + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(VoteStorage::new) + } +} + +impl ::protobuf::Clear for VoteStorage { + fn clear(&mut self) { + self.signature.clear(); + self.blank_ballot.clear(); + self.rest_ballot.clear(); + self.voted_ballot.clear(); + self.unknown_fields.clear(); + } +} + +impl ::std::fmt::Debug for VoteStorage { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + ::protobuf::text_format::fmt(self, f) + } +} + +impl ::protobuf::reflect::ProtobufValue for VoteStorage { + fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { + ::protobuf::reflect::ReflectValueRef::Message(self) + } +} + +#[derive(PartialEq,Clone,Default)] +pub struct CandidateList { + // message fields + pub candidate: ::protobuf::RepeatedField<::std::string::String>, + // special fields + pub unknown_fields: ::protobuf::UnknownFields, + pub cached_size: ::protobuf::CachedSize, +} + +impl<'a> ::std::default::Default for &'a CandidateList { + fn default() -> &'a CandidateList { + ::default_instance() + } +} + +impl CandidateList { + pub fn new() -> CandidateList { + ::std::default::Default::default() + } + + // repeated string candidate = 1; + + + pub fn get_candidate(&self) -> &[::std::string::String] { + &self.candidate + } + pub fn clear_candidate(&mut self) { + self.candidate.clear(); + } + + // Param is passed by value, moved + pub fn set_candidate(&mut self, v: ::protobuf::RepeatedField<::std::string::String>) { + self.candidate = v; + } + + // Mutable pointer to the field. + pub fn mut_candidate(&mut self) -> &mut ::protobuf::RepeatedField<::std::string::String> { + &mut self.candidate + } + + // Take field + pub fn take_candidate(&mut self) -> ::protobuf::RepeatedField<::std::string::String> { + ::std::mem::replace(&mut self.candidate, ::protobuf::RepeatedField::new()) + } +} + +impl ::protobuf::Message for CandidateList { + 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_repeated_string_into(wire_type, is, &mut self.candidate)?; + }, + _ => { + ::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; + for value in &self.candidate { + my_size += ::protobuf::rt::string_size(1, &value); + }; + 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<()> { + for v in &self.candidate { + os.write_string(1, &v)?; + }; + 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() -> CandidateList { + CandidateList::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_repeated_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( + "candidate", + |m: &CandidateList| { &m.candidate }, + |m: &mut CandidateList| { &mut m.candidate }, + )); + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "CandidateList", + fields, + file_descriptor_proto() + ) + }) + } + + fn default_instance() -> &'static CandidateList { + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(CandidateList::new) + } +} + +impl ::protobuf::Clear for CandidateList { + fn clear(&mut self) { + self.candidate.clear(); + self.unknown_fields.clear(); + } +} + +impl ::std::fmt::Debug for CandidateList { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + ::protobuf::text_format::fmt(self, f) + } +} + +impl ::protobuf::reflect::ProtobufValue for CandidateList { + fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { + ::protobuf::reflect::ReflectValueRef::Message(self) + } +} + +#[derive(PartialEq,Clone,Default)] +pub struct SystemParametersStorage { + // message fields + pub poll_point: ::std::vec::Vec, + pub candidates: ::protobuf::SingularPtrField, + // special fields + pub unknown_fields: ::protobuf::UnknownFields, + pub cached_size: ::protobuf::CachedSize, +} + +impl<'a> ::std::default::Default for &'a SystemParametersStorage { + fn default() -> &'a SystemParametersStorage { + ::default_instance() + } +} + +impl SystemParametersStorage { + pub fn new() -> SystemParametersStorage { + ::std::default::Default::default() + } + + // bytes poll_point = 1; + + + pub fn get_poll_point(&self) -> &[u8] { + &self.poll_point + } + pub fn clear_poll_point(&mut self) { + self.poll_point.clear(); + } + + // Param is passed by value, moved + pub fn set_poll_point(&mut self, v: ::std::vec::Vec) { + self.poll_point = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_poll_point(&mut self) -> &mut ::std::vec::Vec { + &mut self.poll_point + } + + // Take field + pub fn take_poll_point(&mut self) -> ::std::vec::Vec { + ::std::mem::replace(&mut self.poll_point, ::std::vec::Vec::new()) + } + + // .com.webank.wedpr.abv.proto.CandidateList candidates = 2; + + + pub fn get_candidates(&self) -> &CandidateList { + self.candidates.as_ref().unwrap_or_else(|| ::default_instance()) + } + pub fn clear_candidates(&mut self) { + self.candidates.clear(); + } + + pub fn has_candidates(&self) -> bool { + self.candidates.is_some() + } + + // Param is passed by value, moved + pub fn set_candidates(&mut self, v: CandidateList) { + self.candidates = ::protobuf::SingularPtrField::some(v); + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_candidates(&mut self) -> &mut CandidateList { + if self.candidates.is_none() { + self.candidates.set_default(); + } + self.candidates.as_mut().unwrap() + } + + // Take field + pub fn take_candidates(&mut self) -> CandidateList { + self.candidates.take().unwrap_or_else(|| CandidateList::new()) + } +} + +impl ::protobuf::Message for SystemParametersStorage { + fn is_initialized(&self) -> bool { + for v in &self.candidates { + 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_bytes_into(wire_type, is, &mut self.poll_point)?; + }, + 2 => { + ::protobuf::rt::read_singular_message_into(wire_type, is, &mut self.candidates)?; + }, + _ => { + ::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.poll_point.is_empty() { + my_size += ::protobuf::rt::bytes_size(1, &self.poll_point); + } + if let Some(ref v) = self.candidates.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.poll_point.is_empty() { + os.write_bytes(1, &self.poll_point)?; + } + if let Some(ref v) = self.candidates.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() -> SystemParametersStorage { + SystemParametersStorage::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>( + "poll_point", + |m: &SystemParametersStorage| { &m.poll_point }, + |m: &mut SystemParametersStorage| { &mut m.poll_point }, + )); + fields.push(::protobuf::reflect::accessor::make_singular_ptr_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( + "candidates", + |m: &SystemParametersStorage| { &m.candidates }, + |m: &mut SystemParametersStorage| { &mut m.candidates }, + )); + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "SystemParametersStorage", + fields, + file_descriptor_proto() + ) + }) + } + + fn default_instance() -> &'static SystemParametersStorage { + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(SystemParametersStorage::new) + } +} + +impl ::protobuf::Clear for SystemParametersStorage { + fn clear(&mut self) { + self.poll_point.clear(); + self.candidates.clear(); + self.unknown_fields.clear(); + } +} + +impl ::std::fmt::Debug for SystemParametersStorage { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + ::protobuf::text_format::fmt(self, f) + } +} + +impl ::protobuf::reflect::ProtobufValue for SystemParametersStorage { + fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { + ::protobuf::reflect::ReflectValueRef::Message(self) + } +} + +#[derive(PartialEq,Clone,Default)] +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, +} + +impl<'a> ::std::default::Default for &'a BallotProof { + fn default() -> &'a BallotProof { + ::default_instance() + } +} + +impl BallotProof { + pub fn new() -> BallotProof { + ::std::default::Default::default() + } + + // bytes format_proof = 1; + + + pub fn get_format_proof(&self) -> &[u8] { + &self.format_proof + } + pub fn clear_format_proof(&mut self) { + self.format_proof.clear(); + } + + // Param is passed by value, moved + pub fn set_format_proof(&mut self, v: ::std::vec::Vec) { + self.format_proof = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_format_proof(&mut self) -> &mut ::std::vec::Vec { + &mut self.format_proof + } + + // Take field + pub fn take_format_proof(&mut self) -> ::std::vec::Vec { + ::std::mem::replace(&mut self.format_proof, ::std::vec::Vec::new()) + } + + // 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(); + } + + // 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())?; + }, + }; + } + ::std::result::Result::Ok(()) + } + + // Compute sizes of nested messages + #[allow(unused_variables)] + fn compute_size(&self) -> u32 { + let mut my_size = 0; + 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 + } + + fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { + 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(()) + } + + 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() -> BallotProof { + BallotProof::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>( + "format_proof", + |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, + file_descriptor_proto() + ) + }) + } + + fn default_instance() -> &'static BallotProof { + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(BallotProof::new) + } +} + +impl ::protobuf::Clear for BallotProof { + fn clear(&mut self) { + self.format_proof.clear(); + self.either_equality_proof.clear(); + self.unknown_fields.clear(); + } +} + +impl ::std::fmt::Debug for BallotProof { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + ::protobuf::text_format::fmt(self, f) + } +} + +impl ::protobuf::reflect::ProtobufValue for BallotProof { + fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { + ::protobuf::reflect::ReflectValueRef::Message(self) + } +} + +#[derive(PartialEq,Clone,Default)] +pub struct CandidateBallotProofPair { + // message fields + pub candidate: ::std::string::String, + pub value: ::protobuf::SingularPtrField, + // special fields + pub unknown_fields: ::protobuf::UnknownFields, + pub cached_size: ::protobuf::CachedSize, +} + +impl<'a> ::std::default::Default for &'a CandidateBallotProofPair { + fn default() -> &'a CandidateBallotProofPair { + ::default_instance() + } +} + +impl CandidateBallotProofPair { + pub fn new() -> CandidateBallotProofPair { + ::std::default::Default::default() + } + + // string candidate = 1; + + + pub fn get_candidate(&self) -> &str { + &self.candidate + } + pub fn clear_candidate(&mut self) { + self.candidate.clear(); + } + + // Param is passed by value, moved + pub fn set_candidate(&mut self, v: ::std::string::String) { + self.candidate = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_candidate(&mut self) -> &mut ::std::string::String { + &mut self.candidate + } + + // Take field + pub fn take_candidate(&mut self) -> ::std::string::String { + ::std::mem::replace(&mut self.candidate, ::std::string::String::new()) + } + + // .com.webank.wedpr.abv.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 CandidateBallotProofPair { + 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.candidate)?; + }, + 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.candidate.is_empty() { + my_size += ::protobuf::rt::string_size(1, &self.candidate); + } + 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.candidate.is_empty() { + os.write_string(1, &self.candidate)?; + } + 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() -> CandidateBallotProofPair { + CandidateBallotProofPair::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>( + "candidate", + |m: &CandidateBallotProofPair| { &m.candidate }, + |m: &mut CandidateBallotProofPair| { &mut m.candidate }, + )); + fields.push(::protobuf::reflect::accessor::make_singular_ptr_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( + "value", + |m: &CandidateBallotProofPair| { &m.value }, + |m: &mut CandidateBallotProofPair| { &mut m.value }, + )); + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "CandidateBallotProofPair", + fields, + file_descriptor_proto() + ) + }) + } + + fn default_instance() -> &'static CandidateBallotProofPair { + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(CandidateBallotProofPair::new) + } +} + +impl ::protobuf::Clear for CandidateBallotProofPair { + fn clear(&mut self) { + self.candidate.clear(); + self.value.clear(); + self.unknown_fields.clear(); + } +} + +impl ::std::fmt::Debug for CandidateBallotProofPair { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + ::protobuf::text_format::fmt(self, f) + } +} + +impl ::protobuf::reflect::ProtobufValue for CandidateBallotProofPair { + fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { + ::protobuf::reflect::ReflectValueRef::Message(self) + } +} + +#[derive(PartialEq,Clone,Default)] +pub struct VoteRequest { + // message fields + pub vote: ::protobuf::SingularPtrField, + pub ballot_proof: ::protobuf::RepeatedField, + pub range_proof: ::std::vec::Vec, + pub sum_balance_proof: ::std::vec::Vec, + // special fields + pub unknown_fields: ::protobuf::UnknownFields, + pub cached_size: ::protobuf::CachedSize, +} + +impl<'a> ::std::default::Default for &'a VoteRequest { + fn default() -> &'a VoteRequest { + ::default_instance() + } +} + +impl VoteRequest { + pub fn new() -> VoteRequest { + ::std::default::Default::default() + } + + // .com.webank.wedpr.abv.proto.VoteStorage vote = 1; + + + pub fn get_vote(&self) -> &VoteStorage { + self.vote.as_ref().unwrap_or_else(|| ::default_instance()) + } + pub fn clear_vote(&mut self) { + self.vote.clear(); + } + + pub fn has_vote(&self) -> bool { + self.vote.is_some() + } + + // Param is passed by value, moved + pub fn set_vote(&mut self, v: VoteStorage) { + self.vote = ::protobuf::SingularPtrField::some(v); + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_vote(&mut self) -> &mut VoteStorage { + if self.vote.is_none() { + self.vote.set_default(); + } + self.vote.as_mut().unwrap() + } + + // Take field + pub fn take_vote(&mut self) -> VoteStorage { + self.vote.take().unwrap_or_else(|| VoteStorage::new()) + } + + // repeated .com.webank.wedpr.abv.proto.CandidateBallotProofPair ballot_proof = 2; + + + pub fn get_ballot_proof(&self) -> &[CandidateBallotProofPair] { + &self.ballot_proof + } + pub fn clear_ballot_proof(&mut self) { + self.ballot_proof.clear(); + } + + // Param is passed by value, moved + pub fn set_ballot_proof(&mut self, v: ::protobuf::RepeatedField) { + self.ballot_proof = v; + } + + // Mutable pointer to the field. + pub fn mut_ballot_proof(&mut self) -> &mut ::protobuf::RepeatedField { + &mut self.ballot_proof + } + + // Take field + pub fn take_ballot_proof(&mut self) -> ::protobuf::RepeatedField { + ::std::mem::replace(&mut self.ballot_proof, ::protobuf::RepeatedField::new()) + } + + // bytes range_proof = 3; + + + pub fn get_range_proof(&self) -> &[u8] { + &self.range_proof + } + pub fn clear_range_proof(&mut self) { + self.range_proof.clear(); + } + + // Param is passed by value, moved + pub fn set_range_proof(&mut self, v: ::std::vec::Vec) { + self.range_proof = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_range_proof(&mut self) -> &mut ::std::vec::Vec { + &mut self.range_proof + } + + // Take field + pub fn take_range_proof(&mut self) -> ::std::vec::Vec { + ::std::mem::replace(&mut self.range_proof, ::std::vec::Vec::new()) + } + + // bytes sum_balance_proof = 4; + + + pub fn get_sum_balance_proof(&self) -> &[u8] { + &self.sum_balance_proof + } + pub fn clear_sum_balance_proof(&mut self) { + self.sum_balance_proof.clear(); + } + + // Param is passed by value, moved + pub fn set_sum_balance_proof(&mut self, v: ::std::vec::Vec) { + self.sum_balance_proof = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_sum_balance_proof(&mut self) -> &mut ::std::vec::Vec { + &mut self.sum_balance_proof + } + + // Take field + pub fn take_sum_balance_proof(&mut self) -> ::std::vec::Vec { + ::std::mem::replace(&mut self.sum_balance_proof, ::std::vec::Vec::new()) + } +} + +impl ::protobuf::Message for VoteRequest { + fn is_initialized(&self) -> bool { + for v in &self.vote { + if !v.is_initialized() { + return false; + } + }; + for v in &self.ballot_proof { + 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.vote)?; + }, + 2 => { + ::protobuf::rt::read_repeated_message_into(wire_type, is, &mut self.ballot_proof)?; + }, + 3 => { + ::protobuf::rt::read_singular_proto3_bytes_into(wire_type, is, &mut self.range_proof)?; + }, + 4 => { + ::protobuf::rt::read_singular_proto3_bytes_into(wire_type, is, &mut self.sum_balance_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 let Some(ref v) = self.vote.as_ref() { + let len = v.compute_size(); + my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; + } + for value in &self.ballot_proof { + let len = value.compute_size(); + my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; + }; + if !self.range_proof.is_empty() { + my_size += ::protobuf::rt::bytes_size(3, &self.range_proof); + } + if !self.sum_balance_proof.is_empty() { + my_size += ::protobuf::rt::bytes_size(4, &self.sum_balance_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 let Some(ref v) = self.vote.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)?; + } + for v in &self.ballot_proof { + os.write_tag(2, ::protobuf::wire_format::WireTypeLengthDelimited)?; + os.write_raw_varint32(v.get_cached_size())?; + v.write_to_with_cached_sizes(os)?; + }; + if !self.range_proof.is_empty() { + os.write_bytes(3, &self.range_proof)?; + } + if !self.sum_balance_proof.is_empty() { + os.write_bytes(4, &self.sum_balance_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() -> VoteRequest { + VoteRequest::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>( + "vote", + |m: &VoteRequest| { &m.vote }, + |m: &mut VoteRequest| { &mut m.vote }, + )); + fields.push(::protobuf::reflect::accessor::make_repeated_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( + "ballot_proof", + |m: &VoteRequest| { &m.ballot_proof }, + |m: &mut VoteRequest| { &mut m.ballot_proof }, + )); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( + "range_proof", + |m: &VoteRequest| { &m.range_proof }, + |m: &mut VoteRequest| { &mut m.range_proof }, + )); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( + "sum_balance_proof", + |m: &VoteRequest| { &m.sum_balance_proof }, + |m: &mut VoteRequest| { &mut m.sum_balance_proof }, + )); + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "VoteRequest", + fields, + file_descriptor_proto() + ) + }) + } + + fn default_instance() -> &'static VoteRequest { + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(VoteRequest::new) + } +} + +impl ::protobuf::Clear for VoteRequest { + fn clear(&mut self) { + self.vote.clear(); + self.ballot_proof.clear(); + self.range_proof.clear(); + self.sum_balance_proof.clear(); + self.unknown_fields.clear(); + } +} + +impl ::std::fmt::Debug for VoteRequest { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + ::protobuf::text_format::fmt(self, f) + } +} + +impl ::protobuf::reflect::ProtobufValue for VoteRequest { + 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, + // 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.abv.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.abv.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()) + } +} + +impl ::protobuf::Message for DecryptedResultPartStorage { + fn is_initialized(&self) -> bool { + for v in &self.blank_part { + if !v.is_initialized() { + return false; + } + }; + for v in &self.candidate_part { + 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.blank_part)?; + }, + 2 => { + ::protobuf::rt::read_repeated_message_into(wire_type, is, &mut self.candidate_part)?; + }, + _ => { + ::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.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; + }; + 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.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)?; + } + 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)?; + }; + 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() -> 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_singular_ptr_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( + "blank_part", + |m: &DecryptedResultPartStorage| { &m.blank_part }, + |m: &mut DecryptedResultPartStorage| { &mut m.blank_part }, + )); + 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 }, + )); + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "DecryptedResultPartStorage", + fields, + file_descriptor_proto() + ) + }) + } + + fn default_instance() -> &'static DecryptedResultPartStorage { + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(DecryptedResultPartStorage::new) + } +} + +impl ::protobuf::Clear for DecryptedResultPartStorage { + fn clear(&mut self) { + self.blank_part.clear(); + self.candidate_part.clear(); + self.unknown_fields.clear(); + } +} + +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 DecryptedResultPartStorage { + fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { + ::protobuf::reflect::ReflectValueRef::Message(self) + } +} + +#[derive(PartialEq,Clone,Default)] +pub struct StringToCountingPartPair { + // message fields + pub key: ::std::string::String, + pub value: ::protobuf::SingularPtrField, + // special fields + pub unknown_fields: ::protobuf::UnknownFields, + pub cached_size: ::protobuf::CachedSize, +} + +impl<'a> ::std::default::Default for &'a StringToCountingPartPair { + fn default() -> &'a StringToCountingPartPair { + ::default_instance() + } +} + +impl StringToCountingPartPair { + pub fn new() -> StringToCountingPartPair { + ::std::default::Default::default() + } + + // string key = 1; + + + pub fn get_key(&self) -> &str { + &self.key + } + pub fn clear_key(&mut self) { + self.key.clear(); + } + + // Param is passed by value, moved + pub fn set_key(&mut self, v: ::std::string::String) { + self.key = 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 ::std::string::String { + &mut self.key + } + + // Take field + pub fn take_key(&mut self) -> ::std::string::String { + ::std::mem::replace(&mut self.key, ::std::string::String::new()) + } + + // .com.webank.wedpr.abv.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 CountingPart { + // message fields + pub counter_id: ::std::string::String, + pub c2_r: ::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 c2_r = 2; + + + pub fn get_c2_r(&self) -> &[u8] { + &self.c2_r + } + pub fn clear_c2_r(&mut self) { + self.c2_r.clear(); + } + + // Param is passed by value, moved + pub fn set_c2_r(&mut self, v: ::std::vec::Vec) { + self.c2_r = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_c2_r(&mut self) -> &mut ::std::vec::Vec { + &mut self.c2_r + } + + // Take field + pub fn take_c2_r(&mut self) -> ::std::vec::Vec { + ::std::mem::replace(&mut self.c2_r, ::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.c2_r)?; + }, + 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.c2_r.is_empty() { + my_size += ::protobuf::rt::bytes_size(2, &self.c2_r); + } + 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.c2_r.is_empty() { + os.write_bytes(2, &self.c2_r)?; + } + 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>( + "c2_r", + |m: &CountingPart| { &m.c2_r }, + |m: &mut CountingPart| { &mut m.c2_r }, + )); + 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.c2_r.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) + } +} + +impl ::protobuf::reflect::ProtobufValue for CountingPart { + fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { + ::protobuf::reflect::ReflectValueRef::Message(self) + } +} + +#[derive(PartialEq,Clone,Default)] +pub struct VoteResultStorage { + // message fields + pub result: ::protobuf::RepeatedField, + // special fields + pub unknown_fields: ::protobuf::UnknownFields, + pub cached_size: ::protobuf::CachedSize, +} + +impl<'a> ::std::default::Default for &'a VoteResultStorage { + fn default() -> &'a VoteResultStorage { + ::default_instance() + } +} + +impl VoteResultStorage { + pub fn new() -> VoteResultStorage { + ::std::default::Default::default() + } + + // repeated .com.webank.wedpr.abv.proto.StringToInt64Pair result = 1; + + + pub fn get_result(&self) -> &[StringToInt64Pair] { + &self.result + } + pub fn clear_result(&mut self) { + self.result.clear(); + } + + // Param is passed by value, moved + pub fn set_result(&mut self, v: ::protobuf::RepeatedField) { + self.result = v; + } + + // Mutable pointer to the field. + pub fn mut_result(&mut self) -> &mut ::protobuf::RepeatedField { + &mut self.result + } + + // Take field + pub fn take_result(&mut self) -> ::protobuf::RepeatedField { + ::std::mem::replace(&mut self.result, ::protobuf::RepeatedField::new()) + } +} + +impl ::protobuf::Message for VoteResultStorage { + fn is_initialized(&self) -> bool { + for v in &self.result { + 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_repeated_message_into(wire_type, is, &mut self.result)?; + }, + _ => { + ::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; + for value in &self.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 + } + + fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { + for v in &self.result { + os.write_tag(1, ::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() -> VoteResultStorage { + VoteResultStorage::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_repeated_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( + "result", + |m: &VoteResultStorage| { &m.result }, + |m: &mut VoteResultStorage| { &mut m.result }, + )); + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "VoteResultStorage", + fields, + file_descriptor_proto() + ) + }) + } + + fn default_instance() -> &'static VoteResultStorage { + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(VoteResultStorage::new) + } +} + +impl ::protobuf::Clear for VoteResultStorage { + fn clear(&mut self) { + self.result.clear(); + self.unknown_fields.clear(); + } +} + +impl ::std::fmt::Debug for VoteResultStorage { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + ::protobuf::text_format::fmt(self, f) + } +} + +impl ::protobuf::reflect::ProtobufValue for VoteResultStorage { + fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { + ::protobuf::reflect::ReflectValueRef::Message(self) + } +} + +#[derive(PartialEq,Clone,Default)] +pub struct StringToInt64Pair { + // message fields + pub key: ::std::string::String, + pub value: i64, + // special fields + pub unknown_fields: ::protobuf::UnknownFields, + pub cached_size: ::protobuf::CachedSize, +} + +impl<'a> ::std::default::Default for &'a StringToInt64Pair { + fn default() -> &'a StringToInt64Pair { + ::default_instance() + } +} + +impl StringToInt64Pair { + pub fn new() -> StringToInt64Pair { + ::std::default::Default::default() + } + + // string key = 1; + + + pub fn get_key(&self) -> &str { + &self.key + } + pub fn clear_key(&mut self) { + self.key.clear(); + } + + // Param is passed by value, moved + pub fn set_key(&mut self, v: ::std::string::String) { + self.key = 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 ::std::string::String { + &mut self.key + } + + // Take field + pub fn take_key(&mut self) -> ::std::string::String { + ::std::mem::replace(&mut self.key, ::std::string::String::new()) + } + + // int64 value = 2; + + + pub fn get_value(&self) -> i64 { + self.value + } + pub fn clear_value(&mut self) { + self.value = 0; + } + + // Param is passed by value, moved + pub fn set_value(&mut self, v: i64) { + self.value = v; + } +} + +impl ::protobuf::Message for StringToInt64Pair { + 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.key)?; + }, + 2 => { + 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.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.key.is_empty() { + my_size += ::protobuf::rt::string_size(1, &self.key); + } + 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.key.is_empty() { + os.write_string(1, &self.key)?; + } + if self.value != 0 { + os.write_int64(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() -> StringToInt64Pair { + StringToInt64Pair::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: &StringToInt64Pair| { &m.key }, + |m: &mut StringToInt64Pair| { &mut m.key }, + )); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeInt64>( + "value", + |m: &StringToInt64Pair| { &m.value }, + |m: &mut StringToInt64Pair| { &mut m.value }, + )); + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "StringToInt64Pair", + fields, + file_descriptor_proto() + ) + }) + } + + fn default_instance() -> &'static StringToInt64Pair { + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(StringToInt64Pair::new) + } +} + +impl ::protobuf::Clear for StringToInt64Pair { + fn clear(&mut self) { + self.key.clear(); + self.value = 0; + self.unknown_fields.clear(); + } +} + +impl ::std::fmt::Debug for StringToInt64Pair { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + ::protobuf::text_format::fmt(self, f) + } +} + +impl ::protobuf::reflect::ProtobufValue for StringToInt64Pair { + fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { + ::protobuf::reflect::ReflectValueRef::Message(self) + } +} + +static file_descriptor_proto_data: &'static [u8] = b"\ + \n\x16solution/abv/abv.proto\x12\x1acom.webank.wedpr.abv.proto\";\n\rCou\ + nterSecret\x12*\n\x11poll_secret_share\x18\x01\x20\x01(\x0cR\x0fpollSecr\ + etShare\"n\n#CounterSystemParametersShareRequest\x12\x1d\n\ncounter_id\ + \x18\x01\x20\x01(\tR\tcounterId\x12(\n\x10poll_point_share\x18\x02\x20\ + \x01(\x0cR\x0epollPointShare\"\x9f\x01\n\x1eCounterSystemParametersStora\ + ge\x12}\n\x1acounter_parameters_request\x18\x01\x20\x03(\x0b2?.com.weban\ + k.wedpr.abv.proto.CounterSystemParametersShareRequestR\x18counterParamet\ + ersRequest\".\n\x0bVoterSecret\x12\x1f\n\x0bvote_secret\x18\x01\x20\x01(\ + \x0cR\nvoteSecret\"o\n\x13RegistrationRequest\x12X\n\x0cweight_point\x18\ + \x01\x20\x01(\x0b25.com.webank.wedpr.abv.proto.RegistrationBlindingPoint\ + R\x0bweightPoint\"\x7f\n\x19RegistrationBlindingPoint\x12.\n\x13blinding\ + _poll_point\x18\x01\x20\x01(\x0cR\x11blindingPollPoint\x122\n\x15blindin\ + g_basepoint_g2\x18\x02\x20\x01(\x0cR\x13blindingBasepointG2\"\xd8\x01\n\ + \x14RegistrationResponse\x12!\n\x0cvoter_weight\x18\x01\x20\x01(\rR\x0bv\ + oterWeight\x12:\n\x06ballot\x18\x02\x20\x01(\x0b2\".com.webank.wedpr.abv\ + .proto.BallotR\x06ballot\x12\x1c\n\tsignature\x18\x03\x20\x01(\x0cR\tsig\ + nature\x12C\n\x0bzero_ballot\x18\x04\x20\x01(\x0b2\".com.webank.wedpr.ab\ + v.proto.BallotR\nzeroBallot\"L\n\x06Ballot\x12\x20\n\x0bciphertext1\x18\ + \x01\x20\x01(\x0cR\x0bciphertext1\x12\x20\n\x0bciphertext2\x18\x02\x20\ + \x01(\x0cR\x0bciphertext2\"@\n\nVoteChoice\x12\x1c\n\tcandidate\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&.com.webank.\ + wedpr.abv.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.abv.proto.BallotR\x06ballot\"\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.abv.pro\ + to.BallotR\x0bblankBallot\x12C\n\x0brest_ballot\x18\x03\x20\x01(\x0b2\".\ + com.webank.wedpr.abv.proto.BallotR\nrestBallot\x12N\n\x0cvoted_ballot\ + \x18\x04\x20\x03(\x0b2+.com.webank.wedpr.abv.proto.CandidateBallotR\x0bv\ + otedBallot\"-\n\rCandidateList\x12\x1c\n\tcandidate\x18\x01\x20\x03(\tR\ + \tcandidate\"\x83\x01\n\x17SystemParametersStorage\x12\x1d\n\npoll_point\ + \x18\x01\x20\x01(\x0cR\tpollPoint\x12I\n\ncandidates\x18\x02\x20\x01(\ + \x0b2).com.webank.wedpr.abv.proto.CandidateListR\ncandidates\"d\n\x0bBal\ + lotProof\x12!\n\x0cformat_proof\x18\x01\x20\x01(\x0cR\x0bformatProof\x12\ + 2\n\x15either_equality_proof\x18\x02\x20\x01(\x0cR\x13eitherEqualityProo\ + f\"w\n\x18CandidateBallotProofPair\x12\x1c\n\tcandidate\x18\x01\x20\x01(\ + \tR\tcandidate\x12=\n\x05value\x18\x02\x20\x01(\x0b2'.com.webank.wedpr.a\ + bv.proto.BallotProofR\x05value\"\xf0\x01\n\x0bVoteRequest\x12;\n\x04vote\ + \x18\x01\x20\x01(\x0b2'.com.webank.wedpr.abv.proto.VoteStorageR\x04vote\ + \x12W\n\x0cballot_proof\x18\x02\x20\x03(\x0b24.com.webank.wedpr.abv.prot\ + o.CandidateBallotProofPairR\x0bballotProof\x12\x1f\n\x0brange_proof\x18\ + \x03\x20\x01(\x0cR\nrangeProof\x12*\n\x11sum_balance_proof\x18\x04\x20\ + \x01(\x0cR\x0fsumBalanceProof\"\xc2\x01\n\x1aDecryptedResultPartStorage\ + \x12G\n\nblank_part\x18\x01\x20\x01(\x0b2(.com.webank.wedpr.abv.proto.Co\ + untingPartR\tblankPart\x12[\n\x0ecandidate_part\x18\x02\x20\x03(\x0b24.c\ + om.webank.wedpr.abv.proto.StringToCountingPartPairR\rcandidatePart\"l\n\ + \x18StringToCountingPartPair\x12\x10\n\x03key\x18\x01\x20\x01(\tR\x03key\ + \x12>\n\x05value\x18\x02\x20\x01(\x0b2(.com.webank.wedpr.abv.proto.Count\ + ingPartR\x05value\"g\n\x0cCountingPart\x12\x1d\n\ncounter_id\x18\x01\x20\ + \x01(\tR\tcounterId\x12\x11\n\x04c2_r\x18\x02\x20\x01(\x0cR\x03c2R\x12%\ + \n\x0eequality_proof\x18\x03\x20\x01(\x0cR\requalityProof\"Z\n\x11VoteRe\ + sultStorage\x12E\n\x06result\x18\x01\x20\x03(\x0b2-.com.webank.wedpr.abv\ + .proto.StringToInt64PairR\x06result\";\n\x11StringToInt64Pair\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.abv.protoP\x01b\x06proto3\ +"; + +static file_descriptor_proto_lazy: ::protobuf::rt::LazyV2<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::rt::LazyV2::INIT; + +fn parse_descriptor_proto() -> ::protobuf::descriptor::FileDescriptorProto { + ::protobuf::Message::parse_from_bytes(file_descriptor_proto_data).unwrap() +} + +pub fn file_descriptor_proto() -> &'static ::protobuf::descriptor::FileDescriptorProto { + file_descriptor_proto_lazy.get(|| { + parse_descriptor_proto() + }) +} diff --git a/protos/src/generated/hdk.rs b/protos/src/generated/hdk.rs index 9d2c4f0..4e954a3 100644 --- a/protos/src/generated/hdk.rs +++ b/protos/src/generated/hdk.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.25.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_25_1; #[derive(PartialEq,Clone,Default)] pub struct HdkResult { diff --git a/protos/src/generated/mod.rs b/protos/src/generated/mod.rs index 0769561..fcda58c 100644 --- a/protos/src/generated/mod.rs +++ b/protos/src/generated/mod.rs @@ -3,3 +3,4 @@ pub mod hdk; pub mod scd; pub mod vcl; +pub mod abv; diff --git a/protos/src/generated/scd.rs b/protos/src/generated/scd.rs index d9bd149..98ac0d6 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.25.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_25_1; #[derive(PartialEq,Clone,Default)] pub struct CertificateSchema { diff --git a/protos/src/generated/vcl.rs b/protos/src/generated/vcl.rs index e086e05..dae04f6 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.25.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_25_1; #[derive(PartialEq,Clone,Default)] pub struct EncodedOwnerSecret { diff --git a/protos/src/main.rs b/protos/src/main.rs index 6c8390f..c56249c 100644 --- a/protos/src/main.rs +++ b/protos/src/main.rs @@ -27,7 +27,7 @@ fn generate_proto_for_all() { .includes(&["."]) // List all used proto files here. // You can remove any proto files that are not used by your project. - .inputs(&["solution/vcl/vcl.proto","solution/scd/scd.proto","solution/ktb/hdk.proto"]) + .inputs(&["solution/vcl/vcl.proto","solution/scd/scd.proto","solution/ktb/hdk.proto", "solution/abv/abv.proto"]) .customize(Customize { ..Default::default() }) diff --git a/solution/anonymous_bounded_voting/Cargo.toml b/solution/anonymous_bounded_voting/Cargo.toml new file mode 100644 index 0000000..38dae5e --- /dev/null +++ b/solution/anonymous_bounded_voting/Cargo.toml @@ -0,0 +1,22 @@ +[package] +name = "wedpr_s_anonymous_bounded_voting" +version = "1.5.0" +authors = [ "WeDPR " ] +edition = "2018" +license = "Apache-2.0" +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] +wedpr_l_macros = "1.0.0" +wedpr_l_utils = "1.1.0" +wedpr_l_crypto_zkp_discrete_logarithm_proof = { git = "https://github.com/WeBankBlockchain/WeDPR-Lab-Crypto.git", branch = "release-1.2.0" } +wedpr_s_protos = { path = "../../protos"} +wedpr_l_protos = { git = "https://github.com/WeBankBlockchain/WeDPR-Lab-Crypto.git", branch = "release-1.2.0", version = "1.1.1" } +curve25519-dalek = { version = "1", features = [ "serde" ] } +wedpr_l_crypto_zkp_utils = { git = "https://github.com/WeBankBlockchain/WeDPR-Lab-Crypto.git", branch = "release-1.2.0" } +wedpr_l_crypto_signature_secp256k1 = { git = "https://github.com/WeBankBlockchain/WeDPR-Lab-Crypto.git", branch = "release-1.2.0" } +lazy_static = "1.4.0" +wedpr_l_crypto_hash_keccak256 = { git = "https://github.com/WeBankBlockchain/WeDPR-Lab-Crypto.git", branch = "release-1.2.0" } +wedpr_l_crypto_zkp_range_proof = { git = "https://github.com/WeBankBlockchain/WeDPR-Lab-Crypto.git", branch = "release-1.2.0" } diff --git a/solution/anonymous_bounded_voting/src/config.rs b/solution/anonymous_bounded_voting/src/config.rs new file mode 100644 index 0000000..e17778e --- /dev/null +++ b/solution/anonymous_bounded_voting/src/config.rs @@ -0,0 +1,8 @@ +use wedpr_l_crypto_hash_keccak256::WedprKeccak256; +use wedpr_l_crypto_signature_secp256k1::WedprSecp256k1Recover; + +lazy_static! { + pub static ref SIGNATURE_SECP256K1: WedprSecp256k1Recover = + WedprSecp256k1Recover::default(); + pub static ref HASH_KECCAK256: WedprKeccak256 = WedprKeccak256::default(); +} diff --git a/solution/anonymous_bounded_voting/src/coordinator.rs b/solution/anonymous_bounded_voting/src/coordinator.rs new file mode 100644 index 0000000..5f6447b --- /dev/null +++ b/solution/anonymous_bounded_voting/src/coordinator.rs @@ -0,0 +1,126 @@ +// Copyright 2020 WeDPR Lab Project Authors. Licensed under Apache-2.0. + +//! Library of anonymous bounded voting (ABV) solution. + +use crate::config::{HASH_KECCAK256, SIGNATURE_SECP256K1}; +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_s_protos::generated::abv::{ + Ballot, CandidateList, CounterSystemParametersStorage, CountingPart, + DecryptedResultPartStorage, RegistrationRequest, RegistrationResponse, + StringToCountingPartPair, SystemParametersStorage, +}; + +pub fn make_system_parameters( + candidates: &CandidateList, + counter_storage: &CounterSystemParametersStorage, +) -> Result { + let mut poll_point = RistrettoPoint::default(); + for counter_request in counter_storage.get_counter_parameters_request() { + poll_point += bytes_to_point(counter_request.get_poll_point_share())?; + } + let mut storage = SystemParametersStorage::default(); + storage.set_candidates(candidates.clone()); + storage.set_poll_point(point_to_bytes(&poll_point)); + Ok(storage) +} + +pub fn certify_bounded_voter( + secret_key: &[u8], + value: u32, + registration_request: &RegistrationRequest, +) -> Result { + // let blinding_basepoint_g2 = + // bytes_to_point(registration_request.get_weight_point(). + // get_blinding_basepoint_g2())?; + let blinding_poll_point = bytes_to_point( + registration_request + .get_weight_point() + .get_blinding_poll_point(), + )?; + let ciphertext1 = + blinding_poll_point + (*BASEPOINT_G1 * Scalar::from(value)); + let mut ballot = Ballot::new(); + ballot.set_ciphertext1(point_to_bytes(&ciphertext1)); + ballot.set_ciphertext2( + registration_request + .get_weight_point() + .get_blinding_basepoint_g2() + .to_vec(), + ); + 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_KECCAK256.hash(&hash_vec); + let signature = SIGNATURE_SECP256K1.sign(secret_key, &message_hash)?; + let mut response = RegistrationResponse::new(); + response.set_signature(signature); + response.set_ballot(ballot); + response.set_voter_weight(value); + Ok(response) +} + +pub fn aggregate_decrypted_part_sum( + param: &SystemParametersStorage, + decrypted_result_part_storage: &DecryptedResultPartStorage, + counting_result_sum: &mut DecryptedResultPartStorage, +) -> Result { + if !counting_result_sum.has_blank_part() { + counting_result_sum + .mut_blank_part() + .set_counter_id("default".to_string()); + counting_result_sum + .mut_blank_part() + .set_c2_r(point_to_bytes(&RistrettoPoint::default())); + for candidate in param.get_candidates().get_candidate() { + let mut counting_part = CountingPart::new(); + counting_part.set_c2_r(point_to_bytes(&RistrettoPoint::default())); + let mut tmp_pair = StringToCountingPartPair::new(); + tmp_pair.set_key(candidate.to_string()); + tmp_pair.set_value(counting_part); + counting_result_sum.mut_candidate_part().push(tmp_pair); + } + } + let mut blank_c2_r_sum = + bytes_to_point(&counting_result_sum.get_blank_part().get_c2_r())?; + let blank_part_share = bytes_to_point( + &decrypted_result_part_storage.get_blank_part().get_c2_r(), + )?; + + blank_c2_r_sum += blank_part_share; + counting_result_sum + .mut_blank_part() + .set_c2_r(point_to_bytes(&blank_c2_r_sum)); + for candidate in param.get_candidates().get_candidate() { + let mut candidate_counting_part = CountingPart::new(); + for tmp_pair in counting_result_sum.get_candidate_part() { + if candidate == tmp_pair.get_key() { + candidate_counting_part = tmp_pair.get_value().clone(); + } + } + + let mut candidate_c2_r_sum = + bytes_to_point(&candidate_counting_part.get_c2_r())?; + + let mut counting_part = CountingPart::new(); + for tmp_pair in decrypted_result_part_storage.get_candidate_part() { + if candidate == tmp_pair.get_key() { + counting_part = tmp_pair.get_value().clone(); + } + } + + let candidate_c2_r = bytes_to_point(&counting_part.get_c2_r())?; + candidate_c2_r_sum += candidate_c2_r; + let mut candidate_part = CountingPart::new(); + candidate_part.set_c2_r(point_to_bytes(&candidate_c2_r_sum)); + let mut tmp_pair = StringToCountingPartPair::new(); + tmp_pair.set_key(candidate.to_string()); + tmp_pair.set_value(candidate_part); + counting_result_sum.mut_candidate_part().push(tmp_pair); + } + Ok(true) +} diff --git a/solution/anonymous_bounded_voting/src/counter.rs b/solution/anonymous_bounded_voting/src/counter.rs new file mode 100644 index 0000000..137a443 --- /dev/null +++ b/solution/anonymous_bounded_voting/src/counter.rs @@ -0,0 +1,148 @@ +// Copyright 2020 WeDPR Lab Project Authors. Licensed under Apache-2.0. + +//! Library of anonymous bounded voting (ABV) solution. + +use curve25519_dalek::scalar::Scalar; +use wedpr_l_crypto_zkp_discrete_logarithm_proof::prove_equality_relationship_proof; +use wedpr_l_crypto_zkp_utils::{ + bytes_to_point, bytes_to_scalar, get_random_scalar, point_to_bytes, + scalar_to_bytes, BASEPOINT_G1, BASEPOINT_G2, +}; +use wedpr_l_protos::proto_to_bytes; +use wedpr_l_utils::error::WedprError; +use wedpr_s_protos::generated::abv::{ + Ballot, CounterSecret, CounterSystemParametersShareRequest, CountingPart, + DecryptedResultPartStorage, StringToCountingPartPair, StringToInt64Pair, + SystemParametersStorage, VoteResultStorage, VoteStorage, +}; + +pub fn make_counter_secret() -> CounterSecret { + let secret_share = get_random_scalar(); + CounterSecret { + poll_secret_share: scalar_to_bytes(&secret_share), + unknown_fields: Default::default(), + cached_size: Default::default(), + } +} + +pub fn make_system_parameters_share( + counter_id: &str, + counter_secret: &CounterSecret, +) -> Result { + let secret_scalar = + bytes_to_scalar(counter_secret.get_poll_secret_share())?; + let poll_point_share = secret_scalar * *BASEPOINT_G2; + Ok(CounterSystemParametersShareRequest { + counter_id: counter_id.to_string(), + poll_point_share: point_to_bytes(&poll_point_share), + unknown_fields: Default::default(), + cached_size: Default::default(), + }) +} + +pub fn count( + counter_id: &str, + secret: &CounterSecret, + storage: &VoteStorage, +) -> Result { + let secret_share = bytes_to_scalar(&secret.get_poll_secret_share())?; + let mut request = DecryptedResultPartStorage::new(); + let blank_ciphertext2_sum = + bytes_to_point(storage.get_blank_ballot().get_ciphertext2())?; + for candidate_ballot_pair in storage.get_voted_ballot() { + let candidate = candidate_ballot_pair.get_candidate(); + let ballot = candidate_ballot_pair.get_ballot(); + let candidate_part_share = bytes_to_point(ballot.get_ciphertext2())?; + let equity_proof = prove_equality_relationship_proof( + &secret_share, + &BASEPOINT_G2, + &candidate_part_share, + ); + let mut counting_part = CountingPart::new(); + counting_part.set_c2_r(point_to_bytes( + &(&candidate_part_share * (secret_share)), + )); + counting_part.set_equality_proof(proto_to_bytes(&equity_proof)?); + let mut candidate_counting_part_pair = StringToCountingPartPair::new(); + candidate_counting_part_pair.set_key(candidate.to_string()); + candidate_counting_part_pair.set_value(counting_part); + request + .mut_candidate_part() + .push(candidate_counting_part_pair); + } + let blank_part = blank_ciphertext2_sum * (secret_share); + let equity_proof = prove_equality_relationship_proof( + &secret_share, + &BASEPOINT_G2, + &blank_ciphertext2_sum, + ); + request + .mut_blank_part() + .set_equality_proof(proto_to_bytes(&equity_proof)?); + request + .mut_blank_part() + .set_c2_r(point_to_bytes(&blank_part)); + request + .mut_blank_part() + .set_counter_id(counter_id.to_string()); + Ok(request) +} + +// In this function, everyone can check anonymousvoting result by c1 - c2r_sum, +// because we already know v and candidates, by using c1 - c2r_sum, we can check +// whether vG_1 =? c1 - c2r_sum. pub fn verify_counter(result_pb: +pub fn finalize_vote_result( + param: &SystemParametersStorage, + vote_sum: &VoteStorage, + counting_result_sum: &DecryptedResultPartStorage, + max_number: i64, +) -> Result { + let mut request = VoteResultStorage::new(); + let blank_c1_sum = + bytes_to_point(vote_sum.get_blank_ballot().get_ciphertext1())?; + let blank_c2_r_sum = + bytes_to_point(counting_result_sum.get_blank_part().get_c2_r())?; + let tmp = blank_c1_sum - (blank_c2_r_sum); + for i in 1..=max_number { + let try_num = Scalar::from(i as u64); + if tmp.eq(&(*BASEPOINT_G1 * try_num)) { + let mut tmp_pair = StringToInt64Pair::new(); + tmp_pair.set_key("Wedpr_voting_total_ballots".to_string()); + tmp_pair.set_value(i); + request.mut_result().push(tmp_pair); + break; + } + } + for candidate in param.get_candidates().get_candidate() { + let mut ballot = Ballot::new(); + for tmp_pair in vote_sum.get_voted_ballot() { + if candidate == tmp_pair.get_candidate() { + ballot = tmp_pair.get_ballot().clone(); + } + } + + let mut candidate_counting_part = CountingPart::new(); + for tmp_pair in counting_result_sum.get_candidate_part() { + if candidate == tmp_pair.get_key() { + candidate_counting_part = tmp_pair.get_value().clone(); + } + } + let candidate_c2_r_sum = + bytes_to_point(candidate_counting_part.get_c2_r())?; + let tmp = + bytes_to_point(ballot.get_ciphertext1())? - (candidate_c2_r_sum); + + for i in 0..=max_number { + let try_num = Scalar::from(i as u64); + + if tmp.eq(&(*BASEPOINT_G1 * try_num)) { + let mut tmp_pair = StringToInt64Pair::new(); + tmp_pair.set_key(candidate.to_string()); + tmp_pair.set_value(i); + request.mut_result().push(tmp_pair); + break; + } + } + } + Ok(request) +} diff --git a/solution/anonymous_bounded_voting/src/lib.rs b/solution/anonymous_bounded_voting/src/lib.rs new file mode 100644 index 0000000..5dded5c --- /dev/null +++ b/solution/anonymous_bounded_voting/src/lib.rs @@ -0,0 +1,189 @@ +// Copyright 2020 WeDPR Lab Project Authors. Licensed under Apache-2.0. + +//! Library of anonymous bounded voting (ABV) solution. + +#[macro_use] +extern crate lazy_static; + +#[macro_use] +extern crate wedpr_l_macros; + +mod config; +pub mod coordinator; +pub mod counter; +pub mod verifier; +pub mod voter; + +#[cfg(test)] +mod tests { + use super::*; + use crate::config::SIGNATURE_SECP256K1; + use wedpr_l_crypto_zkp_utils::bytes_to_point; + use wedpr_l_utils::traits::Signature; + use wedpr_s_protos::generated::abv::{ + CandidateList, CounterSecret, CounterSystemParametersStorage, + DecryptedResultPartStorage, VoteChoice, VoteChoices, VoteStorage, + VoterSecret, + }; + + #[test] + fn test_bounded_voting() { + // Generate coordinator's key pair + let max_vote_number = 20000; + let (public_key, secret_key) = SIGNATURE_SECP256K1.generate_keypair(); + let mut candidate_list = CandidateList::new(); + // Init candidate list + for candidate in vec!["Kitten", "Doge", "Bunny"] { + candidate_list.mut_candidate().push(candidate.to_string()); + } + let counter_id_list = vec!["1001", "1002", "1003"]; + let blank_ballot_count = vec![10, 100, 1000, 10000]; + + let mut counter_secret_list: Vec = vec![]; + let mut counter_parameters_storage = + CounterSystemParametersStorage::default(); + // Counter init + for id in counter_id_list.clone() { + let share_secret = counter::make_counter_secret(); + counter_secret_list.push(share_secret.clone()); + let counter_parameters_request = + counter::make_system_parameters_share(id, &share_secret) + .unwrap(); + counter_parameters_storage + .mut_counter_parameters_request() + .push(counter_parameters_request.clone()); + } + // coordinator make system parameters + let system_parameters = coordinator::make_system_parameters( + &candidate_list, + &counter_parameters_storage, + ) + .unwrap(); + + // voter init + let mut voter_secret_list: Vec = vec![]; + let mut response_list = vec![]; + + for blank_ballot in blank_ballot_count { + let vote_secret = voter::make_voter_secret(); + voter_secret_list.push(vote_secret.clone()); + + // voter -> coordinator generate blank ballot + let vote_request = voter::make_bounded_registration_request( + &vote_secret, + &system_parameters, + ) + .unwrap(); + let response = coordinator::certify_bounded_voter( + &secret_key, + blank_ballot, + &vote_request, + ) + .unwrap(); + response_list.push(response.clone()); + // verify blank ballot + let result = + voter::verify_blank_ballot(&vote_request, &response).unwrap(); + assert_eq!(true, result); + } + + // voter vote + let make_choice = |x: &Vec| { + let mut choices = VoteChoices::new(); + for i in 0..candidate_list.get_candidate().len() { + let mut pair = VoteChoice::new(); + pair.set_candidate(candidate_list.get_candidate()[i].clone()); + pair.set_value(x[i]); + choices.mut_choice().push(pair); + } + choices + }; + + let voting_ballot_count: Vec> = + vec![vec![1, 2, 3], vec![10, 20, 30], vec![100, 200, 300], vec![ + 1000, 2000, 3000, + ]]; + let mut vote_request_list = vec![]; + let mut encrypted_vote_sum = VoteStorage::new(); + for index in 0..voting_ballot_count.len() { + let ballot_choice = make_choice(&voting_ballot_count[index]); + let vote_request = voter::vote_bounded( + &voter_secret_list[index], + &ballot_choice, + &response_list[index], + &system_parameters, + ) + .unwrap(); + assert_eq!( + true, + verifier::verify_bounded_vote_request( + &system_parameters, + &vote_request, + &public_key + ) + .unwrap() + ); + assert_eq!( + true, + verifier::aggregate_vote_sum_response( + &system_parameters, + &vote_request.get_vote(), + &mut encrypted_vote_sum + ) + .unwrap() + ); + vote_request_list.push(vote_request); + } + let mut vote_sum_total = DecryptedResultPartStorage::new(); + let length = counter_secret_list.len().clone(); + for index in 0..length { + let decrypt_request = counter::count( + &counter_id_list[index], + &counter_secret_list[index], + &encrypted_vote_sum, + ) + .unwrap(); + let share = bytes_to_point( + counter_parameters_storage.get_counter_parameters_request() + [index] + .get_poll_point_share(), + ) + .unwrap(); + assert_eq!( + true, + verifier::verify_count_request( + &system_parameters, + &encrypted_vote_sum, + &share, + &decrypt_request + ) + .unwrap() + ); + assert_eq!( + true, + coordinator::aggregate_decrypted_part_sum( + &system_parameters, + &decrypt_request, + &mut vote_sum_total + ) + .unwrap() + ); + } + let final_result_request = counter::finalize_vote_result( + &system_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( + &system_parameters, + &encrypted_vote_sum, + &vote_sum_total, + &final_result_request, + ) + .unwrap(); + assert!(result); + } +} diff --git a/solution/anonymous_bounded_voting/src/verifier.rs b/solution/anonymous_bounded_voting/src/verifier.rs new file mode 100644 index 0000000..a6ab486 --- /dev/null +++ b/solution/anonymous_bounded_voting/src/verifier.rs @@ -0,0 +1,325 @@ +// Copyright 2020 WeDPR Lab Project Authors. Licensed under Apache-2.0. + +//! Library of anonymous bounded voting (ABV) solution. + +use wedpr_l_utils::error::WedprError; +use wedpr_s_protos::generated::abv::{ + Ballot, CandidateBallot, CountingPart, DecryptedResultPartStorage, + VoteResultStorage, VoteStorage, +}; + +use crate::config::{HASH_KECCAK256, SIGNATURE_SECP256K1}; +use curve25519_dalek::{ristretto::RistrettoPoint, scalar::Scalar}; +use wedpr_l_crypto_zkp_discrete_logarithm_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, point_to_bytes, BASEPOINT_G1, BASEPOINT_G2, +}; +use wedpr_l_protos::{ + bytes_to_proto, + generated::zkp::{BalanceProof, EqualityProof}, +}; +use wedpr_l_utils::traits::{Hash, Signature}; +use wedpr_s_protos::generated::abv::{SystemParametersStorage, VoteRequest}; + +pub fn verify_bounded_vote_request( + param: &SystemParametersStorage, + request: &VoteRequest, + public_key: &[u8], +) -> Result { + let poll_point = bytes_to_point(param.get_poll_point())?; + let signature = request.get_vote().get_signature(); + let blank_ballot = 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_KECCAK256.hash(&hash_vec); + + if !SIGNATURE_SECP256K1.verify( + &public_key, + &message_hash.as_ref(), + &signature, + ) { + return Err(WedprError::VerificationError); + } + + let range_proof = request.get_range_proof(); + let mut commitments: Vec = Vec::new(); + let mut voted_ballot_sum = RistrettoPoint::default(); + for candidate_ballot_pair in request.get_vote().get_voted_ballot() { + let ballot = candidate_ballot_pair.get_ballot(); + commitments.push(bytes_to_point(&ballot.get_ciphertext1())?); + voted_ballot_sum += bytes_to_point(&ballot.get_ciphertext1())?; + } + + let rest_ballot = request.get_vote().get_rest_ballot().get_ciphertext1(); + let rest_ballot_point = bytes_to_point(rest_ballot.clone())?; + commitments.push(rest_ballot_point); + pending_commitment_vec(&mut commitments); + if !verify_value_range_in_batch(&commitments, range_proof, &poll_point) { + wedpr_println!("verify range proof failed!"); + return Err(WedprError::VerificationError); + } + + for candidate_ballot in request.get_ballot_proof() { + let candidate = candidate_ballot.get_candidate(); + let ballot_proof = candidate_ballot.get_value(); + let mut candidate_ballot = Ballot::new(); + for candidate_ballot_pair in request.get_vote().get_voted_ballot() { + if candidate_ballot_pair.get_candidate() == candidate { + candidate_ballot = candidate_ballot_pair.get_ballot().clone(); + } + } + + let ciphertext1 = bytes_to_point(&candidate_ballot.get_ciphertext1())?; + let ciphertext2 = bytes_to_point(&candidate_ballot.get_ciphertext2())?; + let format_proof_bytes = ballot_proof.get_format_proof(); + let format_proof = bytes_to_proto::(format_proof_bytes)?; + if !verify_format_proof( + &ciphertext1, + &ciphertext2, + &format_proof, + &*BASEPOINT_G1, + &*BASEPOINT_G2, + &poll_point, + )? { + wedpr_println!("verify_format failed!"); + return Err(WedprError::VerificationError); + } + } + let balance_proof_bytes = request.get_sum_balance_proof(); + let balance_proof = bytes_to_proto::(balance_proof_bytes)?; + if !verify_sum_relationship( + &voted_ballot_sum, + &bytes_to_point(&rest_ballot)?, + &bytes_to_point(&blank_ballot.get_ciphertext1())?, + &balance_proof, + &BASEPOINT_G1, + &poll_point, + )? { + wedpr_println!("verify_balance failed!"); + return Err(WedprError::VerificationError); + } + Ok(true) +} + +pub fn aggregate_vote_sum_response( + param: &SystemParametersStorage, + vote_storage_part: &VoteStorage, + vote_sum: &mut VoteStorage, +) -> Result { + if !vote_sum.has_blank_ballot() { + vote_sum + .mut_blank_ballot() + .set_ciphertext1(point_to_bytes(&RistrettoPoint::default())); + vote_sum + .mut_blank_ballot() + .set_ciphertext2(point_to_bytes(&RistrettoPoint::default())); + for candidate in param.get_candidates().get_candidate() { + let mut ballot = Ballot::new(); + ballot.set_ciphertext1(point_to_bytes(&RistrettoPoint::default())); + ballot.set_ciphertext2(point_to_bytes(&RistrettoPoint::default())); + let mut ballot_pair = CandidateBallot::new(); + ballot_pair.set_candidate(candidate.to_string()); + ballot_pair.set_ballot(ballot); + vote_sum.mut_voted_ballot().push(ballot_pair); + } + } + + let mut tmp_vote_storage_sum = VoteStorage::new(); + let mut blank_c1_sum = + bytes_to_point(&vote_sum.get_blank_ballot().get_ciphertext1())?; + let mut blank_c2_sum = + bytes_to_point(&vote_sum.get_blank_ballot().get_ciphertext2())?; + let c1_tmp_point = bytes_to_point( + &vote_storage_part + .get_blank_ballot() + .get_ciphertext1() + .clone(), + )?; + let c2_tmp_point = bytes_to_point( + &vote_storage_part + .get_blank_ballot() + .get_ciphertext2() + .clone(), + )?; + blank_c1_sum += c1_tmp_point; + blank_c2_sum += c2_tmp_point; + + for candidate in param.get_candidates().get_candidate() { + let mut candidate_ballot = Ballot::new(); + for tmp_pair in vote_sum.get_voted_ballot() { + if tmp_pair.get_candidate() == candidate { + candidate_ballot = tmp_pair.get_ballot().clone(); + } + } + let mut candidate_voted_c1_sum = + bytes_to_point(&candidate_ballot.get_ciphertext1())?; + let mut candidate_voted_c2_sum = + bytes_to_point(&candidate_ballot.get_ciphertext2())?; + let mut candidates_ballot = Ballot::new(); + for ballot_pair in vote_storage_part.get_voted_ballot() { + if candidate == ballot_pair.get_candidate() { + candidates_ballot = ballot_pair.get_ballot().clone(); + } + } + candidate_voted_c1_sum += + bytes_to_point(&candidates_ballot.get_ciphertext1())?; + candidate_voted_c2_sum += + bytes_to_point(&candidates_ballot.get_ciphertext2())?; + let mut vote_ballot = Ballot::new(); + vote_ballot.set_ciphertext1(point_to_bytes(&candidate_voted_c1_sum)); + vote_ballot.set_ciphertext2(point_to_bytes(&candidate_voted_c2_sum)); + let mut tmp_pair = CandidateBallot::new(); + tmp_pair.set_candidate(candidate.to_string()); + tmp_pair.set_ballot(vote_ballot); + tmp_vote_storage_sum.mut_voted_ballot().push(tmp_pair); + } + tmp_vote_storage_sum + .mut_blank_ballot() + .set_ciphertext1(point_to_bytes(&blank_c1_sum)); + tmp_vote_storage_sum + .mut_blank_ballot() + .set_ciphertext2(point_to_bytes(&blank_c2_sum)); + *vote_sum = tmp_vote_storage_sum.clone(); + Ok(true) +} + +pub fn verify_count_request( + param: &SystemParametersStorage, + encrypted_vote_sum: &VoteStorage, + counter_share: &RistrettoPoint, + request: &DecryptedResultPartStorage, +) -> Result { + let blank_c2_sum = bytes_to_point( + &encrypted_vote_sum.get_blank_ballot().get_ciphertext2(), + )?; + let blank_equality_proof_bytes = + request.get_blank_part().get_equality_proof(); + let blank_c2_r = bytes_to_point(&request.get_blank_part().get_c2_r())?; + let blank_equality_proof = + bytes_to_proto::(&blank_equality_proof_bytes)?; + if !verify_equality_relationship_proof( + &counter_share, + &blank_c2_r, + &blank_equality_proof, + &BASEPOINT_G2, + &blank_c2_sum, + )? { + return Ok(false); + } + for candidate in param.get_candidates().get_candidate() { + let mut candidate_ballot = Ballot::new(); + for pair in encrypted_vote_sum.get_voted_ballot() { + if candidate == pair.get_candidate() { + candidate_ballot = pair.get_ballot().clone(); + } + } + let candidate_c2_sum = + bytes_to_point(&candidate_ballot.get_ciphertext2())?; + let mut counting_part = CountingPart::new(); + for pair in request.get_candidate_part() { + if candidate == pair.get_key() { + counting_part = pair.get_value().clone(); + } + } + let candidate_c2_r = bytes_to_point(&counting_part.get_c2_r())?; + let candidate_equality_proof_bytes = counting_part.get_equality_proof(); + let candidate_equality_proof = + bytes_to_proto::(candidate_equality_proof_bytes)?; + + if !verify_equality_relationship_proof( + &counter_share, + &candidate_c2_r, + &candidate_equality_proof.clone(), + &BASEPOINT_G2, + &candidate_c2_sum, + )? { + wedpr_println!("verify_equality failed!"); + return Ok(false); + } + } + Ok(true) +} + +// In this function, everyone can check anonymousvoting result by c1 - c2r_sum, +// because we already know v and candidates, by using c1 - c2r_sum, we can check +// whether vG_1 =? c1 - c2r_sum. pub fn verify_counter(result_pb: +pub fn verify_vote_result( + param: &SystemParametersStorage, + vote_sum: &VoteStorage, + counting_result_sum: &DecryptedResultPartStorage, + vote_result_request: &VoteResultStorage, +) -> Result { + let blank_c1_sum = + bytes_to_point(&vote_sum.get_blank_ballot().get_ciphertext1())?; + let blank_c2_r_sum = + bytes_to_point(&counting_result_sum.get_blank_part().get_c2_r())?; + let expected_blank_ballot_result = blank_c1_sum - (blank_c2_r_sum); + let mut get_blank_result: i64 = 0; + for tmp in vote_result_request.get_result() { + if tmp.get_key() == "Wedpr_voting_total_ballots" { + get_blank_result = tmp.get_value(); + } + } + + if expected_blank_ballot_result + .ne(&(*BASEPOINT_G1 * (Scalar::from(get_blank_result as u64)))) + { + wedpr_println!("verify blank_ballot_result failed!"); + return Ok(false); + } + + for candidate in param.get_candidates().get_candidate() { + let mut ballot = Ballot::new(); + for tmp_pair in vote_sum.get_voted_ballot() { + if candidate == tmp_pair.get_candidate() { + ballot = tmp_pair.get_ballot().clone(); + } + } + + let mut candidate_counting_part = CountingPart::new(); + for tmp_pair in counting_result_sum.get_candidate_part() { + if candidate == tmp_pair.get_key() { + candidate_counting_part = tmp_pair.get_value().clone(); + } + } + + let candidate_c2_r_sum = + bytes_to_point(&candidate_counting_part.get_c2_r())?; + + let expected_candidate_ballot_result = + bytes_to_point(&ballot.get_ciphertext1())? - (candidate_c2_r_sum); + + let mut get_candidate_result: i64 = 0; + for tmp in vote_result_request.get_result() { + if tmp.get_key() == candidate { + get_candidate_result = tmp.get_value(); + } + } + if !expected_candidate_ballot_result + .eq(&(*BASEPOINT_G1 * (Scalar::from(get_candidate_result as u64)))) + { + wedpr_println!("verify candidate {} failed!", candidate); + return Ok(false); + } + } + Ok(true) +} + +pub fn pending_commitment_vec(v: &mut Vec) { + let length = v.len() as i32; + let log_length = (length as f64).log2().ceil() as u32; + let expected_len = 2_i32.pow(log_length); + if expected_len == length { + return; + } + let pending_length = expected_len - length; + let tmp = RistrettoPoint::default(); + for _ in 0..pending_length { + v.push(tmp); + } +} diff --git a/solution/anonymous_bounded_voting/src/voter.rs b/solution/anonymous_bounded_voting/src/voter.rs new file mode 100644 index 0000000..d511b50 --- /dev/null +++ b/solution/anonymous_bounded_voting/src/voter.rs @@ -0,0 +1,193 @@ +// Copyright 2020 WeDPR Lab Project Authors. Licensed under Apache-2.0. + +//! Library of anonymous bounded voting (ABV) solution. + +use curve25519_dalek::{ + ristretto::RistrettoPoint, scalar::Scalar, traits::MultiscalarMul, +}; +use wedpr_l_crypto_zkp_discrete_logarithm_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::{ + bytes_to_point, bytes_to_scalar, get_random_scalar, point_to_bytes, + scalar_to_bytes, BASEPOINT_G1, BASEPOINT_G2, +}; +use wedpr_l_protos::proto_to_bytes; +use wedpr_l_utils::error::WedprError; +use wedpr_s_protos::generated::abv::{ + Ballot, BallotProof, CandidateBallot, CandidateBallotProofPair, + RegistrationRequest, RegistrationResponse, SystemParametersStorage, + VoteChoices, VoteRequest, VoterSecret, +}; + +pub fn make_voter_secret() -> VoterSecret { + let vote_secret = get_random_scalar(); + VoterSecret { + vote_secret: scalar_to_bytes(&vote_secret), + unknown_fields: Default::default(), + cached_size: Default::default(), + } +} + +pub fn make_bounded_registration_request( + secret: &VoterSecret, + param: &SystemParametersStorage, +) -> Result { + let vote_secret = bytes_to_scalar(secret.get_vote_secret())?; + let blinding_basepoint_g2 = vote_secret * *BASEPOINT_G2; + let poll_point = bytes_to_point(param.get_poll_point())?; + let blinding_poll_point = vote_secret * poll_point; + let mut request = RegistrationRequest::new(); + request + .mut_weight_point() + .set_blinding_basepoint_g2(point_to_bytes(&blinding_basepoint_g2)); + request + .mut_weight_point() + .set_blinding_poll_point(point_to_bytes(&blinding_poll_point)); + Ok(request) +} + +pub fn verify_blank_ballot( + request: &RegistrationRequest, + response: &RegistrationResponse, +) -> Result { + let blinding_poll_point = + bytes_to_point(request.get_weight_point().get_blinding_poll_point())?; + // let blinding_basepoint_g2 = bytes_to_point( + // request.get_weight_point().get_blinding_basepoint_g2(), + // )?; + let voter_weight = response.get_voter_weight(); + let computed_ciphertext1 = point_to_bytes( + &(blinding_poll_point + *BASEPOINT_G1 * Scalar::from(voter_weight)), + ); + + let response_ciphertext1 = response.get_ballot().get_ciphertext1(); + + let request_ciphertext2 = + request.get_weight_point().get_blinding_basepoint_g2(); + let response_ciphertext2 = response.get_ballot().get_ciphertext2(); + + Ok(&computed_ciphertext1 == response_ciphertext1 + && request_ciphertext2 == response_ciphertext2) +} + +pub fn vote_bounded( + secret: &VoterSecret, + choices: &VoteChoices, + response: &RegistrationResponse, + param: &SystemParametersStorage, +) -> Result { + let mut request = VoteRequest::new(); + let mut blinding_vote_sum = Scalar::zero(); + let mut blindings: Vec = Vec::new(); + let mut vote_value: Vec = Vec::new(); + let mut v_weight_rest = response.get_voter_weight() as i64; + let poll_point = bytes_to_point(param.get_poll_point())?; + let vote_secret = bytes_to_scalar(secret.get_vote_secret())?; + + for choice_keypair in choices.get_choice() { + let candidate_address = choice_keypair.get_candidate(); + let value = choice_keypair.get_value(); + v_weight_rest -= value as i64; + if v_weight_rest < 0 { + return Err(WedprError::ArgumentError); + } + let mut vote_ballot = Ballot::new(); + let blinding = get_random_scalar(); + let ciphertext1 = RistrettoPoint::multiscalar_mul( + &[Scalar::from(value as u64), blinding], + &[*BASEPOINT_G1, poll_point], + ); + let format_proof = prove_format_proof( + value as u64, + &blinding, + &*BASEPOINT_G1, + &*BASEPOINT_G2, + &poll_point, + ); + blinding_vote_sum += blinding; + let ciphertext2 = *BASEPOINT_G2 * blinding; + vote_ballot.set_ciphertext1(point_to_bytes(&ciphertext1)); + vote_ballot.set_ciphertext2(point_to_bytes(&ciphertext2)); + let mut ballot_proof = BallotProof::new(); + ballot_proof.set_format_proof(proto_to_bytes(&format_proof)?); + let mut proof_keypair = CandidateBallotProofPair::new(); + proof_keypair.set_candidate(candidate_address.to_string()); + proof_keypair.set_value(ballot_proof); + request.mut_ballot_proof().push(proof_keypair); + + blindings.push(blinding); + vote_value.push(value as u64); + let mut ballot_pair = CandidateBallot::new(); + ballot_pair.set_candidate(candidate_address.to_string()); + ballot_pair.set_ballot(vote_ballot); + request.mut_vote().mut_voted_ballot().push(ballot_pair); + } + let v_vote_sum = + (response.get_voter_weight() - v_weight_rest as u32) as u64; + let blinding_rest = get_random_scalar(); + let rest_ballot = RistrettoPoint::multiscalar_mul( + &[Scalar::from(v_weight_rest as u64), blinding_rest], + &[*BASEPOINT_G1, poll_point], + ); + + let balance_proof = prove_sum_relationship( + v_vote_sum, + v_weight_rest as u64, + &blinding_vote_sum, + &blinding_rest, + &vote_secret, + &BASEPOINT_G1, + &poll_point, + ); + vote_value.push(v_weight_rest as u64); + blindings.push(blinding_rest); + pending_u64_vec(&mut vote_value); + pending_scalar_vec(&mut blindings); + + let (range_proof, _) = + prove_value_range_in_batch(&vote_value, &blindings, &poll_point)?; + let signature = response.get_signature(); + request + .mut_vote() + .set_blank_ballot(response.get_ballot().clone()); + request.set_sum_balance_proof(proto_to_bytes(&balance_proof)?); + request.set_range_proof(range_proof); + request.mut_vote().set_signature(signature.to_vec()); + request + .mut_vote() + .mut_rest_ballot() + .set_ciphertext1(point_to_bytes(&rest_ballot)); + Ok(request) +} + +fn pending_u64_vec(v: &mut Vec) -> bool { + let length = v.len() as i32; + let log_length = (length as f64).log2().ceil() as u32; + let expected_len = 2_i32.pow(log_length); + if expected_len == length { + return true; + } + let pending_length = expected_len - length; + for _ in 0..pending_length { + let tpm = 0u64; + v.push(tpm); + } + true +} + +fn pending_scalar_vec(v: &mut Vec) -> bool { + let length = v.len() as i32; + let log_length = (length as f64).log2().ceil() as u32; + let expected_len = 2_i32.pow(log_length); + if expected_len == length { + return true; + } + let pending_length = expected_len - length; + for _ in 0..pending_length { + let tpm = Scalar::default(); + v.push(tpm); + } + true +} From 146a20e0ff35dd2ba7ef1b1195de09b757e8866b Mon Sep 17 00:00:00 2001 From: HaoXuan40404 <444649358@qq.com> Date: Mon, 30 Aug 2021 17:35:26 +0800 Subject: [PATCH 02/15] format code --- protos/src/generated/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/protos/src/generated/mod.rs b/protos/src/generated/mod.rs index fcda58c..25517a9 100644 --- a/protos/src/generated/mod.rs +++ b/protos/src/generated/mod.rs @@ -1,6 +1,6 @@ // Copyright 2020 WeDPR Lab Project Authors. Licensed under Apache-2.0. +pub mod abv; pub mod hdk; pub mod scd; pub mod vcl; -pub mod abv; From a5d622efba615fe401c0db02c386f6187625a07b Mon Sep 17 00:00:00 2001 From: HaoXuan40404 <444649358@qq.com> Date: Mon, 30 Aug 2021 17:42:57 +0800 Subject: [PATCH 03/15] update abv version --- release_note.txt | 2 +- solution/anonymous_bounded_voting/src/config.rs | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/release_note.txt b/release_note.txt index ec7b967..76864c1 100644 --- a/release_note.txt +++ b/release_note.txt @@ -1 +1 @@ -v1.4.0 \ No newline at end of file +v1.5.0 \ No newline at end of file diff --git a/solution/anonymous_bounded_voting/src/config.rs b/solution/anonymous_bounded_voting/src/config.rs index e17778e..8796220 100644 --- a/solution/anonymous_bounded_voting/src/config.rs +++ b/solution/anonymous_bounded_voting/src/config.rs @@ -1,3 +1,7 @@ +// Copyright 2020 WeDPR Lab Project Authors. Licensed under Apache-2.0. + +//! Config of anonymous bounded voting (ABV) solution. + use wedpr_l_crypto_hash_keccak256::WedprKeccak256; use wedpr_l_crypto_signature_secp256k1::WedprSecp256k1Recover; From 00cc08b5f54eca98baa9e83becba720799e9516c Mon Sep 17 00:00:00 2001 From: HaoXuan40404 <444649358@qq.com> Date: Wed, 1 Sep 2021 11:14:41 +0800 Subject: [PATCH 04/15] rename acv --- Cargo.toml | 3 +- ffi/ffi_c/ffi_c_acv/Cargo.toml | 26 ++ ffi/ffi_c/ffi_c_acv/src/coordinator.rs | 107 +++++ ffi/ffi_c/ffi_c_acv/src/counter.rs | 122 ++++++ ffi/ffi_c/ffi_c_acv/src/lib.rs | 16 + ffi/ffi_c/ffi_c_acv/src/verifier.rs | 123 ++++++ ffi/ffi_c/ffi_c_acv/src/voter.rs | 6 + .../solution/{abv/abv.proto => acv/acv.proto} | 16 +- protos/src/generated/{abv.rs => acv.rs} | 409 +++++++----------- protos/src/generated/mod.rs | 2 +- protos/src/main.rs | 2 +- .../Cargo.toml | 4 +- .../src/config.rs | 4 +- .../src/coordinator.rs | 27 +- .../src/counter.rs | 12 +- .../src/lib.rs | 4 +- .../src/verifier.rs | 17 +- .../src/voter.rs | 20 +- 18 files changed, 610 insertions(+), 310 deletions(-) create mode 100644 ffi/ffi_c/ffi_c_acv/Cargo.toml create mode 100644 ffi/ffi_c/ffi_c_acv/src/coordinator.rs create mode 100644 ffi/ffi_c/ffi_c_acv/src/counter.rs create mode 100644 ffi/ffi_c/ffi_c_acv/src/lib.rs create mode 100644 ffi/ffi_c/ffi_c_acv/src/verifier.rs create mode 100644 ffi/ffi_c/ffi_c_acv/src/voter.rs rename protos/solution/{abv/abv.proto => acv/acv.proto} (86%) rename protos/src/generated/{abv.rs => acv.rs} (91%) rename solution/{anonymous_bounded_voting => anonymous_ciphertext_voting}/Cargo.toml (91%) rename solution/{anonymous_bounded_voting => anonymous_ciphertext_voting}/src/config.rs (62%) rename solution/{anonymous_bounded_voting => anonymous_ciphertext_voting}/src/coordinator.rs (84%) rename solution/{anonymous_bounded_voting => anonymous_ciphertext_voting}/src/counter.rs (94%) rename solution/{anonymous_bounded_voting => anonymous_ciphertext_voting}/src/lib.rs (98%) rename solution/{anonymous_bounded_voting => anonymous_ciphertext_voting}/src/verifier.rs (96%) rename solution/{anonymous_bounded_voting => anonymous_ciphertext_voting}/src/voter.rs (91%) diff --git a/Cargo.toml b/Cargo.toml index 9c8d152..d5ffbd8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,6 +2,7 @@ members = [ "bounty", +# "ffi/ffi_c/ffi_c_acv", "ffi/ffi_c/ffi_c_ktb", "ffi/ffi_c/ffi_c_scd", "ffi/ffi_c/ffi_c_vcl", @@ -12,5 +13,5 @@ members = [ "solution/key_tool_box/hierarchical_deterministic_key", "solution/selective_certificate_disclosure", "solution/verifiable_confidential_ledger", - "solution/anonymous_bounded_voting", + "solution/anonymous_ciphertext_voting", ] diff --git a/ffi/ffi_c/ffi_c_acv/Cargo.toml b/ffi/ffi_c/ffi_c_acv/Cargo.toml new file mode 100644 index 0000000..2b4bd99 --- /dev/null +++ b/ffi/ffi_c/ffi_c_acv/Cargo.toml @@ -0,0 +1,26 @@ +[package] +name = "ffi_c_abv" +version = "1.5.0" +authors = [ "WeDPR " ] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[lib] +name = "ffi_c_abv" +crate-type = [ "cdylib", "staticlib" ] + +[dependencies] +libc = "0.2.60" +protobuf = "2.22.1" +wedpr_s_anonymous_bounded_voting = { path = "../../../solution/anonymous_ciphertext_voting" } +wedpr_ffi_common = "1.0.0" +wedpr_ffi_macros = "1.0.0" +wedpr_s_protos = { path = "../../../protos"} +wedpr_l_macros = "1.0.0" +wedpr_l_crypto_zkp_utils = "1.1.0" + + +# This is required to generate C/C++ header files. +[build-dependencies] +cbindgen = "0.9.0" diff --git a/ffi/ffi_c/ffi_c_acv/src/coordinator.rs b/ffi/ffi_c/ffi_c_acv/src/coordinator.rs new file mode 100644 index 0000000..20a836b --- /dev/null +++ b/ffi/ffi_c/ffi_c_acv/src/coordinator.rs @@ -0,0 +1,107 @@ +// Copyright 2020 WeDPR Lab Project Authors. Licensed under Apache-2.0. + +//! Library of macros and functions for FFI of a voting coordinator in ABC +//! solution, targeting C/C++ compatible architectures (including iOS). + +// C/C++ FFI: C-style interfaces will be generated. + +use wedpr_s_protos::generated::abv::{CandidateList, CounterSystemParametersStorage, RegistrationRequest, DecryptedResultPartStorage +}; + +use libc::c_char; +use protobuf::{self, Message}; +use std::{ffi::CString, panic, ptr}; +use wedpr_ffi_common::utils::{ + bytes_to_string, c_char_pointer_to_string, string_to_bytes, +}; +use std::os::raw::{c_int, c_long, c_uint}; + + +/// C interface for 'wedpr_abv_make_system_parameters'. +#[no_mangle] +pub extern "C" fn wedpr_abv_make_system_parameters( + candidates_cstring: *mut c_char, + counter_storage_cstring: *mut c_char, +) -> *mut c_char { + let result = panic::catch_unwind(|| { + let candidates = + c_safe_c_char_pointer_to_proto!(candidates_cstring, CandidateList); + + let counter_storage = + c_safe_c_char_pointer_to_proto!(counter_storage_cstring, CounterSystemParametersStorage); + + let system_parameters_storage = + match wedpr_s_anonymous_bounded_voting::coordinator::make_system_parameters( + &candidates, + &counter_storage, + ) { + Ok(v) => v, + Err(_) => return ptr::null_mut(), + }; + c_safe_proto_to_c_char_pointer!(system_parameters_storage) + }); + c_safe_return!(result) +} + +/// C interface for 'wedpr_abv_certify_bounded_voter'. +#[no_mangle] +pub extern "C" fn wedpr_abv_certify_bounded_voter( + secret_key_cstring: *mut c_char, + blank_vote_value: c_uint, + registration_request_cstring: *mut c_char, +) -> *mut c_char { + let result = panic::catch_unwind(|| { + let registration_request = + c_safe_c_char_pointer_to_proto!(registration_request_cstring, RegistrationRequest); + let secret_key = + c_safe_c_char_pointer_to_bytes!(secret_key_cstring); + let value = blank_vote_value as u32; + + let response = + match wedpr_s_anonymous_bounded_voting::coordinator::certify_bounded_voter( + &secret_key, + value, + ®istration_request, + ) { + Ok(v) => v, + Err(_) => return ptr::null_mut(), + }; + c_safe_proto_to_c_char_pointer!(response) + }); + c_safe_return!(result) +} + +/// C interface for 'wedpr_abv_aggregate_decrypted_part_sum'. +#[no_mangle] +pub extern "C" fn wedpr_abv_aggregate_decrypted_part_sum( + param_cstring: *mut c_char, + decrypted_result_part_storage_cstring: *mut c_char, + counting_result_sum_cstring: *mut c_char, +) -> *mut c_char { + let result = panic::catch_unwind(|| { + let param = + c_safe_c_char_pointer_to_proto!(param_cstring, SystemParametersStorage); + + let decrypted_result_part_storage = + c_safe_c_char_pointer_to_proto!(decrypted_result_part_storage_cstring, DecryptedResultPartStorage); + + let mut counting_result_sum = + c_safe_c_char_pointer_to_proto!(counting_result_sum_cstring, DecryptedResultPartStorage); + + + let b_result = + match wedpr_s_anonymous_bounded_voting::coordinator::aggregate_decrypted_part_sum( + ¶m, + &decrypted_result_part_storage, + &mut counting_result_sum, + ) { + Ok(v) => v, + Err(_) => return ptr::null_mut(), + }; + if !b_result { + return ptr::null_mut(); + } + c_safe_proto_to_c_char_pointer!(counting_result_sum) + }); + c_safe_return!(result) +} \ No newline at end of file diff --git a/ffi/ffi_c/ffi_c_acv/src/counter.rs b/ffi/ffi_c/ffi_c_acv/src/counter.rs new file mode 100644 index 0000000..14909ad --- /dev/null +++ b/ffi/ffi_c/ffi_c_acv/src/counter.rs @@ -0,0 +1,122 @@ +// Copyright 2020 WeDPR Lab Project Authors. Licensed under Apache-2.0. + +//! Library of macros and functions for FFI of a counter in ABC +//! solution, targeting C/C++ compatible architectures (including iOS). + +// C/C++ FFI: C-style interfaces will be generated. + +use wedpr_s_protos::generated::abv::{CounterSecret, VoteStorage +}; + +use libc::c_char; +use protobuf::{self, Message}; +use std::{ffi::CString, panic, ptr}; +use wedpr_ffi_common::utils::{ + bytes_to_string, c_char_pointer_to_string, string_to_bytes, +}; +use std::os::raw::c_long; + +/// C interface for 'wedpr_abv_make_counter_secret'. +#[no_mangle] +pub extern "C" fn wedpr_abv_make_counter_secret( +) -> *mut c_char { + let result = panic::catch_unwind(|| { + + let secret = + wedpr_s_anonymous_bounded_voting::counter::make_counter_secret(); + c_safe_proto_to_c_char_pointer!(secret) + }); + c_safe_return!(result) +} + + +/// C interface for 'wedpr_abv_make_system_parameters_share'. +#[no_mangle] +pub extern "C" fn wedpr_abv_make_system_parameters_share( + counter_id_cstring: *mut c_char, + counter_secret_cstring: *mut c_char, +) -> *mut c_char { + let result = panic::catch_unwind(|| { + let counter_id = + c_safe_c_char_pointer_to_string!(counter_id_cstring); + + let counter_secret = + c_safe_c_char_pointer_to_proto!(counter_secret_cstring, CounterSecret); + + let request = + match wedpr_s_anonymous_bounded_voting::counter::make_system_parameters_share( + &counter_id, + &counter_secret, + ) { + Ok(v) => v, + Err(_) => return ptr::null_mut(), + }; + c_safe_proto_to_c_char_pointer!(request) + }); + c_safe_return!(result) +} + +/// C interface for 'wedpr_abv_count'. +#[no_mangle] +pub extern "C" fn wedpr_abv_count( + counter_id_cstring: *mut c_char, + counter_secret_cstring: *mut c_char, + storage_cstring: *mut c_char, +) -> *mut c_char { + let result = panic::catch_unwind(|| { + let counter_id = + c_safe_c_char_pointer_to_string!(counter_id_cstring); + + let counter_secret = + c_safe_c_char_pointer_to_proto!(counter_secret_cstring, CounterSecret); + + let storage = + c_safe_c_char_pointer_to_proto!(storage_cstring, VoteStorage); + + let request = + match wedpr_s_anonymous_bounded_voting::counter::count( + &counter_id, + &counter_secret, + &storage + ) { + Ok(v) => v, + Err(_) => return ptr::null_mut(), + }; + c_safe_proto_to_c_char_pointer!(request) + }); + c_safe_return!(result) +} + +/// C interface for 'wedpr_abv_finalize_vote_result'. +#[no_mangle] +pub extern "C" fn wedpr_abv_finalize_vote_result( + param_cstring: *mut c_char, + vote_sum_cstring: *mut c_char, + counting_result_sum_cstring: *mut c_char, + max_number: c_long, +) -> *mut c_char { + let result = panic::catch_unwind(|| { + + let param = + c_safe_c_char_pointer_to_proto!(param_cstring, SystemParametersStorage); + + let vote_sum = + c_safe_c_char_pointer_to_proto!(vote_sum_cstring, VoteStorage); + + let counting_result_sum = + c_safe_c_char_pointer_to_proto!(counting_result_sum_cstring, DecryptedResultPartStorage); + + let request = + match wedpr_s_anonymous_bounded_voting::counter::finalize_vote_result( + ¶m, + &vote_sum, + &counting_result_sum, + max_number + ) { + Ok(v) => v, + Err(_) => return ptr::null_mut(), + }; + c_safe_proto_to_c_char_pointer!(request) + }); + c_safe_return!(result) +} \ No newline at end of file diff --git a/ffi/ffi_c/ffi_c_acv/src/lib.rs b/ffi/ffi_c/ffi_c_acv/src/lib.rs new file mode 100644 index 0000000..3578ae2 --- /dev/null +++ b/ffi/ffi_c/ffi_c_acv/src/lib.rs @@ -0,0 +1,16 @@ +// Copyright 2020 WeDPR Lab Project Authors. Licensed under Apache-2.0. + +//! Library of macros and functions for FFI of anonymous bounded voting (ABV) solutions, +//! targeting C/C++ compatible architectures (including iOS). + +#[allow(unused_imports)] +#[macro_use] +extern crate wedpr_ffi_macros; + +#[macro_use] +extern crate wedpr_l_macros; + +pub mod coordinator; +pub mod counter; +pub mod verifier; +pub mod voter; \ No newline at end of file diff --git a/ffi/ffi_c/ffi_c_acv/src/verifier.rs b/ffi/ffi_c/ffi_c_acv/src/verifier.rs new file mode 100644 index 0000000..0c54a4e --- /dev/null +++ b/ffi/ffi_c/ffi_c_acv/src/verifier.rs @@ -0,0 +1,123 @@ +// Copyright 2020 WeDPR Lab Project Authors. Licensed under Apache-2.0. + +//! Library of macros and functions for FFI of a verifier in ABC +//! solution, targeting C/C++ compatible architectures (including iOS). + +// C/C++ FFI: C-style interfaces will be generated. + +use wedpr_s_protos::generated::abv::{SystemParametersStorage, VoteStorage +}; + +use libc::c_char; +use protobuf::{self, Message}; +use std::{ffi::CString, panic, ptr}; +use wedpr_ffi_common::utils::{bytes_to_string, c_char_pointer_to_string, string_to_bytes, FAILURE, SUCCESS}; + + +/// C interface for 'wedpr_abv_verify_bounded_vote_request'. +#[no_mangle] +pub extern "C" fn wedpr_abv_verify_bounded_vote_request( + param_cstring: *mut c_char, + request_cstring: *mut c_char, + public_key_cstring: *mut c_char, +) -> i8 { + let result = panic::catch_unwind(|| { + let public_key = + c_safe_c_char_pointer_to_bytes_with_error_value!(public_key_cstring, FAILURE); + + let param = + c_safe_c_char_pointer_to_proto_with_error_value!(param_cstring, SystemParametersStorage, FAILURE); + + let request = + c_safe_c_char_pointer_to_proto_with_error_value!(request_cstring, VoteRequest, FAILURE); + + let b_result = + match wedpr_s_anonymous_bounded_voting::verifier::verify_bounded_vote_request( + ¶m, + &request, + &public_key + ) { + Ok(v) => SUCCESS, + Err(_) => return FAILURE, + }; + b_result + }); + c_safe_return_with_error_value!(result, FAILURE) +} + + +/// C interface for 'wedpr_abv_aggregate_vote_sum_response'. +#[no_mangle] +pub extern "C" fn wedpr_abv_aggregate_vote_sum_response( + param_cstring: *mut c_char, + storage_cstring: *mut c_char, + vote_sum_cstring: *mut c_char, +) -> *mut c_char { + let result = panic::catch_unwind(|| { + + let param = + c_safe_c_char_pointer_to_proto!(param_cstring, SystemParametersStorage); + + let storage = + c_safe_c_char_pointer_to_proto!(storage_cstring, VoteStorage); + + let mut vote_sum = + c_safe_c_char_pointer_to_proto!(vote_sum_cstring, VoteStorage); + + let b_result = + match wedpr_s_anonymous_bounded_voting::verifier::aggregate_vote_sum_response( + ¶m, + &storage, + &mut vote_sum + ) { + Ok(v) => v, + Err(_) => return ptr::null_mut(), + }; + if !b_result { + return ptr::null_mut(); + } + c_safe_proto_to_c_char_pointer!(vote_sum) + }); + c_safe_return!(result) +} + +/// C interface for 'wedpr_abv_verify_count_request'. +#[no_mangle] +pub extern "C" fn wedpr_abv_verify_count_request( + param_cstring: *mut c_char, + encrypted_vote_sum_cstring: *mut c_char, + counter_share_cstring: *mut c_char, + request_cstring: *mut c_char, +) -> i8 { + let result = panic::catch_unwind(|| { + let counter_share_bytes = + c_safe_c_char_pointer_to_bytes_with_error_value!(counter_share_cstring, FAILURE); + + let param = + c_safe_c_char_pointer_to_proto_with_error_value!(param_cstring, SystemParametersStorage, FAILURE); + + let encrypted_vote_sum = + c_safe_c_char_pointer_to_proto_with_error_value!(encrypted_vote_sum_cstring, VoteStorage, FAILURE); + + let request = + c_safe_c_char_pointer_to_proto_with_error_value!(request_cstring, VoteRequest, FAILURE); + + let counter_share = match wedpr_l_crypto_zkp_utils::bytes_to_point(&counter_share_bytes) { + Ok(v) => v, + Err(_) => return FAILURE, + }; + + let b_result = + match wedpr_s_anonymous_bounded_voting::verifier::verify_count_request( + ¶m, + &encrypted_vote_sum, + &counter_share, + &request, + ) { + Ok(v) => SUCCESS, + Err(_) => return FAILURE, + }; + b_result + }); + c_safe_return_with_error_value!(result, FAILURE) +} \ No newline at end of file diff --git a/ffi/ffi_c/ffi_c_acv/src/voter.rs b/ffi/ffi_c/ffi_c_acv/src/voter.rs new file mode 100644 index 0000000..28e1e71 --- /dev/null +++ b/ffi/ffi_c/ffi_c_acv/src/voter.rs @@ -0,0 +1,6 @@ +// Copyright 2020 WeDPR Lab Project Authors. Licensed under Apache-2.0. + +//! Library of macros and functions for FFI of a voter in ABC +//! solution, targeting C/C++ compatible architectures (including iOS). + +// C/C++ FFI: C-style interfaces will be generated. \ No newline at end of file diff --git a/protos/solution/abv/abv.proto b/protos/solution/acv/acv.proto similarity index 86% rename from protos/solution/abv/abv.proto rename to protos/solution/acv/acv.proto index 4ef877d..44ce9fd 100644 --- a/protos/solution/abv/abv.proto +++ b/protos/solution/acv/acv.proto @@ -2,8 +2,8 @@ syntax = "proto3"; -package com.webank.wedpr.abv.proto; -option java_package = "com.webank.wedpr.abv.proto"; +package com.webank.wedpr.acv.proto; +option java_package = "com.webank.wedpr.acv.proto"; option java_multiple_files = true; // Counter Secret value @@ -22,7 +22,7 @@ message CounterSystemParametersStorage { // Voter Secret value message VoterSecret { - bytes vote_secret = 1; + bytes voter_secret = 1; } message RegistrationRequest { @@ -38,7 +38,6 @@ message RegistrationResponse { uint32 voter_weight = 1; Ballot ballot = 2; bytes signature = 3; - Ballot zero_ballot = 4; } message Ballot { @@ -78,18 +77,17 @@ message SystemParametersStorage { message BallotProof { bytes format_proof = 1; - bytes either_equality_proof = 2; } -message CandidateBallotProofPair { - string candidate = 1; +message StringToCandidateBallotProofPair { + string key = 1; BallotProof value = 2; } // Do not use Map, cause unordered in blockchain message VoteRequest { VoteStorage vote = 1; - repeated CandidateBallotProofPair ballot_proof = 2; + repeated StringToCandidateBallotProofPair ballot_proof = 2; bytes range_proof = 3; bytes sum_balance_proof = 4; } @@ -106,7 +104,7 @@ message StringToCountingPartPair { message CountingPart { string counter_id = 1; - bytes c2_r = 2; + bytes blinding_c2 = 2; bytes equality_proof = 3; } diff --git a/protos/src/generated/abv.rs b/protos/src/generated/acv.rs similarity index 91% rename from protos/src/generated/abv.rs rename to protos/src/generated/acv.rs index aaf69b5..9b8ab6c 100644 --- a/protos/src/generated/abv.rs +++ b/protos/src/generated/acv.rs @@ -17,7 +17,7 @@ #![allow(trivial_casts)] #![allow(unused_imports)] #![allow(unused_results)] -//! Generated file from `solution/abv/abv.proto` +//! Generated file from `solution/acv/acv.proto` /// Generated files are compatible only with the same version /// of protobuf runtime. @@ -403,7 +403,7 @@ impl CounterSystemParametersStorage { ::std::default::Default::default() } - // repeated .com.webank.wedpr.abv.proto.CounterSystemParametersShareRequest counter_parameters_request = 1; + // repeated .com.webank.wedpr.acv.proto.CounterSystemParametersShareRequest counter_parameters_request = 1; pub fn get_counter_parameters_request(&self) -> &[CounterSystemParametersShareRequest] { @@ -552,7 +552,7 @@ impl ::protobuf::reflect::ProtobufValue for CounterSystemParametersStorage { #[derive(PartialEq,Clone,Default)] pub struct VoterSecret { // message fields - pub vote_secret: ::std::vec::Vec, + pub voter_secret: ::std::vec::Vec, // special fields pub unknown_fields: ::protobuf::UnknownFields, pub cached_size: ::protobuf::CachedSize, @@ -569,30 +569,30 @@ impl VoterSecret { ::std::default::Default::default() } - // bytes vote_secret = 1; + // bytes voter_secret = 1; - pub fn get_vote_secret(&self) -> &[u8] { - &self.vote_secret + pub fn get_voter_secret(&self) -> &[u8] { + &self.voter_secret } - pub fn clear_vote_secret(&mut self) { - self.vote_secret.clear(); + pub fn clear_voter_secret(&mut self) { + self.voter_secret.clear(); } // Param is passed by value, moved - pub fn set_vote_secret(&mut self, v: ::std::vec::Vec) { - self.vote_secret = v; + pub fn set_voter_secret(&mut self, v: ::std::vec::Vec) { + self.voter_secret = v; } // Mutable pointer to the field. // If field is not initialized, it is initialized with default value first. - pub fn mut_vote_secret(&mut self) -> &mut ::std::vec::Vec { - &mut self.vote_secret + pub fn mut_voter_secret(&mut self) -> &mut ::std::vec::Vec { + &mut self.voter_secret } // Take field - pub fn take_vote_secret(&mut self) -> ::std::vec::Vec { - ::std::mem::replace(&mut self.vote_secret, ::std::vec::Vec::new()) + pub fn take_voter_secret(&mut self) -> ::std::vec::Vec { + ::std::mem::replace(&mut self.voter_secret, ::std::vec::Vec::new()) } } @@ -606,7 +606,7 @@ impl ::protobuf::Message for VoterSecret { 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.vote_secret)?; + ::protobuf::rt::read_singular_proto3_bytes_into(wire_type, is, &mut self.voter_secret)?; }, _ => { ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; @@ -620,8 +620,8 @@ impl ::protobuf::Message for VoterSecret { #[allow(unused_variables)] fn compute_size(&self) -> u32 { let mut my_size = 0; - if !self.vote_secret.is_empty() { - my_size += ::protobuf::rt::bytes_size(1, &self.vote_secret); + if !self.voter_secret.is_empty() { + my_size += ::protobuf::rt::bytes_size(1, &self.voter_secret); } my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); self.cached_size.set(my_size); @@ -629,8 +629,8 @@ impl ::protobuf::Message for VoterSecret { } fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { - if !self.vote_secret.is_empty() { - os.write_bytes(1, &self.vote_secret)?; + if !self.voter_secret.is_empty() { + os.write_bytes(1, &self.voter_secret)?; } os.write_unknown_fields(self.get_unknown_fields())?; ::std::result::Result::Ok(()) @@ -671,9 +671,9 @@ impl ::protobuf::Message for VoterSecret { descriptor.get(|| { let mut fields = ::std::vec::Vec::new(); fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( - "vote_secret", - |m: &VoterSecret| { &m.vote_secret }, - |m: &mut VoterSecret| { &mut m.vote_secret }, + "voter_secret", + |m: &VoterSecret| { &m.voter_secret }, + |m: &mut VoterSecret| { &mut m.voter_secret }, )); ::protobuf::reflect::MessageDescriptor::new_pb_name::( "VoterSecret", @@ -691,7 +691,7 @@ impl ::protobuf::Message for VoterSecret { impl ::protobuf::Clear for VoterSecret { fn clear(&mut self) { - self.vote_secret.clear(); + self.voter_secret.clear(); self.unknown_fields.clear(); } } @@ -728,7 +728,7 @@ impl RegistrationRequest { ::std::default::Default::default() } - // .com.webank.wedpr.abv.proto.RegistrationBlindingPoint weight_point = 1; + // .com.webank.wedpr.acv.proto.RegistrationBlindingPoint weight_point = 1; pub fn get_weight_point(&self) -> &RegistrationBlindingPoint { @@ -1089,7 +1089,6 @@ 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, @@ -1121,7 +1120,7 @@ impl RegistrationResponse { self.voter_weight = v; } - // .com.webank.wedpr.abv.proto.Ballot ballot = 2; + // .com.webank.wedpr.acv.proto.Ballot ballot = 2; pub fn get_ballot(&self) -> &Ballot { @@ -1179,39 +1178,6 @@ impl RegistrationResponse { pub fn take_signature(&mut self) -> ::std::vec::Vec { ::std::mem::replace(&mut self.signature, ::std::vec::Vec::new()) } - - // .com.webank.wedpr.abv.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 { @@ -1221,11 +1187,6 @@ impl ::protobuf::Message for RegistrationResponse { return false; } }; - for v in &self.zero_ballot { - if !v.is_initialized() { - return false; - } - }; true } @@ -1246,9 +1207,6 @@ 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())?; }, @@ -1271,10 +1229,6 @@ 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 @@ -1292,11 +1246,6 @@ 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(()) } @@ -1350,11 +1299,6 @@ 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, @@ -1374,7 +1318,6 @@ impl ::protobuf::Clear for RegistrationResponse { self.voter_weight = 0; self.ballot.clear(); self.signature.clear(); - self.zero_ballot.clear(); self.unknown_fields.clear(); } } @@ -1806,7 +1749,7 @@ impl VoteChoices { ::std::default::Default::default() } - // repeated .com.webank.wedpr.abv.proto.VoteChoice choice = 1; + // repeated .com.webank.wedpr.acv.proto.VoteChoice choice = 1; pub fn get_choice(&self) -> &[VoteChoice] { @@ -1999,7 +1942,7 @@ impl CandidateBallot { ::std::mem::replace(&mut self.candidate, ::std::string::String::new()) } - // .com.webank.wedpr.abv.proto.Ballot ballot = 2; + // .com.webank.wedpr.acv.proto.Ballot ballot = 2; pub fn get_ballot(&self) -> &Ballot { @@ -2217,7 +2160,7 @@ impl VoteStorage { ::std::mem::replace(&mut self.signature, ::std::vec::Vec::new()) } - // .com.webank.wedpr.abv.proto.Ballot blank_ballot = 2; + // .com.webank.wedpr.acv.proto.Ballot blank_ballot = 2; pub fn get_blank_ballot(&self) -> &Ballot { @@ -2250,7 +2193,7 @@ impl VoteStorage { self.blank_ballot.take().unwrap_or_else(|| Ballot::new()) } - // .com.webank.wedpr.abv.proto.Ballot rest_ballot = 3; + // .com.webank.wedpr.acv.proto.Ballot rest_ballot = 3; pub fn get_rest_ballot(&self) -> &Ballot { @@ -2283,7 +2226,7 @@ impl VoteStorage { self.rest_ballot.take().unwrap_or_else(|| Ballot::new()) } - // repeated .com.webank.wedpr.abv.proto.CandidateBallot voted_ballot = 4; + // repeated .com.webank.wedpr.acv.proto.CandidateBallot voted_ballot = 4; pub fn get_voted_ballot(&self) -> &[CandidateBallot] { @@ -2695,7 +2638,7 @@ impl SystemParametersStorage { ::std::mem::replace(&mut self.poll_point, ::std::vec::Vec::new()) } - // .com.webank.wedpr.abv.proto.CandidateList candidates = 2; + // .com.webank.wedpr.acv.proto.CandidateList candidates = 2; pub fn get_candidates(&self) -> &CandidateList { @@ -2868,7 +2811,6 @@ impl ::protobuf::reflect::ProtobufValue for SystemParametersStorage { 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, @@ -2910,32 +2852,6 @@ impl BallotProof { pub fn take_format_proof(&mut self) -> ::std::vec::Vec { ::std::mem::replace(&mut self.format_proof, ::std::vec::Vec::new()) } - - // 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(); - } - - // 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 { @@ -2950,9 +2866,6 @@ impl ::protobuf::Message for BallotProof { 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())?; }, @@ -2968,9 +2881,6 @@ 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 @@ -2980,9 +2890,6 @@ 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(()) } @@ -3026,11 +2933,6 @@ 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, @@ -3048,7 +2950,6 @@ 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(); } } @@ -3066,53 +2967,53 @@ impl ::protobuf::reflect::ProtobufValue for BallotProof { } #[derive(PartialEq,Clone,Default)] -pub struct CandidateBallotProofPair { +pub struct StringToCandidateBallotProofPair { // message fields - pub candidate: ::std::string::String, + pub key: ::std::string::String, pub value: ::protobuf::SingularPtrField, // special fields pub unknown_fields: ::protobuf::UnknownFields, pub cached_size: ::protobuf::CachedSize, } -impl<'a> ::std::default::Default for &'a CandidateBallotProofPair { - fn default() -> &'a CandidateBallotProofPair { - ::default_instance() +impl<'a> ::std::default::Default for &'a StringToCandidateBallotProofPair { + fn default() -> &'a StringToCandidateBallotProofPair { + ::default_instance() } } -impl CandidateBallotProofPair { - pub fn new() -> CandidateBallotProofPair { +impl StringToCandidateBallotProofPair { + pub fn new() -> StringToCandidateBallotProofPair { ::std::default::Default::default() } - // string candidate = 1; + // string key = 1; - pub fn get_candidate(&self) -> &str { - &self.candidate + pub fn get_key(&self) -> &str { + &self.key } - pub fn clear_candidate(&mut self) { - self.candidate.clear(); + pub fn clear_key(&mut self) { + self.key.clear(); } // Param is passed by value, moved - pub fn set_candidate(&mut self, v: ::std::string::String) { - self.candidate = v; + pub fn set_key(&mut self, v: ::std::string::String) { + self.key = v; } // Mutable pointer to the field. // If field is not initialized, it is initialized with default value first. - pub fn mut_candidate(&mut self) -> &mut ::std::string::String { - &mut self.candidate + pub fn mut_key(&mut self) -> &mut ::std::string::String { + &mut self.key } // Take field - pub fn take_candidate(&mut self) -> ::std::string::String { - ::std::mem::replace(&mut self.candidate, ::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.abv.proto.BallotProof value = 2; + // .com.webank.wedpr.acv.proto.BallotProof value = 2; pub fn get_value(&self) -> &BallotProof { @@ -3146,7 +3047,7 @@ impl CandidateBallotProofPair { } } -impl ::protobuf::Message for CandidateBallotProofPair { +impl ::protobuf::Message for StringToCandidateBallotProofPair { fn is_initialized(&self) -> bool { for v in &self.value { if !v.is_initialized() { @@ -3161,7 +3062,7 @@ impl ::protobuf::Message for CandidateBallotProofPair { 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.candidate)?; + ::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)?; @@ -3178,8 +3079,8 @@ impl ::protobuf::Message for CandidateBallotProofPair { #[allow(unused_variables)] fn compute_size(&self) -> u32 { let mut my_size = 0; - if !self.candidate.is_empty() { - my_size += ::protobuf::rt::string_size(1, &self.candidate); + 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(); @@ -3191,8 +3092,8 @@ impl ::protobuf::Message for CandidateBallotProofPair { } fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { - if !self.candidate.is_empty() { - os.write_string(1, &self.candidate)?; + 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)?; @@ -3229,8 +3130,8 @@ impl ::protobuf::Message for CandidateBallotProofPair { Self::descriptor_static() } - fn new() -> CandidateBallotProofPair { - CandidateBallotProofPair::new() + fn new() -> StringToCandidateBallotProofPair { + StringToCandidateBallotProofPair::new() } fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { @@ -3238,44 +3139,44 @@ impl ::protobuf::Message for CandidateBallotProofPair { descriptor.get(|| { let mut fields = ::std::vec::Vec::new(); fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( - "candidate", - |m: &CandidateBallotProofPair| { &m.candidate }, - |m: &mut CandidateBallotProofPair| { &mut m.candidate }, + "key", + |m: &StringToCandidateBallotProofPair| { &m.key }, + |m: &mut StringToCandidateBallotProofPair| { &mut m.key }, )); fields.push(::protobuf::reflect::accessor::make_singular_ptr_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( "value", - |m: &CandidateBallotProofPair| { &m.value }, - |m: &mut CandidateBallotProofPair| { &mut m.value }, + |m: &StringToCandidateBallotProofPair| { &m.value }, + |m: &mut StringToCandidateBallotProofPair| { &mut m.value }, )); - ::protobuf::reflect::MessageDescriptor::new_pb_name::( - "CandidateBallotProofPair", + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "StringToCandidateBallotProofPair", fields, file_descriptor_proto() ) }) } - fn default_instance() -> &'static CandidateBallotProofPair { - static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; - instance.get(CandidateBallotProofPair::new) + fn default_instance() -> &'static StringToCandidateBallotProofPair { + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(StringToCandidateBallotProofPair::new) } } -impl ::protobuf::Clear for CandidateBallotProofPair { +impl ::protobuf::Clear for StringToCandidateBallotProofPair { fn clear(&mut self) { - self.candidate.clear(); + self.key.clear(); self.value.clear(); self.unknown_fields.clear(); } } -impl ::std::fmt::Debug for CandidateBallotProofPair { +impl ::std::fmt::Debug for StringToCandidateBallotProofPair { fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { ::protobuf::text_format::fmt(self, f) } } -impl ::protobuf::reflect::ProtobufValue for CandidateBallotProofPair { +impl ::protobuf::reflect::ProtobufValue for StringToCandidateBallotProofPair { fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { ::protobuf::reflect::ReflectValueRef::Message(self) } @@ -3285,7 +3186,7 @@ impl ::protobuf::reflect::ProtobufValue for CandidateBallotProofPair { pub struct VoteRequest { // message fields pub vote: ::protobuf::SingularPtrField, - pub ballot_proof: ::protobuf::RepeatedField, + pub ballot_proof: ::protobuf::RepeatedField, pub range_proof: ::std::vec::Vec, pub sum_balance_proof: ::std::vec::Vec, // special fields @@ -3304,7 +3205,7 @@ impl VoteRequest { ::std::default::Default::default() } - // .com.webank.wedpr.abv.proto.VoteStorage vote = 1; + // .com.webank.wedpr.acv.proto.VoteStorage vote = 1; pub fn get_vote(&self) -> &VoteStorage { @@ -3337,10 +3238,10 @@ impl VoteRequest { self.vote.take().unwrap_or_else(|| VoteStorage::new()) } - // repeated .com.webank.wedpr.abv.proto.CandidateBallotProofPair ballot_proof = 2; + // repeated .com.webank.wedpr.acv.proto.StringToCandidateBallotProofPair ballot_proof = 2; - pub fn get_ballot_proof(&self) -> &[CandidateBallotProofPair] { + pub fn get_ballot_proof(&self) -> &[StringToCandidateBallotProofPair] { &self.ballot_proof } pub fn clear_ballot_proof(&mut self) { @@ -3348,17 +3249,17 @@ impl VoteRequest { } // Param is passed by value, moved - pub fn set_ballot_proof(&mut self, v: ::protobuf::RepeatedField) { + pub fn set_ballot_proof(&mut self, v: ::protobuf::RepeatedField) { self.ballot_proof = v; } // Mutable pointer to the field. - pub fn mut_ballot_proof(&mut self) -> &mut ::protobuf::RepeatedField { + pub fn mut_ballot_proof(&mut self) -> &mut ::protobuf::RepeatedField { &mut self.ballot_proof } // Take field - pub fn take_ballot_proof(&mut self) -> ::protobuf::RepeatedField { + pub fn take_ballot_proof(&mut self) -> ::protobuf::RepeatedField { ::std::mem::replace(&mut self.ballot_proof, ::protobuf::RepeatedField::new()) } @@ -3537,7 +3438,7 @@ impl ::protobuf::Message for VoteRequest { |m: &VoteRequest| { &m.vote }, |m: &mut VoteRequest| { &mut m.vote }, )); - fields.push(::protobuf::reflect::accessor::make_repeated_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( + fields.push(::protobuf::reflect::accessor::make_repeated_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( "ballot_proof", |m: &VoteRequest| { &m.ballot_proof }, |m: &mut VoteRequest| { &mut m.ballot_proof }, @@ -3609,7 +3510,7 @@ impl DecryptedResultPartStorage { ::std::default::Default::default() } - // .com.webank.wedpr.abv.proto.CountingPart blank_part = 1; + // .com.webank.wedpr.acv.proto.CountingPart blank_part = 1; pub fn get_blank_part(&self) -> &CountingPart { @@ -3642,7 +3543,7 @@ impl DecryptedResultPartStorage { self.blank_part.take().unwrap_or_else(|| CountingPart::new()) } - // repeated .com.webank.wedpr.abv.proto.StringToCountingPartPair candidate_part = 2; + // repeated .com.webank.wedpr.acv.proto.StringToCountingPartPair candidate_part = 2; pub fn get_candidate_part(&self) -> &[StringToCountingPartPair] { @@ -3858,7 +3759,7 @@ impl StringToCountingPartPair { ::std::mem::replace(&mut self.key, ::std::string::String::new()) } - // .com.webank.wedpr.abv.proto.CountingPart value = 2; + // .com.webank.wedpr.acv.proto.CountingPart value = 2; pub fn get_value(&self) -> &CountingPart { @@ -4031,7 +3932,7 @@ impl ::protobuf::reflect::ProtobufValue for StringToCountingPartPair { pub struct CountingPart { // message fields pub counter_id: ::std::string::String, - pub c2_r: ::std::vec::Vec, + pub blinding_c2: ::std::vec::Vec, pub equality_proof: ::std::vec::Vec, // special fields pub unknown_fields: ::protobuf::UnknownFields, @@ -4075,30 +3976,30 @@ impl CountingPart { ::std::mem::replace(&mut self.counter_id, ::std::string::String::new()) } - // bytes c2_r = 2; + // bytes blinding_c2 = 2; - pub fn get_c2_r(&self) -> &[u8] { - &self.c2_r + pub fn get_blinding_c2(&self) -> &[u8] { + &self.blinding_c2 } - pub fn clear_c2_r(&mut self) { - self.c2_r.clear(); + pub fn clear_blinding_c2(&mut self) { + self.blinding_c2.clear(); } // Param is passed by value, moved - pub fn set_c2_r(&mut self, v: ::std::vec::Vec) { - self.c2_r = v; + 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_c2_r(&mut self) -> &mut ::std::vec::Vec { - &mut self.c2_r + pub fn mut_blinding_c2(&mut self) -> &mut ::std::vec::Vec { + &mut self.blinding_c2 } // Take field - pub fn take_c2_r(&mut self) -> ::std::vec::Vec { - ::std::mem::replace(&mut self.c2_r, ::std::vec::Vec::new()) + 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; @@ -4141,7 +4042,7 @@ impl ::protobuf::Message for CountingPart { ::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.c2_r)?; + ::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)?; @@ -4161,8 +4062,8 @@ impl ::protobuf::Message for CountingPart { if !self.counter_id.is_empty() { my_size += ::protobuf::rt::string_size(1, &self.counter_id); } - if !self.c2_r.is_empty() { - my_size += ::protobuf::rt::bytes_size(2, &self.c2_r); + 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); @@ -4176,8 +4077,8 @@ impl ::protobuf::Message for CountingPart { if !self.counter_id.is_empty() { os.write_string(1, &self.counter_id)?; } - if !self.c2_r.is_empty() { - os.write_bytes(2, &self.c2_r)?; + 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)?; @@ -4226,9 +4127,9 @@ impl ::protobuf::Message for CountingPart { |m: &mut CountingPart| { &mut m.counter_id }, )); fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( - "c2_r", - |m: &CountingPart| { &m.c2_r }, - |m: &mut CountingPart| { &mut m.c2_r }, + "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", @@ -4252,7 +4153,7 @@ impl ::protobuf::Message for CountingPart { impl ::protobuf::Clear for CountingPart { fn clear(&mut self) { self.counter_id.clear(); - self.c2_r.clear(); + self.blinding_c2.clear(); self.equality_proof.clear(); self.unknown_fields.clear(); } @@ -4290,7 +4191,7 @@ impl VoteResultStorage { ::std::default::Default::default() } - // repeated .com.webank.wedpr.abv.proto.StringToInt64Pair result = 1; + // repeated .com.webank.wedpr.acv.proto.StringToInt64Pair result = 1; pub fn get_result(&self) -> &[StringToInt64Pair] { @@ -4631,62 +4532,60 @@ impl ::protobuf::reflect::ProtobufValue for StringToInt64Pair { } static file_descriptor_proto_data: &'static [u8] = b"\ - \n\x16solution/abv/abv.proto\x12\x1acom.webank.wedpr.abv.proto\";\n\rCou\ + \n\x16solution/acv/acv.proto\x12\x1acom.webank.wedpr.acv.proto\";\n\rCou\ nterSecret\x12*\n\x11poll_secret_share\x18\x01\x20\x01(\x0cR\x0fpollSecr\ etShare\"n\n#CounterSystemParametersShareRequest\x12\x1d\n\ncounter_id\ \x18\x01\x20\x01(\tR\tcounterId\x12(\n\x10poll_point_share\x18\x02\x20\ \x01(\x0cR\x0epollPointShare\"\x9f\x01\n\x1eCounterSystemParametersStora\ ge\x12}\n\x1acounter_parameters_request\x18\x01\x20\x03(\x0b2?.com.weban\ - k.wedpr.abv.proto.CounterSystemParametersShareRequestR\x18counterParamet\ - ersRequest\".\n\x0bVoterSecret\x12\x1f\n\x0bvote_secret\x18\x01\x20\x01(\ - \x0cR\nvoteSecret\"o\n\x13RegistrationRequest\x12X\n\x0cweight_point\x18\ - \x01\x20\x01(\x0b25.com.webank.wedpr.abv.proto.RegistrationBlindingPoint\ - R\x0bweightPoint\"\x7f\n\x19RegistrationBlindingPoint\x12.\n\x13blinding\ - _poll_point\x18\x01\x20\x01(\x0cR\x11blindingPollPoint\x122\n\x15blindin\ - g_basepoint_g2\x18\x02\x20\x01(\x0cR\x13blindingBasepointG2\"\xd8\x01\n\ - \x14RegistrationResponse\x12!\n\x0cvoter_weight\x18\x01\x20\x01(\rR\x0bv\ - oterWeight\x12:\n\x06ballot\x18\x02\x20\x01(\x0b2\".com.webank.wedpr.abv\ - .proto.BallotR\x06ballot\x12\x1c\n\tsignature\x18\x03\x20\x01(\x0cR\tsig\ - nature\x12C\n\x0bzero_ballot\x18\x04\x20\x01(\x0b2\".com.webank.wedpr.ab\ - v.proto.BallotR\nzeroBallot\"L\n\x06Ballot\x12\x20\n\x0bciphertext1\x18\ - \x01\x20\x01(\x0cR\x0bciphertext1\x12\x20\n\x0bciphertext2\x18\x02\x20\ - \x01(\x0cR\x0bciphertext2\"@\n\nVoteChoice\x12\x1c\n\tcandidate\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&.com.webank.\ - wedpr.abv.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.abv.proto.BallotR\x06ballot\"\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.abv.pro\ - to.BallotR\x0bblankBallot\x12C\n\x0brest_ballot\x18\x03\x20\x01(\x0b2\".\ - com.webank.wedpr.abv.proto.BallotR\nrestBallot\x12N\n\x0cvoted_ballot\ - \x18\x04\x20\x03(\x0b2+.com.webank.wedpr.abv.proto.CandidateBallotR\x0bv\ - otedBallot\"-\n\rCandidateList\x12\x1c\n\tcandidate\x18\x01\x20\x03(\tR\ - \tcandidate\"\x83\x01\n\x17SystemParametersStorage\x12\x1d\n\npoll_point\ - \x18\x01\x20\x01(\x0cR\tpollPoint\x12I\n\ncandidates\x18\x02\x20\x01(\ - \x0b2).com.webank.wedpr.abv.proto.CandidateListR\ncandidates\"d\n\x0bBal\ - lotProof\x12!\n\x0cformat_proof\x18\x01\x20\x01(\x0cR\x0bformatProof\x12\ - 2\n\x15either_equality_proof\x18\x02\x20\x01(\x0cR\x13eitherEqualityProo\ - f\"w\n\x18CandidateBallotProofPair\x12\x1c\n\tcandidate\x18\x01\x20\x01(\ - \tR\tcandidate\x12=\n\x05value\x18\x02\x20\x01(\x0b2'.com.webank.wedpr.a\ - bv.proto.BallotProofR\x05value\"\xf0\x01\n\x0bVoteRequest\x12;\n\x04vote\ - \x18\x01\x20\x01(\x0b2'.com.webank.wedpr.abv.proto.VoteStorageR\x04vote\ - \x12W\n\x0cballot_proof\x18\x02\x20\x03(\x0b24.com.webank.wedpr.abv.prot\ - o.CandidateBallotProofPairR\x0bballotProof\x12\x1f\n\x0brange_proof\x18\ - \x03\x20\x01(\x0cR\nrangeProof\x12*\n\x11sum_balance_proof\x18\x04\x20\ - \x01(\x0cR\x0fsumBalanceProof\"\xc2\x01\n\x1aDecryptedResultPartStorage\ - \x12G\n\nblank_part\x18\x01\x20\x01(\x0b2(.com.webank.wedpr.abv.proto.Co\ - untingPartR\tblankPart\x12[\n\x0ecandidate_part\x18\x02\x20\x03(\x0b24.c\ - om.webank.wedpr.abv.proto.StringToCountingPartPairR\rcandidatePart\"l\n\ - \x18StringToCountingPartPair\x12\x10\n\x03key\x18\x01\x20\x01(\tR\x03key\ - \x12>\n\x05value\x18\x02\x20\x01(\x0b2(.com.webank.wedpr.abv.proto.Count\ - ingPartR\x05value\"g\n\x0cCountingPart\x12\x1d\n\ncounter_id\x18\x01\x20\ - \x01(\tR\tcounterId\x12\x11\n\x04c2_r\x18\x02\x20\x01(\x0cR\x03c2R\x12%\ - \n\x0eequality_proof\x18\x03\x20\x01(\x0cR\requalityProof\"Z\n\x11VoteRe\ - sultStorage\x12E\n\x06result\x18\x01\x20\x03(\x0b2-.com.webank.wedpr.abv\ - .proto.StringToInt64PairR\x06result\";\n\x11StringToInt64Pair\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.abv.protoP\x01b\x06proto3\ + k.wedpr.acv.proto.CounterSystemParametersShareRequestR\x18counterParamet\ + ersRequest\"0\n\x0bVoterSecret\x12!\n\x0cvoter_secret\x18\x01\x20\x01(\ + \x0cR\x0bvoterSecret\"o\n\x13RegistrationRequest\x12X\n\x0cweight_point\ + \x18\x01\x20\x01(\x0b25.com.webank.wedpr.acv.proto.RegistrationBlindingP\ + ointR\x0bweightPoint\"\x7f\n\x19RegistrationBlindingPoint\x12.\n\x13blin\ + ding_poll_point\x18\x01\x20\x01(\x0cR\x11blindingPollPoint\x122\n\x15bli\ + nding_basepoint_g2\x18\x02\x20\x01(\x0cR\x13blindingBasepointG2\"\x93\ + \x01\n\x14RegistrationResponse\x12!\n\x0cvoter_weight\x18\x01\x20\x01(\r\ + R\x0bvoterWeight\x12:\n\x06ballot\x18\x02\x20\x01(\x0b2\".com.webank.wed\ + pr.acv.proto.BallotR\x06ballot\x12\x1c\n\tsignature\x18\x03\x20\x01(\x0c\ + R\tsignature\"L\n\x06Ballot\x12\x20\n\x0bciphertext1\x18\x01\x20\x01(\ + \x0cR\x0bciphertext1\x12\x20\n\x0bciphertext2\x18\x02\x20\x01(\x0cR\x0bc\ + iphertext2\"@\n\nVoteChoice\x12\x1c\n\tcandidate\x18\x01\x20\x01(\tR\tca\ + ndidate\x12\x14\n\x05value\x18\x02\x20\x01(\rR\x05value\"M\n\x0bVoteChoi\ + ces\x12>\n\x06choice\x18\x01\x20\x03(\x0b2&.com.webank.wedpr.acv.proto.V\ + oteChoiceR\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\"\x87\x02\n\x0bVoteStorage\x12\ + \x1c\n\tsignature\x18\x01\x20\x01(\x0cR\tsignature\x12E\n\x0cblank_ballo\ + t\x18\x02\x20\x01(\x0b2\".com.webank.wedpr.acv.proto.BallotR\x0bblankBal\ + lot\x12C\n\x0brest_ballot\x18\x03\x20\x01(\x0b2\".com.webank.wedpr.acv.p\ + roto.BallotR\nrestBallot\x12N\n\x0cvoted_ballot\x18\x04\x20\x03(\x0b2+.c\ + om.webank.wedpr.acv.proto.CandidateBallotR\x0bvotedBallot\"-\n\rCandidat\ + eList\x12\x1c\n\tcandidate\x18\x01\x20\x03(\tR\tcandidate\"\x83\x01\n\ + \x17SystemParametersStorage\x12\x1d\n\npoll_point\x18\x01\x20\x01(\x0cR\ + \tpollPoint\x12I\n\ncandidates\x18\x02\x20\x01(\x0b2).com.webank.wedpr.a\ + cv.proto.CandidateListR\ncandidates\"0\n\x0bBallotProof\x12!\n\x0cformat\ + _proof\x18\x01\x20\x01(\x0cR\x0bformatProof\"s\n\x20StringToCandidateBal\ + lotProofPair\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\ + \"\xf8\x01\n\x0bVoteRequest\x12;\n\x04vote\x18\x01\x20\x01(\x0b2'.com.we\ + bank.wedpr.acv.proto.VoteStorageR\x04vote\x12_\n\x0cballot_proof\x18\x02\ + \x20\x03(\x0b2<.com.webank.wedpr.acv.proto.StringToCandidateBallotProofP\ + airR\x0bballotProof\x12\x1f\n\x0brange_proof\x18\x03\x20\x01(\x0cR\nrang\ + eProof\x12*\n\x11sum_balance_proof\x18\x04\x20\x01(\x0cR\x0fsumBalancePr\ + oof\"\xc2\x01\n\x1aDecryptedResultPartStorage\x12G\n\nblank_part\x18\x01\ + \x20\x01(\x0b2(.com.webank.wedpr.acv.proto.CountingPartR\tblankPart\x12[\ + \n\x0ecandidate_part\x18\x02\x20\x03(\x0b24.com.webank.wedpr.acv.proto.S\ + tringToCountingPartPairR\rcandidatePart\"l\n\x18StringToCountingPartPair\ + \x12\x10\n\x03key\x18\x01\x20\x01(\tR\x03key\x12>\n\x05value\x18\x02\x20\ + \x01(\x0b2(.com.webank.wedpr.acv.proto.CountingPartR\x05value\"u\n\x0cCo\ + untingPart\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_p\ + roof\x18\x03\x20\x01(\x0cR\requalityProof\"Z\n\x11VoteResultStorage\x12E\ + \n\x06result\x18\x01\x20\x03(\x0b2-.com.webank.wedpr.acv.proto.StringToI\ + nt64PairR\x06result\";\n\x11StringToInt64Pair\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\ "; static file_descriptor_proto_lazy: ::protobuf::rt::LazyV2<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::rt::LazyV2::INIT; diff --git a/protos/src/generated/mod.rs b/protos/src/generated/mod.rs index 25517a9..dea52e1 100644 --- a/protos/src/generated/mod.rs +++ b/protos/src/generated/mod.rs @@ -1,6 +1,6 @@ // Copyright 2020 WeDPR Lab Project Authors. Licensed under Apache-2.0. -pub mod abv; +pub mod acv; pub mod hdk; pub mod scd; pub mod vcl; diff --git a/protos/src/main.rs b/protos/src/main.rs index c56249c..8689a05 100644 --- a/protos/src/main.rs +++ b/protos/src/main.rs @@ -27,7 +27,7 @@ fn generate_proto_for_all() { .includes(&["."]) // List all used proto files here. // You can remove any proto files that are not used by your project. - .inputs(&["solution/vcl/vcl.proto","solution/scd/scd.proto","solution/ktb/hdk.proto", "solution/abv/abv.proto"]) + .inputs(&["solution/vcl/vcl.proto","solution/scd/scd.proto","solution/ktb/hdk.proto", "solution/acv/acv.proto"]) .customize(Customize { ..Default::default() }) diff --git a/solution/anonymous_bounded_voting/Cargo.toml b/solution/anonymous_ciphertext_voting/Cargo.toml similarity index 91% rename from solution/anonymous_bounded_voting/Cargo.toml rename to solution/anonymous_ciphertext_voting/Cargo.toml index 38dae5e..f54ccdc 100644 --- a/solution/anonymous_bounded_voting/Cargo.toml +++ b/solution/anonymous_ciphertext_voting/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "wedpr_s_anonymous_bounded_voting" +name = "wedpr_s_anonymous_ciphertext_voting" version = "1.5.0" authors = [ "WeDPR " ] edition = "2018" @@ -13,7 +13,7 @@ wedpr_l_macros = "1.0.0" wedpr_l_utils = "1.1.0" wedpr_l_crypto_zkp_discrete_logarithm_proof = { git = "https://github.com/WeBankBlockchain/WeDPR-Lab-Crypto.git", branch = "release-1.2.0" } wedpr_s_protos = { path = "../../protos"} -wedpr_l_protos = { git = "https://github.com/WeBankBlockchain/WeDPR-Lab-Crypto.git", branch = "release-1.2.0", version = "1.1.1" } +wedpr_l_protos = { git = "https://github.com/WeBankBlockchain/WeDPR-Lab-Crypto.git", branch = "release-1.2.0" } curve25519-dalek = { version = "1", features = [ "serde" ] } wedpr_l_crypto_zkp_utils = { git = "https://github.com/WeBankBlockchain/WeDPR-Lab-Crypto.git", branch = "release-1.2.0" } wedpr_l_crypto_signature_secp256k1 = { git = "https://github.com/WeBankBlockchain/WeDPR-Lab-Crypto.git", branch = "release-1.2.0" } diff --git a/solution/anonymous_bounded_voting/src/config.rs b/solution/anonymous_ciphertext_voting/src/config.rs similarity index 62% rename from solution/anonymous_bounded_voting/src/config.rs rename to solution/anonymous_ciphertext_voting/src/config.rs index 8796220..7a6fe46 100644 --- a/solution/anonymous_bounded_voting/src/config.rs +++ b/solution/anonymous_ciphertext_voting/src/config.rs @@ -1,11 +1,13 @@ // Copyright 2020 WeDPR Lab Project Authors. Licensed under Apache-2.0. -//! Config of anonymous bounded voting (ABV) solution. +//! Config of anonymous ciphertext voting (ACV) solution. use wedpr_l_crypto_hash_keccak256::WedprKeccak256; use wedpr_l_crypto_signature_secp256k1::WedprSecp256k1Recover; lazy_static! { + /// Shared hash algorithm reference for quick implementation replacement. + /// Other code should use this reference, and not directly use a specific implementation. pub static ref SIGNATURE_SECP256K1: WedprSecp256k1Recover = WedprSecp256k1Recover::default(); pub static ref HASH_KECCAK256: WedprKeccak256 = WedprKeccak256::default(); diff --git a/solution/anonymous_bounded_voting/src/coordinator.rs b/solution/anonymous_ciphertext_voting/src/coordinator.rs similarity index 84% rename from solution/anonymous_bounded_voting/src/coordinator.rs rename to solution/anonymous_ciphertext_voting/src/coordinator.rs index 5f6447b..6afe70a 100644 --- a/solution/anonymous_bounded_voting/src/coordinator.rs +++ b/solution/anonymous_ciphertext_voting/src/coordinator.rs @@ -1,6 +1,6 @@ // Copyright 2020 WeDPR Lab Project Authors. Licensed under Apache-2.0. -//! Library of anonymous bounded voting (ABV) solution. +//! Library of anonymous ciphertext voting (ACV) solution. use crate::config::{HASH_KECCAK256, SIGNATURE_SECP256K1}; use curve25519_dalek::{ristretto::RistrettoPoint, scalar::Scalar}; @@ -9,12 +9,13 @@ use wedpr_l_utils::{ error::WedprError, traits::{Hash, Signature}, }; -use wedpr_s_protos::generated::abv::{ +use wedpr_s_protos::generated::acv::{ Ballot, CandidateList, CounterSystemParametersStorage, CountingPart, DecryptedResultPartStorage, RegistrationRequest, RegistrationResponse, StringToCountingPartPair, SystemParametersStorage, }; +/// Makes system parameters by candidate list and counter storage messages. pub fn make_system_parameters( candidates: &CandidateList, counter_storage: &CounterSystemParametersStorage, @@ -29,14 +30,13 @@ pub fn make_system_parameters( Ok(storage) } +/// Certifies ballot value which voter can vote to all candidates. pub fn certify_bounded_voter( secret_key: &[u8], value: u32, registration_request: &RegistrationRequest, ) -> Result { - // let blinding_basepoint_g2 = - // bytes_to_point(registration_request.get_weight_point(). - // get_blinding_basepoint_g2())?; + let blinding_poll_point = bytes_to_point( registration_request .get_weight_point() @@ -64,6 +64,7 @@ pub fn certify_bounded_voter( Ok(response) } +/// Decrypts counters' . pub fn aggregate_decrypted_part_sum( param: &SystemParametersStorage, decrypted_result_part_storage: &DecryptedResultPartStorage, @@ -75,10 +76,10 @@ pub fn aggregate_decrypted_part_sum( .set_counter_id("default".to_string()); counting_result_sum .mut_blank_part() - .set_c2_r(point_to_bytes(&RistrettoPoint::default())); + .set_blinding_c2(point_to_bytes(&RistrettoPoint::default())); for candidate in param.get_candidates().get_candidate() { let mut counting_part = CountingPart::new(); - counting_part.set_c2_r(point_to_bytes(&RistrettoPoint::default())); + counting_part.set_blinding_c2(point_to_bytes(&RistrettoPoint::default())); let mut tmp_pair = StringToCountingPartPair::new(); tmp_pair.set_key(candidate.to_string()); tmp_pair.set_value(counting_part); @@ -86,15 +87,15 @@ pub fn aggregate_decrypted_part_sum( } } let mut blank_c2_r_sum = - bytes_to_point(&counting_result_sum.get_blank_part().get_c2_r())?; + bytes_to_point(&counting_result_sum.get_blank_part().get_blinding_c2())?; let blank_part_share = bytes_to_point( - &decrypted_result_part_storage.get_blank_part().get_c2_r(), + &decrypted_result_part_storage.get_blank_part().get_blinding_c2(), )?; blank_c2_r_sum += blank_part_share; counting_result_sum .mut_blank_part() - .set_c2_r(point_to_bytes(&blank_c2_r_sum)); + .set_blinding_c2(point_to_bytes(&blank_c2_r_sum)); for candidate in param.get_candidates().get_candidate() { let mut candidate_counting_part = CountingPart::new(); for tmp_pair in counting_result_sum.get_candidate_part() { @@ -104,7 +105,7 @@ pub fn aggregate_decrypted_part_sum( } let mut candidate_c2_r_sum = - bytes_to_point(&candidate_counting_part.get_c2_r())?; + bytes_to_point(&candidate_counting_part.get_blinding_c2())?; let mut counting_part = CountingPart::new(); for tmp_pair in decrypted_result_part_storage.get_candidate_part() { @@ -113,10 +114,10 @@ pub fn aggregate_decrypted_part_sum( } } - let candidate_c2_r = bytes_to_point(&counting_part.get_c2_r())?; + let candidate_c2_r = bytes_to_point(&counting_part.get_blinding_c2())?; candidate_c2_r_sum += candidate_c2_r; let mut candidate_part = CountingPart::new(); - candidate_part.set_c2_r(point_to_bytes(&candidate_c2_r_sum)); + candidate_part.set_blinding_c2(point_to_bytes(&candidate_c2_r_sum)); let mut tmp_pair = StringToCountingPartPair::new(); tmp_pair.set_key(candidate.to_string()); tmp_pair.set_value(candidate_part); diff --git a/solution/anonymous_bounded_voting/src/counter.rs b/solution/anonymous_ciphertext_voting/src/counter.rs similarity index 94% rename from solution/anonymous_bounded_voting/src/counter.rs rename to solution/anonymous_ciphertext_voting/src/counter.rs index 137a443..1a8d879 100644 --- a/solution/anonymous_bounded_voting/src/counter.rs +++ b/solution/anonymous_ciphertext_voting/src/counter.rs @@ -1,6 +1,6 @@ // Copyright 2020 WeDPR Lab Project Authors. Licensed under Apache-2.0. -//! Library of anonymous bounded voting (ABV) solution. +//! Library of anonymous ciphertext voting (ACV) solution. use curve25519_dalek::scalar::Scalar; use wedpr_l_crypto_zkp_discrete_logarithm_proof::prove_equality_relationship_proof; @@ -10,7 +10,7 @@ use wedpr_l_crypto_zkp_utils::{ }; use wedpr_l_protos::proto_to_bytes; use wedpr_l_utils::error::WedprError; -use wedpr_s_protos::generated::abv::{ +use wedpr_s_protos::generated::acv::{ Ballot, CounterSecret, CounterSystemParametersShareRequest, CountingPart, DecryptedResultPartStorage, StringToCountingPartPair, StringToInt64Pair, SystemParametersStorage, VoteResultStorage, VoteStorage, @@ -59,7 +59,7 @@ pub fn count( &candidate_part_share, ); let mut counting_part = CountingPart::new(); - counting_part.set_c2_r(point_to_bytes( + counting_part.set_blinding_c2(point_to_bytes( &(&candidate_part_share * (secret_share)), )); counting_part.set_equality_proof(proto_to_bytes(&equity_proof)?); @@ -81,7 +81,7 @@ pub fn count( .set_equality_proof(proto_to_bytes(&equity_proof)?); request .mut_blank_part() - .set_c2_r(point_to_bytes(&blank_part)); + .set_blinding_c2(point_to_bytes(&blank_part)); request .mut_blank_part() .set_counter_id(counter_id.to_string()); @@ -101,7 +101,7 @@ pub fn finalize_vote_result( let blank_c1_sum = bytes_to_point(vote_sum.get_blank_ballot().get_ciphertext1())?; let blank_c2_r_sum = - bytes_to_point(counting_result_sum.get_blank_part().get_c2_r())?; + bytes_to_point(counting_result_sum.get_blank_part().get_blinding_c2())?; let tmp = blank_c1_sum - (blank_c2_r_sum); for i in 1..=max_number { let try_num = Scalar::from(i as u64); @@ -128,7 +128,7 @@ pub fn finalize_vote_result( } } let candidate_c2_r_sum = - bytes_to_point(candidate_counting_part.get_c2_r())?; + bytes_to_point(candidate_counting_part.get_blinding_c2())?; let tmp = bytes_to_point(ballot.get_ciphertext1())? - (candidate_c2_r_sum); diff --git a/solution/anonymous_bounded_voting/src/lib.rs b/solution/anonymous_ciphertext_voting/src/lib.rs similarity index 98% rename from solution/anonymous_bounded_voting/src/lib.rs rename to solution/anonymous_ciphertext_voting/src/lib.rs index 5dded5c..b6ee48d 100644 --- a/solution/anonymous_bounded_voting/src/lib.rs +++ b/solution/anonymous_ciphertext_voting/src/lib.rs @@ -1,6 +1,6 @@ // Copyright 2020 WeDPR Lab Project Authors. Licensed under Apache-2.0. -//! Library of anonymous bounded voting (ABV) solution. +//! Library of anonymous ciphertext voting (ACV) solution. #[macro_use] extern crate lazy_static; @@ -20,7 +20,7 @@ mod tests { use crate::config::SIGNATURE_SECP256K1; use wedpr_l_crypto_zkp_utils::bytes_to_point; use wedpr_l_utils::traits::Signature; - use wedpr_s_protos::generated::abv::{ + use wedpr_s_protos::generated::acv::{ CandidateList, CounterSecret, CounterSystemParametersStorage, DecryptedResultPartStorage, VoteChoice, VoteChoices, VoteStorage, VoterSecret, diff --git a/solution/anonymous_bounded_voting/src/verifier.rs b/solution/anonymous_ciphertext_voting/src/verifier.rs similarity index 96% rename from solution/anonymous_bounded_voting/src/verifier.rs rename to solution/anonymous_ciphertext_voting/src/verifier.rs index a6ab486..4a18ee8 100644 --- a/solution/anonymous_bounded_voting/src/verifier.rs +++ b/solution/anonymous_ciphertext_voting/src/verifier.rs @@ -1,11 +1,11 @@ // Copyright 2020 WeDPR Lab Project Authors. Licensed under Apache-2.0. -//! Library of anonymous bounded voting (ABV) solution. +//! Library of anonymous ciphertext voting (ACV) solution. use wedpr_l_utils::error::WedprError; -use wedpr_s_protos::generated::abv::{ +use wedpr_s_protos::generated::acv::{ Ballot, CandidateBallot, CountingPart, DecryptedResultPartStorage, - VoteResultStorage, VoteStorage, + VoteResultStorage, VoteStorage,SystemParametersStorage, VoteRequest }; use crate::config::{HASH_KECCAK256, SIGNATURE_SECP256K1}; @@ -23,7 +23,6 @@ use wedpr_l_protos::{ generated::zkp::{BalanceProof, EqualityProof}, }; use wedpr_l_utils::traits::{Hash, Signature}; -use wedpr_s_protos::generated::abv::{SystemParametersStorage, VoteRequest}; pub fn verify_bounded_vote_request( param: &SystemParametersStorage, @@ -65,7 +64,7 @@ pub fn verify_bounded_vote_request( } for candidate_ballot in request.get_ballot_proof() { - let candidate = candidate_ballot.get_candidate(); + let candidate = candidate_ballot.get_key(); let ballot_proof = candidate_ballot.get_value(); let mut candidate_ballot = Ballot::new(); for candidate_ballot_pair in request.get_vote().get_voted_ballot() { @@ -199,7 +198,7 @@ pub fn verify_count_request( )?; let blank_equality_proof_bytes = request.get_blank_part().get_equality_proof(); - let blank_c2_r = bytes_to_point(&request.get_blank_part().get_c2_r())?; + let blank_c2_r = bytes_to_point(&request.get_blank_part().get_blinding_c2())?; let blank_equality_proof = bytes_to_proto::(&blank_equality_proof_bytes)?; if !verify_equality_relationship_proof( @@ -226,7 +225,7 @@ pub fn verify_count_request( counting_part = pair.get_value().clone(); } } - let candidate_c2_r = bytes_to_point(&counting_part.get_c2_r())?; + let candidate_c2_r = bytes_to_point(&counting_part.get_blinding_c2())?; let candidate_equality_proof_bytes = counting_part.get_equality_proof(); let candidate_equality_proof = bytes_to_proto::(candidate_equality_proof_bytes)?; @@ -257,7 +256,7 @@ pub fn verify_vote_result( let blank_c1_sum = bytes_to_point(&vote_sum.get_blank_ballot().get_ciphertext1())?; let blank_c2_r_sum = - bytes_to_point(&counting_result_sum.get_blank_part().get_c2_r())?; + bytes_to_point(&counting_result_sum.get_blank_part().get_blinding_c2())?; let expected_blank_ballot_result = blank_c1_sum - (blank_c2_r_sum); let mut get_blank_result: i64 = 0; for tmp in vote_result_request.get_result() { @@ -289,7 +288,7 @@ pub fn verify_vote_result( } let candidate_c2_r_sum = - bytes_to_point(&candidate_counting_part.get_c2_r())?; + bytes_to_point(&candidate_counting_part.get_blinding_c2())?; let expected_candidate_ballot_result = bytes_to_point(&ballot.get_ciphertext1())? - (candidate_c2_r_sum); diff --git a/solution/anonymous_bounded_voting/src/voter.rs b/solution/anonymous_ciphertext_voting/src/voter.rs similarity index 91% rename from solution/anonymous_bounded_voting/src/voter.rs rename to solution/anonymous_ciphertext_voting/src/voter.rs index d511b50..97bbb8e 100644 --- a/solution/anonymous_bounded_voting/src/voter.rs +++ b/solution/anonymous_ciphertext_voting/src/voter.rs @@ -1,6 +1,6 @@ // Copyright 2020 WeDPR Lab Project Authors. Licensed under Apache-2.0. -//! Library of anonymous bounded voting (ABV) solution. +//! Library of anonymous ciphertext voting (ACV) solution. use curve25519_dalek::{ ristretto::RistrettoPoint, scalar::Scalar, traits::MultiscalarMul, @@ -15,8 +15,8 @@ use wedpr_l_crypto_zkp_utils::{ }; use wedpr_l_protos::proto_to_bytes; use wedpr_l_utils::error::WedprError; -use wedpr_s_protos::generated::abv::{ - Ballot, BallotProof, CandidateBallot, CandidateBallotProofPair, +use wedpr_s_protos::generated::acv::{ + Ballot, BallotProof, CandidateBallot, StringToCandidateBallotProofPair, RegistrationRequest, RegistrationResponse, SystemParametersStorage, VoteChoices, VoteRequest, VoterSecret, }; @@ -24,7 +24,7 @@ use wedpr_s_protos::generated::abv::{ pub fn make_voter_secret() -> VoterSecret { let vote_secret = get_random_scalar(); VoterSecret { - vote_secret: scalar_to_bytes(&vote_secret), + voter_secret: scalar_to_bytes(&vote_secret), unknown_fields: Default::default(), cached_size: Default::default(), } @@ -34,10 +34,10 @@ pub fn make_bounded_registration_request( secret: &VoterSecret, param: &SystemParametersStorage, ) -> Result { - let vote_secret = bytes_to_scalar(secret.get_vote_secret())?; - let blinding_basepoint_g2 = vote_secret * *BASEPOINT_G2; + let voter_secret = bytes_to_scalar(secret.get_voter_secret())?; + let blinding_basepoint_g2 = voter_secret * *BASEPOINT_G2; let poll_point = bytes_to_point(param.get_poll_point())?; - let blinding_poll_point = vote_secret * poll_point; + let blinding_poll_point = voter_secret * poll_point; let mut request = RegistrationRequest::new(); request .mut_weight_point() @@ -84,7 +84,7 @@ pub fn vote_bounded( let mut vote_value: Vec = Vec::new(); let mut v_weight_rest = response.get_voter_weight() as i64; let poll_point = bytes_to_point(param.get_poll_point())?; - let vote_secret = bytes_to_scalar(secret.get_vote_secret())?; + let vote_secret = bytes_to_scalar(secret.get_voter_secret())?; for choice_keypair in choices.get_choice() { let candidate_address = choice_keypair.get_candidate(); @@ -112,8 +112,8 @@ pub fn vote_bounded( vote_ballot.set_ciphertext2(point_to_bytes(&ciphertext2)); let mut ballot_proof = BallotProof::new(); ballot_proof.set_format_proof(proto_to_bytes(&format_proof)?); - let mut proof_keypair = CandidateBallotProofPair::new(); - proof_keypair.set_candidate(candidate_address.to_string()); + let mut proof_keypair = StringToCandidateBallotProofPair::new(); + proof_keypair.set_key(candidate_address.to_string()); proof_keypair.set_value(ballot_proof); request.mut_ballot_proof().push(proof_keypair); From bdba188836085188f611b3b38c2dc2c13ce6f121 Mon Sep 17 00:00:00 2001 From: HaoXuan40404 <444649358@qq.com> Date: Wed, 1 Sep 2021 11:18:45 +0800 Subject: [PATCH 05/15] remove acv ffi --- Cargo.toml | 1 - ffi/ffi_c/ffi_c_acv/Cargo.toml | 26 ------ ffi/ffi_c/ffi_c_acv/src/coordinator.rs | 107 --------------------- ffi/ffi_c/ffi_c_acv/src/counter.rs | 122 ------------------------ ffi/ffi_c/ffi_c_acv/src/lib.rs | 16 ---- ffi/ffi_c/ffi_c_acv/src/verifier.rs | 123 ------------------------- ffi/ffi_c/ffi_c_acv/src/voter.rs | 6 -- 7 files changed, 401 deletions(-) delete mode 100644 ffi/ffi_c/ffi_c_acv/Cargo.toml delete mode 100644 ffi/ffi_c/ffi_c_acv/src/coordinator.rs delete mode 100644 ffi/ffi_c/ffi_c_acv/src/counter.rs delete mode 100644 ffi/ffi_c/ffi_c_acv/src/lib.rs delete mode 100644 ffi/ffi_c/ffi_c_acv/src/verifier.rs delete mode 100644 ffi/ffi_c/ffi_c_acv/src/voter.rs diff --git a/Cargo.toml b/Cargo.toml index d5ffbd8..d15399f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,6 @@ members = [ "bounty", -# "ffi/ffi_c/ffi_c_acv", "ffi/ffi_c/ffi_c_ktb", "ffi/ffi_c/ffi_c_scd", "ffi/ffi_c/ffi_c_vcl", diff --git a/ffi/ffi_c/ffi_c_acv/Cargo.toml b/ffi/ffi_c/ffi_c_acv/Cargo.toml deleted file mode 100644 index 2b4bd99..0000000 --- a/ffi/ffi_c/ffi_c_acv/Cargo.toml +++ /dev/null @@ -1,26 +0,0 @@ -[package] -name = "ffi_c_abv" -version = "1.5.0" -authors = [ "WeDPR " ] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[lib] -name = "ffi_c_abv" -crate-type = [ "cdylib", "staticlib" ] - -[dependencies] -libc = "0.2.60" -protobuf = "2.22.1" -wedpr_s_anonymous_bounded_voting = { path = "../../../solution/anonymous_ciphertext_voting" } -wedpr_ffi_common = "1.0.0" -wedpr_ffi_macros = "1.0.0" -wedpr_s_protos = { path = "../../../protos"} -wedpr_l_macros = "1.0.0" -wedpr_l_crypto_zkp_utils = "1.1.0" - - -# This is required to generate C/C++ header files. -[build-dependencies] -cbindgen = "0.9.0" diff --git a/ffi/ffi_c/ffi_c_acv/src/coordinator.rs b/ffi/ffi_c/ffi_c_acv/src/coordinator.rs deleted file mode 100644 index 20a836b..0000000 --- a/ffi/ffi_c/ffi_c_acv/src/coordinator.rs +++ /dev/null @@ -1,107 +0,0 @@ -// Copyright 2020 WeDPR Lab Project Authors. Licensed under Apache-2.0. - -//! Library of macros and functions for FFI of a voting coordinator in ABC -//! solution, targeting C/C++ compatible architectures (including iOS). - -// C/C++ FFI: C-style interfaces will be generated. - -use wedpr_s_protos::generated::abv::{CandidateList, CounterSystemParametersStorage, RegistrationRequest, DecryptedResultPartStorage -}; - -use libc::c_char; -use protobuf::{self, Message}; -use std::{ffi::CString, panic, ptr}; -use wedpr_ffi_common::utils::{ - bytes_to_string, c_char_pointer_to_string, string_to_bytes, -}; -use std::os::raw::{c_int, c_long, c_uint}; - - -/// C interface for 'wedpr_abv_make_system_parameters'. -#[no_mangle] -pub extern "C" fn wedpr_abv_make_system_parameters( - candidates_cstring: *mut c_char, - counter_storage_cstring: *mut c_char, -) -> *mut c_char { - let result = panic::catch_unwind(|| { - let candidates = - c_safe_c_char_pointer_to_proto!(candidates_cstring, CandidateList); - - let counter_storage = - c_safe_c_char_pointer_to_proto!(counter_storage_cstring, CounterSystemParametersStorage); - - let system_parameters_storage = - match wedpr_s_anonymous_bounded_voting::coordinator::make_system_parameters( - &candidates, - &counter_storage, - ) { - Ok(v) => v, - Err(_) => return ptr::null_mut(), - }; - c_safe_proto_to_c_char_pointer!(system_parameters_storage) - }); - c_safe_return!(result) -} - -/// C interface for 'wedpr_abv_certify_bounded_voter'. -#[no_mangle] -pub extern "C" fn wedpr_abv_certify_bounded_voter( - secret_key_cstring: *mut c_char, - blank_vote_value: c_uint, - registration_request_cstring: *mut c_char, -) -> *mut c_char { - let result = panic::catch_unwind(|| { - let registration_request = - c_safe_c_char_pointer_to_proto!(registration_request_cstring, RegistrationRequest); - let secret_key = - c_safe_c_char_pointer_to_bytes!(secret_key_cstring); - let value = blank_vote_value as u32; - - let response = - match wedpr_s_anonymous_bounded_voting::coordinator::certify_bounded_voter( - &secret_key, - value, - ®istration_request, - ) { - Ok(v) => v, - Err(_) => return ptr::null_mut(), - }; - c_safe_proto_to_c_char_pointer!(response) - }); - c_safe_return!(result) -} - -/// C interface for 'wedpr_abv_aggregate_decrypted_part_sum'. -#[no_mangle] -pub extern "C" fn wedpr_abv_aggregate_decrypted_part_sum( - param_cstring: *mut c_char, - decrypted_result_part_storage_cstring: *mut c_char, - counting_result_sum_cstring: *mut c_char, -) -> *mut c_char { - let result = panic::catch_unwind(|| { - let param = - c_safe_c_char_pointer_to_proto!(param_cstring, SystemParametersStorage); - - let decrypted_result_part_storage = - c_safe_c_char_pointer_to_proto!(decrypted_result_part_storage_cstring, DecryptedResultPartStorage); - - let mut counting_result_sum = - c_safe_c_char_pointer_to_proto!(counting_result_sum_cstring, DecryptedResultPartStorage); - - - let b_result = - match wedpr_s_anonymous_bounded_voting::coordinator::aggregate_decrypted_part_sum( - ¶m, - &decrypted_result_part_storage, - &mut counting_result_sum, - ) { - Ok(v) => v, - Err(_) => return ptr::null_mut(), - }; - if !b_result { - return ptr::null_mut(); - } - c_safe_proto_to_c_char_pointer!(counting_result_sum) - }); - c_safe_return!(result) -} \ No newline at end of file diff --git a/ffi/ffi_c/ffi_c_acv/src/counter.rs b/ffi/ffi_c/ffi_c_acv/src/counter.rs deleted file mode 100644 index 14909ad..0000000 --- a/ffi/ffi_c/ffi_c_acv/src/counter.rs +++ /dev/null @@ -1,122 +0,0 @@ -// Copyright 2020 WeDPR Lab Project Authors. Licensed under Apache-2.0. - -//! Library of macros and functions for FFI of a counter in ABC -//! solution, targeting C/C++ compatible architectures (including iOS). - -// C/C++ FFI: C-style interfaces will be generated. - -use wedpr_s_protos::generated::abv::{CounterSecret, VoteStorage -}; - -use libc::c_char; -use protobuf::{self, Message}; -use std::{ffi::CString, panic, ptr}; -use wedpr_ffi_common::utils::{ - bytes_to_string, c_char_pointer_to_string, string_to_bytes, -}; -use std::os::raw::c_long; - -/// C interface for 'wedpr_abv_make_counter_secret'. -#[no_mangle] -pub extern "C" fn wedpr_abv_make_counter_secret( -) -> *mut c_char { - let result = panic::catch_unwind(|| { - - let secret = - wedpr_s_anonymous_bounded_voting::counter::make_counter_secret(); - c_safe_proto_to_c_char_pointer!(secret) - }); - c_safe_return!(result) -} - - -/// C interface for 'wedpr_abv_make_system_parameters_share'. -#[no_mangle] -pub extern "C" fn wedpr_abv_make_system_parameters_share( - counter_id_cstring: *mut c_char, - counter_secret_cstring: *mut c_char, -) -> *mut c_char { - let result = panic::catch_unwind(|| { - let counter_id = - c_safe_c_char_pointer_to_string!(counter_id_cstring); - - let counter_secret = - c_safe_c_char_pointer_to_proto!(counter_secret_cstring, CounterSecret); - - let request = - match wedpr_s_anonymous_bounded_voting::counter::make_system_parameters_share( - &counter_id, - &counter_secret, - ) { - Ok(v) => v, - Err(_) => return ptr::null_mut(), - }; - c_safe_proto_to_c_char_pointer!(request) - }); - c_safe_return!(result) -} - -/// C interface for 'wedpr_abv_count'. -#[no_mangle] -pub extern "C" fn wedpr_abv_count( - counter_id_cstring: *mut c_char, - counter_secret_cstring: *mut c_char, - storage_cstring: *mut c_char, -) -> *mut c_char { - let result = panic::catch_unwind(|| { - let counter_id = - c_safe_c_char_pointer_to_string!(counter_id_cstring); - - let counter_secret = - c_safe_c_char_pointer_to_proto!(counter_secret_cstring, CounterSecret); - - let storage = - c_safe_c_char_pointer_to_proto!(storage_cstring, VoteStorage); - - let request = - match wedpr_s_anonymous_bounded_voting::counter::count( - &counter_id, - &counter_secret, - &storage - ) { - Ok(v) => v, - Err(_) => return ptr::null_mut(), - }; - c_safe_proto_to_c_char_pointer!(request) - }); - c_safe_return!(result) -} - -/// C interface for 'wedpr_abv_finalize_vote_result'. -#[no_mangle] -pub extern "C" fn wedpr_abv_finalize_vote_result( - param_cstring: *mut c_char, - vote_sum_cstring: *mut c_char, - counting_result_sum_cstring: *mut c_char, - max_number: c_long, -) -> *mut c_char { - let result = panic::catch_unwind(|| { - - let param = - c_safe_c_char_pointer_to_proto!(param_cstring, SystemParametersStorage); - - let vote_sum = - c_safe_c_char_pointer_to_proto!(vote_sum_cstring, VoteStorage); - - let counting_result_sum = - c_safe_c_char_pointer_to_proto!(counting_result_sum_cstring, DecryptedResultPartStorage); - - let request = - match wedpr_s_anonymous_bounded_voting::counter::finalize_vote_result( - ¶m, - &vote_sum, - &counting_result_sum, - max_number - ) { - Ok(v) => v, - Err(_) => return ptr::null_mut(), - }; - c_safe_proto_to_c_char_pointer!(request) - }); - c_safe_return!(result) -} \ No newline at end of file diff --git a/ffi/ffi_c/ffi_c_acv/src/lib.rs b/ffi/ffi_c/ffi_c_acv/src/lib.rs deleted file mode 100644 index 3578ae2..0000000 --- a/ffi/ffi_c/ffi_c_acv/src/lib.rs +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2020 WeDPR Lab Project Authors. Licensed under Apache-2.0. - -//! Library of macros and functions for FFI of anonymous bounded voting (ABV) solutions, -//! targeting C/C++ compatible architectures (including iOS). - -#[allow(unused_imports)] -#[macro_use] -extern crate wedpr_ffi_macros; - -#[macro_use] -extern crate wedpr_l_macros; - -pub mod coordinator; -pub mod counter; -pub mod verifier; -pub mod voter; \ No newline at end of file diff --git a/ffi/ffi_c/ffi_c_acv/src/verifier.rs b/ffi/ffi_c/ffi_c_acv/src/verifier.rs deleted file mode 100644 index 0c54a4e..0000000 --- a/ffi/ffi_c/ffi_c_acv/src/verifier.rs +++ /dev/null @@ -1,123 +0,0 @@ -// Copyright 2020 WeDPR Lab Project Authors. Licensed under Apache-2.0. - -//! Library of macros and functions for FFI of a verifier in ABC -//! solution, targeting C/C++ compatible architectures (including iOS). - -// C/C++ FFI: C-style interfaces will be generated. - -use wedpr_s_protos::generated::abv::{SystemParametersStorage, VoteStorage -}; - -use libc::c_char; -use protobuf::{self, Message}; -use std::{ffi::CString, panic, ptr}; -use wedpr_ffi_common::utils::{bytes_to_string, c_char_pointer_to_string, string_to_bytes, FAILURE, SUCCESS}; - - -/// C interface for 'wedpr_abv_verify_bounded_vote_request'. -#[no_mangle] -pub extern "C" fn wedpr_abv_verify_bounded_vote_request( - param_cstring: *mut c_char, - request_cstring: *mut c_char, - public_key_cstring: *mut c_char, -) -> i8 { - let result = panic::catch_unwind(|| { - let public_key = - c_safe_c_char_pointer_to_bytes_with_error_value!(public_key_cstring, FAILURE); - - let param = - c_safe_c_char_pointer_to_proto_with_error_value!(param_cstring, SystemParametersStorage, FAILURE); - - let request = - c_safe_c_char_pointer_to_proto_with_error_value!(request_cstring, VoteRequest, FAILURE); - - let b_result = - match wedpr_s_anonymous_bounded_voting::verifier::verify_bounded_vote_request( - ¶m, - &request, - &public_key - ) { - Ok(v) => SUCCESS, - Err(_) => return FAILURE, - }; - b_result - }); - c_safe_return_with_error_value!(result, FAILURE) -} - - -/// C interface for 'wedpr_abv_aggregate_vote_sum_response'. -#[no_mangle] -pub extern "C" fn wedpr_abv_aggregate_vote_sum_response( - param_cstring: *mut c_char, - storage_cstring: *mut c_char, - vote_sum_cstring: *mut c_char, -) -> *mut c_char { - let result = panic::catch_unwind(|| { - - let param = - c_safe_c_char_pointer_to_proto!(param_cstring, SystemParametersStorage); - - let storage = - c_safe_c_char_pointer_to_proto!(storage_cstring, VoteStorage); - - let mut vote_sum = - c_safe_c_char_pointer_to_proto!(vote_sum_cstring, VoteStorage); - - let b_result = - match wedpr_s_anonymous_bounded_voting::verifier::aggregate_vote_sum_response( - ¶m, - &storage, - &mut vote_sum - ) { - Ok(v) => v, - Err(_) => return ptr::null_mut(), - }; - if !b_result { - return ptr::null_mut(); - } - c_safe_proto_to_c_char_pointer!(vote_sum) - }); - c_safe_return!(result) -} - -/// C interface for 'wedpr_abv_verify_count_request'. -#[no_mangle] -pub extern "C" fn wedpr_abv_verify_count_request( - param_cstring: *mut c_char, - encrypted_vote_sum_cstring: *mut c_char, - counter_share_cstring: *mut c_char, - request_cstring: *mut c_char, -) -> i8 { - let result = panic::catch_unwind(|| { - let counter_share_bytes = - c_safe_c_char_pointer_to_bytes_with_error_value!(counter_share_cstring, FAILURE); - - let param = - c_safe_c_char_pointer_to_proto_with_error_value!(param_cstring, SystemParametersStorage, FAILURE); - - let encrypted_vote_sum = - c_safe_c_char_pointer_to_proto_with_error_value!(encrypted_vote_sum_cstring, VoteStorage, FAILURE); - - let request = - c_safe_c_char_pointer_to_proto_with_error_value!(request_cstring, VoteRequest, FAILURE); - - let counter_share = match wedpr_l_crypto_zkp_utils::bytes_to_point(&counter_share_bytes) { - Ok(v) => v, - Err(_) => return FAILURE, - }; - - let b_result = - match wedpr_s_anonymous_bounded_voting::verifier::verify_count_request( - ¶m, - &encrypted_vote_sum, - &counter_share, - &request, - ) { - Ok(v) => SUCCESS, - Err(_) => return FAILURE, - }; - b_result - }); - c_safe_return_with_error_value!(result, FAILURE) -} \ No newline at end of file diff --git a/ffi/ffi_c/ffi_c_acv/src/voter.rs b/ffi/ffi_c/ffi_c_acv/src/voter.rs deleted file mode 100644 index 28e1e71..0000000 --- a/ffi/ffi_c/ffi_c_acv/src/voter.rs +++ /dev/null @@ -1,6 +0,0 @@ -// Copyright 2020 WeDPR Lab Project Authors. Licensed under Apache-2.0. - -//! Library of macros and functions for FFI of a voter in ABC -//! solution, targeting C/C++ compatible architectures (including iOS). - -// C/C++ FFI: C-style interfaces will be generated. \ No newline at end of file From f187bbdc0f24493034ba59486ccbc166df19846f Mon Sep 17 00:00:00 2001 From: julyawang <1090667500@qq.com> Date: Thu, 2 Sep 2021 10:40:53 +0800 Subject: [PATCH 06/15] add comment --- protos/solution/acv/acv.proto | 3 +++ .../anonymous_ciphertext_voting/src/coordinator.rs | 6 +++--- .../anonymous_ciphertext_voting/src/counter.rs | 14 +++++++++++--- .../anonymous_ciphertext_voting/src/verifier.rs | 9 ++++++--- solution/anonymous_ciphertext_voting/src/voter.rs | 11 +++++++++++ .../verifiable_confidential_ledger/src/main.rs | 1 + 6 files changed, 35 insertions(+), 9 deletions(-) diff --git a/protos/solution/acv/acv.proto b/protos/solution/acv/acv.proto index 44ce9fd..225fa7f 100644 --- a/protos/solution/acv/acv.proto +++ b/protos/solution/acv/acv.proto @@ -66,6 +66,7 @@ message VoteStorage { repeated CandidateBallot voted_ballot = 4; } +// system parameters message CandidateList { repeated string candidate = 1; } @@ -75,6 +76,8 @@ message SystemParametersStorage { CandidateList candidates = 2; } + +// proofs message BallotProof { bytes format_proof = 1; } diff --git a/solution/anonymous_ciphertext_voting/src/coordinator.rs b/solution/anonymous_ciphertext_voting/src/coordinator.rs index 6afe70a..549e661 100644 --- a/solution/anonymous_ciphertext_voting/src/coordinator.rs +++ b/solution/anonymous_ciphertext_voting/src/coordinator.rs @@ -15,7 +15,7 @@ use wedpr_s_protos::generated::acv::{ StringToCountingPartPair, SystemParametersStorage, }; -/// Makes system parameters by candidate list and counter storage messages. +/// Makes system parameters containing public key and candidates list using counter storage messages. pub fn make_system_parameters( candidates: &CandidateList, counter_storage: &CounterSystemParametersStorage, @@ -30,7 +30,7 @@ pub fn make_system_parameters( Ok(storage) } -/// Certifies ballot value which voter can vote to all candidates. +/// Certifies voter's weight which indicates the maximum value that the voter can vote totally. pub fn certify_bounded_voter( secret_key: &[u8], value: u32, @@ -64,7 +64,7 @@ pub fn certify_bounded_voter( Ok(response) } -/// Decrypts counters' . +/// Aggregates the decrypted results of all counters, ? pub fn aggregate_decrypted_part_sum( param: &SystemParametersStorage, decrypted_result_part_storage: &DecryptedResultPartStorage, diff --git a/solution/anonymous_ciphertext_voting/src/counter.rs b/solution/anonymous_ciphertext_voting/src/counter.rs index 1a8d879..c154266 100644 --- a/solution/anonymous_ciphertext_voting/src/counter.rs +++ b/solution/anonymous_ciphertext_voting/src/counter.rs @@ -16,6 +16,7 @@ use wedpr_s_protos::generated::acv::{ SystemParametersStorage, VoteResultStorage, VoteStorage, }; +/// Generates a random number as secret key used for making system parameter and counting. pub fn make_counter_secret() -> CounterSecret { let secret_share = get_random_scalar(); CounterSecret { @@ -25,6 +26,8 @@ pub fn make_counter_secret() -> CounterSecret { } } +/// Makes share of system parameter using secret key, +/// where system parameter here means global public key. pub fn make_system_parameters_share( counter_id: &str, counter_secret: &CounterSecret, @@ -40,6 +43,13 @@ pub fn make_system_parameters_share( }) } + +/// Generates intermediate values and zero-knowledge proof for final count, +/// where the intermediate values is the share of ballots received by each candidate, +/// the zero-knowledge proof is equality relationship proof used to prove that +/// counter's count process is correct, specifically refers to that +/// the secret key counter used in counting is equal to the secret key generated +/// for making system parameter. pub fn count( counter_id: &str, secret: &CounterSecret, @@ -88,9 +98,7 @@ pub fn count( Ok(request) } -// In this function, everyone can check anonymousvoting result by c1 - c2r_sum, -// because we already know v and candidates, by using c1 - c2r_sum, we can check -// whether vG_1 =? c1 - c2r_sum. pub fn verify_counter(result_pb: +/// Count the value of ballots received by each candidate. pub fn finalize_vote_result( param: &SystemParametersStorage, vote_sum: &VoteStorage, diff --git a/solution/anonymous_ciphertext_voting/src/verifier.rs b/solution/anonymous_ciphertext_voting/src/verifier.rs index 4a18ee8..81a3ee7 100644 --- a/solution/anonymous_ciphertext_voting/src/verifier.rs +++ b/solution/anonymous_ciphertext_voting/src/verifier.rs @@ -24,6 +24,8 @@ use wedpr_l_protos::{ }; use wedpr_l_utils::traits::{Hash, Signature}; +/// Verifies whether each ballot of voters is correct, +/// specifically refers to the format, the accounting balance and the numerical range of each ballot. pub fn verify_bounded_vote_request( param: &SystemParametersStorage, request: &VoteRequest, @@ -105,6 +107,7 @@ pub fn verify_bounded_vote_request( Ok(true) } +/// ? pub fn aggregate_vote_sum_response( param: &SystemParametersStorage, vote_storage_part: &VoteStorage, @@ -187,6 +190,8 @@ pub fn aggregate_vote_sum_response( Ok(true) } +/// Verifies whether the counting process is correct, +/// specifically refers to that whether each counter used correct secret key when counting. pub fn verify_count_request( param: &SystemParametersStorage, encrypted_vote_sum: &VoteStorage, @@ -244,9 +249,7 @@ pub fn verify_count_request( Ok(true) } -// In this function, everyone can check anonymousvoting result by c1 - c2r_sum, -// because we already know v and candidates, by using c1 - c2r_sum, we can check -// whether vG_1 =? c1 - c2r_sum. pub fn verify_counter(result_pb: +/// Verifies whether the final score of each candidate is correct. pub fn verify_vote_result( param: &SystemParametersStorage, vote_sum: &VoteStorage, diff --git a/solution/anonymous_ciphertext_voting/src/voter.rs b/solution/anonymous_ciphertext_voting/src/voter.rs index 97bbb8e..a1ac0d2 100644 --- a/solution/anonymous_ciphertext_voting/src/voter.rs +++ b/solution/anonymous_ciphertext_voting/src/voter.rs @@ -21,6 +21,7 @@ use wedpr_s_protos::generated::acv::{ VoteChoices, VoteRequest, VoterSecret, }; +/// Generates a random number as secret number for applying blank ballot. pub fn make_voter_secret() -> VoterSecret { let vote_secret = get_random_scalar(); VoterSecret { @@ -30,6 +31,7 @@ pub fn make_voter_secret() -> VoterSecret { } } +/// Applys to the coordinator for blank ballot using own weight and secret number. pub fn make_bounded_registration_request( secret: &VoterSecret, param: &SystemParametersStorage, @@ -48,6 +50,8 @@ pub fn make_bounded_registration_request( Ok(request) } +/// Verifies blank ballot issued by coordinator +/// by recalculating and comparing whether it is consistent. pub fn verify_blank_ballot( request: &RegistrationRequest, response: &RegistrationResponse, @@ -72,6 +76,13 @@ pub fn verify_blank_ballot( && request_ciphertext2 == response_ciphertext2) } +/// Generate a vote request containing ballots for selected candidates, rest ballot +/// and a group of zero-knowledge proofs to prove that ballots is correct, +/// where zero-knowledge proofs contains format proof, balance proof and range proof. +/// The format proof is used to prove that the format of ballots is correct +/// so that it can be counted in the total number of votes when counting, +/// the balance proof is used to prove that poll ballots + the rest ballot = the blank ballot, +/// the range proof is used to prove that the value of ballot is non-negative. pub fn vote_bounded( secret: &VoterSecret, choices: &VoteChoices, diff --git a/solution/verifiable_confidential_ledger/src/main.rs b/solution/verifiable_confidential_ledger/src/main.rs index cbc9555..d9b023d 100644 --- a/solution/verifiable_confidential_ledger/src/main.rs +++ b/solution/verifiable_confidential_ledger/src/main.rs @@ -6,6 +6,7 @@ use colored::*; use std; use wedpr_l_crypto_zkp_utils::point_to_bytes; use wedpr_s_verifiable_confidential_ledger::vcl; +use protobuf::Message; fn main() { print_highlight2( From a739e30a848f88ce32312ee048ea4b54a8316659 Mon Sep 17 00:00:00 2001 From: HaoXuan40404 <444649358@qq.com> Date: Thu, 2 Sep 2021 10:56:22 +0800 Subject: [PATCH 07/15] remove func to coordinato --- .../src/coordinator.rs | 152 +++++++++++++++++- .../src/counter.rs | 69 +------- .../anonymous_ciphertext_voting/src/lib.rs | 16 +- .../src/verifier.rs | 100 ++---------- 4 files changed, 170 insertions(+), 167 deletions(-) diff --git a/solution/anonymous_ciphertext_voting/src/coordinator.rs b/solution/anonymous_ciphertext_voting/src/coordinator.rs index 549e661..3107989 100644 --- a/solution/anonymous_ciphertext_voting/src/coordinator.rs +++ b/solution/anonymous_ciphertext_voting/src/coordinator.rs @@ -2,18 +2,16 @@ //! Library of anonymous ciphertext voting (ACV) solution. -use crate::config::{HASH_KECCAK256, SIGNATURE_SECP256K1}; use curve25519_dalek::{ristretto::RistrettoPoint, scalar::Scalar}; -use wedpr_l_crypto_zkp_utils::{bytes_to_point, point_to_bytes, BASEPOINT_G1}; +use wedpr_l_crypto_zkp_utils::{BASEPOINT_G1, bytes_to_point, point_to_bytes}; use wedpr_l_utils::{ error::WedprError, traits::{Hash, Signature}, }; -use wedpr_s_protos::generated::acv::{ - Ballot, CandidateList, CounterSystemParametersStorage, CountingPart, - DecryptedResultPartStorage, RegistrationRequest, RegistrationResponse, - StringToCountingPartPair, SystemParametersStorage, -}; + +use wedpr_s_protos::generated::acv::{Ballot, CandidateBallot, CandidateList, CounterSystemParametersStorage, CountingPart, DecryptedResultPartStorage, RegistrationRequest, RegistrationResponse, StringToCountingPartPair, StringToInt64Pair, SystemParametersStorage, VoteResultStorage, VoteStorage}; + +use crate::config::{HASH_KECCAK256, SIGNATURE_SECP256K1}; /// Makes system parameters containing public key and candidates list using counter storage messages. pub fn make_system_parameters( @@ -125,3 +123,143 @@ pub fn aggregate_decrypted_part_sum( } Ok(true) } + +/// ? +pub fn aggregate_vote_sum_response( + param: &SystemParametersStorage, + vote_storage_part: &VoteStorage, + vote_sum: &mut VoteStorage, +) -> Result { + if !vote_sum.has_blank_ballot() { + vote_sum + .mut_blank_ballot() + .set_ciphertext1(point_to_bytes(&RistrettoPoint::default())); + vote_sum + .mut_blank_ballot() + .set_ciphertext2(point_to_bytes(&RistrettoPoint::default())); + for candidate in param.get_candidates().get_candidate() { + let mut ballot = Ballot::new(); + ballot.set_ciphertext1(point_to_bytes(&RistrettoPoint::default())); + ballot.set_ciphertext2(point_to_bytes(&RistrettoPoint::default())); + let mut ballot_pair = CandidateBallot::new(); + ballot_pair.set_candidate(candidate.to_string()); + ballot_pair.set_ballot(ballot); + vote_sum.mut_voted_ballot().push(ballot_pair); + } + } + + let mut tmp_vote_storage_sum = VoteStorage::new(); + let mut blank_c1_sum = + bytes_to_point(&vote_sum.get_blank_ballot().get_ciphertext1())?; + let mut blank_c2_sum = + bytes_to_point(&vote_sum.get_blank_ballot().get_ciphertext2())?; + let c1_tmp_point = bytes_to_point( + &vote_storage_part + .get_blank_ballot() + .get_ciphertext1() + .clone(), + )?; + let c2_tmp_point = bytes_to_point( + &vote_storage_part + .get_blank_ballot() + .get_ciphertext2() + .clone(), + )?; + blank_c1_sum += c1_tmp_point; + blank_c2_sum += c2_tmp_point; + + for candidate in param.get_candidates().get_candidate() { + let mut candidate_ballot = Ballot::new(); + for tmp_pair in vote_sum.get_voted_ballot() { + if tmp_pair.get_candidate() == candidate { + candidate_ballot = tmp_pair.get_ballot().clone(); + } + } + let mut candidate_voted_c1_sum = + bytes_to_point(&candidate_ballot.get_ciphertext1())?; + let mut candidate_voted_c2_sum = + bytes_to_point(&candidate_ballot.get_ciphertext2())?; + let mut candidates_ballot = Ballot::new(); + for ballot_pair in vote_storage_part.get_voted_ballot() { + if candidate == ballot_pair.get_candidate() { + candidates_ballot = ballot_pair.get_ballot().clone(); + } + } + candidate_voted_c1_sum += + bytes_to_point(&candidates_ballot.get_ciphertext1())?; + candidate_voted_c2_sum += + bytes_to_point(&candidates_ballot.get_ciphertext2())?; + let mut vote_ballot = Ballot::new(); + vote_ballot.set_ciphertext1(point_to_bytes(&candidate_voted_c1_sum)); + vote_ballot.set_ciphertext2(point_to_bytes(&candidate_voted_c2_sum)); + let mut tmp_pair = CandidateBallot::new(); + tmp_pair.set_candidate(candidate.to_string()); + tmp_pair.set_ballot(vote_ballot); + tmp_vote_storage_sum.mut_voted_ballot().push(tmp_pair); + } + tmp_vote_storage_sum + .mut_blank_ballot() + .set_ciphertext1(point_to_bytes(&blank_c1_sum)); + tmp_vote_storage_sum + .mut_blank_ballot() + .set_ciphertext2(point_to_bytes(&blank_c2_sum)); + *vote_sum = tmp_vote_storage_sum.clone(); + Ok(true) +} + +/// Count the value of ballots received by each candidate. +pub fn finalize_vote_result( + param: &SystemParametersStorage, + vote_sum: &VoteStorage, + counting_result_sum: &DecryptedResultPartStorage, + max_number: i64, +) -> Result { + let mut request = VoteResultStorage::new(); + let blank_c1_sum = + bytes_to_point(vote_sum.get_blank_ballot().get_ciphertext1())?; + let blank_c2_r_sum = + bytes_to_point(counting_result_sum.get_blank_part().get_blinding_c2())?; + let tmp = blank_c1_sum - (blank_c2_r_sum); + for i in 1..=max_number { + let try_num = Scalar::from(i as u64); + if tmp.eq(&(*BASEPOINT_G1 * try_num)) { + let mut tmp_pair = StringToInt64Pair::new(); + tmp_pair.set_key("Wedpr_voting_total_ballots".to_string()); + tmp_pair.set_value(i); + request.mut_result().push(tmp_pair); + break; + } + } + for candidate in param.get_candidates().get_candidate() { + let mut ballot = Ballot::new(); + for tmp_pair in vote_sum.get_voted_ballot() { + if candidate == tmp_pair.get_candidate() { + ballot = tmp_pair.get_ballot().clone(); + } + } + + let mut candidate_counting_part = CountingPart::new(); + for tmp_pair in counting_result_sum.get_candidate_part() { + if candidate == tmp_pair.get_key() { + candidate_counting_part = tmp_pair.get_value().clone(); + } + } + let candidate_c2_r_sum = + bytes_to_point(candidate_counting_part.get_blinding_c2())?; + let tmp = + bytes_to_point(ballot.get_ciphertext1())? - (candidate_c2_r_sum); + + for i in 0..=max_number { + let try_num = Scalar::from(i as u64); + + if tmp.eq(&(*BASEPOINT_G1 * try_num)) { + let mut tmp_pair = StringToInt64Pair::new(); + tmp_pair.set_key(candidate.to_string()); + tmp_pair.set_value(i); + request.mut_result().push(tmp_pair); + break; + } + } + } + Ok(request) +} diff --git a/solution/anonymous_ciphertext_voting/src/counter.rs b/solution/anonymous_ciphertext_voting/src/counter.rs index c154266..f17c036 100644 --- a/solution/anonymous_ciphertext_voting/src/counter.rs +++ b/solution/anonymous_ciphertext_voting/src/counter.rs @@ -2,18 +2,18 @@ //! Library of anonymous ciphertext voting (ACV) solution. -use curve25519_dalek::scalar::Scalar; use wedpr_l_crypto_zkp_discrete_logarithm_proof::prove_equality_relationship_proof; use wedpr_l_crypto_zkp_utils::{ - bytes_to_point, bytes_to_scalar, get_random_scalar, point_to_bytes, - scalar_to_bytes, BASEPOINT_G1, BASEPOINT_G2, + BASEPOINT_G2, bytes_to_point, bytes_to_scalar, + get_random_scalar, point_to_bytes, scalar_to_bytes, }; use wedpr_l_protos::proto_to_bytes; use wedpr_l_utils::error::WedprError; + use wedpr_s_protos::generated::acv::{ - Ballot, CounterSecret, CounterSystemParametersShareRequest, CountingPart, - DecryptedResultPartStorage, StringToCountingPartPair, StringToInt64Pair, - SystemParametersStorage, VoteResultStorage, VoteStorage, + CounterSecret, CounterSystemParametersShareRequest, CountingPart, + DecryptedResultPartStorage, StringToCountingPartPair, + VoteStorage, }; /// Generates a random number as secret key used for making system parameter and counting. @@ -97,60 +97,3 @@ pub fn count( .set_counter_id(counter_id.to_string()); Ok(request) } - -/// Count the value of ballots received by each candidate. -pub fn finalize_vote_result( - param: &SystemParametersStorage, - vote_sum: &VoteStorage, - counting_result_sum: &DecryptedResultPartStorage, - max_number: i64, -) -> Result { - let mut request = VoteResultStorage::new(); - let blank_c1_sum = - bytes_to_point(vote_sum.get_blank_ballot().get_ciphertext1())?; - let blank_c2_r_sum = - bytes_to_point(counting_result_sum.get_blank_part().get_blinding_c2())?; - let tmp = blank_c1_sum - (blank_c2_r_sum); - for i in 1..=max_number { - let try_num = Scalar::from(i as u64); - if tmp.eq(&(*BASEPOINT_G1 * try_num)) { - let mut tmp_pair = StringToInt64Pair::new(); - tmp_pair.set_key("Wedpr_voting_total_ballots".to_string()); - tmp_pair.set_value(i); - request.mut_result().push(tmp_pair); - break; - } - } - for candidate in param.get_candidates().get_candidate() { - let mut ballot = Ballot::new(); - for tmp_pair in vote_sum.get_voted_ballot() { - if candidate == tmp_pair.get_candidate() { - ballot = tmp_pair.get_ballot().clone(); - } - } - - let mut candidate_counting_part = CountingPart::new(); - for tmp_pair in counting_result_sum.get_candidate_part() { - if candidate == tmp_pair.get_key() { - candidate_counting_part = tmp_pair.get_value().clone(); - } - } - let candidate_c2_r_sum = - bytes_to_point(candidate_counting_part.get_blinding_c2())?; - let tmp = - bytes_to_point(ballot.get_ciphertext1())? - (candidate_c2_r_sum); - - for i in 0..=max_number { - let try_num = Scalar::from(i as u64); - - if tmp.eq(&(*BASEPOINT_G1 * try_num)) { - let mut tmp_pair = StringToInt64Pair::new(); - tmp_pair.set_key(candidate.to_string()); - tmp_pair.set_value(i); - request.mut_result().push(tmp_pair); - break; - } - } - } - Ok(request) -} diff --git a/solution/anonymous_ciphertext_voting/src/lib.rs b/solution/anonymous_ciphertext_voting/src/lib.rs index b6ee48d..a86b747 100644 --- a/solution/anonymous_ciphertext_voting/src/lib.rs +++ b/solution/anonymous_ciphertext_voting/src/lib.rs @@ -16,16 +16,20 @@ pub mod voter; #[cfg(test)] mod tests { - use super::*; - use crate::config::SIGNATURE_SECP256K1; use wedpr_l_crypto_zkp_utils::bytes_to_point; use wedpr_l_utils::traits::Signature; + use wedpr_s_protos::generated::acv::{ CandidateList, CounterSecret, CounterSystemParametersStorage, - DecryptedResultPartStorage, VoteChoice, VoteChoices, VoteStorage, - VoterSecret, + DecryptedResultPartStorage, VoteChoice, VoteChoices, VoterSecret, + VoteStorage, }; + use crate::config::SIGNATURE_SECP256K1; + use crate::coordinator; + + use super::*; + #[test] fn test_bounded_voting() { // Generate coordinator's key pair @@ -125,7 +129,7 @@ mod tests { ); assert_eq!( true, - verifier::aggregate_vote_sum_response( + coordinator::aggregate_vote_sum_response( &system_parameters, &vote_request.get_vote(), &mut encrypted_vote_sum @@ -169,7 +173,7 @@ mod tests { .unwrap() ); } - let final_result_request = counter::finalize_vote_result( + let final_result_request = coordinator::finalize_vote_result( &system_parameters, &encrypted_vote_sum, &vote_sum_total, diff --git a/solution/anonymous_ciphertext_voting/src/verifier.rs b/solution/anonymous_ciphertext_voting/src/verifier.rs index 81a3ee7..58ff755 100644 --- a/solution/anonymous_ciphertext_voting/src/verifier.rs +++ b/solution/anonymous_ciphertext_voting/src/verifier.rs @@ -2,13 +2,6 @@ //! Library of anonymous ciphertext voting (ACV) solution. -use wedpr_l_utils::error::WedprError; -use wedpr_s_protos::generated::acv::{ - Ballot, CandidateBallot, CountingPart, DecryptedResultPartStorage, - VoteResultStorage, VoteStorage,SystemParametersStorage, VoteRequest -}; - -use crate::config::{HASH_KECCAK256, SIGNATURE_SECP256K1}; use curve25519_dalek::{ristretto::RistrettoPoint, scalar::Scalar}; use wedpr_l_crypto_zkp_discrete_logarithm_proof::{ verify_equality_relationship_proof, verify_format_proof, @@ -16,14 +9,22 @@ use wedpr_l_crypto_zkp_discrete_logarithm_proof::{ }; use wedpr_l_crypto_zkp_range_proof::verify_value_range_in_batch; use wedpr_l_crypto_zkp_utils::{ - bytes_to_point, point_to_bytes, BASEPOINT_G1, BASEPOINT_G2, + BASEPOINT_G1, BASEPOINT_G2, bytes_to_point, }; use wedpr_l_protos::{ bytes_to_proto, generated::zkp::{BalanceProof, EqualityProof}, }; +use wedpr_l_utils::error::WedprError; use wedpr_l_utils::traits::{Hash, Signature}; +use wedpr_s_protos::generated::acv::{ + Ballot, CountingPart, DecryptedResultPartStorage, + SystemParametersStorage, VoteRequest, VoteResultStorage, VoteStorage +}; + +use crate::config::{HASH_KECCAK256, SIGNATURE_SECP256K1}; + /// Verifies whether each ballot of voters is correct, /// specifically refers to the format, the accounting balance and the numerical range of each ballot. pub fn verify_bounded_vote_request( @@ -107,89 +108,6 @@ pub fn verify_bounded_vote_request( Ok(true) } -/// ? -pub fn aggregate_vote_sum_response( - param: &SystemParametersStorage, - vote_storage_part: &VoteStorage, - vote_sum: &mut VoteStorage, -) -> Result { - if !vote_sum.has_blank_ballot() { - vote_sum - .mut_blank_ballot() - .set_ciphertext1(point_to_bytes(&RistrettoPoint::default())); - vote_sum - .mut_blank_ballot() - .set_ciphertext2(point_to_bytes(&RistrettoPoint::default())); - for candidate in param.get_candidates().get_candidate() { - let mut ballot = Ballot::new(); - ballot.set_ciphertext1(point_to_bytes(&RistrettoPoint::default())); - ballot.set_ciphertext2(point_to_bytes(&RistrettoPoint::default())); - let mut ballot_pair = CandidateBallot::new(); - ballot_pair.set_candidate(candidate.to_string()); - ballot_pair.set_ballot(ballot); - vote_sum.mut_voted_ballot().push(ballot_pair); - } - } - - let mut tmp_vote_storage_sum = VoteStorage::new(); - let mut blank_c1_sum = - bytes_to_point(&vote_sum.get_blank_ballot().get_ciphertext1())?; - let mut blank_c2_sum = - bytes_to_point(&vote_sum.get_blank_ballot().get_ciphertext2())?; - let c1_tmp_point = bytes_to_point( - &vote_storage_part - .get_blank_ballot() - .get_ciphertext1() - .clone(), - )?; - let c2_tmp_point = bytes_to_point( - &vote_storage_part - .get_blank_ballot() - .get_ciphertext2() - .clone(), - )?; - blank_c1_sum += c1_tmp_point; - blank_c2_sum += c2_tmp_point; - - for candidate in param.get_candidates().get_candidate() { - let mut candidate_ballot = Ballot::new(); - for tmp_pair in vote_sum.get_voted_ballot() { - if tmp_pair.get_candidate() == candidate { - candidate_ballot = tmp_pair.get_ballot().clone(); - } - } - let mut candidate_voted_c1_sum = - bytes_to_point(&candidate_ballot.get_ciphertext1())?; - let mut candidate_voted_c2_sum = - bytes_to_point(&candidate_ballot.get_ciphertext2())?; - let mut candidates_ballot = Ballot::new(); - for ballot_pair in vote_storage_part.get_voted_ballot() { - if candidate == ballot_pair.get_candidate() { - candidates_ballot = ballot_pair.get_ballot().clone(); - } - } - candidate_voted_c1_sum += - bytes_to_point(&candidates_ballot.get_ciphertext1())?; - candidate_voted_c2_sum += - bytes_to_point(&candidates_ballot.get_ciphertext2())?; - let mut vote_ballot = Ballot::new(); - vote_ballot.set_ciphertext1(point_to_bytes(&candidate_voted_c1_sum)); - vote_ballot.set_ciphertext2(point_to_bytes(&candidate_voted_c2_sum)); - let mut tmp_pair = CandidateBallot::new(); - tmp_pair.set_candidate(candidate.to_string()); - tmp_pair.set_ballot(vote_ballot); - tmp_vote_storage_sum.mut_voted_ballot().push(tmp_pair); - } - tmp_vote_storage_sum - .mut_blank_ballot() - .set_ciphertext1(point_to_bytes(&blank_c1_sum)); - tmp_vote_storage_sum - .mut_blank_ballot() - .set_ciphertext2(point_to_bytes(&blank_c2_sum)); - *vote_sum = tmp_vote_storage_sum.clone(); - Ok(true) -} - /// Verifies whether the counting process is correct, /// specifically refers to that whether each counter used correct secret key when counting. pub fn verify_count_request( From 82574396dfde82ac322275cff4efb255c4f214a0 Mon Sep 17 00:00:00 2001 From: julyawang <1090667500@qq.com> Date: Fri, 3 Sep 2021 11:13:09 +0800 Subject: [PATCH 08/15] fix comment --- bounty/Cargo.toml | 11 +- ffi/ffi_c/ffi_c_ktb/Cargo.toml | 7 +- ffi/ffi_c/ffi_c_scd/Cargo.toml | 5 +- ffi/ffi_c/ffi_c_vcl/Cargo.toml | 7 +- ffi/ffi_java/ffi_java_ktb/Cargo.toml | 4 +- ffi/ffi_java/ffi_java_scd/Cargo.toml | 5 +- ffi/ffi_java/ffi_java_vcl/Cargo.toml | 7 +- protos/Cargo.toml | 1 - protos/solution/acv/acv.proto | 88 ++++++----- protos/src/generated/acv.rs | 2 + protos/src/generated/scd.rs | 2 + protos/src/generated/vcl.rs | 2 + .../anonymous_ciphertext_voting/Cargo.toml | 14 +- .../src/coordinator.rs | 148 ++++++++++-------- .../src/counter.rs | 19 ++- .../anonymous_ciphertext_voting/src/lib.rs | 7 +- .../src/verifier.rs | 35 +++-- .../anonymous_ciphertext_voting/src/voter.rs | 25 +-- .../hierarchical_deterministic_key/Cargo.toml | 11 +- .../Cargo.toml | 5 +- .../verifiable_confidential_ledger/Cargo.toml | 15 +- .../src/main.rs | 2 +- 22 files changed, 234 insertions(+), 188 deletions(-) diff --git a/bounty/Cargo.toml b/bounty/Cargo.toml index fc8cd2e..34e8794 100644 --- a/bounty/Cargo.toml +++ b/bounty/Cargo.toml @@ -10,17 +10,18 @@ edition = "2018" colored = "1.8" curve25519-dalek = { version = "1", features = [ "serde" ] } protobuf = "2.22.1" -sha3 = "0.8" rand = "0.3.17" +sha3 = "0.8" wedpr_l_crypto_zkp_discrete_logarithm_proof = "1.0.0" -wedpr_l_crypto_zkp_range_proof = { git = "https://github.com/WeBankBlockchain/WeDPR-Lab-Crypto", branch = "main" } +wedpr_l_crypto_zkp_range_proof = { git = "https://github.com/WeBankBlockchain/WeDPR-Lab-Crypto", branch = "main" } +wedpr_l_crypto_zkp_utils = "1.0.0" wedpr_l_macros = "1.0.0" -wedpr_s_protos = "1.3.0" wedpr_l_protos = "1.0.0" wedpr_l_utils = "1.0.0" -wedpr_l_crypto_zkp_utils = "1.0.0" -wedpr_s_verifiable_confidential_ledger = { path = "../solution/verifiable_confidential_ledger"} +wedpr_s_protos = "1.3.0" wedpr_s_selective_certificate_disclosure = "1.3.0" +wedpr_s_verifiable_confidential_ledger = { path = "../solution/verifiable_confidential_ledger" } + [dev-dependencies] wedpr_l_common_coder_base64 = "1.0.0" diff --git a/ffi/ffi_c/ffi_c_ktb/Cargo.toml b/ffi/ffi_c/ffi_c_ktb/Cargo.toml index a7f3703..2956017 100644 --- a/ffi/ffi_c/ffi_c_ktb/Cargo.toml +++ b/ffi/ffi_c/ffi_c_ktb/Cargo.toml @@ -13,13 +13,14 @@ crate-type = [ "cdylib", "staticlib" ] [dependencies] libc = "0.2.60" protobuf = "2.22.1" -wedpr_s_hierarchical_deterministic_key = "1.3.0" wedpr_ffi_common = "1.0.0" wedpr_ffi_macros = "1.0.0" -wedpr_s_protos = "1.3.0" wedpr_l_macros = "1.0.0" # This is required to generate C/C++ header files. +wedpr_s_hierarchical_deterministic_key = "1.3.0" +wedpr_s_protos = "1.3.0" + [build-dependencies] -cbindgen = "0.9.0" \ No newline at end of file +cbindgen = "0.9.0" diff --git a/ffi/ffi_c/ffi_c_scd/Cargo.toml b/ffi/ffi_c/ffi_c_scd/Cargo.toml index 6574f25..6f86ea2 100644 --- a/ffi/ffi_c/ffi_c_scd/Cargo.toml +++ b/ffi/ffi_c/ffi_c_scd/Cargo.toml @@ -13,12 +13,13 @@ crate-type = [ "cdylib", "staticlib" ] [dependencies] libc = "0.2.60" protobuf = "2.22.1" -wedpr_s_selective_certificate_disclosure = "1.3.0" wedpr_ffi_common = "1.0.0" wedpr_ffi_macros = "1.0.0" -wedpr_s_protos = "1.3.0" wedpr_l_macros = "1.0.0" # This is required to generate C/C++ header files. +wedpr_s_protos = "1.3.0" +wedpr_s_selective_certificate_disclosure = "1.3.0" + [build-dependencies] cbindgen = "0.9.0" diff --git a/ffi/ffi_c/ffi_c_vcl/Cargo.toml b/ffi/ffi_c/ffi_c_vcl/Cargo.toml index aab8e70..c505866 100644 --- a/ffi/ffi_c/ffi_c_vcl/Cargo.toml +++ b/ffi/ffi_c/ffi_c_vcl/Cargo.toml @@ -13,13 +13,14 @@ crate-type = [ "cdylib", "staticlib" ] [dependencies] libc = "0.2.60" protobuf = "2.22.1" -wedpr_s_verifiable_confidential_ledger = { path = "../../../solution/verifiable_confidential_ledger"} wedpr_ffi_common = "1.0.0" wedpr_ffi_macros = "1.1.0" -wedpr_s_protos = { path = "../../../protos"} -wedpr_l_protos = "1.1.0" wedpr_l_macros = "1.0.0" # This is required to generate C/C++ header files. +wedpr_l_protos = "1.1.0" +wedpr_s_protos = { path = "../../../protos" } +wedpr_s_verifiable_confidential_ledger = { path = "../../../solution/verifiable_confidential_ledger" } + [build-dependencies] cbindgen = "0.9.0" diff --git a/ffi/ffi_java/ffi_java_ktb/Cargo.toml b/ffi/ffi_java/ffi_java_ktb/Cargo.toml index 1ceb186..db0d342 100644 --- a/ffi/ffi_java/ffi_java_ktb/Cargo.toml +++ b/ffi/ffi_java/ffi_java_ktb/Cargo.toml @@ -13,13 +13,13 @@ crate-type = [ "cdylib", "staticlib" ] [dependencies] jni = "0.13.0" protobuf = "2.22.1" -wedpr_s_hierarchical_deterministic_key = "1.3.0" wedpr_ffi_common = "1.1.0" wedpr_ffi_macros = "1.1.0" +wedpr_s_hierarchical_deterministic_key = "1.3.0" wedpr_s_protos = "1.3.0" [build-dependencies] cbindgen = "0.9.0" [target.'cfg(target_os = "android")'.dependencies] -jni = { version = "0.13.1", default-features = false } \ No newline at end of file +jni = { version = "0.13.1", default-features = false } diff --git a/ffi/ffi_java/ffi_java_scd/Cargo.toml b/ffi/ffi_java/ffi_java_scd/Cargo.toml index 2398603..ee2754b 100644 --- a/ffi/ffi_java/ffi_java_scd/Cargo.toml +++ b/ffi/ffi_java/ffi_java_scd/Cargo.toml @@ -12,12 +12,13 @@ crate-type = [ "cdylib" ] [dependencies] jni = "0.13.0" protobuf = "2.22.1" -wedpr_s_selective_certificate_disclosure = "1.3.0" wedpr_ffi_common = "1.0.0" wedpr_ffi_macros = "1.0.0" -wedpr_s_protos = "1.3.0" wedpr_l_protos = "1.0.0" +wedpr_s_protos = "1.3.0" +wedpr_s_selective_certificate_disclosure = "1.3.0" + [build-dependencies] cbindgen = "0.9.0" diff --git a/ffi/ffi_java/ffi_java_vcl/Cargo.toml b/ffi/ffi_java/ffi_java_vcl/Cargo.toml index 2eeab4a..1b6c84d 100644 --- a/ffi/ffi_java/ffi_java_vcl/Cargo.toml +++ b/ffi/ffi_java/ffi_java_vcl/Cargo.toml @@ -13,11 +13,12 @@ crate-type = [ "cdylib", "staticlib" ] [dependencies] jni = "0.13.0" protobuf = "2.22.1" -wedpr_s_verifiable_confidential_ledger = { path = "../../../solution/verifiable_confidential_ledger"} wedpr_ffi_common = "1.1.0" wedpr_ffi_macros = "1.1.0" -wedpr_s_protos = { path = "../../../protos"} -wedpr_l_protos = "1.1.0" +wedpr_l_protos = "1.1.0" + +wedpr_s_protos = { path = "../../../protos" } +wedpr_s_verifiable_confidential_ledger = { path = "../../../solution/verifiable_confidential_ledger" } [build-dependencies] cbindgen = "0.9.0" diff --git a/protos/Cargo.toml b/protos/Cargo.toml index 2689d89..6f7b6f2 100644 --- a/protos/Cargo.toml +++ b/protos/Cargo.toml @@ -11,4 +11,3 @@ description = "Library of WeDPR protobuf definitions and their generated code." [dependencies] protobuf = "2.22.1" protoc-rust = "2.22.1" - diff --git a/protos/solution/acv/acv.proto b/protos/solution/acv/acv.proto index 225fa7f..f32e5f3 100644 --- a/protos/solution/acv/acv.proto +++ b/protos/solution/acv/acv.proto @@ -6,88 +6,93 @@ package com.webank.wedpr.acv.proto; option java_package = "com.webank.wedpr.acv.proto"; option java_multiple_files = true; -// Counter Secret value -message CounterSecret { - bytes poll_secret_share = 1; +// Candidate list. +message CandidateList { + repeated string candidate = 1; } -message CounterSystemParametersShareRequest { - string counter_id = 1; - bytes poll_point_share = 2; +// System parameters. +message SystemParametersStorage { + bytes poll_point = 1; + CandidateList candidates = 2; } -message CounterSystemParametersStorage { - repeated CounterSystemParametersShareRequest counter_parameters_request = 1; +// Counter's secret value. +message CounterSecret { + bytes poll_secret_share = 1; } -// Voter Secret value +// Voter's secret value. message VoterSecret { bytes voter_secret = 1; } +// Request of voter's registration. message RegistrationRequest { RegistrationBlindingPoint weight_point = 1; } +// delete? message RegistrationBlindingPoint { bytes blinding_poll_point = 1; bytes blinding_basepoint_g2 = 2; } +// Response of coordinator for voter's registration. message RegistrationResponse { uint32 voter_weight = 1; Ballot ballot = 2; bytes signature = 3; } +// Ciphertext ballot. message Ballot { bytes ciphertext1 = 1; bytes ciphertext2 = 2; } + +// Request of generating system parameter from a counter. +message CounterSystemParametersShareRequest { + string counter_id = 1; + bytes poll_point_share = 2; +} + +// Requests of generating system parameter from all counters. +message CounterSystemParametersStorage { + repeated CounterSystemParametersShareRequest counter_parameters_request = 1; +} + +// Choice of ballot casting for each candidate. message VoteChoice { string candidate = 1; uint32 value = 2; } +// Choices for all candidate. message VoteChoices { repeated VoteChoice choice = 1; } +// Ciphertext ballot for each candidate. message CandidateBallot { string candidate = 1; Ballot ballot = 2; } -message VoteStorage { - bytes signature = 1; - Ballot blank_ballot = 2; - Ballot rest_ballot = 3; - repeated CandidateBallot voted_ballot = 4; -} - -// system parameters -message CandidateList { - repeated string candidate = 1; -} - -message SystemParametersStorage { - bytes poll_point = 1; - CandidateList candidates = 2; -} - - -// proofs +// ZKP data to verify the format of ciphertext ballot. message BallotProof { bytes format_proof = 1; } +// Pair of candidate index and the ballot proof he received. message StringToCandidateBallotProofPair { string key = 1; BallotProof value = 2; } // Do not use Map, cause unordered in blockchain +// Request of polling for all candidates. message VoteRequest { VoteStorage vote = 1; repeated StringToCandidateBallotProofPair ballot_proof = 2; @@ -95,26 +100,39 @@ message VoteRequest { bytes sum_balance_proof = 4; } -message DecryptedResultPartStorage { - CountingPart blank_part = 1; - repeated StringToCountingPartPair candidate_part = 2; +// Polling for each candidates. +message VoteStorage { + bytes signature = 1; + Ballot blank_ballot = 2; + Ballot rest_ballot = 3; + repeated CandidateBallot voted_ballot = 4; +} + +// Decrypted ballot and ZKP data to verify the process of counting of each counter. +message CountingPart { + string counter_id = 1; + bytes blinding_c2 = 2; + bytes equality_proof = 3; } +// Pair of candidate index and the decrypted ballot he received. message StringToCountingPartPair { string key = 1; CountingPart value = 2; } -message CountingPart { - string counter_id = 1; - bytes blinding_c2 = 2; - bytes equality_proof = 3; +// Decrypted ballot and ZKP data to verify the process of counting of all counters. +message DecryptedResultPartStorage { + CountingPart blank_part = 1; + repeated StringToCountingPartPair candidate_part = 2; } +// Final result of all candidates. message VoteResultStorage { repeated StringToInt64Pair result = 1; } +// Final result of each candidate. message StringToInt64Pair { string key = 1; int64 value = 2; diff --git a/protos/src/generated/acv.rs b/protos/src/generated/acv.rs index 9b8ab6c..329ba2d 100644 --- a/protos/src/generated/acv.rs +++ b/protos/src/generated/acv.rs @@ -1,3 +1,5 @@ +// Copyright 2020 WeDPR Lab Project Authors. Licensed under Apache-2.0. + // This file is generated by rust-protobuf 2.25.1. Do not edit // @generated diff --git a/protos/src/generated/scd.rs b/protos/src/generated/scd.rs index 98ac0d6..f02bf66 100644 --- a/protos/src/generated/scd.rs +++ b/protos/src/generated/scd.rs @@ -1,3 +1,5 @@ +// Copyright 2020 WeDPR Lab Project Authors. Licensed under Apache-2.0. + // This file is generated by rust-protobuf 2.25.1. Do not edit // @generated diff --git a/protos/src/generated/vcl.rs b/protos/src/generated/vcl.rs index dae04f6..54c9de9 100644 --- a/protos/src/generated/vcl.rs +++ b/protos/src/generated/vcl.rs @@ -1,3 +1,5 @@ +// Copyright 2020 WeDPR Lab Project Authors. Licensed under Apache-2.0. + // This file is generated by rust-protobuf 2.25.1. Do not edit // @generated diff --git a/solution/anonymous_ciphertext_voting/Cargo.toml b/solution/anonymous_ciphertext_voting/Cargo.toml index f54ccdc..0247840 100644 --- a/solution/anonymous_ciphertext_voting/Cargo.toml +++ b/solution/anonymous_ciphertext_voting/Cargo.toml @@ -9,14 +9,14 @@ 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] -wedpr_l_macros = "1.0.0" -wedpr_l_utils = "1.1.0" -wedpr_l_crypto_zkp_discrete_logarithm_proof = { git = "https://github.com/WeBankBlockchain/WeDPR-Lab-Crypto.git", branch = "release-1.2.0" } -wedpr_s_protos = { path = "../../protos"} -wedpr_l_protos = { git = "https://github.com/WeBankBlockchain/WeDPR-Lab-Crypto.git", branch = "release-1.2.0" } curve25519-dalek = { version = "1", features = [ "serde" ] } -wedpr_l_crypto_zkp_utils = { git = "https://github.com/WeBankBlockchain/WeDPR-Lab-Crypto.git", branch = "release-1.2.0" } -wedpr_l_crypto_signature_secp256k1 = { git = "https://github.com/WeBankBlockchain/WeDPR-Lab-Crypto.git", branch = "release-1.2.0" } lazy_static = "1.4.0" wedpr_l_crypto_hash_keccak256 = { git = "https://github.com/WeBankBlockchain/WeDPR-Lab-Crypto.git", branch = "release-1.2.0" } +wedpr_l_crypto_signature_secp256k1 = { git = "https://github.com/WeBankBlockchain/WeDPR-Lab-Crypto.git", branch = "release-1.2.0" } +wedpr_l_crypto_zkp_discrete_logarithm_proof = { git = "https://github.com/WeBankBlockchain/WeDPR-Lab-Crypto.git", branch = "release-1.2.0" } wedpr_l_crypto_zkp_range_proof = { git = "https://github.com/WeBankBlockchain/WeDPR-Lab-Crypto.git", branch = "release-1.2.0" } +wedpr_l_crypto_zkp_utils = { git = "https://github.com/WeBankBlockchain/WeDPR-Lab-Crypto.git", branch = "release-1.2.0" } +wedpr_l_macros = "1.0.0" +wedpr_l_protos = { git = "https://github.com/WeBankBlockchain/WeDPR-Lab-Crypto.git", branch = "release-1.2.0" } +wedpr_l_utils = "1.1.0" +wedpr_s_protos = { path = "../../protos" } diff --git a/solution/anonymous_ciphertext_voting/src/coordinator.rs b/solution/anonymous_ciphertext_voting/src/coordinator.rs index 3107989..4f1a9b1 100644 --- a/solution/anonymous_ciphertext_voting/src/coordinator.rs +++ b/solution/anonymous_ciphertext_voting/src/coordinator.rs @@ -3,17 +3,23 @@ //! Library of anonymous ciphertext voting (ACV) solution. use curve25519_dalek::{ristretto::RistrettoPoint, scalar::Scalar}; -use wedpr_l_crypto_zkp_utils::{BASEPOINT_G1, bytes_to_point, point_to_bytes}; +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_s_protos::generated::acv::{Ballot, CandidateBallot, CandidateList, CounterSystemParametersStorage, CountingPart, DecryptedResultPartStorage, RegistrationRequest, RegistrationResponse, StringToCountingPartPair, StringToInt64Pair, SystemParametersStorage, VoteResultStorage, VoteStorage}; +use wedpr_s_protos::generated::acv::{ + Ballot, CandidateBallot, CandidateList, CounterSystemParametersStorage, + CountingPart, DecryptedResultPartStorage, RegistrationRequest, + RegistrationResponse, StringToCountingPartPair, StringToInt64Pair, + SystemParametersStorage, VoteResultStorage, VoteStorage, +}; use crate::config::{HASH_KECCAK256, SIGNATURE_SECP256K1}; -/// Makes system parameters containing public key and candidates list using counter storage messages. +/// Makes system parameters containing public key and candidates list using +/// counter storage messages. pub fn make_system_parameters( candidates: &CandidateList, counter_storage: &CounterSystemParametersStorage, @@ -28,13 +34,13 @@ pub fn make_system_parameters( Ok(storage) } -/// Certifies voter's weight which indicates the maximum value that the voter can vote totally. +/// Certifies voter's weight which indicates the maximum value that the voter +/// can vote in total. pub fn certify_bounded_voter( secret_key: &[u8], value: u32, registration_request: &RegistrationRequest, ) -> Result { - let blinding_poll_point = bytes_to_point( registration_request .get_weight_point() @@ -62,69 +68,7 @@ pub fn certify_bounded_voter( Ok(response) } -/// Aggregates the decrypted results of all counters, ? -pub fn aggregate_decrypted_part_sum( - param: &SystemParametersStorage, - decrypted_result_part_storage: &DecryptedResultPartStorage, - counting_result_sum: &mut DecryptedResultPartStorage, -) -> Result { - if !counting_result_sum.has_blank_part() { - counting_result_sum - .mut_blank_part() - .set_counter_id("default".to_string()); - counting_result_sum - .mut_blank_part() - .set_blinding_c2(point_to_bytes(&RistrettoPoint::default())); - for candidate in param.get_candidates().get_candidate() { - let mut counting_part = CountingPart::new(); - counting_part.set_blinding_c2(point_to_bytes(&RistrettoPoint::default())); - let mut tmp_pair = StringToCountingPartPair::new(); - tmp_pair.set_key(candidate.to_string()); - tmp_pair.set_value(counting_part); - counting_result_sum.mut_candidate_part().push(tmp_pair); - } - } - let mut blank_c2_r_sum = - bytes_to_point(&counting_result_sum.get_blank_part().get_blinding_c2())?; - let blank_part_share = bytes_to_point( - &decrypted_result_part_storage.get_blank_part().get_blinding_c2(), - )?; - - blank_c2_r_sum += blank_part_share; - counting_result_sum - .mut_blank_part() - .set_blinding_c2(point_to_bytes(&blank_c2_r_sum)); - for candidate in param.get_candidates().get_candidate() { - let mut candidate_counting_part = CountingPart::new(); - for tmp_pair in counting_result_sum.get_candidate_part() { - if candidate == tmp_pair.get_key() { - candidate_counting_part = tmp_pair.get_value().clone(); - } - } - - let mut candidate_c2_r_sum = - bytes_to_point(&candidate_counting_part.get_blinding_c2())?; - - let mut counting_part = CountingPart::new(); - for tmp_pair in decrypted_result_part_storage.get_candidate_part() { - if candidate == tmp_pair.get_key() { - counting_part = tmp_pair.get_value().clone(); - } - } - - let candidate_c2_r = bytes_to_point(&counting_part.get_blinding_c2())?; - candidate_c2_r_sum += candidate_c2_r; - let mut candidate_part = CountingPart::new(); - candidate_part.set_blinding_c2(point_to_bytes(&candidate_c2_r_sum)); - let mut tmp_pair = StringToCountingPartPair::new(); - tmp_pair.set_key(candidate.to_string()); - tmp_pair.set_value(candidate_part); - counting_result_sum.mut_candidate_part().push(tmp_pair); - } - Ok(true) -} - -/// ? +/// Aggregates anonymous ciphertext ballot from all voters for each candidate. pub fn aggregate_vote_sum_response( param: &SystemParametersStorage, vote_storage_part: &VoteStorage, @@ -207,7 +151,73 @@ pub fn aggregate_vote_sum_response( Ok(true) } -/// Count the value of ballots received by each candidate. +/// Aggregates decrypted ballot from all counters for each candidate. +pub fn aggregate_decrypted_part_sum( + param: &SystemParametersStorage, + decrypted_result_part_storage: &DecryptedResultPartStorage, + counting_result_sum: &mut DecryptedResultPartStorage, +) -> Result { + if !counting_result_sum.has_blank_part() { + counting_result_sum + .mut_blank_part() + .set_counter_id("default".to_string()); + counting_result_sum + .mut_blank_part() + .set_blinding_c2(point_to_bytes(&RistrettoPoint::default())); + for candidate in param.get_candidates().get_candidate() { + let mut counting_part = CountingPart::new(); + counting_part + .set_blinding_c2(point_to_bytes(&RistrettoPoint::default())); + let mut tmp_pair = StringToCountingPartPair::new(); + tmp_pair.set_key(candidate.to_string()); + tmp_pair.set_value(counting_part); + counting_result_sum.mut_candidate_part().push(tmp_pair); + } + } + let mut blank_c2_r_sum = bytes_to_point( + &counting_result_sum.get_blank_part().get_blinding_c2(), + )?; + let blank_part_share = bytes_to_point( + &decrypted_result_part_storage + .get_blank_part() + .get_blinding_c2(), + )?; + + blank_c2_r_sum += blank_part_share; + counting_result_sum + .mut_blank_part() + .set_blinding_c2(point_to_bytes(&blank_c2_r_sum)); + for candidate in param.get_candidates().get_candidate() { + let mut candidate_counting_part = CountingPart::new(); + for tmp_pair in counting_result_sum.get_candidate_part() { + if candidate == tmp_pair.get_key() { + candidate_counting_part = tmp_pair.get_value().clone(); + } + } + + let mut candidate_c2_r_sum = + bytes_to_point(&candidate_counting_part.get_blinding_c2())?; + + let mut counting_part = CountingPart::new(); + for tmp_pair in decrypted_result_part_storage.get_candidate_part() { + if candidate == tmp_pair.get_key() { + counting_part = tmp_pair.get_value().clone(); + } + } + + let candidate_c2_r = bytes_to_point(&counting_part.get_blinding_c2())?; + candidate_c2_r_sum += candidate_c2_r; + let mut candidate_part = CountingPart::new(); + candidate_part.set_blinding_c2(point_to_bytes(&candidate_c2_r_sum)); + let mut tmp_pair = StringToCountingPartPair::new(); + tmp_pair.set_key(candidate.to_string()); + tmp_pair.set_value(candidate_part); + counting_result_sum.mut_candidate_part().push(tmp_pair); + } + Ok(true) +} + +/// Count the final result of ballots received by each candidate. pub fn finalize_vote_result( param: &SystemParametersStorage, vote_sum: &VoteStorage, diff --git a/solution/anonymous_ciphertext_voting/src/counter.rs b/solution/anonymous_ciphertext_voting/src/counter.rs index f17c036..6451866 100644 --- a/solution/anonymous_ciphertext_voting/src/counter.rs +++ b/solution/anonymous_ciphertext_voting/src/counter.rs @@ -4,19 +4,19 @@ use wedpr_l_crypto_zkp_discrete_logarithm_proof::prove_equality_relationship_proof; use wedpr_l_crypto_zkp_utils::{ - BASEPOINT_G2, bytes_to_point, bytes_to_scalar, - get_random_scalar, point_to_bytes, scalar_to_bytes, + bytes_to_point, bytes_to_scalar, get_random_scalar, point_to_bytes, + scalar_to_bytes, BASEPOINT_G2, }; use wedpr_l_protos::proto_to_bytes; use wedpr_l_utils::error::WedprError; use wedpr_s_protos::generated::acv::{ CounterSecret, CounterSystemParametersShareRequest, CountingPart, - DecryptedResultPartStorage, StringToCountingPartPair, - VoteStorage, + DecryptedResultPartStorage, StringToCountingPartPair, VoteStorage, }; -/// Generates a random number as secret key used for making system parameter and counting. +/// Generates a random number as secret key for making system parameter and +/// counting. pub fn make_counter_secret() -> CounterSecret { let secret_share = get_random_scalar(); CounterSecret { @@ -43,11 +43,10 @@ pub fn make_system_parameters_share( }) } - -/// Generates intermediate values and zero-knowledge proof for final count, -/// where the intermediate values is the share of ballots received by each candidate, -/// the zero-knowledge proof is equality relationship proof used to prove that -/// counter's count process is correct, specifically refers to that +/// Generates decrypted ballot and zero-knowledge proof for final count, +/// where the decrypted ballot is the share of ballots received by each +/// candidate, the zero-knowledge proof is equality relationship proof used to +/// prove that counter's count process is correct, specifically refers to that /// the secret key counter used in counting is equal to the secret key generated /// for making system parameter. pub fn count( diff --git a/solution/anonymous_ciphertext_voting/src/lib.rs b/solution/anonymous_ciphertext_voting/src/lib.rs index a86b747..e2a34ed 100644 --- a/solution/anonymous_ciphertext_voting/src/lib.rs +++ b/solution/anonymous_ciphertext_voting/src/lib.rs @@ -21,12 +21,11 @@ mod tests { use wedpr_s_protos::generated::acv::{ CandidateList, CounterSecret, CounterSystemParametersStorage, - DecryptedResultPartStorage, VoteChoice, VoteChoices, VoterSecret, - VoteStorage, + DecryptedResultPartStorage, VoteChoice, VoteChoices, VoteStorage, + VoterSecret, }; - use crate::config::SIGNATURE_SECP256K1; - use crate::coordinator; + use crate::{config::SIGNATURE_SECP256K1, coordinator}; use super::*; diff --git a/solution/anonymous_ciphertext_voting/src/verifier.rs b/solution/anonymous_ciphertext_voting/src/verifier.rs index 58ff755..543c2fe 100644 --- a/solution/anonymous_ciphertext_voting/src/verifier.rs +++ b/solution/anonymous_ciphertext_voting/src/verifier.rs @@ -8,25 +8,27 @@ use wedpr_l_crypto_zkp_discrete_logarithm_proof::{ verify_sum_relationship, }; use wedpr_l_crypto_zkp_range_proof::verify_value_range_in_batch; -use wedpr_l_crypto_zkp_utils::{ - BASEPOINT_G1, BASEPOINT_G2, bytes_to_point, -}; +use wedpr_l_crypto_zkp_utils::{bytes_to_point, BASEPOINT_G1, BASEPOINT_G2}; use wedpr_l_protos::{ bytes_to_proto, generated::zkp::{BalanceProof, EqualityProof}, }; -use wedpr_l_utils::error::WedprError; -use wedpr_l_utils::traits::{Hash, Signature}; +use wedpr_l_utils::{ + error::WedprError, + traits::{Hash, Signature}, +}; use wedpr_s_protos::generated::acv::{ - Ballot, CountingPart, DecryptedResultPartStorage, - SystemParametersStorage, VoteRequest, VoteResultStorage, VoteStorage + Ballot, CountingPart, DecryptedResultPartStorage, SystemParametersStorage, + VoteRequest, VoteResultStorage, VoteStorage, }; use crate::config::{HASH_KECCAK256, SIGNATURE_SECP256K1}; -/// Verifies whether each ballot of voters is correct, -/// specifically refers to the format, the accounting balance and the numerical range of each ballot. +/// Verifies a group of zero-knowledge proofs in the vote request from each +/// voter to confirm whether each ballot of voter is correct, specifically +/// refers to the format, the accounting balance and the numerical range of each +/// ciphertext ballot. pub fn verify_bounded_vote_request( param: &SystemParametersStorage, request: &VoteRequest, @@ -108,8 +110,9 @@ pub fn verify_bounded_vote_request( Ok(true) } -/// Verifies whether the counting process is correct, -/// specifically refers to that whether each counter used correct secret key when counting. +/// Verifies zero-knowledge proof in the count request from each counter to +/// confirm whether the counting process is correct, specifically refers to that +/// whether each counter used correct secret key when counting. pub fn verify_count_request( param: &SystemParametersStorage, encrypted_vote_sum: &VoteStorage, @@ -121,7 +124,8 @@ pub fn verify_count_request( )?; let blank_equality_proof_bytes = request.get_blank_part().get_equality_proof(); - let blank_c2_r = bytes_to_point(&request.get_blank_part().get_blinding_c2())?; + let blank_c2_r = + bytes_to_point(&request.get_blank_part().get_blinding_c2())?; let blank_equality_proof = bytes_to_proto::(&blank_equality_proof_bytes)?; if !verify_equality_relationship_proof( @@ -176,8 +180,9 @@ pub fn verify_vote_result( ) -> Result { let blank_c1_sum = bytes_to_point(&vote_sum.get_blank_ballot().get_ciphertext1())?; - let blank_c2_r_sum = - bytes_to_point(&counting_result_sum.get_blank_part().get_blinding_c2())?; + let blank_c2_r_sum = bytes_to_point( + &counting_result_sum.get_blank_part().get_blinding_c2(), + )?; let expected_blank_ballot_result = blank_c1_sum - (blank_c2_r_sum); let mut get_blank_result: i64 = 0; for tmp in vote_result_request.get_result() { @@ -230,7 +235,7 @@ pub fn verify_vote_result( Ok(true) } -pub fn pending_commitment_vec(v: &mut Vec) { +fn pending_commitment_vec(v: &mut Vec) { let length = v.len() as i32; let log_length = (length as f64).log2().ceil() as u32; let expected_len = 2_i32.pow(log_length); diff --git a/solution/anonymous_ciphertext_voting/src/voter.rs b/solution/anonymous_ciphertext_voting/src/voter.rs index a1ac0d2..309ea90 100644 --- a/solution/anonymous_ciphertext_voting/src/voter.rs +++ b/solution/anonymous_ciphertext_voting/src/voter.rs @@ -16,12 +16,12 @@ use wedpr_l_crypto_zkp_utils::{ use wedpr_l_protos::proto_to_bytes; use wedpr_l_utils::error::WedprError; use wedpr_s_protos::generated::acv::{ - Ballot, BallotProof, CandidateBallot, StringToCandidateBallotProofPair, - RegistrationRequest, RegistrationResponse, SystemParametersStorage, - VoteChoices, VoteRequest, VoterSecret, + Ballot, BallotProof, CandidateBallot, RegistrationRequest, + RegistrationResponse, StringToCandidateBallotProofPair, + SystemParametersStorage, VoteChoices, VoteRequest, VoterSecret, }; -/// Generates a random number as secret number for applying blank ballot. +/// Generates a random number as secret number for applying for blank ballot. pub fn make_voter_secret() -> VoterSecret { let vote_secret = get_random_scalar(); VoterSecret { @@ -31,7 +31,7 @@ pub fn make_voter_secret() -> VoterSecret { } } -/// Applys to the coordinator for blank ballot using own weight and secret number. +/// Applys to the coordinator for blank ballot using own secret number and system parameters. pub fn make_bounded_registration_request( secret: &VoterSecret, param: &SystemParametersStorage, @@ -76,13 +76,14 @@ pub fn verify_blank_ballot( && request_ciphertext2 == response_ciphertext2) } -/// Generate a vote request containing ballots for selected candidates, rest ballot -/// and a group of zero-knowledge proofs to prove that ballots is correct, -/// where zero-knowledge proofs contains format proof, balance proof and range proof. -/// The format proof is used to prove that the format of ballots is correct -/// so that it can be counted in the total number of votes when counting, -/// the balance proof is used to prove that poll ballots + the rest ballot = the blank ballot, -/// the range proof is used to prove that the value of ballot is non-negative. +/// Generate a vote request containing ballots for selected candidates, rest +/// ballot and a group of zero-knowledge proofs to prove that ballots is +/// correct, where zero-knowledge proofs contains format proof, balance proof +/// and range proof. The format proof is used to prove that the format of +/// ballots is correct so that it can be counted in the total number of votes +/// when counting, the balance proof is used to prove that poll ballots + the +/// rest ballot = the blank ballot, the range proof is used to prove that the +/// value of each ballot is non-negative. pub fn vote_bounded( secret: &VoterSecret, choices: &VoteChoices, diff --git a/solution/key_tool_box/hierarchical_deterministic_key/Cargo.toml b/solution/key_tool_box/hierarchical_deterministic_key/Cargo.toml index 94a7539..9b35bc2 100644 --- a/solution/key_tool_box/hierarchical_deterministic_key/Cargo.toml +++ b/solution/key_tool_box/hierarchical_deterministic_key/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "wedpr_s_hierarchical_deterministic_key" version = "1.3.0" -authors = ["wedpr "] +authors = [ "wedpr " ] edition = "2018" license = "Apache-2.0" description = "Library of Hierarchical Deterministic Key (HDK) solution." @@ -11,14 +11,15 @@ description = "Library of Hierarchical Deterministic Key (HDK) solution." [dependencies] hex = "0.3" rand = "0.7" -wagyu_lib = { package = "wagyu-bitcoin", version = "0.6.3" } wagyu-model = "0.6.3" +wagyu_lib = { package = "wagyu-bitcoin", version = "0.6.3" } wedpr_l_macros = "1.0.0" -wedpr_s_protos = "1.3.0" wedpr_l_utils = "1.0.0" +wedpr_s_protos = "1.3.0" + [dev-dependencies] +wedpr_l_common_coder_base64 = "1.0.0" wedpr_l_crypto_ecies_secp256k1 = "1.0.0" -wedpr_l_crypto_signature_secp256k1 = "1.0.0" wedpr_l_crypto_hash_keccak256 = "1.0.0" -wedpr_l_common_coder_base64 = "1.0.0" +wedpr_l_crypto_signature_secp256k1 = "1.0.0" diff --git a/solution/selective_certificate_disclosure/Cargo.toml b/solution/selective_certificate_disclosure/Cargo.toml index 928f4b1..038a0ec 100644 --- a/solution/selective_certificate_disclosure/Cargo.toml +++ b/solution/selective_certificate_disclosure/Cargo.toml @@ -10,14 +10,15 @@ description = "Library of selective certificate disclosure (SCD) solution." [dependencies] colored = "1.8" -wedpr-indy-crypto = "0.4.5" protobuf = "2.22.1" serde = "1.0.102" serde_json = "1.0.41" +wedpr-indy-crypto = "0.4.5" wedpr_l_macros = "1.0.0" -wedpr_s_protos = "1.3.0" wedpr_l_utils = "1.0.0" #wedpr_l_common_coder_base64 = {version = "1.0.0", optional = true} +wedpr_s_protos = "1.3.0" + [dev-dependencies] criterion = "0.2" diff --git a/solution/verifiable_confidential_ledger/Cargo.toml b/solution/verifiable_confidential_ledger/Cargo.toml index a106326..8dff50e 100644 --- a/solution/verifiable_confidential_ledger/Cargo.toml +++ b/solution/verifiable_confidential_ledger/Cargo.toml @@ -11,16 +11,17 @@ description = "Library of verifiable confidential ledger (VCL) solution." [dependencies] colored = "1.8" curve25519-dalek = { version = "1", features = [ "serde" ] } -wedpr_l_macros = "1.0.0" -wedpr_s_protos = { path = "../../protos"} -wedpr_l_protos = "1.1.0" -wedpr_l_utils = "1.1.0" +protobuf = "2.22.1" +#protoc-rust = "2.20.0" + wedpr_l_crypto_zkp_discrete_logarithm_proof = "1.1.0" -wedpr_l_crypto_zkp_range_proof = { git = "https://github.com/WeBankBlockchain/WeDPR-Lab-Crypto", branch = "main" } +wedpr_l_crypto_zkp_range_proof = { git = "https://github.com/WeBankBlockchain/WeDPR-Lab-Crypto", branch = "main" } wedpr_l_crypto_zkp_utils = "1.1.0" -protobuf = "2.22.1" -#protoc-rust = "2.20.0" +wedpr_l_macros = "1.0.0" +wedpr_l_protos = "1.1.0" +wedpr_l_utils = "1.1.0" +wedpr_s_protos = { path = "../../protos" } [dev-dependencies] criterion = "0.2" diff --git a/solution/verifiable_confidential_ledger/src/main.rs b/solution/verifiable_confidential_ledger/src/main.rs index d9b023d..8f4a3eb 100644 --- a/solution/verifiable_confidential_ledger/src/main.rs +++ b/solution/verifiable_confidential_ledger/src/main.rs @@ -3,10 +3,10 @@ //! Minimalist demo of verifiable confidential ledger. use colored::*; +use protobuf::Message; use std; use wedpr_l_crypto_zkp_utils::point_to_bytes; use wedpr_s_verifiable_confidential_ledger::vcl; -use protobuf::Message; fn main() { print_highlight2( From 702653593a39bfb2858e786c44deaf5575a7cf86 Mon Sep 17 00:00:00 2001 From: HaoXuan40404 <444649358@qq.com> Date: Mon, 6 Sep 2021 17:32:20 +0800 Subject: [PATCH 09/15] add acv demo --- .../anonymous_ciphertext_voting/Cargo.toml | 1 + .../src/coordinator.rs | 5 +- .../anonymous_ciphertext_voting/src/lib.rs | 12 +- .../anonymous_ciphertext_voting/src/main.rs | 376 ++++++++++++++++++ .../src/verifier.rs | 2 +- .../anonymous_ciphertext_voting/src/voter.rs | 10 +- 6 files changed, 391 insertions(+), 15 deletions(-) create mode 100644 solution/anonymous_ciphertext_voting/src/main.rs diff --git a/solution/anonymous_ciphertext_voting/Cargo.toml b/solution/anonymous_ciphertext_voting/Cargo.toml index 0247840..eda313b 100644 --- a/solution/anonymous_ciphertext_voting/Cargo.toml +++ b/solution/anonymous_ciphertext_voting/Cargo.toml @@ -20,3 +20,4 @@ wedpr_l_macros = "1.0.0" wedpr_l_protos = { git = "https://github.com/WeBankBlockchain/WeDPR-Lab-Crypto.git", branch = "release-1.2.0" } wedpr_l_utils = "1.1.0" wedpr_s_protos = { path = "../../protos" } +colored = "1.8" diff --git a/solution/anonymous_ciphertext_voting/src/coordinator.rs b/solution/anonymous_ciphertext_voting/src/coordinator.rs index 4f1a9b1..7089175 100644 --- a/solution/anonymous_ciphertext_voting/src/coordinator.rs +++ b/solution/anonymous_ciphertext_voting/src/coordinator.rs @@ -36,7 +36,7 @@ pub fn make_system_parameters( /// Certifies voter's weight which indicates the maximum value that the voter /// can vote in total. -pub fn certify_bounded_voter( +pub fn certify_voter( secret_key: &[u8], value: u32, registration_request: &RegistrationRequest, @@ -74,6 +74,7 @@ pub fn aggregate_vote_sum_response( vote_storage_part: &VoteStorage, vote_sum: &mut VoteStorage, ) -> Result { + // Init storage when first part upload if !vote_sum.has_blank_ballot() { vote_sum .mut_blank_ballot() @@ -91,7 +92,6 @@ pub fn aggregate_vote_sum_response( vote_sum.mut_voted_ballot().push(ballot_pair); } } - let mut tmp_vote_storage_sum = VoteStorage::new(); let mut blank_c1_sum = bytes_to_point(&vote_sum.get_blank_ballot().get_ciphertext1())?; @@ -157,6 +157,7 @@ pub fn aggregate_decrypted_part_sum( decrypted_result_part_storage: &DecryptedResultPartStorage, counting_result_sum: &mut DecryptedResultPartStorage, ) -> Result { + // Init storage when first part upload if !counting_result_sum.has_blank_part() { counting_result_sum .mut_blank_part() diff --git a/solution/anonymous_ciphertext_voting/src/lib.rs b/solution/anonymous_ciphertext_voting/src/lib.rs index e2a34ed..c331659 100644 --- a/solution/anonymous_ciphertext_voting/src/lib.rs +++ b/solution/anonymous_ciphertext_voting/src/lib.rs @@ -8,7 +8,7 @@ extern crate lazy_static; #[macro_use] extern crate wedpr_l_macros; -mod config; +pub mod config; pub mod coordinator; pub mod counter; pub mod verifier; @@ -30,7 +30,7 @@ mod tests { use super::*; #[test] - fn test_bounded_voting() { + fn test_anonymous_ciphertext_voting() { // Generate coordinator's key pair let max_vote_number = 20000; let (public_key, secret_key) = SIGNATURE_SECP256K1.generate_keypair(); @@ -72,12 +72,12 @@ mod tests { voter_secret_list.push(vote_secret.clone()); // voter -> coordinator generate blank ballot - let vote_request = voter::make_bounded_registration_request( + let vote_request = voter::make_registration_request( &vote_secret, &system_parameters, ) .unwrap(); - let response = coordinator::certify_bounded_voter( + let response = coordinator::certify_voter( &secret_key, blank_ballot, &vote_request, @@ -110,7 +110,7 @@ mod tests { let mut encrypted_vote_sum = VoteStorage::new(); for index in 0..voting_ballot_count.len() { let ballot_choice = make_choice(&voting_ballot_count[index]); - let vote_request = voter::vote_bounded( + let vote_request = voter::vote( &voter_secret_list[index], &ballot_choice, &response_list[index], @@ -119,7 +119,7 @@ mod tests { .unwrap(); assert_eq!( true, - verifier::verify_bounded_vote_request( + verifier::verify_vote_request( &system_parameters, &vote_request, &public_key diff --git a/solution/anonymous_ciphertext_voting/src/main.rs b/solution/anonymous_ciphertext_voting/src/main.rs new file mode 100644 index 0000000..898c748 --- /dev/null +++ b/solution/anonymous_ciphertext_voting/src/main.rs @@ -0,0 +1,376 @@ +// Copyright 2020 WeDPR Lab Project Authors. Licensed under Apache-2.0. + +//! Minimalist demo of anonymous ciphertext voting. + +use wedpr_l_crypto_zkp_utils::bytes_to_point; +use wedpr_l_utils::traits::Signature; + +use wedpr_s_protos::generated::acv::{ + CandidateList, CounterSecret, CounterSystemParametersStorage, + DecryptedResultPartStorage, VoteChoice, VoteChoices, VoteStorage, + VoterSecret, +}; + +extern crate wedpr_s_anonymous_ciphertext_voting; +use colored::Colorize; +use wedpr_s_anonymous_ciphertext_voting::{ + config::SIGNATURE_SECP256K1, coordinator, counter, verifier, voter, +}; + +fn main() { + print_highlight2( + "#\n# Welcome to anonymous ciphertext voting (ACV) demo!", + "# 欢迎来到匿名密文投票demo演示!\n#", + ); + println!(); + print_alert2( + "Please select the display language used for this demonstration: ▼▼▼", + "请选择演示所使用的显示语言:▼▼▼", + ); + + print_alert2( + " ▶ Enter \"1\" to select English (default option)", + " ▶ 输入 \"2\" 选择中文", + ); + println!(); + let mut choice = wait_for_input(); + loop { + // The default option. + if choice == "1" || choice.is_empty() { + flow_en(); + break; + } else if choice == "2" { + flow_cn(); + break; + } else { + print_alert2( + "输入错误!请重新输入:", + "Invalid input! Please try again:", + ); + choice = wait_for_input(); + } + } +} + +fn flow_en() { + // TODO: en flow +} + +fn flow_cn() { + print_wide( + "投票demo流程中,你将体验如何通过明文数据生成投票密文, \ + 并了解投票密文如何解密获取最终结果的过程", + ); + + print_wide("本示例中,您将与三个投票者,共同为三位候选人进行投票"); + + println!( + "{} {} {}\n", + "【演示进度】", + "<<申请空白选票>>".yellow(), + "↦ 生成密文选票 ↦ 聚合密文选票 ↦ 联合解密选票 ↦ 公布计票结果", + ); + + print_alert( + "现在请输入空白选票的投票数额:\ + ▼▼(空白选票为投票者可以为所有候选人分配的票数总和))", + ); + print_highlight( + "在这个demo中,我们暂定投票上限为100(真实业务可按需扩展),\ + 请输入0到100之间的整数", + ); + let value1 = wait_for_number_cn(); + + let max_vote_number = 20000; + let (public_key, secret_key) = SIGNATURE_SECP256K1.generate_keypair(); + let mut candidate_list = CandidateList::new(); + // Init candidate list + for candidate in vec!["小明", "小王", "小张"] { + candidate_list.mut_candidate().push(candidate.to_string()); + } + let counter_id_list = vec!["1001", "1002", "1003"]; + let mut blank_ballot_count = vec![100, 100, 100]; + blank_ballot_count.push(value1 as u32); + println!("候选人分别为:{:?}", vec!["小明", "小王", "小张"]); + + let mut counter_secret_list: Vec = vec![]; + let mut counter_parameters_storage = + CounterSystemParametersStorage::default(); + // Counter init + for id in counter_id_list.clone() { + let share_secret = counter::make_counter_secret(); + counter_secret_list.push(share_secret.clone()); + let counter_parameters_request = + counter::make_system_parameters_share(id, &share_secret).unwrap(); + counter_parameters_storage + .mut_counter_parameters_request() + .push(counter_parameters_request.clone()); + } + // coordinator make system parameters + let system_parameters = coordinator::make_system_parameters( + &candidate_list, + &counter_parameters_storage, + ) + .unwrap(); + + // voter init + let mut voter_secret_list: Vec = vec![]; + let mut response_list = vec![]; + + for blank_ballot in blank_ballot_count { + let vote_secret = voter::make_voter_secret(); + voter_secret_list.push(vote_secret.clone()); + + // voter -> coordinator generate blank ballot + let vote_request = + voter::make_registration_request(&vote_secret, &system_parameters) + .unwrap(); + let response = coordinator::certify_voter( + &secret_key, + blank_ballot, + &vote_request, + ) + .unwrap(); + response_list.push(response.clone()); + // verify blank ballot + let result = + voter::verify_blank_ballot(&vote_request, &response).unwrap(); + assert_eq!(true, result); + } + println!("您的空白选票为:{:?}", response_list[3].get_ballot()); + + println!( + "{} {} {}\n", + "【演示进度】申请空白选票 ↦ ", + "<<生成密文选票>> ".yellow(), + "↦ 聚合密文选票 ↦ 联合解密选票 ↦ 公布计票结果", + ); + print_alert("现在请输入您对候选人:【小明】的投票数额:▼▼"); + let value2 = wait_for_number_cn(); + print_alert("现在请输入您对候选人:【小王】的投票数额:▼▼"); + let value3 = wait_for_number_cn(); + print_alert("现在请输入您对候选人:【小张】的投票数额:▼▼"); + let value4 = wait_for_number_cn(); + print_alert("注:当总数额大于空白选票数额时将会导致投票失败"); + + // voter vote + let make_choice = |x: &Vec| { + let mut choices = VoteChoices::new(); + for i in 0..candidate_list.get_candidate().len() { + let mut pair = VoteChoice::new(); + pair.set_candidate(candidate_list.get_candidate()[i].clone()); + pair.set_value(x[i]); + choices.mut_choice().push(pair); + } + choices + }; + + let voting_ballot_count: Vec> = + vec![vec![10, 20, 30], vec![10, 20, 30], vec![10, 20, 30], vec![ + value2, value3, value4, + ]]; + + let mut vote_request_list = vec![]; + let mut encrypted_vote_sum = VoteStorage::new(); + for index in 0..voting_ballot_count.len() { + let ballot_choice = make_choice(&voting_ballot_count[index]); + let vote_request = voter::vote( + &voter_secret_list[index], + &ballot_choice, + &response_list[index], + &system_parameters, + ) + .unwrap(); + assert_eq!( + true, + verifier::verify_vote_request( + &system_parameters, + &vote_request, + &public_key + ) + .unwrap() + ); + assert_eq!( + true, + coordinator::aggregate_vote_sum_response( + &system_parameters, + &vote_request.get_vote(), + &mut encrypted_vote_sum + ) + .unwrap() + ); + vote_request_list.push(vote_request); + } + println!("您的密文选票为:{:?}", vote_request_list[3].get_vote()); + pause_cn(); + + println!( + "{} {} {}\n", + "【演示进度】申请空白选票 ↦ 生成密文选票 ↦ ", + "<<聚合密文选票>> ".yellow(), + "↦ 联合解密选票 ↦ 公布计票结果", + ); + + println!("所有投票者聚合后的密文选票为:{:?}", encrypted_vote_sum); + pause_cn(); + + println!( + "{} {} {}\n", + "【演示进度】申请空白选票 ↦ 生成密文选票 ↦ 聚合密文选票 ↦ ", + "<<联合解密选票>> ".yellow(), + "↦ 公布计票结果", + ); + + let mut vote_sum_total = DecryptedResultPartStorage::new(); + let length = counter_secret_list.len().clone(); + for index in 0..length { + let decrypt_request = counter::count( + &counter_id_list[index], + &counter_secret_list[index], + &encrypted_vote_sum, + ) + .unwrap(); + let share = bytes_to_point( + counter_parameters_storage.get_counter_parameters_request()[index] + .get_poll_point_share(), + ) + .unwrap(); + assert_eq!( + true, + verifier::verify_count_request( + &system_parameters, + &encrypted_vote_sum, + &share, + &decrypt_request + ) + .unwrap() + ); + assert_eq!( + true, + coordinator::aggregate_decrypted_part_sum( + &system_parameters, + &decrypt_request, + &mut vote_sum_total + ) + .unwrap() + ); + } + println!("所有计票者联合解密投票结果为:{:?}", vote_sum_total); + pause_cn(); + + println!( + "{} {} {}\n", + "【演示进度】申请空白选票 ↦ 生成密文选票 ↦ 聚合密文选票 ↦ \ + 联合解密选票 ↦ ", + "<<公布计票结果>> ".yellow(), + "", + ); + + let final_result_request = coordinator::finalize_vote_result( + &system_parameters, + &encrypted_vote_sum, + &vote_sum_total, + max_vote_number, + ) + .unwrap(); + println!("另外三位投票者对候选人的投票分别均为10,20,30"); + for f_result in final_result_request.get_result() { + println!( + "候选人:{}, 最终得票{}", + f_result.get_key(), + f_result.get_value() + ) + } + let result = verifier::verify_vote_result( + &system_parameters, + &encrypted_vote_sum, + &vote_sum_total, + &final_result_request, + ) + .unwrap(); + assert!(result); + + pause_cn(); + + print_alert("十分感谢您的试用!"); + println!( + "\n{}\n\n{}\n{}\n", + "关于WeDPR,如需了解更多,欢迎通过以下方式联系我们", + "1. 微信公众号【微众银行区块链】", + "2. 官方邮箱【wedpr@webank.com】" + ); + println!(); +} + +// Utility functions +fn print_highlight(message: &str) { + println!("{}", message.green()); +} + +fn print_highlight2(message1: &str, message2: &str) { + println!("{}\n{}", message1.green(), message2.green()); +} + +fn print_alert(message: &str) { + println!("{}", message.yellow()); +} + +fn print_alert2(message1: &str, message2: &str) { + println!("{}\n{}", message1.yellow(), message2.yellow()); +} + +fn print_wide(message: &str) { + println!("\n{}\n", message); +} + +fn wait_for_input() -> String { + let mut input = String::new(); + std::io::stdin() + .read_line(&mut input) + .expect("Failed to read line."); + input.trim().to_string() +} + +// In this demo, we set the upper limit of input value to 10000. +const MAX_INPUT_VALUE: i32 = 100; + +fn wait_for_number(error_message: &str) -> u32 { + let mut input = wait_for_input(); + let mut input_num = input.parse::(); + loop { + match input_num { + // TODO: Enable negative input in the demo. + Ok(v) if (v >= 0) && (v <= MAX_INPUT_VALUE) => return v as u32, + _ => { + print_alert(error_message); + input = wait_for_input(); + input_num = input.parse::(); + }, + } + } +} + +fn wait_for_number_cn() -> u32 { + wait_for_number("请输入有效数字:") +} + +fn wait_for_number_en() -> u32 { + wait_for_number("Please input a valid number:") +} + +fn pause(info_message: &str) { + let mut enter_continue = String::new(); + print_wide(info_message); + std::io::stdin() + .read_line(&mut enter_continue) + .expect("read_line should not fail"); + println!("... {}\n", enter_continue.trim()); +} + +fn pause_cn() { + pause("按任意键继续..."); +} + +fn pause_en() { + pause("Press any key to continue..."); +} diff --git a/solution/anonymous_ciphertext_voting/src/verifier.rs b/solution/anonymous_ciphertext_voting/src/verifier.rs index 543c2fe..ea9554f 100644 --- a/solution/anonymous_ciphertext_voting/src/verifier.rs +++ b/solution/anonymous_ciphertext_voting/src/verifier.rs @@ -29,7 +29,7 @@ use crate::config::{HASH_KECCAK256, SIGNATURE_SECP256K1}; /// voter to confirm whether each ballot of voter is correct, specifically /// refers to the format, the accounting balance and the numerical range of each /// ciphertext ballot. -pub fn verify_bounded_vote_request( +pub fn verify_vote_request( param: &SystemParametersStorage, request: &VoteRequest, public_key: &[u8], diff --git a/solution/anonymous_ciphertext_voting/src/voter.rs b/solution/anonymous_ciphertext_voting/src/voter.rs index 309ea90..c2e414d 100644 --- a/solution/anonymous_ciphertext_voting/src/voter.rs +++ b/solution/anonymous_ciphertext_voting/src/voter.rs @@ -31,8 +31,9 @@ pub fn make_voter_secret() -> VoterSecret { } } -/// Applys to the coordinator for blank ballot using own secret number and system parameters. -pub fn make_bounded_registration_request( +/// Applys to the coordinator for blank ballot using own secret number and +/// system parameters. +pub fn make_registration_request( secret: &VoterSecret, param: &SystemParametersStorage, ) -> Result { @@ -58,9 +59,6 @@ pub fn verify_blank_ballot( ) -> Result { let blinding_poll_point = bytes_to_point(request.get_weight_point().get_blinding_poll_point())?; - // let blinding_basepoint_g2 = bytes_to_point( - // request.get_weight_point().get_blinding_basepoint_g2(), - // )?; let voter_weight = response.get_voter_weight(); let computed_ciphertext1 = point_to_bytes( &(blinding_poll_point + *BASEPOINT_G1 * Scalar::from(voter_weight)), @@ -84,7 +82,7 @@ pub fn verify_blank_ballot( /// when counting, the balance proof is used to prove that poll ballots + the /// rest ballot = the blank ballot, the range proof is used to prove that the /// value of each ballot is non-negative. -pub fn vote_bounded( +pub fn vote( secret: &VoterSecret, choices: &VoteChoices, response: &RegistrationResponse, From b85b6a193e34e03544eea04e2d2da4239d5471d7 Mon Sep 17 00:00:00 2001 From: HaoXuan40404 <444649358@qq.com> Date: Tue, 7 Sep 2021 16:53:33 +0800 Subject: [PATCH 10/15] rename hdk --- .../hierarchical_deterministic_key/Cargo.toml | 4 ++-- .../hierarchical_deterministic_key/src/hdk.rs | 20 +++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/solution/key_tool_box/hierarchical_deterministic_key/Cargo.toml b/solution/key_tool_box/hierarchical_deterministic_key/Cargo.toml index 9b35bc2..70893bf 100644 --- a/solution/key_tool_box/hierarchical_deterministic_key/Cargo.toml +++ b/solution/key_tool_box/hierarchical_deterministic_key/Cargo.toml @@ -11,8 +11,8 @@ description = "Library of Hierarchical Deterministic Key (HDK) solution." [dependencies] hex = "0.3" rand = "0.7" -wagyu-model = "0.6.3" -wagyu_lib = { package = "wagyu-bitcoin", version = "0.6.3" } +wagyu-model = { package = "h-wagyu-model", version = "0.6.3" } +wagyu_lib = { package = "wagyu-hdk", version = "0.6.4" } wedpr_l_macros = "1.0.0" wedpr_l_utils = "1.0.0" diff --git a/solution/key_tool_box/hierarchical_deterministic_key/src/hdk.rs b/solution/key_tool_box/hierarchical_deterministic_key/src/hdk.rs index 4b5e90e..52a86c6 100644 --- a/solution/key_tool_box/hierarchical_deterministic_key/src/hdk.rs +++ b/solution/key_tool_box/hierarchical_deterministic_key/src/hdk.rs @@ -3,8 +3,8 @@ //! Core functions of hierarchical deterministic key (HDK) use wagyu_lib::{ - wordlist, BitcoinDerivationPath, BitcoinExtendedPrivateKey, - BitcoinMnemonic, Mainnet, + wordlist, HdkDerivationPath, HdkExtendedPrivateKey, + HdkMnemonic, Mainnet, }; use wagyu_model::{ mnemonic::Mnemonic, ExtendedPrivateKey, MnemonicCount, MnemonicExtended, @@ -22,7 +22,7 @@ use wedpr_s_protos::generated::hdk::ExtendedKeyPair; pub fn create_mnemonic_en(word_count: u8) -> Result { let rng = &mut StdRng::from_entropy(); let mnemonic = - match BitcoinMnemonic::::new_with_count( + match HdkMnemonic::::new_with_count( rng, word_count, ) { Ok(v) => v, @@ -44,7 +44,7 @@ pub fn create_master_key_en( mnemonic_str: &str, ) -> Result, WedprError> { let mnemonic = - match BitcoinMnemonic::::from_phrase( + match HdkMnemonic::::from_phrase( mnemonic_str, ) { Ok(v) => v, @@ -98,7 +98,7 @@ pub fn derive_extended_key( }, }; let master_key = - match BitcoinExtendedPrivateKey::::from_str(master_key_str) { + match HdkExtendedPrivateKey::::from_str(master_key_str) { Ok(v) => v, Err(_) => { wedpr_println!( @@ -110,7 +110,7 @@ pub fn derive_extended_key( }; let derivation_path = - match BitcoinDerivationPath::from_str(&key_derivation_path) { + match HdkDerivationPath::from_str(&key_derivation_path) { Ok(v) => v, Err(_) => { wedpr_println!( @@ -132,10 +132,9 @@ pub fn derive_extended_key( return Err(WedprError::FormatError); }, }; - let private_key_hex = extended_private_key + let private_key_hex = hex::encode(extended_private_key .to_private_key() - .to_secp256k1_secret_key() - .to_string(); + .to_secp256k1_secret_key().serialize()); let extended_private_key_bytes = match decode_hex_string(&private_key_hex) { Ok(v) => v, @@ -151,7 +150,8 @@ pub fn derive_extended_key( let extended_public_key_uncompress_bytes = extended_private_key .to_public_key() .to_secp256k1_public_key() - .serialize_uncompressed(); + .serialize(); + // .serialize_uncompressed(); // TODO: Replace with a better way to initialize PB if available. Ok(ExtendedKeyPair { From dd23474c7ff446ee8029c88c3c8e2a91017a6fa1 Mon Sep 17 00:00:00 2001 From: julyawang <1090667500@qq.com> Date: Tue, 7 Sep 2021 19:50:19 +0800 Subject: [PATCH 11/15] fix acv main --- .../anonymous_ciphertext_voting/src/main.rs | 298 +++++++++++++----- 1 file changed, 216 insertions(+), 82 deletions(-) diff --git a/solution/anonymous_ciphertext_voting/src/main.rs b/solution/anonymous_ciphertext_voting/src/main.rs index 898c748..c2af12b 100644 --- a/solution/anonymous_ciphertext_voting/src/main.rs +++ b/solution/anonymous_ciphertext_voting/src/main.rs @@ -52,31 +52,48 @@ fn main() { } } -fn flow_en() { - // TODO: en flow -} - fn flow_cn() { print_wide( - "投票demo流程中,你将体验如何通过明文数据生成投票密文, \ - 并了解投票密文如何解密获取最终结果的过程", + "投票demo流程中,你将体验隐匿密文投票的全过程,具体包括:\n + 1. 投票者如何使用密文选票进行匿名投票;\n + 2. 计票者如何联合解密得到计票结果;\n + 3. 任意验证者如何借助零知识证明来验证整个过程中投票者与计票者行为的正确性。", ); + print_wide("为了更容易理解其效果,我们设定了如下示例场景。"); - print_wide("本示例中,您将与三个投票者,共同为三位候选人进行投票"); + println!( + "{}\n{}\n{}\n", + "【场景介绍】".yellow(), + "4个投票者为3个候选人进行投票,\ + 每个投票者都可向其中任意一个或多个候选人投出包含一定数值的密文选票,", + "3个计票者需合作才能统计出每个候选人的最终得票。", + ); + println!( + "{}\n{}\n{}\n{}\n{}\n{}\n", + "【流程介绍】".yellow(), + "1. 投票者获得初始选票;", + "2. 投票者决定为各候选人分别投出多少数额,\ + 生成并公布对应的密文选票和零知识证明;", + "3. 任意验证者验证投票者公布的密文选票是否正确有效;", + "4. 计票者联合计算每个候选人的得票,公布统计结果和零知识证明;", + "5. 任意验证者验证计票者的计票过程及计票结果是否正确有效。" + ); + pause_cn(); println!( "{} {} {}\n", "【演示进度】", - "<<申请空白选票>>".yellow(), - "↦ 生成密文选票 ↦ 聚合密文选票 ↦ 联合解密选票 ↦ 公布计票结果", + "<<生成并公布初始密文选票>>".yellow(), + "↦ 生成并公布对各候选人的密文选票 ↦ 验证密文选票 ↦ \ + 联合计票并公布计票信息↦ 验证计票过程 ↦ 公布计票结果 ↦ 验证计票结果", ); print_alert( - "现在请输入空白选票的投票数额:\ - ▼▼(空白选票为投票者可以为所有候选人分配的票数总和))", + "现在请输入初始选票的数额:▼▼(初始选票的数额表示:\ + 该投票者可以投出的密文选票总额上限)", ); print_highlight( - "在这个demo中,我们暂定投票上限为100(真实业务可按需扩展),\ + "在这个demo中,我们暂定初始选票数额上限为100(真实业务可按需扩展),\ 请输入0到100之间的整数", ); let value1 = wait_for_number_cn(); @@ -85,13 +102,12 @@ fn flow_cn() { let (public_key, secret_key) = SIGNATURE_SECP256K1.generate_keypair(); let mut candidate_list = CandidateList::new(); // Init candidate list - for candidate in vec!["小明", "小王", "小张"] { + for candidate in vec!["候选人1", "候选人2", "候选人3"] { candidate_list.mut_candidate().push(candidate.to_string()); } let counter_id_list = vec!["1001", "1002", "1003"]; let mut blank_ballot_count = vec![100, 100, 100]; blank_ballot_count.push(value1 as u32); - println!("候选人分别为:{:?}", vec!["小明", "小王", "小张"]); let mut counter_secret_list: Vec = vec![]; let mut counter_parameters_storage = @@ -137,23 +153,34 @@ fn flow_cn() { voter::verify_blank_ballot(&vote_request, &response).unwrap(); assert_eq!(true, result); } - println!("您的空白选票为:{:?}", response_list[3].get_ballot()); + println!( + "您的初始密文选票为:\n{:?}\n", + response_list[3].get_ballot() + ); + print_alert( + "可以看到,投票者公布的初始密文选票中不包含投票者的身份及其初始数额。", + ); + pause_cn(); println!( - "{} {} {}\n", - "【演示进度】申请空白选票 ↦ ", - "<<生成密文选票>> ".yellow(), - "↦ 聚合密文选票 ↦ 联合解密选票 ↦ 公布计票结果", + "{} {} {} \n", + "【演示进度】生成并公布初始密文选票 ↦", + "<<生成并公布对各候选人的密文选票>>".yellow(), + "↦ 验证密文选票 ↦ 联合计票并公布计票信息↦ 验证计票过程 ↦ 公布计票结果 \ + ↦ 验证计票结果", ); - print_alert("现在请输入您对候选人:【小明】的投票数额:▼▼"); + + print_alert("现在请输入您对候选人1的投票数额:▼▼"); let value2 = wait_for_number_cn(); - print_alert("现在请输入您对候选人:【小王】的投票数额:▼▼"); + print_alert("现在请输入您对候选人2的投票数额:▼▼"); let value3 = wait_for_number_cn(); - print_alert("现在请输入您对候选人:【小张】的投票数额:▼▼"); + print_alert("现在请输入您对候选人3的投票数额:▼▼"); + print_highlight( + "(注:当投出的总数额大于初始选票数值时,会导致投票失败)。", + ); let value4 = wait_for_number_cn(); - print_alert("注:当总数额大于空白选票数额时将会导致投票失败"); - // voter vote + // Voter votes. let make_choice = |x: &Vec| { let mut choices = VoteChoices::new(); for i in 0..candidate_list.get_candidate().len() { @@ -164,11 +191,15 @@ fn flow_cn() { } choices }; - - let voting_ballot_count: Vec> = - vec![vec![10, 20, 30], vec![10, 20, 30], vec![10, 20, 30], vec![ - value2, value3, value4, - ]]; + let candidate1_default = 10; + let candidate2_default = 20; + let candidate3_default = 30; + let voting_ballot_count: Vec> = vec![ + vec![candidate1_default, candidate2_default, candidate3_default], + vec![candidate1_default, candidate2_default, candidate3_default], + vec![candidate1_default, candidate2_default, candidate3_default], + vec![value2, value3, value4], + ]; let mut vote_request_list = vec![]; let mut encrypted_vote_sum = VoteStorage::new(); @@ -181,47 +212,67 @@ fn flow_cn() { &system_parameters, ) .unwrap(); - assert_eq!( - true, - verifier::verify_vote_request( - &system_parameters, - &vote_request, - &public_key - ) - .unwrap() - ); - assert_eq!( - true, - coordinator::aggregate_vote_sum_response( - &system_parameters, - &vote_request.get_vote(), - &mut encrypted_vote_sum - ) - .unwrap() - ); + coordinator::aggregate_vote_sum_response( + &system_parameters, + &vote_request.get_vote(), + &mut encrypted_vote_sum, + ) + .unwrap(); vote_request_list.push(vote_request); } - println!("您的密文选票为:{:?}", vote_request_list[3].get_vote()); + println!( + "\n您公布的密文选票为:\n{:?}\n", + vote_request_list[3].get_vote() + ); + print_alert( + "可以看到:投票者公布的密文选票中不包含投票者身份、候选人身份、\ + 投票数额等信息。", + ); + println!("假定其他投票者对三位候选人的投票均为[10,20,30]。"); pause_cn(); println!( - "{} {} {}\n", - "【演示进度】申请空白选票 ↦ 生成密文选票 ↦ ", - "<<聚合密文选票>> ".yellow(), - "↦ 联合解密选票 ↦ 公布计票结果", + "{} {} {} \n", + "【演示进度】 生成并公布初始密文选票 ↦ 生成并公布对各候选人的密文选票 \ + ↦", + "验证密文选票".yellow(), + "↦ 联合计票并公布计票信息↦ 验证计票过程 ↦ 公布计票结果 ↦ 验证计票结果", + ); + + println!( + "验证内容包括:\n1. 投给每个候选人的密文选票数额非负;\n2. \ + 每个密文选票格式正确(否则会导致后续计票失败);\n3. \ + 投票者投出的密文选票数额之和小于等于其初始选票数额。" ); - println!("所有投票者聚合后的密文选票为:{:?}", encrypted_vote_sum); + print_alert("\n只有通过验证的密文选票,才会进入后续计票流程。"); + pause_cn(); + + // Verifier verifies voters. + let length = vote_request_list.len().clone(); + for index in 0..length { + let verify_voter = verifier::verify_vote_request( + &system_parameters, + &vote_request_list[index], + &public_key, + ) + .unwrap(); + println!("\n对投票者{}的验证结果为:{:?}", index, verify_voter); + } pause_cn(); println!( - "{} {} {}\n", - "【演示进度】申请空白选票 ↦ 生成密文选票 ↦ 聚合密文选票 ↦ ", - "<<联合解密选票>> ".yellow(), - "↦ 公布计票结果", + "{} {} {} \n", + "【演示进度】 生成并公布初始密文选票 ↦ 生成并公布对各候选人的密文选票 \ + ↦ 验证密文选票 ↦", + "联合计票并公布计票信息".yellow(), + "↦ 验证计票过程 ↦ 公布计票结果 ↦ 验证计票结果", ); + // Counters count. let mut vote_sum_total = DecryptedResultPartStorage::new(); + let mut decrypt_request_list = vec![]; + let mut share_list = vec![]; let length = counter_secret_list.len().clone(); for index in 0..length { let decrypt_request = counter::count( @@ -235,16 +286,6 @@ fn flow_cn() { .get_poll_point_share(), ) .unwrap(); - assert_eq!( - true, - verifier::verify_count_request( - &system_parameters, - &encrypted_vote_sum, - &share, - &decrypt_request - ) - .unwrap() - ); assert_eq!( true, coordinator::aggregate_decrypted_part_sum( @@ -254,16 +295,48 @@ fn flow_cn() { ) .unwrap() ); + decrypt_request_list.push(decrypt_request); + share_list.push(share); } - println!("所有计票者联合解密投票结果为:{:?}", vote_sum_total); + println!("所有计票者联合计票的计票信息为:\n{:?}", vote_sum_total); + print_alert( + "可以看到:计票者公布的计票信息中不包含计票者身份等计票者隐私信息。", + ); pause_cn(); println!( - "{} {} {}\n", - "【演示进度】申请空白选票 ↦ 生成密文选票 ↦ 聚合密文选票 ↦ \ - 联合解密选票 ↦ ", - "<<公布计票结果>> ".yellow(), - "", + "{} {} {} \n", + "【演示进度】 生成并公布初始密文选票 ↦ 生成并公布对各候选人的密文选票 \ + ↦ 验证密文选票 ↦ 联合计票并公布计票信息 ↦", + "验证计票过程".yellow(), + "↦ 公布计票结果 ↦ 验证计票结果", + ); + + println!( + "验证计票过程,是指:\n + 验证计票者公布的计票信息是使用正确的计票者密钥计算而得,\ + 而不是随意构造而得。" + ); + let length = counter_secret_list.len().clone(); + for index in 0..length { + let verify_counter = verifier::verify_count_request( + &system_parameters, + &encrypted_vote_sum, + &share_list[index], + &decrypt_request_list[index], + ) + .unwrap(); + println!("\n对计票者{}的验证结果为:{:?}", index, verify_counter); + } + + pause_cn(); + + println!( + "{} {} {} \n", + "【演示进度】 生成并公布初始密文选票 ↦ 生成并公布对各候选人的密文选票 \ + ↦ 验证密文选票 ↦ 联合计票并公布计票信息 ↦ 验证计票过程 ↦", + "公布计票结果".yellow(), + "↦ 验证计票结果", ); let final_result_request = coordinator::finalize_vote_result( @@ -273,23 +346,80 @@ fn flow_cn() { max_vote_number, ) .unwrap(); - println!("另外三位投票者对候选人的投票分别均为10,20,30"); - for f_result in final_result_request.get_result() { - println!( - "候选人:{}, 最终得票{}", - f_result.get_key(), - f_result.get_value() - ) + + println!( + "{}: 最终得票为{}。", + final_result_request.get_result()[1].get_key(), + final_result_request.get_result()[1].get_value() + ); + println!( + "{}: 最终得票为{}。", + final_result_request.get_result()[2].get_key(), + final_result_request.get_result()[2].get_value() + ); + println!( + "{}: 最终得票为{}。", + final_result_request.get_result()[3].get_key(), + final_result_request.get_result()[3].get_value() + ); + + print_alert("\n对比明文统计结果:"); + let plaintext_result1 = + (candidate1_default + candidate1_default + candidate1_default + value2).into(); + let plaintext_result2 = + (candidate2_default + candidate2_default + candidate2_default + value3).into(); + let plaintext_result3 = + (candidate3_default + candidate3_default + candidate3_default + value4).into(); + println!( + "候选人1得票:{} + {} + {} + {} = {}", + candidate1_default, + candidate1_default, + candidate1_default, + value2, + plaintext_result1 + ); + println!( + "候选人2得票:{} + {} + {} + {} = {}", + candidate2_default, + candidate2_default, + candidate2_default, + value3, + plaintext_result2 + ); + println!( + "候选人3得票:{} + {} + {} + {} = {}", + candidate3_default, + candidate3_default, + candidate3_default, + value4, + plaintext_result3 + ); + if final_result_request.get_result()[1].get_value() == plaintext_result1 + && final_result_request.get_result()[2].get_value() == plaintext_result2 + && final_result_request.get_result()[3].get_value() == plaintext_result3 + { + print_alert("\n可以看到,密文选票的计票结果与明文计算结果一致。"); } - let result = verifier::verify_vote_result( + + pause_cn(); + + println!( + "{} {} \n", + "【演示进度】 生成并公布初始密文选票 ↦ 生成并公布对各候选人的密文选票 \ + ↦ 验证密文选票 ↦ 联合计票并公布计票信息 ↦ 验证计票过程 ↦ \ + 公布计票结果 ↦", + "验证计票结果".yellow(), + ); + + let verify_result = verifier::verify_vote_result( &system_parameters, &encrypted_vote_sum, &vote_sum_total, &final_result_request, ) .unwrap(); - assert!(result); + println!("\n验证结果为:{:?}", verify_result); pause_cn(); print_alert("十分感谢您的试用!"); @@ -302,6 +432,10 @@ fn flow_cn() { println!(); } +fn flow_en() { + // TODO: en flow +} + // Utility functions fn print_highlight(message: &str) { println!("{}", message.green()); From b16214ccb4cc803c5a17a1f70a5eee116daa6863 Mon Sep 17 00:00:00 2001 From: qyan-dev Date: Fri, 17 Sep 2021 22:58:27 +0800 Subject: [PATCH 12/15] v1.5 revise --- .../workflows/{vcl.yml => default_test.yml} | 4 +- .rustfmt.toml | 2 +- ffi/ffi_c/ffi_c_ktb/Cargo.toml | 4 +- ffi/ffi_c/ffi_c_scd/Cargo.toml | 3 +- ffi/ffi_c/ffi_c_vcl/Cargo.toml | 3 +- ffi/ffi_java/ffi_java_ktb/Cargo.toml | 1 + ffi/ffi_java/ffi_java_scd/Cargo.toml | 1 + ffi/ffi_java/ffi_java_vcl/Cargo.toml | 1 + protos/solution/acv/acv.proto | 56 +- protos/src/generated/acv.rs | 2222 ++++++++--------- protos/src/generated/hdk.rs | 6 +- protos/src/generated/mod.rs | 2 +- protos/src/generated/scd.rs | 4 +- protos/src/generated/vcl.rs | 4 +- .../anonymous_ciphertext_voting/src/config.rs | 11 +- .../src/coordinator.rs | 323 ++- .../src/counter.rs | 84 +- .../anonymous_ciphertext_voting/src/lib.rs | 241 +- .../anonymous_ciphertext_voting/src/main.rs | 857 +++++-- .../anonymous_ciphertext_voting/src/utils.rs | 73 + .../src/verifier.rs | 189 +- .../anonymous_ciphertext_voting/src/voter.rs | 197 +- .../hierarchical_deterministic_key/Cargo.toml | 4 +- .../hierarchical_deterministic_key/src/hdk.rs | 45 +- .../Cargo.toml | 2 - .../src/main.rs | 2 +- .../verifiable_confidential_ledger/Cargo.toml | 1 - .../src/main.rs | 3 +- 28 files changed, 2387 insertions(+), 1958 deletions(-) rename .github/workflows/{vcl.yml => default_test.yml} (78%) create mode 100644 solution/anonymous_ciphertext_voting/src/utils.rs diff --git a/.github/workflows/vcl.yml b/.github/workflows/default_test.yml similarity index 78% rename from .github/workflows/vcl.yml rename to .github/workflows/default_test.yml index 4c063bc..5a22438 100644 --- a/.github/workflows/vcl.yml +++ b/.github/workflows/default_test.yml @@ -1,4 +1,4 @@ -name: Rust +name: Default-Test on: push: @@ -14,6 +14,6 @@ jobs: - name: Nightly default run: rustup default nightly - name: Build - run: cargo build --verbose + run: cargo build --all --all-targets --verbose - name: Run tests run: cargo test --verbose diff --git a/.rustfmt.toml b/.rustfmt.toml index de39635..cfb9516 100644 --- a/.rustfmt.toml +++ b/.rustfmt.toml @@ -5,7 +5,7 @@ format_strings = true indent_style = "Block" match_block_trailing_comma = true max_width = 80 -merge_imports = true +imports_granularity = "Crate" normalize_comments = true normalize_doc_attributes = true overflow_delimited_expr = true diff --git a/ffi/ffi_c/ffi_c_ktb/Cargo.toml b/ffi/ffi_c/ffi_c_ktb/Cargo.toml index 2956017..f7d537b 100644 --- a/ffi/ffi_c/ffi_c_ktb/Cargo.toml +++ b/ffi/ffi_c/ffi_c_ktb/Cargo.toml @@ -16,11 +16,9 @@ protobuf = "2.22.1" wedpr_ffi_common = "1.0.0" wedpr_ffi_macros = "1.0.0" wedpr_l_macros = "1.0.0" - - -# This is required to generate C/C++ header files. wedpr_s_hierarchical_deterministic_key = "1.3.0" wedpr_s_protos = "1.3.0" +# This is required to generate C/C++ header files. [build-dependencies] cbindgen = "0.9.0" diff --git a/ffi/ffi_c/ffi_c_scd/Cargo.toml b/ffi/ffi_c/ffi_c_scd/Cargo.toml index 6f86ea2..263517b 100644 --- a/ffi/ffi_c/ffi_c_scd/Cargo.toml +++ b/ffi/ffi_c/ffi_c_scd/Cargo.toml @@ -16,10 +16,9 @@ protobuf = "2.22.1" wedpr_ffi_common = "1.0.0" wedpr_ffi_macros = "1.0.0" wedpr_l_macros = "1.0.0" - -# This is required to generate C/C++ header files. wedpr_s_protos = "1.3.0" wedpr_s_selective_certificate_disclosure = "1.3.0" +# This is required to generate C/C++ header files. [build-dependencies] cbindgen = "0.9.0" diff --git a/ffi/ffi_c/ffi_c_vcl/Cargo.toml b/ffi/ffi_c/ffi_c_vcl/Cargo.toml index c505866..5d2b3c8 100644 --- a/ffi/ffi_c/ffi_c_vcl/Cargo.toml +++ b/ffi/ffi_c/ffi_c_vcl/Cargo.toml @@ -16,11 +16,10 @@ protobuf = "2.22.1" wedpr_ffi_common = "1.0.0" wedpr_ffi_macros = "1.1.0" wedpr_l_macros = "1.0.0" - -# This is required to generate C/C++ header files. wedpr_l_protos = "1.1.0" wedpr_s_protos = { path = "../../../protos" } wedpr_s_verifiable_confidential_ledger = { path = "../../../solution/verifiable_confidential_ledger" } +# This is required to generate C/C++ header files. [build-dependencies] cbindgen = "0.9.0" diff --git a/ffi/ffi_java/ffi_java_ktb/Cargo.toml b/ffi/ffi_java/ffi_java_ktb/Cargo.toml index db0d342..f06f5a3 100644 --- a/ffi/ffi_java/ffi_java_ktb/Cargo.toml +++ b/ffi/ffi_java/ffi_java_ktb/Cargo.toml @@ -18,6 +18,7 @@ wedpr_ffi_macros = "1.1.0" wedpr_s_hierarchical_deterministic_key = "1.3.0" wedpr_s_protos = "1.3.0" +# This is required to generate C/C++ header files. [build-dependencies] cbindgen = "0.9.0" diff --git a/ffi/ffi_java/ffi_java_scd/Cargo.toml b/ffi/ffi_java/ffi_java_scd/Cargo.toml index ee2754b..6c7e826 100644 --- a/ffi/ffi_java/ffi_java_scd/Cargo.toml +++ b/ffi/ffi_java/ffi_java_scd/Cargo.toml @@ -19,6 +19,7 @@ wedpr_l_protos = "1.0.0" wedpr_s_protos = "1.3.0" wedpr_s_selective_certificate_disclosure = "1.3.0" +# This is required to generate C/C++ header files. [build-dependencies] cbindgen = "0.9.0" diff --git a/ffi/ffi_java/ffi_java_vcl/Cargo.toml b/ffi/ffi_java/ffi_java_vcl/Cargo.toml index 1b6c84d..d07a15f 100644 --- a/ffi/ffi_java/ffi_java_vcl/Cargo.toml +++ b/ffi/ffi_java/ffi_java_vcl/Cargo.toml @@ -20,6 +20,7 @@ wedpr_l_protos = "1.1.0" wedpr_s_protos = { path = "../../../protos" } wedpr_s_verifiable_confidential_ledger = { path = "../../../solution/verifiable_confidential_ledger" } +# This is required to generate C/C++ header files. [build-dependencies] cbindgen = "0.9.0" diff --git a/protos/solution/acv/acv.proto b/protos/solution/acv/acv.proto index f32e5f3..fa06820 100644 --- a/protos/solution/acv/acv.proto +++ b/protos/solution/acv/acv.proto @@ -1,4 +1,4 @@ -// Copyright 2020 WeDPR Lab Project Authors. Licensed under Apache-2.0. +// Copyright 2021 WeDPR Lab Project Authors. Licensed under Apache-2.0. syntax = "proto3"; @@ -11,34 +11,34 @@ message CandidateList { repeated string candidate = 1; } -// System parameters. -message SystemParametersStorage { +// Shared system parameters to initialize a poll. +message PollParametersStorage { bytes poll_point = 1; CandidateList candidates = 2; } -// Counter's secret value. +// Secret of a counter. message CounterSecret { bytes poll_secret_share = 1; } -// Voter's secret value. +// Secret of a voter. message VoterSecret { bytes voter_secret = 1; } -// Request of voter's registration. +// Request of registering a voter. message RegistrationRequest { RegistrationBlindingPoint weight_point = 1; } -// delete? +// Blinding points for a voter registration. message RegistrationBlindingPoint { bytes blinding_poll_point = 1; bytes blinding_basepoint_g2 = 2; } -// Response of coordinator for voter's registration. +// Response of voter registration. message RegistrationResponse { uint32 voter_weight = 1; Ballot ballot = 2; @@ -51,30 +51,29 @@ message Ballot { bytes ciphertext2 = 2; } - -// Request of generating system parameter from a counter. -message CounterSystemParametersShareRequest { +// Request of aggregating a part of system parameters from a counter. +message CounterParametersShareRequest { string counter_id = 1; bytes poll_point_share = 2; } -// Requests of generating system parameter from all counters. -message CounterSystemParametersStorage { - repeated CounterSystemParametersShareRequest counter_parameters_request = 1; +// Shared system parameters to initialize a group of counters. +message CounterParametersStorage { + repeated CounterParametersShareRequest counter_parameters_share = 1; } -// Choice of ballot casting for each candidate. +// Vote choice for a candidate. message VoteChoice { string candidate = 1; uint32 value = 2; } -// Choices for all candidate. +// Choice list for all candidates. message VoteChoices { repeated VoteChoice choice = 1; } -// Ciphertext ballot for each candidate. +// Ciphertext ballot for a candidate. message CandidateBallot { string candidate = 1; Ballot ballot = 2; @@ -85,22 +84,21 @@ message BallotProof { bytes format_proof = 1; } -// Pair of candidate index and the ballot proof he received. -message StringToCandidateBallotProofPair { +// Pair of string (candidate id) and BallotProof. +message StringToBallotProofPair { string key = 1; BallotProof value = 2; } -// Do not use Map, cause unordered in blockchain -// Request of polling for all candidates. +// Request of voting for all candidates. message VoteRequest { VoteStorage vote = 1; - repeated StringToCandidateBallotProofPair ballot_proof = 2; + repeated StringToBallotProofPair ballot_proof = 2; bytes range_proof = 3; bytes sum_balance_proof = 4; } -// Polling for each candidates. +// Ciphertext ballot for all candidates. message VoteStorage { bytes signature = 1; Ballot blank_ballot = 2; @@ -108,32 +106,32 @@ message VoteStorage { repeated CandidateBallot voted_ballot = 4; } -// Decrypted ballot and ZKP data to verify the process of counting of each counter. +// Partially decrypted ballot and associated ZKP data for a candidate. message CountingPart { string counter_id = 1; bytes blinding_c2 = 2; bytes equality_proof = 3; } -// Pair of candidate index and the decrypted ballot he received. +// Pair of string (candidate id) and CountingPart. message StringToCountingPartPair { string key = 1; CountingPart value = 2; } -// Decrypted ballot and ZKP data to verify the process of counting of all counters. +// Partially decrypted ballots and associated ZKP data for a poll. message DecryptedResultPartStorage { CountingPart blank_part = 1; repeated StringToCountingPartPair candidate_part = 2; } -// Final result of all candidates. +// Fully decrypted result of a poll. message VoteResultStorage { repeated StringToInt64Pair result = 1; } -// Final result of each candidate. +// Pair of string (candidate id) and number. message StringToInt64Pair { string key = 1; int64 value = 2; -} \ No newline at end of file +} diff --git a/protos/src/generated/acv.rs b/protos/src/generated/acv.rs index 329ba2d..0d93ea2 100644 --- a/protos/src/generated/acv.rs +++ b/protos/src/generated/acv.rs @@ -1,6 +1,6 @@ -// Copyright 2020 WeDPR Lab Project Authors. Licensed under Apache-2.0. +// Copyright 2021 WeDPR Lab Project Authors. Licensed under Apache-2.0. -// This file is generated by rust-protobuf 2.25.1. Do not edit +// This file is generated by rust-protobuf 2.22.1. Do not edit // @generated // https://github.com/rust-lang/rust-clippy/issues/702 @@ -23,56 +23,55 @@ /// Generated files are compatible only with the same version /// of protobuf runtime. -// const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_25_1; +// const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_22_1; #[derive(PartialEq,Clone,Default)] -pub struct CounterSecret { +pub struct CandidateList { // message fields - pub poll_secret_share: ::std::vec::Vec, + pub candidate: ::protobuf::RepeatedField<::std::string::String>, // special fields pub unknown_fields: ::protobuf::UnknownFields, pub cached_size: ::protobuf::CachedSize, } -impl<'a> ::std::default::Default for &'a CounterSecret { - fn default() -> &'a CounterSecret { - ::default_instance() +impl<'a> ::std::default::Default for &'a CandidateList { + fn default() -> &'a CandidateList { + ::default_instance() } } -impl CounterSecret { - pub fn new() -> CounterSecret { +impl CandidateList { + pub fn new() -> CandidateList { ::std::default::Default::default() } - // bytes poll_secret_share = 1; + // repeated string candidate = 1; - pub fn get_poll_secret_share(&self) -> &[u8] { - &self.poll_secret_share + pub fn get_candidate(&self) -> &[::std::string::String] { + &self.candidate } - pub fn clear_poll_secret_share(&mut self) { - self.poll_secret_share.clear(); + pub fn clear_candidate(&mut self) { + self.candidate.clear(); } // Param is passed by value, moved - pub fn set_poll_secret_share(&mut self, v: ::std::vec::Vec) { - self.poll_secret_share = v; + pub fn set_candidate(&mut self, v: ::protobuf::RepeatedField<::std::string::String>) { + self.candidate = v; } // Mutable pointer to the field. - // If field is not initialized, it is initialized with default value first. - pub fn mut_poll_secret_share(&mut self) -> &mut ::std::vec::Vec { - &mut self.poll_secret_share + pub fn mut_candidate(&mut self) -> &mut ::protobuf::RepeatedField<::std::string::String> { + &mut self.candidate } // Take field - pub fn take_poll_secret_share(&mut self) -> ::std::vec::Vec { - ::std::mem::replace(&mut self.poll_secret_share, ::std::vec::Vec::new()) + pub fn take_candidate(&mut self) -> ::protobuf::RepeatedField<::std::string::String> { + ::std::mem::replace(&mut self.candidate, ::protobuf::RepeatedField::new()) } } -impl ::protobuf::Message for CounterSecret { +impl ::protobuf::Message for CandidateList { fn is_initialized(&self) -> bool { true } @@ -82,7 +81,7 @@ impl ::protobuf::Message for CounterSecret { 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.poll_secret_share)?; + ::protobuf::rt::read_repeated_string_into(wire_type, is, &mut self.candidate)?; }, _ => { ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; @@ -96,18 +95,18 @@ impl ::protobuf::Message for CounterSecret { #[allow(unused_variables)] fn compute_size(&self) -> u32 { let mut my_size = 0; - if !self.poll_secret_share.is_empty() { - my_size += ::protobuf::rt::bytes_size(1, &self.poll_secret_share); - } + for value in &self.candidate { + my_size += ::protobuf::rt::string_size(1, &value); + }; 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.poll_secret_share.is_empty() { - os.write_bytes(1, &self.poll_secret_share)?; - } + for v in &self.candidate { + os.write_string(1, &v)?; + }; os.write_unknown_fields(self.get_unknown_fields())?; ::std::result::Result::Ok(()) } @@ -138,128 +137,140 @@ impl ::protobuf::Message for CounterSecret { Self::descriptor_static() } - fn new() -> CounterSecret { - CounterSecret::new() + fn new() -> CandidateList { + CandidateList::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>( - "poll_secret_share", - |m: &CounterSecret| { &m.poll_secret_share }, - |m: &mut CounterSecret| { &mut m.poll_secret_share }, + fields.push(::protobuf::reflect::accessor::make_repeated_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( + "candidate", + |m: &CandidateList| { &m.candidate }, + |m: &mut CandidateList| { &mut m.candidate }, )); - ::protobuf::reflect::MessageDescriptor::new_pb_name::( - "CounterSecret", + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "CandidateList", fields, file_descriptor_proto() ) }) } - fn default_instance() -> &'static CounterSecret { - static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; - instance.get(CounterSecret::new) + fn default_instance() -> &'static CandidateList { + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(CandidateList::new) } } -impl ::protobuf::Clear for CounterSecret { +impl ::protobuf::Clear for CandidateList { fn clear(&mut self) { - self.poll_secret_share.clear(); + self.candidate.clear(); self.unknown_fields.clear(); } } -impl ::std::fmt::Debug for CounterSecret { +impl ::std::fmt::Debug for CandidateList { fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { ::protobuf::text_format::fmt(self, f) } } -impl ::protobuf::reflect::ProtobufValue for CounterSecret { +impl ::protobuf::reflect::ProtobufValue for CandidateList { fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { ::protobuf::reflect::ReflectValueRef::Message(self) } } #[derive(PartialEq,Clone,Default)] -pub struct CounterSystemParametersShareRequest { +pub struct PollParametersStorage { // message fields - pub counter_id: ::std::string::String, - pub poll_point_share: ::std::vec::Vec, + pub poll_point: ::std::vec::Vec, + pub candidates: ::protobuf::SingularPtrField, // special fields pub unknown_fields: ::protobuf::UnknownFields, pub cached_size: ::protobuf::CachedSize, } -impl<'a> ::std::default::Default for &'a CounterSystemParametersShareRequest { - fn default() -> &'a CounterSystemParametersShareRequest { - ::default_instance() +impl<'a> ::std::default::Default for &'a PollParametersStorage { + fn default() -> &'a PollParametersStorage { + ::default_instance() } } -impl CounterSystemParametersShareRequest { - pub fn new() -> CounterSystemParametersShareRequest { +impl PollParametersStorage { + pub fn new() -> PollParametersStorage { ::std::default::Default::default() } - // string counter_id = 1; + // bytes poll_point = 1; - pub fn get_counter_id(&self) -> &str { - &self.counter_id + pub fn get_poll_point(&self) -> &[u8] { + &self.poll_point } - pub fn clear_counter_id(&mut self) { - self.counter_id.clear(); + pub fn clear_poll_point(&mut self) { + self.poll_point.clear(); } // Param is passed by value, moved - pub fn set_counter_id(&mut self, v: ::std::string::String) { - self.counter_id = v; + pub fn set_poll_point(&mut self, v: ::std::vec::Vec) { + self.poll_point = 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 mut_poll_point(&mut self) -> &mut ::std::vec::Vec { + &mut self.poll_point } // 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 take_poll_point(&mut self) -> ::std::vec::Vec { + ::std::mem::replace(&mut self.poll_point, ::std::vec::Vec::new()) } - // bytes poll_point_share = 2; + // .com.webank.wedpr.acv.proto.CandidateList candidates = 2; - pub fn get_poll_point_share(&self) -> &[u8] { - &self.poll_point_share + pub fn get_candidates(&self) -> &CandidateList { + self.candidates.as_ref().unwrap_or_else(|| ::default_instance()) } - pub fn clear_poll_point_share(&mut self) { - self.poll_point_share.clear(); + pub fn clear_candidates(&mut self) { + self.candidates.clear(); + } + + pub fn has_candidates(&self) -> bool { + self.candidates.is_some() } // Param is passed by value, moved - pub fn set_poll_point_share(&mut self, v: ::std::vec::Vec) { - self.poll_point_share = v; + pub fn set_candidates(&mut self, v: CandidateList) { + self.candidates = ::protobuf::SingularPtrField::some(v); } // Mutable pointer to the field. // If field is not initialized, it is initialized with default value first. - pub fn mut_poll_point_share(&mut self) -> &mut ::std::vec::Vec { - &mut self.poll_point_share + pub fn mut_candidates(&mut self) -> &mut CandidateList { + if self.candidates.is_none() { + self.candidates.set_default(); + } + self.candidates.as_mut().unwrap() } // Take field - pub fn take_poll_point_share(&mut self) -> ::std::vec::Vec { - ::std::mem::replace(&mut self.poll_point_share, ::std::vec::Vec::new()) + pub fn take_candidates(&mut self) -> CandidateList { + self.candidates.take().unwrap_or_else(|| CandidateList::new()) } } -impl ::protobuf::Message for CounterSystemParametersShareRequest { +impl ::protobuf::Message for PollParametersStorage { fn is_initialized(&self) -> bool { + for v in &self.candidates { + if !v.is_initialized() { + return false; + } + }; true } @@ -268,10 +279,10 @@ impl ::protobuf::Message for CounterSystemParametersShareRequest { 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)?; + ::protobuf::rt::read_singular_proto3_bytes_into(wire_type, is, &mut self.poll_point)?; }, 2 => { - ::protobuf::rt::read_singular_proto3_bytes_into(wire_type, is, &mut self.poll_point_share)?; + ::protobuf::rt::read_singular_message_into(wire_type, is, &mut self.candidates)?; }, _ => { ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; @@ -285,11 +296,12 @@ impl ::protobuf::Message for CounterSystemParametersShareRequest { #[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.poll_point.is_empty() { + my_size += ::protobuf::rt::bytes_size(1, &self.poll_point); } - if !self.poll_point_share.is_empty() { - my_size += ::protobuf::rt::bytes_size(2, &self.poll_point_share); + if let Some(ref v) = self.candidates.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); @@ -297,11 +309,13 @@ impl ::protobuf::Message for CounterSystemParametersShareRequest { } 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.poll_point.is_empty() { + os.write_bytes(1, &self.poll_point)?; } - if !self.poll_point_share.is_empty() { - os.write_bytes(2, &self.poll_point_share)?; + if let Some(ref v) = self.candidates.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(()) @@ -333,111 +347,107 @@ impl ::protobuf::Message for CounterSystemParametersShareRequest { Self::descriptor_static() } - fn new() -> CounterSystemParametersShareRequest { - CounterSystemParametersShareRequest::new() + fn new() -> PollParametersStorage { + PollParametersStorage::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: &CounterSystemParametersShareRequest| { &m.counter_id }, - |m: &mut CounterSystemParametersShareRequest| { &mut m.counter_id }, - )); fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( - "poll_point_share", - |m: &CounterSystemParametersShareRequest| { &m.poll_point_share }, - |m: &mut CounterSystemParametersShareRequest| { &mut m.poll_point_share }, + "poll_point", + |m: &PollParametersStorage| { &m.poll_point }, + |m: &mut PollParametersStorage| { &mut m.poll_point }, + )); + fields.push(::protobuf::reflect::accessor::make_singular_ptr_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( + "candidates", + |m: &PollParametersStorage| { &m.candidates }, + |m: &mut PollParametersStorage| { &mut m.candidates }, )); - ::protobuf::reflect::MessageDescriptor::new_pb_name::( - "CounterSystemParametersShareRequest", + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "PollParametersStorage", fields, file_descriptor_proto() ) }) } - fn default_instance() -> &'static CounterSystemParametersShareRequest { - static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; - instance.get(CounterSystemParametersShareRequest::new) + fn default_instance() -> &'static PollParametersStorage { + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(PollParametersStorage::new) } } -impl ::protobuf::Clear for CounterSystemParametersShareRequest { +impl ::protobuf::Clear for PollParametersStorage { fn clear(&mut self) { - self.counter_id.clear(); - self.poll_point_share.clear(); + self.poll_point.clear(); + self.candidates.clear(); self.unknown_fields.clear(); } } -impl ::std::fmt::Debug for CounterSystemParametersShareRequest { +impl ::std::fmt::Debug for PollParametersStorage { fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { ::protobuf::text_format::fmt(self, f) } } -impl ::protobuf::reflect::ProtobufValue for CounterSystemParametersShareRequest { +impl ::protobuf::reflect::ProtobufValue for PollParametersStorage { fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { ::protobuf::reflect::ReflectValueRef::Message(self) } } #[derive(PartialEq,Clone,Default)] -pub struct CounterSystemParametersStorage { +pub struct CounterSecret { // message fields - pub counter_parameters_request: ::protobuf::RepeatedField, + pub poll_secret_share: ::std::vec::Vec, // special fields pub unknown_fields: ::protobuf::UnknownFields, pub cached_size: ::protobuf::CachedSize, } -impl<'a> ::std::default::Default for &'a CounterSystemParametersStorage { - fn default() -> &'a CounterSystemParametersStorage { - ::default_instance() +impl<'a> ::std::default::Default for &'a CounterSecret { + fn default() -> &'a CounterSecret { + ::default_instance() } } -impl CounterSystemParametersStorage { - pub fn new() -> CounterSystemParametersStorage { +impl CounterSecret { + pub fn new() -> CounterSecret { ::std::default::Default::default() } - // repeated .com.webank.wedpr.acv.proto.CounterSystemParametersShareRequest counter_parameters_request = 1; + // bytes poll_secret_share = 1; - pub fn get_counter_parameters_request(&self) -> &[CounterSystemParametersShareRequest] { - &self.counter_parameters_request + pub fn get_poll_secret_share(&self) -> &[u8] { + &self.poll_secret_share } - pub fn clear_counter_parameters_request(&mut self) { - self.counter_parameters_request.clear(); + pub fn clear_poll_secret_share(&mut self) { + self.poll_secret_share.clear(); } // Param is passed by value, moved - pub fn set_counter_parameters_request(&mut self, v: ::protobuf::RepeatedField) { - self.counter_parameters_request = v; + pub fn set_poll_secret_share(&mut self, v: ::std::vec::Vec) { + self.poll_secret_share = v; } // Mutable pointer to the field. - pub fn mut_counter_parameters_request(&mut self) -> &mut ::protobuf::RepeatedField { - &mut self.counter_parameters_request + // If field is not initialized, it is initialized with default value first. + pub fn mut_poll_secret_share(&mut self) -> &mut ::std::vec::Vec { + &mut self.poll_secret_share } // Take field - pub fn take_counter_parameters_request(&mut self) -> ::protobuf::RepeatedField { - ::std::mem::replace(&mut self.counter_parameters_request, ::protobuf::RepeatedField::new()) + pub fn take_poll_secret_share(&mut self) -> ::std::vec::Vec { + ::std::mem::replace(&mut self.poll_secret_share, ::std::vec::Vec::new()) } } -impl ::protobuf::Message for CounterSystemParametersStorage { +impl ::protobuf::Message for CounterSecret { fn is_initialized(&self) -> bool { - for v in &self.counter_parameters_request { - if !v.is_initialized() { - return false; - } - }; true } @@ -446,7 +456,7 @@ impl ::protobuf::Message for CounterSystemParametersStorage { let (field_number, wire_type) = is.read_tag_unpack()?; match field_number { 1 => { - ::protobuf::rt::read_repeated_message_into(wire_type, is, &mut self.counter_parameters_request)?; + ::protobuf::rt::read_singular_proto3_bytes_into(wire_type, is, &mut self.poll_secret_share)?; }, _ => { ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; @@ -460,21 +470,18 @@ impl ::protobuf::Message for CounterSystemParametersStorage { #[allow(unused_variables)] fn compute_size(&self) -> u32 { let mut my_size = 0; - for value in &self.counter_parameters_request { - let len = value.compute_size(); - my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; - }; + if !self.poll_secret_share.is_empty() { + my_size += ::protobuf::rt::bytes_size(1, &self.poll_secret_share); + } 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<()> { - for v in &self.counter_parameters_request { - 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.poll_secret_share.is_empty() { + os.write_bytes(1, &self.poll_secret_share)?; + } os.write_unknown_fields(self.get_unknown_fields())?; ::std::result::Result::Ok(()) } @@ -505,47 +512,47 @@ impl ::protobuf::Message for CounterSystemParametersStorage { Self::descriptor_static() } - fn new() -> CounterSystemParametersStorage { - CounterSystemParametersStorage::new() + fn new() -> CounterSecret { + CounterSecret::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_repeated_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( - "counter_parameters_request", - |m: &CounterSystemParametersStorage| { &m.counter_parameters_request }, - |m: &mut CounterSystemParametersStorage| { &mut m.counter_parameters_request }, + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( + "poll_secret_share", + |m: &CounterSecret| { &m.poll_secret_share }, + |m: &mut CounterSecret| { &mut m.poll_secret_share }, )); - ::protobuf::reflect::MessageDescriptor::new_pb_name::( - "CounterSystemParametersStorage", + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "CounterSecret", fields, file_descriptor_proto() ) }) } - fn default_instance() -> &'static CounterSystemParametersStorage { - static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; - instance.get(CounterSystemParametersStorage::new) + fn default_instance() -> &'static CounterSecret { + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(CounterSecret::new) } } -impl ::protobuf::Clear for CounterSystemParametersStorage { +impl ::protobuf::Clear for CounterSecret { fn clear(&mut self) { - self.counter_parameters_request.clear(); + self.poll_secret_share.clear(); self.unknown_fields.clear(); } } -impl ::std::fmt::Debug for CounterSystemParametersStorage { +impl ::std::fmt::Debug for CounterSecret { fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { ::protobuf::text_format::fmt(self, f) } } -impl ::protobuf::reflect::ProtobufValue for CounterSystemParametersStorage { +impl ::protobuf::reflect::ProtobufValue for CounterSecret { fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { ::protobuf::reflect::ReflectValueRef::Message(self) } @@ -1538,69 +1545,80 @@ impl ::protobuf::reflect::ProtobufValue for Ballot { } #[derive(PartialEq,Clone,Default)] -pub struct VoteChoice { +pub struct CounterParametersShareRequest { // message fields - pub candidate: ::std::string::String, - pub value: u32, + pub counter_id: ::std::string::String, + pub poll_point_share: ::std::vec::Vec, // special fields pub unknown_fields: ::protobuf::UnknownFields, pub cached_size: ::protobuf::CachedSize, } -impl<'a> ::std::default::Default for &'a VoteChoice { - fn default() -> &'a VoteChoice { - ::default_instance() +impl<'a> ::std::default::Default for &'a CounterParametersShareRequest { + fn default() -> &'a CounterParametersShareRequest { + ::default_instance() } } -impl VoteChoice { - pub fn new() -> VoteChoice { +impl CounterParametersShareRequest { + pub fn new() -> CounterParametersShareRequest { ::std::default::Default::default() } - // string candidate = 1; + // string counter_id = 1; - pub fn get_candidate(&self) -> &str { - &self.candidate + pub fn get_counter_id(&self) -> &str { + &self.counter_id } - pub fn clear_candidate(&mut self) { - self.candidate.clear(); + pub fn clear_counter_id(&mut self) { + self.counter_id.clear(); } // Param is passed by value, moved - pub fn set_candidate(&mut self, v: ::std::string::String) { - self.candidate = v; + 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_candidate(&mut self) -> &mut ::std::string::String { - &mut self.candidate + pub fn mut_counter_id(&mut self) -> &mut ::std::string::String { + &mut self.counter_id } // Take field - pub fn take_candidate(&mut self) -> ::std::string::String { - ::std::mem::replace(&mut self.candidate, ::std::string::String::new()) + pub fn take_counter_id(&mut self) -> ::std::string::String { + ::std::mem::replace(&mut self.counter_id, ::std::string::String::new()) } - // uint32 value = 2; + // bytes poll_point_share = 2; - pub fn get_value(&self) -> u32 { - self.value + pub fn get_poll_point_share(&self) -> &[u8] { + &self.poll_point_share } - pub fn clear_value(&mut self) { - self.value = 0; + pub fn clear_poll_point_share(&mut self) { + self.poll_point_share.clear(); } // Param is passed by value, moved - pub fn set_value(&mut self, v: u32) { - self.value = v; + pub fn set_poll_point_share(&mut self, v: ::std::vec::Vec) { + self.poll_point_share = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_poll_point_share(&mut self) -> &mut ::std::vec::Vec { + &mut self.poll_point_share + } + + // Take field + pub fn take_poll_point_share(&mut self) -> ::std::vec::Vec { + ::std::mem::replace(&mut self.poll_point_share, ::std::vec::Vec::new()) } } -impl ::protobuf::Message for VoteChoice { +impl ::protobuf::Message for CounterParametersShareRequest { fn is_initialized(&self) -> bool { true } @@ -1610,14 +1628,10 @@ impl ::protobuf::Message for VoteChoice { 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.candidate)?; + ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.counter_id)?; }, 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_singular_proto3_bytes_into(wire_type, is, &mut self.poll_point_share)?; }, _ => { ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; @@ -1631,11 +1645,11 @@ impl ::protobuf::Message for VoteChoice { #[allow(unused_variables)] fn compute_size(&self) -> u32 { let mut my_size = 0; - if !self.candidate.is_empty() { - my_size += ::protobuf::rt::string_size(1, &self.candidate); + if !self.counter_id.is_empty() { + my_size += ::protobuf::rt::string_size(1, &self.counter_id); } - if self.value != 0 { - my_size += ::protobuf::rt::value_size(2, self.value, ::protobuf::wire_format::WireTypeVarint); + if !self.poll_point_share.is_empty() { + my_size += ::protobuf::rt::bytes_size(2, &self.poll_point_share); } my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); self.cached_size.set(my_size); @@ -1643,11 +1657,11 @@ impl ::protobuf::Message for VoteChoice { } fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { - if !self.candidate.is_empty() { - os.write_string(1, &self.candidate)?; + if !self.counter_id.is_empty() { + os.write_string(1, &self.counter_id)?; } - if self.value != 0 { - os.write_uint32(2, self.value)?; + if !self.poll_point_share.is_empty() { + os.write_bytes(2, &self.poll_point_share)?; } os.write_unknown_fields(self.get_unknown_fields())?; ::std::result::Result::Ok(()) @@ -1679,8 +1693,8 @@ impl ::protobuf::Message for VoteChoice { Self::descriptor_static() } - fn new() -> VoteChoice { - VoteChoice::new() + fn new() -> CounterParametersShareRequest { + CounterParametersShareRequest::new() } fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { @@ -1688,98 +1702,98 @@ impl ::protobuf::Message for VoteChoice { descriptor.get(|| { let mut fields = ::std::vec::Vec::new(); fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( - "candidate", - |m: &VoteChoice| { &m.candidate }, - |m: &mut VoteChoice| { &mut m.candidate }, + "counter_id", + |m: &CounterParametersShareRequest| { &m.counter_id }, + |m: &mut CounterParametersShareRequest| { &mut m.counter_id }, )); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeUint32>( - "value", - |m: &VoteChoice| { &m.value }, - |m: &mut VoteChoice| { &mut m.value }, + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( + "poll_point_share", + |m: &CounterParametersShareRequest| { &m.poll_point_share }, + |m: &mut CounterParametersShareRequest| { &mut m.poll_point_share }, )); - ::protobuf::reflect::MessageDescriptor::new_pb_name::( - "VoteChoice", + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "CounterParametersShareRequest", fields, file_descriptor_proto() ) }) } - fn default_instance() -> &'static VoteChoice { - static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; - instance.get(VoteChoice::new) + fn default_instance() -> &'static CounterParametersShareRequest { + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(CounterParametersShareRequest::new) } } -impl ::protobuf::Clear for VoteChoice { +impl ::protobuf::Clear for CounterParametersShareRequest { fn clear(&mut self) { - self.candidate.clear(); - self.value = 0; + self.counter_id.clear(); + self.poll_point_share.clear(); self.unknown_fields.clear(); } } -impl ::std::fmt::Debug for VoteChoice { +impl ::std::fmt::Debug for CounterParametersShareRequest { fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { ::protobuf::text_format::fmt(self, f) } } -impl ::protobuf::reflect::ProtobufValue for VoteChoice { +impl ::protobuf::reflect::ProtobufValue for CounterParametersShareRequest { fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { ::protobuf::reflect::ReflectValueRef::Message(self) } } #[derive(PartialEq,Clone,Default)] -pub struct VoteChoices { +pub struct CounterParametersStorage { // message fields - pub choice: ::protobuf::RepeatedField, + pub counter_parameters_share: ::protobuf::RepeatedField, // special fields pub unknown_fields: ::protobuf::UnknownFields, pub cached_size: ::protobuf::CachedSize, } -impl<'a> ::std::default::Default for &'a VoteChoices { - fn default() -> &'a VoteChoices { - ::default_instance() +impl<'a> ::std::default::Default for &'a CounterParametersStorage { + fn default() -> &'a CounterParametersStorage { + ::default_instance() } } -impl VoteChoices { - pub fn new() -> VoteChoices { +impl CounterParametersStorage { + pub fn new() -> CounterParametersStorage { ::std::default::Default::default() } - // repeated .com.webank.wedpr.acv.proto.VoteChoice choice = 1; + // repeated .com.webank.wedpr.acv.proto.CounterParametersShareRequest counter_parameters_share = 1; - pub fn get_choice(&self) -> &[VoteChoice] { - &self.choice + pub fn get_counter_parameters_share(&self) -> &[CounterParametersShareRequest] { + &self.counter_parameters_share } - pub fn clear_choice(&mut self) { - self.choice.clear(); + pub fn clear_counter_parameters_share(&mut self) { + self.counter_parameters_share.clear(); } // Param is passed by value, moved - pub fn set_choice(&mut self, v: ::protobuf::RepeatedField) { - self.choice = v; + pub fn set_counter_parameters_share(&mut self, v: ::protobuf::RepeatedField) { + self.counter_parameters_share = v; } // Mutable pointer to the field. - pub fn mut_choice(&mut self) -> &mut ::protobuf::RepeatedField { - &mut self.choice + pub fn mut_counter_parameters_share(&mut self) -> &mut ::protobuf::RepeatedField { + &mut self.counter_parameters_share } // Take field - pub fn take_choice(&mut self) -> ::protobuf::RepeatedField { - ::std::mem::replace(&mut self.choice, ::protobuf::RepeatedField::new()) + pub fn take_counter_parameters_share(&mut self) -> ::protobuf::RepeatedField { + ::std::mem::replace(&mut self.counter_parameters_share, ::protobuf::RepeatedField::new()) } } -impl ::protobuf::Message for VoteChoices { +impl ::protobuf::Message for CounterParametersStorage { fn is_initialized(&self) -> bool { - for v in &self.choice { + for v in &self.counter_parameters_share { if !v.is_initialized() { return false; } @@ -1792,7 +1806,7 @@ impl ::protobuf::Message for VoteChoices { let (field_number, wire_type) = is.read_tag_unpack()?; match field_number { 1 => { - ::protobuf::rt::read_repeated_message_into(wire_type, is, &mut self.choice)?; + ::protobuf::rt::read_repeated_message_into(wire_type, is, &mut self.counter_parameters_share)?; }, _ => { ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; @@ -1806,7 +1820,7 @@ impl ::protobuf::Message for VoteChoices { #[allow(unused_variables)] fn compute_size(&self) -> u32 { let mut my_size = 0; - for value in &self.choice { + for value in &self.counter_parameters_share { let len = value.compute_size(); my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; }; @@ -1816,7 +1830,7 @@ impl ::protobuf::Message for VoteChoices { } fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { - for v in &self.choice { + for v in &self.counter_parameters_share { os.write_tag(1, ::protobuf::wire_format::WireTypeLengthDelimited)?; os.write_raw_varint32(v.get_cached_size())?; v.write_to_with_cached_sizes(os)?; @@ -1851,70 +1865,70 @@ impl ::protobuf::Message for VoteChoices { Self::descriptor_static() } - fn new() -> VoteChoices { - VoteChoices::new() + fn new() -> CounterParametersStorage { + CounterParametersStorage::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_repeated_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( - "choice", - |m: &VoteChoices| { &m.choice }, - |m: &mut VoteChoices| { &mut m.choice }, + fields.push(::protobuf::reflect::accessor::make_repeated_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( + "counter_parameters_share", + |m: &CounterParametersStorage| { &m.counter_parameters_share }, + |m: &mut CounterParametersStorage| { &mut m.counter_parameters_share }, )); - ::protobuf::reflect::MessageDescriptor::new_pb_name::( - "VoteChoices", + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "CounterParametersStorage", fields, file_descriptor_proto() ) }) } - fn default_instance() -> &'static VoteChoices { - static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; - instance.get(VoteChoices::new) + fn default_instance() -> &'static CounterParametersStorage { + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(CounterParametersStorage::new) } } -impl ::protobuf::Clear for VoteChoices { +impl ::protobuf::Clear for CounterParametersStorage { fn clear(&mut self) { - self.choice.clear(); + self.counter_parameters_share.clear(); self.unknown_fields.clear(); } } -impl ::std::fmt::Debug for VoteChoices { +impl ::std::fmt::Debug for CounterParametersStorage { fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { ::protobuf::text_format::fmt(self, f) } } -impl ::protobuf::reflect::ProtobufValue for VoteChoices { +impl ::protobuf::reflect::ProtobufValue for CounterParametersStorage { fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { ::protobuf::reflect::ReflectValueRef::Message(self) } } #[derive(PartialEq,Clone,Default)] -pub struct CandidateBallot { +pub struct VoteChoice { // message fields pub candidate: ::std::string::String, - pub ballot: ::protobuf::SingularPtrField, + pub value: u32, // special fields pub unknown_fields: ::protobuf::UnknownFields, pub cached_size: ::protobuf::CachedSize, } -impl<'a> ::std::default::Default for &'a CandidateBallot { - fn default() -> &'a CandidateBallot { - ::default_instance() +impl<'a> ::std::default::Default for &'a VoteChoice { + fn default() -> &'a VoteChoice { + ::default_instance() } } -impl CandidateBallot { - pub fn new() -> CandidateBallot { +impl VoteChoice { + pub fn new() -> VoteChoice { ::std::default::Default::default() } @@ -1944,47 +1958,24 @@ impl CandidateBallot { ::std::mem::replace(&mut self.candidate, ::std::string::String::new()) } - // .com.webank.wedpr.acv.proto.Ballot ballot = 2; + // uint32 value = 2; - pub fn get_ballot(&self) -> &Ballot { - self.ballot.as_ref().unwrap_or_else(|| ::default_instance()) - } - pub fn clear_ballot(&mut self) { - self.ballot.clear(); + pub fn get_value(&self) -> u32 { + self.value } - - pub fn has_ballot(&self) -> bool { - self.ballot.is_some() + pub fn clear_value(&mut self) { + self.value = 0; } // Param is passed by value, moved - 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_ballot(&mut self) -> &mut Ballot { - if self.ballot.is_none() { - self.ballot.set_default(); - } - self.ballot.as_mut().unwrap() - } - - // Take field - pub fn take_ballot(&mut self) -> Ballot { - self.ballot.take().unwrap_or_else(|| Ballot::new()) + pub fn set_value(&mut self, v: u32) { + self.value = v; } } -impl ::protobuf::Message for CandidateBallot { +impl ::protobuf::Message for VoteChoice { fn is_initialized(&self) -> bool { - for v in &self.ballot { - if !v.is_initialized() { - return false; - } - }; true } @@ -1996,7 +1987,11 @@ impl ::protobuf::Message for CandidateBallot { ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.candidate)?; }, 2 => { - ::protobuf::rt::read_singular_message_into(wire_type, is, &mut self.ballot)?; + 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())?; @@ -2013,9 +2008,8 @@ impl ::protobuf::Message for CandidateBallot { if !self.candidate.is_empty() { my_size += ::protobuf::rt::string_size(1, &self.candidate); } - 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; + 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); @@ -2026,10 +2020,8 @@ impl ::protobuf::Message for CandidateBallot { if !self.candidate.is_empty() { os.write_string(1, &self.candidate)?; } - if let Some(ref v) = self.ballot.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)?; + if self.value != 0 { + os.write_uint32(2, self.value)?; } os.write_unknown_fields(self.get_unknown_fields())?; ::std::result::Result::Ok(()) @@ -2061,8 +2053,8 @@ impl ::protobuf::Message for CandidateBallot { Self::descriptor_static() } - fn new() -> CandidateBallot { - CandidateBallot::new() + fn new() -> VoteChoice { + VoteChoice::new() } fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { @@ -2071,202 +2063,97 @@ impl ::protobuf::Message for CandidateBallot { let mut fields = ::std::vec::Vec::new(); fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( "candidate", - |m: &CandidateBallot| { &m.candidate }, - |m: &mut CandidateBallot| { &mut m.candidate }, + |m: &VoteChoice| { &m.candidate }, + |m: &mut VoteChoice| { &mut m.candidate }, )); - fields.push(::protobuf::reflect::accessor::make_singular_ptr_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( - "ballot", - |m: &CandidateBallot| { &m.ballot }, - |m: &mut CandidateBallot| { &mut m.ballot }, + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeUint32>( + "value", + |m: &VoteChoice| { &m.value }, + |m: &mut VoteChoice| { &mut m.value }, )); - ::protobuf::reflect::MessageDescriptor::new_pb_name::( - "CandidateBallot", + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "VoteChoice", fields, file_descriptor_proto() ) }) } - fn default_instance() -> &'static CandidateBallot { - static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; - instance.get(CandidateBallot::new) + fn default_instance() -> &'static VoteChoice { + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(VoteChoice::new) } } -impl ::protobuf::Clear for CandidateBallot { +impl ::protobuf::Clear for VoteChoice { fn clear(&mut self) { self.candidate.clear(); - self.ballot.clear(); + self.value = 0; self.unknown_fields.clear(); } } -impl ::std::fmt::Debug for CandidateBallot { +impl ::std::fmt::Debug for VoteChoice { fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { ::protobuf::text_format::fmt(self, f) } } -impl ::protobuf::reflect::ProtobufValue for CandidateBallot { +impl ::protobuf::reflect::ProtobufValue for VoteChoice { fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { ::protobuf::reflect::ReflectValueRef::Message(self) } } #[derive(PartialEq,Clone,Default)] -pub struct VoteStorage { +pub struct VoteChoices { // message fields - pub signature: ::std::vec::Vec, - pub blank_ballot: ::protobuf::SingularPtrField, - pub rest_ballot: ::protobuf::SingularPtrField, - pub voted_ballot: ::protobuf::RepeatedField, + pub choice: ::protobuf::RepeatedField, // special fields pub unknown_fields: ::protobuf::UnknownFields, pub cached_size: ::protobuf::CachedSize, } -impl<'a> ::std::default::Default for &'a VoteStorage { - fn default() -> &'a VoteStorage { - ::default_instance() +impl<'a> ::std::default::Default for &'a VoteChoices { + fn default() -> &'a VoteChoices { + ::default_instance() } } -impl VoteStorage { - pub fn new() -> VoteStorage { +impl VoteChoices { + pub fn new() -> VoteChoices { ::std::default::Default::default() } - // bytes signature = 1; + // repeated .com.webank.wedpr.acv.proto.VoteChoice choice = 1; - pub fn get_signature(&self) -> &[u8] { - &self.signature + pub fn get_choice(&self) -> &[VoteChoice] { + &self.choice } - pub fn clear_signature(&mut self) { - self.signature.clear(); + pub fn clear_choice(&mut self) { + self.choice.clear(); } // Param is passed by value, moved - pub fn set_signature(&mut self, v: ::std::vec::Vec) { - self.signature = v; + pub fn set_choice(&mut self, v: ::protobuf::RepeatedField) { + self.choice = v; } // Mutable pointer to the field. - // If field is not initialized, it is initialized with default value first. - pub fn mut_signature(&mut self) -> &mut ::std::vec::Vec { - &mut self.signature - } - - // Take field - 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 blank_ballot = 2; - - - pub fn get_blank_ballot(&self) -> &Ballot { - self.blank_ballot.as_ref().unwrap_or_else(|| ::default_instance()) - } - pub fn clear_blank_ballot(&mut self) { - self.blank_ballot.clear(); - } - - pub fn has_blank_ballot(&self) -> bool { - self.blank_ballot.is_some() - } - - // Param is passed by value, moved - pub fn set_blank_ballot(&mut self, v: Ballot) { - self.blank_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_blank_ballot(&mut self) -> &mut Ballot { - if self.blank_ballot.is_none() { - self.blank_ballot.set_default(); - } - self.blank_ballot.as_mut().unwrap() - } - - // Take field - pub fn take_blank_ballot(&mut self) -> Ballot { - self.blank_ballot.take().unwrap_or_else(|| Ballot::new()) - } - - // .com.webank.wedpr.acv.proto.Ballot rest_ballot = 3; - - - pub fn get_rest_ballot(&self) -> &Ballot { - self.rest_ballot.as_ref().unwrap_or_else(|| ::default_instance()) - } - pub fn clear_rest_ballot(&mut self) { - self.rest_ballot.clear(); - } - - pub fn has_rest_ballot(&self) -> bool { - self.rest_ballot.is_some() - } - - // Param is passed by value, moved - pub fn set_rest_ballot(&mut self, v: Ballot) { - self.rest_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_rest_ballot(&mut self) -> &mut Ballot { - if self.rest_ballot.is_none() { - self.rest_ballot.set_default(); - } - self.rest_ballot.as_mut().unwrap() - } - - // Take field - pub fn take_rest_ballot(&mut self) -> Ballot { - self.rest_ballot.take().unwrap_or_else(|| Ballot::new()) - } - - // repeated .com.webank.wedpr.acv.proto.CandidateBallot voted_ballot = 4; - - - pub fn get_voted_ballot(&self) -> &[CandidateBallot] { - &self.voted_ballot - } - pub fn clear_voted_ballot(&mut self) { - self.voted_ballot.clear(); - } - - // Param is passed by value, moved - pub fn set_voted_ballot(&mut self, v: ::protobuf::RepeatedField) { - self.voted_ballot = v; - } - - // Mutable pointer to the field. - pub fn mut_voted_ballot(&mut self) -> &mut ::protobuf::RepeatedField { - &mut self.voted_ballot + pub fn mut_choice(&mut self) -> &mut ::protobuf::RepeatedField { + &mut self.choice } // Take field - pub fn take_voted_ballot(&mut self) -> ::protobuf::RepeatedField { - ::std::mem::replace(&mut self.voted_ballot, ::protobuf::RepeatedField::new()) + pub fn take_choice(&mut self) -> ::protobuf::RepeatedField { + ::std::mem::replace(&mut self.choice, ::protobuf::RepeatedField::new()) } } -impl ::protobuf::Message for VoteStorage { +impl ::protobuf::Message for VoteChoices { fn is_initialized(&self) -> bool { - for v in &self.blank_ballot { - if !v.is_initialized() { - return false; - } - }; - for v in &self.rest_ballot { - if !v.is_initialized() { - return false; - } - }; - for v in &self.voted_ballot { + for v in &self.choice { if !v.is_initialized() { return false; } @@ -2279,16 +2166,7 @@ impl ::protobuf::Message for VoteStorage { 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.signature)?; - }, - 2 => { - ::protobuf::rt::read_singular_message_into(wire_type, is, &mut self.blank_ballot)?; - }, - 3 => { - ::protobuf::rt::read_singular_message_into(wire_type, is, &mut self.rest_ballot)?; - }, - 4 => { - ::protobuf::rt::read_repeated_message_into(wire_type, is, &mut self.voted_ballot)?; + ::protobuf::rt::read_repeated_message_into(wire_type, is, &mut self.choice)?; }, _ => { ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; @@ -2302,18 +2180,7 @@ impl ::protobuf::Message for VoteStorage { #[allow(unused_variables)] fn compute_size(&self) -> u32 { let mut my_size = 0; - if !self.signature.is_empty() { - my_size += ::protobuf::rt::bytes_size(1, &self.signature); - } - if let Some(ref v) = self.blank_ballot.as_ref() { - let len = v.compute_size(); - my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; - } - if let Some(ref v) = self.rest_ballot.as_ref() { - let len = v.compute_size(); - my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; - } - for value in &self.voted_ballot { + for value in &self.choice { let len = value.compute_size(); my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; }; @@ -2323,21 +2190,8 @@ impl ::protobuf::Message for VoteStorage { } fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { - if !self.signature.is_empty() { - os.write_bytes(1, &self.signature)?; - } - if let Some(ref v) = self.blank_ballot.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)?; - } - if let Some(ref v) = self.rest_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)?; - } - for v in &self.voted_ballot { - os.write_tag(4, ::protobuf::wire_format::WireTypeLengthDelimited)?; + for v in &self.choice { + os.write_tag(1, ::protobuf::wire_format::WireTypeLengthDelimited)?; os.write_raw_varint32(v.get_cached_size())?; v.write_to_with_cached_sizes(os)?; }; @@ -2371,94 +2225,77 @@ impl ::protobuf::Message for VoteStorage { Self::descriptor_static() } - fn new() -> VoteStorage { - VoteStorage::new() + fn new() -> VoteChoices { + VoteChoices::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>( - "signature", - |m: &VoteStorage| { &m.signature }, - |m: &mut VoteStorage| { &mut m.signature }, - )); - fields.push(::protobuf::reflect::accessor::make_singular_ptr_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( - "blank_ballot", - |m: &VoteStorage| { &m.blank_ballot }, - |m: &mut VoteStorage| { &mut m.blank_ballot }, - )); - fields.push(::protobuf::reflect::accessor::make_singular_ptr_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( - "rest_ballot", - |m: &VoteStorage| { &m.rest_ballot }, - |m: &mut VoteStorage| { &mut m.rest_ballot }, - )); - fields.push(::protobuf::reflect::accessor::make_repeated_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( - "voted_ballot", - |m: &VoteStorage| { &m.voted_ballot }, - |m: &mut VoteStorage| { &mut m.voted_ballot }, + fields.push(::protobuf::reflect::accessor::make_repeated_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( + "choice", + |m: &VoteChoices| { &m.choice }, + |m: &mut VoteChoices| { &mut m.choice }, )); - ::protobuf::reflect::MessageDescriptor::new_pb_name::( - "VoteStorage", + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "VoteChoices", fields, file_descriptor_proto() ) }) } - fn default_instance() -> &'static VoteStorage { - static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; - instance.get(VoteStorage::new) + fn default_instance() -> &'static VoteChoices { + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(VoteChoices::new) } } -impl ::protobuf::Clear for VoteStorage { +impl ::protobuf::Clear for VoteChoices { fn clear(&mut self) { - self.signature.clear(); - self.blank_ballot.clear(); - self.rest_ballot.clear(); - self.voted_ballot.clear(); + self.choice.clear(); self.unknown_fields.clear(); } } -impl ::std::fmt::Debug for VoteStorage { +impl ::std::fmt::Debug for VoteChoices { fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { ::protobuf::text_format::fmt(self, f) } } -impl ::protobuf::reflect::ProtobufValue for VoteStorage { +impl ::protobuf::reflect::ProtobufValue for VoteChoices { fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { ::protobuf::reflect::ReflectValueRef::Message(self) } } #[derive(PartialEq,Clone,Default)] -pub struct CandidateList { +pub struct CandidateBallot { // message fields - pub candidate: ::protobuf::RepeatedField<::std::string::String>, + pub candidate: ::std::string::String, + pub ballot: ::protobuf::SingularPtrField, // special fields pub unknown_fields: ::protobuf::UnknownFields, pub cached_size: ::protobuf::CachedSize, } -impl<'a> ::std::default::Default for &'a CandidateList { - fn default() -> &'a CandidateList { - ::default_instance() +impl<'a> ::std::default::Default for &'a CandidateBallot { + fn default() -> &'a CandidateBallot { + ::default_instance() } } -impl CandidateList { - pub fn new() -> CandidateList { +impl CandidateBallot { + pub fn new() -> CandidateBallot { ::std::default::Default::default() } - // repeated string candidate = 1; + // string candidate = 1; - pub fn get_candidate(&self) -> &[::std::string::String] { + pub fn get_candidate(&self) -> &str { &self.candidate } pub fn clear_candidate(&mut self) { @@ -2466,23 +2303,62 @@ impl CandidateList { } // Param is passed by value, moved - pub fn set_candidate(&mut self, v: ::protobuf::RepeatedField<::std::string::String>) { + pub fn set_candidate(&mut self, v: ::std::string::String) { self.candidate = v; } // Mutable pointer to the field. - pub fn mut_candidate(&mut self) -> &mut ::protobuf::RepeatedField<::std::string::String> { + // If field is not initialized, it is initialized with default value first. + pub fn mut_candidate(&mut self) -> &mut ::std::string::String { &mut self.candidate } // Take field - pub fn take_candidate(&mut self) -> ::protobuf::RepeatedField<::std::string::String> { - ::std::mem::replace(&mut self.candidate, ::protobuf::RepeatedField::new()) + pub fn take_candidate(&mut self) -> ::std::string::String { + ::std::mem::replace(&mut self.candidate, ::std::string::String::new()) + } + + // .com.webank.wedpr.acv.proto.Ballot ballot = 2; + + + pub fn get_ballot(&self) -> &Ballot { + self.ballot.as_ref().unwrap_or_else(|| ::default_instance()) + } + 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_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_ballot(&mut self) -> &mut Ballot { + if self.ballot.is_none() { + self.ballot.set_default(); + } + self.ballot.as_mut().unwrap() + } + + // Take field + pub fn take_ballot(&mut self) -> Ballot { + self.ballot.take().unwrap_or_else(|| Ballot::new()) } } -impl ::protobuf::Message for CandidateList { +impl ::protobuf::Message for CandidateBallot { fn is_initialized(&self) -> bool { + for v in &self.ballot { + if !v.is_initialized() { + return false; + } + }; true } @@ -2491,7 +2367,10 @@ impl ::protobuf::Message for CandidateList { let (field_number, wire_type) = is.read_tag_unpack()?; match field_number { 1 => { - ::protobuf::rt::read_repeated_string_into(wire_type, is, &mut self.candidate)?; + ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.candidate)?; + }, + 2 => { + ::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())?; @@ -2505,18 +2384,27 @@ impl ::protobuf::Message for CandidateList { #[allow(unused_variables)] fn compute_size(&self) -> u32 { let mut my_size = 0; - for value in &self.candidate { - my_size += ::protobuf::rt::string_size(1, &value); - }; + if !self.candidate.is_empty() { + my_size += ::protobuf::rt::string_size(1, &self.candidate); + } + 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); my_size } fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { - for v in &self.candidate { - os.write_string(1, &v)?; - }; + if !self.candidate.is_empty() { + os.write_string(1, &self.candidate)?; + } + if let Some(ref v) = self.ballot.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(()) } @@ -2547,140 +2435,107 @@ impl ::protobuf::Message for CandidateList { Self::descriptor_static() } - fn new() -> CandidateList { - CandidateList::new() + fn new() -> CandidateBallot { + CandidateBallot::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_repeated_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( "candidate", - |m: &CandidateList| { &m.candidate }, - |m: &mut CandidateList| { &mut m.candidate }, + |m: &CandidateBallot| { &m.candidate }, + |m: &mut CandidateBallot| { &mut m.candidate }, )); - ::protobuf::reflect::MessageDescriptor::new_pb_name::( - "CandidateList", + fields.push(::protobuf::reflect::accessor::make_singular_ptr_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( + "ballot", + |m: &CandidateBallot| { &m.ballot }, + |m: &mut CandidateBallot| { &mut m.ballot }, + )); + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "CandidateBallot", fields, file_descriptor_proto() ) }) } - fn default_instance() -> &'static CandidateList { - static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; - instance.get(CandidateList::new) + fn default_instance() -> &'static CandidateBallot { + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(CandidateBallot::new) } } -impl ::protobuf::Clear for CandidateList { +impl ::protobuf::Clear for CandidateBallot { fn clear(&mut self) { self.candidate.clear(); + self.ballot.clear(); self.unknown_fields.clear(); } } -impl ::std::fmt::Debug for CandidateList { +impl ::std::fmt::Debug for CandidateBallot { fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { ::protobuf::text_format::fmt(self, f) } } -impl ::protobuf::reflect::ProtobufValue for CandidateList { +impl ::protobuf::reflect::ProtobufValue for CandidateBallot { fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { ::protobuf::reflect::ReflectValueRef::Message(self) } } #[derive(PartialEq,Clone,Default)] -pub struct SystemParametersStorage { +pub struct BallotProof { // message fields - pub poll_point: ::std::vec::Vec, - pub candidates: ::protobuf::SingularPtrField, + pub format_proof: ::std::vec::Vec, // special fields pub unknown_fields: ::protobuf::UnknownFields, pub cached_size: ::protobuf::CachedSize, -} - -impl<'a> ::std::default::Default for &'a SystemParametersStorage { - fn default() -> &'a SystemParametersStorage { - ::default_instance() - } -} - -impl SystemParametersStorage { - pub fn new() -> SystemParametersStorage { - ::std::default::Default::default() - } - - // bytes poll_point = 1; - - - pub fn get_poll_point(&self) -> &[u8] { - &self.poll_point - } - pub fn clear_poll_point(&mut self) { - self.poll_point.clear(); - } - - // Param is passed by value, moved - pub fn set_poll_point(&mut self, v: ::std::vec::Vec) { - self.poll_point = v; - } - - // Mutable pointer to the field. - // If field is not initialized, it is initialized with default value first. - pub fn mut_poll_point(&mut self) -> &mut ::std::vec::Vec { - &mut self.poll_point +} + +impl<'a> ::std::default::Default for &'a BallotProof { + fn default() -> &'a BallotProof { + ::default_instance() } +} - // Take field - pub fn take_poll_point(&mut self) -> ::std::vec::Vec { - ::std::mem::replace(&mut self.poll_point, ::std::vec::Vec::new()) +impl BallotProof { + pub fn new() -> BallotProof { + ::std::default::Default::default() } - // .com.webank.wedpr.acv.proto.CandidateList candidates = 2; + // bytes format_proof = 1; - pub fn get_candidates(&self) -> &CandidateList { - self.candidates.as_ref().unwrap_or_else(|| ::default_instance()) - } - pub fn clear_candidates(&mut self) { - self.candidates.clear(); + pub fn get_format_proof(&self) -> &[u8] { + &self.format_proof } - - pub fn has_candidates(&self) -> bool { - self.candidates.is_some() + pub fn clear_format_proof(&mut self) { + self.format_proof.clear(); } // Param is passed by value, moved - pub fn set_candidates(&mut self, v: CandidateList) { - self.candidates = ::protobuf::SingularPtrField::some(v); + pub fn set_format_proof(&mut self, v: ::std::vec::Vec) { + self.format_proof = v; } // Mutable pointer to the field. // If field is not initialized, it is initialized with default value first. - pub fn mut_candidates(&mut self) -> &mut CandidateList { - if self.candidates.is_none() { - self.candidates.set_default(); - } - self.candidates.as_mut().unwrap() + pub fn mut_format_proof(&mut self) -> &mut ::std::vec::Vec { + &mut self.format_proof } // Take field - pub fn take_candidates(&mut self) -> CandidateList { - self.candidates.take().unwrap_or_else(|| CandidateList::new()) + 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 SystemParametersStorage { +impl ::protobuf::Message for BallotProof { fn is_initialized(&self) -> bool { - for v in &self.candidates { - if !v.is_initialized() { - return false; - } - }; true } @@ -2689,10 +2544,7 @@ impl ::protobuf::Message for SystemParametersStorage { 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.poll_point)?; - }, - 2 => { - ::protobuf::rt::read_singular_message_into(wire_type, is, &mut self.candidates)?; + ::protobuf::rt::read_singular_proto3_bytes_into(wire_type, is, &mut self.format_proof)?; }, _ => { ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; @@ -2706,12 +2558,8 @@ impl ::protobuf::Message for SystemParametersStorage { #[allow(unused_variables)] fn compute_size(&self) -> u32 { let mut my_size = 0; - if !self.poll_point.is_empty() { - my_size += ::protobuf::rt::bytes_size(1, &self.poll_point); - } - if let Some(ref v) = self.candidates.as_ref() { - let len = v.compute_size(); - my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; + if !self.format_proof.is_empty() { + my_size += ::protobuf::rt::bytes_size(1, &self.format_proof); } my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); self.cached_size.set(my_size); @@ -2719,13 +2567,8 @@ impl ::protobuf::Message for SystemParametersStorage { } fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { - if !self.poll_point.is_empty() { - os.write_bytes(1, &self.poll_point)?; - } - if let Some(ref v) = self.candidates.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)?; + if !self.format_proof.is_empty() { + os.write_bytes(1, &self.format_proof)?; } os.write_unknown_fields(self.get_unknown_fields())?; ::std::result::Result::Ok(()) @@ -2757,8 +2600,8 @@ impl ::protobuf::Message for SystemParametersStorage { Self::descriptor_static() } - fn new() -> SystemParametersStorage { - SystemParametersStorage::new() + fn new() -> BallotProof { + BallotProof::new() } fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { @@ -2766,98 +2609,131 @@ impl ::protobuf::Message for SystemParametersStorage { descriptor.get(|| { let mut fields = ::std::vec::Vec::new(); fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( - "poll_point", - |m: &SystemParametersStorage| { &m.poll_point }, - |m: &mut SystemParametersStorage| { &mut m.poll_point }, - )); - fields.push(::protobuf::reflect::accessor::make_singular_ptr_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( - "candidates", - |m: &SystemParametersStorage| { &m.candidates }, - |m: &mut SystemParametersStorage| { &mut m.candidates }, + "format_proof", + |m: &BallotProof| { &m.format_proof }, + |m: &mut BallotProof| { &mut m.format_proof }, )); - ::protobuf::reflect::MessageDescriptor::new_pb_name::( - "SystemParametersStorage", + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "BallotProof", fields, file_descriptor_proto() ) }) } - fn default_instance() -> &'static SystemParametersStorage { - static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; - instance.get(SystemParametersStorage::new) + fn default_instance() -> &'static BallotProof { + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(BallotProof::new) } } -impl ::protobuf::Clear for SystemParametersStorage { +impl ::protobuf::Clear for BallotProof { fn clear(&mut self) { - self.poll_point.clear(); - self.candidates.clear(); + self.format_proof.clear(); self.unknown_fields.clear(); } } -impl ::std::fmt::Debug for SystemParametersStorage { +impl ::std::fmt::Debug for BallotProof { fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { ::protobuf::text_format::fmt(self, f) } } -impl ::protobuf::reflect::ProtobufValue for SystemParametersStorage { +impl ::protobuf::reflect::ProtobufValue for BallotProof { fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { ::protobuf::reflect::ReflectValueRef::Message(self) } } #[derive(PartialEq,Clone,Default)] -pub struct BallotProof { +pub struct StringToBallotProofPair { // message fields - pub format_proof: ::std::vec::Vec, + pub key: ::std::string::String, + pub value: ::protobuf::SingularPtrField, // special fields pub unknown_fields: ::protobuf::UnknownFields, pub cached_size: ::protobuf::CachedSize, } -impl<'a> ::std::default::Default for &'a BallotProof { - fn default() -> &'a BallotProof { - ::default_instance() +impl<'a> ::std::default::Default for &'a StringToBallotProofPair { + fn default() -> &'a StringToBallotProofPair { + ::default_instance() } } -impl BallotProof { - pub fn new() -> BallotProof { +impl StringToBallotProofPair { + pub fn new() -> StringToBallotProofPair { ::std::default::Default::default() } - // bytes format_proof = 1; + // string key = 1; - pub fn get_format_proof(&self) -> &[u8] { - &self.format_proof + pub fn get_key(&self) -> &str { + &self.key } - pub fn clear_format_proof(&mut self) { - self.format_proof.clear(); + pub fn clear_key(&mut self) { + self.key.clear(); } // Param is passed by value, moved - pub fn set_format_proof(&mut self, v: ::std::vec::Vec) { - self.format_proof = v; + pub fn set_key(&mut self, v: ::std::string::String) { + self.key = v; } // Mutable pointer to the field. // If field is not initialized, it is initialized with default value first. - pub fn mut_format_proof(&mut self) -> &mut ::std::vec::Vec { - &mut self.format_proof + pub fn mut_key(&mut self) -> &mut ::std::string::String { + &mut self.key } // Take field - pub fn take_format_proof(&mut self) -> ::std::vec::Vec { - ::std::mem::replace(&mut self.format_proof, ::std::vec::Vec::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.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 BallotProof { +impl ::protobuf::Message for StringToBallotProofPair { fn is_initialized(&self) -> bool { + for v in &self.value { + if !v.is_initialized() { + return false; + } + }; true } @@ -2866,7 +2742,10 @@ impl ::protobuf::Message for BallotProof { 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)?; + ::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())?; @@ -2880,8 +2759,12 @@ impl ::protobuf::Message for BallotProof { #[allow(unused_variables)] fn compute_size(&self) -> u32 { let mut my_size = 0; - if !self.format_proof.is_empty() { - my_size += ::protobuf::rt::bytes_size(1, &self.format_proof); + 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); @@ -2889,8 +2772,13 @@ impl ::protobuf::Message for BallotProof { } fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { - if !self.format_proof.is_empty() { - os.write_bytes(1, &self.format_proof)?; + 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(()) @@ -2922,136 +2810,200 @@ impl ::protobuf::Message for BallotProof { Self::descriptor_static() } - fn new() -> BallotProof { - BallotProof::new() + fn new() -> StringToBallotProofPair { + StringToBallotProofPair::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>( - "format_proof", - |m: &BallotProof| { &m.format_proof }, - |m: &mut BallotProof| { &mut m.format_proof }, + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( + "key", + |m: &StringToBallotProofPair| { &m.key }, + |m: &mut StringToBallotProofPair| { &mut m.key }, )); - ::protobuf::reflect::MessageDescriptor::new_pb_name::( - "BallotProof", + fields.push(::protobuf::reflect::accessor::make_singular_ptr_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( + "value", + |m: &StringToBallotProofPair| { &m.value }, + |m: &mut StringToBallotProofPair| { &mut m.value }, + )); + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "StringToBallotProofPair", fields, file_descriptor_proto() ) }) } - fn default_instance() -> &'static BallotProof { - static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; - instance.get(BallotProof::new) + fn default_instance() -> &'static StringToBallotProofPair { + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(StringToBallotProofPair::new) } } -impl ::protobuf::Clear for BallotProof { +impl ::protobuf::Clear for StringToBallotProofPair { fn clear(&mut self) { - self.format_proof.clear(); + self.key.clear(); + self.value.clear(); self.unknown_fields.clear(); } } -impl ::std::fmt::Debug for BallotProof { +impl ::std::fmt::Debug for StringToBallotProofPair { fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { ::protobuf::text_format::fmt(self, f) } } -impl ::protobuf::reflect::ProtobufValue for BallotProof { +impl ::protobuf::reflect::ProtobufValue for StringToBallotProofPair { fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { ::protobuf::reflect::ReflectValueRef::Message(self) } } #[derive(PartialEq,Clone,Default)] -pub struct StringToCandidateBallotProofPair { +pub struct VoteRequest { // message fields - pub key: ::std::string::String, - pub value: ::protobuf::SingularPtrField, + pub vote: ::protobuf::SingularPtrField, + pub ballot_proof: ::protobuf::RepeatedField, + pub range_proof: ::std::vec::Vec, + pub sum_balance_proof: ::std::vec::Vec, // special fields pub unknown_fields: ::protobuf::UnknownFields, pub cached_size: ::protobuf::CachedSize, } -impl<'a> ::std::default::Default for &'a StringToCandidateBallotProofPair { - fn default() -> &'a StringToCandidateBallotProofPair { - ::default_instance() +impl<'a> ::std::default::Default for &'a VoteRequest { + fn default() -> &'a VoteRequest { + ::default_instance() + } +} + +impl VoteRequest { + pub fn new() -> VoteRequest { + ::std::default::Default::default() + } + + // .com.webank.wedpr.acv.proto.VoteStorage vote = 1; + + + pub fn get_vote(&self) -> &VoteStorage { + self.vote.as_ref().unwrap_or_else(|| ::default_instance()) + } + pub fn clear_vote(&mut self) { + self.vote.clear(); + } + + pub fn has_vote(&self) -> bool { + self.vote.is_some() + } + + // Param is passed by value, moved + pub fn set_vote(&mut self, v: VoteStorage) { + self.vote = ::protobuf::SingularPtrField::some(v); + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_vote(&mut self) -> &mut VoteStorage { + if self.vote.is_none() { + self.vote.set_default(); + } + self.vote.as_mut().unwrap() + } + + // Take field + pub fn take_vote(&mut self) -> VoteStorage { + self.vote.take().unwrap_or_else(|| VoteStorage::new()) + } + + // repeated .com.webank.wedpr.acv.proto.StringToBallotProofPair ballot_proof = 2; + + + pub fn get_ballot_proof(&self) -> &[StringToBallotProofPair] { + &self.ballot_proof + } + pub fn clear_ballot_proof(&mut self) { + self.ballot_proof.clear(); + } + + // Param is passed by value, moved + pub fn set_ballot_proof(&mut self, v: ::protobuf::RepeatedField) { + self.ballot_proof = v; } -} -impl StringToCandidateBallotProofPair { - pub fn new() -> StringToCandidateBallotProofPair { - ::std::default::Default::default() + // Mutable pointer to the field. + pub fn mut_ballot_proof(&mut self) -> &mut ::protobuf::RepeatedField { + &mut self.ballot_proof } - // string key = 1; + // Take field + pub fn take_ballot_proof(&mut self) -> ::protobuf::RepeatedField { + ::std::mem::replace(&mut self.ballot_proof, ::protobuf::RepeatedField::new()) + } + + // bytes range_proof = 3; - pub fn get_key(&self) -> &str { - &self.key + pub fn get_range_proof(&self) -> &[u8] { + &self.range_proof } - pub fn clear_key(&mut self) { - self.key.clear(); + pub fn clear_range_proof(&mut self) { + self.range_proof.clear(); } // Param is passed by value, moved - pub fn set_key(&mut self, v: ::std::string::String) { - self.key = v; + pub fn set_range_proof(&mut self, v: ::std::vec::Vec) { + self.range_proof = 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 ::std::string::String { - &mut self.key + pub fn mut_range_proof(&mut self) -> &mut ::std::vec::Vec { + &mut self.range_proof } // Take field - pub fn take_key(&mut self) -> ::std::string::String { - ::std::mem::replace(&mut self.key, ::std::string::String::new()) + pub fn take_range_proof(&mut self) -> ::std::vec::Vec { + ::std::mem::replace(&mut self.range_proof, ::std::vec::Vec::new()) } - // .com.webank.wedpr.acv.proto.BallotProof value = 2; + // bytes sum_balance_proof = 4; - 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 get_sum_balance_proof(&self) -> &[u8] { + &self.sum_balance_proof } - - pub fn has_value(&self) -> bool { - self.value.is_some() + pub fn clear_sum_balance_proof(&mut self) { + self.sum_balance_proof.clear(); } // Param is passed by value, moved - pub fn set_value(&mut self, v: BallotProof) { - self.value = ::protobuf::SingularPtrField::some(v); + pub fn set_sum_balance_proof(&mut self, v: ::std::vec::Vec) { + self.sum_balance_proof = 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() + pub fn mut_sum_balance_proof(&mut self) -> &mut ::std::vec::Vec { + &mut self.sum_balance_proof } // Take field - pub fn take_value(&mut self) -> BallotProof { - self.value.take().unwrap_or_else(|| BallotProof::new()) + pub fn take_sum_balance_proof(&mut self) -> ::std::vec::Vec { + ::std::mem::replace(&mut self.sum_balance_proof, ::std::vec::Vec::new()) } } -impl ::protobuf::Message for StringToCandidateBallotProofPair { +impl ::protobuf::Message for VoteRequest { fn is_initialized(&self) -> bool { - for v in &self.value { + for v in &self.vote { + if !v.is_initialized() { + return false; + } + }; + for v in &self.ballot_proof { if !v.is_initialized() { return false; } @@ -3064,10 +3016,16 @@ impl ::protobuf::Message for StringToCandidateBallotProofPair { 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.vote)?; }, 2 => { - ::protobuf::rt::read_singular_message_into(wire_type, is, &mut self.value)?; + ::protobuf::rt::read_repeated_message_into(wire_type, is, &mut self.ballot_proof)?; + }, + 3 => { + ::protobuf::rt::read_singular_proto3_bytes_into(wire_type, is, &mut self.range_proof)?; + }, + 4 => { + ::protobuf::rt::read_singular_proto3_bytes_into(wire_type, is, &mut self.sum_balance_proof)?; }, _ => { ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; @@ -3081,26 +3039,41 @@ impl ::protobuf::Message for StringToCandidateBallotProofPair { #[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.vote.as_ref() { let len = v.compute_size(); my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; } + for value in &self.ballot_proof { + let len = value.compute_size(); + my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; + }; + if !self.range_proof.is_empty() { + my_size += ::protobuf::rt::bytes_size(3, &self.range_proof); + } + if !self.sum_balance_proof.is_empty() { + my_size += ::protobuf::rt::bytes_size(4, &self.sum_balance_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.key.is_empty() { - os.write_string(1, &self.key)?; + if let Some(ref v) = self.vote.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.ballot_proof { os.write_tag(2, ::protobuf::wire_format::WireTypeLengthDelimited)?; os.write_raw_varint32(v.get_cached_size())?; v.write_to_with_cached_sizes(os)?; + }; + if !self.range_proof.is_empty() { + os.write_bytes(3, &self.range_proof)?; + } + if !self.sum_balance_proof.is_empty() { + os.write_bytes(4, &self.sum_balance_proof)?; } os.write_unknown_fields(self.get_unknown_fields())?; ::std::result::Result::Ok(()) @@ -3132,200 +3105,224 @@ impl ::protobuf::Message for StringToCandidateBallotProofPair { Self::descriptor_static() } - fn new() -> StringToCandidateBallotProofPair { - StringToCandidateBallotProofPair::new() + fn new() -> VoteRequest { + VoteRequest::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: &StringToCandidateBallotProofPair| { &m.key }, - |m: &mut StringToCandidateBallotProofPair| { &mut m.key }, + fields.push(::protobuf::reflect::accessor::make_singular_ptr_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( + "vote", + |m: &VoteRequest| { &m.vote }, + |m: &mut VoteRequest| { &mut m.vote }, )); - fields.push(::protobuf::reflect::accessor::make_singular_ptr_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( - "value", - |m: &StringToCandidateBallotProofPair| { &m.value }, - |m: &mut StringToCandidateBallotProofPair| { &mut m.value }, + fields.push(::protobuf::reflect::accessor::make_repeated_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( + "ballot_proof", + |m: &VoteRequest| { &m.ballot_proof }, + |m: &mut VoteRequest| { &mut m.ballot_proof }, + )); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( + "range_proof", + |m: &VoteRequest| { &m.range_proof }, + |m: &mut VoteRequest| { &mut m.range_proof }, + )); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( + "sum_balance_proof", + |m: &VoteRequest| { &m.sum_balance_proof }, + |m: &mut VoteRequest| { &mut m.sum_balance_proof }, )); - ::protobuf::reflect::MessageDescriptor::new_pb_name::( - "StringToCandidateBallotProofPair", + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "VoteRequest", fields, file_descriptor_proto() ) }) } - fn default_instance() -> &'static StringToCandidateBallotProofPair { - static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; - instance.get(StringToCandidateBallotProofPair::new) + fn default_instance() -> &'static VoteRequest { + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(VoteRequest::new) } } -impl ::protobuf::Clear for StringToCandidateBallotProofPair { +impl ::protobuf::Clear for VoteRequest { fn clear(&mut self) { - self.key.clear(); - self.value.clear(); + self.vote.clear(); + self.ballot_proof.clear(); + self.range_proof.clear(); + self.sum_balance_proof.clear(); self.unknown_fields.clear(); } } -impl ::std::fmt::Debug for StringToCandidateBallotProofPair { +impl ::std::fmt::Debug for VoteRequest { fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { ::protobuf::text_format::fmt(self, f) } } -impl ::protobuf::reflect::ProtobufValue for StringToCandidateBallotProofPair { +impl ::protobuf::reflect::ProtobufValue for VoteRequest { fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { ::protobuf::reflect::ReflectValueRef::Message(self) } } #[derive(PartialEq,Clone,Default)] -pub struct VoteRequest { +pub struct VoteStorage { // message fields - pub vote: ::protobuf::SingularPtrField, - pub ballot_proof: ::protobuf::RepeatedField, - pub range_proof: ::std::vec::Vec, - pub sum_balance_proof: ::std::vec::Vec, + pub signature: ::std::vec::Vec, + pub blank_ballot: ::protobuf::SingularPtrField, + pub rest_ballot: ::protobuf::SingularPtrField, + pub voted_ballot: ::protobuf::RepeatedField, // special fields pub unknown_fields: ::protobuf::UnknownFields, pub cached_size: ::protobuf::CachedSize, } -impl<'a> ::std::default::Default for &'a VoteRequest { - fn default() -> &'a VoteRequest { - ::default_instance() +impl<'a> ::std::default::Default for &'a VoteStorage { + fn default() -> &'a VoteStorage { + ::default_instance() } } -impl VoteRequest { - pub fn new() -> VoteRequest { +impl VoteStorage { + pub fn new() -> VoteStorage { ::std::default::Default::default() } - // .com.webank.wedpr.acv.proto.VoteStorage vote = 1; + // bytes signature = 1; - pub fn get_vote(&self) -> &VoteStorage { - self.vote.as_ref().unwrap_or_else(|| ::default_instance()) - } - pub fn clear_vote(&mut self) { - self.vote.clear(); + pub fn get_signature(&self) -> &[u8] { + &self.signature } - - pub fn has_vote(&self) -> bool { - self.vote.is_some() + pub fn clear_signature(&mut self) { + self.signature.clear(); } // Param is passed by value, moved - pub fn set_vote(&mut self, v: VoteStorage) { - self.vote = ::protobuf::SingularPtrField::some(v); + pub fn set_signature(&mut self, v: ::std::vec::Vec) { + self.signature = v; } // Mutable pointer to the field. // If field is not initialized, it is initialized with default value first. - pub fn mut_vote(&mut self) -> &mut VoteStorage { - if self.vote.is_none() { - self.vote.set_default(); - } - self.vote.as_mut().unwrap() + pub fn mut_signature(&mut self) -> &mut ::std::vec::Vec { + &mut self.signature } // Take field - pub fn take_vote(&mut self) -> VoteStorage { - self.vote.take().unwrap_or_else(|| VoteStorage::new()) + pub fn take_signature(&mut self) -> ::std::vec::Vec { + ::std::mem::replace(&mut self.signature, ::std::vec::Vec::new()) } - // repeated .com.webank.wedpr.acv.proto.StringToCandidateBallotProofPair ballot_proof = 2; + // .com.webank.wedpr.acv.proto.Ballot blank_ballot = 2; - pub fn get_ballot_proof(&self) -> &[StringToCandidateBallotProofPair] { - &self.ballot_proof + pub fn get_blank_ballot(&self) -> &Ballot { + self.blank_ballot.as_ref().unwrap_or_else(|| ::default_instance()) } - pub fn clear_ballot_proof(&mut self) { - self.ballot_proof.clear(); + pub fn clear_blank_ballot(&mut self) { + self.blank_ballot.clear(); + } + + pub fn has_blank_ballot(&self) -> bool { + self.blank_ballot.is_some() } // Param is passed by value, moved - pub fn set_ballot_proof(&mut self, v: ::protobuf::RepeatedField) { - self.ballot_proof = v; + pub fn set_blank_ballot(&mut self, v: Ballot) { + self.blank_ballot = ::protobuf::SingularPtrField::some(v); } // Mutable pointer to the field. - pub fn mut_ballot_proof(&mut self) -> &mut ::protobuf::RepeatedField { - &mut self.ballot_proof + // If field is not initialized, it is initialized with default value first. + pub fn mut_blank_ballot(&mut self) -> &mut Ballot { + if self.blank_ballot.is_none() { + self.blank_ballot.set_default(); + } + self.blank_ballot.as_mut().unwrap() } // Take field - pub fn take_ballot_proof(&mut self) -> ::protobuf::RepeatedField { - ::std::mem::replace(&mut self.ballot_proof, ::protobuf::RepeatedField::new()) + pub fn take_blank_ballot(&mut self) -> Ballot { + self.blank_ballot.take().unwrap_or_else(|| Ballot::new()) } - // bytes range_proof = 3; + // .com.webank.wedpr.acv.proto.Ballot rest_ballot = 3; - pub fn get_range_proof(&self) -> &[u8] { - &self.range_proof + pub fn get_rest_ballot(&self) -> &Ballot { + self.rest_ballot.as_ref().unwrap_or_else(|| ::default_instance()) } - pub fn clear_range_proof(&mut self) { - self.range_proof.clear(); + pub fn clear_rest_ballot(&mut self) { + self.rest_ballot.clear(); + } + + pub fn has_rest_ballot(&self) -> bool { + self.rest_ballot.is_some() } // Param is passed by value, moved - pub fn set_range_proof(&mut self, v: ::std::vec::Vec) { - self.range_proof = v; + pub fn set_rest_ballot(&mut self, v: Ballot) { + self.rest_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_range_proof(&mut self) -> &mut ::std::vec::Vec { - &mut self.range_proof + pub fn mut_rest_ballot(&mut self) -> &mut Ballot { + if self.rest_ballot.is_none() { + self.rest_ballot.set_default(); + } + self.rest_ballot.as_mut().unwrap() } // Take field - pub fn take_range_proof(&mut self) -> ::std::vec::Vec { - ::std::mem::replace(&mut self.range_proof, ::std::vec::Vec::new()) + pub fn take_rest_ballot(&mut self) -> Ballot { + self.rest_ballot.take().unwrap_or_else(|| Ballot::new()) } - // bytes sum_balance_proof = 4; + // repeated .com.webank.wedpr.acv.proto.CandidateBallot voted_ballot = 4; - pub fn get_sum_balance_proof(&self) -> &[u8] { - &self.sum_balance_proof + pub fn get_voted_ballot(&self) -> &[CandidateBallot] { + &self.voted_ballot } - pub fn clear_sum_balance_proof(&mut self) { - self.sum_balance_proof.clear(); + pub fn clear_voted_ballot(&mut self) { + self.voted_ballot.clear(); } // Param is passed by value, moved - pub fn set_sum_balance_proof(&mut self, v: ::std::vec::Vec) { - self.sum_balance_proof = v; + pub fn set_voted_ballot(&mut self, v: ::protobuf::RepeatedField) { + self.voted_ballot = v; } // Mutable pointer to the field. - // If field is not initialized, it is initialized with default value first. - pub fn mut_sum_balance_proof(&mut self) -> &mut ::std::vec::Vec { - &mut self.sum_balance_proof + pub fn mut_voted_ballot(&mut self) -> &mut ::protobuf::RepeatedField { + &mut self.voted_ballot } // Take field - pub fn take_sum_balance_proof(&mut self) -> ::std::vec::Vec { - ::std::mem::replace(&mut self.sum_balance_proof, ::std::vec::Vec::new()) + pub fn take_voted_ballot(&mut self) -> ::protobuf::RepeatedField { + ::std::mem::replace(&mut self.voted_ballot, ::protobuf::RepeatedField::new()) } } -impl ::protobuf::Message for VoteRequest { +impl ::protobuf::Message for VoteStorage { fn is_initialized(&self) -> bool { - for v in &self.vote { + for v in &self.blank_ballot { if !v.is_initialized() { return false; } }; - for v in &self.ballot_proof { + for v in &self.rest_ballot { + if !v.is_initialized() { + return false; + } + }; + for v in &self.voted_ballot { if !v.is_initialized() { return false; } @@ -3338,16 +3335,16 @@ impl ::protobuf::Message for VoteRequest { let (field_number, wire_type) = is.read_tag_unpack()?; match field_number { 1 => { - ::protobuf::rt::read_singular_message_into(wire_type, is, &mut self.vote)?; + ::protobuf::rt::read_singular_proto3_bytes_into(wire_type, is, &mut self.signature)?; }, 2 => { - ::protobuf::rt::read_repeated_message_into(wire_type, is, &mut self.ballot_proof)?; + ::protobuf::rt::read_singular_message_into(wire_type, is, &mut self.blank_ballot)?; }, 3 => { - ::protobuf::rt::read_singular_proto3_bytes_into(wire_type, is, &mut self.range_proof)?; + ::protobuf::rt::read_singular_message_into(wire_type, is, &mut self.rest_ballot)?; }, 4 => { - ::protobuf::rt::read_singular_proto3_bytes_into(wire_type, is, &mut self.sum_balance_proof)?; + ::protobuf::rt::read_repeated_message_into(wire_type, is, &mut self.voted_ballot)?; }, _ => { ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; @@ -3361,42 +3358,45 @@ impl ::protobuf::Message for VoteRequest { #[allow(unused_variables)] fn compute_size(&self) -> u32 { let mut my_size = 0; - if let Some(ref v) = self.vote.as_ref() { + if !self.signature.is_empty() { + my_size += ::protobuf::rt::bytes_size(1, &self.signature); + } + if let Some(ref v) = self.blank_ballot.as_ref() { let len = v.compute_size(); my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; } - for value in &self.ballot_proof { + if let Some(ref v) = self.rest_ballot.as_ref() { + let len = v.compute_size(); + my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; + } + for value in &self.voted_ballot { let len = value.compute_size(); my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; }; - if !self.range_proof.is_empty() { - my_size += ::protobuf::rt::bytes_size(3, &self.range_proof); - } - if !self.sum_balance_proof.is_empty() { - my_size += ::protobuf::rt::bytes_size(4, &self.sum_balance_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 let Some(ref v) = self.vote.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.signature.is_empty() { + os.write_bytes(1, &self.signature)?; } - for v in &self.ballot_proof { + if let Some(ref v) = self.blank_ballot.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)?; - }; - if !self.range_proof.is_empty() { - os.write_bytes(3, &self.range_proof)?; } - if !self.sum_balance_proof.is_empty() { - os.write_bytes(4, &self.sum_balance_proof)?; + if let Some(ref v) = self.rest_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)?; } + for v in &self.voted_ballot { + 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(()) } @@ -3427,162 +3427,173 @@ impl ::protobuf::Message for VoteRequest { Self::descriptor_static() } - fn new() -> VoteRequest { - VoteRequest::new() + fn new() -> VoteStorage { + VoteStorage::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>( - "vote", - |m: &VoteRequest| { &m.vote }, - |m: &mut VoteRequest| { &mut m.vote }, + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( + "signature", + |m: &VoteStorage| { &m.signature }, + |m: &mut VoteStorage| { &mut m.signature }, )); - fields.push(::protobuf::reflect::accessor::make_repeated_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( - "ballot_proof", - |m: &VoteRequest| { &m.ballot_proof }, - |m: &mut VoteRequest| { &mut m.ballot_proof }, + fields.push(::protobuf::reflect::accessor::make_singular_ptr_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( + "blank_ballot", + |m: &VoteStorage| { &m.blank_ballot }, + |m: &mut VoteStorage| { &mut m.blank_ballot }, )); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( - "range_proof", - |m: &VoteRequest| { &m.range_proof }, - |m: &mut VoteRequest| { &mut m.range_proof }, + fields.push(::protobuf::reflect::accessor::make_singular_ptr_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( + "rest_ballot", + |m: &VoteStorage| { &m.rest_ballot }, + |m: &mut VoteStorage| { &mut m.rest_ballot }, )); - fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( - "sum_balance_proof", - |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>( + "voted_ballot", + |m: &VoteStorage| { &m.voted_ballot }, + |m: &mut VoteStorage| { &mut m.voted_ballot }, )); - ::protobuf::reflect::MessageDescriptor::new_pb_name::( - "VoteRequest", + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "VoteStorage", fields, file_descriptor_proto() ) }) } - fn default_instance() -> &'static VoteRequest { - static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; - instance.get(VoteRequest::new) + fn default_instance() -> &'static VoteStorage { + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(VoteStorage::new) } } -impl ::protobuf::Clear for VoteRequest { +impl ::protobuf::Clear for VoteStorage { fn clear(&mut self) { - self.vote.clear(); - self.ballot_proof.clear(); - self.range_proof.clear(); - self.sum_balance_proof.clear(); + self.signature.clear(); + self.blank_ballot.clear(); + self.rest_ballot.clear(); + self.voted_ballot.clear(); self.unknown_fields.clear(); } } -impl ::std::fmt::Debug for VoteRequest { +impl ::std::fmt::Debug for VoteStorage { fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { ::protobuf::text_format::fmt(self, f) } } -impl ::protobuf::reflect::ProtobufValue for VoteRequest { +impl ::protobuf::reflect::ProtobufValue for VoteStorage { fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { ::protobuf::reflect::ReflectValueRef::Message(self) } } #[derive(PartialEq,Clone,Default)] -pub struct DecryptedResultPartStorage { +pub struct CountingPart { // message fields - pub blank_part: ::protobuf::SingularPtrField, - pub candidate_part: ::protobuf::RepeatedField, + 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 DecryptedResultPartStorage { - fn default() -> &'a DecryptedResultPartStorage { - ::default_instance() +impl<'a> ::std::default::Default for &'a CountingPart { + fn default() -> &'a CountingPart { + ::default_instance() } } -impl DecryptedResultPartStorage { - pub fn new() -> DecryptedResultPartStorage { +impl CountingPart { + pub fn new() -> CountingPart { ::std::default::Default::default() } - // .com.webank.wedpr.acv.proto.CountingPart blank_part = 1; + // string counter_id = 1; - pub fn get_blank_part(&self) -> &CountingPart { - self.blank_part.as_ref().unwrap_or_else(|| ::default_instance()) + pub fn get_counter_id(&self) -> &str { + &self.counter_id } - pub fn clear_blank_part(&mut self) { - self.blank_part.clear(); + pub fn clear_counter_id(&mut self) { + self.counter_id.clear(); } - pub fn has_blank_part(&self) -> bool { - self.blank_part.is_some() + // 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_blank_part(&mut self, v: CountingPart) { - self.blank_part = ::protobuf::SingularPtrField::some(v); + 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_blank_part(&mut self) -> &mut CountingPart { - if self.blank_part.is_none() { - self.blank_part.set_default(); - } - self.blank_part.as_mut().unwrap() + pub fn mut_blinding_c2(&mut self) -> &mut ::std::vec::Vec { + &mut self.blinding_c2 } // Take field - pub fn take_blank_part(&mut self) -> CountingPart { - self.blank_part.take().unwrap_or_else(|| CountingPart::new()) + pub fn take_blinding_c2(&mut self) -> ::std::vec::Vec { + ::std::mem::replace(&mut self.blinding_c2, ::std::vec::Vec::new()) } - // repeated .com.webank.wedpr.acv.proto.StringToCountingPartPair candidate_part = 2; + // bytes equality_proof = 3; - pub fn get_candidate_part(&self) -> &[StringToCountingPartPair] { - &self.candidate_part + pub fn get_equality_proof(&self) -> &[u8] { + &self.equality_proof } - pub fn clear_candidate_part(&mut self) { - self.candidate_part.clear(); + pub fn clear_equality_proof(&mut self) { + self.equality_proof.clear(); } // Param is passed by value, moved - pub fn set_candidate_part(&mut self, v: ::protobuf::RepeatedField) { - self.candidate_part = v; + pub fn set_equality_proof(&mut self, v: ::std::vec::Vec) { + self.equality_proof = 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_equality_proof(&mut self) -> &mut ::std::vec::Vec { + &mut self.equality_proof } // Take field - pub fn take_candidate_part(&mut self) -> ::protobuf::RepeatedField { - ::std::mem::replace(&mut self.candidate_part, ::protobuf::RepeatedField::new()) + 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 DecryptedResultPartStorage { +impl ::protobuf::Message for CountingPart { fn is_initialized(&self) -> bool { - for v in &self.blank_part { - if !v.is_initialized() { - return false; - } - }; - for v in &self.candidate_part { - if !v.is_initialized() { - return false; - } - }; true } @@ -3591,10 +3602,13 @@ 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)?; + ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.counter_id)?; }, 2 => { - ::protobuf::rt::read_repeated_message_into(wire_type, is, &mut self.candidate_part)?; + ::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())?; @@ -3608,30 +3622,30 @@ 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() { - let len = v.compute_size(); - my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; + 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); } - for value in &self.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 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 !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)?; } - 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)?; - }; os.write_unknown_fields(self.get_unknown_fields())?; ::std::result::Result::Ok(()) } @@ -3662,53 +3676,59 @@ impl ::protobuf::Message for DecryptedResultPartStorage { Self::descriptor_static() } - fn new() -> DecryptedResultPartStorage { - DecryptedResultPartStorage::new() + 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_singular_ptr_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( - "blank_part", - |m: &DecryptedResultPartStorage| { &m.blank_part }, - |m: &mut DecryptedResultPartStorage| { &mut m.blank_part }, + 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_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_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( + "blinding_c2", + |m: &CountingPart| { &m.blinding_c2 }, + |m: &mut CountingPart| { &mut m.blinding_c2 }, )); - ::protobuf::reflect::MessageDescriptor::new_pb_name::( - "DecryptedResultPartStorage", + 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 DecryptedResultPartStorage { - static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; - instance.get(DecryptedResultPartStorage::new) + fn default_instance() -> &'static CountingPart { + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(CountingPart::new) } } -impl ::protobuf::Clear for DecryptedResultPartStorage { +impl ::protobuf::Clear for CountingPart { fn clear(&mut self) { - self.blank_part.clear(); - self.candidate_part.clear(); + self.counter_id.clear(); + self.blinding_c2.clear(); + self.equality_proof.clear(); self.unknown_fields.clear(); } } -impl ::std::fmt::Debug for DecryptedResultPartStorage { +impl ::std::fmt::Debug for CountingPart { 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 CountingPart { fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { ::protobuf::reflect::ReflectValueRef::Message(self) } @@ -3931,108 +3951,97 @@ impl ::protobuf::reflect::ProtobufValue for StringToCountingPartPair { } #[derive(PartialEq,Clone,Default)] -pub struct CountingPart { +pub struct DecryptedResultPartStorage { // message fields - pub counter_id: ::std::string::String, - pub blinding_c2: ::std::vec::Vec, - pub equality_proof: ::std::vec::Vec, + pub blank_part: ::protobuf::SingularPtrField, + pub candidate_part: ::protobuf::RepeatedField, // 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 DecryptedResultPartStorage { + fn default() -> &'a DecryptedResultPartStorage { + ::default_instance() } } -impl CountingPart { - pub fn new() -> CountingPart { +impl DecryptedResultPartStorage { + pub fn new() -> DecryptedResultPartStorage { ::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(); - } + // .com.webank.wedpr.acv.proto.CountingPart blank_part = 1; - // 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_blank_part(&self) -> &CountingPart { + self.blank_part.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_blank_part(&mut self) { + self.blank_part.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_blank_part(&self) -> bool { + self.blank_part.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_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_blinding_c2(&mut self) -> &mut ::std::vec::Vec { - &mut self.blinding_c2 + 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_blinding_c2(&mut self) -> ::std::vec::Vec { - ::std::mem::replace(&mut self.blinding_c2, ::std::vec::Vec::new()) + pub fn take_blank_part(&mut self) -> CountingPart { + self.blank_part.take().unwrap_or_else(|| CountingPart::new()) } - // bytes equality_proof = 3; + // repeated .com.webank.wedpr.acv.proto.StringToCountingPartPair candidate_part = 2; - pub fn get_equality_proof(&self) -> &[u8] { - &self.equality_proof + pub fn get_candidate_part(&self) -> &[StringToCountingPartPair] { + &self.candidate_part } - pub fn clear_equality_proof(&mut self) { - self.equality_proof.clear(); + pub fn clear_candidate_part(&mut self) { + self.candidate_part.clear(); } // Param is passed by value, moved - pub fn set_equality_proof(&mut self, v: ::std::vec::Vec) { - self.equality_proof = v; + pub fn set_candidate_part(&mut self, v: ::protobuf::RepeatedField) { + self.candidate_part = 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_candidate_part(&mut self) -> &mut ::protobuf::RepeatedField { + &mut self.candidate_part } // 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_candidate_part(&mut self) -> ::protobuf::RepeatedField { + ::std::mem::replace(&mut self.candidate_part, ::protobuf::RepeatedField::new()) } } -impl ::protobuf::Message for CountingPart { +impl ::protobuf::Message for DecryptedResultPartStorage { fn is_initialized(&self) -> bool { + for v in &self.blank_part { + if !v.is_initialized() { + return false; + } + }; + for v in &self.candidate_part { + if !v.is_initialized() { + return false; + } + }; true } @@ -4041,13 +4050,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)?; + ::protobuf::rt::read_singular_message_into(wire_type, is, &mut self.blank_part)?; }, 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_repeated_message_into(wire_type, is, &mut self.candidate_part)?; }, _ => { ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; @@ -4061,30 +4067,30 @@ 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 !self.equality_proof.is_empty() { - my_size += ::protobuf::rt::bytes_size(3, &self.equality_proof); + 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; + }; 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)?; + 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)?; } + 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)?; + }; os.write_unknown_fields(self.get_unknown_fields())?; ::std::result::Result::Ok(()) } @@ -4115,59 +4121,53 @@ impl ::protobuf::Message for CountingPart { Self::descriptor_static() } - fn new() -> CountingPart { - CountingPart::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>( - "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>( + "blank_part", + |m: &DecryptedResultPartStorage| { &m.blank_part }, + |m: &mut DecryptedResultPartStorage| { &mut m.blank_part }, )); - 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_repeated_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( + "candidate_part", + |m: &DecryptedResultPartStorage| { &m.candidate_part }, + |m: &mut DecryptedResultPartStorage| { &mut m.candidate_part }, )); - ::protobuf::reflect::MessageDescriptor::new_pb_name::( - "CountingPart", + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "DecryptedResultPartStorage", 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 DecryptedResultPartStorage { + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(DecryptedResultPartStorage::new) } } -impl ::protobuf::Clear for CountingPart { +impl ::protobuf::Clear for DecryptedResultPartStorage { fn clear(&mut self) { - self.counter_id.clear(); - self.blinding_c2.clear(); - self.equality_proof.clear(); + self.blank_part.clear(); + self.candidate_part.clear(); self.unknown_fields.clear(); } } -impl ::std::fmt::Debug for CountingPart { +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 CountingPart { +impl ::protobuf::reflect::ProtobufValue for DecryptedResultPartStorage { fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { ::protobuf::reflect::ReflectValueRef::Message(self) } @@ -4534,60 +4534,60 @@ impl ::protobuf::reflect::ProtobufValue for StringToInt64Pair { } static file_descriptor_proto_data: &'static [u8] = b"\ - \n\x16solution/acv/acv.proto\x12\x1acom.webank.wedpr.acv.proto\";\n\rCou\ - nterSecret\x12*\n\x11poll_secret_share\x18\x01\x20\x01(\x0cR\x0fpollSecr\ - etShare\"n\n#CounterSystemParametersShareRequest\x12\x1d\n\ncounter_id\ - \x18\x01\x20\x01(\tR\tcounterId\x12(\n\x10poll_point_share\x18\x02\x20\ - \x01(\x0cR\x0epollPointShare\"\x9f\x01\n\x1eCounterSystemParametersStora\ - ge\x12}\n\x1acounter_parameters_request\x18\x01\x20\x03(\x0b2?.com.weban\ - k.wedpr.acv.proto.CounterSystemParametersShareRequestR\x18counterParamet\ - ersRequest\"0\n\x0bVoterSecret\x12!\n\x0cvoter_secret\x18\x01\x20\x01(\ - \x0cR\x0bvoterSecret\"o\n\x13RegistrationRequest\x12X\n\x0cweight_point\ - \x18\x01\x20\x01(\x0b25.com.webank.wedpr.acv.proto.RegistrationBlindingP\ - ointR\x0bweightPoint\"\x7f\n\x19RegistrationBlindingPoint\x12.\n\x13blin\ - ding_poll_point\x18\x01\x20\x01(\x0cR\x11blindingPollPoint\x122\n\x15bli\ - nding_basepoint_g2\x18\x02\x20\x01(\x0cR\x13blindingBasepointG2\"\x93\ - \x01\n\x14RegistrationResponse\x12!\n\x0cvoter_weight\x18\x01\x20\x01(\r\ - R\x0bvoterWeight\x12:\n\x06ballot\x18\x02\x20\x01(\x0b2\".com.webank.wed\ - pr.acv.proto.BallotR\x06ballot\x12\x1c\n\tsignature\x18\x03\x20\x01(\x0c\ - R\tsignature\"L\n\x06Ballot\x12\x20\n\x0bciphertext1\x18\x01\x20\x01(\ - \x0cR\x0bciphertext1\x12\x20\n\x0bciphertext2\x18\x02\x20\x01(\x0cR\x0bc\ - iphertext2\"@\n\nVoteChoice\x12\x1c\n\tcandidate\x18\x01\x20\x01(\tR\tca\ - ndidate\x12\x14\n\x05value\x18\x02\x20\x01(\rR\x05value\"M\n\x0bVoteChoi\ - ces\x12>\n\x06choice\x18\x01\x20\x03(\x0b2&.com.webank.wedpr.acv.proto.V\ - oteChoiceR\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\"\x87\x02\n\x0bVoteStorage\x12\ - \x1c\n\tsignature\x18\x01\x20\x01(\x0cR\tsignature\x12E\n\x0cblank_ballo\ - t\x18\x02\x20\x01(\x0b2\".com.webank.wedpr.acv.proto.BallotR\x0bblankBal\ - lot\x12C\n\x0brest_ballot\x18\x03\x20\x01(\x0b2\".com.webank.wedpr.acv.p\ - roto.BallotR\nrestBallot\x12N\n\x0cvoted_ballot\x18\x04\x20\x03(\x0b2+.c\ - om.webank.wedpr.acv.proto.CandidateBallotR\x0bvotedBallot\"-\n\rCandidat\ - eList\x12\x1c\n\tcandidate\x18\x01\x20\x03(\tR\tcandidate\"\x83\x01\n\ - \x17SystemParametersStorage\x12\x1d\n\npoll_point\x18\x01\x20\x01(\x0cR\ + \n\x16solution/acv/acv.proto\x12\x1acom.webank.wedpr.acv.proto\"-\n\rCan\ + didateList\x12\x1c\n\tcandidate\x18\x01\x20\x03(\tR\tcandidate\"\x81\x01\ + \n\x15PollParametersStorage\x12\x1d\n\npoll_point\x18\x01\x20\x01(\x0cR\ \tpollPoint\x12I\n\ncandidates\x18\x02\x20\x01(\x0b2).com.webank.wedpr.a\ - cv.proto.CandidateListR\ncandidates\"0\n\x0bBallotProof\x12!\n\x0cformat\ - _proof\x18\x01\x20\x01(\x0cR\x0bformatProof\"s\n\x20StringToCandidateBal\ - lotProofPair\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\ - \"\xf8\x01\n\x0bVoteRequest\x12;\n\x04vote\x18\x01\x20\x01(\x0b2'.com.we\ - bank.wedpr.acv.proto.VoteStorageR\x04vote\x12_\n\x0cballot_proof\x18\x02\ - \x20\x03(\x0b2<.com.webank.wedpr.acv.proto.StringToCandidateBallotProofP\ - airR\x0bballotProof\x12\x1f\n\x0brange_proof\x18\x03\x20\x01(\x0cR\nrang\ - eProof\x12*\n\x11sum_balance_proof\x18\x04\x20\x01(\x0cR\x0fsumBalancePr\ - oof\"\xc2\x01\n\x1aDecryptedResultPartStorage\x12G\n\nblank_part\x18\x01\ - \x20\x01(\x0b2(.com.webank.wedpr.acv.proto.CountingPartR\tblankPart\x12[\ - \n\x0ecandidate_part\x18\x02\x20\x03(\x0b24.com.webank.wedpr.acv.proto.S\ - tringToCountingPartPairR\rcandidatePart\"l\n\x18StringToCountingPartPair\ - \x12\x10\n\x03key\x18\x01\x20\x01(\tR\x03key\x12>\n\x05value\x18\x02\x20\ - \x01(\x0b2(.com.webank.wedpr.acv.proto.CountingPartR\x05value\"u\n\x0cCo\ - untingPart\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_p\ - roof\x18\x03\x20\x01(\x0cR\requalityProof\"Z\n\x11VoteResultStorage\x12E\ - \n\x06result\x18\x01\x20\x03(\x0b2-.com.webank.wedpr.acv.proto.StringToI\ - nt64PairR\x06result\";\n\x11StringToInt64Pair\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\ + 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\ "; 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 4e954a3..aa0f428 100644 --- a/protos/src/generated/hdk.rs +++ b/protos/src/generated/hdk.rs @@ -1,4 +1,6 @@ -// This file is generated by rust-protobuf 2.25.1. Do not edit +// Copyright 2021 WeDPR Lab Project Authors. Licensed under Apache-2.0. + +// This file is generated by rust-protobuf 2.22.1. Do not edit // @generated // https://github.com/rust-lang/rust-clippy/issues/702 @@ -21,7 +23,7 @@ /// Generated files are compatible only with the same version /// of protobuf runtime. -// const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_25_1; +// const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_22_1; #[derive(PartialEq,Clone,Default)] pub struct HdkResult { diff --git a/protos/src/generated/mod.rs b/protos/src/generated/mod.rs index dea52e1..888b89a 100644 --- a/protos/src/generated/mod.rs +++ b/protos/src/generated/mod.rs @@ -1,4 +1,4 @@ -// Copyright 2020 WeDPR Lab Project Authors. Licensed under Apache-2.0. +// Copyright 2021 WeDPR Lab Project Authors. Licensed under Apache-2.0. pub mod acv; pub mod hdk; diff --git a/protos/src/generated/scd.rs b/protos/src/generated/scd.rs index f02bf66..d9bd149 100644 --- a/protos/src/generated/scd.rs +++ b/protos/src/generated/scd.rs @@ -1,6 +1,6 @@ // Copyright 2020 WeDPR Lab Project Authors. Licensed under Apache-2.0. -// This file is generated by rust-protobuf 2.25.1. Do not edit +// This file is generated by rust-protobuf 2.22.1. Do not edit // @generated // https://github.com/rust-lang/rust-clippy/issues/702 @@ -23,7 +23,7 @@ /// Generated files are compatible only with the same version /// of protobuf runtime. -// const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_25_1; +// const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_22_1; #[derive(PartialEq,Clone,Default)] pub struct CertificateSchema { diff --git a/protos/src/generated/vcl.rs b/protos/src/generated/vcl.rs index 54c9de9..e086e05 100644 --- a/protos/src/generated/vcl.rs +++ b/protos/src/generated/vcl.rs @@ -1,6 +1,6 @@ // Copyright 2020 WeDPR Lab Project Authors. Licensed under Apache-2.0. -// This file is generated by rust-protobuf 2.25.1. Do not edit +// This file is generated by rust-protobuf 2.22.1. Do not edit // @generated // https://github.com/rust-lang/rust-clippy/issues/702 @@ -23,7 +23,7 @@ /// Generated files are compatible only with the same version /// of protobuf runtime. -// const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_25_1; +// const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_22_1; #[derive(PartialEq,Clone,Default)] pub struct EncodedOwnerSecret { diff --git a/solution/anonymous_ciphertext_voting/src/config.rs b/solution/anonymous_ciphertext_voting/src/config.rs index 7a6fe46..75c4cb8 100644 --- a/solution/anonymous_ciphertext_voting/src/config.rs +++ b/solution/anonymous_ciphertext_voting/src/config.rs @@ -6,9 +6,12 @@ use wedpr_l_crypto_hash_keccak256::WedprKeccak256; use wedpr_l_crypto_signature_secp256k1::WedprSecp256k1Recover; lazy_static! { - /// Shared hash algorithm reference for quick implementation replacement. - /// Other code should use this reference, and not directly use a specific implementation. - pub static ref SIGNATURE_SECP256K1: WedprSecp256k1Recover = + /// Shared signature algorithm reference for quick implementation replacement. + pub static ref SIGNATURE: WedprSecp256k1Recover = WedprSecp256k1Recover::default(); - pub static ref HASH_KECCAK256: WedprKeccak256 = WedprKeccak256::default(); + /// Shared hash algorithm reference for quick implementation replacement. + pub static ref HASH: WedprKeccak256 = WedprKeccak256::default(); } + +/// Poll result key for total ballots. +pub const POLL_RESULT_KEY_TOTAL_BALLOTS: &str = "Wedpr_voting_total_ballots"; diff --git a/solution/anonymous_ciphertext_voting/src/coordinator.rs b/solution/anonymous_ciphertext_voting/src/coordinator.rs index 7089175..fef77ac 100644 --- a/solution/anonymous_ciphertext_voting/src/coordinator.rs +++ b/solution/anonymous_ciphertext_voting/src/coordinator.rs @@ -1,6 +1,6 @@ // Copyright 2020 WeDPR Lab Project Authors. Licensed under Apache-2.0. -//! Library of anonymous ciphertext voting (ACV) solution. +//! Library for a poll coordinator. use curve25519_dalek::{ristretto::RistrettoPoint, scalar::Scalar}; use wedpr_l_crypto_zkp_utils::{bytes_to_point, point_to_bytes, BASEPOINT_G1}; @@ -10,36 +10,39 @@ use wedpr_l_utils::{ }; use wedpr_s_protos::generated::acv::{ - Ballot, CandidateBallot, CandidateList, CounterSystemParametersStorage, - CountingPart, DecryptedResultPartStorage, RegistrationRequest, - RegistrationResponse, StringToCountingPartPair, StringToInt64Pair, - SystemParametersStorage, VoteResultStorage, VoteStorage, + Ballot, CandidateBallot, CandidateList, CounterParametersStorage, + CountingPart, DecryptedResultPartStorage, PollParametersStorage, + RegistrationRequest, RegistrationResponse, StringToCountingPartPair, + StringToInt64Pair, VoteResultStorage, VoteStorage, }; -use crate::config::{HASH_KECCAK256, SIGNATURE_SECP256K1}; +use crate::{ + config::{HASH, POLL_RESULT_KEY_TOTAL_BALLOTS, SIGNATURE}, + utils::{get_ballot_by_candidate, get_counting_part_by_candidate}, +}; -/// Makes system parameters containing public key and candidates list using -/// counter storage messages. -pub fn make_system_parameters( - candidates: &CandidateList, - counter_storage: &CounterSystemParametersStorage, -) -> Result { +/// Makes system parameters for a new poll. +pub fn make_poll_parameters( + candidate_list: &CandidateList, + counter_parameters: &CounterParametersStorage, +) -> Result { let mut poll_point = RistrettoPoint::default(); - for counter_request in counter_storage.get_counter_parameters_request() { - poll_point += bytes_to_point(counter_request.get_poll_point_share())?; + for share in counter_parameters.get_counter_parameters_share() { + poll_point += bytes_to_point(share.get_poll_point_share())?; } - let mut storage = SystemParametersStorage::default(); - storage.set_candidates(candidates.clone()); + + let mut storage = PollParametersStorage::default(); + storage.set_candidates(candidate_list.clone()); storage.set_poll_point(point_to_bytes(&poll_point)); Ok(storage) } -/// Certifies voter's weight which indicates the maximum value that the voter -/// can vote in total. +/// Certifies a voter's registration. It confirm its weight which indicates the +/// maximum votes that the voter can vote for all candidates in a poll. pub fn certify_voter( secret_key: &[u8], - value: u32, registration_request: &RegistrationRequest, + voter_weight: u32, ) -> Result { let blinding_poll_point = bytes_to_point( registration_request @@ -47,7 +50,7 @@ pub fn certify_voter( .get_blinding_poll_point(), )?; let ciphertext1 = - blinding_poll_point + (*BASEPOINT_G1 * Scalar::from(value)); + blinding_poll_point + (*BASEPOINT_G1 * Scalar::from(voter_weight)); let mut ballot = Ballot::new(); ballot.set_ciphertext1(point_to_bytes(&ciphertext1)); ballot.set_ciphertext2( @@ -56,33 +59,34 @@ pub fn certify_voter( .get_blinding_basepoint_g2() .to_vec(), ); + // 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_KECCAK256.hash(&hash_vec); - let signature = SIGNATURE_SECP256K1.sign(secret_key, &message_hash)?; + let message_hash = HASH.hash(&hash_vec); + let signature = SIGNATURE.sign(secret_key, &message_hash)?; + let mut response = RegistrationResponse::new(); response.set_signature(signature); response.set_ballot(ballot); - response.set_voter_weight(value); + response.set_voter_weight(voter_weight); Ok(response) } -/// Aggregates anonymous ciphertext ballot from all voters for each candidate. +/// Aggregates all ciphertext ballots from a voter. pub fn aggregate_vote_sum_response( - param: &SystemParametersStorage, - vote_storage_part: &VoteStorage, + poll_parameters: &PollParametersStorage, + vote_part: &VoteStorage, vote_sum: &mut VoteStorage, ) -> Result { - // Init storage when first part upload + // Initialize for the first part. if !vote_sum.has_blank_ballot() { - vote_sum - .mut_blank_ballot() + let blank_ballot = vote_sum.mut_blank_ballot(); + blank_ballot .set_ciphertext1(point_to_bytes(&RistrettoPoint::default())); - vote_sum - .mut_blank_ballot() + blank_ballot .set_ciphertext2(point_to_bytes(&RistrettoPoint::default())); - for candidate in param.get_candidates().get_candidate() { + for candidate in poll_parameters.get_candidates().get_candidate() { let mut ballot = Ballot::new(); ballot.set_ciphertext1(point_to_bytes(&RistrettoPoint::default())); ballot.set_ciphertext2(point_to_bytes(&RistrettoPoint::default())); @@ -92,185 +96,160 @@ pub fn aggregate_vote_sum_response( vote_sum.mut_voted_ballot().push(ballot_pair); } } - let mut tmp_vote_storage_sum = VoteStorage::new(); - let mut blank_c1_sum = - bytes_to_point(&vote_sum.get_blank_ballot().get_ciphertext1())?; - let mut blank_c2_sum = - bytes_to_point(&vote_sum.get_blank_ballot().get_ciphertext2())?; - let c1_tmp_point = bytes_to_point( - &vote_storage_part - .get_blank_ballot() - .get_ciphertext1() - .clone(), - )?; - let c2_tmp_point = bytes_to_point( - &vote_storage_part - .get_blank_ballot() - .get_ciphertext2() - .clone(), - )?; - blank_c1_sum += c1_tmp_point; - blank_c2_sum += c2_tmp_point; - for candidate in param.get_candidates().get_candidate() { - let mut candidate_ballot = Ballot::new(); - for tmp_pair in vote_sum.get_voted_ballot() { - if tmp_pair.get_candidate() == candidate { - candidate_ballot = tmp_pair.get_ballot().clone(); - } - } - let mut candidate_voted_c1_sum = - bytes_to_point(&candidate_ballot.get_ciphertext1())?; - let mut candidate_voted_c2_sum = - bytes_to_point(&candidate_ballot.get_ciphertext2())?; - let mut candidates_ballot = Ballot::new(); - for ballot_pair in vote_storage_part.get_voted_ballot() { - if candidate == ballot_pair.get_candidate() { - candidates_ballot = ballot_pair.get_ballot().clone(); - } - } - candidate_voted_c1_sum += - bytes_to_point(&candidates_ballot.get_ciphertext1())?; - candidate_voted_c2_sum += - bytes_to_point(&candidates_ballot.get_ciphertext2())?; - let mut vote_ballot = Ballot::new(); - vote_ballot.set_ciphertext1(point_to_bytes(&candidate_voted_c1_sum)); - vote_ballot.set_ciphertext2(point_to_bytes(&candidate_voted_c2_sum)); - let mut tmp_pair = CandidateBallot::new(); - tmp_pair.set_candidate(candidate.to_string()); - tmp_pair.set_ballot(vote_ballot); - tmp_vote_storage_sum.mut_voted_ballot().push(tmp_pair); + let c1_point = + bytes_to_point(&vote_part.get_blank_ballot().get_ciphertext1())?; + let blank_c1_sum = + bytes_to_point(&vote_sum.get_blank_ballot().get_ciphertext1())? + + c1_point; + let c2_point = + bytes_to_point(&vote_part.get_blank_ballot().get_ciphertext2())?; + let blank_c2_sum = + bytes_to_point(&vote_sum.get_blank_ballot().get_ciphertext2())? + + c2_point; + + let mut output_vote_sum = VoteStorage::new(); + for candidate in poll_parameters.get_candidates().get_candidate() { + let sum_ballot = get_ballot_by_candidate(&vote_sum, candidate)?; + let new_ballot = get_ballot_by_candidate(&vote_part, candidate)?; + let candidate_voted_c1_sum = + bytes_to_point(&sum_ballot.get_ciphertext1())? + + bytes_to_point(&new_ballot.get_ciphertext1())?; + let candidate_voted_c2_sum = + bytes_to_point(&sum_ballot.get_ciphertext2())? + + bytes_to_point(&new_ballot.get_ciphertext2())?; + + // Write back. + let mut new_sum_ballot = Ballot::new(); + new_sum_ballot.set_ciphertext1(point_to_bytes(&candidate_voted_c1_sum)); + new_sum_ballot.set_ciphertext2(point_to_bytes(&candidate_voted_c2_sum)); + let mut new_pair = CandidateBallot::new(); + new_pair.set_candidate(candidate.to_string()); + new_pair.set_ballot(new_sum_ballot); + output_vote_sum.mut_voted_ballot().push(new_pair); } - tmp_vote_storage_sum - .mut_blank_ballot() - .set_ciphertext1(point_to_bytes(&blank_c1_sum)); - tmp_vote_storage_sum - .mut_blank_ballot() - .set_ciphertext2(point_to_bytes(&blank_c2_sum)); - *vote_sum = tmp_vote_storage_sum.clone(); + let blank_ballot = output_vote_sum.mut_blank_ballot(); + blank_ballot.set_ciphertext1(point_to_bytes(&blank_c1_sum)); + blank_ballot.set_ciphertext2(point_to_bytes(&blank_c2_sum)); + *vote_sum = output_vote_sum; Ok(true) } -/// Aggregates decrypted ballot from all counters for each candidate. +/// Aggregates a partially decrypted result from a counter. pub fn aggregate_decrypted_part_sum( - param: &SystemParametersStorage, - decrypted_result_part_storage: &DecryptedResultPartStorage, - counting_result_sum: &mut DecryptedResultPartStorage, + poll_parameters: &PollParametersStorage, + partially_decrypted_result: &DecryptedResultPartStorage, + aggregated_decrypted_result: &mut DecryptedResultPartStorage, ) -> Result { - // Init storage when first part upload - if !counting_result_sum.has_blank_part() { - counting_result_sum - .mut_blank_part() - .set_counter_id("default".to_string()); - counting_result_sum - .mut_blank_part() - .set_blinding_c2(point_to_bytes(&RistrettoPoint::default())); - for candidate in param.get_candidates().get_candidate() { + // Initialize for the first part. + if !aggregated_decrypted_result.has_blank_part() { + let blank_part = aggregated_decrypted_result.mut_blank_part(); + blank_part.set_counter_id("sum".to_string()); + blank_part.set_blinding_c2(point_to_bytes(&RistrettoPoint::default())); + for candidate in poll_parameters.get_candidates().get_candidate() { let mut counting_part = CountingPart::new(); counting_part .set_blinding_c2(point_to_bytes(&RistrettoPoint::default())); - let mut tmp_pair = StringToCountingPartPair::new(); - tmp_pair.set_key(candidate.to_string()); - tmp_pair.set_value(counting_part); - counting_result_sum.mut_candidate_part().push(tmp_pair); + let mut new_pair = StringToCountingPartPair::new(); + new_pair.set_key(candidate.to_string()); + new_pair.set_value(counting_part); + aggregated_decrypted_result + .mut_candidate_part() + .push(new_pair); } } - let mut blank_c2_r_sum = bytes_to_point( - &counting_result_sum.get_blank_part().get_blinding_c2(), - )?; + let blank_part_share = bytes_to_point( - &decrypted_result_part_storage + &partially_decrypted_result .get_blank_part() .get_blinding_c2(), )?; - - blank_c2_r_sum += blank_part_share; - counting_result_sum + let blank_c2_r_sum = bytes_to_point( + &aggregated_decrypted_result + .get_blank_part() + .get_blinding_c2(), + )? + blank_part_share; + aggregated_decrypted_result .mut_blank_part() .set_blinding_c2(point_to_bytes(&blank_c2_r_sum)); - for candidate in param.get_candidates().get_candidate() { - let mut candidate_counting_part = CountingPart::new(); - for tmp_pair in counting_result_sum.get_candidate_part() { - if candidate == tmp_pair.get_key() { - candidate_counting_part = tmp_pair.get_value().clone(); - } - } - - let mut candidate_c2_r_sum = - bytes_to_point(&candidate_counting_part.get_blinding_c2())?; - let mut counting_part = CountingPart::new(); - for tmp_pair in decrypted_result_part_storage.get_candidate_part() { - if candidate == tmp_pair.get_key() { - counting_part = tmp_pair.get_value().clone(); - } - } + let mut output_decrypted_result = aggregated_decrypted_result.clone(); + output_decrypted_result.clear_candidate_part(); + for candidate in poll_parameters.get_candidates().get_candidate() { + let aggregated_part = get_counting_part_by_candidate( + &aggregated_decrypted_result, + candidate, + )?; + let new_part = get_counting_part_by_candidate( + &partially_decrypted_result, + candidate, + )?; + let candidate_c2_r = bytes_to_point(&new_part.get_blinding_c2())?; + let candidate_c2_r_sum = + bytes_to_point(&aggregated_part.get_blinding_c2())? + + candidate_c2_r; - let candidate_c2_r = bytes_to_point(&counting_part.get_blinding_c2())?; - candidate_c2_r_sum += candidate_c2_r; + // Write back. let mut candidate_part = CountingPart::new(); candidate_part.set_blinding_c2(point_to_bytes(&candidate_c2_r_sum)); - let mut tmp_pair = StringToCountingPartPair::new(); - tmp_pair.set_key(candidate.to_string()); - tmp_pair.set_value(candidate_part); - counting_result_sum.mut_candidate_part().push(tmp_pair); + let mut new_pair = StringToCountingPartPair::new(); + new_pair.set_key(candidate.to_string()); + new_pair.set_value(candidate_part); + output_decrypted_result.mut_candidate_part().push(new_pair); } + *aggregated_decrypted_result = output_decrypted_result; Ok(true) } -/// Count the final result of ballots received by each candidate. +/// Computes the final vote result from aggregated partially decrypted results. pub fn finalize_vote_result( - param: &SystemParametersStorage, + poll_parameters: &PollParametersStorage, vote_sum: &VoteStorage, - counting_result_sum: &DecryptedResultPartStorage, - max_number: i64, + aggregated_decrypted_result: &DecryptedResultPartStorage, + max_vote_limit: i64, ) -> Result { - let mut request = VoteResultStorage::new(); + let mut result = VoteResultStorage::new(); let blank_c1_sum = bytes_to_point(vote_sum.get_blank_ballot().get_ciphertext1())?; - let blank_c2_r_sum = - bytes_to_point(counting_result_sum.get_blank_part().get_blinding_c2())?; - let tmp = blank_c1_sum - (blank_c2_r_sum); - for i in 1..=max_number { - let try_num = Scalar::from(i as u64); - if tmp.eq(&(*BASEPOINT_G1 * try_num)) { - let mut tmp_pair = StringToInt64Pair::new(); - tmp_pair.set_key("Wedpr_voting_total_ballots".to_string()); - tmp_pair.set_value(i); - request.mut_result().push(tmp_pair); + let blank_c2_r_sum = bytes_to_point( + aggregated_decrypted_result + .get_blank_part() + .get_blinding_c2(), + )?; + + // Compute the total votes. + let target_total = blank_c1_sum - blank_c2_r_sum; + for i in 1..=max_vote_limit { + if target_total.eq(&(*BASEPOINT_G1 * Scalar::from(i as u64))) { + let mut new_pair = StringToInt64Pair::new(); + new_pair.set_key(POLL_RESULT_KEY_TOTAL_BALLOTS.to_string()); + new_pair.set_value(i); + result.mut_result().push(new_pair); break; } } - for candidate in param.get_candidates().get_candidate() { - let mut ballot = Ballot::new(); - for tmp_pair in vote_sum.get_voted_ballot() { - if candidate == tmp_pair.get_candidate() { - ballot = tmp_pair.get_ballot().clone(); - } - } - let mut candidate_counting_part = CountingPart::new(); - for tmp_pair in counting_result_sum.get_candidate_part() { - if candidate == tmp_pair.get_key() { - candidate_counting_part = tmp_pair.get_value().clone(); - } - } + // Compute the votes for each candidate. + for candidate in poll_parameters.get_candidates().get_candidate() { + let ballot = get_ballot_by_candidate(vote_sum, candidate)?; + let candidate_counting_part = get_counting_part_by_candidate( + aggregated_decrypted_result, + candidate, + )?; let candidate_c2_r_sum = bytes_to_point(candidate_counting_part.get_blinding_c2())?; - let tmp = - bytes_to_point(ballot.get_ciphertext1())? - (candidate_c2_r_sum); - - for i in 0..=max_number { - let try_num = Scalar::from(i as u64); - - if tmp.eq(&(*BASEPOINT_G1 * try_num)) { - let mut tmp_pair = StringToInt64Pair::new(); - tmp_pair.set_key(candidate.to_string()); - tmp_pair.set_value(i); - request.mut_result().push(tmp_pair); + let target_candidate = + bytes_to_point(ballot.get_ciphertext1())? - candidate_c2_r_sum; + + for i in 0..=max_vote_limit { + if target_candidate.eq(&(*BASEPOINT_G1 * Scalar::from(i as u64))) { + let mut new_pair = StringToInt64Pair::new(); + new_pair.set_key(candidate.to_string()); + new_pair.set_value(i); + result.mut_result().push(new_pair); break; } } } - Ok(request) + Ok(result) } diff --git a/solution/anonymous_ciphertext_voting/src/counter.rs b/solution/anonymous_ciphertext_voting/src/counter.rs index 6451866..8d3aa60 100644 --- a/solution/anonymous_ciphertext_voting/src/counter.rs +++ b/solution/anonymous_ciphertext_voting/src/counter.rs @@ -1,6 +1,6 @@ // Copyright 2020 WeDPR Lab Project Authors. Licensed under Apache-2.0. -//! Library of anonymous ciphertext voting (ACV) solution. +//! Library for a poll counter. use wedpr_l_crypto_zkp_discrete_logarithm_proof::prove_equality_relationship_proof; use wedpr_l_crypto_zkp_utils::{ @@ -11,12 +11,11 @@ use wedpr_l_protos::proto_to_bytes; use wedpr_l_utils::error::WedprError; use wedpr_s_protos::generated::acv::{ - CounterSecret, CounterSystemParametersShareRequest, CountingPart, + CounterParametersShareRequest, CounterSecret, CountingPart, DecryptedResultPartStorage, StringToCountingPartPair, VoteStorage, }; -/// Generates a random number as secret key for making system parameter and -/// counting. +/// Makes secrets used by a counter. pub fn make_counter_secret() -> CounterSecret { let secret_share = get_random_scalar(); CounterSecret { @@ -26,16 +25,15 @@ pub fn make_counter_secret() -> CounterSecret { } } -/// Makes share of system parameter using secret key, -/// where system parameter here means global public key. -pub fn make_system_parameters_share( +/// Makes share of system parameters used by a group of counters. +pub fn make_parameters_share( counter_id: &str, counter_secret: &CounterSecret, -) -> Result { +) -> Result { let secret_scalar = bytes_to_scalar(counter_secret.get_poll_secret_share())?; let poll_point_share = secret_scalar * *BASEPOINT_G2; - Ok(CounterSystemParametersShareRequest { + Ok(CounterParametersShareRequest { counter_id: counter_id.to_string(), poll_point_share: point_to_bytes(&poll_point_share), unknown_fields: Default::default(), @@ -43,56 +41,58 @@ pub fn make_system_parameters_share( }) } -/// Generates decrypted ballot and zero-knowledge proof for final count, -/// where the decrypted ballot is the share of ballots received by each -/// candidate, the zero-knowledge proof is equality relationship proof used to -/// prove that counter's count process is correct, specifically refers to that -/// the secret key counter used in counting is equal to the secret key generated -/// for making system parameter. +/// Counts the aggregated ciphertext ballots and generates associated ZKP +/// proofs. pub fn count( counter_id: &str, - secret: &CounterSecret, - storage: &VoteStorage, + counter_secret: &CounterSecret, + encrypted_vote_sum: &VoteStorage, ) -> Result { - let secret_share = bytes_to_scalar(&secret.get_poll_secret_share())?; - let mut request = DecryptedResultPartStorage::new(); - let blank_ciphertext2_sum = - bytes_to_point(storage.get_blank_ballot().get_ciphertext2())?; - for candidate_ballot_pair in storage.get_voted_ballot() { - let candidate = candidate_ballot_pair.get_candidate(); + let secret_share = + bytes_to_scalar(&counter_secret.get_poll_secret_share())?; + let mut partially_decrypted_result = DecryptedResultPartStorage::new(); + for candidate_ballot_pair in encrypted_vote_sum.get_voted_ballot() { + // Count by partially decrypting the aggregated ciphertext ballots. let ballot = candidate_ballot_pair.get_ballot(); let candidate_part_share = bytes_to_point(ballot.get_ciphertext2())?; - let equity_proof = prove_equality_relationship_proof( - &secret_share, - &BASEPOINT_G2, - &candidate_part_share, - ); let mut counting_part = CountingPart::new(); counting_part.set_blinding_c2(point_to_bytes( &(&candidate_part_share * (secret_share)), )); - counting_part.set_equality_proof(proto_to_bytes(&equity_proof)?); + + // Prove the equality for each candidate. + let equality_proof = prove_equality_relationship_proof( + &secret_share, + &BASEPOINT_G2, + &candidate_part_share, + ); + counting_part.set_equality_proof(proto_to_bytes(&equality_proof)?); + + // Write back. + let candidate = candidate_ballot_pair.get_candidate(); let mut candidate_counting_part_pair = StringToCountingPartPair::new(); candidate_counting_part_pair.set_key(candidate.to_string()); candidate_counting_part_pair.set_value(counting_part); - request + partially_decrypted_result .mut_candidate_part() .push(candidate_counting_part_pair); } - let blank_part = blank_ciphertext2_sum * (secret_share); - let equity_proof = prove_equality_relationship_proof( + + // Prove the equality for the blank ballot. + let blank_ciphertext2_sum = bytes_to_point( + encrypted_vote_sum.get_blank_ballot().get_ciphertext2(), + )?; + let blinding_c2 = blank_ciphertext2_sum * (secret_share); + let equality_proof = prove_equality_relationship_proof( &secret_share, &BASEPOINT_G2, &blank_ciphertext2_sum, ); - request - .mut_blank_part() - .set_equality_proof(proto_to_bytes(&equity_proof)?); - request - .mut_blank_part() - .set_blinding_c2(point_to_bytes(&blank_part)); - request - .mut_blank_part() - .set_counter_id(counter_id.to_string()); - Ok(request) + + // Write back. + let blank_part = partially_decrypted_result.mut_blank_part(); + blank_part.set_equality_proof(proto_to_bytes(&equality_proof)?); + blank_part.set_blinding_c2(point_to_bytes(&blinding_c2)); + blank_part.set_counter_id(counter_id.to_string()); + Ok(partially_decrypted_result) } diff --git a/solution/anonymous_ciphertext_voting/src/lib.rs b/solution/anonymous_ciphertext_voting/src/lib.rs index c331659..586ced7 100644 --- a/solution/anonymous_ciphertext_voting/src/lib.rs +++ b/solution/anonymous_ciphertext_voting/src/lib.rs @@ -11,182 +11,173 @@ extern crate wedpr_l_macros; pub mod config; pub mod coordinator; pub mod counter; +mod utils; pub mod verifier; pub mod voter; #[cfg(test)] mod tests { + use super::*; + use crate::{config::SIGNATURE, coordinator}; use wedpr_l_crypto_zkp_utils::bytes_to_point; use wedpr_l_utils::traits::Signature; - use wedpr_s_protos::generated::acv::{ - CandidateList, CounterSecret, CounterSystemParametersStorage, - DecryptedResultPartStorage, VoteChoice, VoteChoices, VoteStorage, - VoterSecret, + CandidateList, CounterParametersStorage, CounterSecret, + DecryptedResultPartStorage, VoteStorage, VoterSecret, }; - use crate::{config::SIGNATURE_SECP256K1, coordinator}; - - use super::*; - #[test] fn test_anonymous_ciphertext_voting() { - // Generate coordinator's key pair - let max_vote_number = 20000; - let (public_key, secret_key) = SIGNATURE_SECP256K1.generate_keypair(); - let mut candidate_list = CandidateList::new(); - // Init candidate list - for candidate in vec!["Kitten", "Doge", "Bunny"] { - candidate_list.mut_candidate().push(candidate.to_string()); - } - let counter_id_list = vec!["1001", "1002", "1003"]; - let blank_ballot_count = vec![10, 100, 1000, 10000]; - + // Initialize a group of counters. let mut counter_secret_list: Vec = vec![]; - let mut counter_parameters_storage = - CounterSystemParametersStorage::default(); - // Counter init - for id in counter_id_list.clone() { - let share_secret = counter::make_counter_secret(); - counter_secret_list.push(share_secret.clone()); - let counter_parameters_request = - counter::make_system_parameters_share(id, &share_secret) + let mut counter_parameters = CounterParametersStorage::default(); + // You can use any strings for counter ids. + let counter_id_list = ["1001", "1002", "1003"]; + for counter_id in counter_id_list { + let counter_secret = counter::make_counter_secret(); + let counter_parameters_share = + counter::make_parameters_share(counter_id, &counter_secret) .unwrap(); - counter_parameters_storage - .mut_counter_parameters_request() - .push(counter_parameters_request.clone()); + counter_parameters + .mut_counter_parameters_share() + .push(counter_parameters_share); + counter_secret_list.push(counter_secret); } - // coordinator make system parameters - let system_parameters = coordinator::make_system_parameters( + + // Initialize the coordinator. + let (public_key, secret_key) = SIGNATURE.generate_keypair(); + + // Coordinator initializes a new poll. + let mut candidate_list = CandidateList::new(); + for candidate in ["Kitten", "Doge", "Bunny"] { + candidate_list.mut_candidate().push(candidate.to_string()); + } + let poll_parameters = coordinator::make_poll_parameters( &candidate_list, - &counter_parameters_storage, + &counter_parameters, ) .unwrap(); - // voter init + // Initialize all voters. let mut voter_secret_list: Vec = vec![]; - let mut response_list = vec![]; - - for blank_ballot in blank_ballot_count { + let mut voter_registration_list = vec![]; + // Voter weight is the max voting power of each voter assigned by + // coordinator. + let voter_weight_list = [10, 20, 50, 60]; + for voter_weight in voter_weight_list { let vote_secret = voter::make_voter_secret(); - voter_secret_list.push(vote_secret.clone()); - - // voter -> coordinator generate blank ballot - let vote_request = voter::make_registration_request( + // Register a voter with coordinator. + let registration_request = voter::make_registration_request( &vote_secret, - &system_parameters, + &poll_parameters, ) .unwrap(); - let response = coordinator::certify_voter( + let registration_response = coordinator::certify_voter( &secret_key, - blank_ballot, - &vote_request, + ®istration_request, + voter_weight, ) .unwrap(); - response_list.push(response.clone()); - // verify blank ballot - let result = - voter::verify_blank_ballot(&vote_request, &response).unwrap(); - assert_eq!(true, result); + // Verify the blank ballot contained in registration_response. + assert!(voter::verify_blank_ballot( + ®istration_request, + ®istration_response + ) + .unwrap()); + voter_registration_list.push(registration_response); + voter_secret_list.push(vote_secret); } - // voter vote - let make_choice = |x: &Vec| { - let mut choices = VoteChoices::new(); - for i in 0..candidate_list.get_candidate().len() { - let mut pair = VoteChoice::new(); - pair.set_candidate(candidate_list.get_candidate()[i].clone()); - pair.set_value(x[i]); - choices.mut_choice().push(pair); - } - choices - }; - - let voting_ballot_count: Vec> = - vec![vec![1, 2, 3], vec![10, 20, 30], vec![100, 200, 300], vec![ - 1000, 2000, 3000, + // All voters vote. + // Kitten Doge Bunny + // voter1: 1 2 3 + // voter2: 2 4 6 + // voter3: 10 15 25 + // voter4: 20 10 5 + let voter_choice_list: Vec> = + vec![vec![1, 2, 3], vec![2, 4, 6], vec![10, 15, 25], vec![ + 20, 10, 5, ]]; let mut vote_request_list = vec![]; let mut encrypted_vote_sum = VoteStorage::new(); - for index in 0..voting_ballot_count.len() { - let ballot_choice = make_choice(&voting_ballot_count[index]); + for index in 0..voter_choice_list.len() { + let vote_choices = voter::make_vote_choices( + &voter_choice_list[index], + &candidate_list, + ); let vote_request = voter::vote( &voter_secret_list[index], - &ballot_choice, - &response_list[index], - &system_parameters, + &vote_choices, + &voter_registration_list[index], + &poll_parameters, ) .unwrap(); - assert_eq!( - true, - verifier::verify_vote_request( - &system_parameters, - &vote_request, - &public_key - ) - .unwrap() - ); - assert_eq!( - true, - coordinator::aggregate_vote_sum_response( - &system_parameters, - &vote_request.get_vote(), - &mut encrypted_vote_sum - ) - .unwrap() - ); + assert!(verifier::verify_vote_request( + &poll_parameters, + &vote_request, + &public_key + ) + .unwrap()); + + // Coordinator aggregates individual ciphertext ballots. + assert!(coordinator::aggregate_vote_sum_response( + &poll_parameters, + &vote_request.get_vote(), + &mut encrypted_vote_sum + ) + .unwrap()); vote_request_list.push(vote_request); } - let mut vote_sum_total = DecryptedResultPartStorage::new(); - let length = counter_secret_list.len().clone(); - for index in 0..length { - let decrypt_request = counter::count( + + // All counters decrypt the poll result in a distributed manner. + let mut aggregated_decrypted_result = DecryptedResultPartStorage::new(); + for index in 0..counter_secret_list.len() { + let partially_decrypted_result = counter::count( &counter_id_list[index], &counter_secret_list[index], &encrypted_vote_sum, ) .unwrap(); - let share = bytes_to_point( - counter_parameters_storage.get_counter_parameters_request() - [index] + let counter_share = bytes_to_point( + counter_parameters.get_counter_parameters_share()[index] .get_poll_point_share(), ) .unwrap(); - assert_eq!( - true, - verifier::verify_count_request( - &system_parameters, - &encrypted_vote_sum, - &share, - &decrypt_request - ) - .unwrap() - ); - assert_eq!( - true, - coordinator::aggregate_decrypted_part_sum( - &system_parameters, - &decrypt_request, - &mut vote_sum_total - ) - .unwrap() - ); + assert!(verifier::verify_count_request( + &poll_parameters, + &encrypted_vote_sum, + &counter_share, + &partially_decrypted_result + ) + .unwrap()); + + // Coordinator aggregates parts of decrypted poll result. + assert!(coordinator::aggregate_decrypted_part_sum( + &poll_parameters, + &partially_decrypted_result, + &mut aggregated_decrypted_result + ) + .unwrap()); } - let final_result_request = coordinator::finalize_vote_result( - &system_parameters, + + // Coordinator decrypts the final poll result by enumerating all + // possible value and checking ZKP data. + // TODO: Design a better way to do the decryption. + // Each candidate should not receive more than 20k votes. + let max_vote_limit = 200; + let vote_result = coordinator::finalize_vote_result( + &poll_parameters, &encrypted_vote_sum, - &vote_sum_total, - max_vote_number, + &aggregated_decrypted_result, + max_vote_limit, ) .unwrap(); - wedpr_println!("final result is : {:?}", final_result_request); - let result = verifier::verify_vote_result( - &system_parameters, + assert!(verifier::verify_vote_result( + &poll_parameters, &encrypted_vote_sum, - &vote_sum_total, - &final_result_request, + &aggregated_decrypted_result, + &vote_result, ) - .unwrap(); - assert!(result); + .unwrap()); } } diff --git a/solution/anonymous_ciphertext_voting/src/main.rs b/solution/anonymous_ciphertext_voting/src/main.rs index c2af12b..f827207 100644 --- a/solution/anonymous_ciphertext_voting/src/main.rs +++ b/solution/anonymous_ciphertext_voting/src/main.rs @@ -6,21 +6,21 @@ use wedpr_l_crypto_zkp_utils::bytes_to_point; use wedpr_l_utils::traits::Signature; use wedpr_s_protos::generated::acv::{ - CandidateList, CounterSecret, CounterSystemParametersStorage, - DecryptedResultPartStorage, VoteChoice, VoteChoices, VoteStorage, - VoterSecret, + CandidateList, CounterParametersStorage, CounterSecret, + DecryptedResultPartStorage, VoteStorage, VoterSecret, }; extern crate wedpr_s_anonymous_ciphertext_voting; use colored::Colorize; use wedpr_s_anonymous_ciphertext_voting::{ - config::SIGNATURE_SECP256K1, coordinator, counter, verifier, voter, + config::{POLL_RESULT_KEY_TOTAL_BALLOTS, SIGNATURE}, + coordinator, counter, verifier, voter, }; fn main() { print_highlight2( "#\n# Welcome to anonymous ciphertext voting (ACV) demo!", - "# 欢迎来到匿名密文投票demo演示!\n#", + "# 欢迎来到多方密文决策demo演示!\n#", ); println!(); print_alert2( @@ -54,8 +54,8 @@ fn main() { fn flow_cn() { print_wide( - "投票demo流程中,你将体验隐匿密文投票的全过程,具体包括:\n - 1. 投票者如何使用密文选票进行匿名投票;\n + "投票demo流程中,您将体验多方密文决策的全过程,具体包括:\n + 1. 投票者如何使用密文选票进行隐匿投票;\n 2. 计票者如何联合解密得到计票结果;\n 3. 任意验证者如何借助零知识证明来验证整个过程中投票者与计票者行为的正确性。", ); @@ -71,10 +71,10 @@ fn flow_cn() { println!( "{}\n{}\n{}\n{}\n{}\n{}\n", "【流程介绍】".yellow(), - "1. 投票者获得初始选票;", - "2. 投票者决定为各候选人分别投出多少数额,\ - 生成并公布对应的密文选票和零知识证明;", - "3. 任意验证者验证投票者公布的密文选票是否正确有效;", + "1. 投票者申请密文空白选票;", + "2. 投票者决定为各候选人分别投出多少票数,\ + 生成并投出对应的密文选票和零知识证明;", + "3. 任意验证者验证投票者投出的密文选票是否正确有效;", "4. 计票者联合计算每个候选人的得票,公布统计结果和零知识证明;", "5. 任意验证者验证计票者的计票过程及计票结果是否正确有效。" ); @@ -83,114 +83,102 @@ fn flow_cn() { println!( "{} {} {}\n", "【演示进度】", - "<<生成并公布初始密文选票>>".yellow(), - "↦ 生成并公布对各候选人的密文选票 ↦ 验证密文选票 ↦ \ - 联合计票并公布计票信息↦ 验证计票过程 ↦ 公布计票结果 ↦ 验证计票结果", + "<<申请密文空白选票>>".yellow(), + "↦ 投出对各候选人的密文选票 ↦ 验证密文选票 ↦ 联合计票并公布计票信息↦ \ + 验证计票过程 ↦ 公布计票结果 ↦ 验证计票结果", ); print_alert( - "现在请输入初始选票的数额:▼▼(初始选票的数额表示:\ - 该投票者可以投出的密文选票总额上限)", + "现在请输入当前投票者的密文空白选票的权重:\ + ▼▼(密文空白选票的权重表示:该投票者可以投出的密文选票最大总票数)", ); print_highlight( - "在这个demo中,我们暂定初始选票数额上限为100(真实业务可按需扩展),\ + "这里,我们暂定密文空白选票权重上限为100(真实业务可按需扩展),\ 请输入0到100之间的整数", ); - let value1 = wait_for_number_cn(); + let last_voter_weight = wait_for_number_cn(); + let mut voter_weight_list = vec![100, 100, 100]; + voter_weight_list.push(last_voter_weight as u32); + let last_voter_id = voter_weight_list.len() - 1; - let max_vote_number = 20000; - let (public_key, secret_key) = SIGNATURE_SECP256K1.generate_keypair(); - let mut candidate_list = CandidateList::new(); - // Init candidate list - for candidate in vec!["候选人1", "候选人2", "候选人3"] { - candidate_list.mut_candidate().push(candidate.to_string()); - } + // Initialize a group of counters. let counter_id_list = vec!["1001", "1002", "1003"]; - let mut blank_ballot_count = vec![100, 100, 100]; - blank_ballot_count.push(value1 as u32); - let mut counter_secret_list: Vec = vec![]; - let mut counter_parameters_storage = - CounterSystemParametersStorage::default(); - // Counter init + let mut counter_parameters = CounterParametersStorage::default(); for id in counter_id_list.clone() { - let share_secret = counter::make_counter_secret(); - counter_secret_list.push(share_secret.clone()); - let counter_parameters_request = - counter::make_system_parameters_share(id, &share_secret).unwrap(); - counter_parameters_storage - .mut_counter_parameters_request() - .push(counter_parameters_request.clone()); + let counter_secret = counter::make_counter_secret(); + let counter_parameters_share = + counter::make_parameters_share(id, &counter_secret).unwrap(); + counter_parameters + .mut_counter_parameters_share() + .push(counter_parameters_share); + counter_secret_list.push(counter_secret); } - // coordinator make system parameters - let system_parameters = coordinator::make_system_parameters( - &candidate_list, - &counter_parameters_storage, - ) - .unwrap(); - // voter init - let mut voter_secret_list: Vec = vec![]; - let mut response_list = vec![]; + // Initialize the coordinator. + let (public_key, secret_key) = SIGNATURE.generate_keypair(); - for blank_ballot in blank_ballot_count { - let vote_secret = voter::make_voter_secret(); - voter_secret_list.push(vote_secret.clone()); + // Coordinator initializes a new poll. + let mut candidate_list = CandidateList::new(); + for candidate in ["张三", "李四", "王五"] { + candidate_list.mut_candidate().push(candidate.to_string()); + } + let poll_parameters = + coordinator::make_poll_parameters(&candidate_list, &counter_parameters) + .unwrap(); - // voter -> coordinator generate blank ballot - let vote_request = - voter::make_registration_request(&vote_secret, &system_parameters) + // Initialize all voters. + let mut voter_secret_list: Vec = vec![]; + let mut voter_registration_list = vec![]; + // Voter weight is the max voting power of each voter assigned by + // coordinator. + for blank_ballot in voter_weight_list { + let vote_secret = voter::make_voter_secret(); + // Register a voter with coordinator. + let registration_request = + voter::make_registration_request(&vote_secret, &poll_parameters) .unwrap(); - let response = coordinator::certify_voter( + let registration_response = coordinator::certify_voter( &secret_key, + ®istration_request, blank_ballot, - &vote_request, ) .unwrap(); - response_list.push(response.clone()); - // verify blank ballot - let result = - voter::verify_blank_ballot(&vote_request, &response).unwrap(); - assert_eq!(true, result); + // Verify the blank ballot contained in registration_response. + assert!(voter::verify_blank_ballot( + ®istration_request, + ®istration_response + ) + .unwrap()); + voter_registration_list.push(registration_response); + voter_secret_list.push(vote_secret); } println!( - "您的初始密文选票为:\n{:?}\n", - response_list[3].get_ballot() - ); - print_alert( - "可以看到,投票者公布的初始密文选票中不包含投票者的身份及其初始数额。", + "您的密文空白选票为:\n{:?}\n", + voter_registration_list[last_voter_id].get_ballot() ); + print_alert("注:投票者申请的密文空白选票中不包含投票者的身份及其权重。"); pause_cn(); println!( "{} {} {} \n", - "【演示进度】生成并公布初始密文选票 ↦", - "<<生成并公布对各候选人的密文选票>>".yellow(), + "【演示进度】 申请密文空白选票 ↦", + "<<投出对各候选人的密文选票>>".yellow(), "↦ 验证密文选票 ↦ 联合计票并公布计票信息↦ 验证计票过程 ↦ 公布计票结果 \ ↦ 验证计票结果", ); - print_alert("现在请输入您对候选人1的投票数额:▼▼"); - let value2 = wait_for_number_cn(); - print_alert("现在请输入您对候选人2的投票数额:▼▼"); - let value3 = wait_for_number_cn(); - print_alert("现在请输入您对候选人3的投票数额:▼▼"); + print_alert("现在请输入您对 张三 投票的票数:▼▼"); + let candidate1_votes = wait_for_number_cn(); + print_alert("现在请输入您对 李四 投票的票数:▼▼"); + let candidate2_votes = wait_for_number_cn(); + print_alert("现在请输入您对 王五 投票的票数:▼▼"); print_highlight( - "(注:当投出的总数额大于初始选票数值时,会导致投票失败)。", - ); - let value4 = wait_for_number_cn(); - - // Voter votes. - let make_choice = |x: &Vec| { - let mut choices = VoteChoices::new(); - for i in 0..candidate_list.get_candidate().len() { - let mut pair = VoteChoice::new(); - pair.set_candidate(candidate_list.get_candidate()[i].clone()); - pair.set_value(x[i]); - choices.mut_choice().push(pair); - } - choices - }; + "注:当投出的总票数大于密文空白选票权重时,会导致投票失败。", + ); + let candidate3_votes = wait_for_number_cn(); + + // All voters vote. let candidate1_default = 10; let candidate2_default = 20; let candidate3_default = 30; @@ -198,22 +186,39 @@ fn flow_cn() { vec![candidate1_default, candidate2_default, candidate3_default], vec![candidate1_default, candidate2_default, candidate3_default], vec![candidate1_default, candidate2_default, candidate3_default], - vec![value2, value3, value4], + vec![candidate1_votes, candidate2_votes, candidate3_votes], ]; let mut vote_request_list = vec![]; let mut encrypted_vote_sum = VoteStorage::new(); for index in 0..voting_ballot_count.len() { - let ballot_choice = make_choice(&voting_ballot_count[index]); - let vote_request = voter::vote( + let vote_choices = voter::make_vote_choices( + &voting_ballot_count[index], + &candidate_list, + ); + let vote_request = match voter::vote( &voter_secret_list[index], - &ballot_choice, - &response_list[index], - &system_parameters, - ) - .unwrap(); + &vote_choices, + &voter_registration_list[index], + &poll_parameters, + ) { + Ok(v) => v, + Err(_) => { + println!( + "\n投票失败:您投出的总票数超出您的权重限制:{} + {} + {} \ + > {}\n", + candidate2_votes, + candidate2_votes, + candidate3_votes, + last_voter_weight + ); + return; + }, + }; + + // Coordinator aggregates individual ciphertext ballots. coordinator::aggregate_vote_sum_response( - &system_parameters, + &poll_parameters, &vote_request.get_vote(), &mut encrypted_vote_sum, ) @@ -221,205 +226,221 @@ fn flow_cn() { vote_request_list.push(vote_request); } println!( - "\n您公布的密文选票为:\n{:?}\n", - vote_request_list[3].get_vote() + "\n您投出的密文选票为:\n{:?}\n", + vote_request_list[last_voter_id].get_vote() ); print_alert( - "可以看到:投票者公布的密文选票中不包含投票者身份、候选人身份、\ - 投票数额等信息。", + "注:投票者投出的密文选票中不包含投票者身份、候选人获得票数等信息。", ); println!("假定其他投票者对三位候选人的投票均为[10,20,30]。"); pause_cn(); println!( "{} {} {} \n", - "【演示进度】 生成并公布初始密文选票 ↦ 生成并公布对各候选人的密文选票 \ - ↦", - "验证密文选票".yellow(), + "【演示进度】 申请密文空白选票 ↦ 投出对各候选人的密文选票 ↦", + "<<验证密文选票>>".yellow(), "↦ 联合计票并公布计票信息↦ 验证计票过程 ↦ 公布计票结果 ↦ 验证计票结果", ); println!( - "验证内容包括:\n1. 投给每个候选人的密文选票数额非负;\n2. \ + "验证内容包括:\n1. 投给每个候选人的密文选票票数非负;\n2. \ 每个密文选票格式正确(否则会导致后续计票失败);\n3. \ - 投票者投出的密文选票数额之和小于等于其初始选票数额。" + 投票者投出的密文选票票数之和小于等于其密文空白选票权重。" ); - - print_alert("\n只有通过验证的密文选票,才会进入后续计票流程。"); + print_alert("\n注:只有通过验证的密文选票,才会进入后续计票流程。"); pause_cn(); - // Verifier verifies voters. - let length = vote_request_list.len().clone(); - for index in 0..length { - let verify_voter = verifier::verify_vote_request( - &system_parameters, - &vote_request_list[index], - &public_key, - ) - .unwrap(); - println!("\n对投票者{}的验证结果为:{:?}", index, verify_voter); + // Verifier verifies all ciphertext ballots. + for index in 0..vote_request_list.len() { + println!( + "对投票者{}的验证结果为:{}", + index, + if verifier::verify_vote_request( + &poll_parameters, + &vote_request_list[index], + &public_key, + ) + .unwrap() + { + "✓" + } else { + "✗" + } + ); } pause_cn(); println!( "{} {} {} \n", - "【演示进度】 生成并公布初始密文选票 ↦ 生成并公布对各候选人的密文选票 \ - ↦ 验证密文选票 ↦", - "联合计票并公布计票信息".yellow(), + "【演示进度】 申请密文空白选票 ↦ 投出对各候选人的密文选票 ↦ \ + 验证密文选票 ↦", + "<<联合计票并公布计票信息>>".yellow(), "↦ 验证计票过程 ↦ 公布计票结果 ↦ 验证计票结果", ); - // Counters count. - let mut vote_sum_total = DecryptedResultPartStorage::new(); - let mut decrypt_request_list = vec![]; - let mut share_list = vec![]; - let length = counter_secret_list.len().clone(); - for index in 0..length { - let decrypt_request = counter::count( + // All counters decrypt the poll result in a distributed manner. + let mut aggregated_decrypted_result = DecryptedResultPartStorage::new(); + let mut partially_decrypted_result_list = vec![]; + let mut counter_share_list = vec![]; + for index in 0..counter_secret_list.len() { + let partially_decrypted_result = counter::count( &counter_id_list[index], &counter_secret_list[index], &encrypted_vote_sum, ) .unwrap(); - let share = bytes_to_point( - counter_parameters_storage.get_counter_parameters_request()[index] + let counter_share = bytes_to_point( + counter_parameters.get_counter_parameters_share()[index] .get_poll_point_share(), ) .unwrap(); + + // Coordinator aggregates parts of decrypted poll result. assert_eq!( true, coordinator::aggregate_decrypted_part_sum( - &system_parameters, - &decrypt_request, - &mut vote_sum_total + &poll_parameters, + &partially_decrypted_result, + &mut aggregated_decrypted_result ) .unwrap() ); - decrypt_request_list.push(decrypt_request); - share_list.push(share); + partially_decrypted_result_list.push(partially_decrypted_result); + counter_share_list.push(counter_share); } - println!("所有计票者联合计票的计票信息为:\n{:?}", vote_sum_total); + println!( + "所有计票者联合计票的聚合计票信息为:\n{:?}", + aggregated_decrypted_result + ); print_alert( - "可以看到:计票者公布的计票信息中不包含计票者身份等计票者隐私信息。", + "注:计票者公布的聚合计票信息中无法反推出个人投票数等隐私信息。", ); pause_cn(); println!( "{} {} {} \n", - "【演示进度】 生成并公布初始密文选票 ↦ 生成并公布对各候选人的密文选票 \ - ↦ 验证密文选票 ↦ 联合计票并公布计票信息 ↦", - "验证计票过程".yellow(), + "【演示进度】 申请密文空白选票 ↦ 投出对各候选人的密文选票 ↦ \ + 验证密文选票 ↦ 联合计票并公布计票信息 ↦", + "<<验证计票过程>>".yellow(), "↦ 公布计票结果 ↦ 验证计票结果", ); println!( - "验证计票过程,是指:\n + "验证内容包括:\n1. \ 验证计票者公布的计票信息是使用正确的计票者密钥计算而得,\ - 而不是随意构造而得。" + 而不是随意构造而得。\n" ); - let length = counter_secret_list.len().clone(); - for index in 0..length { - let verify_counter = verifier::verify_count_request( - &system_parameters, - &encrypted_vote_sum, - &share_list[index], - &decrypt_request_list[index], - ) - .unwrap(); - println!("\n对计票者{}的验证结果为:{:?}", index, verify_counter); + for index in 0..counter_secret_list.len() { + println!( + "对计票者{}的验证结果为:{}", + index, + if verifier::verify_count_request( + &poll_parameters, + &encrypted_vote_sum, + &counter_share_list[index], + &partially_decrypted_result_list[index], + ) + .unwrap() + { + "✓" + } else { + "✗" + } + ); } pause_cn(); println!( "{} {} {} \n", - "【演示进度】 生成并公布初始密文选票 ↦ 生成并公布对各候选人的密文选票 \ - ↦ 验证密文选票 ↦ 联合计票并公布计票信息 ↦ 验证计票过程 ↦", - "公布计票结果".yellow(), + "【演示进度】 申请密文空白选票 ↦ 投出对各候选人的密文选票 ↦ \ + 验证密文选票 ↦ 联合计票并公布计票信息 ↦ 验证计票过程 ↦", + "<<公布计票结果>>".yellow(), "↦ 验证计票结果", ); - let final_result_request = coordinator::finalize_vote_result( - &system_parameters, + let max_vote_limit = 20000; + let vote_result = coordinator::finalize_vote_result( + &poll_parameters, &encrypted_vote_sum, - &vote_sum_total, - max_vote_number, + &aggregated_decrypted_result, + max_vote_limit, ) .unwrap(); + for result in vote_result.get_result() { + if result.get_key() == POLL_RESULT_KEY_TOTAL_BALLOTS { + continue; + } + println!("{} 最终得票为 {}", result.get_key(), result.get_value()); + } + // TODO: Refactor to use a more elegant way for the following code. + print_alert("\n对比传统明文计票结果:"); + let plaintext_result1 = (candidate1_default + + candidate1_default + + candidate1_default + + candidate1_votes) as i64; + let plaintext_result2 = (candidate2_default + + candidate2_default + + candidate2_default + + candidate2_votes) as i64; + let plaintext_result3 = (candidate3_default + + candidate3_default + + candidate3_default + + candidate3_votes) as i64; println!( - "{}: 最终得票为{}。", - final_result_request.get_result()[1].get_key(), - final_result_request.get_result()[1].get_value() - ); - println!( - "{}: 最终得票为{}。", - final_result_request.get_result()[2].get_key(), - final_result_request.get_result()[2].get_value() - ); - println!( - "{}: 最终得票为{}。", - final_result_request.get_result()[3].get_key(), - final_result_request.get_result()[3].get_value() - ); - - print_alert("\n对比明文统计结果:"); - let plaintext_result1 = - (candidate1_default + candidate1_default + candidate1_default + value2).into(); - let plaintext_result2 = - (candidate2_default + candidate2_default + candidate2_default + value3).into(); - let plaintext_result3 = - (candidate3_default + candidate3_default + candidate3_default + value4).into(); - println!( - "候选人1得票:{} + {} + {} + {} = {}", + "张三得票:{} + {} + {} + {} = {}", candidate1_default, candidate1_default, candidate1_default, - value2, + candidate1_votes, plaintext_result1 ); println!( - "候选人2得票:{} + {} + {} + {} = {}", + "李四得票:{} + {} + {} + {} = {}", candidate2_default, candidate2_default, candidate2_default, - value3, + candidate2_votes, plaintext_result2 ); println!( - "候选人3得票:{} + {} + {} + {} = {}", + "王五得票:{} + {} + {} + {} = {}", candidate3_default, candidate3_default, candidate3_default, - value4, + candidate3_votes, plaintext_result3 ); - if final_result_request.get_result()[1].get_value() == plaintext_result1 - && final_result_request.get_result()[2].get_value() == plaintext_result2 - && final_result_request.get_result()[3].get_value() == plaintext_result3 - { - print_alert("\n可以看到,密文选票的计票结果与明文计算结果一致。"); - } - + assert!( + vote_result.get_result()[1].get_value() == plaintext_result1 + && vote_result.get_result()[2].get_value() == plaintext_result2 + && vote_result.get_result()[3].get_value() == plaintext_result3 + ); + print_alert("\n注:密文选票的计票结果与传统明文计票结果一致。"); pause_cn(); println!( "{} {} \n", - "【演示进度】 生成并公布初始密文选票 ↦ 生成并公布对各候选人的密文选票 \ - ↦ 验证密文选票 ↦ 联合计票并公布计票信息 ↦ 验证计票过程 ↦ \ - 公布计票结果 ↦", - "验证计票结果".yellow(), + "【演示进度】 申请密文空白选票 ↦ 投出对各候选人的密文选票 ↦ \ + 验证密文选票 ↦ 联合计票并公布计票信息 ↦ 验证计票过程 ↦ 公布计票结果 ↦", + "<<验证计票结果>>".yellow(), + ); + println!( + "\n最终计票结果的有效性:{}", + if verifier::verify_vote_result( + &poll_parameters, + &encrypted_vote_sum, + &aggregated_decrypted_result, + &vote_result, + ) + .unwrap() + { + "✓" + } else { + "✗" + } ); - - let verify_result = verifier::verify_vote_result( - &system_parameters, - &encrypted_vote_sum, - &vote_sum_total, - &final_result_request, - ) - .unwrap(); - - println!("\n验证结果为:{:?}", verify_result); pause_cn(); print_alert("十分感谢您的试用!"); @@ -433,10 +454,426 @@ fn flow_cn() { } fn flow_en() { - // TODO: en flow + print_wide( + "In this demo, you will experience how to use anonymous ciphertext \ + voting, including: \n + 1. A certified voter generates ciphertext ballots to protect real \ + opinion. \n + 2. A group of counters jointly decrypt and count the voting results. \n + 3. A public verifier verifies the validity of the whole voting process \ + via advance zero-knowledge proof (ZKP).", + ); + print_wide( + "We use the following application scenario for easy demonstration of \ + this new capability.", + ); + + println!( + "{}\n{}\n", + "[Background]".yellow(), + "4 voters vote for 3 candidates, where each voter can vote for \ + multiple candidates as long as the total number of voted ballots are \ + no more than its preassigned weight.", + ); + println!( + "{}\n{}\n{}\n{}\n{}\n{}\n", + "[Story]".yellow(), + "1. A voter apply for certified blank ciphertext ballots.", + "2. A voter votes for chosen candidates and generates ZKP proofs.", + "3. A public verifier verifies the validity of voting via ZKP.", + "4. A group of counters jointly decrypt and count the voting results \ + and generates ZKP proofs.", + "5. A public verifier verifies the validity of counting via ZKP." + ); + pause_en(); + + println!( + "{} {} {}\n", + "[Demo progress]", + "<>".yellow(), + "↦ Vote ↦ Verify voting ↦ Count jointly ↦ Verify counting ↦ Publish \ + result ↦ Verify result", + ); + + print_alert( + "Please enter your voter weight: ▼▼ The voter weight specifies the \ + max votes you can vote.", + ); + print_highlight( + "In this demo, we use 100 as the weight limit, which could be \ + extended for a higher limit in real applications. Please enter a \ + integer number between 0 and 100.", + ); + let last_voter_weight = wait_for_number_en(); + let mut voter_weight_list = vec![100, 100, 100]; + voter_weight_list.push(last_voter_weight as u32); + let last_voter_id = voter_weight_list.len() - 1; + + // Initialize a group of counters. + let counter_id_list = vec!["1001", "1002", "1003"]; + let mut counter_secret_list: Vec = vec![]; + let mut counter_parameters = CounterParametersStorage::default(); + for id in counter_id_list.clone() { + let counter_secret = counter::make_counter_secret(); + let counter_parameters_share = + counter::make_parameters_share(id, &counter_secret).unwrap(); + counter_parameters + .mut_counter_parameters_share() + .push(counter_parameters_share); + counter_secret_list.push(counter_secret); + } + + // Initialize the coordinator. + let (public_key, secret_key) = SIGNATURE.generate_keypair(); + + // Coordinator initializes a new poll. + let mut candidate_list = CandidateList::new(); + for candidate in ["Kitten", "Doge", "Bunny"] { + candidate_list.mut_candidate().push(candidate.to_string()); + } + let poll_parameters = + coordinator::make_poll_parameters(&candidate_list, &counter_parameters) + .unwrap(); + + // Initialize all voters. + let mut voter_secret_list: Vec = vec![]; + let mut voter_registration_list = vec![]; + // Voter weight is the max voting power of each voter assigned by + // coordinator. + for blank_ballot in voter_weight_list { + let vote_secret = voter::make_voter_secret(); + // Register a voter with coordinator. + let registration_request = + voter::make_registration_request(&vote_secret, &poll_parameters) + .unwrap(); + let registration_response = coordinator::certify_voter( + &secret_key, + ®istration_request, + blank_ballot, + ) + .unwrap(); + // Verify the blank ballot contained in registration_response. + assert!(voter::verify_blank_ballot( + ®istration_request, + ®istration_response + ) + .unwrap()); + voter_registration_list.push(registration_response); + voter_secret_list.push(vote_secret); + } + println!( + "You will receive the following certified blank ballots: \n{:?}\n", + voter_registration_list[last_voter_id].get_ballot() + ); + print_alert( + "Notice: No voter id or weight in certified blank ciphertext ballots.", + ); + pause_en(); + + println!( + "{} {} {} \n", + "[Demo progress] Apply for certified blank ballots ↦", + "<>".yellow(), + "↦ Verify voting ↦ Count jointly ↦ Verify counting ↦ Publish result ↦ \ + Verify result", + ); + + print_alert("Please enter your votes for Kitten ▼▼"); + let candidate1_votes = wait_for_number_en(); + print_alert("Please enter your votes for Doge ▼▼"); + let candidate2_votes = wait_for_number_en(); + print_alert("Please enter your votes for Bunny ▼▼"); + print_highlight( + "Notice: Your total votes cannot exceed your voter weight.", + ); + let candidate3_votes = wait_for_number_en(); + + // All voters vote. + let candidate1_default = 10; + let candidate2_default = 20; + let candidate3_default = 30; + let voting_ballot_count: Vec> = vec![ + vec![candidate1_default, candidate2_default, candidate3_default], + vec![candidate1_default, candidate2_default, candidate3_default], + vec![candidate1_default, candidate2_default, candidate3_default], + vec![candidate1_votes, candidate2_votes, candidate3_votes], + ]; + + let mut vote_request_list = vec![]; + let mut encrypted_vote_sum = VoteStorage::new(); + for index in 0..voting_ballot_count.len() { + let vote_choices = voter::make_vote_choices( + &voting_ballot_count[index], + &candidate_list, + ); + let vote_request = match voter::vote( + &voter_secret_list[index], + &vote_choices, + &voter_registration_list[index], + &poll_parameters, + ) { + Ok(v) => v, + Err(_) => { + println!( + "\nVote Failed: Your total votes has exceeded your voter \ + weight: {} + {} + {} > {}\n", + candidate2_votes, + candidate2_votes, + candidate3_votes, + last_voter_weight + ); + return; + }, + }; + + // Coordinator aggregates individual ciphertext ballots. + coordinator::aggregate_vote_sum_response( + &poll_parameters, + &vote_request.get_vote(), + &mut encrypted_vote_sum, + ) + .unwrap(); + vote_request_list.push(vote_request); + } + println!( + "\nYour voted ciphertext ballots are: \n{:?}\n", + vote_request_list[last_voter_id].get_vote() + ); + print_alert( + "Notice: No voter id or candidate votes in ciphertext ballots.", + ); + println!( + "For simplicity, we assume the other three voters voted [10, 20, 30] \ + for our candidates." + ); + pause_en(); + + println!( + "{} {} {} \n", + "[Demo progress] Apply for certified blank ballots ↦ Vote ↦", + "<>".yellow(), + "↦ Count jointly ↦ Verify counting ↦ Publish result ↦ Verify result", + ); + + println!( + "Now verifying: \n1. All votes in ciphertext ballots is not negative \ + numbers.\n2. All ciphertext ballots are in a valid format.\n3. The \ + vote sum in ciphertext ballots from the same voter is no larger than \ + its weight." + ); + print_alert( + "\nNotice: Only verified ciphertext ballots will be later counted.", + ); + pause_en(); + + // Verifier verifies all ciphertext ballots. + for index in 0..vote_request_list.len() { + println!( + "Voter {}'s voted ciphertext ballots: {}", + index, + if verifier::verify_vote_request( + &poll_parameters, + &vote_request_list[index], + &public_key, + ) + .unwrap() + { + "✓" + } else { + "✗" + } + ); + } + pause_en(); + + println!( + "{} {} {} \n", + "[Demo progress] Apply for certified blank ballots ↦ Vote ↦ Verify \ + voting ↦", + "<>".yellow(), + "↦ Verify counting ↦ Publish result ↦ Verify result", + ); + + // All counters decrypt the poll result in a distributed manner. + let mut aggregated_decrypted_result = DecryptedResultPartStorage::new(); + let mut partially_decrypted_result_list = vec![]; + let mut counter_share_list = vec![]; + for index in 0..counter_secret_list.len() { + let partially_decrypted_result = counter::count( + &counter_id_list[index], + &counter_secret_list[index], + &encrypted_vote_sum, + ) + .unwrap(); + let counter_share = bytes_to_point( + counter_parameters.get_counter_parameters_share()[index] + .get_poll_point_share(), + ) + .unwrap(); + + // Coordinator aggregates parts of decrypted poll result. + assert_eq!( + true, + coordinator::aggregate_decrypted_part_sum( + &poll_parameters, + &partially_decrypted_result, + &mut aggregated_decrypted_result + ) + .unwrap() + ); + partially_decrypted_result_list.push(partially_decrypted_result); + counter_share_list.push(counter_share); + } + println!( + "Aggregated decrypted voting result is: \n{:?}", + aggregated_decrypted_result + ); + print_alert( + "Notice: Individual votes cannot be recovered from aggregated \ + decrypted voting result.", + ); + pause_en(); + + println!( + "{} {} {} \n", + "[Demo progress] Apply for certified blank ballots ↦ Vote ↦ Verify \ + voting ↦ Count jointly ↦", + "<>".yellow(), + "↦ Publish result ↦ Verify result", + ); + + println!( + "Now verifying:\n1. All counters use the correct secret share to \ + count partially decrypted voting result.\n" + ); + for index in 0..counter_secret_list.len() { + println!( + "Counter {}'s partially decrypted voting result: {}", + index, + if verifier::verify_count_request( + &poll_parameters, + &encrypted_vote_sum, + &counter_share_list[index], + &partially_decrypted_result_list[index], + ) + .unwrap() + { + "✓" + } else { + "✗" + } + ); + } + + pause_en(); + + println!( + "{} {} {} \n", + "[Demo progress] Apply for certified blank ballots ↦ Vote ↦ Verify \ + voting ↦ Count jointly ↦ Verify counting ↦", + "<>".yellow(), + "↦ Verify result", + ); + + let max_vote_limit = 20000; + let vote_result = coordinator::finalize_vote_result( + &poll_parameters, + &encrypted_vote_sum, + &aggregated_decrypted_result, + max_vote_limit, + ) + .unwrap(); + for result in vote_result.get_result() { + if result.get_key() == POLL_RESULT_KEY_TOTAL_BALLOTS { + continue; + } + println!("{}: total votes = {}", result.get_key(), result.get_value()); + } + + // TODO: Refactor to use a more elegant way for the following code. + print_alert("\nCompare with traditional plaintext counting:"); + let plaintext_result1 = (candidate1_default + + candidate1_default + + candidate1_default + + candidate1_votes) as i64; + let plaintext_result2 = (candidate2_default + + candidate2_default + + candidate2_default + + candidate2_votes) as i64; + let plaintext_result3 = (candidate3_default + + candidate3_default + + candidate3_default + + candidate3_votes) as i64; + println!( + "Kitten: {} + {} + {} + {} = {}", + candidate1_default, + candidate1_default, + candidate1_default, + candidate1_votes, + plaintext_result1 + ); + println!( + "Doge: {} + {} + {} + {} = {}", + candidate2_default, + candidate2_default, + candidate2_default, + candidate2_votes, + plaintext_result2 + ); + println!( + "Bunny: {} + {} + {} + {} = {}", + candidate3_default, + candidate3_default, + candidate3_default, + candidate3_votes, + plaintext_result3 + ); + assert!( + vote_result.get_result()[1].get_value() == plaintext_result1 + && vote_result.get_result()[2].get_value() == plaintext_result2 + && vote_result.get_result()[3].get_value() == plaintext_result3 + ); + print_alert( + "\nNotice: ciphertext ballot counting yield the same result as \ + traditional plaintext counting.", + ); + pause_en(); + + println!( + "{} {} \n", + "[Demo progress] Apply for certified blank ballots ↦ Vote ↦ Verify \ + voting ↦ Count jointly ↦ Verify counting ↦ Publish result ↦", + "<>".yellow(), + ); + println!( + "\nFinal voting result's validity: {}", + if verifier::verify_vote_result( + &poll_parameters, + &encrypted_vote_sum, + &aggregated_decrypted_result, + &vote_result, + ) + .unwrap() + { + "✓" + } else { + "✗" + } + ); + pause_en(); + + print_alert("Thank you for your time!"); + println!( + "\n{}\n\n{}\n", + "Welcome to contact us for more information about WeDPR by the \ + following Email:", + "wedpr@webank.com" + ); + println!(); } // Utility functions +// TODO: Extract those common functions to solution utility. fn print_highlight(message: &str) { println!("{}", message.green()); } @@ -465,7 +902,7 @@ fn wait_for_input() -> String { input.trim().to_string() } -// In this demo, we set the upper limit of input value to 10000. +// In this demo, we set the upper limit of input value to 100. const MAX_INPUT_VALUE: i32 = 100; fn wait_for_number(error_message: &str) -> u32 { diff --git a/solution/anonymous_ciphertext_voting/src/utils.rs b/solution/anonymous_ciphertext_voting/src/utils.rs new file mode 100644 index 0000000..3b2f39a --- /dev/null +++ b/solution/anonymous_ciphertext_voting/src/utils.rs @@ -0,0 +1,73 @@ +// Copyright 2020 WeDPR Lab Project Authors. Licensed under Apache-2.0. + +//! Library of ACV utility functions. + +use curve25519_dalek::{ristretto::RistrettoPoint, scalar::Scalar}; +use wedpr_l_utils::error::WedprError; +use wedpr_s_protos::generated::acv::{ + Ballot, CountingPart, DecryptedResultPartStorage, VoteResultStorage, + VoteStorage, +}; + +pub fn get_counting_part_by_candidate( + decrypted_result: &DecryptedResultPartStorage, + candidate: &str, +) -> Result { + for pair in decrypted_result.get_candidate_part() { + if pair.get_key() == candidate { + return Ok(pair.get_value().clone()); + } + } + Err(WedprError::ArgumentError) +} + +pub fn get_ballot_by_candidate( + vote_storage: &VoteStorage, + candidate: &str, +) -> Result { + for pair in vote_storage.get_voted_ballot() { + if pair.get_candidate() == candidate { + return Ok(pair.get_ballot().clone()); + } + } + Err(WedprError::ArgumentError) +} + +pub fn get_int64_by_candidate( + vote_result: &VoteResultStorage, + candidate: &str, +) -> Result { + for pair in vote_result.get_result() { + if pair.get_key() == candidate { + return Ok(pair.get_value()); + } + } + Err(WedprError::ArgumentError) +} + +pub fn align_commitment_list_if_needed(list: &mut Vec) { + let pending_length = compute_pending_size(list.len()); + for _ in 0..pending_length { + list.push(RistrettoPoint::default()); + } +} + +pub fn align_u64_list_if_needed(list: &mut Vec) { + let pending_length = compute_pending_size(list.len()); + for _ in 0..pending_length { + list.push(0u64); + } +} + +pub fn align_scalar_list_if_needed(list: &mut Vec) { + let pending_length = compute_pending_size(list.len()); + for _ in 0..pending_length { + list.push(Scalar::default()); + } +} + +fn compute_pending_size(length: usize) -> usize { + let log_length = (length as f64).log2().ceil() as u32; + let aligned_length = 2_i32.pow(log_length) as usize; + aligned_length - length +} diff --git a/solution/anonymous_ciphertext_voting/src/verifier.rs b/solution/anonymous_ciphertext_voting/src/verifier.rs index ea9554f..47b2417 100644 --- a/solution/anonymous_ciphertext_voting/src/verifier.rs +++ b/solution/anonymous_ciphertext_voting/src/verifier.rs @@ -1,6 +1,6 @@ // Copyright 2020 WeDPR Lab Project Authors. Licensed under Apache-2.0. -//! Library of anonymous ciphertext voting (ACV) solution. +//! Library for a poll verifier. use curve25519_dalek::{ristretto::RistrettoPoint, scalar::Scalar}; use wedpr_l_crypto_zkp_discrete_logarithm_proof::{ @@ -19,69 +19,64 @@ use wedpr_l_utils::{ }; use wedpr_s_protos::generated::acv::{ - Ballot, CountingPart, DecryptedResultPartStorage, SystemParametersStorage, - VoteRequest, VoteResultStorage, VoteStorage, + DecryptedResultPartStorage, PollParametersStorage, VoteRequest, + VoteResultStorage, VoteStorage, }; -use crate::config::{HASH_KECCAK256, SIGNATURE_SECP256K1}; +use crate::{ + config::{HASH, POLL_RESULT_KEY_TOTAL_BALLOTS, SIGNATURE}, + utils::{ + align_commitment_list_if_needed, get_ballot_by_candidate, + get_counting_part_by_candidate, get_int64_by_candidate, + }, +}; -/// Verifies a group of zero-knowledge proofs in the vote request from each -/// voter to confirm whether each ballot of voter is correct, specifically -/// refers to the format, the accounting balance and the numerical range of each -/// ciphertext ballot. +/// Verifies whether ciphertext ballots from a certified voter are valid. pub fn verify_vote_request( - param: &SystemParametersStorage, - request: &VoteRequest, + poll_parameters: &PollParametersStorage, + vote_request: &VoteRequest, public_key: &[u8], ) -> Result { - let poll_point = bytes_to_point(param.get_poll_point())?; - let signature = request.get_vote().get_signature(); - let blank_ballot = request.get_vote().get_blank_ballot(); + 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_KECCAK256.hash(&hash_vec); - - if !SIGNATURE_SECP256K1.verify( - &public_key, - &message_hash.as_ref(), - &signature, - ) { + let message_hash: Vec = HASH.hash(&hash_vec); + if !SIGNATURE.verify(&public_key, &message_hash.as_ref(), &signature) { return Err(WedprError::VerificationError); } - let range_proof = request.get_range_proof(); let mut commitments: Vec = Vec::new(); let mut voted_ballot_sum = RistrettoPoint::default(); - for candidate_ballot_pair in request.get_vote().get_voted_ballot() { + for candidate_ballot_pair in vote_request.get_vote().get_voted_ballot() { let ballot = candidate_ballot_pair.get_ballot(); commitments.push(bytes_to_point(&ballot.get_ciphertext1())?); voted_ballot_sum += bytes_to_point(&ballot.get_ciphertext1())?; } - let rest_ballot = request.get_vote().get_rest_ballot().get_ciphertext1(); - let rest_ballot_point = bytes_to_point(rest_ballot.clone())?; + let rest_ballot = + vote_request.get_vote().get_rest_ballot().get_ciphertext1(); + let rest_ballot_point = bytes_to_point(rest_ballot)?; commitments.push(rest_ballot_point); - pending_commitment_vec(&mut commitments); + 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); } - for candidate_ballot in request.get_ballot_proof() { + for candidate_ballot in vote_request.get_ballot_proof() { let candidate = candidate_ballot.get_key(); let ballot_proof = candidate_ballot.get_value(); - let mut candidate_ballot = Ballot::new(); - for candidate_ballot_pair in request.get_vote().get_voted_ballot() { - if candidate_ballot_pair.get_candidate() == candidate { - candidate_ballot = candidate_ballot_pair.get_ballot().clone(); - } - } + let candidate_ballot = + get_ballot_by_candidate(&vote_request.get_vote(), candidate)?; let ciphertext1 = bytes_to_point(&candidate_ballot.get_ciphertext1())?; let ciphertext2 = bytes_to_point(&candidate_ballot.get_ciphertext2())?; - let format_proof_bytes = ballot_proof.get_format_proof(); - let format_proof = bytes_to_proto::(format_proof_bytes)?; + let format_proof = + bytes_to_proto::(ballot_proof.get_format_proof())?; if !verify_format_proof( &ciphertext1, &ciphertext2, @@ -94,8 +89,9 @@ pub fn verify_vote_request( return Err(WedprError::VerificationError); } } - let balance_proof_bytes = request.get_sum_balance_proof(); - let balance_proof = bytes_to_proto::(balance_proof_bytes)?; + + let balance_proof = + bytes_to_proto::(vote_request.get_sum_balance_proof())?; if !verify_sum_relationship( &voted_ballot_sum, &bytes_to_point(&rest_ballot)?, @@ -110,22 +106,25 @@ pub fn verify_vote_request( Ok(true) } -/// Verifies zero-knowledge proof in the count request from each counter to -/// confirm whether the counting process is correct, specifically refers to that -/// whether each counter used correct secret key when counting. +/// Verifies whether a partially decrypted result from a counter is valid. pub fn verify_count_request( - param: &SystemParametersStorage, + poll_parameters: &PollParametersStorage, encrypted_vote_sum: &VoteStorage, counter_share: &RistrettoPoint, - request: &DecryptedResultPartStorage, + partially_decrypted_result: &DecryptedResultPartStorage, ) -> Result { + // Verify the total votes. let blank_c2_sum = bytes_to_point( &encrypted_vote_sum.get_blank_ballot().get_ciphertext2(), )?; - let blank_equality_proof_bytes = - request.get_blank_part().get_equality_proof(); - let blank_c2_r = - bytes_to_point(&request.get_blank_part().get_blinding_c2())?; + let blank_equality_proof_bytes = partially_decrypted_result + .get_blank_part() + .get_equality_proof(); + let blank_c2_r = bytes_to_point( + &partially_decrypted_result + .get_blank_part() + .get_blinding_c2(), + )?; let blank_equality_proof = bytes_to_proto::(&blank_equality_proof_bytes)?; if !verify_equality_relationship_proof( @@ -137,30 +136,25 @@ pub fn verify_count_request( )? { return Ok(false); } - for candidate in param.get_candidates().get_candidate() { - let mut candidate_ballot = Ballot::new(); - for pair in encrypted_vote_sum.get_voted_ballot() { - if candidate == pair.get_candidate() { - candidate_ballot = pair.get_ballot().clone(); - } - } + + // Verify the votes for each candidate. + for candidate in poll_parameters.get_candidates().get_candidate() { + let candidate_ballot = + get_ballot_by_candidate(encrypted_vote_sum, candidate)?; let candidate_c2_sum = bytes_to_point(&candidate_ballot.get_ciphertext2())?; - let mut counting_part = CountingPart::new(); - for pair in request.get_candidate_part() { - if candidate == pair.get_key() { - counting_part = pair.get_value().clone(); - } - } + let counting_part = get_counting_part_by_candidate( + partially_decrypted_result, + candidate, + )?; let candidate_c2_r = bytes_to_point(&counting_part.get_blinding_c2())?; - let candidate_equality_proof_bytes = counting_part.get_equality_proof(); - let candidate_equality_proof = - bytes_to_proto::(candidate_equality_proof_bytes)?; - + let candidate_equality_proof = bytes_to_proto::( + counting_part.get_equality_proof(), + )?; if !verify_equality_relationship_proof( &counter_share, &candidate_c2_r, - &candidate_equality_proof.clone(), + &candidate_equality_proof, &BASEPOINT_G2, &candidate_c2_sum, )? { @@ -171,62 +165,45 @@ pub fn verify_count_request( Ok(true) } -/// Verifies whether the final score of each candidate is correct. +/// Verifies whether the final vote result is valid. pub fn verify_vote_result( - param: &SystemParametersStorage, + poll_parameters: &PollParametersStorage, vote_sum: &VoteStorage, - counting_result_sum: &DecryptedResultPartStorage, - vote_result_request: &VoteResultStorage, + aggregated_decrypted_result: &DecryptedResultPartStorage, + vote_result: &VoteResultStorage, ) -> Result { let blank_c1_sum = bytes_to_point(&vote_sum.get_blank_ballot().get_ciphertext1())?; let blank_c2_r_sum = bytes_to_point( - &counting_result_sum.get_blank_part().get_blinding_c2(), + &aggregated_decrypted_result + .get_blank_part() + .get_blinding_c2(), )?; - let expected_blank_ballot_result = blank_c1_sum - (blank_c2_r_sum); - let mut get_blank_result: i64 = 0; - for tmp in vote_result_request.get_result() { - if tmp.get_key() == "Wedpr_voting_total_ballots" { - get_blank_result = tmp.get_value(); - } - } + let blank_result = + get_int64_by_candidate(vote_result, POLL_RESULT_KEY_TOTAL_BALLOTS)?; + let expected_blank_ballot_result = blank_c1_sum - (blank_c2_r_sum); if expected_blank_ballot_result - .ne(&(*BASEPOINT_G1 * (Scalar::from(get_blank_result as u64)))) + .ne(&(*BASEPOINT_G1 * (Scalar::from(blank_result as u64)))) { wedpr_println!("verify blank_ballot_result failed!"); return Ok(false); } - for candidate in param.get_candidates().get_candidate() { - let mut ballot = Ballot::new(); - for tmp_pair in vote_sum.get_voted_ballot() { - if candidate == tmp_pair.get_candidate() { - ballot = tmp_pair.get_ballot().clone(); - } - } - - let mut candidate_counting_part = CountingPart::new(); - for tmp_pair in counting_result_sum.get_candidate_part() { - if candidate == tmp_pair.get_key() { - candidate_counting_part = tmp_pair.get_value().clone(); - } - } - + for candidate in poll_parameters.get_candidates().get_candidate() { + let ballot = get_ballot_by_candidate(vote_sum, candidate)?; + let candidate_counting_part = get_counting_part_by_candidate( + aggregated_decrypted_result, + candidate, + )?; let candidate_c2_r_sum = bytes_to_point(&candidate_counting_part.get_blinding_c2())?; + let candidate_result = get_int64_by_candidate(vote_result, candidate)?; let expected_candidate_ballot_result = bytes_to_point(&ballot.get_ciphertext1())? - (candidate_c2_r_sum); - - let mut get_candidate_result: i64 = 0; - for tmp in vote_result_request.get_result() { - if tmp.get_key() == candidate { - get_candidate_result = tmp.get_value(); - } - } if !expected_candidate_ballot_result - .eq(&(*BASEPOINT_G1 * (Scalar::from(get_candidate_result as u64)))) + .eq(&(*BASEPOINT_G1 * (Scalar::from(candidate_result as u64)))) { wedpr_println!("verify candidate {} failed!", candidate); return Ok(false); @@ -234,17 +211,3 @@ pub fn verify_vote_result( } Ok(true) } - -fn pending_commitment_vec(v: &mut Vec) { - let length = v.len() as i32; - let log_length = (length as f64).log2().ceil() as u32; - let expected_len = 2_i32.pow(log_length); - if expected_len == length { - return; - } - let pending_length = expected_len - length; - let tmp = RistrettoPoint::default(); - for _ in 0..pending_length { - v.push(tmp); - } -} diff --git a/solution/anonymous_ciphertext_voting/src/voter.rs b/solution/anonymous_ciphertext_voting/src/voter.rs index c2e414d..17cb22d 100644 --- a/solution/anonymous_ciphertext_voting/src/voter.rs +++ b/solution/anonymous_ciphertext_voting/src/voter.rs @@ -1,7 +1,8 @@ // Copyright 2020 WeDPR Lab Project Authors. Licensed under Apache-2.0. -//! Library of anonymous ciphertext voting (ACV) solution. +//! Library for a poll voter. +use crate::utils::{align_scalar_list_if_needed, align_u64_list_if_needed}; use curve25519_dalek::{ ristretto::RistrettoPoint, scalar::Scalar, traits::MultiscalarMul, }; @@ -16,12 +17,12 @@ use wedpr_l_crypto_zkp_utils::{ use wedpr_l_protos::proto_to_bytes; use wedpr_l_utils::error::WedprError; use wedpr_s_protos::generated::acv::{ - Ballot, BallotProof, CandidateBallot, RegistrationRequest, - RegistrationResponse, StringToCandidateBallotProofPair, - SystemParametersStorage, VoteChoices, VoteRequest, VoterSecret, + Ballot, BallotProof, CandidateBallot, CandidateList, PollParametersStorage, + RegistrationRequest, RegistrationResponse, StringToBallotProofPair, + VoteChoice, VoteChoices, VoteRequest, VoterSecret, }; -/// Generates a random number as secret number for applying for blank ballot. +/// Makes secrets used by a voter. pub fn make_voter_secret() -> VoterSecret { let vote_secret = get_random_scalar(); VoterSecret { @@ -31,28 +32,25 @@ pub fn make_voter_secret() -> VoterSecret { } } -/// Applys to the coordinator for blank ballot using own secret number and -/// system parameters. +/// Makes a request for voter registration. pub fn make_registration_request( secret: &VoterSecret, - param: &SystemParametersStorage, + poll_parameters: &PollParametersStorage, ) -> 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(param.get_poll_point())?; + let poll_point = bytes_to_point(poll_parameters.get_poll_point())?; let blinding_poll_point = voter_secret * poll_point; let mut request = RegistrationRequest::new(); - request - .mut_weight_point() + let weight_point = request.mut_weight_point(); + weight_point .set_blinding_basepoint_g2(point_to_bytes(&blinding_basepoint_g2)); - request - .mut_weight_point() - .set_blinding_poll_point(point_to_bytes(&blinding_poll_point)); + weight_point.set_blinding_poll_point(point_to_bytes(&blinding_poll_point)); Ok(request) } -/// Verifies blank ballot issued by coordinator -/// by recalculating and comparing whether it is consistent. +/// Verifies whether the blank ballot contained in a registration response is +/// valid. pub fn verify_blank_ballot( request: &RegistrationRequest, response: &RegistrationResponse, @@ -63,52 +61,69 @@ pub fn verify_blank_ballot( let computed_ciphertext1 = point_to_bytes( &(blinding_poll_point + *BASEPOINT_G1 * Scalar::from(voter_weight)), ); - let response_ciphertext1 = response.get_ballot().get_ciphertext1(); let request_ciphertext2 = request.get_weight_point().get_blinding_basepoint_g2(); let response_ciphertext2 = response.get_ballot().get_ciphertext2(); - Ok(&computed_ciphertext1 == response_ciphertext1 - && request_ciphertext2 == response_ciphertext2) + Ok(response_ciphertext1 == computed_ciphertext1 + && response_ciphertext2 == request_ciphertext2) +} + +/// Makes choices for all candidates. +pub fn make_vote_choices( + choice_list: &Vec, + candidate_list: &CandidateList, +) -> VoteChoices { + let mut choices = VoteChoices::new(); + for i in 0..candidate_list.get_candidate().len() { + let mut pair = VoteChoice::new(); + pair.set_candidate(candidate_list.get_candidate()[i].clone()); + pair.set_value(choice_list[i]); + choices.mut_choice().push(pair); + } + choices } -/// Generate a vote request containing ballots for selected candidates, rest -/// ballot and a group of zero-knowledge proofs to prove that ballots is -/// correct, where zero-knowledge proofs contains format proof, balance proof -/// and range proof. The format proof is used to prove that the format of -/// ballots is correct so that it can be counted in the total number of votes -/// when counting, the balance proof is used to prove that poll ballots + the -/// rest ballot = the blank ballot, the range proof is used to prove that the -/// value of each ballot is non-negative. +/// Votes the ciphertext ballots and generates associated ZKP proofs. pub fn vote( - secret: &VoterSecret, - choices: &VoteChoices, - response: &RegistrationResponse, - param: &SystemParametersStorage, + voter_secret: &VoterSecret, + vote_choices: &VoteChoices, + registration_response: &RegistrationResponse, + poll_parameters: &PollParametersStorage, ) -> Result { - let mut request = VoteRequest::new(); - let mut blinding_vote_sum = Scalar::zero(); - let mut blindings: Vec = Vec::new(); - let mut vote_value: Vec = Vec::new(); - let mut v_weight_rest = response.get_voter_weight() as i64; - let poll_point = bytes_to_point(param.get_poll_point())?; - let vote_secret = bytes_to_scalar(secret.get_voter_secret())?; - - for choice_keypair in choices.get_choice() { + let mut vote_request = VoteRequest::new(); + + // Compute for each choice. + let mut blinding_sum = Scalar::zero(); + let mut blinding_list: Vec = Vec::new(); + let mut choice_list: Vec = Vec::new(); + let mut unused_vote_weight = + registration_response.get_voter_weight() as i64; + let poll_point = bytes_to_point(poll_parameters.get_poll_point())?; + for choice_keypair in vote_choices.get_choice() { let candidate_address = choice_keypair.get_candidate(); let value = choice_keypair.get_value(); - v_weight_rest -= value as i64; - if v_weight_rest < 0 { + unused_vote_weight -= value as i64; + // Max voter weight has been used up. + if unused_vote_weight < 0 { return Err(WedprError::ArgumentError); } + + // Make a ciphertext ballot. let mut vote_ballot = Ballot::new(); let blinding = get_random_scalar(); let ciphertext1 = RistrettoPoint::multiscalar_mul( &[Scalar::from(value as u64), blinding], &[*BASEPOINT_G1, poll_point], ); + blinding_sum += blinding; + let ciphertext2 = *BASEPOINT_G2 * blinding; + vote_ballot.set_ciphertext1(point_to_bytes(&ciphertext1)); + vote_ballot.set_ciphertext2(point_to_bytes(&ciphertext2)); + + // Prove ballot format. let format_proof = prove_format_proof( value as u64, &blinding, @@ -116,88 +131,60 @@ pub fn vote( &*BASEPOINT_G2, &poll_point, ); - blinding_vote_sum += blinding; - let ciphertext2 = *BASEPOINT_G2 * blinding; - vote_ballot.set_ciphertext1(point_to_bytes(&ciphertext1)); - vote_ballot.set_ciphertext2(point_to_bytes(&ciphertext2)); let mut ballot_proof = BallotProof::new(); ballot_proof.set_format_proof(proto_to_bytes(&format_proof)?); - let mut proof_keypair = StringToCandidateBallotProofPair::new(); - proof_keypair.set_key(candidate_address.to_string()); - proof_keypair.set_value(ballot_proof); - request.mut_ballot_proof().push(proof_keypair); - blindings.push(blinding); - vote_value.push(value as u64); + // Write back. + let mut proof_pair = StringToBallotProofPair::new(); + proof_pair.set_key(candidate_address.to_string()); + proof_pair.set_value(ballot_proof); + vote_request.mut_ballot_proof().push(proof_pair); + + blinding_list.push(blinding); + choice_list.push(value as u64); + let mut ballot_pair = CandidateBallot::new(); ballot_pair.set_candidate(candidate_address.to_string()); ballot_pair.set_ballot(vote_ballot); - request.mut_vote().mut_voted_ballot().push(ballot_pair); + vote_request.mut_vote().mut_voted_ballot().push(ballot_pair); } - let v_vote_sum = - (response.get_voter_weight() - v_weight_rest as u32) as u64; + + // Compute for the rest unused ballots. let blinding_rest = get_random_scalar(); let rest_ballot = RistrettoPoint::multiscalar_mul( - &[Scalar::from(v_weight_rest as u64), blinding_rest], + &[Scalar::from(unused_vote_weight as u64), blinding_rest], &[*BASEPOINT_G1, poll_point], ); + // Prove the balance. + let used_vote_weight_sum = (registration_response.get_voter_weight() + - unused_vote_weight as u32) as u64; + let vote_secret = bytes_to_scalar(voter_secret.get_voter_secret())?; let balance_proof = prove_sum_relationship( - v_vote_sum, - v_weight_rest as u64, - &blinding_vote_sum, + used_vote_weight_sum, + unused_vote_weight as u64, + &blinding_sum, &blinding_rest, &vote_secret, &BASEPOINT_G1, &poll_point, ); - vote_value.push(v_weight_rest as u64); - blindings.push(blinding_rest); - pending_u64_vec(&mut vote_value); - pending_scalar_vec(&mut blindings); + // Prove the range. + choice_list.push(unused_vote_weight as u64); + blinding_list.push(blinding_rest); + align_u64_list_if_needed(&mut choice_list); + align_scalar_list_if_needed(&mut blinding_list); let (range_proof, _) = - prove_value_range_in_batch(&vote_value, &blindings, &poll_point)?; - let signature = response.get_signature(); - request - .mut_vote() - .set_blank_ballot(response.get_ballot().clone()); - request.set_sum_balance_proof(proto_to_bytes(&balance_proof)?); - request.set_range_proof(range_proof); - request.mut_vote().set_signature(signature.to_vec()); - request - .mut_vote() - .mut_rest_ballot() - .set_ciphertext1(point_to_bytes(&rest_ballot)); - Ok(request) -} + prove_value_range_in_batch(&choice_list, &blinding_list, &poll_point)?; -fn pending_u64_vec(v: &mut Vec) -> bool { - let length = v.len() as i32; - let log_length = (length as f64).log2().ceil() as u32; - let expected_len = 2_i32.pow(log_length); - if expected_len == length { - return true; - } - let pending_length = expected_len - length; - for _ in 0..pending_length { - let tpm = 0u64; - v.push(tpm); - } - true -} - -fn pending_scalar_vec(v: &mut Vec) -> bool { - let length = v.len() as i32; - let log_length = (length as f64).log2().ceil() as u32; - let expected_len = 2_i32.pow(log_length); - if expected_len == length { - return true; - } - let pending_length = expected_len - length; - for _ in 0..pending_length { - let tpm = Scalar::default(); - v.push(tpm); - } - true + // Write back. + vote_request.set_sum_balance_proof(proto_to_bytes(&balance_proof)?); + vote_request.set_range_proof(range_proof); + let vote = vote_request.mut_vote(); + vote.set_signature(registration_response.get_signature().to_vec()); + vote.mut_rest_ballot() + .set_ciphertext1(point_to_bytes(&rest_ballot)); + vote.set_blank_ballot(registration_response.get_ballot().clone()); + Ok(vote_request) } diff --git a/solution/key_tool_box/hierarchical_deterministic_key/Cargo.toml b/solution/key_tool_box/hierarchical_deterministic_key/Cargo.toml index 70893bf..f0d9c1a 100644 --- a/solution/key_tool_box/hierarchical_deterministic_key/Cargo.toml +++ b/solution/key_tool_box/hierarchical_deterministic_key/Cargo.toml @@ -11,8 +11,8 @@ description = "Library of Hierarchical Deterministic Key (HDK) solution." [dependencies] hex = "0.3" rand = "0.7" -wagyu-model = { package = "h-wagyu-model", version = "0.6.3" } -wagyu_lib = { package = "wagyu-hdk", version = "0.6.4" } +hdk_ext_model = { package = "h-wagyu-model", version = "0.6.3" } +hdk_ext_lib = { package = "wagyu-hdk", version = "0.6.4" } wedpr_l_macros = "1.0.0" wedpr_l_utils = "1.0.0" diff --git a/solution/key_tool_box/hierarchical_deterministic_key/src/hdk.rs b/solution/key_tool_box/hierarchical_deterministic_key/src/hdk.rs index 52a86c6..5383375 100644 --- a/solution/key_tool_box/hierarchical_deterministic_key/src/hdk.rs +++ b/solution/key_tool_box/hierarchical_deterministic_key/src/hdk.rs @@ -2,11 +2,10 @@ //! Core functions of hierarchical deterministic key (HDK) -use wagyu_lib::{ - wordlist, HdkDerivationPath, HdkExtendedPrivateKey, - HdkMnemonic, Mainnet, +use hdk_ext_lib::{ + wordlist, HdkDerivationPath, HdkExtendedPrivateKey, HdkMnemonic, Mainnet, }; -use wagyu_model::{ +use hdk_ext_model::{ mnemonic::Mnemonic, ExtendedPrivateKey, MnemonicCount, MnemonicExtended, }; @@ -43,21 +42,20 @@ pub fn create_master_key_en( password: &str, mnemonic_str: &str, ) -> Result, WedprError> { - let mnemonic = - match HdkMnemonic::::from_phrase( - mnemonic_str, - ) { - Ok(v) => v, - Err(_) => { - wedpr_println!( - "mnemonic check failed!, mnemonic = {}", - mnemonic_str - ); - return Err(WedprError::ArgumentError); - }, - }; + let mnemonic = match HdkMnemonic::::from_phrase( + mnemonic_str, + ) { + Ok(v) => v, + Err(_) => { + wedpr_println!( + "mnemonic check failed!, mnemonic = {}", + mnemonic_str + ); + return Err(WedprError::ArgumentError); + }, + }; let master_extended_private_key = match mnemonic - .to_extended_private_key(Some(password).clone()) + .to_extended_private_key(Some(password)) { Ok(v) => v, Err(_) => { @@ -132,9 +130,12 @@ pub fn derive_extended_key( return Err(WedprError::FormatError); }, }; - let private_key_hex = hex::encode(extended_private_key - .to_private_key() - .to_secp256k1_secret_key().serialize()); + let private_key_hex = hex::encode( + extended_private_key + .to_private_key() + .to_secp256k1_secret_key() + .serialize(), + ); let extended_private_key_bytes = match decode_hex_string(&private_key_hex) { Ok(v) => v, @@ -151,7 +152,7 @@ pub fn derive_extended_key( .to_public_key() .to_secp256k1_public_key() .serialize(); - // .serialize_uncompressed(); + // .serialize_uncompressed(); // TODO: Replace with a better way to initialize PB if available. Ok(ExtendedKeyPair { diff --git a/solution/selective_certificate_disclosure/Cargo.toml b/solution/selective_certificate_disclosure/Cargo.toml index 038a0ec..ca7b8ad 100644 --- a/solution/selective_certificate_disclosure/Cargo.toml +++ b/solution/selective_certificate_disclosure/Cargo.toml @@ -16,8 +16,6 @@ serde_json = "1.0.41" wedpr-indy-crypto = "0.4.5" wedpr_l_macros = "1.0.0" wedpr_l_utils = "1.0.0" -#wedpr_l_common_coder_base64 = {version = "1.0.0", optional = true} - wedpr_s_protos = "1.3.0" [dev-dependencies] diff --git a/solution/selective_certificate_disclosure/src/main.rs b/solution/selective_certificate_disclosure/src/main.rs index 4f427a8..7bd4ecb 100644 --- a/solution/selective_certificate_disclosure/src/main.rs +++ b/solution/selective_certificate_disclosure/src/main.rs @@ -63,7 +63,7 @@ fn flow_cn() { let (certificate_template, template_private_key) = issuer_init_certificate_template(); print_wide( - "本demo中,你将体验如何申请并使用具备选择性认证披露功能的新一代数字凭证。\ + "本demo中,您将体验如何申请并使用具备选择性认证披露功能的新一代数字凭证。\ 为了更容易理解其效果,我们设定了如下示例应用场景。", ); println!( diff --git a/solution/verifiable_confidential_ledger/Cargo.toml b/solution/verifiable_confidential_ledger/Cargo.toml index 8dff50e..3209818 100644 --- a/solution/verifiable_confidential_ledger/Cargo.toml +++ b/solution/verifiable_confidential_ledger/Cargo.toml @@ -12,7 +12,6 @@ description = "Library of verifiable confidential ledger (VCL) solution." colored = "1.8" curve25519-dalek = { version = "1", features = [ "serde" ] } protobuf = "2.22.1" -#protoc-rust = "2.20.0" wedpr_l_crypto_zkp_discrete_logarithm_proof = "1.1.0" wedpr_l_crypto_zkp_range_proof = { git = "https://github.com/WeBankBlockchain/WeDPR-Lab-Crypto", branch = "main" } diff --git a/solution/verifiable_confidential_ledger/src/main.rs b/solution/verifiable_confidential_ledger/src/main.rs index 8f4a3eb..afde04a 100644 --- a/solution/verifiable_confidential_ledger/src/main.rs +++ b/solution/verifiable_confidential_ledger/src/main.rs @@ -3,7 +3,6 @@ //! Minimalist demo of verifiable confidential ledger. use colored::*; -use protobuf::Message; use std; use wedpr_l_crypto_zkp_utils::point_to_bytes; use wedpr_s_verifiable_confidential_ledger::vcl; @@ -46,7 +45,7 @@ fn main() { } fn flow_cn() { - print_wide("账本demo流程中,你将体验如何通过账本金额的明文数据生成对应的密文凭证, \ + print_wide("账本demo流程中,您将体验如何通过账本金额的明文数据生成对应的密文凭证, \ 并了解密文凭证配套零知识证明的基础用法"); println!( From 885b2c9c4749a66d559840c24afb1ba0073dd78a Mon Sep 17 00:00:00 2001 From: HaoXuan40404 <444649358@qq.com> Date: Sun, 26 Sep 2021 14:20:14 +0800 Subject: [PATCH 13/15] fix with acv sit --- solution/anonymous_ciphertext_voting/src/main.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/solution/anonymous_ciphertext_voting/src/main.rs b/solution/anonymous_ciphertext_voting/src/main.rs index f827207..9780f07 100644 --- a/solution/anonymous_ciphertext_voting/src/main.rs +++ b/solution/anonymous_ciphertext_voting/src/main.rs @@ -207,7 +207,7 @@ fn flow_cn() { println!( "\n投票失败:您投出的总票数超出您的权重限制:{} + {} + {} \ > {}\n", - candidate2_votes, + candidate1_votes, candidate2_votes, candidate3_votes, last_voter_weight @@ -617,7 +617,7 @@ fn flow_en() { println!( "\nVote Failed: Your total votes has exceeded your voter \ weight: {} + {} + {} > {}\n", - candidate2_votes, + candidate1_votes, candidate2_votes, candidate3_votes, last_voter_weight From 0f9cbca317f5c0cd0c25a98ee8ee7a1486548ad6 Mon Sep 17 00:00:00 2001 From: julyawang <1090667500@qq.com> Date: Sun, 26 Sep 2021 15:16:11 +0800 Subject: [PATCH 14/15] fix acv main --- solution/anonymous_ciphertext_voting/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/solution/anonymous_ciphertext_voting/src/main.rs b/solution/anonymous_ciphertext_voting/src/main.rs index 9780f07..ee8e4c8 100644 --- a/solution/anonymous_ciphertext_voting/src/main.rs +++ b/solution/anonymous_ciphertext_voting/src/main.rs @@ -326,7 +326,7 @@ fn flow_cn() { ); println!( - "验证内容包括:\n1. \ + "验证内容包括:\n 验证计票者公布的计票信息是使用正确的计票者密钥计算而得,\ 而不是随意构造而得。\n" ); From 92c1562556e1180f163d1bdba0f030893a446a95 Mon Sep 17 00:00:00 2001 From: HaoXuan40404 <444649358@qq.com> Date: Wed, 29 Sep 2021 10:07:14 +0800 Subject: [PATCH 15/15] update 1.5.0 crate --- bounty/Cargo.toml | 6 +++--- ffi/ffi_c/ffi_c_ktb/Cargo.toml | 4 ++-- ffi/ffi_c/ffi_c_scd/Cargo.toml | 4 ++-- ffi/ffi_java/ffi_java_ktb/Cargo.toml | 4 ++-- ffi/ffi_java/ffi_java_scd/Cargo.toml | 4 ++-- protos/Cargo.toml | 2 +- solution/anonymous_ciphertext_voting/Cargo.toml | 14 +++++++------- .../hierarchical_deterministic_key/Cargo.toml | 2 +- .../selective_certificate_disclosure/Cargo.toml | 2 +- solution/verifiable_confidential_ledger/Cargo.toml | 2 +- 10 files changed, 22 insertions(+), 22 deletions(-) diff --git a/bounty/Cargo.toml b/bounty/Cargo.toml index 34e8794..ae81bc7 100644 --- a/bounty/Cargo.toml +++ b/bounty/Cargo.toml @@ -13,13 +13,13 @@ protobuf = "2.22.1" rand = "0.3.17" sha3 = "0.8" wedpr_l_crypto_zkp_discrete_logarithm_proof = "1.0.0" -wedpr_l_crypto_zkp_range_proof = { git = "https://github.com/WeBankBlockchain/WeDPR-Lab-Crypto", branch = "main" } +wedpr_l_crypto_zkp_range_proof = "1.2.0" wedpr_l_crypto_zkp_utils = "1.0.0" wedpr_l_macros = "1.0.0" wedpr_l_protos = "1.0.0" wedpr_l_utils = "1.0.0" -wedpr_s_protos = "1.3.0" -wedpr_s_selective_certificate_disclosure = "1.3.0" +wedpr_s_protos = { path = "../protos" } +wedpr_s_selective_certificate_disclosure = { path = "../solution/selective_certificate_disclosure" } wedpr_s_verifiable_confidential_ledger = { path = "../solution/verifiable_confidential_ledger" } diff --git a/ffi/ffi_c/ffi_c_ktb/Cargo.toml b/ffi/ffi_c/ffi_c_ktb/Cargo.toml index f7d537b..0a1514e 100644 --- a/ffi/ffi_c/ffi_c_ktb/Cargo.toml +++ b/ffi/ffi_c/ffi_c_ktb/Cargo.toml @@ -16,8 +16,8 @@ protobuf = "2.22.1" wedpr_ffi_common = "1.0.0" wedpr_ffi_macros = "1.0.0" wedpr_l_macros = "1.0.0" -wedpr_s_hierarchical_deterministic_key = "1.3.0" -wedpr_s_protos = "1.3.0" +wedpr_s_hierarchical_deterministic_key = { path = "../../../solution/key_tool_box/hierarchical_deterministic_key" } +wedpr_s_protos = { path = "../../../protos" } # This is required to generate C/C++ header files. [build-dependencies] diff --git a/ffi/ffi_c/ffi_c_scd/Cargo.toml b/ffi/ffi_c/ffi_c_scd/Cargo.toml index 263517b..7ce1a5b 100644 --- a/ffi/ffi_c/ffi_c_scd/Cargo.toml +++ b/ffi/ffi_c/ffi_c_scd/Cargo.toml @@ -16,8 +16,8 @@ protobuf = "2.22.1" wedpr_ffi_common = "1.0.0" wedpr_ffi_macros = "1.0.0" wedpr_l_macros = "1.0.0" -wedpr_s_protos = "1.3.0" -wedpr_s_selective_certificate_disclosure = "1.3.0" +wedpr_s_protos = { path = "../../../protos" } +wedpr_s_selective_certificate_disclosure = { path = "../../../solution/selective_certificate_disclosure" } # This is required to generate C/C++ header files. [build-dependencies] diff --git a/ffi/ffi_java/ffi_java_ktb/Cargo.toml b/ffi/ffi_java/ffi_java_ktb/Cargo.toml index f06f5a3..2bb76a2 100644 --- a/ffi/ffi_java/ffi_java_ktb/Cargo.toml +++ b/ffi/ffi_java/ffi_java_ktb/Cargo.toml @@ -15,8 +15,8 @@ jni = "0.13.0" protobuf = "2.22.1" wedpr_ffi_common = "1.1.0" wedpr_ffi_macros = "1.1.0" -wedpr_s_hierarchical_deterministic_key = "1.3.0" -wedpr_s_protos = "1.3.0" +wedpr_s_hierarchical_deterministic_key = { path = "../../../solution/key_tool_box/hierarchical_deterministic_key" } +wedpr_s_protos = { path = "../../../protos" } # This is required to generate C/C++ header files. [build-dependencies] diff --git a/ffi/ffi_java/ffi_java_scd/Cargo.toml b/ffi/ffi_java/ffi_java_scd/Cargo.toml index 6c7e826..4a44616 100644 --- a/ffi/ffi_java/ffi_java_scd/Cargo.toml +++ b/ffi/ffi_java/ffi_java_scd/Cargo.toml @@ -16,8 +16,8 @@ wedpr_ffi_common = "1.0.0" wedpr_ffi_macros = "1.0.0" wedpr_l_protos = "1.0.0" -wedpr_s_protos = "1.3.0" -wedpr_s_selective_certificate_disclosure = "1.3.0" +wedpr_s_protos = { path = "../../../protos" } +wedpr_s_selective_certificate_disclosure = { path = "../../../solution/selective_certificate_disclosure" } # This is required to generate C/C++ header files. [build-dependencies] diff --git a/protos/Cargo.toml b/protos/Cargo.toml index 6f7b6f2..e47d204 100644 --- a/protos/Cargo.toml +++ b/protos/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "wedpr_s_protos" -version = "1.4.0" +version = "1.5.0" authors = [ "WeDPR " ] edition = "2018" license = "Apache-2.0" diff --git a/solution/anonymous_ciphertext_voting/Cargo.toml b/solution/anonymous_ciphertext_voting/Cargo.toml index eda313b..b54a765 100644 --- a/solution/anonymous_ciphertext_voting/Cargo.toml +++ b/solution/anonymous_ciphertext_voting/Cargo.toml @@ -4,20 +4,20 @@ version = "1.5.0" authors = [ "WeDPR " ] edition = "2018" license = "Apache-2.0" -description = "Library of WeDPR protobuf definitions and their generated code." +description = "Library of anonymous ciphertext voting (ACV) solution." # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] curve25519-dalek = { version = "1", features = [ "serde" ] } lazy_static = "1.4.0" -wedpr_l_crypto_hash_keccak256 = { git = "https://github.com/WeBankBlockchain/WeDPR-Lab-Crypto.git", branch = "release-1.2.0" } -wedpr_l_crypto_signature_secp256k1 = { git = "https://github.com/WeBankBlockchain/WeDPR-Lab-Crypto.git", branch = "release-1.2.0" } -wedpr_l_crypto_zkp_discrete_logarithm_proof = { git = "https://github.com/WeBankBlockchain/WeDPR-Lab-Crypto.git", branch = "release-1.2.0" } -wedpr_l_crypto_zkp_range_proof = { git = "https://github.com/WeBankBlockchain/WeDPR-Lab-Crypto.git", branch = "release-1.2.0" } -wedpr_l_crypto_zkp_utils = { git = "https://github.com/WeBankBlockchain/WeDPR-Lab-Crypto.git", branch = "release-1.2.0" } +wedpr_l_crypto_hash_keccak256 = "1.1.0" +wedpr_l_crypto_signature_secp256k1 = "1.1.0" +wedpr_l_crypto_zkp_discrete_logarithm_proof = "1.2.0" +wedpr_l_crypto_zkp_range_proof = "1.2.0" +wedpr_l_crypto_zkp_utils = "1.2.0" wedpr_l_macros = "1.0.0" -wedpr_l_protos = { git = "https://github.com/WeBankBlockchain/WeDPR-Lab-Crypto.git", branch = "release-1.2.0" } +wedpr_l_protos = "1.2.0" wedpr_l_utils = "1.1.0" wedpr_s_protos = { path = "../../protos" } colored = "1.8" diff --git a/solution/key_tool_box/hierarchical_deterministic_key/Cargo.toml b/solution/key_tool_box/hierarchical_deterministic_key/Cargo.toml index f0d9c1a..9440dca 100644 --- a/solution/key_tool_box/hierarchical_deterministic_key/Cargo.toml +++ b/solution/key_tool_box/hierarchical_deterministic_key/Cargo.toml @@ -16,7 +16,7 @@ hdk_ext_lib = { package = "wagyu-hdk", version = "0.6.4" } wedpr_l_macros = "1.0.0" wedpr_l_utils = "1.0.0" -wedpr_s_protos = "1.3.0" +wedpr_s_protos = { path = "../../../protos" } [dev-dependencies] wedpr_l_common_coder_base64 = "1.0.0" diff --git a/solution/selective_certificate_disclosure/Cargo.toml b/solution/selective_certificate_disclosure/Cargo.toml index ca7b8ad..72d18f5 100644 --- a/solution/selective_certificate_disclosure/Cargo.toml +++ b/solution/selective_certificate_disclosure/Cargo.toml @@ -16,7 +16,7 @@ serde_json = "1.0.41" wedpr-indy-crypto = "0.4.5" wedpr_l_macros = "1.0.0" wedpr_l_utils = "1.0.0" -wedpr_s_protos = "1.3.0" +wedpr_s_protos = { path = "../../protos" } [dev-dependencies] criterion = "0.2" diff --git a/solution/verifiable_confidential_ledger/Cargo.toml b/solution/verifiable_confidential_ledger/Cargo.toml index 3209818..be2dfc8 100644 --- a/solution/verifiable_confidential_ledger/Cargo.toml +++ b/solution/verifiable_confidential_ledger/Cargo.toml @@ -14,7 +14,7 @@ curve25519-dalek = { version = "1", features = [ "serde" ] } protobuf = "2.22.1" wedpr_l_crypto_zkp_discrete_logarithm_proof = "1.1.0" -wedpr_l_crypto_zkp_range_proof = { git = "https://github.com/WeBankBlockchain/WeDPR-Lab-Crypto", branch = "main" } +wedpr_l_crypto_zkp_range_proof = "1.2.0" wedpr_l_crypto_zkp_utils = "1.1.0" wedpr_l_macros = "1.0.0"