Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
297 changes: 158 additions & 139 deletions Cargo.lock

Large diffs are not rendered by default.

36 changes: 18 additions & 18 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,24 @@ either = { version = "1.15.*", features = ["serde"] }
generic-array = { version = "1.1.0", features = ["alloc", "serde"] }
itertools = "0.13"
num = "0.4.3"
p3-air = { git = "https://github.com/Plonky3/Plonky3.git", rev = "539bbc84085efb609f4f62cb03cf49588388abdb" }
p3-baby-bear = { git = "https://github.com/Plonky3/Plonky3.git", rev = "539bbc84085efb609f4f62cb03cf49588388abdb" }
p3-challenger = { git = "https://github.com/Plonky3/Plonky3.git", rev = "539bbc84085efb609f4f62cb03cf49588388abdb" }
p3-commit = { git = "https://github.com/Plonky3/Plonky3.git", rev = "539bbc84085efb609f4f62cb03cf49588388abdb" }
p3-dft = { git = "https://github.com/Plonky3/Plonky3.git", rev = "539bbc84085efb609f4f62cb03cf49588388abdb" }
p3-field = { git = "https://github.com/Plonky3/Plonky3.git", rev = "539bbc84085efb609f4f62cb03cf49588388abdb" }
p3-fri = { git = "https://github.com/Plonky3/Plonky3.git", rev = "539bbc84085efb609f4f62cb03cf49588388abdb" }
p3-goldilocks = { git = "https://github.com/Plonky3/Plonky3.git", rev = "539bbc84085efb609f4f62cb03cf49588388abdb" }
p3-matrix = { git = "https://github.com/Plonky3/Plonky3.git", rev = "539bbc84085efb609f4f62cb03cf49588388abdb" }
p3-maybe-rayon = { git = "https://github.com/Plonky3/Plonky3.git", rev = "539bbc84085efb609f4f62cb03cf49588388abdb" }
p3-mds = { git = "https://github.com/Plonky3/Plonky3.git", rev = "539bbc84085efb609f4f62cb03cf49588388abdb" }
p3-merkle-tree = { git = "https://github.com/Plonky3/Plonky3.git", rev = "539bbc84085efb609f4f62cb03cf49588388abdb" }
p3-monty-31 = { git = "https://github.com/Plonky3/Plonky3.git", rev = "539bbc84085efb609f4f62cb03cf49588388abdb" }
p3-poseidon = { git = "https://github.com/Plonky3/Plonky3.git", rev = "539bbc84085efb609f4f62cb03cf49588388abdb" }
p3-poseidon2 = { git = "https://github.com/Plonky3/Plonky3.git", rev = "539bbc84085efb609f4f62cb03cf49588388abdb" }
p3-poseidon2-air = { git = "https://github.com/Plonky3/Plonky3.git", rev = "539bbc84085efb609f4f62cb03cf49588388abdb" }
p3-symmetric = { git = "https://github.com/Plonky3/Plonky3.git", rev = "539bbc84085efb609f4f62cb03cf49588388abdb" }
p3-util = { git = "https://github.com/Plonky3/Plonky3.git", rev = "539bbc84085efb609f4f62cb03cf49588388abdb" }
p3-air = { version = "=0.4.1", default-features = false }
p3-baby-bear = { version = "=0.4.1", default-features = false }
p3-challenger = { version = "=0.4.1", default-features = false }
p3-commit = { version = "=0.4.1", default-features = false }
p3-dft = { version = "=0.4.1", default-features = false }
p3-field = { version = "=0.4.1", default-features = false }
p3-fri = { version = "=0.4.1", default-features = false }
p3-goldilocks = { version = "=0.4.1", default-features = false }
p3-matrix = { version = "=0.4.1", default-features = false }
p3-maybe-rayon = { version = "=0.4.1", default-features = false }
p3-mds = { version = "=0.4.1", default-features = false }
p3-merkle-tree = { version = "=0.4.1", default-features = false }
p3-monty-31 = { version = "=0.4.1", default-features = false }
p3-poseidon = { version = "=0.4.1", default-features = false }
p3-poseidon2 = { version = "=0.4.1", default-features = false }
p3-poseidon2-air = { version = "=0.4.1", default-features = false }
p3-symmetric = { version = "=0.4.1", default-features = false }
p3-util = { version = "=0.4.1", default-features = false }
rand = "0.8"
rand_chacha = { version = "0.3", features = ["serde1"] }
rand_core = "0.6"
Expand Down
17 changes: 16 additions & 1 deletion clippy.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
# TODO(Matthias): review and see which exception we can remove over time.
# Eg removing syn is blocked by ark-ff-asm cutting a new release
# (https://github.com/arkworks-rs/algebra/issues/813) amongst other things.
allowed-duplicate-crates = ["regex-automata", "regex-syntax"]
allowed-duplicate-crates = [
"dashu-base",
"dashu-float",
"dashu-int",
"dashu-ratio",
"generic-array",
"itertools",
"thiserror",
"thiserror-impl",
"regex-automata",
"regex-syntax",
"rand",
"rand_chacha",
"rand_core",
"getrandom",
]
4 changes: 2 additions & 2 deletions crates/curves/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ generic-array.workspace = true
k256 = { version = "0.13.3", features = ["expose-field"] }
num.workspace = true
p256 = { version = "0.13.2", features = ["expose-field"] }
p3-field.workspace = true
p3.workspace = true
serde = { workspace = true, features = ["derive"] }
typenum = "1.17.0"

