Make function signatures conform to assignment
This commit is contained in:
+5
-4
@@ -3,14 +3,15 @@ use crate::{gate::Gate, gate_type::GateType};
|
|||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Circuit {
|
pub struct Circuit {
|
||||||
pub gates: Vec<Gate>, // All gates
|
pub gates: Vec<Gate>, // All gates
|
||||||
|
pub input_bits: Vec<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Circuit {
|
impl Circuit {
|
||||||
pub fn eval(self, input_bits: Vec<bool>,) -> bool {
|
pub fn eval(self, ) -> bool {
|
||||||
let mut evaluated_gates = vec![];
|
let mut evaluated_gates = vec![];
|
||||||
|
|
||||||
for gate in self.gates {
|
for gate in self.gates {
|
||||||
let result = gate.eval(&input_bits, &evaluated_gates);
|
let result = gate.eval(&self.input_bits, &evaluated_gates);
|
||||||
evaluated_gates.push(result);
|
evaluated_gates.push(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -24,7 +25,7 @@ impl Circuit {
|
|||||||
This method should create a circuit that outputs 1 if the first number A (encoded in the first n
|
This method should create a circuit that outputs 1 if the first number A (encoded in the first n
|
||||||
bits) is greater than the second number B (encoded in the next n bits) .
|
bits) is greater than the second number B (encoded in the next n bits) .
|
||||||
*/
|
*/
|
||||||
pub fn compare_n_bit_numbers( n: usize) -> Self {
|
pub fn compare_n_bit_numbers( n: usize, input_bits: Vec<bool>,) -> Self {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
base case n=1: 1-bit:
|
base case n=1: 1-bit:
|
||||||
@@ -69,7 +70,7 @@ impl Circuit {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
let gates = create_n_bit_comparator_gates(n);
|
let gates = create_n_bit_comparator_gates(n);
|
||||||
return Circuit { gates };
|
return Circuit { gates, input_bits };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -33,8 +33,8 @@ fn main() {
|
|||||||
input_bits.extend_from_slice(&b_bits);
|
input_bits.extend_from_slice(&b_bits);
|
||||||
|
|
||||||
// Build and evaluate the comparison circuit
|
// Build and evaluate the comparison circuit
|
||||||
let circuit = Circuit::compare_n_bit_numbers(256);
|
let circuit = Circuit::compare_n_bit_numbers(256, input_bits);
|
||||||
let circuit_result = circuit.eval(input_bits);
|
let circuit_result = circuit.eval();
|
||||||
|
|
||||||
let a_int = BigUint::from_bytes_le(&a.to_bytes());
|
let a_int = BigUint::from_bytes_le(&a.to_bytes());
|
||||||
let b_int = BigUint::from_bytes_le(&b.to_bytes());
|
let b_int = BigUint::from_bytes_le(&b.to_bytes());
|
||||||
|
|||||||
+2
-3
@@ -6,8 +6,6 @@ mod tests {
|
|||||||
use rand::rngs::OsRng;
|
use rand::rngs::OsRng;
|
||||||
#[test]
|
#[test]
|
||||||
fn test_scalar_comparison_via_circuit() {
|
fn test_scalar_comparison_via_circuit() {
|
||||||
let circuit = Circuit::compare_n_bit_numbers(256);
|
|
||||||
|
|
||||||
for _ in 0..100 {
|
for _ in 0..100 {
|
||||||
let a = Scalar::random(&mut OsRng);
|
let a = Scalar::random(&mut OsRng);
|
||||||
let b = Scalar::random(&mut OsRng);
|
let b = Scalar::random(&mut OsRng);
|
||||||
@@ -22,7 +20,8 @@ mod tests {
|
|||||||
input_bits.extend_from_slice(&b_bits);
|
input_bits.extend_from_slice(&b_bits);
|
||||||
|
|
||||||
// Evaluate the comparison circuit
|
// Evaluate the comparison circuit
|
||||||
let circuit_result = circuit.clone().eval(input_bits);
|
let circuit = Circuit::compare_n_bit_numbers(256, input_bits);
|
||||||
|
let circuit_result = circuit.clone().eval();
|
||||||
|
|
||||||
// Compare expected result using BigUint
|
// Compare expected result using BigUint
|
||||||
let a_int = BigUint::from_bytes_le(&a.to_bytes());
|
let a_int = BigUint::from_bytes_le(&a.to_bytes());
|
||||||
|
|||||||
Reference in New Issue
Block a user