Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion g16ckt/src/circuit/modes/execute_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
13 changes: 1 addition & 12 deletions g16ckt/src/core/gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
39 changes: 23 additions & 16 deletions g16ckt/src/gadgets/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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];
Expand All @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion g16ckt/src/gadgets/bigint/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub fn add_constant<C: CircuitContext>(
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] {
Expand Down
6 changes: 3 additions & 3 deletions g16ckt/src/gadgets/bigint/cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ pub fn equal_zero<C: CircuitContext>(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;
}
Expand Down Expand Up @@ -118,7 +118,7 @@ pub fn greater_than<C: CircuitContext>(
.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(),
Expand All @@ -140,7 +140,7 @@ pub fn less_than_constant<C: CircuitContext>(
.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(),
Expand Down
Loading