33//! Library for a poll coordinator.
44
55use curve25519_dalek:: { ristretto:: RistrettoPoint , scalar:: Scalar } ;
6+ use std:: time:: Instant ;
67use wedpr_l_crypto_zkp_utils:: { bytes_to_point, point_to_bytes, BASEPOINT_G1 } ;
78use wedpr_l_utils:: error:: WedprError ;
89
@@ -353,27 +354,8 @@ pub fn finalize_vote_result(
353354 max_vote_limit : i64 ,
354355) -> Result < VoteResultStorage , WedprError > {
355356 let mut result = VoteResultStorage :: new ( ) ;
356- let blank_c1_sum =
357- bytes_to_point ( vote_sum. get_blank_ballot ( ) . get_ciphertext1 ( ) ) ?;
358- let blank_c2_r_sum = bytes_to_point (
359- aggregated_decrypted_result
360- . get_blank_part ( )
361- . get_blinding_c2 ( ) ,
362- ) ?;
363-
364- // Compute the total votes.
365- let target_total = blank_c1_sum - blank_c2_r_sum;
366- for i in 1 ..=max_vote_limit {
367- if target_total. eq ( & ( * BASEPOINT_G1 * Scalar :: from ( i as u64 ) ) ) {
368- let mut new_pair = StringToInt64Pair :: new ( ) ;
369- new_pair. set_key ( POLL_RESULT_KEY_TOTAL_BALLOTS . to_string ( ) ) ;
370- new_pair. set_value ( i) ;
371- result. mut_result ( ) . push ( new_pair) ;
372- break ;
373- }
374- }
375-
376357 // Compute the votes for each candidate.
358+ let mut iter = 0 ;
377359 for candidate in poll_parameters. get_candidates ( ) . get_candidate ( ) {
378360 let ballot = get_ballot_by_candidate ( vote_sum, candidate) ?;
379361 let candidate_counting_part = get_counting_part_by_candidate (
@@ -386,6 +368,7 @@ pub fn finalize_vote_result(
386368 bytes_to_point ( ballot. get_ciphertext1 ( ) ) ? - candidate_c2_r_sum;
387369
388370 for i in 0 ..=max_vote_limit {
371+ iter = & iter + 1 ;
389372 if target_candidate. eq ( & ( * BASEPOINT_G1 * Scalar :: from ( i as u64 ) ) ) {
390373 let mut new_pair = StringToInt64Pair :: new ( ) ;
391374 new_pair. set_key ( candidate. to_string ( ) ) ;
@@ -395,6 +378,11 @@ pub fn finalize_vote_result(
395378 }
396379 }
397380 }
381+ wedpr_println ! (
382+ "** finalize_vote_result decrypt candidate iter: {:?}, result: {:?}" ,
383+ iter,
384+ result. get_result( )
385+ ) ;
398386 Ok ( result)
399387}
400388
@@ -430,6 +418,7 @@ pub fn decrypt_unlisted_candidate_ballot(
430418 }
431419 // decrypt the unlisted candidate ballot value when decrypt candidate
432420 // success
421+ let mut iter = 0 ;
433422 for unlisted_vote_ballot in vote_sum. get_voted_ballot_unlisted ( ) {
434423 if unlisted_candidate_part. get_candidate_cipher ( )
435424 != unlisted_vote_ballot. get_key ( )
@@ -454,6 +443,7 @@ pub fn decrypt_unlisted_candidate_ballot(
454443 // decrypt the ballot value
455444 for i in 0 ..=max_vote_limit {
456445 let try_num = Scalar :: from ( i as u64 ) ;
446+ iter = & iter + 1 ;
457447 if !target_total. eq ( & ( * BASEPOINT_G1 * try_num) ) {
458448 continue ;
459449 }
@@ -475,6 +465,11 @@ pub fn decrypt_unlisted_candidate_ballot(
475465 break ;
476466 }
477467 }
468+ wedpr_println ! (
469+ "** decrypt_unlisted_candidate_ballot iter: {:?}, result: {:?}" ,
470+ iter,
471+ decrypted_unlisted_candidate_ballot_result
472+ ) ;
478473 Ok ( true )
479474}
480475
@@ -485,12 +480,16 @@ pub fn finalize_vote_result_unlisted(
485480 max_vote_limit : i64 ,
486481 max_candidate_number : i64 ,
487482) -> Result < VoteResultStorage , WedprError > {
483+ let start_t = Instant :: now ( ) ;
484+ let mut start = Instant :: now ( ) ;
488485 let mut vote_result = finalize_vote_result (
489486 poll_parameters,
490487 vote_sum,
491488 aggregated_decrypted_result,
492489 max_vote_limit,
493490 ) ?;
491+ let finalize_vote_result_duration = start. elapsed ( ) ;
492+ start = Instant :: now ( ) ;
494493 // finalize the vote result for the unlisted-candidates
495494 let mut aggregated_unlisted_candidate_ballot_result = BTreeMap :: new ( ) ;
496495 for mut unlisted_candidate in
@@ -514,5 +513,16 @@ pub fn finalize_vote_result_unlisted(
514513 . mut_unlisted_result ( )
515514 . push ( unlisted_candidate_ballot_result) ;
516515 }
516+ let decrypt_unlisted_candidate_ballot_duration = start. elapsed ( ) ;
517+ let total_time_cost = start_t. elapsed ( ) ;
518+ wedpr_println ! (
519+ "** Time elapsed: finalize_vote_result_duration: {:?}, \
520+ decrypt_unlisted_candidate_ballot_duration: {:?}, total time cost: \
521+ {:?}, ### {:?}",
522+ finalize_vote_result_duration,
523+ decrypt_unlisted_candidate_ballot_duration,
524+ total_time_cost,
525+ vote_result
526+ ) ;
517527 Ok ( vote_result)
518528}
0 commit comments