@@ -6,13 +6,16 @@ pub(crate) mod utils;
66pub mod curves ;
77
88use bignum::BigNum ;
9- use bignum::bignum::evaluate_quadratic_expression ;
109
11- use crate::curve_jac::AffineTranscript ;
1210use crate::scalar_field::ScalarField ;
1311use std::ops:: {Add , Neg , Sub };
1412mod benchmarks ;
1513
14+ // Re-exports for derive_curve_impl macro
15+ pub use bignum::bignum::evaluate_quadratic_expression ;
16+ pub use curve_jac:: {AffineTranscript , CurveJ };
17+ pub use utils::hash_to_curve::hash_to_curve ;
18+
1619/// Implements an elliptic curve over a prime field that is not the circuit's native field.
1720
1821pub struct BigCurveParams <B > {
@@ -77,8 +80,8 @@ pub comptime fn derive_curve_impl(
7780 params : Quoted ,
7881) -> Quoted {
7982 let typ = struct_def .as_type ();
80- let CurveJ = quote { $crate ::curve_jac:: CurveJ };
81- let AffineTranscript = quote { $crate ::curve_jac:: AffineTranscript };
83+ let CurveJ = quote { $crate ::CurveJ };
84+ let AffineTranscript = quote { $crate ::AffineTranscript };
8285
8386 quote {
8487 impl $crate ::BigCurve <$field_type > for $typ {
@@ -168,7 +171,7 @@ pub comptime fn derive_curve_impl(
168171 }
169172
170173 fn hash_to_curve <let N : u32 >(seed : [u8 ; N ]) -> Self {
171- let r = $crate ::utils::hash_to_curve:: hash_to_curve ::<$field_type , N >(seed , $params .a , $params .b );
174+ let r = $crate ::hash_to_curve ::<$field_type , N >(seed , $params .a , $params .b );
172175 Self { x : r .0 , y : r .1 , is_infinity : false }
173176 }
174177
@@ -183,15 +186,15 @@ pub comptime fn derive_curve_impl(
183186 // Expensive witness generation! Avoid if possible
184187 impl std::ops::Add for $typ {
185188 fn add (self , other : Self ) -> Self {
186- let lhsJ = $crate ::curve_jac:: CurveJ ::<$field_type , $typ >::from (self );
187- let rhsJ = $crate ::curve_jac:: CurveJ ::<$field_type , $typ >::from (other );
189+ let lhsJ = $crate ::CurveJ ::<$field_type , $typ >::from (self );
190+ let rhsJ = $crate ::CurveJ ::<$field_type , $typ >::from (other );
188191 let (result_jac , j_transcript ) = unsafe { lhsJ .add (rhsJ ) };
189- let transcript = unsafe { $crate ::curve_jac:: AffineTranscript ::from_j (j_transcript ) };
192+ let transcript = unsafe { $crate ::AffineTranscript ::from_j (j_transcript ) };
190193 if std::runtime:: is_unconstrained () {
191194 $typ:: from_coordinates (transcript .x3 , transcript .y3 , result_jac .is_infinity )
192195
193196 } else {
194- $crate ::add_with_hint ::<$field_type , $typ >(self , other , transcript )
197+ $crate ::add_with_hint ::<$field_type , $typ >(self , other , transcript )
195198 }
196199 }
197200 }
@@ -207,12 +210,12 @@ pub comptime fn derive_curve_impl(
207210
208211 impl std::ops::Sub for $typ {
209212 fn sub (self , other : Self ) -> Self {
210- let lhsJ = $crate ::curve_jac:: CurveJ ::<$field_type , $typ >::from (self );
211- let rhsJ = $crate ::curve_jac:: CurveJ ::<$field_type , $typ >::from (other );
213+ let lhsJ = $crate ::CurveJ ::<$field_type , $typ >::from (self );
214+ let rhsJ = $crate ::CurveJ ::<$field_type , $typ >::from (other );
212215 let (result_jac , j_transcript ) = unsafe { lhsJ .sub (rhsJ ) };
213-
216+
214217 // Convert back to affine coordinates using the transcript
215- let transcript = unsafe { $crate ::curve_jac:: AffineTranscript ::from_j (j_transcript ) };
218+ let transcript = unsafe { $crate ::AffineTranscript ::from_j (j_transcript ) };
216219 if std::runtime:: is_unconstrained () {
217220 $typ:: from_coordinates (transcript .x3 , transcript .y3 , result_jac .is_infinity )
218221 } else {
@@ -528,7 +531,7 @@ fn incomplete_subtract_with_hint<B: BigNum, P: BigCurve<B>>(
528531 P ::from_coordinates (x3 , y3 , false )
529532}
530533
531- pub ( crate ) fn add_with_hint <B : BigNum , P : BigCurve <B >>(
534+ pub fn add_with_hint <B : BigNum , P : BigCurve <B >>(
532535 point : P ,
533536 other : P ,
534537 transcript : AffineTranscript <B >,
@@ -658,7 +661,7 @@ pub(crate) fn add_with_hint<B: BigNum, P: BigCurve<B>>(
658661 result
659662}
660663
661- pub ( crate ) fn sub_with_hint <B : BigNum , P : BigCurve <B >>(
664+ pub fn sub_with_hint <B : BigNum , P : BigCurve <B >>(
662665 point : P ,
663666 other : P ,
664667 transcript : AffineTranscript <B >,
@@ -807,7 +810,7 @@ pub(crate) fn sub_with_hint<B: BigNum, P: BigCurve<B>>(
807810/// # Note
808811///
809812/// This function assumes the transcript is generated using unconstrained functions.
810- pub ( crate ) fn mul_with_hint <let NScalarSlices : u32 , let NTranscriptSlices : u32 , B : BigNum , P : BigCurve <B >>(
813+ pub fn mul_with_hint <let NScalarSlices : u32 , let NTranscriptSlices : u32 , B : BigNum , P : BigCurve <B >>(
811814 point : P ,
812815 scalar : ScalarField <NScalarSlices >,
813816 transcript : [AffineTranscript <B >; NTranscriptSlices ],
@@ -888,7 +891,7 @@ fn msm_with_hint<let Size: u32, let NScalarSlices: u32, let NTranscriptSlices: u
888891 accumulator
889892}
890893
891- unconstrained fn get_mul_transcript <let NScalarSlices : u32 , B : BigNum , P : BigCurve <B >>(
894+ pub unconstrained fn get_mul_transcript <let NScalarSlices : u32 , B : BigNum , P : BigCurve <B >>(
892895 point : P ,
893896 scalar : ScalarField <NScalarSlices >,
894897) -> [AffineTranscript <B >; 6 + NScalarSlices * 5 ] {
@@ -897,7 +900,7 @@ unconstrained fn get_mul_transcript<let NScalarSlices: u32, B: BigNum, P: BigCur
897900 transcript
898901}
899902
900- fn evaluate_linear_expression <F : BigNum , Curve : BigCurve <F >, let NScalarSlices : u32 , let NMuls : u32 , let NAdds : u32 >(
903+ pub fn evaluate_linear_expression <F : BigNum , Curve : BigCurve <F >, let NScalarSlices : u32 , let NMuls : u32 , let NAdds : u32 >(
901904 mul_points : [Curve ; NMuls ],
902905 mul_scalars : [ScalarField <NScalarSlices >; NMuls ],
903906 add_points : [Curve ; NAdds ],
0 commit comments