Skip to content

Commit cc08df1

Browse files
cyjseagullHaoXuan40404
authored andcommitted
optimize acv output message
1 parent c1bbe0c commit cc08df1

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

solution/anonymous_ciphertext_voting/src/coordinator.rs

+35-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
//! Library for a poll coordinator.
44
55
use curve25519_dalek::{ristretto::RistrettoPoint, scalar::Scalar};
6+
use std::time::Instant;
67
use wedpr_l_crypto_zkp_utils::{bytes_to_point, point_to_bytes, BASEPOINT_G1};
78
use wedpr_l_utils::error::WedprError;
89

@@ -363,7 +364,9 @@ pub fn finalize_vote_result(
363364

364365
// Compute the total votes.
365366
let target_total = blank_c1_sum - blank_c2_r_sum;
366-
for i in 1..=max_vote_limit {
367+
let mut calculate_total_iter = 0;
368+
for i in 0..=max_vote_limit {
369+
calculate_total_iter = &calculate_total_iter + 1;
367370
if target_total.eq(&(*BASEPOINT_G1 * Scalar::from(i as u64))) {
368371
let mut new_pair = StringToInt64Pair::new();
369372
new_pair.set_key(POLL_RESULT_KEY_TOTAL_BALLOTS.to_string());
@@ -374,6 +377,7 @@ pub fn finalize_vote_result(
374377
}
375378

376379
// Compute the votes for each candidate.
380+
let mut iter = 0;
377381
for candidate in poll_parameters.get_candidates().get_candidate() {
378382
let ballot = get_ballot_by_candidate(vote_sum, candidate)?;
379383
let candidate_counting_part = get_counting_part_by_candidate(
@@ -386,6 +390,7 @@ pub fn finalize_vote_result(
386390
bytes_to_point(ballot.get_ciphertext1())? - candidate_c2_r_sum;
387391

388392
for i in 0..=max_vote_limit {
393+
iter = &iter + 1;
389394
if target_candidate.eq(&(*BASEPOINT_G1 * Scalar::from(i as u64))) {
390395
let mut new_pair = StringToInt64Pair::new();
391396
new_pair.set_key(candidate.to_string());
@@ -395,6 +400,13 @@ pub fn finalize_vote_result(
395400
}
396401
}
397402
}
403+
wedpr_println!(
404+
"** finalize_vote_result calculate_total_iter: {:?}, decrypt \
405+
candidate iter: {:?}, result: {:?}",
406+
calculate_total_iter,
407+
iter,
408+
result.get_result()
409+
);
398410
Ok(result)
399411
}
400412

@@ -430,6 +442,7 @@ pub fn decrypt_unlisted_candidate_ballot(
430442
}
431443
// decrypt the unlisted candidate ballot value when decrypt candidate
432444
// success
445+
let mut iter = 0;
433446
for unlisted_vote_ballot in vote_sum.get_voted_ballot_unlisted() {
434447
if unlisted_candidate_part.get_candidate_cipher()
435448
!= unlisted_vote_ballot.get_key()
@@ -454,6 +467,7 @@ pub fn decrypt_unlisted_candidate_ballot(
454467
// decrypt the ballot value
455468
for i in 0..=max_vote_limit {
456469
let try_num = Scalar::from(i as u64);
470+
iter = &iter + 1;
457471
if !target_total.eq(&(*BASEPOINT_G1 * try_num)) {
458472
continue;
459473
}
@@ -475,6 +489,11 @@ pub fn decrypt_unlisted_candidate_ballot(
475489
break;
476490
}
477491
}
492+
wedpr_println!(
493+
"** decrypt_unlisted_candidate_ballot iter: {:?}, result: {:?}",
494+
iter,
495+
decrypted_unlisted_candidate_ballot_result
496+
);
478497
Ok(true)
479498
}
480499

@@ -485,12 +504,16 @@ pub fn finalize_vote_result_unlisted(
485504
max_vote_limit: i64,
486505
max_candidate_number: i64,
487506
) -> Result<VoteResultStorage, WedprError> {
507+
let start_t = Instant::now();
508+
let mut start = Instant::now();
488509
let mut vote_result = finalize_vote_result(
489510
poll_parameters,
490511
vote_sum,
491512
aggregated_decrypted_result,
492513
max_vote_limit,
493514
)?;
515+
let finalize_vote_result_duration = start.elapsed();
516+
start = Instant::now();
494517
// finalize the vote result for the unlisted-candidates
495518
let mut aggregated_unlisted_candidate_ballot_result = BTreeMap::new();
496519
for mut unlisted_candidate in
@@ -514,5 +537,16 @@ pub fn finalize_vote_result_unlisted(
514537
.mut_unlisted_result()
515538
.push(unlisted_candidate_ballot_result);
516539
}
540+
let decrypt_unlisted_candidate_ballot_duration = start.elapsed();
541+
let total_time_cost = start_t.elapsed();
542+
wedpr_println!(
543+
"** Time elapsed: finalize_vote_result_duration: {:?}, \
544+
decrypt_unlisted_candidate_ballot_duration: {:?}, total time cost: \
545+
{:?}, ### {:?}",
546+
finalize_vote_result_duration,
547+
decrypt_unlisted_candidate_ballot_duration,
548+
total_time_cost,
549+
vote_result
550+
);
517551
Ok(vote_result)
518552
}

0 commit comments

Comments
 (0)