Introduce ecc::BaseFitsInScalarInstructions trait.

This commit is contained in:
therealyingtong 2022-03-22 14:50:16 +08:00
parent cbf3d6a7f6
commit 5ebfe91eee
2 changed files with 32 additions and 1 deletions

View File

@ -138,6 +138,18 @@ pub trait EccInstructions<C: CurveAffine>:
) -> Result<Self::Point, Error>;
}
/// Instructions that can be implemented for a curve whose base field fits into
/// its scalar field.
pub trait BaseFitsInScalarInstructions<C: CurveAffine>: EccInstructions<C> {
/// Converts a base field element that exists as a variable in the circuit
/// into a scalar to be used in variable-base scalar multiplication.
fn scalar_var_from_base(
&self,
layouter: &mut impl Layouter<C::Base>,
base: &Self::Var,
) -> Result<Self::ScalarVar, Error>;
}
/// Defines the fixed points for a given instantiation of the ECC chip.
pub trait FixedPoints<C: CurveAffine>: Debug + Eq + Clone {
/// Fixed points that can be used with full-width scalar multiplication.

View File

@ -1,6 +1,6 @@
//! Chip implementations for the ECC gadgets.
use super::{EccInstructions, FixedPoints};
use super::{BaseFitsInScalarInstructions, EccInstructions, FixedPoints};
use crate::{
primitives::sinsemilla,
utilities::{lookup_range_check::LookupRangeCheckConfig, UtilitiesInstructions},
@ -533,3 +533,22 @@ where
)
}
}
impl<Fixed: FixedPoints<pallas::Affine>> BaseFitsInScalarInstructions<pallas::Affine>
for EccChip<Fixed>
where
<Fixed as FixedPoints<pallas::Affine>>::Base:
FixedPoint<pallas::Affine, ScalarKind = BaseFieldElem>,
<Fixed as FixedPoints<pallas::Affine>>::FullScalar:
FixedPoint<pallas::Affine, ScalarKind = FullScalar>,
<Fixed as FixedPoints<pallas::Affine>>::ShortScalar:
FixedPoint<pallas::Affine, ScalarKind = ShortScalar>,
{
fn scalar_var_from_base(
&self,
_layouter: &mut impl Layouter<pallas::Base>,
base: &Self::Var,
) -> Result<Self::ScalarVar, Error> {
Ok(base.clone())
}
}