Expand All @@ -31,7 +31,7 @@ rug = { version = "1.26.1", optional = true }

[dev-dependencies]
num = { version = "0.4.3", features = ["rand"] }
rand = "0.8.5"
rand.workspace = true

[features]
bigint-rug = ["rug"]
6 changes: 3 additions & 3 deletions crates/curves/src/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use typenum::{U2, U4, Unsigned};
use generic_array::{ArrayLength, GenericArray, sequence::GenericSequence};
use num::BigUint;

use p3_field::Field;
use p3::field::Field;

use crate::{polynomial::Polynomial, utils::biguint_from_limbs};

Expand Down Expand Up @@ -49,7 +49,7 @@ pub trait FieldParameters:
fn modulus_field_iter<F: Field>() -> impl Iterator<Item = F> {
Self::MODULUS
.iter()
.map(|x| F::from_canonical_u8(*x))
.map(|x| F::from_u8(*x))
.take(Self::NB_LIMBS)
}

Expand All @@ -64,7 +64,7 @@ pub trait FieldParameters:
fn to_limbs_field_vec<E: From<F>, F: Field>(x: &BigUint) -> Vec<E> {
Self::to_limbs(x)
.into_iter()
.map(|x| F::from_canonical_u8(x).into())
.map(|x| F::from_u8(x).into())
.collect::<Vec<_>>()
}

Expand Down
44 changes: 15 additions & 29 deletions crates/curves/src/polynomial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use core::{
use std::slice::Iter;

use itertools::Itertools;
use p3_field::{Field, FieldAlgebra, FieldExtensionAlgebra};
use p3::field::{Algebra, Field};

/// A polynomial represented as a vector of coefficients.
#[derive(Debug, Clone)]
Expand Down Expand Up @@ -45,15 +45,16 @@ impl<T> Polynomial<T> {
}

/// Evaluates the polynomial at a given point.
pub fn eval<S: FieldExtensionAlgebra<T>>(&self, x: S) -> S
pub fn eval<S>(&self, x: S) -> S
where
T: FieldAlgebra,
S: Field + Algebra<T>,
T: Field,
{
let powers = x.powers();
self.coefficients
.iter()
.zip(powers)
.map(|(c, x)| x * c.clone())
.map(|(c, x)| x * *c)
.sum()
}

Expand Down Expand Up @@ -197,62 +198,51 @@ impl<T: Sub<Output = T> + Neg<Output = T> + Clone> Sub for &Polynomial<T> {
}
}

