diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e5eced54..10e382fb7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ - (`ark-poly`) Add fast polynomial division - (`ark-ec`) Improve GLV scalar multiplication performance by skipping leading zeroes. - (`ark-poly`) Make `SparsePolynomial.coeffs` field public +- [\#1044](https://github.com/arkworks-rs/algebra/pull/1044) Add implementation for small field with native integer types ### Breaking changes diff --git a/ff-macros/src/lib.rs b/ff-macros/src/lib.rs index 41e19f0bd..1efd9c4e2 100644 --- a/ff-macros/src/lib.rs +++ b/ff-macros/src/lib.rs @@ -12,6 +12,7 @@ use proc_macro::TokenStream; use syn::{Expr, ExprLit, Item, ItemFn, Lit, Meta}; mod montgomery; +mod small_fp; mod unroll; pub(crate) mod utils; @@ -74,6 +75,34 @@ pub fn mont_config(input: proc_macro::TokenStream) -> proc_macro::TokenStream { .into() } +/// Derive the `SmallFpConfig` trait for small prime fields. +/// +/// The attributes available to this macro are: +/// * `modulus`: Specify the prime modulus underlying this prime field. +/// * `generator`: Specify the generator of the multiplicative subgroup. +/// * `backend`: Specify either "standard" or "montgomery" backend. +#[proc_macro_derive(SmallFpConfig, attributes(modulus, generator, backend))] +pub fn small_fp_config(input: TokenStream) -> TokenStream { + let ast: syn::DeriveInput = syn::parse(input).unwrap(); + + let modulus: u128 = fetch_attr("modulus", &ast.attrs) + .expect("Please supply a modulus attribute") + .parse() + .expect("Modulus should be a number"); + + let generator: u128 = fetch_attr("generator", &ast.attrs) + .expect("Please supply a generator attribute") + .parse() + .expect("Generator should be a number"); + + let backend: String = fetch_attr("backend", &ast.attrs) + .expect("Please supply a backend attribute") + .parse() + .expect("Backend should be a string"); + + small_fp::small_fp_config_helper(modulus, generator, backend, ast.ident).into() +} + const ARG_MSG: &str = "Failed to parse unroll threshold; must be a positive integer"; /// Attribute used to unroll for loops found inside a function block. diff --git a/ff/Cargo.toml b/ff/Cargo.toml index 30323fdaa..31965cb92 100644 --- a/ff/Cargo.toml +++ b/ff/Cargo.toml @@ -42,4 +42,4 @@ hex.workspace = true default = [] std = [ "ark-std/std", "ark-serialize/std" ] parallel = [ "std", "rayon", "ark-std/parallel", "ark-serialize/parallel" ] -asm = [] +asm = [] \ No newline at end of file