From 64c077a0c284a0219dbf7426b114c1005a59a390 Mon Sep 17 00:00:00 2001 From: jialinli Date: Fri, 23 Jan 2026 09:11:51 -0800 Subject: [PATCH 1/3] reexport --- Nargo.toml | 1 - src/bigcurve_test.nr | 2 +- src/curve_jac.nr | 14 +++++++------- src/lib.nr | 39 +++++++++++++++++++++------------------ 4 files changed, 29 insertions(+), 27 deletions(-) diff --git a/Nargo.toml b/Nargo.toml index c740675..0d9f731 100644 --- a/Nargo.toml +++ b/Nargo.toml @@ -7,4 +7,3 @@ compiler_version = ">=1.0.0" [dependencies] bignum = { git = "https://github.com/noir-lang/noir-bignum", tag = "v0.8.2" } poseidon = { git = "https://github.com/noir-lang/poseidon", tag = "v0.1.1" } - diff --git a/src/bigcurve_test.nr b/src/bigcurve_test.nr index 926f0c4..615700b 100644 --- a/src/bigcurve_test.nr +++ b/src/bigcurve_test.nr @@ -583,7 +583,7 @@ fn test_make_table() { unsafe { let P: BN254J = BN254J::one(); - let mut transcript: [JTranscript] = &[]; + let mut transcript: [JTranscript] = @[]; let T: curve_jac::PointTable = curve_jac::PointTable::new(P); for i in 0..8 { transcript = transcript.push_back(T.transcript[i]); diff --git a/src/curve_jac.nr b/src/curve_jac.nr index 19850f8..f07e297 100644 --- a/src/curve_jac.nr +++ b/src/curve_jac.nr @@ -29,7 +29,7 @@ pub struct CurveJ { pub(crate) x: B, pub(crate) y: B, pub(crate) z: B, - pub(crate) is_infinity: bool, + pub is_infinity: bool, } /// A transcript of a group operation in Jacobian coordinates. @@ -67,9 +67,9 @@ where /// # Optimization /// If you have an array of `JTranscript` objects, you can convert them into `AffineTranscript` objects using only one modular inverse. pub struct AffineTranscript { - pub(crate) lambda: B, - pub(crate) x3: B, - pub(crate) y3: B, + pub lambda: B, + pub x3: B, + pub y3: B, } impl AffineTranscript @@ -80,7 +80,7 @@ where AffineTranscript { lambda: B::zero(), x3: B::zero(), y3: B::zero() } } - pub(crate) unconstrained fn from_j(j_tx: JTranscript) -> Self { + pub unconstrained fn from_j(j_tx: JTranscript) -> Self { AffineTranscript::from_jacobian_transcript([j_tx])[0] } @@ -279,11 +279,11 @@ where CurveJ { x: B::zero(), y: B::zero(), z: B::zero(), is_infinity: true } } - pub(crate) unconstrained fn sub(self, p2: Self) -> (Self, JTranscript) { + pub unconstrained fn sub(self, p2: Self) -> (Self, JTranscript) { self.add(p2.neg()) } - pub(crate) unconstrained fn add(self, p2: Self) -> (Self, JTranscript) { + pub unconstrained fn add(self, p2: Self) -> (Self, JTranscript) { let X1 = self.x; let X2 = p2.x; let Y1 = self.y; diff --git a/src/lib.nr b/src/lib.nr index d7998e9..7432e2b 100644 --- a/src/lib.nr +++ b/src/lib.nr @@ -6,13 +6,16 @@ pub(crate) mod utils; pub mod curves; use bignum::BigNum; -use bignum::bignum::evaluate_quadratic_expression; -use crate::curve_jac::AffineTranscript; use crate::scalar_field::ScalarField; use std::ops::{Add, Neg, Sub}; mod benchmarks; +// Re-exports for derive_curve_impl macro +pub use bignum::bignum::evaluate_quadratic_expression; +pub use curve_jac::{AffineTranscript, CurveJ}; +pub use utils::hash_to_curve::hash_to_curve; + /// Implements an elliptic curve over a prime field that is not the circuit's native field. pub struct BigCurveParams { @@ -77,8 +80,8 @@ pub comptime fn derive_curve_impl( params: Quoted, ) -> Quoted { let typ = struct_def.as_type(); - let CurveJ = quote { $crate::curve_jac::CurveJ }; - let AffineTranscript = quote { $crate::curve_jac::AffineTranscript }; + let CurveJ = quote { $crate::CurveJ }; + let AffineTranscript = quote { $crate::AffineTranscript }; quote { impl $crate::BigCurve<$field_type> for $typ { @@ -168,7 +171,7 @@ pub comptime fn derive_curve_impl( } fn hash_to_curve(seed: [u8; N]) -> Self { - let r = $crate::utils::hash_to_curve::hash_to_curve::<$field_type, N>(seed, $params.a, $params.b); + let r = $crate::hash_to_curve::<$field_type, N>(seed, $params.a, $params.b); Self { x: r.0, y: r.1, is_infinity: false } } @@ -183,15 +186,15 @@ pub comptime fn derive_curve_impl( // Expensive witness generation! Avoid if possible impl std::ops::Add for $typ { fn add(self, other: Self) -> Self { - let lhsJ = $crate::curve_jac::CurveJ::<$field_type, $typ>::from(self); - let rhsJ = $crate::curve_jac::CurveJ::<$field_type, $typ>::from(other); + let lhsJ = $crate::CurveJ::<$field_type, $typ>::from(self); + let rhsJ = $crate::CurveJ::<$field_type, $typ>::from(other); let (result_jac, j_transcript) = unsafe { lhsJ.add(rhsJ) }; - let transcript = unsafe { $crate::curve_jac::AffineTranscript::from_j(j_transcript) }; + let transcript = unsafe { $crate::AffineTranscript::from_j(j_transcript) }; if std::runtime::is_unconstrained() { $typ::from_coordinates(transcript.x3, transcript.y3, result_jac.is_infinity) } else { - $crate::add_with_hint::<$field_type, $typ>(self, other, transcript) + $crate::add_with_hint::<$field_type, $typ>(self, other, transcript) } } } @@ -207,12 +210,12 @@ pub comptime fn derive_curve_impl( impl std::ops::Sub for $typ { fn sub(self, other: Self) -> Self { - let lhsJ = $crate::curve_jac::CurveJ::<$field_type, $typ>::from(self); - let rhsJ = $crate::curve_jac::CurveJ::<$field_type, $typ>::from(other); + let lhsJ = $crate::CurveJ::<$field_type, $typ>::from(self); + let rhsJ = $crate::CurveJ::<$field_type, $typ>::from(other); let (result_jac, j_transcript) = unsafe { lhsJ.sub(rhsJ) }; - + // Convert back to affine coordinates using the transcript - let transcript = unsafe { $crate::curve_jac::AffineTranscript::from_j(j_transcript) }; + let transcript = unsafe { $crate::AffineTranscript::from_j(j_transcript) }; if std::runtime::is_unconstrained() { $typ::from_coordinates(transcript.x3, transcript.y3, result_jac.is_infinity) } else { @@ -528,7 +531,7 @@ fn incomplete_subtract_with_hint>( P::from_coordinates(x3, y3, false) } -pub(crate) fn add_with_hint>( +pub fn add_with_hint>( point: P, other: P, transcript: AffineTranscript, @@ -658,7 +661,7 @@ pub(crate) fn add_with_hint>( result } -pub(crate) fn sub_with_hint>( +pub fn sub_with_hint>( point: P, other: P, transcript: AffineTranscript, @@ -807,7 +810,7 @@ pub(crate) fn sub_with_hint>( /// # Note /// /// This function assumes the transcript is generated using unconstrained functions. -pub(crate) fn mul_with_hint>( +pub fn mul_with_hint>( point: P, scalar: ScalarField, transcript: [AffineTranscript; NTranscriptSlices], @@ -888,7 +891,7 @@ fn msm_with_hint>( +pub unconstrained fn get_mul_transcript>( point: P, scalar: ScalarField, ) -> [AffineTranscript; 6 + NScalarSlices * 5] { @@ -897,7 +900,7 @@ unconstrained fn get_mul_transcript, let NScalarSlices: u32, let NMuls: u32, let NAdds: u32>( +pub fn evaluate_linear_expression, let NScalarSlices: u32, let NMuls: u32, let NAdds: u32>( mul_points: [Curve; NMuls], mul_scalars: [ScalarField; NMuls], add_points: [Curve; NAdds], From 1c88692f99578c38994083e745d8d4d9c5aa9f87 Mon Sep 17 00:00:00 2001 From: jialinli Date: Fri, 23 Jan 2026 09:16:28 -0800 Subject: [PATCH 2/3] fix --- src/bigcurve_test.nr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bigcurve_test.nr b/src/bigcurve_test.nr index 615700b..926f0c4 100644 --- a/src/bigcurve_test.nr +++ b/src/bigcurve_test.nr @@ -583,7 +583,7 @@ fn test_make_table() { unsafe { let P: BN254J = BN254J::one(); - let mut transcript: [JTranscript] = @[]; + let mut transcript: [JTranscript] = &[]; let T: curve_jac::PointTable = curve_jac::PointTable::new(P); for i in 0..8 { transcript = transcript.push_back(T.transcript[i]); From 92ca371a7c7805cdc0be6e9fae96c80a3f95561e Mon Sep 17 00:00:00 2001 From: jialinli Date: Fri, 23 Jan 2026 09:27:33 -0800 Subject: [PATCH 3/3] remove unused variable --- src/lib.nr | 1 - 1 file changed, 1 deletion(-) diff --git a/src/lib.nr b/src/lib.nr index 7432e2b..d85e005 100644 --- a/src/lib.nr +++ b/src/lib.nr @@ -80,7 +80,6 @@ pub comptime fn derive_curve_impl( params: Quoted, ) -> Quoted { let typ = struct_def.as_type(); - let CurveJ = quote { $crate::CurveJ }; let AffineTranscript = quote { $crate::AffineTranscript }; quote {