From 0f60a814859f2fd19b8a1070abdb23bbd026d4fc Mon Sep 17 00:00:00 2001 From: therealyingtong Date: Sat, 12 Jun 2021 12:32:31 +0800 Subject: [PATCH] ecc::chip.rs: Add EccScalarFixed, EccScalarFixedShort structs --- src/circuit/gadget/ecc/chip.rs | 36 ++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/src/circuit/gadget/ecc/chip.rs b/src/circuit/gadget/ecc/chip.rs index 84a75ae1..b23bac17 100644 --- a/src/circuit/gadget/ecc/chip.rs +++ b/src/circuit/gadget/ecc/chip.rs @@ -1,6 +1,7 @@ use super::EccInstructions; use crate::circuit::gadget::utilities::{copy, CellValue, Var}; -use crate::constants; +use crate::constants::{self, OrchardFixedBasesFull, ValueCommitV}; +use arrayvec::ArrayVec; use group::prime::PrimeCurveAffine; use halo2::{ @@ -180,14 +181,37 @@ impl EccChip { } } +/// A full-width scalar used for fixed-base scalar multiplication. +/// This is decomposed in chunks of `window_width` bits in little-endian order. +/// For example, if `window_width` = 3, we will have [k_0, k_1, ..., k_n] +/// where `scalar = k_0 + k_1 * (2^3) + ... + k_n * (2^3)^n` and each `k_i` is +/// in the range [0..2^3). +#[derive(Clone, Debug)] +pub struct EccScalarFixed { + value: Option, + windows: ArrayVec, { constants::NUM_WINDOWS }>, +} + +/// A signed short scalar used for fixed-base scalar multiplication. +/// This is decomposed in chunks of `window_width` bits in little-endian order. +/// For example, if `window_width` = 3, we will have [k_0, k_1, ..., k_n] +/// where `scalar = k_0 + k_1 * (2^3) + ... + k_n * (2^3)^n` and each `k_i` is +/// in the range [0..2^3). +#[derive(Clone, Debug)] +pub struct EccScalarFixedShort { + magnitude: Option, + sign: CellValue, + windows: ArrayVec, { constants::NUM_WINDOWS_SHORT }>, +} + impl EccInstructions for EccChip { - type ScalarFixed = (); // TODO - type ScalarFixedShort = (); // TODO - type ScalarVar = (); // TODO + type ScalarFixed = EccScalarFixed; + type ScalarFixedShort = EccScalarFixedShort; + type ScalarVar = CellValue; type Point = EccPoint; type X = CellValue; - type FixedPoints = (); // TODO - type FixedPointsShort = (); // TODO + type FixedPoints = OrchardFixedBasesFull; + type FixedPointsShort = ValueCommitV; fn constrain_equal( &self,