mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-01-03 14:23:07 +00:00
Not working
This commit is contained in:
parent
744996ef1c
commit
68bd0f4b3d
@ -415,6 +415,7 @@ mod tests {
|
||||
_phantom: PhantomData,
|
||||
};
|
||||
let vars = EvaluationVars {
|
||||
selector_index: usize::MAX,
|
||||
local_constants: &[],
|
||||
local_wires: &get_wires(orig_vec, insertion_index, element_to_insert),
|
||||
public_inputs_hash: &HashOut::rand(),
|
||||
|
||||
@ -613,16 +613,20 @@ mod tests {
|
||||
type FF = <C as GenericConfig<D>>::FE;
|
||||
|
||||
let config = CircuitConfig::standard_recursion_zk_config();
|
||||
let config = CircuitConfig::standard_recursion_config();
|
||||
|
||||
let pw = PartialWitness::new();
|
||||
let mut pw = PartialWitness::new();
|
||||
let mut builder = CircuitBuilder::<F, D>::new(config);
|
||||
|
||||
let x = FF::rand();
|
||||
let y = FF::rand();
|
||||
let z = x / y;
|
||||
let xt = builder.constant_extension(x);
|
||||
let yt = builder.constant_extension(y);
|
||||
let zt = builder.constant_extension(z);
|
||||
let xt = builder.add_virtual_extension_target();
|
||||
pw.set_extension_target(xt, x);
|
||||
let yt = builder.add_virtual_extension_target();
|
||||
pw.set_extension_target(yt, y);
|
||||
let zt = builder.add_virtual_extension_target();
|
||||
pw.set_extension_target(zt, z);
|
||||
let comp_zt = builder.div_extension(xt, yt);
|
||||
builder.connect_extension(zt, comp_zt);
|
||||
|
||||
@ -635,7 +639,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_mul_algebra() -> Result<()> {
|
||||
const D: usize = 2;
|
||||
type C = KeccakGoldilocksConfig;
|
||||
type C = PoseidonGoldilocksConfig;
|
||||
type F = <C as GenericConfig<D>>::F;
|
||||
type FF = <C as GenericConfig<D>>::FE;
|
||||
|
||||
@ -650,14 +654,15 @@ mod tests {
|
||||
ExtensionAlgebraTarget(builder.add_virtual_extension_targets(D).try_into().unwrap());
|
||||
let zt =
|
||||
ExtensionAlgebraTarget(builder.add_virtual_extension_targets(D).try_into().unwrap());
|
||||
let comp_zt = builder.mul_ext_algebra(xt, yt);
|
||||
// let comp_zt = builder.mul_ext_algebra(xt, yt);
|
||||
let comp_zt = builder.add_ext_algebra(xt, yt);
|
||||
for i in 0..D {
|
||||
builder.connect_extension(zt.0[i], comp_zt.0[i]);
|
||||
}
|
||||
|
||||
let x = ExtensionAlgebra::<FF, D>(FF::rand_arr());
|
||||
let y = ExtensionAlgebra::<FF, D>(FF::rand_arr());
|
||||
let z = x * y;
|
||||
let z = x + y;
|
||||
for i in 0..D {
|
||||
pw.set_extension_target(xt.0[i], x.0[i]);
|
||||
pw.set_extension_target(yt.0[i], y.0[i]);
|
||||
@ -669,4 +674,34 @@ mod tests {
|
||||
|
||||
verify(proof, &data.verifier_only, &data.common)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_yo() -> Result<()> {
|
||||
const D: usize = 2;
|
||||
type C = PoseidonGoldilocksConfig;
|
||||
type F = <C as GenericConfig<D>>::F;
|
||||
type FF = <C as GenericConfig<D>>::FE;
|
||||
|
||||
let config = CircuitConfig::standard_recursion_config();
|
||||
|
||||
let mut pw = PartialWitness::new();
|
||||
let mut builder = CircuitBuilder::<F, D>::new(config);
|
||||
|
||||
let xt = builder.add_virtual_extension_target();
|
||||
let yt = builder.add_virtual_extension_target();
|
||||
let zt = builder.add_virtual_extension_target();
|
||||
let comp_zt = builder.mul_extension(xt, yt);
|
||||
builder.connect_extension(zt, comp_zt);
|
||||
|
||||
let x = FF::rand();
|
||||
let y = FF::rand();
|
||||
let z = x * y;
|
||||
pw.set_extension_target(xt, x);
|
||||
pw.set_extension_target(yt, y);
|
||||
|
||||
let data = builder.build::<C>();
|
||||
let proof = data.prove(pw)?;
|
||||
|
||||
verify(proof, &data.verifier_only, &data.common)
|
||||
}
|
||||
}
|
||||
|
||||
@ -130,48 +130,48 @@ impl<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for U32AddManyGate
|
||||
constraints
|
||||
}
|
||||
|
||||
fn eval_unfiltered_base_one(
|
||||
&self,
|
||||
vars: EvaluationVarsBase<F>,
|
||||
mut yield_constr: StridedConstraintConsumer<F>,
|
||||
) {
|
||||
for i in 0..self.num_ops {
|
||||
let addends: Vec<F> = (0..self.num_addends)
|
||||
.map(|j| vars.local_wires[self.wire_ith_op_jth_addend(i, j)])
|
||||
.collect();
|
||||
let carry = vars.local_wires[self.wire_ith_carry(i)];
|
||||
|
||||
let computed_output = addends.iter().fold(F::ZERO, |x, &y| x + y) + carry;
|
||||
|
||||
let output_result = vars.local_wires[self.wire_ith_output_result(i)];
|
||||
let output_carry = vars.local_wires[self.wire_ith_output_carry(i)];
|
||||
|
||||
let base = F::from_canonical_u64(1 << 32u64);
|
||||
let combined_output = output_carry * base + output_result;
|
||||
|
||||
yield_constr.one(combined_output - computed_output);
|
||||
|
||||
let mut combined_result_limbs = F::ZERO;
|
||||
let mut combined_carry_limbs = F::ZERO;
|
||||
let base = F::from_canonical_u64(1u64 << Self::limb_bits());
|
||||
for j in (0..Self::num_limbs()).rev() {
|
||||
let this_limb = vars.local_wires[self.wire_ith_output_jth_limb(i, j)];
|
||||
let max_limb = 1 << Self::limb_bits();
|
||||
let product = (0..max_limb)
|
||||
.map(|x| this_limb - F::from_canonical_usize(x))
|
||||
.product();
|
||||
yield_constr.one(product);
|
||||
|
||||
if j < Self::num_result_limbs() {
|
||||
combined_result_limbs = base * combined_result_limbs + this_limb;
|
||||
} else {
|
||||
combined_carry_limbs = base * combined_carry_limbs + this_limb;
|
||||
}
|
||||
}
|
||||
yield_constr.one(combined_result_limbs - output_result);
|
||||
yield_constr.one(combined_carry_limbs - output_carry);
|
||||
}
|
||||
}
|
||||
// fn eval_unfiltered_base_one(
|
||||
// &self,
|
||||
// vars: EvaluationVarsBase<F>,
|
||||
// mut yield_constr: StridedConstraintConsumer<F>,
|
||||
// ) {
|
||||
// for i in 0..self.num_ops {
|
||||
// let addends: Vec<F> = (0..self.num_addends)
|
||||
// .map(|j| vars.local_wires[self.wire_ith_op_jth_addend(i, j)])
|
||||
// .collect();
|
||||
// let carry = vars.local_wires[self.wire_ith_carry(i)];
|
||||
//
|
||||
// let computed_output = addends.iter().fold(F::ZERO, |x, &y| x + y) + carry;
|
||||
//
|
||||
// let output_result = vars.local_wires[self.wire_ith_output_result(i)];
|
||||
// let output_carry = vars.local_wires[self.wire_ith_output_carry(i)];
|
||||
//
|
||||
// let base = F::from_canonical_u64(1 << 32u64);
|
||||
// let combined_output = output_carry * base + output_result;
|
||||
//
|
||||
// yield_constr.one(combined_output - computed_output);
|
||||
//
|
||||
// let mut combined_result_limbs = F::ZERO;
|
||||
// let mut combined_carry_limbs = F::ZERO;
|
||||
// let base = F::from_canonical_u64(1u64 << Self::limb_bits());
|
||||
// for j in (0..Self::num_limbs()).rev() {
|
||||
// let this_limb = vars.local_wires[self.wire_ith_output_jth_limb(i, j)];
|
||||
// let max_limb = 1 << Self::limb_bits();
|
||||
// let product = (0..max_limb)
|
||||
// .map(|x| this_limb - F::from_canonical_usize(x))
|
||||
// .product();
|
||||
// yield_constr.one(product);
|
||||
//
|
||||
// if j < Self::num_result_limbs() {
|
||||
// combined_result_limbs = base * combined_result_limbs + this_limb;
|
||||
// } else {
|
||||
// combined_carry_limbs = base * combined_carry_limbs + this_limb;
|
||||
// }
|
||||
// }
|
||||
// yield_constr.one(combined_result_limbs - output_result);
|
||||
// yield_constr.one(combined_carry_limbs - output_carry);
|
||||
// }
|
||||
// }
|
||||
|
||||
fn eval_unfiltered_recursively(
|
||||
&self,
|
||||
@ -448,6 +448,7 @@ mod tests {
|
||||
};
|
||||
|
||||
let vars = EvaluationVars {
|
||||
selector_index: usize::MAX,
|
||||
local_constants: &[],
|
||||
local_wires: &get_wires(addends, carries),
|
||||
public_inputs_hash: &HashOut::rand(),
|
||||
|
||||
@ -57,8 +57,8 @@ impl<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for ArithmeticGate
|
||||
}
|
||||
|
||||
fn eval_unfiltered(&self, vars: EvaluationVars<F, D>) -> Vec<F::Extension> {
|
||||
let const_0 = vars.local_constants[0];
|
||||
let const_1 = vars.local_constants[1];
|
||||
let const_0 = vars.get_constant(0);
|
||||
let const_1 = vars.get_constant(1);
|
||||
|
||||
let mut constraints = Vec::new();
|
||||
for i in 0..self.num_ops {
|
||||
@ -91,8 +91,8 @@ impl<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for ArithmeticGate
|
||||
builder: &mut CircuitBuilder<F, D>,
|
||||
vars: EvaluationTargets<D>,
|
||||
) -> Vec<ExtensionTarget<D>> {
|
||||
let const_0 = vars.local_constants[0];
|
||||
let const_1 = vars.local_constants[1];
|
||||
let const_0 = vars.get_constant(0);
|
||||
let const_1 = vars.get_constant(1);
|
||||
|
||||
let mut constraints = Vec::new();
|
||||
for i in 0..self.num_ops {
|
||||
@ -157,8 +157,8 @@ impl<F: RichField + Extendable<D>, const D: usize> PackedEvaluableBase<F, D> for
|
||||
vars: EvaluationVarsBasePacked<P>,
|
||||
mut yield_constr: StridedConstraintConsumer<P>,
|
||||
) {
|
||||
let const_0 = vars.local_constants[0];
|
||||
let const_1 = vars.local_constants[1];
|
||||
let const_0 = vars.get_constant(0);
|
||||
let const_1 = vars.get_constant(1);
|
||||
|
||||
for i in 0..self.num_ops {
|
||||
let multiplicand_0 = vars.local_wires[Self::wire_ith_multiplicand_0(i)];
|
||||
|
||||
@ -55,8 +55,8 @@ impl<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for ArithmeticExte
|
||||
}
|
||||
|
||||
fn eval_unfiltered(&self, vars: EvaluationVars<F, D>) -> Vec<F::Extension> {
|
||||
let const_0 = vars.local_constants[0];
|
||||
let const_1 = vars.local_constants[1];
|
||||
let const_0 = vars.get_constant(0);
|
||||
let const_1 = vars.get_constant(1);
|
||||
|
||||
let mut constraints = Vec::new();
|
||||
for i in 0..self.num_ops {
|
||||
@ -78,8 +78,8 @@ impl<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for ArithmeticExte
|
||||
vars: EvaluationVarsBase<F>,
|
||||
mut yield_constr: StridedConstraintConsumer<F>,
|
||||
) {
|
||||
let const_0 = vars.local_constants[0];
|
||||
let const_1 = vars.local_constants[1];
|
||||
let const_0 = vars.get_constant(0);
|
||||
let const_1 = vars.get_constant(1);
|
||||
|
||||
for i in 0..self.num_ops {
|
||||
let multiplicand_0 = vars.get_local_ext(Self::wires_ith_multiplicand_0(i));
|
||||
@ -98,8 +98,8 @@ impl<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for ArithmeticExte
|
||||
builder: &mut CircuitBuilder<F, D>,
|
||||
vars: EvaluationTargets<D>,
|
||||
) -> Vec<ExtensionTarget<D>> {
|
||||
let const_0 = vars.local_constants[0];
|
||||
let const_1 = vars.local_constants[1];
|
||||
let const_0 = vars.get_constant(0);
|
||||
let const_1 = vars.get_constant(1);
|
||||
|
||||
let mut constraints = Vec::new();
|
||||
for i in 0..self.num_ops {
|
||||
|
||||
@ -445,6 +445,7 @@ mod tests {
|
||||
};
|
||||
|
||||
let vars = EvaluationVars {
|
||||
selector_index: usize::MAX,
|
||||
local_constants: &[],
|
||||
local_wires: &get_wires(multiplicands_0, multiplicands_1, addends),
|
||||
public_inputs_hash: &HashOut::rand(),
|
||||
|
||||
@ -602,6 +602,7 @@ mod tests {
|
||||
_phantom: PhantomData,
|
||||
};
|
||||
let less_than_vars = EvaluationVars {
|
||||
selector_index: usize::MAX,
|
||||
local_constants: &[],
|
||||
local_wires: &get_wires(first_input, second_input),
|
||||
public_inputs_hash: &HashOut::rand(),
|
||||
@ -620,6 +621,7 @@ mod tests {
|
||||
_phantom: PhantomData,
|
||||
};
|
||||
let equal_vars = EvaluationVars {
|
||||
selector_index: usize::MAX,
|
||||
local_constants: &[],
|
||||
local_wires: &get_wires(first_input, first_input),
|
||||
public_inputs_hash: &HashOut::rand(),
|
||||
|
||||
@ -682,6 +682,7 @@ mod tests {
|
||||
_phantom: PhantomData,
|
||||
};
|
||||
let less_than_vars = EvaluationVars {
|
||||
selector_index: usize::MAX,
|
||||
local_constants: &[],
|
||||
local_wires: &get_wires(first_input, second_input),
|
||||
public_inputs_hash: &HashOut::rand(),
|
||||
@ -700,6 +701,7 @@ mod tests {
|
||||
_phantom: PhantomData,
|
||||
};
|
||||
let equal_vars = EvaluationVars {
|
||||
selector_index: usize::MAX,
|
||||
local_constants: &[],
|
||||
local_wires: &get_wires(first_input, first_input),
|
||||
public_inputs_hash: &HashOut::rand(),
|
||||
|
||||
@ -42,23 +42,21 @@ impl<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for ConstantGate {
|
||||
|
||||
fn eval_unfiltered(&self, vars: EvaluationVars<F, D>) -> Vec<F::Extension> {
|
||||
(0..self.num_consts)
|
||||
.map(|i| {
|
||||
vars.local_constants[self.const_input(i)] - vars.local_wires[self.wire_output(i)]
|
||||
})
|
||||
.map(|i| vars.get_constant(self.const_input(i)) - vars.local_wires[self.wire_output(i)])
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn eval_unfiltered_base_one(
|
||||
&self,
|
||||
_vars: EvaluationVarsBase<F>,
|
||||
_yield_constr: StridedConstraintConsumer<F>,
|
||||
) {
|
||||
panic!("use eval_unfiltered_base_packed instead");
|
||||
}
|
||||
// fn eval_unfiltered_base_one(
|
||||
// &self,
|
||||
// _vars: EvaluationVarsBase<F>,
|
||||
// _yield_constr: StridedConstraintConsumer<F>,
|
||||
// ) {
|
||||
// panic!("use eval_unfiltered_base_packed instead");
|
||||
// }
|
||||
|
||||
fn eval_unfiltered_base_batch(&self, vars_base: EvaluationVarsBaseBatch<F>) -> Vec<F> {
|
||||
self.eval_unfiltered_base_batch_packed(vars_base)
|
||||
}
|
||||
// fn eval_unfiltered_base_batch(&self, vars_base: EvaluationVarsBaseBatch<F>) -> Vec<F> {
|
||||
// self.eval_unfiltered_base_batch_packed(vars_base)
|
||||
// }
|
||||
|
||||
fn eval_unfiltered_recursively(
|
||||
&self,
|
||||
@ -68,7 +66,7 @@ impl<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for ConstantGate {
|
||||
(0..self.num_consts)
|
||||
.map(|i| {
|
||||
builder.sub_extension(
|
||||
vars.local_constants[self.const_input(i)],
|
||||
vars.get_constant(self.const_input(i)),
|
||||
vars.local_wires[self.wire_output(i)],
|
||||
)
|
||||
})
|
||||
@ -113,17 +111,17 @@ impl<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for ConstantGate {
|
||||
}
|
||||
}
|
||||
|
||||
impl<F: RichField + Extendable<D>, const D: usize> PackedEvaluableBase<F, D> for ConstantGate {
|
||||
fn eval_unfiltered_base_packed<P: PackedField<Scalar = F>>(
|
||||
&self,
|
||||
vars: EvaluationVarsBasePacked<P>,
|
||||
mut yield_constr: StridedConstraintConsumer<P>,
|
||||
) {
|
||||
yield_constr.many((0..self.num_consts).map(|i| {
|
||||
vars.local_constants[self.const_input(i)] - vars.local_wires[self.wire_output(i)]
|
||||
}));
|
||||
}
|
||||
}
|
||||
// impl<F: RichField + Extendable<D>, const D: usize> PackedEvaluableBase<F, D> for ConstantGate {
|
||||
// fn eval_unfiltered_base_packed<P: PackedField<Scalar = F>>(
|
||||
// &self,
|
||||
// vars: EvaluationVarsBasePacked<P>,
|
||||
// mut yield_constr: StridedConstraintConsumer<P>,
|
||||
// ) {
|
||||
// yield_constr.many((0..self.num_consts).map(|i| {
|
||||
// vars.get_constant(self.const_input(i)) - vars.local_wires[self.wire_output(i)]
|
||||
// }));
|
||||
// }
|
||||
// }
|
||||
|
||||
#[derive(Debug)]
|
||||
struct ConstantGenerator<F: Field> {
|
||||
|
||||
@ -394,6 +394,7 @@ mod tests {
|
||||
};
|
||||
|
||||
let vars = EvaluationVars {
|
||||
selector_index: usize::MAX,
|
||||
local_constants: &[],
|
||||
local_wires: &get_wires(base, power as u64),
|
||||
public_inputs_hash: &HashOut::rand(),
|
||||
|
||||
@ -50,6 +50,7 @@ pub trait Gate<F: RichField + Extendable<D>, const D: usize>: 'static + Send + S
|
||||
.collect::<Vec<_>>();
|
||||
let public_inputs_hash = &vars_base.public_inputs_hash;
|
||||
let vars = EvaluationVars {
|
||||
selector_index: vars_base.selector_index,
|
||||
local_constants,
|
||||
local_wires,
|
||||
public_inputs_hash,
|
||||
@ -91,6 +92,7 @@ pub trait Gate<F: RichField + Extendable<D>, const D: usize>: 'static + Send + S
|
||||
combination_num,
|
||||
vars.local_constants[selector_index],
|
||||
);
|
||||
vars.selector_index = selector_index;
|
||||
self.eval_unfiltered(vars)
|
||||
.into_iter()
|
||||
.map(|c| filter * c)
|
||||
@ -115,6 +117,7 @@ pub trait Gate<F: RichField + Extendable<D>, const D: usize>: 'static + Send + S
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
vars_batch.selector_index = selector_index;
|
||||
let mut res_batch = self.eval_unfiltered_base_batch(vars_batch);
|
||||
for res_chunk in res_batch.chunks_exact_mut(filters.len()) {
|
||||
batch_multiply_inplace(res_chunk, &filters);
|
||||
@ -137,6 +140,7 @@ pub trait Gate<F: RichField + Extendable<D>, const D: usize>: 'static + Send + S
|
||||
combination_num,
|
||||
vars.local_constants[selector_index],
|
||||
);
|
||||
vars.selector_index = selector_index;
|
||||
let my_constraints = self.eval_unfiltered_recursively(builder, vars);
|
||||
for (acc, c) in combined_gate_constraints.iter_mut().zip(my_constraints) {
|
||||
*acc = builder.mul_add_extension(filter, c, *acc);
|
||||
|
||||
@ -32,6 +32,7 @@ pub fn test_low_degree<F: RichField + Extendable<D>, G: Gate<F, D>, const D: usi
|
||||
.iter()
|
||||
.zip(constant_ldes.iter())
|
||||
.map(|(local_wires, local_constants)| EvaluationVars {
|
||||
selector_index: usize::MAX,
|
||||
local_constants,
|
||||
local_wires,
|
||||
public_inputs_hash,
|
||||
@ -110,9 +111,15 @@ where
|
||||
let public_inputs_hash = HashOut::rand();
|
||||
|
||||
// Batch of 1.
|
||||
let vars_base_batch =
|
||||
EvaluationVarsBaseBatch::new(1, &constants_base, &wires_base, &public_inputs_hash);
|
||||
let vars_base_batch = EvaluationVarsBaseBatch::new(
|
||||
usize::MAX,
|
||||
1,
|
||||
&constants_base,
|
||||
&wires_base,
|
||||
&public_inputs_hash,
|
||||
);
|
||||
let vars = EvaluationVars {
|
||||
selector_index: usize::MAX,
|
||||
local_constants: &constants,
|
||||
local_wires: &wires,
|
||||
public_inputs_hash: &public_inputs_hash,
|
||||
@ -145,6 +152,7 @@ where
|
||||
pw.set_hash_target(public_inputs_hash_t, public_inputs_hash);
|
||||
|
||||
let vars = EvaluationVars {
|
||||
selector_index: usize::MAX,
|
||||
local_constants: &constants,
|
||||
local_wires: &wires,
|
||||
public_inputs_hash: &public_inputs_hash,
|
||||
@ -152,6 +160,7 @@ where
|
||||
let evals = gate.eval_unfiltered(vars);
|
||||
|
||||
let vars_t = EvaluationTargets {
|
||||
selector_index: usize::MAX,
|
||||
local_constants: &constants_t,
|
||||
local_wires: &wires_t,
|
||||
public_inputs_hash: &public_inputs_hash_t,
|
||||
|
||||
@ -352,6 +352,7 @@ mod tests {
|
||||
let eval_point = FF::rand();
|
||||
let gate = HighDegreeInterpolationGate::<F, D>::new(1);
|
||||
let vars = EvaluationVars {
|
||||
selector_index: usize::MAX,
|
||||
local_constants: &[],
|
||||
local_wires: &get_wires(&gate, shift, coeffs, eval_point),
|
||||
public_inputs_hash: &HashOut::rand(),
|
||||
|
||||
@ -453,6 +453,7 @@ mod tests {
|
||||
let eval_point = FF::rand();
|
||||
let gate = LowDegreeInterpolationGate::<F, D>::new(subgroup_bits);
|
||||
let vars = EvaluationVars {
|
||||
selector_index: usize::MAX,
|
||||
local_constants: &[],
|
||||
local_wires: &get_wires(&gate, shift, coeffs, eval_point),
|
||||
public_inputs_hash: &HashOut::rand(),
|
||||
|
||||
@ -52,7 +52,7 @@ impl<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for MulExtensionGa
|
||||
}
|
||||
|
||||
fn eval_unfiltered(&self, vars: EvaluationVars<F, D>) -> Vec<F::Extension> {
|
||||
let const_0 = vars.local_constants[0];
|
||||
let const_0 = vars.get_constant(0);
|
||||
|
||||
let mut constraints = Vec::new();
|
||||
for i in 0..self.num_ops {
|
||||
@ -67,29 +67,29 @@ impl<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for MulExtensionGa
|
||||
constraints
|
||||
}
|
||||
|
||||
fn eval_unfiltered_base_one(
|
||||
&self,
|
||||
vars: EvaluationVarsBase<F>,
|
||||
mut yield_constr: StridedConstraintConsumer<F>,
|
||||
) {
|
||||
let const_0 = vars.local_constants[0];
|
||||
|
||||
for i in 0..self.num_ops {
|
||||
let multiplicand_0 = vars.get_local_ext(Self::wires_ith_multiplicand_0(i));
|
||||
let multiplicand_1 = vars.get_local_ext(Self::wires_ith_multiplicand_1(i));
|
||||
let output = vars.get_local_ext(Self::wires_ith_output(i));
|
||||
let computed_output = (multiplicand_0 * multiplicand_1).scalar_mul(const_0);
|
||||
|
||||
yield_constr.many((output - computed_output).to_basefield_array());
|
||||
}
|
||||
}
|
||||
// fn eval_unfiltered_base_one(
|
||||
// &self,
|
||||
// vars: EvaluationVarsBase<F>,
|
||||
// mut yield_constr: StridedConstraintConsumer<F>,
|
||||
// ) {
|
||||
// let const_0 = vars.get_constant(0);
|
||||
//
|
||||
// for i in 0..self.num_ops {
|
||||
// let multiplicand_0 = vars.get_local_ext(Self::wires_ith_multiplicand_0(i));
|
||||
// let multiplicand_1 = vars.get_local_ext(Self::wires_ith_multiplicand_1(i));
|
||||
// let output = vars.get_local_ext(Self::wires_ith_output(i));
|
||||
// let computed_output = (multiplicand_0 * multiplicand_1).scalar_mul(const_0);
|
||||
//
|
||||
// yield_constr.many((output - computed_output).to_basefield_array());
|
||||
// }
|
||||
// }
|
||||
|
||||
fn eval_unfiltered_recursively(
|
||||
&self,
|
||||
builder: &mut CircuitBuilder<F, D>,
|
||||
vars: EvaluationTargets<D>,
|
||||
) -> Vec<ExtensionTarget<D>> {
|
||||
let const_0 = vars.local_constants[0];
|
||||
let const_0 = vars.get_constant(0);
|
||||
|
||||
let mut constraints = Vec::new();
|
||||
for i in 0..self.num_ops {
|
||||
|
||||
@ -413,6 +413,7 @@ mod tests {
|
||||
.map(|(l, &i)| l[i])
|
||||
.collect();
|
||||
let good_vars = EvaluationVars {
|
||||
selector_index: usize::MAX,
|
||||
local_constants: &[],
|
||||
local_wires: &get_wires(
|
||||
bits,
|
||||
@ -424,6 +425,7 @@ mod tests {
|
||||
};
|
||||
let bad_claimed_elements = F::rand_vec(4);
|
||||
let bad_vars = EvaluationVars {
|
||||
selector_index: usize::MAX,
|
||||
local_constants: &[],
|
||||
local_wires: &get_wires(bits, lists, access_indices, bad_claimed_elements),
|
||||
public_inputs_hash: &HashOut::rand(),
|
||||
|
||||
@ -292,6 +292,7 @@ mod tests {
|
||||
};
|
||||
|
||||
let vars = EvaluationVars {
|
||||
selector_index: usize::MAX,
|
||||
local_constants: &[],
|
||||
local_wires: &get_wires(input_limbs),
|
||||
public_inputs_hash: &HashOut::rand(),
|
||||
|
||||
@ -437,6 +437,7 @@ mod tests {
|
||||
};
|
||||
|
||||
let vars = EvaluationVars {
|
||||
selector_index: usize::MAX,
|
||||
local_constants: &[],
|
||||
local_wires: &get_wires(inputs_x, inputs_y, borrows),
|
||||
public_inputs_hash: &HashOut::rand(),
|
||||
|
||||
@ -446,6 +446,7 @@ mod tests {
|
||||
};
|
||||
|
||||
let vars = EvaluationVars {
|
||||
selector_index: usize::MAX,
|
||||
local_constants: &[],
|
||||
local_wires: &get_wires(first_inputs, second_inputs, switch_bools),
|
||||
public_inputs_hash: &HashOut::rand(),
|
||||
|
||||
@ -637,6 +637,9 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||
where
|
||||
[(); C::Hasher::HASH_SIZE]:,
|
||||
{
|
||||
for g in &self.gate_instances {
|
||||
dbg!(&g.gate_ref.0.id());
|
||||
}
|
||||
let mut timing = TimingTree::new("preprocess", Level::Trace);
|
||||
let start = Instant::now();
|
||||
let rate_bits = self.config.fri_config.rate_bits;
|
||||
@ -672,11 +675,13 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||
|
||||
let mut gates = self.gates.iter().cloned().collect::<Vec<_>>();
|
||||
gates.sort_unstable_by_key(|g| g.0.degree());
|
||||
dbg!(&gates);
|
||||
let (constant_vecs, selector_indices, combination_nums) = compute_selectors(
|
||||
gates.clone(),
|
||||
&self.gate_instances,
|
||||
self.config.max_quotient_degree_factor + 1,
|
||||
);
|
||||
dbg!(&constant_vecs, &selector_indices, &combination_nums);
|
||||
let num_constants = constant_vecs.len();
|
||||
// let (gate_tree, max_filtered_constraint_degree, num_constants) = Tree::from_gates(gates);
|
||||
// let prefixed_gates = PrefixedGate::from_tree(gate_tree);
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
pub mod circuit_builder;
|
||||
pub mod circuit_data;
|
||||
pub mod config;
|
||||
mod constest;
|
||||
pub(crate) mod copy_constraint;
|
||||
mod get_challenges;
|
||||
pub(crate) mod permutation_argument;
|
||||
|
||||
@ -427,6 +427,7 @@ fn compute_quotient_polys<
|
||||
}
|
||||
|
||||
let vars_batch = EvaluationVarsBaseBatch::new(
|
||||
usize::MAX,
|
||||
xs_batch.len(),
|
||||
&local_constants_batch,
|
||||
&local_wires_batch,
|
||||
|
||||
@ -56,6 +56,7 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||
let local_constants = &proof.openings.constants;
|
||||
let local_wires = &proof.openings.wires;
|
||||
let vars = EvaluationTargets {
|
||||
selector_index: usize::MAX,
|
||||
local_constants,
|
||||
local_wires,
|
||||
public_inputs_hash: &public_inputs_hash,
|
||||
|
||||
@ -152,7 +152,7 @@ pub(crate) fn eval_vanishing_poly_base_batch<
|
||||
let partial_products = partial_products_batch[k];
|
||||
let s_sigmas = s_sigmas_batch[k];
|
||||
|
||||
let constraint_terms = PackedStridedView::new(constraint_terms_batch.clone(), n, k);
|
||||
let constraint_terms = PackedStridedView::new(&constraint_terms_batch, n, k);
|
||||
|
||||
let l1_x = z_h_on_coset.eval_l1(index, x);
|
||||
for i in 0..num_challenges {
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
use std::ops::Range;
|
||||
use std::os::unix::raw::uid_t;
|
||||
|
||||
use plonky2_field::extension_field::algebra::ExtensionAlgebra;
|
||||
use plonky2_field::extension_field::{Extendable, FieldExtension};
|
||||
@ -11,6 +12,7 @@ use crate::util::strided_view::PackedStridedView;
|
||||
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct EvaluationVars<'a, F: RichField + Extendable<D>, const D: usize> {
|
||||
pub selector_index: usize,
|
||||
pub local_constants: &'a [F::Extension],
|
||||
pub local_wires: &'a [F::Extension],
|
||||
pub public_inputs_hash: &'a HashOut<F>,
|
||||
@ -21,6 +23,7 @@ pub struct EvaluationVars<'a, F: RichField + Extendable<D>, const D: usize> {
|
||||
/// evaluation points, then wire 1 for all points, and so on).
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct EvaluationVarsBaseBatch<'a, F: Field> {
|
||||
pub selector_index: usize,
|
||||
batch_size: usize,
|
||||
pub local_constants: &'a [F],
|
||||
pub local_wires: &'a [F],
|
||||
@ -30,6 +33,7 @@ pub struct EvaluationVarsBaseBatch<'a, F: Field> {
|
||||
/// A view into `EvaluationVarsBaseBatch` for a particular evaluation point. Does not copy the data.
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct EvaluationVarsBase<'a, F: Field> {
|
||||
pub selector_index: usize,
|
||||
pub local_constants: PackedStridedView<'a, F>,
|
||||
pub local_wires: PackedStridedView<'a, F>,
|
||||
pub public_inputs_hash: &'a HashOut<F>,
|
||||
@ -40,12 +44,22 @@ pub struct EvaluationVarsBase<'a, F: Field> {
|
||||
// have packed extension fields.
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct EvaluationVarsBasePacked<'a, P: PackedField> {
|
||||
pub selector_index: usize,
|
||||
pub local_constants: PackedStridedView<'a, P>,
|
||||
pub local_wires: PackedStridedView<'a, P>,
|
||||
pub public_inputs_hash: &'a HashOut<P::Scalar>,
|
||||
}
|
||||
impl<'a, P: PackedField> EvaluationVarsBasePacked<'a, P> {
|
||||
pub fn get_constant(&self, i: usize) -> P {
|
||||
self.local_constants[if i < self.selector_index { i } else { i + 1 }]
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, F: RichField + Extendable<D>, const D: usize> EvaluationVars<'a, F, D> {
|
||||
pub fn get_constant(&self, i: usize) -> F::Extension {
|
||||
self.local_constants[if i < self.selector_index { i } else { i + 1 }]
|
||||
}
|
||||
|
||||
pub fn get_local_ext_algebra(
|
||||
&self,
|
||||
wire_range: Range<usize>,
|
||||
@ -58,6 +72,7 @@ impl<'a, F: RichField + Extendable<D>, const D: usize> EvaluationVars<'a, F, D>
|
||||
|
||||
impl<'a, F: Field> EvaluationVarsBaseBatch<'a, F> {
|
||||
pub fn new(
|
||||
selector_index: usize,
|
||||
batch_size: usize,
|
||||
local_constants: &'a [F],
|
||||
local_wires: &'a [F],
|
||||
@ -66,6 +81,7 @@ impl<'a, F: Field> EvaluationVarsBaseBatch<'a, F> {
|
||||
assert_eq!(local_constants.len() % batch_size, 0);
|
||||
assert_eq!(local_wires.len() % batch_size, 0);
|
||||
Self {
|
||||
selector_index,
|
||||
batch_size,
|
||||
local_constants,
|
||||
local_wires,
|
||||
@ -80,10 +96,10 @@ impl<'a, F: Field> EvaluationVarsBaseBatch<'a, F> {
|
||||
pub fn view(&self, index: usize) -> EvaluationVarsBase<'a, F> {
|
||||
// We cannot implement `Index` as `EvaluationVarsBase` is a struct, not a reference.
|
||||
assert!(index < self.len());
|
||||
let local_constants =
|
||||
PackedStridedView::new(self.local_constants.to_vec(), self.len(), index);
|
||||
let local_wires = PackedStridedView::new(self.local_wires.to_vec(), self.len(), index);
|
||||
let local_constants = PackedStridedView::new(self.local_constants, self.len(), index);
|
||||
let local_wires = PackedStridedView::new(self.local_wires, self.len(), index);
|
||||
EvaluationVarsBase {
|
||||
selector_index: self.selector_index,
|
||||
local_constants,
|
||||
local_wires,
|
||||
public_inputs_hash: self.public_inputs_hash,
|
||||
@ -91,7 +107,7 @@ impl<'a, F: Field> EvaluationVarsBaseBatch<'a, F> {
|
||||
}
|
||||
|
||||
pub fn iter(&self) -> EvaluationVarsBaseBatchIter<'a, F> {
|
||||
EvaluationVarsBaseBatchIter::new(self.clone())
|
||||
EvaluationVarsBaseBatchIter::new(*self)
|
||||
}
|
||||
|
||||
pub fn pack<P: PackedField<Scalar = F>>(
|
||||
@ -102,16 +118,17 @@ impl<'a, F: Field> EvaluationVarsBaseBatch<'a, F> {
|
||||
) {
|
||||
let n_leftovers = self.len() % P::WIDTH;
|
||||
(
|
||||
EvaluationVarsBaseBatchIterPacked::new_with_start(self.clone(), 0),
|
||||
EvaluationVarsBaseBatchIterPacked::new_with_start(
|
||||
self.clone(),
|
||||
self.len() - n_leftovers,
|
||||
),
|
||||
EvaluationVarsBaseBatchIterPacked::new_with_start(*self, 0),
|
||||
EvaluationVarsBaseBatchIterPacked::new_with_start(*self, self.len() - n_leftovers),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, F: Field> EvaluationVarsBase<'a, F> {
|
||||
pub fn get_constant(&self, i: usize) -> F {
|
||||
self.local_constants[if i < self.selector_index { i } else { i + 1 }]
|
||||
}
|
||||
|
||||
pub fn get_local_ext<const D: usize>(&self, wire_range: Range<usize>) -> F::Extension
|
||||
where
|
||||
F: RichField + Extendable<D>,
|
||||
@ -151,6 +168,7 @@ impl<'a, F: Field> Iterator for EvaluationVarsBaseBatchIter<'a, F> {
|
||||
/// Note: if the length of `EvaluationVarsBaseBatch` is not a multiple of `P::WIDTH`, then the
|
||||
/// leftovers at the end are ignored.
|
||||
pub struct EvaluationVarsBaseBatchIterPacked<'a, P: PackedField> {
|
||||
selector_index: usize,
|
||||
/// Index to yield next, in units of `P::Scalar`. E.g. if `P::WIDTH == 4`, then we will yield
|
||||
/// the vars for points `i`, `i + 1`, `i + 2`, and `i + 3`, packed.
|
||||
i: usize,
|
||||
@ -164,6 +182,7 @@ impl<'a, P: PackedField> EvaluationVarsBaseBatchIterPacked<'a, P> {
|
||||
) -> Self {
|
||||
assert!(start <= vars_batch.len());
|
||||
EvaluationVarsBaseBatchIterPacked {
|
||||
selector_index: vars_batch.selector_index,
|
||||
i: start,
|
||||
vars_batch,
|
||||
}
|
||||
@ -175,16 +194,14 @@ impl<'a, P: PackedField> Iterator for EvaluationVarsBaseBatchIterPacked<'a, P> {
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
if self.i + P::WIDTH <= self.vars_batch.len() {
|
||||
let local_constants = PackedStridedView::new(
|
||||
self.vars_batch.local_constants.to_vec(),
|
||||
self.vars_batch.len(),
|
||||
self.i,
|
||||
);
|
||||
let local_wires = PackedStridedView::new(
|
||||
self.vars_batch.local_wires.to_vec(),
|
||||
self.vars_batch.local_constants,
|
||||
self.vars_batch.len(),
|
||||
self.i,
|
||||
);
|
||||
let local_wires =
|
||||
PackedStridedView::new(self.vars_batch.local_wires, self.vars_batch.len(), self.i);
|
||||
let res = EvaluationVarsBasePacked {
|
||||
selector_index: self.selector_index,
|
||||
local_constants,
|
||||
local_wires,
|
||||
public_inputs_hash: self.vars_batch.public_inputs_hash,
|
||||
@ -209,12 +226,17 @@ impl<'a, P: PackedField> ExactSizeIterator for EvaluationVarsBaseBatchIterPacked
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct EvaluationTargets<'a, const D: usize> {
|
||||
pub selector_index: usize,
|
||||
pub local_constants: &'a [ExtensionTarget<D>],
|
||||
pub local_wires: &'a [ExtensionTarget<D>],
|
||||
pub public_inputs_hash: &'a HashOutTarget,
|
||||
}
|
||||
|
||||
impl<'a, const D: usize> EvaluationTargets<'a, D> {
|
||||
pub fn get_constant(&self, i: usize) -> ExtensionTarget<D> {
|
||||
self.local_constants[if i < self.selector_index { i } else { i + 1 }]
|
||||
}
|
||||
|
||||
pub fn get_local_ext_algebra(&self, wire_range: Range<usize>) -> ExtensionAlgebraTarget<D> {
|
||||
debug_assert_eq!(wire_range.len(), D);
|
||||
let arr = self.local_wires[wire_range].try_into().unwrap();
|
||||
|
||||
@ -52,6 +52,7 @@ where
|
||||
let local_constants = &proof.openings.constants;
|
||||
let local_wires = &proof.openings.wires;
|
||||
let vars = EvaluationVars {
|
||||
selector_index: usize::MAX,
|
||||
local_constants,
|
||||
local_wires,
|
||||
public_inputs_hash: &public_inputs_hash,
|
||||
|
||||
@ -46,7 +46,7 @@ impl<'a, P: PackedField> PackedStridedView<'a, P> {
|
||||
// end of the same allocated object'; the UB results even if the pointer is not dereferenced.
|
||||
|
||||
#[inline]
|
||||
pub fn new(data: Vec<P::Scalar>, stride: usize, offset: usize) -> Self {
|
||||
pub fn new(data: &'a [P::Scalar], stride: usize, offset: usize) -> Self {
|
||||
assert!(
|
||||
stride >= P::WIDTH,
|
||||
"stride (got {}) must be at least P::WIDTH ({})",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user