From 6cbf32c2cd66f3f26561810661109ec3cf4da7cc Mon Sep 17 00:00:00 2001 From: therealyingtong Date: Wed, 24 Feb 2021 22:36:00 +0800 Subject: [PATCH] Add FixedPoints type and trait to ECC gadget --- src/gadget/ecc.rs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/gadget/ecc.rs b/src/gadget/ecc.rs index 3caa6c9..d9a9d74 100644 --- a/src/gadget/ecc.rs +++ b/src/gadget/ecc.rs @@ -8,12 +8,17 @@ use crate::{ plonk::Error, }; +/// Trait allowing circuit's fixed points to be enumerated. +pub trait FixedPoints: Clone + fmt::Debug {} + /// The set of circuit instructions required to use the ECC gadgets. pub trait EccInstructions: Chip { /// Variable representing an element of the elliptic curve's scalar field. type Scalar: Clone + fmt::Debug; /// Variable representing an elliptic curve point. type Point: Clone + fmt::Debug; + /// Variable representing the set of fixed bases in the circuit. + type FixedPoints: FixedPoints; /// Variable representing a fixed elliptic curve point (constant in the circuit). type FixedPoint: Clone + fmt::Debug; @@ -29,10 +34,10 @@ pub trait EccInstructions: Chip { value: Option, ) -> Result; - /// Loads a fixed point into the circuit. - fn load_fixed( + /// Gets a fixed point into the circuit. + fn get_fixed( layouter: &mut impl Layouter, - value: Option, + fixed_points: Self::FixedPoints, ) -> Result; /// Performs point addition, returning `a + b`. @@ -116,9 +121,12 @@ pub struct FixedPoint> { } impl> FixedPoint { - /// Loads a fixed point with the given value into the circuit. - pub fn load(mut layouter: impl Layouter, value: Option) -> Result { - EccChip::load_fixed(&mut layouter, value).map(|inner| FixedPoint { inner }) + /// Gets a reference to the specified fixed point in the circuit. + pub fn get( + mut layouter: impl Layouter, + point: EccChip::FixedPoints, + ) -> Result { + EccChip::get_fixed(&mut layouter, point).map(|inner| FixedPoint { inner }) } /// Returns `[by] self`.