Skip to content

Commit c04339b

Browse files
committed
Use next_power_of_two function, and address some reviewer comments
1 parent aaa2a75 commit c04339b

1 file changed

Lines changed: 4 additions & 13 deletions

File tree

crates/tlog_tiles/src/tlog.rs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ pub fn inclusion_proof<R: HashReader>(n: u64, leaf_index: u64, r: &R) -> Result<
391391
subtree_inclusion_proof(&Subtree::new(0, n)?, leaf_index, r)
392392
}
393393

394-
/// Returns the subproof that the subtree `n` contains the record with index
394+
/// Returns the proof that the subtree `n` contains the record with index
395395
/// `leaf_index`.
396396
///
397397
/// # Errors
@@ -777,17 +777,8 @@ impl Subtree {
777777
return Err(TlogError::ConditionNotMet("`lo < hi`".into()));
778778
}
779779
// `s` is the smallest power of 2 that is greater than or equal
780-
// to `lo - hi`.
781-
let s = {
782-
let n = hi - lo;
783-
let l = n.ilog2();
784-
// If n is not already a power of two, round up.
785-
if n > 1 << l {
786-
1 << (l + 1)
787-
} else {
788-
1 << l
789-
}
790-
};
780+
// to `hi - lo`.
781+
let s = (hi - lo).next_power_of_two();
791782
if lo & (s - 1) != 0 {
792783
return Err(TlogError::ConditionNotMet(
793784
"`lo` must be a multiple of the smallest power of two ≥ `hi - lo`".into(),
@@ -988,7 +979,7 @@ impl Subtree {
988979
// `m` is split across children. Fully include the left, recurse
989980
// on right child of `m` with `known` set to false as the right
990981
// child of `m` was not one of the inputs to the algorithm.
991-
assert!(m.lo == self.lo, "bad math in subproof walk");
982+
assert!(m.lo == self.lo, "bad math in walk_subproof");
992983
let m_right = m.children().1;
993984
(f(&left), right.walk_subproof(&m_right, false, f, strategy)?)
994985
};

0 commit comments

Comments
 (0)