mirror of https://github.com/zcash/orchard.git
chip::mul_fixed.rs: Make q_mul_fixed a selector instead of fixed column.
This commit is contained in:
parent
23f2ed5abe
commit
b69094036c
|
@ -99,11 +99,13 @@ pub struct EccConfig {
|
||||||
pub q_mul_overflow: Selector,
|
pub q_mul_overflow: Selector,
|
||||||
|
|
||||||
/// Fixed-base full-width scalar multiplication
|
/// Fixed-base full-width scalar multiplication
|
||||||
pub mul_fixed: Column<Fixed>,
|
pub q_mul_fixed: Selector,
|
||||||
/// Fixed-base signed short scalar multiplication
|
/// Fixed-base signed short scalar multiplication
|
||||||
pub q_mul_fixed_short: Selector,
|
pub q_mul_fixed_short: Selector,
|
||||||
/// Fixed-base multiplication using a base field element as the scalar
|
/// Fixed-base multiplication using a base field element as the scalar
|
||||||
pub base_field_fixed: Column<Fixed>,
|
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
|
/// Witness point
|
||||||
pub q_point: Selector,
|
pub q_point: Selector,
|
||||||
|
@ -184,9 +186,10 @@ impl EccChip {
|
||||||
q_mul_decompose_var: meta.selector(),
|
q_mul_decompose_var: meta.selector(),
|
||||||
q_mul_overflow: meta.selector(),
|
q_mul_overflow: meta.selector(),
|
||||||
q_mul_lsb: meta.selector(),
|
q_mul_lsb: meta.selector(),
|
||||||
mul_fixed: meta.fixed_column(),
|
q_mul_fixed: meta.selector(),
|
||||||
q_mul_fixed_short: 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_point: meta.selector(),
|
||||||
q_scalar_fixed: meta.selector(),
|
q_scalar_fixed: meta.selector(),
|
||||||
q_scalar_fixed_short: meta.selector(),
|
q_scalar_fixed_short: meta.selector(),
|
||||||
|
|
|
@ -11,7 +11,8 @@ use group::Curve;
|
||||||
use halo2::{
|
use halo2::{
|
||||||
circuit::Region,
|
circuit::Region,
|
||||||
plonk::{
|
plonk::{
|
||||||
Advice, Column, ConstraintSystem, Error, Expression, Fixed, Permutation, VirtualCells,
|
Advice, Column, ConstraintSystem, Error, Expression, Fixed, Permutation, Selector,
|
||||||
|
VirtualCells,
|
||||||
},
|
},
|
||||||
poly::Rotation,
|
poly::Rotation,
|
||||||
};
|
};
|
||||||
|
@ -62,7 +63,7 @@ impl OrchardFixedBases {
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct Config<const NUM_WINDOWS: usize> {
|
pub struct Config<const NUM_WINDOWS: usize> {
|
||||||
mul_fixed: Column<Fixed>,
|
q_mul_fixed: Selector,
|
||||||
// The fixed Lagrange interpolation coefficients for `x_p`.
|
// The fixed Lagrange interpolation coefficients for `x_p`.
|
||||||
lagrange_coeffs: [Column<Fixed>; constants::H],
|
lagrange_coeffs: [Column<Fixed>; constants::H],
|
||||||
// The fixed `z` for each window such that `y + z = u^2`.
|
// The fixed `z` for each window such that `y + z = u^2`.
|
||||||
|
@ -87,7 +88,7 @@ pub struct Config<const NUM_WINDOWS: usize> {
|
||||||
impl<const NUM_WINDOWS: usize> From<&EccConfig> for Config<NUM_WINDOWS> {
|
impl<const NUM_WINDOWS: usize> From<&EccConfig> for Config<NUM_WINDOWS> {
|
||||||
fn from(ecc_config: &EccConfig) -> Self {
|
fn from(ecc_config: &EccConfig) -> Self {
|
||||||
let config = Self {
|
let config = Self {
|
||||||
mul_fixed: ecc_config.mul_fixed,
|
q_mul_fixed: ecc_config.q_mul_fixed,
|
||||||
lagrange_coeffs: ecc_config.lagrange_coeffs,
|
lagrange_coeffs: ecc_config.lagrange_coeffs,
|
||||||
fixed_z: ecc_config.fixed_z,
|
fixed_z: ecc_config.fixed_z,
|
||||||
x_p: ecc_config.advices[0],
|
x_p: ecc_config.advices[0],
|
||||||
|
@ -138,7 +139,7 @@ impl<const NUM_WINDOWS: usize> Config<NUM_WINDOWS> {
|
||||||
meta.create_gate(
|
meta.create_gate(
|
||||||
"x_p, y_p checks for ScalarFixed, ScalarFixedShort",
|
"x_p, y_p checks for ScalarFixed, ScalarFixedShort",
|
||||||
|meta| {
|
|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());
|
let window = meta.query_advice(self.window, Rotation::cur());
|
||||||
self.coords_check(meta, mul_fixed, window)
|
self.coords_check(meta, mul_fixed, window)
|
||||||
},
|
},
|
||||||
|
@ -194,7 +195,7 @@ impl<const NUM_WINDOWS: usize> Config<NUM_WINDOWS> {
|
||||||
offset: usize,
|
offset: usize,
|
||||||
scalar: &ScalarFixed,
|
scalar: &ScalarFixed,
|
||||||
base: OrchardFixedBases,
|
base: OrchardFixedBases,
|
||||||
coords_check_toggle: Column<Fixed>,
|
coords_check_toggle: Selector,
|
||||||
) -> Result<(EccPoint, EccPoint), Error> {
|
) -> Result<(EccPoint, EccPoint), Error> {
|
||||||
// Assign fixed columns for given fixed base
|
// Assign fixed columns for given fixed base
|
||||||
self.assign_fixed_constants(region, offset, base, coords_check_toggle)?;
|
self.assign_fixed_constants(region, offset, base, coords_check_toggle)?;
|
||||||
|
@ -216,7 +217,7 @@ impl<const NUM_WINDOWS: usize> Config<NUM_WINDOWS> {
|
||||||
region: &mut Region<'_, pallas::Base>,
|
region: &mut Region<'_, pallas::Base>,
|
||||||
offset: usize,
|
offset: usize,
|
||||||
base: OrchardFixedBases,
|
base: OrchardFixedBases,
|
||||||
fixed_column: Column<Fixed>,
|
coords_check_toggle: Selector,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
let mut constants = None;
|
let mut constants = None;
|
||||||
|
|
||||||
|
@ -241,12 +242,7 @@ impl<const NUM_WINDOWS: usize> Config<NUM_WINDOWS> {
|
||||||
|
|
||||||
// Assign fixed columns for given fixed base
|
// Assign fixed columns for given fixed base
|
||||||
for window in 0..NUM_WINDOWS {
|
for window in 0..NUM_WINDOWS {
|
||||||
region.assign_fixed(
|
coords_check_toggle.enable(region, window + offset)?;
|
||||||
|| "Enable coords check",
|
|
||||||
fixed_column,
|
|
||||||
window + offset,
|
|
||||||
|| Ok(pallas::Base::one()),
|
|
||||||
)?;
|
|
||||||
|
|
||||||
// Assign x-coordinate Lagrange interpolation coefficients
|
// Assign x-coordinate Lagrange interpolation coefficients
|
||||||
for k in 0..(constants::H) {
|
for k in 0..(constants::H) {
|
||||||
|
|
|
@ -31,7 +31,7 @@ impl<const NUM_WINDOWS: usize> Config<NUM_WINDOWS> {
|
||||||
offset,
|
offset,
|
||||||
&scalar.into(),
|
&scalar.into(),
|
||||||
base.into(),
|
base.into(),
|
||||||
self.0.mul_fixed,
|
self.0.q_mul_fixed,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Add to the accumulator and return the final result as `[scalar]B`.
|
// Add to the accumulator and return the final result as `[scalar]B`.
|
||||||
|
|
|
@ -71,7 +71,7 @@ impl<const NUM_WINDOWS: usize> Config<NUM_WINDOWS> {
|
||||||
offset,
|
offset,
|
||||||
&scalar.into(),
|
&scalar.into(),
|
||||||
base.clone().into(),
|
base.clone().into(),
|
||||||
self.super_config.mul_fixed,
|
self.super_config.q_mul_fixed,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Add to the cumulative sum to get `[magnitude]B`.
|
// Add to the cumulative sum to get `[magnitude]B`.
|
||||||
|
|
Loading…
Reference in New Issue