gadget::ecc.rs: Bound EccInstructions on UtilitiesInstructions.

This commit is contained in:
therealyingtong 2021-07-10 09:09:26 +08:00
parent 7b497c53a3
commit 32f28ed4b0
3 changed files with 10 additions and 10 deletions

View File

@ -9,12 +9,12 @@ use halo2::{
plonk::Error, plonk::Error,
}; };
use crate::circuit::gadget::utilities::CellValue; use crate::circuit::gadget::utilities::UtilitiesInstructions;
pub mod chip; pub mod chip;
/// 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<C::Base> { pub trait EccInstructions<C: CurveAffine>: Chip<C::Base> + UtilitiesInstructions<C::Base> {
/// Variable representing an element of the elliptic curve's base field, that /// Variable representing an element of the elliptic curve's base field, that
/// is used as a scalar in variable-base scalar mul. /// is used as a scalar in variable-base scalar mul.
/// ///
@ -137,7 +137,7 @@ pub trait EccInstructions<C: CurveAffine>: Chip<C::Base> {
fn mul_fixed_base_field_elem( fn mul_fixed_base_field_elem(
&self, &self,
layouter: &mut impl Layouter<C::Base>, layouter: &mut impl Layouter<C::Base>,
base_field_elem: CellValue<C::Base>, base_field_elem: Self::Var,
base: &Self::FixedPoints, base: &Self::FixedPoints,
) -> Result<Self::Point, Error>; ) -> Result<Self::Point, Error>;
} }
@ -369,7 +369,7 @@ where
pub fn mul_base_field_elem( pub fn mul_base_field_elem(
&self, &self,
mut layouter: impl Layouter<C::Base>, mut layouter: impl Layouter<C::Base>,
by: CellValue<C::Base>, by: EccChip::Var,
) -> Result<Point<C, EccChip>, Error> { ) -> Result<Point<C, EccChip>, Error> {
self.chip self.chip
.mul_fixed_base_field_elem(&mut layouter, by, &self.inner) .mul_fixed_base_field_elem(&mut layouter, by, &self.inner)

View File

@ -2,7 +2,7 @@ use super::EccInstructions;
use crate::{ use crate::{
circuit::gadget::utilities::{ circuit::gadget::utilities::{
copy, decompose_running_sum::RunningSumConfig, lookup_range_check::LookupRangeCheckConfig, copy, decompose_running_sum::RunningSumConfig, lookup_range_check::LookupRangeCheckConfig,
CellValue, Var, CellValue, UtilitiesInstructions, Var,
}, },
constants::{self, OrchardFixedBasesFull, ValueCommitV}, constants::{self, OrchardFixedBasesFull, ValueCommitV},
primitives::sinsemilla, primitives::sinsemilla,
@ -159,6 +159,10 @@ impl Chip<pallas::Base> for EccChip {
} }
} }
impl UtilitiesInstructions<pallas::Base> for EccChip {
type Var = CellValue<pallas::Base>;
}
impl EccChip { impl EccChip {
pub fn construct(config: <Self as Chip<pallas::Base>>::Config) -> Self { pub fn construct(config: <Self as Chip<pallas::Base>>::Config) -> Self {
Self { config } Self { config }

View File

@ -426,7 +426,7 @@ pub mod tests {
chip::{EccChip, OrchardFixedBasesFull}, chip::{EccChip, OrchardFixedBasesFull},
FixedPoint, Point, FixedPoint, Point,
}, },
utilities::{CellValue, UtilitiesInstructions}, utilities::UtilitiesInstructions,
}; };
use crate::constants; use crate::constants;
@ -434,10 +434,6 @@ pub mod tests {
chip: EccChip, chip: EccChip,
mut layouter: impl Layouter<pallas::Base>, mut layouter: impl Layouter<pallas::Base>,
) -> Result<(), Error> { ) -> Result<(), Error> {
impl UtilitiesInstructions<pallas::Base> for EccChip {
type Var = CellValue<pallas::Base>;
}
// commit_ivk_r // commit_ivk_r
let commit_ivk_r = OrchardFixedBasesFull::CommitIvkR; let commit_ivk_r = OrchardFixedBasesFull::CommitIvkR;
test_single_base( test_single_base(