Function tallytree::proof::inclusion::create_inclusion_exclusion_proof[][src]

pub fn create_inclusion_exclusion_proof(
    root: &NodeRef,
    vote_reference: &VoteReference,
    v: &Validation
) -> Result<(InclusionProof, ExclusionProof), String>
Expand description

Create proof of a vote references’ existence or non-existance in a merkle tree.

Return either inclusion proof or exclusion proof.

Inclusion proof includes the hash of the nodes needed to calculate the merkle tree root hash from the votes position in the tree, including the vote itself.

Exclusion proof includes the hash of the nodes needed to calculate the merkle tree root hash from both neighboring nodes of where the vote would have been positioned in the tree.

           A
         /  \
        B    C
       / \   | \
      D   E  F  Ø
      |   |  |
      V1  V2 V4

In the above tree, the inclusion proof for vote V4 would be:

  • V4, Ø
  • B, None

The other nodes in the path, F, C and A, can be derived from the nodes provided.

In the above tree, the exclusion proof for non-existant vote V3 would be

  • V1, V2
  • None, C

… proving the existence of V2 and

  • V4, Ø
  • B, None

… proving the existence of V4. This is enough to prove that V3 does not exist in the tree.

Example:

use tallytree::generate::generate_tree;
use tallytree::proof::inclusion::create_inclusion_exclusion_proof;
use tallytree::Validation;

let tree = generate_tree(vec![
  ([0xaa; 32], vec![1, 0]),
  ([0xcc; 32], vec![1, 0]),
], true).unwrap();
let (inclusion, _) = create_inclusion_exclusion_proof(&tree, &[0xaa; 32], &Validation::Strict).unwrap();
let (_, exclusion) = create_inclusion_exclusion_proof(&tree, &[0xbb; 32], &Validation::Strict).unwrap();