impl<T: FieldAlgebra> Mul for Polynomial<T> {
impl<T: Field> Mul for Polynomial<T> {
type Output = Self;

fn mul(self, other: Self) -> Self {
let mut result = vec![T::ZERO; self.coefficients.len() + other.coefficients.len() - 1];
for (i, a) in self.coefficients.into_iter().enumerate() {
for (j, b) in other.coefficients.iter().enumerate() {
result[i + j] = result[i + j].clone() + a.clone() * b.clone();
result[i + j] += a * *b;
}
}
Self::new(result)
}
}

impl<T: FieldAlgebra> Mul for &Polynomial<T> {
impl<T: Field> Mul for &Polynomial<T> {
type Output = Polynomial<T>;

fn mul(self, other: Self) -> Polynomial<T> {
let mut result = vec![T::ZERO; self.coefficients.len() + other.coefficients.len() - 1];
for (i, a) in self.coefficients.iter().enumerate() {
for (j, b) in other.coefficients.iter().enumerate() {
result[i + j] = result[i + j].clone() + a.clone() * b.clone();
result[i + j] += *a * *b;
}
}
Polynomial::new(result)
}
}

impl<T: FieldAlgebra> Mul<T> for Polynomial<T> {
impl<T: Field> Mul<T> for Polynomial<T> {
type Output = Self;

fn mul(self, other: T) -> Self {
Self::new(
self.coefficients
.into_iter()
.map(|x| x * other.clone())
.collect(),
)
Self::new(self.coefficients.into_iter().map(|x| x * other).collect())
}
}

impl<T: FieldAlgebra> Mul<T> for &Polynomial<T> {
impl<T: Field> Mul<T> for &Polynomial<T> {
type Output = Polynomial<T>;

fn mul(self, other: T) -> Polynomial<T> {
Polynomial::new(
self.coefficients
.iter()
.cloned()
.map(|x| x * other.clone())
.collect(),
)
Polynomial::new(self.coefficients.iter().map(|x| *x * other).collect())
}
}

impl<T: Eq + FieldAlgebra> PartialEq<Polynomial<T>> for Polynomial<T> {
impl<T: Eq + Field> PartialEq<Polynomial<T>> for Polynomial<T> {
fn eq(&self, other: &Polynomial<T>) -> bool {
if self.coefficients.len() != other.coefficients.len() {
let (shorter, longer) = if self.coefficients.len() < other.coefficients.len() {
Expand All @@ -277,11 +267,7 @@ impl<T: Eq + FieldAlgebra> PartialEq<Polynomial<T>> for Polynomial<T> {
impl Polynomial<u8> {
pub fn as_field<F: Field>(self) -> Polynomial<F> {
Polynomial {
coefficients: self
.coefficients
.iter()
.map(|x| F::from_canonical_u8(*x))
.collect(),
coefficients: self.coefficients.iter().map(|x| F::from_u8(*x)).collect(),
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions crates/ff_ext/src/babybear.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub mod impl_babybear {
babybear::{BabyBear, Poseidon2BabyBear},
challenger::DuplexChallenger,
field::{
Field, FieldAlgebra, FieldExtensionAlgebra, PackedValue, PrimeField32, TwoAdicField,
Field, PrimeCharacteristicRing, PrimeField32, TwoAdicField,
extension::{BinomialExtensionField, BinomiallyExtendable},
},
merkle_tree::MerkleTreeMmcs,
Expand Down Expand Up @@ -76,13 +76,13 @@ pub mod impl_babybear {

impl FieldFrom<u64> for BabyBear {
fn from_v(v: u64) -> Self {
Self::from_canonical_u64(v)
Self::from_u64(v)
}
}

impl FieldFrom<u64> for BabyBearExt4 {
fn from_v(v: u64) -> Self {
Self::from_canonical_u64(v)
Self::from_u64(v)
}
}

Expand Down Expand Up @@ -167,7 +167,7 @@ pub mod impl_babybear {
fn try_from_uniform_bytes(bytes: [u8; 8]) -> Option<Self> {
let value = u32::from_le_bytes(bytes[..4].try_into().unwrap());
let is_canonical = value < Self::ORDER_U32;
is_canonical.then(|| Self::from_canonical_u32(value))
is_canonical.then(|| Self::from_u32(value))
}
}

Expand All @@ -183,7 +183,7 @@ pub mod impl_babybear {
array[..chunk.len()].copy_from_slice(chunk);
unsafe { std::ptr::read_unaligned(array.as_ptr() as *const u32) }
})
.map(Self::from_canonical_u32)
.map(Self::from_u32)
.collect::<Vec<_>>()
}

Expand All @@ -206,7 +206,7 @@ pub mod impl_babybear {
type BaseField = BabyBear;

fn to_canonical_u64_vec(&self) -> Vec<u64> {
self.as_base_slice()
self.as_bases()
.iter()
.map(|v: &Self::BaseField| v.as_canonical_u32() as u64)
.collect()
Expand Down
14 changes: 7 additions & 7 deletions crates/ff_ext/src/goldilock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub mod impl_goldilocks {
use p3::{
challenger::DuplexChallenger,
field::{
Field, FieldAlgebra, FieldExtensionAlgebra, PackedValue, PrimeField64, TwoAdicField,
Field, PrimeCharacteristicRing, PrimeField64, TwoAdicField,
extension::{BinomialExtensionField, BinomiallyExtendable},
},
goldilocks::{
Expand All @@ -27,13 +27,13 @@ pub mod impl_goldilocks {

impl FieldFrom<u64> for Goldilocks {
fn from_v(v: u64) -> Self {
Self::from_canonical_u64(v)
Self::from_u64(v)
}
}

impl FieldFrom<u64> for GoldilocksExt2 {
fn from_v(v: u64) -> Self {
Self::from_canonical_u64(v)
Self::from_u64(v)
}
}

Expand Down Expand Up @@ -92,7 +92,7 @@ pub mod impl_goldilocks {
.flatten()
.chain(HL_GOLDILOCKS_8_INTERNAL_ROUND_CONSTANTS.iter())
.chain(HL_GOLDILOCKS_8_EXTERNAL_ROUND_CONSTANTS[1].iter().flatten())
.map(|v| Self::from_canonical_u64(*v))
.map(|v| Self::from_u64(*v))
.collect()
}

Expand All @@ -117,7 +117,7 @@ pub mod impl_goldilocks {
fn try_from_uniform_bytes(bytes: [u8; 8]) -> Option<Self> {
let value = u64::from_le_bytes(bytes);
let is_canonical = value < Self::ORDER_U64;
is_canonical.then(|| Self::from_canonical_u64(value))
is_canonical.then(|| Self::from_u64(value))
}
}

Expand All @@ -133,7 +133,7 @@ pub mod impl_goldilocks {
array[..chunk.len()].copy_from_slice(chunk);
unsafe { std::ptr::read_unaligned(array.as_ptr() as *const u64) }
})
.map(Self::from_canonical_u64)
.map(Self::from_u64)
.collect::<Vec<_>>()
}

Expand All @@ -154,7 +154,7 @@ pub mod impl_goldilocks {
type BaseField = Goldilocks;

fn to_canonical_u64_vec(&self) -> Vec<u64> {
self.as_base_slice()
self.as_bases()
.iter()
.map(|v: &Self::BaseField| v.as_canonical_u64())
.collect()
Expand Down
Loading
Loading