diff --git a/g16ckt/src/circuit/modes/execute_mode.rs b/g16ckt/src/circuit/modes/execute_mode.rs index d421123..62164b3 100644 --- a/g16ckt/src/circuit/modes/execute_mode.rs +++ b/g16ckt/src/circuit/modes/execute_mode.rs @@ -113,7 +113,13 @@ impl CircuitMode for ExecuteMode { } self.storage - .set(wire_id, |entry| *entry = Some(value)) + .set(wire_id, |entry| { + assert!( + entry.is_none(), + "overwriting wire_id {wire_id} value in storage" + ); + *entry = Some(value) + }) .unwrap(); } diff --git a/g16ckt/src/core/gate.rs b/g16ckt/src/core/gate.rs index 27faf35..05cac8a 100644 --- a/g16ckt/src/core/gate.rs +++ b/g16ckt/src/core/gate.rs @@ -133,18 +133,7 @@ impl Gate { } #[must_use] - pub fn not(wire_a: &mut WireId) -> Self { - let wire_a = *wire_a; - Self { - wire_a, - wire_b: wire_a, - wire_c: wire_a, - gate_type: GateType::Not, - } - } - - #[must_use] - pub fn not_with_xor(wire_a: WireId, wire_c: WireId) -> Self { + pub fn not(wire_a: WireId, wire_c: WireId) -> Self { Self { wire_a, wire_b: TRUE_WIRE, diff --git a/g16ckt/src/gadgets/basic.rs b/g16ckt/src/gadgets/basic.rs index c5dbd34..2d58432 100644 --- a/g16ckt/src/gadgets/basic.rs +++ b/g16ckt/src/gadgets/basic.rs @@ -117,11 +117,12 @@ mod tests { [true], 10_000, |circuit, wire| { - let [mut wire] = *wire; - circuit.add_gate(Gate::not(&mut wire)); - circuit.add_gate(Gate::not(&mut wire)); - - vec![wire] + let [wire] = *wire; + let wire_not = circuit.issue_wire(); + circuit.add_gate(Gate::not(wire, wire_not)); + let wire_not_not = circuit.issue_wire(); + circuit.add_gate(Gate::not(wire_not, wire_not_not)); + vec![wire_not_not] }, ) .output_value[0]; @@ -131,12 +132,14 @@ mod tests { [true], 10_000, |circuit, wire| { - let [mut wire] = *wire; - circuit.add_gate(Gate::not(&mut wire)); - circuit.add_gate(Gate::not(&mut wire)); - circuit.add_gate(Gate::not(&mut wire)); - - vec![wire] + let [wire] = *wire; + let wire_not = circuit.issue_wire(); + circuit.add_gate(Gate::not(wire, wire_not)); + let wire_not_not = circuit.issue_wire(); + circuit.add_gate(Gate::not(wire_not, wire_not_not)); + let wire_not_not_not = circuit.issue_wire(); + circuit.add_gate(Gate::not(wire_not_not, wire_not_not_not)); + vec![wire_not_not_not] }, ) .output_value[0]; @@ -150,13 +153,17 @@ mod tests { [true, true], 10_000, |circuit, wires| { - let [mut a_wire, mut b_wire] = *wires; + let [a_wire, b_wire] = *wires; - circuit.add_gate(Gate::not(&mut a_wire)); - circuit.add_gate(Gate::not(&mut a_wire)); + let a_wire_not = circuit.issue_wire(); + circuit.add_gate(Gate::not(a_wire, a_wire_not)); + let a_wire_not2 = circuit.issue_wire(); + circuit.add_gate(Gate::not(a_wire_not, a_wire_not2)); - circuit.add_gate(Gate::not(&mut b_wire)); - circuit.add_gate(Gate::not(&mut b_wire)); + let b_wire_not = circuit.issue_wire(); + circuit.add_gate(Gate::not(b_wire, b_wire_not)); + let b_wire_not2 = circuit.issue_wire(); + circuit.add_gate(Gate::not(b_wire_not, b_wire_not2)); let res = circuit.issue_wire(); circuit.add_gate(Gate::and(a_wire, b_wire, res)); diff --git a/g16ckt/src/gadgets/bigint/add.rs b/g16ckt/src/gadgets/bigint/add.rs index 926f136..8e41f34 100644 --- a/g16ckt/src/gadgets/bigint/add.rs +++ b/g16ckt/src/gadgets/bigint/add.rs @@ -57,7 +57,7 @@ pub fn add_constant( bits.push(a_i); } else if i == first_one { let wire = circuit.issue_wire(); - circuit.add_gate(Gate::not_with_xor(a_i, wire)); //This must be necessary, since the bit is duplicated + circuit.add_gate(Gate::not(a_i, wire)); //This must be necessary, since the bit is duplicated bits.push(wire); carry = Some(a_i); } else if b_bits[i] { diff --git a/g16ckt/src/gadgets/bigint/cmp.rs b/g16ckt/src/gadgets/bigint/cmp.rs index 12900c9..5ca5bc6 100644 --- a/g16ckt/src/gadgets/bigint/cmp.rs +++ b/g16ckt/src/gadgets/bigint/cmp.rs @@ -90,7 +90,7 @@ pub fn equal_zero(circuit: &mut C, a: &BigIntWires) -> WireId let is_bit_zero = circuit.issue_wire(); //this xor might be negated with innate NOT maintenance - circuit.add_gate(Gate::not_with_xor(a.get(0).unwrap(), is_bit_zero)); + circuit.add_gate(Gate::not(a.get(0).unwrap(), is_bit_zero)); return is_bit_zero; } @@ -118,7 +118,7 @@ pub fn greater_than( .map(|b_i| { let w = circuit.issue_wire(); //this xor might be negated with innate NOT maintenance - circuit.add_gate(Gate::not_with_xor(*b_i, w)); + circuit.add_gate(Gate::not(*b_i, w)); w }) .collect(), @@ -140,7 +140,7 @@ pub fn less_than_constant( .map(|a_i| { let w = circuit.issue_wire(); //this xor might be negated with innate NOT maintenance - circuit.add_gate(Gate::not_with_xor(*a_i, w)); + circuit.add_gate(Gate::not(*a_i, w)); w }) .collect(),