Expand description

A proof is a data structure that proves that a given element is in the accumulator. It is used to validate a transaction. A proof is composed of a list of hashes and a list of integers. The hashes are the hashes need to calculate the root hash for validation. The integers are the position of the element in the accumulator.

Example

use std::str::FromStr;

use bitcoin_hashes::sha256;
use bitcoin_hashes::Hash;
use bitcoin_hashes::HashEngine;
use rustreexo::accumulator::node_hash::NodeHash;
use rustreexo::accumulator::proof::Proof;
use rustreexo::accumulator::stump::Stump;
let s = Stump::new();
// Creates a tree with those values as leaves
let test_values: Vec<u8> = vec![0, 1, 2, 3, 4, 5, 6, 7];
// Targets are the nodes we intend to prove
let targets = vec![0];

// The hashes used to prove an element.
let mut proof_hashes = Vec::new();

proof_hashes.push(
    NodeHash::from_str("4bf5122f344554c53bde2ebb8cd2b7e3d1600ad631c385a5d7cce23c7785459a")
        .unwrap(),
);
proof_hashes.push(
    NodeHash::from_str("9576f4ade6e9bc3a6458b506ce3e4e890df29cb14cb5d3d887672aef55647a2b")
        .unwrap(),
);
proof_hashes.push(
    NodeHash::from_str("29590a14c1b09384b94a2c0e94bf821ca75b62eacebc47893397ca88e3bbcbd7")
        .unwrap(),
);

// Hashes of the leaves UTXOs we'll add to the accumulator
let mut hashes = Vec::new();
for i in test_values {
    let mut engine = sha256::Hash::engine();
    engine.input(&[i]);
    hashes.push(sha256::Hash::from_engine(engine).into())
}
// Add the UTXOs to the accumulator
let s = s.modify(&hashes, &vec![], &Proof::default()).unwrap().0;
// Create a proof for the targets
let p = Proof::new(targets, proof_hashes);
// Verify the proof
assert!(s.verify(&p, &vec![hashes[0]]).expect("This proof is valid"));

Structs

  • A proof is a collection of hashes and positions. Each target position points to a leaf to be proven. Hashes are all hashes that can’t be calculated from the data itself. Proofs are generated elsewhere.