diff --git a/ff-macros/Cargo.toml b/ff-macros/Cargo.toml index 4d6f43a37..dc9274860 100644 --- a/ff-macros/Cargo.toml +++ b/ff-macros/Cargo.toml @@ -23,3 +23,6 @@ num-traits.workspace = true [lib] proc-macro = true + +[features] +zkllvm = [] diff --git a/ff-macros/src/lib.rs b/ff-macros/src/lib.rs index 9d90d5840..1755793b4 100644 --- a/ff-macros/src/lib.rs +++ b/ff-macros/src/lib.rs @@ -8,7 +8,7 @@ #![forbid(unsafe_code)] use num_bigint::BigUint; -use proc_macro::TokenStream; +use proc_macro::{Literal, TokenStream, TokenTree}; use syn::{Expr, Item, ItemFn, Lit}; mod montgomery; @@ -27,6 +27,13 @@ pub fn to_sign_and_limbs(input: TokenStream) -> TokenStream { quote::quote!(#tuple).into() } +#[cfg(feature = "zkllvm")] +#[proc_macro] +pub fn to_field_literal(input: TokenStream) -> TokenStream { + let num = utils::parse_string(input).expect("expected decimal string"); + TokenTree::Literal(Literal::field(&num)).into() +} + /// Derive the `MontConfig` trait. /// /// The attributes available to this macro are diff --git a/ff/Cargo.toml b/ff/Cargo.toml index bfbf07798..4ecf511d1 100644 --- a/ff/Cargo.toml +++ b/ff/Cargo.toml @@ -48,6 +48,7 @@ default = [] std = [ "ark-std/std", "ark-serialize/std", "itertools/use_std" ] parallel = [ "std", "rayon", "ark-std/parallel" ] asm = [] +zkllvm = [ "ark-ff-macros/zkllvm" ] [package.metadata.docs.rs] diff --git a/ff/src/fields/models/fp/montgomery_backend.rs b/ff/src/fields/models/fp/montgomery_backend.rs index 3ea75b884..67bae0532 100644 --- a/ff/src/fields/models/fp/montgomery_backend.rs +++ b/ff/src/fields/models/fp/montgomery_backend.rs @@ -588,6 +588,7 @@ pub const fn sqrt_precomputation>( /// } /// ``` #[macro_export] +#[cfg(not(feature = "zkllvm"))] macro_rules! MontFp { ($c0:expr) => {{ let (is_positive, limbs) = $crate::ark_ff_macros::to_sign_and_limbs!($c0); @@ -595,6 +596,14 @@ macro_rules! MontFp { }}; } +#[macro_export] +#[cfg(feature = "zkllvm")] +macro_rules! MontFp { + ($c0:expr) => {{ + $crate::ark_ff_macros::to_field_literal!($c0) + }}; +} + pub use ark_ff_macros::MontConfig; pub use MontFp;