Function tallytree::proof::votecount::create_proof_of_vote_count[][src]

pub fn create_proof_of_vote_count(
    node: &NodeRef,
    v: &Validation
) -> Result<Proof, String>
Expand description

Create a proof for vote count given a root node. Using this proof, it is possible to derive and verify the voter count.

Hash and tally of the nodes in (parentheses) are included in the proof.

  • V3 and Ø allow for generating the hash of C.
  • B and the derived C allow generating the hash of A.
  • A is the root node passed into the function.
           A
         /  \
        (B)  C
       / \   | \
      D   E  F  (Ø)
      |   |  |
      V1  V2 (V3)

Example:

use tallytree::generate::generate_tree;
use tallytree::hash::hash_node_ref;
use tallytree::proof::{create_proof_of_vote_count, verify_proof_of_vote_count};
use tallytree::Validation;

let root = generate_tree(vec![([0xaa; 32], vec![1, 0])], true).unwrap();
let proof = create_proof_of_vote_count(&root, &Validation::Strict).unwrap();
let (vote_count, root_hash, tally) = verify_proof_of_vote_count(&proof).unwrap();
assert_eq!(vote_count, 1);
assert_eq!(vec![1, 0], tally);
assert_eq!(
   hash_node_ref(&root, &Validation::Strict).unwrap(),
   Some((root_hash, Some(tally)))
);