Skip to content

Commit

Permalink
Add FixedPointShort associated type
Browse files Browse the repository at this point in the history
  • Loading branch information
therealyingtong committed May 6, 2021
1 parent 6a64bc1 commit 911b528
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions src/circuit/gadget/ecc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ pub trait EccInstructions<C: CurveAffine>: Chip<C::Base> {
type FixedPoints: Clone + Debug;
/// Variable representing a fixed elliptic curve point (constant in the circuit).
type FixedPoint: Clone + Debug;
/// Variable representing a fixed elliptic curve point (constant in the circuit)
/// to be used in scalar multiplication with a short signed exponent.
type FixedPointShort: Clone + Debug;

/// Witnesses the given base field element as a private input to the circuit for variable-base scalar mul.
fn witness_scalar_var(
Expand Down Expand Up @@ -69,7 +72,14 @@ pub trait EccInstructions<C: CurveAffine>: Chip<C::Base> {
/// Returns a fixed point that had been previously loaded into the circuit.
/// The pre-loaded cells are used to set up equality constraints in other
/// parts of the circuit where the fixed base is used.
fn get_fixed(&self, fixed_points: Self::FixedPoints) -> Result<Self::FixedPoint, Error>;
fn get_fixed(&self, fixed_points: Self::FixedPoints) -> Result<&Self::FixedPoint, Error>;

/// Returns a fixed point to be used in scalar multiplication with a signed
/// short exponent.
fn get_fixed_short(
&self,
fixed_points: Self::FixedPoints,
) -> Result<&Self::FixedPointShort, Error>;

/// Performs incomplete point addition, returning `a + b`.
fn add_incomplete(
Expand Down Expand Up @@ -108,7 +118,7 @@ pub trait EccInstructions<C: CurveAffine>: Chip<C::Base> {
&self,
layouter: &mut impl Layouter<C::Base>,
scalar: &Self::ScalarFixedShort,
base: &Self::FixedPoint,
base: &Self::FixedPointShort,
) -> Result<Self::Point, Error>;
}

Expand Down Expand Up @@ -274,8 +284,10 @@ pub struct FixedPoint<C: CurveAffine, EccChip: EccInstructions<C> + Clone + Debu
impl<C: CurveAffine, EccChip: EccInstructions<C> + Clone + Debug> FixedPoint<C, EccChip> {
/// Gets a reference to the specified fixed point in the circuit.
pub fn get(chip: EccChip, point: EccChip::FixedPoints) -> Result<Self, Error> {
chip.get_fixed(point)
.map(|inner| FixedPoint { chip, inner })
chip.get_fixed(point).map(|inner| FixedPoint {
chip: chip.clone(),
inner: inner.clone(),
})
}

/// Returns `[by] self`.
Expand All @@ -299,14 +311,16 @@ impl<C: CurveAffine, EccChip: EccInstructions<C> + Clone + Debug> FixedPoint<C,
#[derive(Clone, Debug)]
pub struct FixedPointShort<C: CurveAffine, EccChip: EccInstructions<C> + Clone + Debug> {
chip: EccChip,
inner: EccChip::FixedPoint,
inner: EccChip::FixedPointShort,
}

impl<C: CurveAffine, EccChip: EccInstructions<C> + Clone + Debug> FixedPointShort<C, EccChip> {
/// Gets a reference to the specified fixed point in the circuit.
pub fn get(chip: EccChip, point: EccChip::FixedPoints) -> Result<Self, Error> {
chip.get_fixed(point)
.map(|inner| FixedPointShort { chip, inner })
chip.get_fixed_short(point).map(|inner| FixedPointShort {
chip: chip.clone(),
inner: inner.clone(),
})
}

/// Returns `[by] self`.
Expand Down

0 comments on commit 911b528

Please sign in to comment.