Skip to content

Commit

Permalink
debug for testcases
Browse files Browse the repository at this point in the history
  • Loading branch information
rw0x0 committed Jan 22, 2025
1 parent da60df6 commit a15e9ac
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 19 deletions.
2 changes: 1 addition & 1 deletion iris-mpc-gpu/tests/bitinject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ mod bitinject_test {
let mut result = Vec::with_capacity(n_devices * INPUTS_PER_GPU_SIZE);
for (mut a, b, c) in izip!(a, b, c) {
for (a, b, c) in izip!(a.iter_mut(), b, c) {
*a += b + c;
*a = a.wrapping_add(b).wrapping_add(c);
}
result.extend(a);
}
Expand Down
9 changes: 6 additions & 3 deletions iris-mpc-gpu/tests/bucket_threshold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ mod bucket_threshold_test {
let mut x = rng.gen_range::<u16, _>(0..=IrisCodeArray::IRIS_CODE_SIZE as u16);
let neg = rng.gen::<bool>();
if neg {
x = u16::MAX - x + 1;
x = (u16::MAX - x).wrapping_add(1);
}
x
})
Expand All @@ -48,7 +48,7 @@ mod bucket_threshold_test {
fn rep_share<R: Rng>(value: u16, rng: &mut R) -> (u16, u16, u16) {
let a = rng.gen();
let b = rng.gen();
let c = value - a - b;
let c = value.wrapping_sub(a).wrapping_sub(b);

(a, b, c)
}
Expand Down Expand Up @@ -110,7 +110,10 @@ mod bucket_threshold_test {
let mod_ = 1u64 << (16 + B_BITS);
let mut res = Vec::with_capacity(code_input.len());
for (c, m) in code_input.into_iter().zip(mask_input) {
let r = ((m as u64) * A - ((c as u64) << B_BITS) - 1) % mod_;
let r = (((m as u64) * A)
.wrapping_sub((c as u64) << B_BITS)
.wrapping_sub(1))
% mod_;
let msb = r >> (B_BITS + 16 - 1) & 1 == 1;
res.push(msb)
}
Expand Down
9 changes: 6 additions & 3 deletions iris-mpc-gpu/tests/buckets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ mod buckets_test {
let mut x = rng.gen_range::<u16, _>(0..=IrisCodeArray::IRIS_CODE_SIZE as u16);
let neg = rng.gen::<bool>();
if neg {
x = u16::MAX - x + 1;
x = (u16::MAX - x).wrapping_add(1);
}
x
})
Expand All @@ -49,7 +49,7 @@ mod buckets_test {
fn rep_share<R: Rng>(value: u16, rng: &mut R) -> (u16, u16, u16) {
let a = rng.gen();
let b = rng.gen();
let c = value - a - b;
let c = value.wrapping_sub(a).wrapping_sub(b);

(a, b, c)
}
Expand Down Expand Up @@ -101,7 +101,10 @@ mod buckets_test {

let mut count = 0;
for (c, m) in code_input.iter().cloned().zip(mask_input.iter().cloned()) {
let r = ((m as u64) * a - ((c as u64) << B_BITS) - 1) % mod_;
let r = (((m as u64) * a)
.wrapping_sub((c as u64) << B_BITS)
.wrapping_sub(1))
% mod_;
let msb = r >> (B_BITS + 16 - 1) & 1 == 1;
count += msb as u32;
}
Expand Down
4 changes: 2 additions & 2 deletions iris-mpc-gpu/tests/extract_msb_mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ mod extract_msb_mod_test {
let mut x = rng.gen_range::<u16, _>(0..=IrisCodeArray::IRIS_CODE_SIZE as u16);
let neg = rng.gen::<bool>();
if neg {
x = u16::MAX - x + 1;
x = (u16::MAX - x).wrapping_add(1);
}
x
})
Expand All @@ -48,7 +48,7 @@ mod extract_msb_mod_test {
fn rep_share<R: Rng>(value: u16, rng: &mut R) -> (u16, u16, u16) {
let a = rng.gen();
let b = rng.gen();
let c = value - a - b;
let c = value.wrapping_sub(a).wrapping_sub(b);

(a, b, c)
}
Expand Down
2 changes: 1 addition & 1 deletion iris-mpc-gpu/tests/lift.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ mod lift_test {
fn rep_share<R: Rng>(value: u16, rng: &mut R) -> (u16, u16, u16) {
let a = rng.gen();
let b = rng.gen();
let c = value - a - b;
let c= value.wrapping_sub(a).wrapping_sub(b);

(a, b, c)
}
Expand Down
9 changes: 6 additions & 3 deletions iris-mpc-gpu/tests/one_bucket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ mod one_bucket_test {
let mut x = rng.gen_range::<u16, _>(0..=IrisCodeArray::IRIS_CODE_SIZE as u16);
let neg = rng.gen::<bool>();
if neg {
x = u16::MAX - x + 1;
x = (u16::MAX - x).wrapping_add(1);
}
x
})
Expand All @@ -47,7 +47,7 @@ mod one_bucket_test {
fn rep_share<R: Rng>(value: u16, rng: &mut R) -> (u16, u16, u16) {
let a = rng.gen();
let b = rng.gen();
let c = value - a - b;
let c = value.wrapping_sub(a).wrapping_sub(b);

(a, b, c)
}
Expand Down Expand Up @@ -94,7 +94,10 @@ mod one_bucket_test {
let mod_ = 1u64 << (16 + B_BITS);
let mut count = 0;
for (c, m) in code_input.into_iter().zip(mask_input) {
let r = ((m as u64) * A - ((c as u64) << B_BITS) - 1) % mod_;
let r = (((m as u64) * A)
.wrapping_sub((c as u64) << B_BITS)
.wrapping_sub(1))
% mod_;
let msb = r >> (B_BITS + 16 - 1) & 1 == 1;
count += msb as u32;
}
Expand Down
9 changes: 6 additions & 3 deletions iris-mpc-gpu/tests/threshold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ mod threshold_test {
let mut x = rng.gen_range::<u16, _>(0..=IrisCodeArray::IRIS_CODE_SIZE as u16);
let neg = rng.gen::<bool>();
if neg {
x = u16::MAX - x + 1;
x = (u16::MAX - x).wrapping_add(1);
}
x
})
Expand All @@ -48,7 +48,7 @@ mod threshold_test {
fn rep_share<R: Rng>(value: u16, rng: &mut R) -> (u16, u16, u16) {
let a = rng.gen();
let b = rng.gen();
let c = value - a - b;
let c = value.wrapping_sub(a).wrapping_sub(b);

(a, b, c)
}
Expand Down Expand Up @@ -110,7 +110,10 @@ mod threshold_test {
let mod_ = 1u64 << (16 + B_BITS);
let mut res = Vec::with_capacity(code_input.len());
for (c, m) in code_input.into_iter().zip(mask_input) {
let r = ((m as u64) * A - ((c as u64) << B_BITS) - 1) % mod_;
let r = (((m as u64) * A)
.wrapping_sub((c as u64) << B_BITS)
.wrapping_sub(1))
% mod_;
let msb = r >> (B_BITS + 16 - 1) & 1 == 1;
res.push(msb)
}
Expand Down
9 changes: 6 additions & 3 deletions iris-mpc-gpu/tests/threshold_and_or_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ mod test_threshold_and_or_tree_test {
let mut x = rng.gen_range::<u16, _>(0..=IrisCodeArray::IRIS_CODE_SIZE as u16);
let neg = rng.gen::<bool>();
if neg {
x = u16::MAX - x + 1;
x = (u16::MAX - x).wrapping_add(1);
}
x
})
Expand All @@ -46,7 +46,7 @@ mod test_threshold_and_or_tree_test {
fn rep_share<R: Rng>(value: u16, rng: &mut R) -> (u16, u16, u16) {
let a = rng.gen();
let b = rng.gen();
let c = value - a - b;
let c = value.wrapping_sub(a).wrapping_sub(b);

(a, b, c)
}
Expand Down Expand Up @@ -93,7 +93,10 @@ mod test_threshold_and_or_tree_test {
let mod_ = 1u64 << (16 + B_BITS);
let mut res = false;
for (c, m) in code_input.into_iter().zip(mask_input) {
let r = ((m as u64) * A - ((c as u64) << B_BITS) - 1) % mod_;
let r = (((m as u64) * A)
.wrapping_sub((c as u64) << B_BITS)
.wrapping_sub(1))
% mod_;
let msb = r >> (B_BITS + 16 - 1) & 1 == 1;
res |= msb;
}
Expand Down

0 comments on commit a15e9ac

Please sign in to comment.