-
Notifications
You must be signed in to change notification settings - Fork 78
add SmtForest::insert_path() #650
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: next
Are you sure you want to change the base?
Changes from 3 commits
c7f74be
9c97ad6
b03f7c2
074a2fd
8118745
2d7b052
d7b2136
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,10 @@ use itertools::Itertools; | |
| use super::{EmptySubtreeRoots, MerkleError, SmtForest, Word}; | ||
| use crate::{ | ||
| Felt, ONE, WORD_SIZE, ZERO, | ||
| merkle::{int_to_node, smt::SMT_DEPTH}, | ||
| merkle::{ | ||
| int_to_node, | ||
| smt::{SMT_DEPTH, Smt}, | ||
| }, | ||
| }; | ||
|
|
||
| // TESTS | ||
|
|
@@ -89,6 +92,28 @@ fn test_insert_multiple_values() -> Result<(), MerkleError> { | |
| Ok(()) | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_insert_path() -> Result<(), MerkleError> { | ||
| let mut smt = Smt::new(); | ||
| let key = Word::new([ZERO, ZERO, ZERO, ONE]); | ||
| let value = Word::new([ONE; WORD_SIZE]); | ||
| smt.insert(key, value)?; | ||
| let proof = smt.open(&key); | ||
|
||
|
|
||
| let mut forest = SmtForest::new(); | ||
| let root = forest.insert_path(proof); | ||
| assert_eq!(root, smt.root()); | ||
|
|
||
| let stored_proof = forest.open(root, key)?; | ||
| assert!(stored_proof.verify_membership(&key, &value, &root)); | ||
|
|
||
| forest.pop_smts(vec![root]); | ||
| assert!(forest.roots.is_empty()); | ||
| assert!(forest.leaves.is_empty()); | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_batch_insert() -> Result<(), MerkleError> { | ||
| let forest = SmtForest::new(); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.