Skip to content

Commit

Permalink
First crack at the verification function
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikhail Zabaluev committed Jan 28, 2021
1 parent b214f8b commit 7434338
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions chain-vote/src/lib.rs
Expand Up @@ -298,6 +298,24 @@ pub fn tally_result(
Ok(DecryptedTally { votes })
}

/// Verifies that the decrypted tally was correctly obtained from the given
/// `TallyState` and `TallyDecryptShare` parts.
///
/// This can be used for quick online validation for the tallying
/// performed offline.
pub fn verify(
tally_state: &TallyState,
decrypt_shares: &[TallyDecryptShare],
result: &DecryptedTally,
) -> bool {
let r_results = result_vector(tally_state, decrypt_shares);
let gen = gang::GroupElement::generator();
for (i, &w) in result.votes.iter().enumerate() {
if &gen * gang::Scalar::from_u64(w) != r_results[i] {
return false;
}
}
true
}

#[cfg(test)]
Expand Down

0 comments on commit 7434338

Please sign in to comment.