diff --git a/src/circuit/gadget/ecc/chip.rs b/src/circuit/gadget/ecc/chip.rs index 0ce5f6bd..ab02c99a 100644 --- a/src/circuit/gadget/ecc/chip.rs +++ b/src/circuit/gadget/ecc/chip.rs @@ -149,7 +149,7 @@ pub struct EccConfig { /// Variable-base scalar multiplication (lo half) mul_lo: mul::incomplete::Config<{ mul::INCOMPLETE_LO_LEN }>, /// Selector used to enforce boolean decomposition in variable-base scalar mul - pub q_mul_decompose_var: Selector, + pub mul_complete: mul::complete::Config, /// Selector used to enforce switching logic on LSB in variable-base scalar mul pub q_mul_lsb: Selector, /// Variable-base scalar multiplication (overflow check) @@ -228,9 +228,6 @@ impl EccChip { // - advices[4]: lambda1 // - advices[9]: z // - // mul::complete::Config: - // - advices[9]: z_complete - // // TODO: Refactor away from `impl From for _` so that sub-configs can // equality-enable the columns they need to. for column in &advices { @@ -261,6 +258,7 @@ impl EccChip { let mul_lo = mul::incomplete::Config::configure( meta, advices[6], advices[7], advices[0], advices[1], advices[8], advices[2], ); + let mul_complete = mul::complete::Config::configure(meta, advices[9], add); let config = EccConfig { advices, @@ -270,7 +268,7 @@ impl EccChip { add, mul_hi, mul_lo, - q_mul_decompose_var: meta.selector(), + mul_complete, q_mul_overflow: meta.selector(), q_mul_lsb: meta.selector(), q_mul_fixed_full: meta.selector(), diff --git a/src/circuit/gadget/ecc/chip/mul.rs b/src/circuit/gadget/ecc/chip/mul.rs index a95e0831..21dad7b1 100644 --- a/src/circuit/gadget/ecc/chip/mul.rs +++ b/src/circuit/gadget/ecc/chip/mul.rs @@ -16,7 +16,8 @@ use halo2::{ use pasta_curves::pallas; -mod complete; +// TODO: Undo this pub(crate). +pub(crate) mod complete; // TODO: Undo this pub(crate). pub(crate) mod incomplete; mod overflow; @@ -67,7 +68,7 @@ impl From<&EccConfig> for Config { add_config: ecc_config.add, hi_config: ecc_config.mul_hi, lo_config: ecc_config.mul_lo, - complete_config: ecc_config.into(), + complete_config: ecc_config.mul_complete, overflow_config: ecc_config.into(), }; @@ -111,7 +112,6 @@ impl From<&EccConfig> for Config { impl Config { pub(super) fn create_gate(&self, meta: &mut ConstraintSystem) { - self.complete_config.create_gate(meta); self.overflow_config.create_gate(meta); // If `lsb` is 0, (x, y) = (x_p, -y_p). If `lsb` is 1, (x, y) = (0,0). diff --git a/src/circuit/gadget/ecc/chip/mul/complete.rs b/src/circuit/gadget/ecc/chip/mul/complete.rs index 585261a2..5c5ce049 100644 --- a/src/circuit/gadget/ecc/chip/mul/complete.rs +++ b/src/circuit/gadget/ecc/chip/mul/complete.rs @@ -1,4 +1,4 @@ -use super::super::{add, copy, CellValue, EccConfig, EccPoint, Var}; +use super::super::{add, copy, CellValue, EccPoint, Var}; use super::{COMPLETE_RANGE, X, Y, Z}; use crate::circuit::gadget::utilities::{bool_check, ternary}; @@ -10,6 +10,7 @@ use halo2::{ use pasta_curves::{arithmetic::FieldExt, pallas}; +#[derive(Copy, Clone, Debug, Eq, PartialEq)] pub struct Config { // Selector used to constrain the cells used in complete addition. q_mul_decompose_var: Selector, @@ -19,30 +20,31 @@ pub struct Config { add_config: add::Config, } -impl From<&EccConfig> for Config { - fn from(ecc_config: &EccConfig) -> Self { +impl Config { + /// TODO: Make this pub(super). + pub(crate) fn configure( + meta: &mut ConstraintSystem, + z_complete: Column, + add_config: add::Config, + ) -> Self { + meta.enable_equality(z_complete.into()); + let config = Self { - q_mul_decompose_var: ecc_config.q_mul_decompose_var, - z_complete: ecc_config.advices[9], - add_config: ecc_config.add, + q_mul_decompose_var: meta.selector(), + z_complete, + add_config, }; - let add_config_advices = config.add_config.advice_columns(); - assert!( - !add_config_advices.contains(&config.z_complete), - "z_complete cannot overlap with complete addition columns." - ); + config.create_gate(meta); config } -} -impl Config { /// Gate used to check scalar decomposition is correct. /// This is used to check the bits used in complete addition, since the incomplete /// addition gate (controlled by `q_mul`) already checks scalar decomposition for /// the other bits. - pub(super) fn create_gate(&self, meta: &mut ConstraintSystem) { + fn create_gate(&self, meta: &mut ConstraintSystem) { // | y_p | z_complete | // -------------------- // | y_p | z_{i + 1} |