3
3
//! Library for a poll coordinator.
4
4
5
5
use curve25519_dalek:: { ristretto:: RistrettoPoint , scalar:: Scalar } ;
6
+ use std:: time:: Instant ;
6
7
use wedpr_l_crypto_zkp_utils:: { bytes_to_point, point_to_bytes, BASEPOINT_G1 } ;
7
8
use wedpr_l_utils:: error:: WedprError ;
8
9
@@ -363,7 +364,9 @@ pub fn finalize_vote_result(
363
364
364
365
// Compute the total votes.
365
366
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 ;
367
370
if target_total. eq ( & ( * BASEPOINT_G1 * Scalar :: from ( i as u64 ) ) ) {
368
371
let mut new_pair = StringToInt64Pair :: new ( ) ;
369
372
new_pair. set_key ( POLL_RESULT_KEY_TOTAL_BALLOTS . to_string ( ) ) ;
@@ -374,6 +377,7 @@ pub fn finalize_vote_result(
374
377
}
375
378
376
379
// Compute the votes for each candidate.
380
+ let mut iter = 0 ;
377
381
for candidate in poll_parameters. get_candidates ( ) . get_candidate ( ) {
378
382
let ballot = get_ballot_by_candidate ( vote_sum, candidate) ?;
379
383
let candidate_counting_part = get_counting_part_by_candidate (
@@ -386,6 +390,7 @@ pub fn finalize_vote_result(
386
390
bytes_to_point ( ballot. get_ciphertext1 ( ) ) ? - candidate_c2_r_sum;
387
391
388
392
for i in 0 ..=max_vote_limit {
393
+ iter = & iter + 1 ;
389
394
if target_candidate. eq ( & ( * BASEPOINT_G1 * Scalar :: from ( i as u64 ) ) ) {
390
395
let mut new_pair = StringToInt64Pair :: new ( ) ;
391
396
new_pair. set_key ( candidate. to_string ( ) ) ;
@@ -395,6 +400,13 @@ pub fn finalize_vote_result(
395
400
}
396
401
}
397
402
}
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
+ ) ;
398
410
Ok ( result)
399
411
}
400
412
@@ -430,6 +442,7 @@ pub fn decrypt_unlisted_candidate_ballot(
430
442
}
431
443
// decrypt the unlisted candidate ballot value when decrypt candidate
432
444
// success
445
+ let mut iter = 0 ;
433
446
for unlisted_vote_ballot in vote_sum. get_voted_ballot_unlisted ( ) {
434
447
if unlisted_candidate_part. get_candidate_cipher ( )
435
448
!= unlisted_vote_ballot. get_key ( )
@@ -454,6 +467,7 @@ pub fn decrypt_unlisted_candidate_ballot(
454
467
// decrypt the ballot value
455
468
for i in 0 ..=max_vote_limit {
456
469
let try_num = Scalar :: from ( i as u64 ) ;
470
+ iter = & iter + 1 ;
457
471
if !target_total. eq ( & ( * BASEPOINT_G1 * try_num) ) {
458
472
continue ;
459
473
}
@@ -475,6 +489,11 @@ pub fn decrypt_unlisted_candidate_ballot(
475
489
break ;
476
490
}
477
491
}
492
+ wedpr_println ! (
493
+ "** decrypt_unlisted_candidate_ballot iter: {:?}, result: {:?}" ,
494
+ iter,
495
+ decrypted_unlisted_candidate_ballot_result
496
+ ) ;
478
497
Ok ( true )
479
498
}
480
499
@@ -485,12 +504,16 @@ pub fn finalize_vote_result_unlisted(
485
504
max_vote_limit : i64 ,
486
505
max_candidate_number : i64 ,
487
506
) -> Result < VoteResultStorage , WedprError > {
507
+ let start_t = Instant :: now ( ) ;
508
+ let mut start = Instant :: now ( ) ;
488
509
let mut vote_result = finalize_vote_result (
489
510
poll_parameters,
490
511
vote_sum,
491
512
aggregated_decrypted_result,
492
513
max_vote_limit,
493
514
) ?;
515
+ let finalize_vote_result_duration = start. elapsed ( ) ;
516
+ start = Instant :: now ( ) ;
494
517
// finalize the vote result for the unlisted-candidates
495
518
let mut aggregated_unlisted_candidate_ballot_result = BTreeMap :: new ( ) ;
496
519
for mut unlisted_candidate in
@@ -514,5 +537,16 @@ pub fn finalize_vote_result_unlisted(
514
537
. mut_unlisted_result ( )
515
538
. push ( unlisted_candidate_ballot_result) ;
516
539
}
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
+ ) ;
517
551
Ok ( vote_result)
518
552
}
0 commit comments