Skip to content
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

Filter empty values in Smt::with_entries #383

Merged
merged 3 commits into from
Feb 18, 2025
Merged
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
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
Loading