Skip to content

Commit

Permalink
Fix test_uint32_shr failing on debug builds. zcash#76
Browse files Browse the repository at this point in the history
  • Loading branch information
defuse committed Feb 19, 2019
1 parent 49017b4 commit df2faf6
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/circuit/uint32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ impl UInt32 {
}

pub fn shr(&self, by: usize) -> Self {
let by = by % 32;
assert!(by < 32);

let fill = Boolean::constant(false);

Expand Down Expand Up @@ -656,7 +656,7 @@ mod test {
let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]);

for _ in 0..50 {
for i in 0..60 {
for i in 0..32 {
let num = rng.gen();
let a = UInt32::constant(num).shr(i);
let b = UInt32::constant(num >> i);
Expand All @@ -671,6 +671,19 @@ mod test {
}
}

#[test]
fn test_uint32_shr_overflow() {
let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]);

for _ in 0..50 {
for i in 32..60 {
let num = rng.gen();
let result = std::panic::catch_unwind(|| UInt32::constant(num).shr(i));
assert!(result.is_err());
}
}
}

#[test]
fn test_uint32_sha256_maj() {
let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0653]);
Expand Down

0 comments on commit df2faf6

Please sign in to comment.