Skip to content

Commit f187bbd

Browse files
julyawangHaoXuan40404
authored andcommitted
add comment
1 parent bdba188 commit f187bbd

File tree

6 files changed

+35
-9
lines changed

6 files changed

+35
-9
lines changed

protos/solution/acv/acv.proto

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ message VoteStorage {
6666
repeated CandidateBallot voted_ballot = 4;
6767
}
6868

69+
// system parameters
6970
message CandidateList {
7071
repeated string candidate = 1;
7172
}
@@ -75,6 +76,8 @@ message SystemParametersStorage {
7576
CandidateList candidates = 2;
7677
}
7778

79+
80+
// proofs
7881
message BallotProof {
7982
bytes format_proof = 1;
8083
}

solution/anonymous_ciphertext_voting/src/coordinator.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use wedpr_s_protos::generated::acv::{
1515
StringToCountingPartPair, SystemParametersStorage,
1616
};
1717

18-
/// Makes system parameters by candidate list and counter storage messages.
18+
/// Makes system parameters containing public key and candidates list using counter storage messages.
1919
pub fn make_system_parameters(
2020
candidates: &CandidateList,
2121
counter_storage: &CounterSystemParametersStorage,
@@ -30,7 +30,7 @@ pub fn make_system_parameters(
3030
Ok(storage)
3131
}
3232

33-
/// Certifies ballot value which voter can vote to all candidates.
33+
/// Certifies voter's weight which indicates the maximum value that the voter can vote totally.
3434
pub fn certify_bounded_voter(
3535
secret_key: &[u8],
3636
value: u32,
@@ -64,7 +64,7 @@ pub fn certify_bounded_voter(
6464
Ok(response)
6565
}
6666

67-
/// Decrypts counters' .
67+
/// Aggregates the decrypted results of all counters, ?
6868
pub fn aggregate_decrypted_part_sum(
6969
param: &SystemParametersStorage,
7070
decrypted_result_part_storage: &DecryptedResultPartStorage,

solution/anonymous_ciphertext_voting/src/counter.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use wedpr_s_protos::generated::acv::{
1616
SystemParametersStorage, VoteResultStorage, VoteStorage,
1717
};
1818

19+
/// Generates a random number as secret key used for making system parameter and counting.
1920
pub fn make_counter_secret() -> CounterSecret {
2021
let secret_share = get_random_scalar();
2122
CounterSecret {
@@ -25,6 +26,8 @@ pub fn make_counter_secret() -> CounterSecret {
2526
}
2627
}
2728

29+
/// Makes share of system parameter using secret key,
30+
/// where system parameter here means global public key.
2831
pub fn make_system_parameters_share(
2932
counter_id: &str,
3033
counter_secret: &CounterSecret,
@@ -40,6 +43,13 @@ pub fn make_system_parameters_share(
4043
})
4144
}
4245

46+
47+
/// Generates intermediate values and zero-knowledge proof for final count,
48+
/// where the intermediate values is the share of ballots received by each candidate,
49+
/// the zero-knowledge proof is equality relationship proof used to prove that
50+
/// counter's count process is correct, specifically refers to that
51+
/// the secret key counter used in counting is equal to the secret key generated
52+
/// for making system parameter.
4353
pub fn count(
4454
counter_id: &str,
4555
secret: &CounterSecret,
@@ -88,9 +98,7 @@ pub fn count(
8898
Ok(request)
8999
}
90100

91-
// In this function, everyone can check anonymousvoting result by c1 - c2r_sum,
92-
// because we already know v and candidates, by using c1 - c2r_sum, we can check
93-
// whether vG_1 =? c1 - c2r_sum. pub fn verify_counter(result_pb:
101+
/// Count the value of ballots received by each candidate.
94102
pub fn finalize_vote_result(
95103
param: &SystemParametersStorage,
96104
vote_sum: &VoteStorage,

solution/anonymous_ciphertext_voting/src/verifier.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ use wedpr_l_protos::{
2424
};
2525
use wedpr_l_utils::traits::{Hash, Signature};
2626

27+
/// Verifies whether each ballot of voters is correct,
28+
/// specifically refers to the format, the accounting balance and the numerical range of each ballot.
2729
pub fn verify_bounded_vote_request(
2830
param: &SystemParametersStorage,
2931
request: &VoteRequest,
@@ -105,6 +107,7 @@ pub fn verify_bounded_vote_request(
105107
Ok(true)
106108
}
107109

110+
/// ?
108111
pub fn aggregate_vote_sum_response(
109112
param: &SystemParametersStorage,
110113
vote_storage_part: &VoteStorage,
@@ -187,6 +190,8 @@ pub fn aggregate_vote_sum_response(
187190
Ok(true)
188191
}
189192

193+
/// Verifies whether the counting process is correct,
194+
/// specifically refers to that whether each counter used correct secret key when counting.
190195
pub fn verify_count_request(
191196
param: &SystemParametersStorage,
192197
encrypted_vote_sum: &VoteStorage,
@@ -244,9 +249,7 @@ pub fn verify_count_request(
244249
Ok(true)
245250
}
246251

247-
// In this function, everyone can check anonymousvoting result by c1 - c2r_sum,
248-
// because we already know v and candidates, by using c1 - c2r_sum, we can check
249-
// whether vG_1 =? c1 - c2r_sum. pub fn verify_counter(result_pb:
252+
/// Verifies whether the final score of each candidate is correct.
250253
pub fn verify_vote_result(
251254
param: &SystemParametersStorage,
252255
vote_sum: &VoteStorage,

solution/anonymous_ciphertext_voting/src/voter.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use wedpr_s_protos::generated::acv::{
2121
VoteChoices, VoteRequest, VoterSecret,
2222
};
2323

24+
/// Generates a random number as secret number for applying blank ballot.
2425
pub fn make_voter_secret() -> VoterSecret {
2526
let vote_secret = get_random_scalar();
2627
VoterSecret {
@@ -30,6 +31,7 @@ pub fn make_voter_secret() -> VoterSecret {
3031
}
3132
}
3233

34+
/// Applys to the coordinator for blank ballot using own weight and secret number.
3335
pub fn make_bounded_registration_request(
3436
secret: &VoterSecret,
3537
param: &SystemParametersStorage,
@@ -48,6 +50,8 @@ pub fn make_bounded_registration_request(
4850
Ok(request)
4951
}
5052

53+
/// Verifies blank ballot issued by coordinator
54+
/// by recalculating and comparing whether it is consistent.
5155
pub fn verify_blank_ballot(
5256
request: &RegistrationRequest,
5357
response: &RegistrationResponse,
@@ -72,6 +76,13 @@ pub fn verify_blank_ballot(
7276
&& request_ciphertext2 == response_ciphertext2)
7377
}
7478

79+
/// Generate a vote request containing ballots for selected candidates, rest ballot
80+
/// and a group of zero-knowledge proofs to prove that ballots is correct,
81+
/// where zero-knowledge proofs contains format proof, balance proof and range proof.
82+
/// The format proof is used to prove that the format of ballots is correct
83+
/// so that it can be counted in the total number of votes when counting,
84+
/// the balance proof is used to prove that poll ballots + the rest ballot = the blank ballot,
85+
/// the range proof is used to prove that the value of ballot is non-negative.
7586
pub fn vote_bounded(
7687
secret: &VoterSecret,
7788
choices: &VoteChoices,

solution/verifiable_confidential_ledger/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use colored::*;
66
use std;
77
use wedpr_l_crypto_zkp_utils::point_to_bytes;
88
use wedpr_s_verifiable_confidential_ledger::vcl;
9+
use protobuf::Message;
910

1011
fn main() {
1112
print_highlight2(

0 commit comments

Comments
 (0)