Rename fields of Wire

This commit is contained in:
wborgeaud 2022-05-17 11:31:45 +02:00
parent e10e103933
commit 4cd37ca8d4
17 changed files with 80 additions and 57 deletions

View File

@ -264,8 +264,8 @@ impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F> for Insert
fn run_once(&self, witness: &PartitionWitness<F>, out_buffer: &mut GeneratedValues<F>) {
let local_wire = |input| Wire {
gate: self.gate_index,
input,
row: self.gate_index,
column: input,
};
let get_local_wire = |input| witness.get_wire(local_wire(input));

View File

@ -372,8 +372,8 @@ impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F>
fn run_once(&self, witness: &PartitionWitness<F>, out_buffer: &mut GeneratedValues<F>) {
let local_wire = |input| Wire {
gate: self.gate_index,
input,
row: self.gate_index,
column: input,
};
let get_local_wire = |input| witness.get_wire(local_wire(input));

View File

@ -251,8 +251,8 @@ impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F>
fn run_once(&self, witness: &PartitionWitness<F>, out_buffer: &mut GeneratedValues<F>) {
let local_wire = |input| Wire {
gate: self.gate_index,
input,
row: self.gate_index,
column: input,
};
let get_local_wire = |input| witness.get_wire(local_wire(input));

View File

@ -216,8 +216,8 @@ impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F>
fn dependencies(&self) -> Vec<Target> {
let local_target = |input| {
Target::Wire(Wire {
gate: self.gate_index,
input,
row: self.gate_index,
column: input,
})
};
@ -236,8 +236,8 @@ impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F>
fn run_once(&self, witness: &PartitionWitness<F>, out_buffer: &mut GeneratedValues<F>) {
let local_wire = |input| Wire {
gate: self.gate_index,
input,
row: self.gate_index,
column: input,
};
let get_local_wire = |input| witness.get_wire(local_wire(input));

View File

@ -307,8 +307,8 @@ impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F>
fn dependencies(&self) -> Vec<Target> {
let local_target = |input| {
Target::Wire(Wire {
gate: self.gate_index,
input,
row: self.gate_index,
column: input,
})
};
@ -327,8 +327,8 @@ impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F>
fn run_once(&self, witness: &PartitionWitness<F>, out_buffer: &mut GeneratedValues<F>) {
let local_wire = |input| Wire {
gate: self.gate_index,
input,
row: self.gate_index,
column: input,
};
let get_local_wire = |input| witness.get_wire(local_wire(input));

View File

@ -426,8 +426,8 @@ impl<F: RichField + Extendable<D> + Poseidon, const D: usize> SimpleGenerator<F>
fn run_once(&self, witness: &PartitionWitness<F>, out_buffer: &mut GeneratedValues<F>) {
let local_wire = |input| Wire {
gate: self.gate_index,
input,
row: self.gate_index,
column: input,
};
let mut state = (0..SPONGE_WIDTH)
@ -569,16 +569,16 @@ mod tests {
let mut inputs = PartialWitness::new();
inputs.set_wire(
Wire {
gate: gate_index,
input: Gate::WIRE_SWAP,
row: gate_index,
column: Gate::WIRE_SWAP,
},
F::ZERO,
);
for i in 0..SPONGE_WIDTH {
inputs.set_wire(
Wire {
gate: gate_index,
input: Gate::wire_input(i),
row: gate_index,
column: Gate::wire_input(i),
},
permutation_inputs[i],
);
@ -590,8 +590,8 @@ mod tests {
F::poseidon(permutation_inputs.try_into().unwrap());
for i in 0..SPONGE_WIDTH {
let out = witness.get_wire(Wire {
gate: 0,
input: Gate::wire_output(i),
row: 0,
column: Gate::wire_output(i),
});
assert_eq!(out, expected_outputs[i]);
}

View File

@ -329,8 +329,8 @@ impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F>
fn run_once(&self, witness: &PartitionWitness<F>, out_buffer: &mut GeneratedValues<F>) {
let local_wire = |input| Wire {
gate: self.gate_index,
input,
row: self.gate_index,
column: input,
};
let get_local_wire = |input| witness.get_wire(local_wire(input));

View File

@ -17,7 +17,10 @@ pub enum Target {
impl Target {
pub fn wire(gate: usize, input: usize) -> Self {
Self::Wire(Wire { gate, input })
Self::Wire(Wire {
row: gate,
column: input,
})
}
pub fn is_routable(&self, config: &CircuitConfig) -> bool {
@ -33,7 +36,10 @@ impl Target {
pub fn index(&self, num_wires: usize, degree: usize) -> usize {
match self {
Target::Wire(Wire { gate, input }) => gate * num_wires + input,
Target::Wire(Wire {
row: gate,
column: input,
}) => gate * num_wires + input,
Target::VirtualTarget { index } => degree * num_wires + index,
}
}

View File

@ -2,21 +2,26 @@ use std::ops::Range;
use crate::plonk::circuit_data::CircuitConfig;
/// Represents a wire in the circuit.
/// Represents a wire in the circuit, seen as a `degree x num_wires` table.
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct Wire {
/// The index of the associated gate.
pub gate: usize,
/// The index of the gate input wherein this wire is inserted.
pub input: usize,
/// Row index of the wire.
pub row: usize,
/// Column index of the wire.
pub column: usize,
}
impl Wire {
pub fn is_routable(&self, config: &CircuitConfig) -> bool {
self.input < config.num_routed_wires
self.column < config.num_routed_wires
}
pub fn from_range(gate: usize, range: Range<usize>) -> Vec<Self> {
range.map(|i| Wire { gate, input: i }).collect()
range
.map(|i| Wire {
row: gate,
column: i,
})
.collect()
}
}

View File

@ -315,7 +315,7 @@ impl<'a, F: Field> PartitionWitness<'a, F> {
let mut wire_values = vec![vec![F::ZERO; self.degree]; self.num_wires];
for i in 0..self.degree {
for j in 0..self.num_wires {
let t = Target::Wire(Wire { gate: i, input: j });
let t = Target::Wire(Wire { row: i, column: j });
if let Some(x) = self.try_get_target(t) {
wire_values[j][i] = x;
}

View File

@ -527,7 +527,10 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
let gate = self.add_gate(NoopGate, vec![]);
for w in 0..num_wires {
self.add_simple_generator(RandomValueGenerator {
target: Target::Wire(Wire { gate, input: w }),
target: Target::Wire(Wire {
row: gate,
column: w,
}),
});
}
}
@ -542,18 +545,18 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
for w in 0..num_routed_wires {
self.add_simple_generator(RandomValueGenerator {
target: Target::Wire(Wire {
gate: gate_1,
input: w,
row: gate_1,
column: w,
}),
});
self.generate_copy(
Target::Wire(Wire {
gate: gate_1,
input: w,
row: gate_1,
column: w,
}),
Target::Wire(Wire {
gate: gate_2,
input: w,
row: gate_2,
column: w,
}),
);
}
@ -596,7 +599,10 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
for gate in 0..degree {
for input in 0..config.num_wires {
forest.add(Target::Wire(Wire { gate, input }));
forest.add(Target::Wire(Wire {
row: gate,
column: input,
}));
}
}

View File

@ -91,7 +91,10 @@ impl Forest {
// Here we keep just the Wire targets, filtering out everything else.
for gate in 0..self.degree {
for input in 0..self.num_routed_wires {
let w = Wire { gate, input };
let w = Wire {
row: gate,
column: input,
};
let t = Target::Wire(w);
let x_parent = self.parents[self.target_index(t)];
partition.entry(x_parent).or_default().push(w);
@ -146,9 +149,12 @@ impl WirePartition {
let mut sigma = Vec::new();
for input in 0..num_routed_wires {
for gate in 0..degree {
let wire = Wire { gate, input };
let wire = Wire {
row: gate,
column: input,
};
let neighbor = neighbors[&wire];
sigma.push(neighbor.input * degree + neighbor.gate);
sigma.push(neighbor.column * degree + neighbor.row);
}
}
sigma

View File

@ -292,8 +292,8 @@ impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F>
fn run_once(&self, witness: &PartitionWitness<F>, out_buffer: &mut GeneratedValues<F>) {
let local_wire = |input| Wire {
gate: self.gate_index,
input,
row: self.gate_index,
column: input,
};
let get_local_wire = |input| witness.get_wire(local_wire(input));

View File

@ -301,8 +301,8 @@ impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F>
fn run_once(&self, witness: &PartitionWitness<F>, out_buffer: &mut GeneratedValues<F>) {
let local_wire = |input| Wire {
gate: self.gate_index,
input,
row: self.gate_index,
column: input,
};
let get_local_wire = |input| witness.get_wire(local_wire(input));

View File

@ -415,8 +415,8 @@ impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F>
fn run_once(&self, witness: &PartitionWitness<F>, out_buffer: &mut GeneratedValues<F>) {
let local_wire = |input| Wire {
gate: self.gate_index,
input,
row: self.gate_index,
column: input,
};
let get_local_wire = |input| witness.get_wire(local_wire(input));

View File

@ -285,8 +285,8 @@ impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F>
fn run_once(&self, witness: &PartitionWitness<F>, out_buffer: &mut GeneratedValues<F>) {
let local_wire = |input| Wire {
gate: self.gate_index,
input,
row: self.gate_index,
column: input,
};
let get_local_wire = |input| witness.get_wire(local_wire(input));

View File

@ -250,8 +250,8 @@ impl<F: RichField + Extendable<D>, const D: usize> SwitchGenerator<F, D> {
fn run_in_out(&self, witness: &PartitionWitness<F>, out_buffer: &mut GeneratedValues<F>) {
let local_wire = |input| Wire {
gate: self.gate_index,
input,
row: self.gate_index,
column: input,
};
let get_local_wire = |input| witness.get_wire(local_wire(input));
@ -280,8 +280,8 @@ impl<F: RichField + Extendable<D>, const D: usize> SwitchGenerator<F, D> {
fn run_in_switch(&self, witness: &PartitionWitness<F>, out_buffer: &mut GeneratedValues<F>) {
let local_wire = |input| Wire {
gate: self.gate_index,
input,
row: self.gate_index,
column: input,
};
let get_local_wire = |input| witness.get_wire(local_wire(input));