Browse Source

Make function signatures conform to assignment

master
Your Name 2 weeks ago
parent
commit
70da422938
3 changed files with 9 additions and 9 deletions
  1. 5
    4
      src/circuit.rs
  2. 2
    2
      src/main.rs
  3. 2
    3
      tests/test.rs

+ 5
- 4
src/circuit.rs View File

@@ -3,14 +3,15 @@ use crate::{gate::Gate, gate_type::GateType};
3 3
 #[derive(Debug, Clone)]
4 4
 pub struct Circuit {
5 5
     pub gates: Vec<Gate>,      // All gates
6
+    pub input_bits: Vec<bool>,
6 7
 }
7 8
 
8 9
 impl Circuit {
9
-    pub fn eval(self, input_bits: Vec<bool>,)  -> bool {
10
+    pub fn eval(self, )  -> bool {
10 11
         let mut evaluated_gates = vec![];
11 12
 
12 13
         for gate in self.gates {
13
-            let result = gate.eval(&input_bits, &evaluated_gates);
14
+            let result = gate.eval(&self.input_bits, &evaluated_gates);
14 15
             evaluated_gates.push(result);
15 16
         }
16 17
 
@@ -24,7 +25,7 @@ impl Circuit {
24 25
         This method should create a circuit that outputs 1 if the first number A (encoded in the first n
25 26
         bits) is greater than the second number B (encoded in the next n bits) .
26 27
     */
27
-    pub fn compare_n_bit_numbers( n: usize) -> Self {
28
+    pub fn compare_n_bit_numbers( n: usize, input_bits: Vec<bool>,) -> Self {
28 29
 
29 30
         /*
30 31
             base case n=1: 1-bit:
@@ -69,7 +70,7 @@ impl Circuit {
69 70
         */
70 71
 
71 72
         let gates = create_n_bit_comparator_gates(n);
72
-        return Circuit { gates };
73
+        return Circuit { gates, input_bits };
73 74
     }
74 75
 }
75 76
 

+ 2
- 2
src/main.rs View File

@@ -33,8 +33,8 @@ fn main() {
33 33
     input_bits.extend_from_slice(&b_bits);
34 34
 
35 35
     // Build and evaluate the comparison circuit
36
-    let circuit = Circuit::compare_n_bit_numbers(256);
37
-    let circuit_result = circuit.eval(input_bits);
36
+    let circuit = Circuit::compare_n_bit_numbers(256, input_bits);
37
+    let circuit_result = circuit.eval();
38 38
 
39 39
     let a_int = BigUint::from_bytes_le(&a.to_bytes());
40 40
     let b_int = BigUint::from_bytes_le(&b.to_bytes());

+ 2
- 3
tests/test.rs View File

@@ -6,8 +6,6 @@ mod tests {
6 6
     use rand::rngs::OsRng;
7 7
     #[test]
8 8
     fn test_scalar_comparison_via_circuit() {
9
-        let circuit = Circuit::compare_n_bit_numbers(256);
10
-
11 9
         for _ in 0..100 {
12 10
             let a = Scalar::random(&mut OsRng);
13 11
             let b = Scalar::random(&mut OsRng);
@@ -22,7 +20,8 @@ mod tests {
22 20
             input_bits.extend_from_slice(&b_bits);
23 21
 
24 22
             // Evaluate the comparison circuit
25
-            let circuit_result = circuit.clone().eval(input_bits);
23
+            let circuit = Circuit::compare_n_bit_numbers(256, input_bits);
24
+            let circuit_result = circuit.clone().eval();
26 25
 
27 26
             // Compare expected result using BigUint
28 27
             let a_int = BigUint::from_bytes_le(&a.to_bytes());

Loading…
Cancel
Save