Skip to content

Commit

Permalink
merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
TAdev0 committed Oct 7, 2024
1 parent 1178b8e commit 285fce3
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 4 deletions.
34 changes: 32 additions & 2 deletions packages/utreexo/src/stump/accumulator.cairo
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::stump::state::UtreexoStumpState;
use crate::stump::proof::UtreexoBatchProof;
use crate::stump::proof::{UtreexoBatchProof, UtreexoBatchProofTrait};

#[generate_trait]
pub impl StumpUtreexoAccumulatorImpl of StumpUtreexoAccumulator {
Expand All @@ -13,7 +13,37 @@ pub impl StumpUtreexoAccumulatorImpl of StumpUtreexoAccumulator {
fn verify(
self: @UtreexoStumpState, proof: @UtreexoBatchProof, del_hashes: Span<felt252>
) -> Result<(), ByteArray> {
// TODO
if (*proof.targets).is_empty() {
return Result::Ok(());
};

let computed_roots: Span<felt252> = proof.compute_roots(del_hashes, *self.num_leaves)?;

let mut number_matched_roots: u32 = 0;

// Should we reverse *self.roots like in rustreexo to reduce the number of iteration?
for i in 0
..computed_roots
.len() {
for root in *self
.roots {
match root {
Option::Some(root) => {
if (computed_roots[i] == root) {
number_matched_roots += 1;
};
},
Option::None => {},
};
};
};

let computed_roots_len = computed_roots.len();

if (computed_roots_len != number_matched_roots && computed_roots_len != 0) {
return Result::Err("Proof verification failed");
}

Result::Ok(())
}

Expand Down
14 changes: 13 additions & 1 deletion packages/utreexo/src/stump/proof.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use core::fmt::{Display, Formatter, Error};
/// Compatible with https://github.com/utreexo/utreexo
#[derive(Drop, Copy)]
pub struct UtreexoBatchProof {
/// List of sibling nodes required to calculate the root.
/// List of sibling nodes required to calculate the roots.
pub proof: Span<felt252>,
/// Indices of leaves to be deleted (ordered starting from 0, left to right).
pub targets: Span<u64>,
Expand All @@ -27,3 +27,15 @@ impl UtreexoBatchProofDisplay of Display<UtreexoBatchProof> {
Result::Ok(())
}
}

#[generate_trait]
pub impl UtreexoBatchProofImpl of UtreexoBatchProofTrait {
/// Computes a set of roots given a proof and leaves hashes.
fn compute_roots(
self: @UtreexoBatchProof, outpoints_hashes: Span<felt252>, num_leaves: u64,
) -> Result<Span<felt252>, ByteArray> {
// TODO
Result::Ok(array![].span())
}
}

2 changes: 1 addition & 1 deletion packages/utreexo/src/vanilla/proof.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl UtreexoProofDisplay of Display<UtreexoProof> {

#[generate_trait]
pub impl UtreexoProofImpl of UtreexoProofTrait {
/// Computes the root given a a proof and leaf hash.
/// Computes the root given a proof and leaf hash.
///
/// Traverses the tree from leaf to root, hashing paired nodes.
/// Proof order is bottom-up. Returns the computed root.
Expand Down

0 comments on commit 285fce3

Please sign in to comment.