Skip to content

Commit fc1e004

Browse files
committed
panic if valid entry already exists at index
1 parent de9b522 commit fc1e004

File tree

3 files changed

+28
-22
lines changed

3 files changed

+28
-22
lines changed

g16ckt/src/circuit/modes/execute_mode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ impl CircuitMode for ExecuteMode {
115115
self.storage
116116
.set(wire_id, |entry| {
117117
assert!(
118-
entry.is_some(),
118+
entry.is_none(),
119119
"overwriting wire_id {wire_id} value in storage"
120120
);
121121
*entry = Some(value)

g16ckt/src/core/gate.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,12 @@ impl Gate {
133133
}
134134

135135
#[must_use]
136-
pub fn not(wire_a: &mut WireId) -> Self {
137-
let wire_a = *wire_a;
136+
pub fn not(wire_a: WireId, wire_c: WireId) -> Self {
138137
Self {
139138
wire_a,
140-
wire_b: wire_a,
141-
wire_c: wire_a,
142-
gate_type: GateType::Not,
139+
wire_b: TRUE_WIRE,
140+
wire_c,
141+
gate_type: GateType::Xor,
143142
}
144143
}
145144

g16ckt/src/gadgets/basic.rs

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,12 @@ mod tests {
117117
[true],
118118
10_000,
119119
|circuit, wire| {
120-
let [mut wire] = *wire;
121-
circuit.add_gate(Gate::not(&mut wire));
122-
circuit.add_gate(Gate::not(&mut wire));
123-
124-
vec![wire]
120+
let [wire] = *wire;
121+
let wire_not = circuit.issue_wire();
122+
circuit.add_gate(Gate::not(wire, wire_not));
123+
let wire_not_not = circuit.issue_wire();
124+
circuit.add_gate(Gate::not(wire_not, wire_not_not));
125+
vec![wire_not_not]
125126
},
126127
)
127128
.output_value[0];
@@ -131,12 +132,14 @@ mod tests {
131132
[true],
132133
10_000,
133134
|circuit, wire| {
134-
let [mut wire] = *wire;
135-
circuit.add_gate(Gate::not(&mut wire));
136-
circuit.add_gate(Gate::not(&mut wire));
137-
circuit.add_gate(Gate::not(&mut wire));
138-
139-
vec![wire]
135+
let [wire] = *wire;
136+
let wire_not = circuit.issue_wire();
137+
circuit.add_gate(Gate::not(wire, wire_not));
138+
let wire_not_not = circuit.issue_wire();
139+
circuit.add_gate(Gate::not(wire_not, wire_not_not));
140+
let wire_not_not_not = circuit.issue_wire();
141+
circuit.add_gate(Gate::not(wire_not_not, wire_not_not_not));
142+
vec![wire_not_not_not]
140143
},
141144
)
142145
.output_value[0];
@@ -150,13 +153,17 @@ mod tests {
150153
[true, true],
151154
10_000,
152155
|circuit, wires| {
153-
let [mut a_wire, mut b_wire] = *wires;
156+
let [a_wire, b_wire] = *wires;
154157

155-
circuit.add_gate(Gate::not(&mut a_wire));
156-
circuit.add_gate(Gate::not(&mut a_wire));
158+
let a_wire_not = circuit.issue_wire();
159+
circuit.add_gate(Gate::not(a_wire, a_wire_not));
160+
let a_wire_not2 = circuit.issue_wire();
161+
circuit.add_gate(Gate::not(a_wire_not, a_wire_not2));
157162

158-
circuit.add_gate(Gate::not(&mut b_wire));
159-
circuit.add_gate(Gate::not(&mut b_wire));
163+
let b_wire_not = circuit.issue_wire();
164+
circuit.add_gate(Gate::not(b_wire, b_wire_not));
165+
let b_wire_not2 = circuit.issue_wire();
166+
circuit.add_gate(Gate::not(b_wire_not, b_wire_not2));
160167

161168
let res = circuit.issue_wire();
162169
circuit.add_gate(Gate::and(a_wire, b_wire, res));

0 commit comments

Comments
 (0)