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 db60fd2
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 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 @@ -71,6 +74,13 @@ pub trait EccInstructions<C: CurveAffine>: Chip<C::Base> {
/// parts of the circuit where the fixed base is used.
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(
&self,
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 @@ -299,13 +309,13 @@ 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)
chip.get_fixed_short(point)
.map(|inner| FixedPointShort { chip, inner })
}

Expand Down

0 comments on commit db60fd2

Please sign in to comment.