Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion benches/proof_benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ fn proof_verification(c: &mut Criterion) {
let accumulator_size = 100;
let hashes = generate_test_hashes(accumulator_size, 42);
let stump = Stump::new();
let (stump, _) = stump.modify(&hashes, &[], &Proof::default()).unwrap();
let stump = stump.modify(&hashes, &[], &Proof::default()).unwrap();

for target_count in [1, 10].iter() {
let del_hashes = hashes[..*target_count].to_vec();
Expand Down
2 changes: 1 addition & 1 deletion benches/stump_benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ fn stump_verify(c: &mut Criterion) {
let test_size = 1000;
let hashes = generate_test_hashes(test_size, 42);
let stump = Stump::new();
let (stump, _) = stump.modify(&hashes, &[], &Proof::default()).unwrap();
let stump = stump.modify(&hashes, &[], &Proof::default()).unwrap();

for proof_size in [1, 10, 100].iter() {
let del_hashes = hashes[..*proof_size].to_vec();
Expand Down
3 changes: 1 addition & 2 deletions examples/full-accumulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ fn main() {
// Verify the proof. Notice how we use the del_hashes returned by `prove` here.
let s = Stump::new()
.modify(&elements, &[], &Proof::default())
.unwrap()
.0;
.unwrap();
assert_eq!(s.verify(&proof, &[elements[0]]), Ok(true));
// Now we want to update the MemForest, by removing the first utxo, and adding a new one.
// This would be in case we received a new block with a transaction spending the first utxo,
Expand Down
20 changes: 16 additions & 4 deletions examples/proof-update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,20 @@ use rustreexo::accumulator::stump::Stump;

fn main() {
let s = Stump::new();

// Get the hashes of the UTXOs we want to insert
let utxos = get_utxo_hashes1();
// Add the UTXOs to the accumulator. update_data is the data we need to update the proof
// after the accumulator is updated.
let (s, update_data) = s.modify(&utxos, &[], &Proof::default()).unwrap();

// Compute the update data for this block. Notice that we called this before updating the
// accumulator, as the accumulator state is required to compute this data.
let update_data = s.get_update_data(&utxos, &[], &Proof::default()).unwrap();

// Now, update the accumulator with these UTXOs, no STXOs are being spent in this example.
let s = s.modify(&utxos, &[], &Proof::default()).unwrap();

// Create an empty proof, we'll update it to hold our UTXOs
let p = Proof::default();

// Update the proof with the UTXOs we added to the accumulator. This proof was initially empty,
// but we can instruct this function to remember some UTXOs, given their positions in the list of
// UTXOs we added to the accumulator. In this example, we ask it to cache 0 and 1.
Expand All @@ -35,21 +42,26 @@ fn main() {
let (p, cached_hashes) = p
.update(vec![], utxos.clone(), vec![], vec![0, 1], update_data)
.unwrap();

// This should be a valid proof over 0 and 1.
assert_eq!(p.n_targets(), 2);
assert_eq!(s.verify(&p, &cached_hashes), Ok(true));

// Get a subset of the proof, for the first UTXO only
let p1 = p.get_proof_subset(&cached_hashes, &[0], s.leaves).unwrap();

// Should still be valid
assert_eq!(s.verify(&p1, &cached_hashes), Ok(true));

// Assume we have a block that (beyond coinbase) spends our UTXO `0` and creates 7 new UTXOs
// We'll remove `0` as it got spent, and add 1..7 to our cache.
let new_utxos = get_utxo_hashes2();

// First, update the accumulator
let (stump, update_data) = s.modify(&new_utxos, &[utxos[0]], &p1).unwrap();
let stump = s.modify(&new_utxos, &[utxos[0]], &p1).unwrap();

// and the proof
let update_data = s.get_update_data(&utxos, &[], &Proof::default()).unwrap();
let (p2, cached_hashes) = p
.update(
cached_hashes,
Expand Down
7 changes: 2 additions & 5 deletions examples/simple-stump-update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ fn main() {
// Create a new Stump, and add the utxos to it. Notice how we don't use the full return here,
// but only the Stump. To understand what is the second return value, see the documentation
// for `Stump::modify`, or the proof-update example.
let s = Stump::new()
.modify(&utxos, &[], &Proof::default())
.unwrap()
.0;
let s = Stump::new().modify(&utxos, &[], &Proof::default()).unwrap();
// Create a proof that the first utxo is in the Stump.
let proof = Proof::new(vec![0], vec![utxos[1]]);
assert_eq!(s.verify(&proof, &[utxos[0]]), Ok(true));
Expand All @@ -42,7 +39,7 @@ fn main() {
"d3bd63d53c5a70050a28612a2f4b2019f40951a653ae70736d93745efb1124fa",
)
.unwrap();
let s = s.modify(&[new_utxo], &[utxos[0]], &proof).unwrap().0;
let s = s.modify(&[new_utxo], &[utxos[0]], &proof).unwrap();
// Now we can verify that the new utxo is in the Stump, and the old one is not.
let new_proof = Proof::new(vec![2], vec![new_utxo]);
assert_eq!(s.verify(&new_proof, &[new_utxo]), Ok(true));
Expand Down
Loading
Loading