Crate ark_feanor

Crate ark_feanor 

Source
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 PrimeField types
  • 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§

DegRevLex
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.
PreparedDivisor
Struct for ring elements that are stored with associated data to enable faster divisions.
RingElementDisplayWrapper
Wrapper around a ring and one of its elements that implements std::fmt::Display and will print the element. Used by RingStore::format().
RingRef
The second most basic crate::ring::RingStore. Similarly to crate::ring::RingValue it is just a no-op container.
RingValue
The most fundamental crate::ring::RingStore. It is basically a no-op container, i.e. stores a crate::ring::RingBase object by value, and allows accessing it.

Enums§

EnvBindingStrength
Describes the context in which to print an algebraic expression. It is usually used to determine when to use parenthesis during printing.

Constants§

NAME
Library name
VERSION
Version information

Traits§

DivisibilityRing
Trait for rings that support checking divisibility, i.e. whether for x, y there is k such that x = ky.
DivisibilityRingStore
Trait for RingStores that store DivisibilityRings. Mainly used to provide a convenient interface to the DivisibilityRing-functions.
Domain
Trait for rings that are integral, i.e. have no zero divisors.
EuclideanRing
Trait for rings that support euclidean division.
EuclideanRingStore
RingStore for EuclideanRings
HashableElRing
Trait for rings that can compute hashes for their elements. This should be compatible with RingBase::eq_el in the usual way.
HashableElRingStore
RingStore for HashableElRings
MultivariatePolyRingStore
RingStore for MultivariatePolyRing
PolyRingStore
RingStore corresponding to PolyRing.
PrincipalIdealRing
Trait for rings that are principal ideal rings, i.e. every ideal is generated by a single element.
PrincipalIdealRingStore
Trait for RingStores that store PrincipalIdealRings. Mainly used to provide a convenient interface to the PrincipalIdealRing-functions.
RingBase
Basic trait for objects that have a ring structure. This trait is implementor-facing, so designed to be used for implementing new rings.
RingExtension
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.
RingExtensionStore
RingStore for RingExtensions
RingStore
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§

DensePolyRing
The univariate polynomial ring R[X], with polynomials being stored as dense vectors of coefficients. For details, see DensePolyRingBase.
El
Alias for <<Self as RingStore>::Type as RingBase>::Element.
MultivariatePolyRingImpl
RingStore corresponding to MultivariatePolyRingImplBase