From 47258aecfe13c5acfa933821598b9cf93ff13cd0 Mon Sep 17 00:00:00 2001 From: Jake Fecher Date: Tue, 7 Jan 2025 08:36:14 -0600 Subject: [PATCH 1/2] Add Hash functions --- noir_stdlib/src/embedded_curve_ops.nr | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/noir_stdlib/src/embedded_curve_ops.nr b/noir_stdlib/src/embedded_curve_ops.nr index 6b225ee18b2..78875cabe75 100644 --- a/noir_stdlib/src/embedded_curve_ops.nr +++ b/noir_stdlib/src/embedded_curve_ops.nr @@ -1,5 +1,6 @@ use crate::cmp::Eq; use crate::ops::arith::{Add, Neg, Sub}; +use crate::hash::Hash; /// A point on the embedded elliptic curve /// By definition, the base field of the embedded curve is the scalar field of the proof system curve, i.e the Noir Field. @@ -53,6 +54,17 @@ impl Eq for EmbeddedCurvePoint { } } +impl Hash for EmbeddedCurvePoint { + fn hash(self, state: &mut H) where H: crate::hash::Hasher { + if self.is_infinite { + self.is_infinite.hash(state); + } else { + self.x.hash(state); + self.y.hash(state); + } + } +} + /// Scalar for the embedded curve represented as low and high limbs /// By definition, the scalar field of the embedded curve is base field of the proving system curve. /// It may not fit into a Field element, so it is represented with two Field elements; its low and high limbs. @@ -94,6 +106,13 @@ impl Eq for EmbeddedCurveScalar { } } +impl Hash for EmbeddedCurveScalar { + fn hash(self, state: &mut H) where H: crate::hash::Hasher { + self.hi.hash(state); + self.lo.hash(state); + } +} + // Computes a multi scalar multiplication over the embedded curve. // For bn254, We have Grumpkin and Baby JubJub. // For bls12-381, we have JubJub and Bandersnatch. From 3e7ba5ba50fe4a7d7c66d68e96c5194b1e61fcc3 Mon Sep 17 00:00:00 2001 From: Jake Fecher Date: Wed, 22 Jan 2025 11:49:05 -0600 Subject: [PATCH 2/2] Format stdlib --- noir_stdlib/src/embedded_curve_ops.nr | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/noir_stdlib/src/embedded_curve_ops.nr b/noir_stdlib/src/embedded_curve_ops.nr index 78875cabe75..de49eaf2490 100644 --- a/noir_stdlib/src/embedded_curve_ops.nr +++ b/noir_stdlib/src/embedded_curve_ops.nr @@ -1,6 +1,6 @@ use crate::cmp::Eq; -use crate::ops::arith::{Add, Neg, Sub}; use crate::hash::Hash; +use crate::ops::arith::{Add, Neg, Sub}; /// A point on the embedded elliptic curve /// By definition, the base field of the embedded curve is the scalar field of the proof system curve, i.e the Noir Field. @@ -55,7 +55,10 @@ impl Eq for EmbeddedCurvePoint { } impl Hash for EmbeddedCurvePoint { - fn hash(self, state: &mut H) where H: crate::hash::Hasher { + fn hash(self, state: &mut H) + where + H: crate::hash::Hasher, + { if self.is_infinite { self.is_infinite.hash(state); } else { @@ -107,7 +110,10 @@ impl Eq for EmbeddedCurveScalar { } impl Hash for EmbeddedCurveScalar { - fn hash(self, state: &mut H) where H: crate::hash::Hasher { + fn hash(self, state: &mut H) + where + H: crate::hash::Hasher, + { self.hi.hash(state); self.lo.hash(state); }