feat: filter empty values in Smt::with_entries (#383)

This commit is contained in:
Philipp Gackstatter 2025-02-18 11:18:47 +01:00 committed by GitHub
parent 2ba30bf3bf
commit d0e9ead6f4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 12 additions and 1 deletions

View file

@ -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)

View file

@ -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))

View file

@ -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());