From b69094036c7335ca651b4084c691d8871a03939c Mon Sep 17 00:00:00 2001 From: therealyingtong Date: Wed, 7 Jul 2021 15:52:31 +0800 Subject: [PATCH] chip::mul_fixed.rs: Make q_mul_fixed a selector instead of fixed column. --- src/circuit/gadget/ecc/chip.rs | 11 ++++++---- src/circuit/gadget/ecc/chip/mul_fixed.rs | 20 ++++++++----------- .../gadget/ecc/chip/mul_fixed/full_width.rs | 2 +- .../gadget/ecc/chip/mul_fixed/short.rs | 2 +- 4 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/circuit/gadget/ecc/chip.rs b/src/circuit/gadget/ecc/chip.rs index 7d9f082b..82b33f45 100644 --- a/src/circuit/gadget/ecc/chip.rs +++ b/src/circuit/gadget/ecc/chip.rs @@ -99,11 +99,13 @@ pub struct EccConfig { pub q_mul_overflow: Selector, /// Fixed-base full-width scalar multiplication - pub mul_fixed: Column, + pub q_mul_fixed: Selector, /// Fixed-base signed short scalar multiplication pub q_mul_fixed_short: Selector, /// Fixed-base multiplication using a base field element as the scalar - pub base_field_fixed: Column, + pub base_field_fixed_mul: Selector, + /// Canonicity checks on base field element used as scalar in fixed-base mul + pub base_field_fixed_canon: Selector, /// Witness point pub q_point: Selector, @@ -184,9 +186,10 @@ impl EccChip { q_mul_decompose_var: meta.selector(), q_mul_overflow: meta.selector(), q_mul_lsb: meta.selector(), - mul_fixed: meta.fixed_column(), + q_mul_fixed: meta.selector(), q_mul_fixed_short: meta.selector(), - base_field_fixed: meta.fixed_column(), + base_field_fixed_mul: meta.selector(), + base_field_fixed_canon: meta.selector(), q_point: meta.selector(), q_scalar_fixed: meta.selector(), q_scalar_fixed_short: meta.selector(), diff --git a/src/circuit/gadget/ecc/chip/mul_fixed.rs b/src/circuit/gadget/ecc/chip/mul_fixed.rs index 8c812757..e31ea052 100644 --- a/src/circuit/gadget/ecc/chip/mul_fixed.rs +++ b/src/circuit/gadget/ecc/chip/mul_fixed.rs @@ -11,7 +11,8 @@ use group::Curve; use halo2::{ circuit::Region, plonk::{ - Advice, Column, ConstraintSystem, Error, Expression, Fixed, Permutation, VirtualCells, + Advice, Column, ConstraintSystem, Error, Expression, Fixed, Permutation, Selector, + VirtualCells, }, poly::Rotation, }; @@ -62,7 +63,7 @@ impl OrchardFixedBases { #[derive(Clone, Debug)] pub struct Config { - mul_fixed: Column, + q_mul_fixed: Selector, // The fixed Lagrange interpolation coefficients for `x_p`. lagrange_coeffs: [Column; constants::H], // The fixed `z` for each window such that `y + z = u^2`. @@ -87,7 +88,7 @@ pub struct Config { impl From<&EccConfig> for Config { fn from(ecc_config: &EccConfig) -> Self { let config = Self { - mul_fixed: ecc_config.mul_fixed, + q_mul_fixed: ecc_config.q_mul_fixed, lagrange_coeffs: ecc_config.lagrange_coeffs, fixed_z: ecc_config.fixed_z, x_p: ecc_config.advices[0], @@ -138,7 +139,7 @@ impl Config { meta.create_gate( "x_p, y_p checks for ScalarFixed, ScalarFixedShort", |meta| { - let mul_fixed = meta.query_fixed(self.mul_fixed, Rotation::cur()); + let mul_fixed = meta.query_selector(self.q_mul_fixed); let window = meta.query_advice(self.window, Rotation::cur()); self.coords_check(meta, mul_fixed, window) }, @@ -194,7 +195,7 @@ impl Config { offset: usize, scalar: &ScalarFixed, base: OrchardFixedBases, - coords_check_toggle: Column, + coords_check_toggle: Selector, ) -> Result<(EccPoint, EccPoint), Error> { // Assign fixed columns for given fixed base self.assign_fixed_constants(region, offset, base, coords_check_toggle)?; @@ -216,7 +217,7 @@ impl Config { region: &mut Region<'_, pallas::Base>, offset: usize, base: OrchardFixedBases, - fixed_column: Column, + coords_check_toggle: Selector, ) -> Result<(), Error> { let mut constants = None; @@ -241,12 +242,7 @@ impl Config { // Assign fixed columns for given fixed base for window in 0..NUM_WINDOWS { - region.assign_fixed( - || "Enable coords check", - fixed_column, - window + offset, - || Ok(pallas::Base::one()), - )?; + coords_check_toggle.enable(region, window + offset)?; // Assign x-coordinate Lagrange interpolation coefficients for k in 0..(constants::H) { diff --git a/src/circuit/gadget/ecc/chip/mul_fixed/full_width.rs b/src/circuit/gadget/ecc/chip/mul_fixed/full_width.rs index ef68ae9f..b9003311 100644 --- a/src/circuit/gadget/ecc/chip/mul_fixed/full_width.rs +++ b/src/circuit/gadget/ecc/chip/mul_fixed/full_width.rs @@ -31,7 +31,7 @@ impl Config { offset, &scalar.into(), base.into(), - self.0.mul_fixed, + self.0.q_mul_fixed, )?; // Add to the accumulator and return the final result as `[scalar]B`. diff --git a/src/circuit/gadget/ecc/chip/mul_fixed/short.rs b/src/circuit/gadget/ecc/chip/mul_fixed/short.rs index cc2f2d91..697d765b 100644 --- a/src/circuit/gadget/ecc/chip/mul_fixed/short.rs +++ b/src/circuit/gadget/ecc/chip/mul_fixed/short.rs @@ -71,7 +71,7 @@ impl Config { offset, &scalar.into(), base.clone().into(), - self.super_config.mul_fixed, + self.super_config.q_mul_fixed, )?; // Add to the cumulative sum to get `[magnitude]B`.