-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Calculate incremental note commitment trees (#2407)
* Make sapling::tree::NoteCommitmentTree incrementally updateable * Make orchard::tree::NoteCommitmentTree incrementally updateable * Apply suggestions from code review Co-authored-by: teor <teor@riseup.net> * Changed to incrementalmerkletree implementation; update MerkleCRH^Orchard * Improvements from review; organize file names (vectors.rs -> tree.rs) Co-authored-by: Conrado Gouvea <conrado@zfnd.org> Co-authored-by: teor <teor@riseup.net> Co-authored-by: Conrado P. L. Gouvea <conradoplg@gmail.com>
- Loading branch information
1 parent
12c60b5
commit 48cf527
Showing
10 changed files
with
797 additions
and
273 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
mod preallocate; | ||
mod prop; | ||
pub mod test_vectors; | ||
mod test_vectors; | ||
mod tree; |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use halo2::arithmetic::FieldExt; | ||
use halo2::pasta::pallas; | ||
|
||
use crate::orchard::tests::test_vectors; | ||
use crate::orchard::tree::*; | ||
|
||
#[test] | ||
fn empty_roots() { | ||
zebra_test::init(); | ||
|
||
for i in 0..EMPTY_ROOTS.len() { | ||
assert_eq!( | ||
EMPTY_ROOTS[i].to_bytes(), | ||
// The test vector is in reversed order. | ||
test_vectors::EMPTY_ROOTS[MERKLE_DEPTH - i] | ||
); | ||
} | ||
} | ||
|
||
#[test] | ||
fn incremental_roots() { | ||
zebra_test::init(); | ||
|
||
let mut leaves = vec![]; | ||
|
||
let mut incremental_tree = NoteCommitmentTree::default(); | ||
|
||
for (i, commitment_set) in test_vectors::COMMITMENTS.iter().enumerate() { | ||
for cm_x_bytes in commitment_set.iter() { | ||
let cm_x = pallas::Base::from_bytes(&cm_x_bytes).unwrap(); | ||
|
||
leaves.push(cm_x); | ||
|
||
let _ = incremental_tree.append(cm_x); | ||
} | ||
|
||
assert_eq!( | ||
hex::encode(incremental_tree.hash()), | ||
hex::encode(test_vectors::ROOTS[i].anchor) | ||
); | ||
|
||
assert_eq!( | ||
hex::encode((NoteCommitmentTree::from(leaves.clone())).hash()), | ||
hex::encode(test_vectors::ROOTS[i].anchor) | ||
); | ||
} | ||
} |
Oops, something went wrong.