fix: subtree8-rand benchmark panics with debug assertions enabled (#377) (#378)

This commit is contained in:
Krushimir 2025-02-13 20:00:16 +01:00 committed by GitHub
parent 1e59686153
commit bbe11964b1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 14 additions and 0 deletions

View file

@ -5,6 +5,7 @@
- Added parallel implementation of `Smt::compute_mutations` with better performance (#365). - Added parallel implementation of `Smt::compute_mutations` with better performance (#365).
- Implemented parallel leaf hashing in `Smt::process_sorted_pairs_to_leaves` (#365). - Implemented parallel leaf hashing in `Smt::process_sorted_pairs_to_leaves` (#365).
- [BREAKING] Updated Winterfell dependency to v0.12 (#374). - [BREAKING] Updated Winterfell dependency to v0.12 (#374).
- Added debug-only duplicate column check in `build_subtree` (#378).
## 0.13.3 (2025-02-12) ## 0.13.3 (2025-02-12)

View file

@ -100,6 +100,7 @@ fn smt_subtree_random(c: &mut Criterion) {
}) })
.collect(); .collect();
leaves.sort(); leaves.sort();
leaves.dedup_by_key(|leaf| leaf.col);
leaves leaves
}, },
|leaves| { |leaves| {

View file

@ -478,6 +478,18 @@ fn build_subtree(
tree_depth: u8, tree_depth: u8,
bottom_depth: u8, bottom_depth: u8,
) -> (UnorderedMap<NodeIndex, InnerNode>, SubtreeLeaf) { ) -> (UnorderedMap<NodeIndex, InnerNode>, SubtreeLeaf) {
#[cfg(debug_assertions)]
{
// Ensure that all leaves have unique column indices within this subtree.
// In normal usage via public APIs, this should never happen because leaf
// construction enforces uniqueness. However, when testing or benchmarking
// `build_subtree()` in isolation, duplicate columns can appear if input
// constraints are not enforced.
let mut seen_cols = BTreeSet::new();
for leaf in &leaves {
assert!(seen_cols.insert(leaf.col), "Duplicate column found in subtree: {}", leaf.col);
}
}
debug_assert!(bottom_depth <= tree_depth); debug_assert!(bottom_depth <= tree_depth);
debug_assert!(Integer::is_multiple_of(&bottom_depth, &SUBTREE_DEPTH)); debug_assert!(Integer::is_multiple_of(&bottom_depth, &SUBTREE_DEPTH));
debug_assert!(leaves.len() <= usize::pow(2, SUBTREE_DEPTH as u32)); debug_assert!(leaves.len() <= usize::pow(2, SUBTREE_DEPTH as u32));