mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-01-07 00:03:10 +00:00
s/gate_index/row/
This commit is contained in:
parent
a31de48d88
commit
28d90d0e9e
@ -27,25 +27,22 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilderInsert<F, D>
|
||||
v: Vec<ExtensionTarget<D>>,
|
||||
) -> Vec<ExtensionTarget<D>> {
|
||||
let gate = InsertionGate::new(v.len());
|
||||
let gate_index = self.add_gate(gate.clone(), vec![]);
|
||||
let row = self.add_gate(gate.clone(), vec![]);
|
||||
|
||||
v.iter().enumerate().for_each(|(i, &val)| {
|
||||
self.connect_extension(
|
||||
val,
|
||||
ExtensionTarget::from_range(gate_index, gate.wires_original_list_item(i)),
|
||||
ExtensionTarget::from_range(row, gate.wires_original_list_item(i)),
|
||||
);
|
||||
});
|
||||
self.connect(
|
||||
index,
|
||||
Target::wire(gate_index, gate.wires_insertion_index()),
|
||||
);
|
||||
self.connect(index, Target::wire(row, gate.wires_insertion_index()));
|
||||
self.connect_extension(
|
||||
element,
|
||||
ExtensionTarget::from_range(gate_index, gate.wires_element_to_insert()),
|
||||
ExtensionTarget::from_range(row, gate.wires_element_to_insert()),
|
||||
);
|
||||
|
||||
(0..=v.len())
|
||||
.map(|i| ExtensionTarget::from_range(gate_index, gate.wires_output_list_item(i)))
|
||||
.map(|i| ExtensionTarget::from_range(row, gate.wires_output_list_item(i)))
|
||||
.collect::<Vec<_>>()
|
||||
}
|
||||
}
|
||||
|
||||
@ -213,13 +213,9 @@ impl<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for InsertionGate<
|
||||
constraints
|
||||
}
|
||||
|
||||
fn generators(
|
||||
&self,
|
||||
gate_index: usize,
|
||||
_local_constants: &[F],
|
||||
) -> Vec<Box<dyn WitnessGenerator<F>>> {
|
||||
fn generators(&self, row: usize, _local_constants: &[F]) -> Vec<Box<dyn WitnessGenerator<F>>> {
|
||||
let gen = InsertionGenerator::<F, D> {
|
||||
gate_index,
|
||||
row,
|
||||
gate: self.clone(),
|
||||
};
|
||||
vec![Box::new(gen.adapter())]
|
||||
@ -244,13 +240,13 @@ impl<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for InsertionGate<
|
||||
|
||||
#[derive(Debug)]
|
||||
struct InsertionGenerator<F: RichField + Extendable<D>, const D: usize> {
|
||||
gate_index: usize,
|
||||
row: usize,
|
||||
gate: InsertionGate<F, D>,
|
||||
}
|
||||
|
||||
impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F> for InsertionGenerator<F, D> {
|
||||
fn dependencies(&self) -> Vec<Target> {
|
||||
let local_target = |column| Target::wire(self.gate_index, column);
|
||||
let local_target = |column| Target::wire(self.row, column);
|
||||
|
||||
let local_targets = |columns: Range<usize>| columns.map(local_target);
|
||||
|
||||
@ -264,7 +260,7 @@ 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 = |column| Wire {
|
||||
row: self.gate_index,
|
||||
row: self.row,
|
||||
column,
|
||||
};
|
||||
|
||||
|
||||
@ -243,14 +243,14 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||
while exp_bits_vec.len() < num_power_bits {
|
||||
exp_bits_vec.push(_false);
|
||||
}
|
||||
let gate_index = self.add_gate(gate.clone(), vec![]);
|
||||
let row = self.add_gate(gate.clone(), vec![]);
|
||||
|
||||
self.connect(base, Target::wire(gate_index, gate.wire_base()));
|
||||
self.connect(base, Target::wire(row, gate.wire_base()));
|
||||
exp_bits_vec.iter().enumerate().for_each(|(i, bit)| {
|
||||
self.connect(bit.target, Target::wire(gate_index, gate.wire_power_bit(i)));
|
||||
self.connect(bit.target, Target::wire(row, gate.wire_power_bit(i)));
|
||||
});
|
||||
|
||||
Target::wire(gate_index, gate.wire_output())
|
||||
Target::wire(row, gate.wire_output())
|
||||
}
|
||||
|
||||
// TODO: Test
|
||||
|
||||
@ -88,20 +88,17 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||
evaluation_point: ExtensionTarget<D>,
|
||||
) -> ExtensionTarget<D> {
|
||||
let gate = G::new(subgroup_bits);
|
||||
let gate_index = self.add_gate(gate, vec![]);
|
||||
self.connect(coset_shift, Target::wire(gate_index, gate.wire_shift()));
|
||||
let row = self.add_gate(gate, vec![]);
|
||||
self.connect(coset_shift, Target::wire(row, gate.wire_shift()));
|
||||
for (i, &v) in values.iter().enumerate() {
|
||||
self.connect_extension(
|
||||
v,
|
||||
ExtensionTarget::from_range(gate_index, gate.wires_value(i)),
|
||||
);
|
||||
self.connect_extension(v, ExtensionTarget::from_range(row, gate.wires_value(i)));
|
||||
}
|
||||
self.connect_extension(
|
||||
evaluation_point,
|
||||
ExtensionTarget::from_range(gate_index, gate.wires_evaluation_point()),
|
||||
ExtensionTarget::from_range(row, gate.wires_evaluation_point()),
|
||||
);
|
||||
|
||||
ExtensionTarget::from_range(gate_index, gate.wires_evaluation_value())
|
||||
ExtensionTarget::from_range(row, gate.wires_evaluation_value())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -20,21 +20,18 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||
let claimed_element = self.add_virtual_target();
|
||||
|
||||
let dummy_gate = RandomAccessGate::<F, D>::new_from_config(&self.config, bits);
|
||||
let (gate_index, copy) = self.find_slot(dummy_gate, &[], &[]);
|
||||
let (row, copy) = self.find_slot(dummy_gate, &[], &[]);
|
||||
|
||||
v.iter().enumerate().for_each(|(i, &val)| {
|
||||
self.connect(
|
||||
val,
|
||||
Target::wire(gate_index, dummy_gate.wire_list_item(i, copy)),
|
||||
);
|
||||
self.connect(val, Target::wire(row, dummy_gate.wire_list_item(i, copy)));
|
||||
});
|
||||
self.connect(
|
||||
access_index,
|
||||
Target::wire(gate_index, dummy_gate.wire_access_index(copy)),
|
||||
Target::wire(row, dummy_gate.wire_access_index(copy)),
|
||||
);
|
||||
self.connect(
|
||||
claimed_element,
|
||||
Target::wire(gate_index, dummy_gate.wire_claimed_element(copy)),
|
||||
Target::wire(row, dummy_gate.wire_claimed_element(copy)),
|
||||
);
|
||||
|
||||
claimed_element
|
||||
|
||||
@ -54,29 +54,26 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||
"Not enough routed wires."
|
||||
);
|
||||
let gate_type = BaseSumGate::<2>::new_from_config::<F>(&self.config);
|
||||
let gate_index = self.add_gate(gate_type, vec![]);
|
||||
let row = self.add_gate(gate_type, vec![]);
|
||||
for (limb, wire) in bits
|
||||
.iter()
|
||||
.zip(BaseSumGate::<2>::START_LIMBS..BaseSumGate::<2>::START_LIMBS + num_bits)
|
||||
{
|
||||
self.connect(limb.target, Target::wire(gate_index, wire));
|
||||
self.connect(limb.target, Target::wire(row, wire));
|
||||
}
|
||||
for l in gate_type.limbs().skip(num_bits) {
|
||||
self.assert_zero(Target::wire(gate_index, l));
|
||||
self.assert_zero(Target::wire(row, l));
|
||||
}
|
||||
|
||||
self.add_simple_generator(BaseSumGenerator::<2> {
|
||||
gate_index,
|
||||
limbs: bits,
|
||||
});
|
||||
self.add_simple_generator(BaseSumGenerator::<2> { row, limbs: bits });
|
||||
|
||||
Target::wire(gate_index, BaseSumGate::<2>::WIRE_SUM)
|
||||
Target::wire(row, BaseSumGate::<2>::WIRE_SUM)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct BaseSumGenerator<const B: usize> {
|
||||
gate_index: usize,
|
||||
row: usize,
|
||||
limbs: Vec<BoolTarget>,
|
||||
}
|
||||
|
||||
@ -95,10 +92,7 @@ impl<F: Field, const B: usize> SimpleGenerator<F> for BaseSumGenerator<B> {
|
||||
acc * F::from_canonical_usize(B) + F::from_bool(limb)
|
||||
});
|
||||
|
||||
out_buffer.set_target(
|
||||
Target::wire(self.gate_index, BaseSumGate::<B>::WIRE_SUM),
|
||||
sum,
|
||||
);
|
||||
out_buffer.set_target(Target::wire(self.row, BaseSumGate::<B>::WIRE_SUM), sum);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -113,16 +113,12 @@ impl<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for ArithmeticGate
|
||||
constraints
|
||||
}
|
||||
|
||||
fn generators(
|
||||
&self,
|
||||
gate_index: usize,
|
||||
local_constants: &[F],
|
||||
) -> Vec<Box<dyn WitnessGenerator<F>>> {
|
||||
fn generators(&self, row: usize, local_constants: &[F]) -> Vec<Box<dyn WitnessGenerator<F>>> {
|
||||
(0..self.num_ops)
|
||||
.map(|i| {
|
||||
let g: Box<dyn WitnessGenerator<F>> = Box::new(
|
||||
ArithmeticBaseGenerator {
|
||||
gate_index,
|
||||
row,
|
||||
const_0: local_constants[0],
|
||||
const_1: local_constants[1],
|
||||
i,
|
||||
@ -174,7 +170,7 @@ impl<F: RichField + Extendable<D>, const D: usize> PackedEvaluableBase<F, D> for
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
struct ArithmeticBaseGenerator<F: RichField + Extendable<D>, const D: usize> {
|
||||
gate_index: usize,
|
||||
row: usize,
|
||||
const_0: F,
|
||||
const_1: F,
|
||||
i: usize,
|
||||
@ -190,19 +186,18 @@ impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F>
|
||||
ArithmeticGate::wire_ith_addend(self.i),
|
||||
]
|
||||
.iter()
|
||||
.map(|&i| Target::wire(self.gate_index, i))
|
||||
.map(|&i| Target::wire(self.row, i))
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn run_once(&self, witness: &PartitionWitness<F>, out_buffer: &mut GeneratedValues<F>) {
|
||||
let get_wire =
|
||||
|wire: usize| -> F { witness.get_target(Target::wire(self.gate_index, wire)) };
|
||||
let get_wire = |wire: usize| -> F { witness.get_target(Target::wire(self.row, wire)) };
|
||||
|
||||
let multiplicand_0 = get_wire(ArithmeticGate::wire_ith_multiplicand_0(self.i));
|
||||
let multiplicand_1 = get_wire(ArithmeticGate::wire_ith_multiplicand_1(self.i));
|
||||
let addend = get_wire(ArithmeticGate::wire_ith_addend(self.i));
|
||||
|
||||
let output_target = Target::wire(self.gate_index, ArithmeticGate::wire_ith_output(self.i));
|
||||
let output_target = Target::wire(self.row, ArithmeticGate::wire_ith_output(self.i));
|
||||
|
||||
let computed_output =
|
||||
multiplicand_0 * multiplicand_1 * self.const_0 + addend * self.const_1;
|
||||
|
||||
@ -120,16 +120,12 @@ impl<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for ArithmeticExte
|
||||
constraints
|
||||
}
|
||||
|
||||
fn generators(
|
||||
&self,
|
||||
gate_index: usize,
|
||||
local_constants: &[F],
|
||||
) -> Vec<Box<dyn WitnessGenerator<F>>> {
|
||||
fn generators(&self, row: usize, local_constants: &[F]) -> Vec<Box<dyn WitnessGenerator<F>>> {
|
||||
(0..self.num_ops)
|
||||
.map(|i| {
|
||||
let g: Box<dyn WitnessGenerator<F>> = Box::new(
|
||||
ArithmeticExtensionGenerator {
|
||||
gate_index,
|
||||
row,
|
||||
const_0: local_constants[0],
|
||||
const_1: local_constants[1],
|
||||
i,
|
||||
@ -160,7 +156,7 @@ impl<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for ArithmeticExte
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
struct ArithmeticExtensionGenerator<F: RichField + Extendable<D>, const D: usize> {
|
||||
gate_index: usize,
|
||||
row: usize,
|
||||
const_0: F,
|
||||
const_1: F,
|
||||
i: usize,
|
||||
@ -175,13 +171,13 @@ impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F>
|
||||
self.i,
|
||||
))
|
||||
.chain(ArithmeticExtensionGate::<D>::wires_ith_addend(self.i))
|
||||
.map(|i| Target::wire(self.gate_index, i))
|
||||
.map(|i| Target::wire(self.row, i))
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn run_once(&self, witness: &PartitionWitness<F>, out_buffer: &mut GeneratedValues<F>) {
|
||||
let extract_extension = |range: Range<usize>| -> F::Extension {
|
||||
let t = ExtensionTarget::from_range(self.gate_index, range);
|
||||
let t = ExtensionTarget::from_range(self.row, range);
|
||||
witness.get_extension_target(t)
|
||||
};
|
||||
|
||||
@ -194,7 +190,7 @@ impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F>
|
||||
let addend = extract_extension(ArithmeticExtensionGate::<D>::wires_ith_addend(self.i));
|
||||
|
||||
let output_target = ExtensionTarget::from_range(
|
||||
self.gate_index,
|
||||
self.row,
|
||||
ArithmeticExtensionGate::<D>::wires_ith_output(self.i),
|
||||
);
|
||||
|
||||
|
||||
@ -251,13 +251,9 @@ impl<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for AssertLessThan
|
||||
constraints
|
||||
}
|
||||
|
||||
fn generators(
|
||||
&self,
|
||||
gate_index: usize,
|
||||
_local_constants: &[F],
|
||||
) -> Vec<Box<dyn WitnessGenerator<F>>> {
|
||||
fn generators(&self, row: usize, _local_constants: &[F]) -> Vec<Box<dyn WitnessGenerator<F>>> {
|
||||
let gen = AssertLessThanGenerator::<F, D> {
|
||||
gate_index,
|
||||
row,
|
||||
gate: self.clone(),
|
||||
};
|
||||
vec![Box::new(gen.adapter())]
|
||||
@ -354,7 +350,7 @@ impl<F: RichField + Extendable<D>, const D: usize> PackedEvaluableBase<F, D>
|
||||
|
||||
#[derive(Debug)]
|
||||
struct AssertLessThanGenerator<F: RichField + Extendable<D>, const D: usize> {
|
||||
gate_index: usize,
|
||||
row: usize,
|
||||
gate: AssertLessThanGate<F, D>,
|
||||
}
|
||||
|
||||
@ -362,7 +358,7 @@ impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F>
|
||||
for AssertLessThanGenerator<F, D>
|
||||
{
|
||||
fn dependencies(&self) -> Vec<Target> {
|
||||
let local_target = |column| Target::wire(self.gate_index, column);
|
||||
let local_target = |column| Target::wire(self.row, column);
|
||||
|
||||
vec![
|
||||
local_target(self.gate.wire_first_input()),
|
||||
@ -372,7 +368,7 @@ 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 = |column| Wire {
|
||||
row: self.gate_index,
|
||||
row: self.row,
|
||||
column,
|
||||
};
|
||||
|
||||
|
||||
@ -104,13 +104,9 @@ impl<F: RichField + Extendable<D>, const D: usize, const B: usize> Gate<F, D> fo
|
||||
constraints
|
||||
}
|
||||
|
||||
fn generators(
|
||||
&self,
|
||||
gate_index: usize,
|
||||
_local_constants: &[F],
|
||||
) -> Vec<Box<dyn WitnessGenerator<F>>> {
|
||||
fn generators(&self, row: usize, _local_constants: &[F]) -> Vec<Box<dyn WitnessGenerator<F>>> {
|
||||
let gen = BaseSplitGenerator::<B> {
|
||||
gate_index,
|
||||
row,
|
||||
num_limbs: self.num_limbs,
|
||||
};
|
||||
vec![Box::new(gen.adapter())]
|
||||
@ -161,18 +157,18 @@ impl<F: RichField + Extendable<D>, const D: usize, const B: usize> PackedEvaluab
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct BaseSplitGenerator<const B: usize> {
|
||||
gate_index: usize,
|
||||
row: usize,
|
||||
num_limbs: usize,
|
||||
}
|
||||
|
||||
impl<F: RichField, const B: usize> SimpleGenerator<F> for BaseSplitGenerator<B> {
|
||||
fn dependencies(&self) -> Vec<Target> {
|
||||
vec![Target::wire(self.gate_index, BaseSumGate::<B>::WIRE_SUM)]
|
||||
vec![Target::wire(self.row, BaseSumGate::<B>::WIRE_SUM)]
|
||||
}
|
||||
|
||||
fn run_once(&self, witness: &PartitionWitness<F>, out_buffer: &mut GeneratedValues<F>) {
|
||||
let sum_value = witness
|
||||
.get_target(Target::wire(self.gate_index, BaseSumGate::<B>::WIRE_SUM))
|
||||
.get_target(Target::wire(self.row, BaseSumGate::<B>::WIRE_SUM))
|
||||
.to_canonical_u64() as usize;
|
||||
debug_assert_eq!(
|
||||
(0..self.num_limbs).fold(sum_value, |acc, _| acc / B),
|
||||
@ -181,7 +177,7 @@ impl<F: RichField, const B: usize> SimpleGenerator<F> for BaseSplitGenerator<B>
|
||||
);
|
||||
|
||||
let limbs = (BaseSumGate::<B>::START_LIMBS..BaseSumGate::<B>::START_LIMBS + self.num_limbs)
|
||||
.map(|i| Target::wire(self.gate_index, i));
|
||||
.map(|i| Target::wire(self.row, i));
|
||||
let limbs_value = (0..self.num_limbs)
|
||||
.scan(sum_value, |acc, _| {
|
||||
let tmp = *acc % B;
|
||||
|
||||
@ -71,11 +71,7 @@ impl<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for ConstantGate {
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn generators(
|
||||
&self,
|
||||
_gate_index: usize,
|
||||
_local_constants: &[F],
|
||||
) -> Vec<Box<dyn WitnessGenerator<F>>> {
|
||||
fn generators(&self, _row: usize, _local_constants: &[F]) -> Vec<Box<dyn WitnessGenerator<F>>> {
|
||||
vec![]
|
||||
}
|
||||
|
||||
|
||||
@ -161,13 +161,9 @@ impl<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for Exponentiation
|
||||
constraints
|
||||
}
|
||||
|
||||
fn generators(
|
||||
&self,
|
||||
gate_index: usize,
|
||||
_local_constants: &[F],
|
||||
) -> Vec<Box<dyn WitnessGenerator<F>>> {
|
||||
fn generators(&self, row: usize, _local_constants: &[F]) -> Vec<Box<dyn WitnessGenerator<F>>> {
|
||||
let gen = ExponentiationGenerator::<F, D> {
|
||||
gate_index,
|
||||
row,
|
||||
gate: self.clone(),
|
||||
};
|
||||
vec![Box::new(gen.adapter())]
|
||||
@ -231,7 +227,7 @@ impl<F: RichField + Extendable<D>, const D: usize> PackedEvaluableBase<F, D>
|
||||
|
||||
#[derive(Debug)]
|
||||
struct ExponentiationGenerator<F: RichField + Extendable<D>, const D: usize> {
|
||||
gate_index: usize,
|
||||
row: usize,
|
||||
gate: ExponentiationGate<F, D>,
|
||||
}
|
||||
|
||||
@ -239,7 +235,7 @@ impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F>
|
||||
for ExponentiationGenerator<F, D>
|
||||
{
|
||||
fn dependencies(&self) -> Vec<Target> {
|
||||
let local_target = |column| Target::wire(self.gate_index, column);
|
||||
let local_target = |column| Target::wire(self.row, column);
|
||||
|
||||
let mut deps = Vec::with_capacity(self.gate.num_power_bits + 1);
|
||||
deps.push(local_target(self.gate.wire_base()));
|
||||
@ -251,7 +247,7 @@ 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 = |column| Wire {
|
||||
row: self.gate_index,
|
||||
row: self.row,
|
||||
column,
|
||||
};
|
||||
|
||||
|
||||
@ -84,13 +84,13 @@ pub trait Gate<F: RichField + Extendable<D>, const D: usize>: 'static + Send + S
|
||||
fn eval_filtered(
|
||||
&self,
|
||||
mut vars: EvaluationVars<F, D>,
|
||||
gate_index: usize,
|
||||
row: usize,
|
||||
selector_index: usize,
|
||||
group_range: Range<usize>,
|
||||
num_selectors: usize,
|
||||
) -> Vec<F::Extension> {
|
||||
let filter = compute_filter(
|
||||
gate_index,
|
||||
row,
|
||||
group_range,
|
||||
vars.local_constants[selector_index],
|
||||
num_selectors > 1,
|
||||
@ -107,7 +107,7 @@ pub trait Gate<F: RichField + Extendable<D>, const D: usize>: 'static + Send + S
|
||||
fn eval_filtered_base_batch(
|
||||
&self,
|
||||
mut vars_batch: EvaluationVarsBaseBatch<F>,
|
||||
gate_index: usize,
|
||||
row: usize,
|
||||
selector_index: usize,
|
||||
group_range: Range<usize>,
|
||||
num_selectors: usize,
|
||||
@ -116,7 +116,7 @@ pub trait Gate<F: RichField + Extendable<D>, const D: usize>: 'static + Send + S
|
||||
.iter()
|
||||
.map(|vars| {
|
||||
compute_filter(
|
||||
gate_index,
|
||||
row,
|
||||
group_range.clone(),
|
||||
vars.local_constants[selector_index],
|
||||
num_selectors > 1,
|
||||
@ -136,7 +136,7 @@ pub trait Gate<F: RichField + Extendable<D>, const D: usize>: 'static + Send + S
|
||||
&self,
|
||||
builder: &mut CircuitBuilder<F, D>,
|
||||
mut vars: EvaluationTargets<D>,
|
||||
gate_index: usize,
|
||||
row: usize,
|
||||
selector_index: usize,
|
||||
group_range: Range<usize>,
|
||||
num_selectors: usize,
|
||||
@ -144,7 +144,7 @@ pub trait Gate<F: RichField + Extendable<D>, const D: usize>: 'static + Send + S
|
||||
) {
|
||||
let filter = compute_filter_recursively(
|
||||
builder,
|
||||
gate_index,
|
||||
row,
|
||||
group_range,
|
||||
vars.local_constants[selector_index],
|
||||
num_selectors > 1,
|
||||
@ -158,11 +158,7 @@ pub trait Gate<F: RichField + Extendable<D>, const D: usize>: 'static + Send + S
|
||||
|
||||
/// The generators used to populate the witness.
|
||||
/// Note: This should return exactly 1 generator per operation in the gate.
|
||||
fn generators(
|
||||
&self,
|
||||
gate_index: usize,
|
||||
local_constants: &[F],
|
||||
) -> Vec<Box<dyn WitnessGenerator<F>>>;
|
||||
fn generators(&self, row: usize, local_constants: &[F]) -> Vec<Box<dyn WitnessGenerator<F>>>;
|
||||
|
||||
/// The number of wires used by this gate.
|
||||
fn num_wires(&self) -> usize;
|
||||
@ -222,8 +218,8 @@ impl<F: RichField + Extendable<D>, const D: usize> Debug for GateRef<F, D> {
|
||||
}
|
||||
|
||||
/// Map between gate parameters and available slots.
|
||||
/// An available slot is of the form `(gate_index, op)`, meaning the current available slot
|
||||
/// is at gate index `gate_index` in the `op`-th operation.
|
||||
/// An available slot is of the form `(row, op)`, meaning the current available slot
|
||||
/// is at gate index `row` in the `op`-th operation.
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub struct CurrentSlot<F: RichField + Extendable<D>, const D: usize> {
|
||||
pub current_slot: HashMap<Vec<F>, (usize, usize)>,
|
||||
@ -243,16 +239,11 @@ pub struct PrefixedGate<F: RichField + Extendable<D>, const D: usize> {
|
||||
pub prefix: Vec<bool>,
|
||||
}
|
||||
|
||||
/// A gate's filter designed so that it is non-zero if `s = gate_index`.
|
||||
fn compute_filter<K: Field>(
|
||||
gate_index: usize,
|
||||
group_range: Range<usize>,
|
||||
s: K,
|
||||
many_selector: bool,
|
||||
) -> K {
|
||||
debug_assert!(group_range.contains(&gate_index));
|
||||
/// A gate's filter designed so that it is non-zero if `s = row`.
|
||||
fn compute_filter<K: Field>(row: usize, group_range: Range<usize>, s: K, many_selector: bool) -> K {
|
||||
debug_assert!(group_range.contains(&row));
|
||||
group_range
|
||||
.filter(|&i| i != gate_index)
|
||||
.filter(|&i| i != row)
|
||||
.chain(many_selector.then(|| UNUSED_SELECTOR))
|
||||
.map(|i| K::from_canonical_usize(i) - s)
|
||||
.product()
|
||||
@ -260,14 +251,14 @@ fn compute_filter<K: Field>(
|
||||
|
||||
fn compute_filter_recursively<F: RichField + Extendable<D>, const D: usize>(
|
||||
builder: &mut CircuitBuilder<F, D>,
|
||||
gate_index: usize,
|
||||
row: usize,
|
||||
group_range: Range<usize>,
|
||||
s: ExtensionTarget<D>,
|
||||
many_selectors: bool,
|
||||
) -> ExtensionTarget<D> {
|
||||
debug_assert!(group_range.contains(&gate_index));
|
||||
debug_assert!(group_range.contains(&row));
|
||||
let v = group_range
|
||||
.filter(|&i| i != gate_index)
|
||||
.filter(|&i| i != row)
|
||||
.chain(many_selectors.then(|| UNUSED_SELECTOR))
|
||||
.map(|i| {
|
||||
let c = builder.constant_extension(F::Extension::from_canonical_usize(i));
|
||||
|
||||
@ -169,13 +169,9 @@ impl<F: RichField + Extendable<D>, const D: usize> Gate<F, D>
|
||||
constraints
|
||||
}
|
||||
|
||||
fn generators(
|
||||
&self,
|
||||
gate_index: usize,
|
||||
_local_constants: &[F],
|
||||
) -> Vec<Box<dyn WitnessGenerator<F>>> {
|
||||
fn generators(&self, row: usize, _local_constants: &[F]) -> Vec<Box<dyn WitnessGenerator<F>>> {
|
||||
let gen = InterpolationGenerator::<F, D> {
|
||||
gate_index,
|
||||
row,
|
||||
gate: *self,
|
||||
_phantom: PhantomData,
|
||||
};
|
||||
@ -205,7 +201,7 @@ impl<F: RichField + Extendable<D>, const D: usize> Gate<F, D>
|
||||
|
||||
#[derive(Debug)]
|
||||
struct InterpolationGenerator<F: RichField + Extendable<D>, const D: usize> {
|
||||
gate_index: usize,
|
||||
row: usize,
|
||||
gate: HighDegreeInterpolationGate<F, D>,
|
||||
_phantom: PhantomData<F>,
|
||||
}
|
||||
@ -216,7 +212,7 @@ impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F>
|
||||
fn dependencies(&self) -> Vec<Target> {
|
||||
let local_target = |column| {
|
||||
Target::Wire(Wire {
|
||||
row: self.gate_index,
|
||||
row: self.row,
|
||||
column,
|
||||
})
|
||||
};
|
||||
@ -236,7 +232,7 @@ 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 = |column| Wire {
|
||||
row: self.gate_index,
|
||||
row: self.row,
|
||||
column,
|
||||
};
|
||||
|
||||
|
||||
@ -261,13 +261,9 @@ impl<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for LowDegreeInter
|
||||
constraints
|
||||
}
|
||||
|
||||
fn generators(
|
||||
&self,
|
||||
gate_index: usize,
|
||||
_local_constants: &[F],
|
||||
) -> Vec<Box<dyn WitnessGenerator<F>>> {
|
||||
fn generators(&self, row: usize, _local_constants: &[F]) -> Vec<Box<dyn WitnessGenerator<F>>> {
|
||||
let gen = InterpolationGenerator::<F, D> {
|
||||
gate_index,
|
||||
row,
|
||||
gate: *self,
|
||||
_phantom: PhantomData,
|
||||
};
|
||||
@ -296,7 +292,7 @@ impl<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for LowDegreeInter
|
||||
|
||||
#[derive(Debug)]
|
||||
struct InterpolationGenerator<F: RichField + Extendable<D>, const D: usize> {
|
||||
gate_index: usize,
|
||||
row: usize,
|
||||
gate: LowDegreeInterpolationGate<F, D>,
|
||||
_phantom: PhantomData<F>,
|
||||
}
|
||||
@ -307,7 +303,7 @@ impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F>
|
||||
fn dependencies(&self) -> Vec<Target> {
|
||||
let local_target = |column| {
|
||||
Target::Wire(Wire {
|
||||
row: self.gate_index,
|
||||
row: self.row,
|
||||
column,
|
||||
})
|
||||
};
|
||||
@ -327,7 +323,7 @@ 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 = |column| Wire {
|
||||
row: self.gate_index,
|
||||
row: self.row,
|
||||
column,
|
||||
};
|
||||
|
||||
@ -373,7 +369,7 @@ impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F>
|
||||
.skip(2)
|
||||
{
|
||||
out_buffer.set_extension_target(
|
||||
ExtensionTarget::from_range(self.gate_index, self.gate.powers_evaluation_point(i)),
|
||||
ExtensionTarget::from_range(self.row, self.gate.powers_evaluation_point(i)),
|
||||
power,
|
||||
);
|
||||
}
|
||||
|
||||
@ -108,16 +108,12 @@ impl<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for MulExtensionGa
|
||||
constraints
|
||||
}
|
||||
|
||||
fn generators(
|
||||
&self,
|
||||
gate_index: usize,
|
||||
local_constants: &[F],
|
||||
) -> Vec<Box<dyn WitnessGenerator<F>>> {
|
||||
fn generators(&self, row: usize, local_constants: &[F]) -> Vec<Box<dyn WitnessGenerator<F>>> {
|
||||
(0..self.num_ops)
|
||||
.map(|i| {
|
||||
let g: Box<dyn WitnessGenerator<F>> = Box::new(
|
||||
MulExtensionGenerator {
|
||||
gate_index,
|
||||
row,
|
||||
const_0: local_constants[0],
|
||||
i,
|
||||
}
|
||||
@ -147,7 +143,7 @@ impl<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for MulExtensionGa
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
struct MulExtensionGenerator<F: RichField + Extendable<D>, const D: usize> {
|
||||
gate_index: usize,
|
||||
row: usize,
|
||||
const_0: F,
|
||||
i: usize,
|
||||
}
|
||||
@ -158,13 +154,13 @@ impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F>
|
||||
fn dependencies(&self) -> Vec<Target> {
|
||||
MulExtensionGate::<D>::wires_ith_multiplicand_0(self.i)
|
||||
.chain(MulExtensionGate::<D>::wires_ith_multiplicand_1(self.i))
|
||||
.map(|i| Target::wire(self.gate_index, i))
|
||||
.map(|i| Target::wire(self.row, i))
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn run_once(&self, witness: &PartitionWitness<F>, out_buffer: &mut GeneratedValues<F>) {
|
||||
let extract_extension = |range: Range<usize>| -> F::Extension {
|
||||
let t = ExtensionTarget::from_range(self.gate_index, range);
|
||||
let t = ExtensionTarget::from_range(self.row, range);
|
||||
witness.get_extension_target(t)
|
||||
};
|
||||
|
||||
@ -173,10 +169,8 @@ impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F>
|
||||
let multiplicand_1 =
|
||||
extract_extension(MulExtensionGate::<D>::wires_ith_multiplicand_1(self.i));
|
||||
|
||||
let output_target = ExtensionTarget::from_range(
|
||||
self.gate_index,
|
||||
MulExtensionGate::<D>::wires_ith_output(self.i),
|
||||
);
|
||||
let output_target =
|
||||
ExtensionTarget::from_range(self.row, MulExtensionGate::<D>::wires_ith_output(self.i));
|
||||
|
||||
let computed_output = (multiplicand_0 * multiplicand_1).scalar_mul(self.const_0);
|
||||
|
||||
|
||||
@ -31,11 +31,7 @@ impl<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for NoopGate {
|
||||
Vec::new()
|
||||
}
|
||||
|
||||
fn generators(
|
||||
&self,
|
||||
_gate_index: usize,
|
||||
_local_constants: &[F],
|
||||
) -> Vec<Box<dyn WitnessGenerator<F>>> {
|
||||
fn generators(&self, _row: usize, _local_constants: &[F]) -> Vec<Box<dyn WitnessGenerator<F>>> {
|
||||
Vec::new()
|
||||
}
|
||||
|
||||
|
||||
@ -374,13 +374,9 @@ impl<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for PoseidonGate<F
|
||||
constraints
|
||||
}
|
||||
|
||||
fn generators(
|
||||
&self,
|
||||
gate_index: usize,
|
||||
_local_constants: &[F],
|
||||
) -> Vec<Box<dyn WitnessGenerator<F>>> {
|
||||
fn generators(&self, row: usize, _local_constants: &[F]) -> Vec<Box<dyn WitnessGenerator<F>>> {
|
||||
let gen = PoseidonGenerator::<F, D> {
|
||||
gate_index,
|
||||
row,
|
||||
_phantom: PhantomData,
|
||||
};
|
||||
vec![Box::new(gen.adapter())]
|
||||
@ -409,7 +405,7 @@ impl<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for PoseidonGate<F
|
||||
|
||||
#[derive(Debug)]
|
||||
struct PoseidonGenerator<F: RichField + Extendable<D> + Poseidon, const D: usize> {
|
||||
gate_index: usize,
|
||||
row: usize,
|
||||
_phantom: PhantomData<F>,
|
||||
}
|
||||
|
||||
@ -420,13 +416,13 @@ impl<F: RichField + Extendable<D> + Poseidon, const D: usize> SimpleGenerator<F>
|
||||
(0..SPONGE_WIDTH)
|
||||
.map(|i| PoseidonGate::<F, D>::wire_input(i))
|
||||
.chain(Some(PoseidonGate::<F, D>::WIRE_SWAP))
|
||||
.map(|column| Target::wire(self.gate_index, column))
|
||||
.map(|column| Target::wire(self.row, column))
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn run_once(&self, witness: &PartitionWitness<F>, out_buffer: &mut GeneratedValues<F>) {
|
||||
let local_wire = |column| Wire {
|
||||
row: self.gate_index,
|
||||
row: self.row,
|
||||
column,
|
||||
};
|
||||
|
||||
@ -559,7 +555,7 @@ mod tests {
|
||||
let mut builder = CircuitBuilder::new(config);
|
||||
type Gate = PoseidonGate<F, D>;
|
||||
let gate = Gate::new();
|
||||
let gate_index = builder.add_gate(gate, vec![]);
|
||||
let row = builder.add_gate(gate, vec![]);
|
||||
let circuit = builder.build_prover::<C>();
|
||||
|
||||
let permutation_inputs = (0..SPONGE_WIDTH)
|
||||
@ -569,7 +565,7 @@ mod tests {
|
||||
let mut inputs = PartialWitness::new();
|
||||
inputs.set_wire(
|
||||
Wire {
|
||||
row: gate_index,
|
||||
row,
|
||||
column: Gate::WIRE_SWAP,
|
||||
},
|
||||
F::ZERO,
|
||||
@ -577,7 +573,7 @@ mod tests {
|
||||
for i in 0..SPONGE_WIDTH {
|
||||
inputs.set_wire(
|
||||
Wire {
|
||||
row: gate_index,
|
||||
row,
|
||||
column: Gate::wire_input(i),
|
||||
},
|
||||
permutation_inputs[i],
|
||||
|
||||
@ -181,12 +181,8 @@ impl<F: RichField + Extendable<D> + Poseidon, const D: usize> Gate<F, D> for Pos
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn generators(
|
||||
&self,
|
||||
gate_index: usize,
|
||||
_local_constants: &[F],
|
||||
) -> Vec<Box<dyn WitnessGenerator<F>>> {
|
||||
let gen = PoseidonMdsGenerator::<D> { gate_index };
|
||||
fn generators(&self, row: usize, _local_constants: &[F]) -> Vec<Box<dyn WitnessGenerator<F>>> {
|
||||
let gen = PoseidonMdsGenerator::<D> { row };
|
||||
vec![Box::new(gen.adapter())]
|
||||
}
|
||||
|
||||
@ -209,7 +205,7 @@ impl<F: RichField + Extendable<D> + Poseidon, const D: usize> Gate<F, D> for Pos
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
struct PoseidonMdsGenerator<const D: usize> {
|
||||
gate_index: usize,
|
||||
row: usize,
|
||||
}
|
||||
|
||||
impl<F: RichField + Extendable<D> + Poseidon, const D: usize> SimpleGenerator<F>
|
||||
@ -218,14 +214,13 @@ impl<F: RichField + Extendable<D> + Poseidon, const D: usize> SimpleGenerator<F>
|
||||
fn dependencies(&self) -> Vec<Target> {
|
||||
(0..SPONGE_WIDTH)
|
||||
.flat_map(|i| {
|
||||
Target::wires_from_range(self.gate_index, PoseidonMdsGate::<F, D>::wires_input(i))
|
||||
Target::wires_from_range(self.row, PoseidonMdsGate::<F, D>::wires_input(i))
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn run_once(&self, witness: &PartitionWitness<F>, out_buffer: &mut GeneratedValues<F>) {
|
||||
let get_local_get_target =
|
||||
|wire_range| ExtensionTarget::from_range(self.gate_index, wire_range);
|
||||
let get_local_get_target = |wire_range| ExtensionTarget::from_range(self.row, wire_range);
|
||||
let get_local_ext =
|
||||
|wire_range| witness.get_extension_target(get_local_get_target(wire_range));
|
||||
|
||||
|
||||
@ -62,11 +62,7 @@ impl<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for PublicInputGat
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn generators(
|
||||
&self,
|
||||
_gate_index: usize,
|
||||
_local_constants: &[F],
|
||||
) -> Vec<Box<dyn WitnessGenerator<F>>> {
|
||||
fn generators(&self, _row: usize, _local_constants: &[F]) -> Vec<Box<dyn WitnessGenerator<F>>> {
|
||||
Vec::new()
|
||||
}
|
||||
|
||||
|
||||
@ -216,16 +216,12 @@ impl<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for RandomAccessGa
|
||||
constraints
|
||||
}
|
||||
|
||||
fn generators(
|
||||
&self,
|
||||
gate_index: usize,
|
||||
_local_constants: &[F],
|
||||
) -> Vec<Box<dyn WitnessGenerator<F>>> {
|
||||
fn generators(&self, row: usize, _local_constants: &[F]) -> Vec<Box<dyn WitnessGenerator<F>>> {
|
||||
(0..self.num_copies)
|
||||
.map(|copy| {
|
||||
let g: Box<dyn WitnessGenerator<F>> = Box::new(
|
||||
RandomAccessGenerator {
|
||||
gate_index,
|
||||
row,
|
||||
gate: *self,
|
||||
copy,
|
||||
}
|
||||
@ -309,7 +305,7 @@ impl<F: RichField + Extendable<D>, const D: usize> PackedEvaluableBase<F, D>
|
||||
|
||||
#[derive(Debug)]
|
||||
struct RandomAccessGenerator<F: RichField + Extendable<D>, const D: usize> {
|
||||
gate_index: usize,
|
||||
row: usize,
|
||||
gate: RandomAccessGate<F, D>,
|
||||
copy: usize,
|
||||
}
|
||||
@ -318,7 +314,7 @@ impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F>
|
||||
for RandomAccessGenerator<F, D>
|
||||
{
|
||||
fn dependencies(&self) -> Vec<Target> {
|
||||
let local_target = |column| Target::wire(self.gate_index, column);
|
||||
let local_target = |column| Target::wire(self.row, column);
|
||||
|
||||
let mut deps = vec![local_target(self.gate.wire_access_index(self.copy))];
|
||||
for i in 0..self.gate.vec_size() {
|
||||
@ -329,7 +325,7 @@ 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 = |column| Wire {
|
||||
row: self.gate_index,
|
||||
row: self.row,
|
||||
column,
|
||||
};
|
||||
|
||||
|
||||
@ -135,14 +135,10 @@ impl<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for ReducingGate<D
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn generators(
|
||||
&self,
|
||||
gate_index: usize,
|
||||
_local_constants: &[F],
|
||||
) -> Vec<Box<dyn WitnessGenerator<F>>> {
|
||||
fn generators(&self, row: usize, _local_constants: &[F]) -> Vec<Box<dyn WitnessGenerator<F>>> {
|
||||
vec![Box::new(
|
||||
ReducingGenerator {
|
||||
gate_index,
|
||||
row,
|
||||
gate: self.clone(),
|
||||
}
|
||||
.adapter(),
|
||||
@ -168,7 +164,7 @@ impl<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for ReducingGate<D
|
||||
|
||||
#[derive(Debug)]
|
||||
struct ReducingGenerator<const D: usize> {
|
||||
gate_index: usize,
|
||||
row: usize,
|
||||
gate: ReducingGate<D>,
|
||||
}
|
||||
|
||||
@ -177,13 +173,13 @@ impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F> for Reduci
|
||||
ReducingGate::<D>::wires_alpha()
|
||||
.chain(ReducingGate::<D>::wires_old_acc())
|
||||
.chain(self.gate.wires_coeffs())
|
||||
.map(|i| Target::wire(self.gate_index, i))
|
||||
.map(|i| Target::wire(self.row, i))
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn run_once(&self, witness: &PartitionWitness<F>, out_buffer: &mut GeneratedValues<F>) {
|
||||
let extract_extension = |range: Range<usize>| -> F::Extension {
|
||||
let t = ExtensionTarget::from_range(self.gate_index, range);
|
||||
let t = ExtensionTarget::from_range(self.row, range);
|
||||
witness.get_extension_target(t)
|
||||
};
|
||||
|
||||
@ -193,14 +189,13 @@ impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F> for Reduci
|
||||
&self
|
||||
.gate
|
||||
.wires_coeffs()
|
||||
.map(|i| Target::wire(self.gate_index, i))
|
||||
.map(|i| Target::wire(self.row, i))
|
||||
.collect::<Vec<_>>(),
|
||||
);
|
||||
let accs = (0..self.gate.num_coeffs)
|
||||
.map(|i| ExtensionTarget::from_range(self.gate_index, self.gate.wires_accs(i)))
|
||||
.map(|i| ExtensionTarget::from_range(self.row, self.gate.wires_accs(i)))
|
||||
.collect::<Vec<_>>();
|
||||
let output =
|
||||
ExtensionTarget::from_range(self.gate_index, ReducingGate::<D>::wires_output());
|
||||
let output = ExtensionTarget::from_range(self.row, ReducingGate::<D>::wires_output());
|
||||
|
||||
let mut acc = old_acc;
|
||||
for i in 0..self.gate.num_coeffs {
|
||||
|
||||
@ -135,14 +135,10 @@ impl<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for ReducingExtens
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn generators(
|
||||
&self,
|
||||
gate_index: usize,
|
||||
_local_constants: &[F],
|
||||
) -> Vec<Box<dyn WitnessGenerator<F>>> {
|
||||
fn generators(&self, row: usize, _local_constants: &[F]) -> Vec<Box<dyn WitnessGenerator<F>>> {
|
||||
vec![Box::new(
|
||||
ReducingGenerator {
|
||||
gate_index,
|
||||
row,
|
||||
gate: self.clone(),
|
||||
}
|
||||
.adapter(),
|
||||
@ -168,7 +164,7 @@ impl<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for ReducingExtens
|
||||
|
||||
#[derive(Debug)]
|
||||
struct ReducingGenerator<const D: usize> {
|
||||
gate_index: usize,
|
||||
row: usize,
|
||||
gate: ReducingExtensionGate<D>,
|
||||
}
|
||||
|
||||
@ -177,13 +173,13 @@ impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F> for Reduci
|
||||
ReducingExtensionGate::<D>::wires_alpha()
|
||||
.chain(ReducingExtensionGate::<D>::wires_old_acc())
|
||||
.chain((0..self.gate.num_coeffs).flat_map(ReducingExtensionGate::<D>::wires_coeff))
|
||||
.map(|i| Target::wire(self.gate_index, i))
|
||||
.map(|i| Target::wire(self.row, i))
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn run_once(&self, witness: &PartitionWitness<F>, out_buffer: &mut GeneratedValues<F>) {
|
||||
let local_extension = |range: Range<usize>| -> F::Extension {
|
||||
let t = ExtensionTarget::from_range(self.gate_index, range);
|
||||
let t = ExtensionTarget::from_range(self.row, range);
|
||||
witness.get_extension_target(t)
|
||||
};
|
||||
|
||||
@ -193,7 +189,7 @@ impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F> for Reduci
|
||||
.map(|i| local_extension(ReducingExtensionGate::<D>::wires_coeff(i)))
|
||||
.collect::<Vec<_>>();
|
||||
let accs = (0..self.gate.num_coeffs)
|
||||
.map(|i| ExtensionTarget::from_range(self.gate_index, self.gate.wires_accs(i)))
|
||||
.map(|i| ExtensionTarget::from_range(self.row, self.gate.wires_accs(i)))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let mut acc = old_acc;
|
||||
|
||||
@ -52,9 +52,9 @@ impl<const D: usize> ExtensionTarget<D> {
|
||||
res.try_into().unwrap()
|
||||
}
|
||||
|
||||
pub fn from_range(gate: usize, range: Range<usize>) -> Self {
|
||||
pub fn from_range(row: usize, range: Range<usize>) -> Self {
|
||||
debug_assert_eq!(range.end - range.start, D);
|
||||
Target::wires_from_range(gate, range).try_into().unwrap()
|
||||
Target::wires_from_range(row, range).try_into().unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -306,7 +306,7 @@ impl<F: Field> SimpleGenerator<F> for NonzeroTestGenerator {
|
||||
/// Generator used to fill an extra constant.
|
||||
#[derive(Debug, Clone)]
|
||||
pub(crate) struct ConstantGenerator<F: Field> {
|
||||
pub gate_index: usize,
|
||||
pub row: usize,
|
||||
pub constant_index: usize,
|
||||
pub wire_index: usize,
|
||||
pub constant: F,
|
||||
@ -324,9 +324,6 @@ impl<F: Field> SimpleGenerator<F> for ConstantGenerator<F> {
|
||||
}
|
||||
|
||||
fn run_once(&self, _witness: &PartitionWitness<F>, out_buffer: &mut GeneratedValues<F>) {
|
||||
out_buffer.set_target(
|
||||
Target::wire(self.gate_index, self.wire_index),
|
||||
self.constant,
|
||||
);
|
||||
out_buffer.set_target(Target::wire(self.row, self.wire_index), self.constant);
|
||||
}
|
||||
}
|
||||
|
||||
@ -27,8 +27,8 @@ impl Target {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn wires_from_range(gate: usize, range: Range<usize>) -> Vec<Self> {
|
||||
range.map(|i| Self::wire(gate, i)).collect()
|
||||
pub fn wires_from_range(row: usize, range: Range<usize>) -> Vec<Self> {
|
||||
range.map(|i| Self::wire(row, i)).collect()
|
||||
}
|
||||
|
||||
pub fn index(&self, num_wires: usize, degree: usize) -> usize {
|
||||
|
||||
@ -218,12 +218,12 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||
);
|
||||
constants.resize(gate_type.num_constants(), F::ZERO);
|
||||
|
||||
let gate_index = self.gate_instances.len();
|
||||
let row = self.gate_instances.len();
|
||||
|
||||
self.constant_generators
|
||||
.extend(gate_type.extra_constant_wires().into_iter().map(
|
||||
|(constant_index, wire_index)| ConstantGenerator {
|
||||
gate_index,
|
||||
row,
|
||||
constant_index,
|
||||
wire_index,
|
||||
constant: F::ZERO, // Placeholder; will be replaced later.
|
||||
@ -243,7 +243,7 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||
constants,
|
||||
});
|
||||
|
||||
gate_index
|
||||
row
|
||||
}
|
||||
|
||||
fn check_gate_compatibility<G: Gate<F, D>>(&self, gate: &G) {
|
||||
@ -400,7 +400,7 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||
})
|
||||
}
|
||||
|
||||
/// Find an available slot, of the form `(gate_index, op)` for gate `G` using parameters `params`
|
||||
/// Find an available slot, of the form `(row, op)` for gate `G` using parameters `params`
|
||||
/// and constants `constants`. Parameters are any data used to differentiate which gate should be
|
||||
/// used for the given operation.
|
||||
pub fn find_slot<G: Gate<F, D> + Clone>(
|
||||
@ -524,13 +524,10 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||
// For each "regular" blinding factor, we simply add a no-op gate, and insert a random value
|
||||
// for each wire.
|
||||
for _ in 0..regular_poly_openings {
|
||||
let gate = self.add_gate(NoopGate, vec![]);
|
||||
let row = self.add_gate(NoopGate, vec![]);
|
||||
for w in 0..num_wires {
|
||||
self.add_simple_generator(RandomValueGenerator {
|
||||
target: Target::Wire(Wire {
|
||||
row: gate,
|
||||
column: w,
|
||||
}),
|
||||
target: Target::Wire(Wire { row, column: w }),
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -683,9 +680,9 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||
.zip(self.constant_generators.clone())
|
||||
{
|
||||
// Set the constant in the constant polynomial.
|
||||
self.gate_instances[const_gen.gate_index].constants[const_gen.constant_index] = c;
|
||||
self.gate_instances[const_gen.row].constants[const_gen.constant_index] = c;
|
||||
// Generate a copy between the target and the routable wire.
|
||||
self.connect(Target::wire(const_gen.gate_index, const_gen.wire_index), t);
|
||||
self.connect(Target::wire(const_gen.row, const_gen.wire_index), t);
|
||||
// Set the constant in the generator (it's initially set with a dummy value).
|
||||
const_gen.set_constant(c);
|
||||
self.add_simple_generator(const_gen);
|
||||
|
||||
@ -155,21 +155,21 @@ impl<const D: usize> ReducingFactorTarget<D> {
|
||||
reversed_terms.reverse();
|
||||
for chunk in reversed_terms.chunks_exact(max_coeffs_len) {
|
||||
let gate = ReducingGate::new(max_coeffs_len);
|
||||
let gate_index = builder.add_gate(gate.clone(), vec![]);
|
||||
let row = builder.add_gate(gate.clone(), vec![]);
|
||||
|
||||
builder.connect_extension(
|
||||
self.base,
|
||||
ExtensionTarget::from_range(gate_index, ReducingGate::<D>::wires_alpha()),
|
||||
ExtensionTarget::from_range(row, ReducingGate::<D>::wires_alpha()),
|
||||
);
|
||||
builder.connect_extension(
|
||||
acc,
|
||||
ExtensionTarget::from_range(gate_index, ReducingGate::<D>::wires_old_acc()),
|
||||
ExtensionTarget::from_range(row, ReducingGate::<D>::wires_old_acc()),
|
||||
);
|
||||
for (&t, c) in chunk.iter().zip(gate.wires_coeffs()) {
|
||||
builder.connect(t, Target::wire(gate_index, c));
|
||||
builder.connect(t, Target::wire(row, c));
|
||||
}
|
||||
|
||||
acc = ExtensionTarget::from_range(gate_index, ReducingGate::<D>::wires_output());
|
||||
acc = ExtensionTarget::from_range(row, ReducingGate::<D>::wires_output());
|
||||
}
|
||||
|
||||
acc
|
||||
@ -205,31 +205,24 @@ impl<const D: usize> ReducingFactorTarget<D> {
|
||||
reversed_terms.reverse();
|
||||
for chunk in reversed_terms.chunks_exact(max_coeffs_len) {
|
||||
let gate = ReducingExtensionGate::new(max_coeffs_len);
|
||||
let gate_index = builder.add_gate(gate.clone(), vec![]);
|
||||
let row = builder.add_gate(gate.clone(), vec![]);
|
||||
|
||||
builder.connect_extension(
|
||||
self.base,
|
||||
ExtensionTarget::from_range(gate_index, ReducingExtensionGate::<D>::wires_alpha()),
|
||||
ExtensionTarget::from_range(row, ReducingExtensionGate::<D>::wires_alpha()),
|
||||
);
|
||||
builder.connect_extension(
|
||||
acc,
|
||||
ExtensionTarget::from_range(
|
||||
gate_index,
|
||||
ReducingExtensionGate::<D>::wires_old_acc(),
|
||||
),
|
||||
ExtensionTarget::from_range(row, ReducingExtensionGate::<D>::wires_old_acc()),
|
||||
);
|
||||
for (i, &t) in chunk.iter().enumerate() {
|
||||
builder.connect_extension(
|
||||
t,
|
||||
ExtensionTarget::from_range(
|
||||
gate_index,
|
||||
ReducingExtensionGate::<D>::wires_coeff(i),
|
||||
),
|
||||
ExtensionTarget::from_range(row, ReducingExtensionGate::<D>::wires_coeff(i)),
|
||||
);
|
||||
}
|
||||
|
||||
acc =
|
||||
ExtensionTarget::from_range(gate_index, ReducingExtensionGate::<D>::wires_output());
|
||||
acc = ExtensionTarget::from_range(row, ReducingExtensionGate::<D>::wires_output());
|
||||
}
|
||||
|
||||
acc
|
||||
|
||||
@ -131,26 +131,14 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilderU32<F, D>
|
||||
}
|
||||
|
||||
let gate = U32ArithmeticGate::<F, D>::new_from_config(&self.config);
|
||||
let (gate_index, copy) = self.find_slot(gate, &[], &[]);
|
||||
let (row, copy) = self.find_slot(gate, &[], &[]);
|
||||
|
||||
self.connect(
|
||||
Target::wire(gate_index, gate.wire_ith_multiplicand_0(copy)),
|
||||
x.0,
|
||||
);
|
||||
self.connect(
|
||||
Target::wire(gate_index, gate.wire_ith_multiplicand_1(copy)),
|
||||
y.0,
|
||||
);
|
||||
self.connect(Target::wire(gate_index, gate.wire_ith_addend(copy)), z.0);
|
||||
self.connect(Target::wire(row, gate.wire_ith_multiplicand_0(copy)), x.0);
|
||||
self.connect(Target::wire(row, gate.wire_ith_multiplicand_1(copy)), y.0);
|
||||
self.connect(Target::wire(row, gate.wire_ith_addend(copy)), z.0);
|
||||
|
||||
let output_low = U32Target(Target::wire(
|
||||
gate_index,
|
||||
gate.wire_ith_output_low_half(copy),
|
||||
));
|
||||
let output_high = U32Target(Target::wire(
|
||||
gate_index,
|
||||
gate.wire_ith_output_high_half(copy),
|
||||
));
|
||||
let output_low = U32Target(Target::wire(row, gate.wire_ith_output_low_half(copy)));
|
||||
let output_high = U32Target(Target::wire(row, gate.wire_ith_output_high_half(copy)));
|
||||
|
||||
(output_low, output_high)
|
||||
}
|
||||
@ -168,22 +156,20 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilderU32<F, D>
|
||||
_ => {
|
||||
let num_addends = to_add.len();
|
||||
let gate = U32AddManyGate::<F, D>::new_from_config(&self.config, num_addends);
|
||||
let (gate_index, copy) =
|
||||
let (row, copy) =
|
||||
self.find_slot(gate, &[F::from_canonical_usize(num_addends)], &[]);
|
||||
|
||||
for j in 0..num_addends {
|
||||
self.connect(
|
||||
Target::wire(gate_index, gate.wire_ith_op_jth_addend(copy, j)),
|
||||
Target::wire(row, gate.wire_ith_op_jth_addend(copy, j)),
|
||||
to_add[j].0,
|
||||
);
|
||||
}
|
||||
let zero = self.zero();
|
||||
self.connect(Target::wire(gate_index, gate.wire_ith_carry(copy)), zero);
|
||||
self.connect(Target::wire(row, gate.wire_ith_carry(copy)), zero);
|
||||
|
||||
let output_low =
|
||||
U32Target(Target::wire(gate_index, gate.wire_ith_output_result(copy)));
|
||||
let output_high =
|
||||
U32Target(Target::wire(gate_index, gate.wire_ith_output_carry(copy)));
|
||||
let output_low = U32Target(Target::wire(row, gate.wire_ith_output_result(copy)));
|
||||
let output_high = U32Target(Target::wire(row, gate.wire_ith_output_carry(copy)));
|
||||
|
||||
(output_low, output_high)
|
||||
}
|
||||
@ -202,18 +188,18 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilderU32<F, D>
|
||||
let num_addends = to_add.len();
|
||||
|
||||
let gate = U32AddManyGate::<F, D>::new_from_config(&self.config, num_addends);
|
||||
let (gate_index, copy) = self.find_slot(gate, &[F::from_canonical_usize(num_addends)], &[]);
|
||||
let (row, copy) = self.find_slot(gate, &[F::from_canonical_usize(num_addends)], &[]);
|
||||
|
||||
for j in 0..num_addends {
|
||||
self.connect(
|
||||
Target::wire(gate_index, gate.wire_ith_op_jth_addend(copy, j)),
|
||||
Target::wire(row, gate.wire_ith_op_jth_addend(copy, j)),
|
||||
to_add[j].0,
|
||||
);
|
||||
}
|
||||
self.connect(Target::wire(gate_index, gate.wire_ith_carry(copy)), carry.0);
|
||||
self.connect(Target::wire(row, gate.wire_ith_carry(copy)), carry.0);
|
||||
|
||||
let output = U32Target(Target::wire(gate_index, gate.wire_ith_output_result(copy)));
|
||||
let output_carry = U32Target(Target::wire(gate_index, gate.wire_ith_output_carry(copy)));
|
||||
let output = U32Target(Target::wire(row, gate.wire_ith_output_result(copy)));
|
||||
let output_carry = U32Target(Target::wire(row, gate.wire_ith_output_carry(copy)));
|
||||
|
||||
(output, output_carry)
|
||||
}
|
||||
@ -226,17 +212,17 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilderU32<F, D>
|
||||
// Returns x - y - borrow, as a pair (result, borrow), where borrow is 0 or 1 depending on whether borrowing from the next digit is required (iff y + borrow > x).
|
||||
fn sub_u32(&mut self, x: U32Target, y: U32Target, borrow: U32Target) -> (U32Target, U32Target) {
|
||||
let gate = U32SubtractionGate::<F, D>::new_from_config(&self.config);
|
||||
let (gate_index, copy) = self.find_slot(gate, &[], &[]);
|
||||
let (row, copy) = self.find_slot(gate, &[], &[]);
|
||||
|
||||
self.connect(Target::wire(gate_index, gate.wire_ith_input_x(copy)), x.0);
|
||||
self.connect(Target::wire(gate_index, gate.wire_ith_input_y(copy)), y.0);
|
||||
self.connect(Target::wire(row, gate.wire_ith_input_x(copy)), x.0);
|
||||
self.connect(Target::wire(row, gate.wire_ith_input_y(copy)), y.0);
|
||||
self.connect(
|
||||
Target::wire(gate_index, gate.wire_ith_input_borrow(copy)),
|
||||
Target::wire(row, gate.wire_ith_input_borrow(copy)),
|
||||
borrow.0,
|
||||
);
|
||||
|
||||
let output_result = U32Target(Target::wire(gate_index, gate.wire_ith_output_result(copy)));
|
||||
let output_borrow = U32Target(Target::wire(gate_index, gate.wire_ith_output_borrow(copy)));
|
||||
let output_result = U32Target(Target::wire(row, gate.wire_ith_output_result(copy)));
|
||||
let output_borrow = U32Target(Target::wire(row, gate.wire_ith_output_borrow(copy)));
|
||||
|
||||
(output_result, output_borrow)
|
||||
}
|
||||
|
||||
@ -29,28 +29,28 @@ pub fn list_le_circuit<F: RichField + Extendable<D>, const D: usize>(
|
||||
let mut result = one;
|
||||
for i in 0..n {
|
||||
let a_le_b_gate = ComparisonGate::new(num_bits, num_chunks);
|
||||
let a_le_b_gate_index = builder.add_gate(a_le_b_gate.clone(), vec![]);
|
||||
let a_le_b_row = builder.add_gate(a_le_b_gate.clone(), vec![]);
|
||||
builder.connect(
|
||||
Target::wire(a_le_b_gate_index, a_le_b_gate.wire_first_input()),
|
||||
Target::wire(a_le_b_row, a_le_b_gate.wire_first_input()),
|
||||
a[i],
|
||||
);
|
||||
builder.connect(
|
||||
Target::wire(a_le_b_gate_index, a_le_b_gate.wire_second_input()),
|
||||
Target::wire(a_le_b_row, a_le_b_gate.wire_second_input()),
|
||||
b[i],
|
||||
);
|
||||
let a_le_b_result = Target::wire(a_le_b_gate_index, a_le_b_gate.wire_result_bool());
|
||||
let a_le_b_result = Target::wire(a_le_b_row, a_le_b_gate.wire_result_bool());
|
||||
|
||||
let b_le_a_gate = ComparisonGate::new(num_bits, num_chunks);
|
||||
let b_le_a_gate_index = builder.add_gate(b_le_a_gate.clone(), vec![]);
|
||||
let b_le_a_row = builder.add_gate(b_le_a_gate.clone(), vec![]);
|
||||
builder.connect(
|
||||
Target::wire(b_le_a_gate_index, b_le_a_gate.wire_first_input()),
|
||||
Target::wire(b_le_a_row, b_le_a_gate.wire_first_input()),
|
||||
b[i],
|
||||
);
|
||||
builder.connect(
|
||||
Target::wire(b_le_a_gate_index, b_le_a_gate.wire_second_input()),
|
||||
Target::wire(b_le_a_row, b_le_a_gate.wire_second_input()),
|
||||
a[i],
|
||||
);
|
||||
let b_le_a_result = Target::wire(b_le_a_gate_index, b_le_a_gate.wire_result_bool());
|
||||
let b_le_a_result = Target::wire(b_le_a_row, b_le_a_gate.wire_result_bool());
|
||||
|
||||
let these_limbs_equal = builder.mul(a_le_b_result, b_le_a_result);
|
||||
let these_limbs_less_than = builder.sub(one, b_le_a_result);
|
||||
|
||||
@ -12,12 +12,9 @@ pub fn range_check_u32_circuit<F: RichField + Extendable<D>, const D: usize>(
|
||||
) {
|
||||
let num_input_limbs = vals.len();
|
||||
let gate = U32RangeCheckGate::<F, D>::new(num_input_limbs);
|
||||
let gate_index = builder.add_gate(gate, vec![]);
|
||||
let row = builder.add_gate(gate, vec![]);
|
||||
|
||||
for i in 0..num_input_limbs {
|
||||
builder.connect(
|
||||
Target::wire(gate_index, gate.wire_ith_input_limb(i)),
|
||||
vals[i].0,
|
||||
);
|
||||
builder.connect(Target::wire(row, gate.wire_ith_input_limb(i)), vals[i].0);
|
||||
}
|
||||
}
|
||||
|
||||
@ -232,17 +232,13 @@ impl<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for U32AddManyGate
|
||||
constraints
|
||||
}
|
||||
|
||||
fn generators(
|
||||
&self,
|
||||
gate_index: usize,
|
||||
_local_constants: &[F],
|
||||
) -> Vec<Box<dyn WitnessGenerator<F>>> {
|
||||
fn generators(&self, row: usize, _local_constants: &[F]) -> Vec<Box<dyn WitnessGenerator<F>>> {
|
||||
(0..self.num_ops)
|
||||
.map(|i| {
|
||||
let g: Box<dyn WitnessGenerator<F>> = Box::new(
|
||||
U32AddManyGenerator {
|
||||
gate: *self,
|
||||
gate_index,
|
||||
row,
|
||||
i,
|
||||
_phantom: PhantomData,
|
||||
}
|
||||
@ -273,7 +269,7 @@ impl<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for U32AddManyGate
|
||||
#[derive(Clone, Debug)]
|
||||
struct U32AddManyGenerator<F: RichField + Extendable<D>, const D: usize> {
|
||||
gate: U32AddManyGate<F, D>,
|
||||
gate_index: usize,
|
||||
row: usize,
|
||||
i: usize,
|
||||
_phantom: PhantomData<F>,
|
||||
}
|
||||
@ -282,7 +278,7 @@ impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F>
|
||||
for U32AddManyGenerator<F, D>
|
||||
{
|
||||
fn dependencies(&self) -> Vec<Target> {
|
||||
let local_target = |column| Target::wire(self.gate_index, column);
|
||||
let local_target = |column| Target::wire(self.row, column);
|
||||
|
||||
(0..self.gate.num_addends)
|
||||
.map(|j| local_target(self.gate.wire_ith_op_jth_addend(self.i, j)))
|
||||
@ -292,7 +288,7 @@ 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 = |column| Wire {
|
||||
row: self.gate_index,
|
||||
row: self.row,
|
||||
column,
|
||||
};
|
||||
|
||||
|
||||
@ -193,17 +193,13 @@ impl<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for U32ArithmeticG
|
||||
constraints
|
||||
}
|
||||
|
||||
fn generators(
|
||||
&self,
|
||||
gate_index: usize,
|
||||
_local_constants: &[F],
|
||||
) -> Vec<Box<dyn WitnessGenerator<F>>> {
|
||||
fn generators(&self, row: usize, _local_constants: &[F]) -> Vec<Box<dyn WitnessGenerator<F>>> {
|
||||
(0..self.num_ops)
|
||||
.map(|i| {
|
||||
let g: Box<dyn WitnessGenerator<F>> = Box::new(
|
||||
U32ArithmeticGenerator {
|
||||
gate: *self,
|
||||
gate_index,
|
||||
row,
|
||||
i,
|
||||
_phantom: PhantomData,
|
||||
}
|
||||
@ -281,7 +277,7 @@ impl<F: RichField + Extendable<D>, const D: usize> PackedEvaluableBase<F, D>
|
||||
#[derive(Clone, Debug)]
|
||||
struct U32ArithmeticGenerator<F: RichField + Extendable<D>, const D: usize> {
|
||||
gate: U32ArithmeticGate<F, D>,
|
||||
gate_index: usize,
|
||||
row: usize,
|
||||
i: usize,
|
||||
_phantom: PhantomData<F>,
|
||||
}
|
||||
@ -290,7 +286,7 @@ impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F>
|
||||
for U32ArithmeticGenerator<F, D>
|
||||
{
|
||||
fn dependencies(&self) -> Vec<Target> {
|
||||
let local_target = |column| Target::wire(self.gate_index, column);
|
||||
let local_target = |column| Target::wire(self.row, column);
|
||||
|
||||
vec![
|
||||
local_target(self.gate.wire_ith_multiplicand_0(self.i)),
|
||||
@ -301,7 +297,7 @@ 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 = |column| Wire {
|
||||
row: self.gate_index,
|
||||
row: self.row,
|
||||
column,
|
||||
};
|
||||
|
||||
|
||||
@ -283,13 +283,9 @@ impl<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for ComparisonGate
|
||||
constraints
|
||||
}
|
||||
|
||||
fn generators(
|
||||
&self,
|
||||
gate_index: usize,
|
||||
_local_constants: &[F],
|
||||
) -> Vec<Box<dyn WitnessGenerator<F>>> {
|
||||
fn generators(&self, row: usize, _local_constants: &[F]) -> Vec<Box<dyn WitnessGenerator<F>>> {
|
||||
let gen = ComparisonGenerator::<F, D> {
|
||||
gate_index,
|
||||
row,
|
||||
gate: self.clone(),
|
||||
};
|
||||
vec![Box::new(gen.adapter())]
|
||||
@ -397,7 +393,7 @@ impl<F: RichField + Extendable<D>, const D: usize> PackedEvaluableBase<F, D>
|
||||
|
||||
#[derive(Debug)]
|
||||
struct ComparisonGenerator<F: RichField + Extendable<D>, const D: usize> {
|
||||
gate_index: usize,
|
||||
row: usize,
|
||||
gate: ComparisonGate<F, D>,
|
||||
}
|
||||
|
||||
@ -405,7 +401,7 @@ impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F>
|
||||
for ComparisonGenerator<F, D>
|
||||
{
|
||||
fn dependencies(&self) -> Vec<Target> {
|
||||
let local_target = |column| Target::wire(self.gate_index, column);
|
||||
let local_target = |column| Target::wire(self.row, column);
|
||||
|
||||
vec![
|
||||
local_target(self.gate.wire_first_input()),
|
||||
@ -415,7 +411,7 @@ 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 = |column| Wire {
|
||||
row: self.gate_index,
|
||||
row: self.row,
|
||||
column,
|
||||
};
|
||||
|
||||
|
||||
@ -134,15 +134,8 @@ impl<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for U32RangeCheckG
|
||||
constraints
|
||||
}
|
||||
|
||||
fn generators(
|
||||
&self,
|
||||
gate_index: usize,
|
||||
_local_constants: &[F],
|
||||
) -> Vec<Box<dyn WitnessGenerator<F>>> {
|
||||
let gen = U32RangeCheckGenerator {
|
||||
gate: *self,
|
||||
gate_index,
|
||||
};
|
||||
fn generators(&self, row: usize, _local_constants: &[F]) -> Vec<Box<dyn WitnessGenerator<F>>> {
|
||||
let gen = U32RangeCheckGenerator { gate: *self, row };
|
||||
vec![Box::new(gen.adapter())]
|
||||
}
|
||||
|
||||
@ -168,7 +161,7 @@ impl<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for U32RangeCheckG
|
||||
#[derive(Debug)]
|
||||
pub struct U32RangeCheckGenerator<F: RichField + Extendable<D>, const D: usize> {
|
||||
gate: U32RangeCheckGate<F, D>,
|
||||
gate_index: usize,
|
||||
row: usize,
|
||||
}
|
||||
|
||||
impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F>
|
||||
@ -177,7 +170,7 @@ impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F>
|
||||
fn dependencies(&self) -> Vec<Target> {
|
||||
let num_input_limbs = self.gate.num_input_limbs;
|
||||
(0..num_input_limbs)
|
||||
.map(|i| Target::wire(self.gate_index, self.gate.wire_ith_input_limb(i)))
|
||||
.map(|i| Target::wire(self.row, self.gate.wire_ith_input_limb(i)))
|
||||
.collect()
|
||||
}
|
||||
|
||||
@ -185,19 +178,12 @@ impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F>
|
||||
let num_input_limbs = self.gate.num_input_limbs;
|
||||
for i in 0..num_input_limbs {
|
||||
let sum_value = witness
|
||||
.get_target(Target::wire(
|
||||
self.gate_index,
|
||||
self.gate.wire_ith_input_limb(i),
|
||||
))
|
||||
.get_target(Target::wire(self.row, self.gate.wire_ith_input_limb(i)))
|
||||
.to_canonical_u64() as u32;
|
||||
|
||||
let base = U32RangeCheckGate::<F, D>::BASE as u32;
|
||||
let limbs = (0..self.gate.aux_limbs_per_input_limb()).map(|j| {
|
||||
Target::wire(
|
||||
self.gate_index,
|
||||
self.gate.wire_ith_input_limb_jth_aux_limb(i, j),
|
||||
)
|
||||
});
|
||||
let limbs = (0..self.gate.aux_limbs_per_input_limb())
|
||||
.map(|j| Target::wire(self.row, self.gate.wire_ith_input_limb_jth_aux_limb(i, j)));
|
||||
let limbs_value = (0..self.gate.aux_limbs_per_input_limb())
|
||||
.scan(sum_value, |acc, _| {
|
||||
let tmp = *acc % base;
|
||||
|
||||
@ -182,17 +182,13 @@ impl<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for U32Subtraction
|
||||
constraints
|
||||
}
|
||||
|
||||
fn generators(
|
||||
&self,
|
||||
gate_index: usize,
|
||||
_local_constants: &[F],
|
||||
) -> Vec<Box<dyn WitnessGenerator<F>>> {
|
||||
fn generators(&self, row: usize, _local_constants: &[F]) -> Vec<Box<dyn WitnessGenerator<F>>> {
|
||||
(0..self.num_ops)
|
||||
.map(|i| {
|
||||
let g: Box<dyn WitnessGenerator<F>> = Box::new(
|
||||
U32SubtractionGenerator {
|
||||
gate: *self,
|
||||
gate_index,
|
||||
row,
|
||||
i,
|
||||
_phantom: PhantomData,
|
||||
}
|
||||
@ -265,7 +261,7 @@ impl<F: RichField + Extendable<D>, const D: usize> PackedEvaluableBase<F, D>
|
||||
#[derive(Clone, Debug)]
|
||||
struct U32SubtractionGenerator<F: RichField + Extendable<D>, const D: usize> {
|
||||
gate: U32SubtractionGate<F, D>,
|
||||
gate_index: usize,
|
||||
row: usize,
|
||||
i: usize,
|
||||
_phantom: PhantomData<F>,
|
||||
}
|
||||
@ -274,7 +270,7 @@ impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F>
|
||||
for U32SubtractionGenerator<F, D>
|
||||
{
|
||||
fn dependencies(&self) -> Vec<Target> {
|
||||
let local_target = |column| Target::wire(self.gate_index, column);
|
||||
let local_target = |column| Target::wire(self.row, column);
|
||||
|
||||
vec![
|
||||
local_target(self.gate.wire_ith_input_x(self.i)),
|
||||
@ -285,7 +281,7 @@ 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 = |column| Wire {
|
||||
row: self.gate_index,
|
||||
row: self.row,
|
||||
column,
|
||||
};
|
||||
|
||||
|
||||
@ -154,15 +154,11 @@ impl<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for SwitchGate<F,
|
||||
constraints
|
||||
}
|
||||
|
||||
fn generators(
|
||||
&self,
|
||||
gate_index: usize,
|
||||
_local_constants: &[F],
|
||||
) -> Vec<Box<dyn WitnessGenerator<F>>> {
|
||||
fn generators(&self, row: usize, _local_constants: &[F]) -> Vec<Box<dyn WitnessGenerator<F>>> {
|
||||
(0..self.num_copies)
|
||||
.map(|c| {
|
||||
let g: Box<dyn WitnessGenerator<F>> = Box::new(SwitchGenerator::<F, D> {
|
||||
gate_index,
|
||||
row,
|
||||
gate: *self,
|
||||
copy: c,
|
||||
});
|
||||
@ -215,14 +211,14 @@ impl<F: RichField + Extendable<D>, const D: usize> PackedEvaluableBase<F, D> for
|
||||
|
||||
#[derive(Debug)]
|
||||
struct SwitchGenerator<F: RichField + Extendable<D>, const D: usize> {
|
||||
gate_index: usize,
|
||||
row: usize,
|
||||
gate: SwitchGate<F, D>,
|
||||
copy: usize,
|
||||
}
|
||||
|
||||
impl<F: RichField + Extendable<D>, const D: usize> SwitchGenerator<F, D> {
|
||||
fn in_out_dependencies(&self) -> Vec<Target> {
|
||||
let local_target = |column| Target::wire(self.gate_index, column);
|
||||
let local_target = |column| Target::wire(self.row, column);
|
||||
|
||||
let mut deps = Vec::new();
|
||||
for e in 0..self.gate.chunk_size {
|
||||
@ -236,7 +232,7 @@ impl<F: RichField + Extendable<D>, const D: usize> SwitchGenerator<F, D> {
|
||||
}
|
||||
|
||||
fn in_switch_dependencies(&self) -> Vec<Target> {
|
||||
let local_target = |column| Target::wire(self.gate_index, column);
|
||||
let local_target = |column| Target::wire(self.row, column);
|
||||
|
||||
let mut deps = Vec::new();
|
||||
for e in 0..self.gate.chunk_size {
|
||||
@ -250,7 +246,7 @@ 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 = |column| Wire {
|
||||
row: self.gate_index,
|
||||
row: self.row,
|
||||
column,
|
||||
};
|
||||
|
||||
@ -280,7 +276,7 @@ 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 = |column| Wire {
|
||||
row: self.gate_index,
|
||||
row: self.row,
|
||||
column,
|
||||
};
|
||||
|
||||
|
||||
@ -82,30 +82,24 @@ fn create_switch<F: RichField + Extendable<D>, const D: usize>(
|
||||
|
||||
let gate = SwitchGate::new_from_config(&builder.config, chunk_size);
|
||||
let params = vec![F::from_canonical_usize(chunk_size)];
|
||||
let (gate_index, next_copy) = builder.find_slot(gate, ¶ms, &[]);
|
||||
let (row, next_copy) = builder.find_slot(gate, ¶ms, &[]);
|
||||
|
||||
let mut c = Vec::new();
|
||||
let mut d = Vec::new();
|
||||
for e in 0..chunk_size {
|
||||
builder.connect(
|
||||
a1[e],
|
||||
Target::wire(gate_index, gate.wire_first_input(next_copy, e)),
|
||||
Target::wire(row, gate.wire_first_input(next_copy, e)),
|
||||
);
|
||||
builder.connect(
|
||||
a2[e],
|
||||
Target::wire(gate_index, gate.wire_second_input(next_copy, e)),
|
||||
Target::wire(row, gate.wire_second_input(next_copy, e)),
|
||||
);
|
||||
c.push(Target::wire(
|
||||
gate_index,
|
||||
gate.wire_first_output(next_copy, e),
|
||||
));
|
||||
d.push(Target::wire(
|
||||
gate_index,
|
||||
gate.wire_second_output(next_copy, e),
|
||||
));
|
||||
c.push(Target::wire(row, gate.wire_first_output(next_copy, e)));
|
||||
d.push(Target::wire(row, gate.wire_second_output(next_copy, e)));
|
||||
}
|
||||
|
||||
let switch = Target::wire(gate_index, gate.wire_switch_bool(next_copy));
|
||||
let switch = Target::wire(row, gate.wire_switch_bool(next_copy));
|
||||
|
||||
(switch, c, d)
|
||||
}
|
||||
|
||||
@ -54,10 +54,10 @@ pub fn assert_le<F: RichField + Extendable<D>, const D: usize>(
|
||||
num_chunks: usize,
|
||||
) {
|
||||
let gate = AssertLessThanGate::new(bits, num_chunks);
|
||||
let gate_index = builder.add_gate(gate.clone(), vec![]);
|
||||
let row = builder.add_gate(gate.clone(), vec![]);
|
||||
|
||||
builder.connect(Target::wire(gate_index, gate.wire_first_input()), lhs);
|
||||
builder.connect(Target::wire(gate_index, gate.wire_second_input()), rhs);
|
||||
builder.connect(Target::wire(row, gate.wire_first_input()), lhs);
|
||||
builder.connect(Target::wire(row, gate.wire_second_input()), rhs);
|
||||
}
|
||||
|
||||
/// Sort memory operations by address value, then by timestamp value.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user