Skip to content

Commit

Permalink
refactor(compute): clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
10d9e committed Oct 9, 2024
1 parent a127552 commit 0113411
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
8 changes: 4 additions & 4 deletions benchmark/benches/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,11 +289,11 @@ fn gateway_encrypted_multiplication() -> Result<(), Box<dyn ::std::error::Error>
let clear_a = 12345678910u128;
let clear_b = 1234;

let a = GarbledUint128::from_u128(clear_a);
let b = GarbledUint128::from_u128(clear_b);
let a: GarbledUint128 = clear_a.into();
let b: GarbledUint128 = clear_b.into();

let result = &a * &b;
assert_eq!(result.to_u128(), clear_a * clear_b);
let result: u128 = (&a * &b).into();
assert_eq!(result, clear_a * clear_b);
Ok(())
}

Expand Down
26 changes: 13 additions & 13 deletions compute/src/operations/arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ fn build_and_simulate_multiplication<const N: usize>(
let program = Circuit::new(gates, output_indices);

// Simulate the circuit
let result = lhs.simulate(&program, &lhs.bits, &rhs.bits).unwrap();
let result = simulate(&program, &lhs.bits, &rhs.bits).unwrap();

// Return the resulting GarbledUint<N>
GarbledUint::new(result)
Expand Down Expand Up @@ -459,29 +459,29 @@ mod tests {

#[test]
fn test_uint_mul() {
let a = GarbledUint::<4>::from_u8(3); // Binary 0011
let b = GarbledUint::<4>::from_u8(2); // Binary 0010
let a: GarbledUint8 = 3_u8.into(); // Binary 0011
let b: GarbledUint8 = 2_u8.into(); // Binary 0010

let result = a * b;
assert_eq!(result.to_u8(), 6); // 0011 * 0010 = 0110
let result: u8 = (a * b).into();
assert_eq!(result, 6); // 0011 * 0010 = 0110
}

#[test]
fn test_from_u8_mul() {
let a = GarbledUint8::from_u8(7); // Binary 0000 0111
let b = GarbledUint8::from_u8(5); // Binary 0000 0101
let a: GarbledUint8 = 7_u8.into(); // Binary 0000 0111
let b: GarbledUint8 = 5_u8.into(); // Binary 0000 0101

let result = a * b;
assert_eq!(result.to_u8(), 35); // Binary 0010 0011
let result: u8 = (a * b).into();
assert_eq!(result, 35); // Binary 0010 0011
}

#[test]
fn test_from_u16_mul() {
let a = GarbledUint16::from_u16(300); // Binary 0000 0001 0010 1100
let b = GarbledUint16::from_u16(7); // Binary 0000 0000 0000 0111
let a: GarbledUint16 = 300_u16.into(); // Binary 1010101010101011
let b: GarbledUint16 = 7_u16.into(); // Binary 0101010101010101

let result = a * b;
assert_eq!(result.to_u16(), 2100); // Binary 0000 1000 0010 0100
let result: u16 = (a * b).into();
assert_eq!(result, 300_u16 * 7_u16); // Expected result of multiplication between 1010101010101011 and 0101010101010101
}

#[test]
Expand Down

0 comments on commit 0113411

Please sign in to comment.