diff --git a/crypto-primitives/src/merkle_tree/mod.rs b/crypto-primitives/src/merkle_tree/mod.rs index 236826e..50e6f60 100644 --- a/crypto-primitives/src/merkle_tree/mod.rs +++ b/crypto-primitives/src/merkle_tree/mod.rs @@ -258,12 +258,6 @@ impl core::fmt::Display for Error { impl algebra_core::Error for Error {} -/// Returns the log2 value of the given number. -#[inline] -fn log2(number: usize) -> usize { - algebra_core::log2(number) as usize -} - /// Returns the height of the tree, given the size of the tree. #[inline] fn tree_height(tree_size: usize) -> usize { @@ -271,7 +265,7 @@ fn tree_height(tree_size: usize) -> usize { return 1; } - log2(tree_size) + algebra_core::log2(tree_size) as usize } /// Returns true iff the index represents the root. diff --git a/r1cs-std/src/bits/boolean.rs b/r1cs-std/src/bits/boolean.rs index 9ab5ccb..46ec3b0 100644 --- a/r1cs-std/src/bits/boolean.rs +++ b/r1cs-std/src/bits/boolean.rs @@ -591,7 +591,7 @@ impl ToBytesGadget for Boolean { fn to_bytes(&self) -> Result>, SynthesisError> { let mut bits = vec![self.clone()]; bits.extend(vec![Boolean::constant(false); 7]); - let value = self.value().map(|val| val as u8).ok(); + let value = self.value().map(u8::from).ok(); let byte = UInt8 { bits, value }; Ok(vec![byte]) } diff --git a/r1cs-std/src/bits/uint.rs b/r1cs-std/src/bits/uint.rs index 1a3d027..e4dba08 100644 --- a/r1cs-std/src/bits/uint.rs +++ b/r1cs-std/src/bits/uint.rs @@ -3,6 +3,7 @@ macro_rules! make_uint { pub mod $mod_name { use algebra::{Field, FpParameters, PrimeField}; use core::borrow::Borrow; + use core::convert::TryFrom; use r1cs_core::{ lc, ConstraintSystemRef, LinearCombination, Namespace, SynthesisError, Variable, @@ -119,7 +120,9 @@ macro_rules! make_uint { $name { bits: new_bits, - value: self.value.map(|v| v.rotate_right(by as u32)), + value: self + .value + .map(|v| v.rotate_right(u32::try_from(by).unwrap())), } } diff --git a/r1cs-std/src/fields/fp/mod.rs b/r1cs-std/src/fields/fp/mod.rs index 56f2edb..356d499 100644 --- a/r1cs-std/src/fields/fp/mod.rs +++ b/r1cs-std/src/fields/fp/mod.rs @@ -476,8 +476,8 @@ impl TwoBitLookupGadget for AllocatedFp { debug_assert_eq!(c.len(), 4); if let Some(cs) = b.cs() { let result = Self::new_witness(cs.clone(), || { - let lsb = b[0].value()? as usize; - let msb = b[1].value()? as usize; + let lsb = usize::from(b[0].value()?); + let msb = usize::from(b[1].value()?); let index = lsb + (msb << 1); Ok(c[index]) })?; @@ -509,8 +509,8 @@ impl ThreeBitCondNegLookupGadget for AllocatedFp { if let Some(cs) = b.cs() { let result = Self::new_witness(cs.clone(), || { - let lsb = b[0].value()? as usize; - let msb = b[1].value()? as usize; + let lsb = usize::from(b[0].value()?); + let msb = usize::from(b[1].value()?); let index = lsb + (msb << 1); let intermediate = c[index]; @@ -893,8 +893,8 @@ impl TwoBitLookupGadget for FpVar { if b.cs().is_some() { AllocatedFp::two_bit_lookup(b, c).map(Self::Var) } else { - let lsb = b[0].value()? as usize; - let msb = b[1].value()? as usize; + let lsb = usize::from(b[0].value()?); + let msb = usize::from(b[1].value()?); let index = lsb + (msb << 1); Ok(Self::Constant(c[index])) } @@ -916,8 +916,8 @@ impl ThreeBitCondNegLookupGadget for FpVar { if b.cs().or(b0b1.cs()).is_some() { AllocatedFp::three_bit_cond_neg_lookup(b, b0b1, c).map(Self::Var) } else { - let lsb = b[0].value()? as usize; - let msb = b[1].value()? as usize; + let lsb = usize::from(b[0].value()?); + let msb = usize::from(b[1].value()?); let index = lsb + (msb << 1); let intermediate = c[index];