Skip to content

Commit

Permalink
Fix log2 precision loss (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
nulltea authored Mar 11, 2024
1 parent 988fc08 commit f9d3e5f
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lightclient-circuits/src/ssz_merkle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,12 @@ pub fn ssz_merkleize_chunks<F: Field, CircuitBuilder: CommonCircuitBuilder<F>>(
MAX_INPUT_LEAFS_NOT_POW2
);

let len_even = chunks.len() + chunks.len() % 2;
let height = (len_even as f64).log2().ceil() as usize;
let height = if chunks.len() == 1 {
1
} else {
chunks.len().next_power_of_two().ilog2() as usize
};

for depth in 0..height {
// Pad to even length using 32 zero bytes assigned as constants.
let len_even = chunks.len() + chunks.len() % 2;
Expand Down

0 comments on commit f9d3e5f

Please sign in to comment.