From af30f4b141879354c5f9285acf49642e970d34ba Mon Sep 17 00:00:00 2001 From: therealyingtong Date: Tue, 18 May 2021 16:12:06 +0800 Subject: [PATCH] Add Eq to the EccChip trait --- src/circuit/gadget/ecc.rs | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/src/circuit/gadget/ecc.rs b/src/circuit/gadget/ecc.rs index dd0e1b47..6dcc6945 100644 --- a/src/circuit/gadget/ecc.rs +++ b/src/circuit/gadget/ecc.rs @@ -148,12 +148,12 @@ pub trait EccInstructions: Chip { /// to be in the base field of the curve. (See non-normative notes in /// https://zips.z.cash/protocol/nu5.pdf#orchardkeycomponents.) #[derive(Debug)] -pub struct ScalarVar + Clone + Debug> { +pub struct ScalarVar + Clone + Debug + Eq> { chip: EccChip, inner: EccChip::ScalarVar, } -impl + Clone + Debug> ScalarVar { +impl + Clone + Debug + Eq> ScalarVar { /// Constructs a new ScalarVar with the given value. pub fn new( chip: EccChip, @@ -167,12 +167,12 @@ impl + Clone + Debug> ScalarVar + Clone + Debug> { +pub struct ScalarFixed + Clone + Debug + Eq> { chip: EccChip, inner: EccChip::ScalarFixed, } -impl + Clone + Debug> ScalarFixed { +impl + Clone + Debug + Eq> ScalarFixed { /// Constructs a new ScalarFixed with the given value. pub fn new( chip: EccChip, @@ -186,12 +186,14 @@ impl + Clone + Debug> ScalarFixed + Clone + Debug> { +pub struct ScalarFixedShort + Clone + Debug + Eq> { chip: EccChip, inner: EccChip::ScalarFixedShort, } -impl + Clone + Debug> ScalarFixedShort { +impl + Clone + Debug + Eq> + ScalarFixedShort +{ /// Constructs a new ScalarFixedShort with the given value. /// /// # Panics @@ -223,12 +225,12 @@ impl + Clone + Debug> ScalarFixedSho /// An elliptic curve point over the given curve. #[derive(Debug)] -pub struct Point + Clone + Debug> { +pub struct Point + Clone + Debug + Eq> { chip: EccChip, inner: EccChip::Point, } -impl + Clone + Debug> Point { +impl + Clone + Debug + Eq> Point { /// Constructs a new point with the given value. pub fn new( chip: EccChip, @@ -251,7 +253,7 @@ impl + Clone + Debug> Point, other: &Self) -> Result { - assert_eq!(format!("{:?}", self.chip), format!("{:?}", other.chip)); + assert_eq!(self.chip, other.chip); self.chip .add(&mut layouter, &self.inner, &other.inner) .map(|inner| Point { @@ -266,7 +268,7 @@ impl + Clone + Debug> Point, other: &Self, ) -> Result { - assert_eq!(format!("{:?}", self.chip), format!("{:?}", other.chip)); + assert_eq!(self.chip, other.chip); self.chip .add_incomplete(&mut layouter, &self.inner, &other.inner) .map(|inner| Point { @@ -293,12 +295,12 @@ impl + Clone + Debug> Point + Clone + Debug> { +pub struct X + Clone + Debug + Eq> { chip: EccChip, inner: EccChip::X, } -impl + Clone + Debug> X { +impl + Clone + Debug + Eq> X { /// Wraps the given x-coordinate (obtained directly from an instruction) in a gadget. pub fn from_inner(chip: EccChip, inner: EccChip::X) -> Self { X { chip, inner } @@ -308,12 +310,12 @@ impl + Clone + Debug> X /// A constant elliptic curve point over the given curve, for which scalar multiplication /// is more efficient. #[derive(Clone, Debug)] -pub struct FixedPoint + Clone + Debug> { +pub struct FixedPoint + Clone + Debug + Eq> { chip: EccChip, inner: EccChip::FixedPoint, } -impl + Clone + Debug> FixedPoint { +impl + Clone + Debug + Eq> FixedPoint { /// Gets a reference to the specified fixed point in the circuit. pub fn get(chip: EccChip, point: EccChip::FixedPoints) -> Result { chip.get_fixed(point) @@ -339,12 +341,12 @@ impl + Clone + Debug> FixedPoint + Clone + Debug> { +pub struct FixedPointShort + Clone + Debug + Eq> { chip: EccChip, inner: EccChip::FixedPointShort, } -impl + Clone + Debug> FixedPointShort { +impl + Clone + Debug + Eq> FixedPointShort { /// Gets a reference to the specified fixed point in the circuit. pub fn get(chip: EccChip, point: EccChip::FixedPointsShort) -> Result { chip.get_fixed_short(point)