This commit is contained in:
Your Name
2025-04-20 19:16:03 -04:00
commit dfed917799
10 changed files with 665 additions and 0 deletions
+38
View File
@@ -0,0 +1,38 @@
#[cfg(test)]
mod tests {
use apet_ex1::{circuit::Circuit, scalar_to_bits::scalar_to_bits};
use curve25519_dalek::scalar::Scalar;
use num_bigint::BigUint;
use rand::rngs::OsRng;
#[test]
fn test_scalar_comparison_via_circuit() {
for _ in 0..100 {
let a = Scalar::random(&mut OsRng);
let b = Scalar::random(&mut OsRng);
// Convert to bit representation
let a_bits = scalar_to_bits(&a);
let b_bits = scalar_to_bits(&b);
// Combine A and B bits into one input vector
let mut input_bits = Vec::with_capacity(512);
input_bits.extend_from_slice(&a_bits);
input_bits.extend_from_slice(&b_bits);
// Build and evaluate the comparison circuit
let circuit = Circuit::compare_n_bit_numbers(input_bits, 256);
let circuit_result = circuit.eval();
// Compare expected result using BigUint
let a_int = BigUint::from_bytes_le(&a.to_bytes());
let b_int = BigUint::from_bytes_le(&b.to_bytes());
let expected = a_int > b_int;
assert_eq!(
circuit_result, expected,
"Mismatch: A = {:?}, B = {:?}, A > B = {}, but circuit says {}",
a_int, b_int, expected, circuit_result
);
}
}
}