Add FixedPoints type and trait to ECC gadget

This commit is contained in:
therealyingtong 2021-02-24 22:36:00 +08:00
parent 84c63e5e84
commit 6cbf32c2cd
1 changed files with 14 additions and 6 deletions

View File

@ -8,12 +8,17 @@ use crate::{
plonk::Error, plonk::Error,
}; };
/// Trait allowing circuit's fixed points to be enumerated.
pub trait FixedPoints<C: CurveAffine>: Clone + fmt::Debug {}
/// The set of circuit instructions required to use the ECC gadgets. /// The set of circuit instructions required to use the ECC gadgets.
pub trait EccInstructions<C: CurveAffine>: Chip<Field = C::Base> { pub trait EccInstructions<C: CurveAffine>: Chip<Field = C::Base> {
/// Variable representing an element of the elliptic curve's scalar field. /// Variable representing an element of the elliptic curve's scalar field.
type Scalar: Clone + fmt::Debug; type Scalar: Clone + fmt::Debug;
/// Variable representing an elliptic curve point. /// Variable representing an elliptic curve point.
type Point: Clone + fmt::Debug; type Point: Clone + fmt::Debug;
/// Variable representing the set of fixed bases in the circuit.
type FixedPoints: FixedPoints<C>;
/// Variable representing a fixed elliptic curve point (constant in the circuit). /// Variable representing a fixed elliptic curve point (constant in the circuit).
type FixedPoint: Clone + fmt::Debug; type FixedPoint: Clone + fmt::Debug;
@ -29,10 +34,10 @@ pub trait EccInstructions<C: CurveAffine>: Chip<Field = C::Base> {
value: Option<C>, value: Option<C>,
) -> Result<Self::Point, Error>; ) -> Result<Self::Point, Error>;
/// Loads a fixed point into the circuit. /// Gets a fixed point into the circuit.
fn load_fixed( fn get_fixed(
layouter: &mut impl Layouter<Self>, layouter: &mut impl Layouter<Self>,
value: Option<C>, fixed_points: Self::FixedPoints,
) -> Result<Self::FixedPoint, Error>; ) -> Result<Self::FixedPoint, Error>;
/// Performs point addition, returning `a + b`. /// Performs point addition, returning `a + b`.
@ -116,9 +121,12 @@ pub struct FixedPoint<C: CurveAffine, EccChip: EccInstructions<C>> {
} }
impl<C: CurveAffine, EccChip: EccInstructions<C>> FixedPoint<C, EccChip> { impl<C: CurveAffine, EccChip: EccInstructions<C>> FixedPoint<C, EccChip> {
/// Loads a fixed point with the given value into the circuit. /// Gets a reference to the specified fixed point in the circuit.
pub fn load(mut layouter: impl Layouter<EccChip>, value: Option<C>) -> Result<Self, Error> { pub fn get(
EccChip::load_fixed(&mut layouter, value).map(|inner| FixedPoint { inner }) mut layouter: impl Layouter<EccChip>,
point: EccChip::FixedPoints,
) -> Result<Self, Error> {
EccChip::get_fixed(&mut layouter, point).map(|inner| FixedPoint { inner })
} }
/// Returns `[by] self`. /// Returns `[by] self`.