Skip to content

Commit

Permalink
fix: log(0) returns 0 (#1001)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhenfeizhang authored Oct 13, 2023
1 parent 43817d3 commit 7a42d3c
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion zkevm-circuits/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,9 @@ pub trait SubCircuitConfig<F: Field> {
}

/// Ceiling of log_2(n)
/// `log2_ceil(0)` returns 0.
pub fn log2_ceil(n: usize) -> u32 {
u32::BITS - (n as u32).leading_zeros() - (n & (n - 1) == 0) as u32
(u32::BITS - (n as u32).leading_zeros()) - u32::from(n.is_power_of_two())
}

pub(crate) fn keccak(msg: &[u8]) -> Word {
Expand Down

0 comments on commit 7a42d3c

Please sign in to comment.