Expand description
§ark-feanor
A bridge between arkworks’ finite field types and feanor-math’s ring system.
This library enables using feanor-math’s advanced polynomial and Gröbner basis algorithms with arkworks’ cryptographic field implementations, particularly for curves like BLS12-381 and BN254.
§Features
- Zero-cost abstraction: Minimal overhead when wrapping arkworks fields
- Full ring support: Implements all necessary feanor-math traits
- Prime field specialization: Additional functionality for prime fields including division
- Common fields: Pre-configured types for BN254 and BLS12-381
- Polynomial support: Create and manipulate polynomials over cryptographic fields
- Gröbner basis: Compute Gröbner bases for polynomial systems
§Quick Start
ⓘ
use ark_feanor::*;
use ark_bn254::Fr;
// Method 1: Use pre-configured field
let field = &*BN254_FR;
let a = field.int_hom().map(5);
let b = field.int_hom().map(3);
let c = field.add(a, b);
// Method 2: Create your own wrapper
let my_field = ArkFieldWrapper::<Fr>::new();
let x = my_field.from_int(10);
let y = my_field.from_int(20);
let z = my_field.mul_ref(&x, &y);§Polynomial Example
ⓘ
use ark_feanor::*;
use feanor_math::rings::multivariate::*;
// Create polynomial ring BLS12-381_Fr[x, y]
let field = &*BLS12_381_FR;
let poly_ring = MultivariatePolyRingImpl::new(field, 2);
// Create polynomials: x² + y² - 1 and xy - 2
let polys = poly_ring.with_wrapped_indeterminates(|[x, y]| {
vec![
x.clone().pow(2) + y.clone().pow(2) - 1,
x * y - 2,
]
});§Gröbner Basis Computation with F4
ark-feanor implements the F4 algorithm for computing Gröbner bases. F4 processes S-polynomials in batches via matrix reduction, making it efficient for dense systems over cryptographic fields.
ⓘ
use ark_feanor::*;
use ark_feanor::f4::*;
let field = &*BN254_FR;
let poly_ring = MultivariatePolyRingImpl::new(field, 2);
let system = vec![/* your polynomials */];
// Compute Gröbner basis with F4
let gb = f4_simple(&poly_ring, system, DegRevLex);§With Configuration Options
ⓘ
use ark_feanor::*;
use ark_feanor::f4::*;
let field = &*BN254_FR;
let poly_ring = MultivariatePolyRingImpl::new(field, 2);
// Configure with degree limit to avoid explosion
let config = F4Config::new()
.with_max_degree(10); // Abort if degrees exceed 10
let system = vec![/* your polynomials */];
// Compute with configuration
match f4_configured(&poly_ring, system, DegRevLex, config) {
Ok(gb) => println!("Computed GB with {} elements", gb.len()),
Err(GBAborted::DegreeExceeded { max_degree, actual_degree }) => {
println!("Aborted: degree {} exceeded limit {}", actual_degree, max_degree);
}
Err(e) => println!("Error: {:?}", e),
}§Type Aliases
For convenience, this library provides type aliases for common fields:
BN254ScalarField/BN254_FR: The BN254 scalar field (Fr)BN254BaseField/BN254_FQ: The BN254 base field (Fq)BLS12_381ScalarField/BLS12_381_FR: The BLS12-381 scalar field (Fr)BLS12_381BaseField/BLS12_381_FQ: The BLS12-381 base field (Fq)
§Performance
The wrapper is designed to have minimal overhead. Field operations through
ArkFieldWrapper should be within 5% of direct arkworks operations.
§Limitations
- Extension fields (Fq2, Fq6, Fq12) are not yet optimally supported
- Characteristic extraction only works for
PrimeFieldtypes - Some advanced feanor-math features may not be available for all field types
Re-exports§
pub use field_wrapper::ArkFieldWrapper;pub use conversions::extract_characteristic;pub use conversions::biguint_to_field;pub use conversions::bigint_to_field;pub use conversions::i64_to_field;pub use conversions::field_to_biguint;pub use conversions::field_to_small_int;pub use prime_field::FieldProperties;pub use f4::GBAborted;pub use common_fields::*;
Modules§
- common_
fields - Common field type aliases for easy access to popular cryptographic fields.
- conversions
- Type conversions between arkworks and feanor-math types.
- f4
- F4 algorithm for Gröbner basis computation
- field_
wrapper - Core field wrapper that implements feanor-math’s RingBase trait for arkworks fields.
- homomorphisms
- Homomorphisms between arkworks fields and other ring structures.
- prime_
field - Prime field specializations that enable division and field operations.
Structs§
- DegRev
Lex - The graded reverse lexicographic order. This is the most important monomial order, since computing a Groebner basis w.r.t. this order is usually more efficient than for other orders. Also sometimes referred to as “grevlex”.
- Lex
- Lexicographic ordering of monomials.
- Prepared
Divisor - Struct for ring elements that are stored with associated data to enable faster divisions.
- Ring
Element Display Wrapper - Wrapper around a ring and one of its elements that implements
std::fmt::Displayand will print the element. Used byRingStore::format(). - RingRef
- The second most basic
crate::ring::RingStore. Similarly tocrate::ring::RingValueit is just a no-op container. - Ring
Value - The most fundamental
crate::ring::RingStore. It is basically a no-op container, i.e. stores acrate::ring::RingBaseobject by value, and allows accessing it.
Enums§
- EnvBinding
Strength - Describes the context in which to print an algebraic expression. It is usually used to determine when to use parenthesis during printing.
Constants§
Traits§
- Divisibility
Ring - Trait for rings that support checking divisibility, i.e.
whether for
x, ythere isksuch thatx = ky. - Divisibility
Ring Store - Trait for
RingStores that storeDivisibilityRings. Mainly used to provide a convenient interface to theDivisibilityRing-functions. - Domain
- Trait for rings that are integral, i.e. have no zero divisors.
- Euclidean
Ring - Trait for rings that support euclidean division.
- Euclidean
Ring Store RingStoreforEuclideanRings- Hashable
ElRing - Trait for rings that can compute hashes for their elements.
This should be compatible with
RingBase::eq_elin the usual way. - Hashable
ElRing Store RingStoreforHashableElRings- Multivariate
Poly Ring Store RingStoreforMultivariatePolyRing- Poly
Ring Store RingStorecorresponding toPolyRing.- Principal
Ideal Ring - Trait for rings that are principal ideal rings, i.e. every ideal is generated by a single element.
- Principal
Ideal Ring Store - Trait for
RingStores that storePrincipalIdealRings. Mainly used to provide a convenient interface to thePrincipalIdealRing-functions. - Ring
Base - Basic trait for objects that have a ring structure. This trait is implementor-facing, so designed to be used for implementing new rings.
- Ring
Extension - Trait for rings that are an extension ring of a base ring. This does not have to be a proper extension in the mathematical sense, but is in some cases implemented for a wrapper of a ring object that represents the same ring.
- Ring
Extension Store RingStoreforRingExtensions- Ring
Store - Basic trait for objects that store (in some sense) a ring. It can also
be considered the user-facing trait for rings, so rings are always supposed
to be used through a
RingStore-object.
Type Aliases§
- Dense
Poly Ring - The univariate polynomial ring
R[X], with polynomials being stored as dense vectors of coefficients. For details, seeDensePolyRingBase. - El
- Alias for
<<Self as RingStore>::Type as RingBase>::Element. - Multivariate
Poly Ring Impl RingStorecorresponding toMultivariatePolyRingImplBase