Skip to content

Commit

Permalink
feat: filter empty values in Smt::with_entries (#383)
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilippGackstatter authored Feb 18, 2025
1 parent 2ba30bf commit d0e9ead
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- Implemented parallel leaf hashing in `Smt::process_sorted_pairs_to_leaves` (#365).
- [BREAKING] Updated Winterfell dependency to v0.12 (#374).
- Added debug-only duplicate column check in `build_subtree` (#378).
- Filter out empty values in concurrent version of `Smt::with_entries` to fix a panic (#383).

## 0.13.3 (2025-02-18)

Expand Down
2 changes: 2 additions & 0 deletions src/merkle/smt/full/concurrent/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ impl Smt {
let mut seen_keys = BTreeSet::new();
let entries: Vec<_> = entries
.into_iter()
// Filter out key-value pairs whose value is empty.
.filter(|(_key, value)| *value != Self::EMPTY_VALUE)
.map(|(key, value)| {
if seen_keys.insert(key) {
Ok((key, value))
Expand Down
10 changes: 9 additions & 1 deletion src/merkle/smt/full/concurrent/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,15 @@ fn test_multithreaded_subtrees() {
#[test]
fn test_with_entries_concurrent() {
const PAIR_COUNT: u64 = COLS_PER_SUBTREE * 64;
let entries = generate_entries(PAIR_COUNT);
let mut entries = generate_entries(PAIR_COUNT);
let mut rng = rand::thread_rng();

// Set 10% of the entries to have empty words as their values.
for _ in 0..PAIR_COUNT / 10 {
let random_index = rng.gen_range(0..PAIR_COUNT);
entries[random_index as usize].1 = EMPTY_WORD;
}

let control = Smt::with_entries_sequential(entries.clone()).unwrap();
let smt = Smt::with_entries(entries.clone()).unwrap();
assert_eq!(smt.root(), control.root());
Expand Down

0 comments on commit d0e9ead

Please sign in to comment.