Skip to content

Commit

Permalink
Format
Browse files Browse the repository at this point in the history
  • Loading branch information
Pratyush committed Dec 28, 2023
1 parent fd16996 commit b257da7
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 27 deletions.
4 changes: 2 additions & 2 deletions src/uint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ mod convert;
mod eq;
mod not;
mod or;
mod shl;
mod shr;
mod rotate;
mod select;
mod shl;
mod shr;
mod xor;

#[doc(hidden)]
Expand Down
5 changes: 2 additions & 3 deletions src/uint/prim_uint.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use core::usize;
use core::ops::{Shl, ShlAssign, Shr, ShrAssign};
use core::usize;

#[doc(hidden)]
// Adapted from <https://github.com/rust-num/num-traits/pull/224>
Expand Down Expand Up @@ -164,7 +164,6 @@ pub trait NumBytes:
#[doc(hidden)]
impl<const N: usize> NumBytes for [u8; N] {}


mod _private {
pub trait Sealed {}

Expand All @@ -173,4 +172,4 @@ mod _private {
impl Sealed for u32 {}
impl Sealed for u64 {}
impl Sealed for u128 {}
}
}
14 changes: 4 additions & 10 deletions src/uint/shl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,9 @@ impl<const N: usize, T: PrimUInt, F: PrimeField> UInt<N, T, F> {
for (a, b) in bits[other as usize..].iter_mut().zip(&self.bits) {
*a = b.clone();
}

let value = self.value.and_then(|a| Some(a << other));
Ok(Self {
bits,
value,
})
Ok(Self { bits, value })
} else {
panic!("attempt to shift left with overflow")
}
Expand Down Expand Up @@ -120,11 +117,8 @@ mod tests {
} else {
AllocationMode::Witness
};
let expected = UInt::<N, T, F>::new_variable(
cs.clone(),
|| Ok(a.value()? << b),
expected_mode,
)?;
let expected =
UInt::<N, T, F>::new_variable(cs.clone(), || Ok(a.value()? << b), expected_mode)?;
assert_eq!(expected.value(), computed.value());
expected.enforce_equal(&computed)?;
if !a.is_constant() {
Expand Down
14 changes: 4 additions & 10 deletions src/uint/shr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,9 @@ impl<const N: usize, T: PrimUInt, F: PrimeField> UInt<N, T, F> {
for (a, b) in bits.iter_mut().zip(&self.bits[other as usize..]) {
*a = b.clone();
}

let value = self.value.and_then(|a| Some(a >> other));
Ok(Self {
bits,
value,
})
Ok(Self { bits, value })
} else {
panic!("attempt to shift right with overflow")
}
Expand Down Expand Up @@ -120,11 +117,8 @@ mod tests {
} else {
AllocationMode::Witness
};
let expected = UInt::<N, T, F>::new_variable(
cs.clone(),
|| Ok(a.value()? >> b),
expected_mode,
)?;
let expected =
UInt::<N, T, F>::new_variable(cs.clone(), || Ok(a.value()? >> b), expected_mode)?;
assert_eq!(expected.value(), computed.value());
expected.enforce_equal(&computed)?;
if !a.is_constant() {
Expand Down
2 changes: 0 additions & 2 deletions src/uint/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,6 @@ where
Ok(())
}



pub(crate) fn run_unary_random<const ITERATIONS: usize, const N: usize, T, F>(
test: impl Fn(UInt<N, T, F>) -> Result<(), SynthesisError> + Copy,
) -> Result<(), SynthesisError>
Expand Down

0 comments on commit b257da7

Please sign in to comment.