Skip to content

Commit 2f15abb

Browse files
authored
Merge branch 'main' into opt/11-parallel-fri-fold
2 parents f646464 + 8415149 commit 2f15abb

44 files changed

Lines changed: 1449 additions & 1923 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Cargo.lock

Lines changed: 5 additions & 484 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bin/cli/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ edition = "2024"
77
executor = { path = "../../executor" }
88
prover = { path = "../../prover", package = "lambda-vm-prover" }
99
stark = { path = "../../crypto/stark" }
10-
crypto = { path = "../../crypto/crypto" }
1110
clap = { version = "4.3.10", features = ["derive"] }
1211
bincode = "1"
1312
tikv-jemallocator = "0.6"

crypto/crypto/Cargo.toml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ edition = "2024"
1010
math = { path = "../math", features = ["alloc"] }
1111
digest = "0.10.7"
1212
sha3 = { version = "0.10.8", default-features = false }
13-
sha2 = { version = "0.10", default-features = false }
1413
# Optional
1514
serde = { version = "1.0", default-features = false, features = [
1615
"derive",
@@ -21,15 +20,15 @@ rand = { version = "0.8.5", default-features = false }
2120
rand_chacha = { version = "0.3.1", default-features = false }
2221

2322
[dev-dependencies]
24-
criterion = "0.4"
25-
iai-callgrind = "0.3.1"
23+
math = { path = "../math", features = ["test-utils"] }
2624
rand = "0.8.5"
2725
rand_chacha = "0.3.1"
26+
sha2 = { version = "0.10", default-features = false }
2827

2928
[features]
3029
default = ["asm", "std"]
3130
asm = ["sha3/asm"]
32-
std = ["math/std", "sha2/std", "sha3/std", "serde?/std"]
31+
std = ["math/std", "sha3/std", "serde?/std"]
3332
serde = ["dep:serde"]
3433
parallel = ["dep:rayon"]
3534
alloc = []

crypto/crypto/src/errors.rs

Lines changed: 0 additions & 37 deletions
This file was deleted.

crypto/crypto/src/hash/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ This folder contains hash functions that are typically used in non-interactive p
88

99
Pedersen is based on elliptic curves, while [Monolith](https://eprint.iacr.org/2023/1025), [Poseidon](https://eprint.iacr.org/2019/458.pdf) and [Rescue Prime](https://eprint.iacr.org/2020/1143) are algebraic hash functions.
1010

11-
For an introduction to hash functions, see [this intro](https://blog.alignedlayer.com/introduction-hash-functions-in-cryptography/) and [its follow-up](https://blog.alignedlayer.com/design-strategies-how-to-construct-a-hashing-mode-2/).
11+
For an introduction to hash functions, see [this intro](https://blog.alignedlayer.com/introduction-hash-functions-in-cryptography/) and [its follow-up](https://blog.alignedlayer.com/design-strategies-how-to-construct-a-hashing-mode-2/).

crypto/crypto/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
#[macro_use]
44
extern crate alloc;
55

6-
#[cfg(feature = "std")]
7-
pub mod errors;
86
pub mod fiat_shamir;
97
pub mod hash;
108
pub mod merkle_tree;

crypto/crypto/src/merkle_tree/backends/field_element.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use crate::hash::poseidon::Poseidon;
2-
32
use crate::merkle_tree::traits::IsMerkleTreeBackend;
43
use core::marker::PhantomData;
54
use digest::{Digest, Output};
Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,15 @@
1-
use sha2::{Sha256, Sha512};
2-
use sha3::{Keccak256, Keccak512, Sha3_256, Sha3_512};
1+
use sha3::Keccak256;
32

43
use super::{
54
field_element::FieldElementBackend,
65
field_element_vector::{FieldElementPairBackend, FieldElementVectorBackend},
76
};
87

98
// Field element backend definitions
10-
11-
// - With 256 bit
12-
pub type Sha3_256Backend<F> = FieldElementBackend<F, Sha3_256, 32>;
139
pub type Keccak256Backend<F> = FieldElementBackend<F, Keccak256, 32>;
14-
pub type Sha2_256Backend<F> = FieldElementBackend<F, Sha256, 32>;
15-
16-
// - With 512 bit
17-
pub type Sha3_512Backend<F> = FieldElementBackend<F, Sha3_512, 64>;
18-
pub type Keccak512Backend<F> = FieldElementBackend<F, Keccak512, 64>;
19-
pub type Sha2_512Backend<F> = FieldElementBackend<F, Sha512, 64>;
2010

2111
// Vector of field elements backend definitions
22-
23-
// - With 256 bit
24-
pub type BatchSha3_256Backend<F> = FieldElementVectorBackend<F, Sha3_256, 32>;
2512
pub type BatchKeccak256Backend<F> = FieldElementVectorBackend<F, Keccak256, 32>;
26-
pub type BatchSha2_256Backend<F> = FieldElementVectorBackend<F, Sha256, 32>;
27-
28-
// - With 512 bit
29-
pub type BatchSha3_512Backend<F> = FieldElementVectorBackend<F, Sha3_512, 64>;
30-
pub type BatchKeccak512Backend<F> = FieldElementVectorBackend<F, Keccak512, 64>;
31-
pub type BatchSha2_512Backend<F> = FieldElementVectorBackend<F, Sha512, 64>;
3213

3314
// Fixed-size pair backends (more efficient for FRI layers)
34-
35-
// - With 256 bit
3615
pub type PairKeccak256Backend<F> = FieldElementPairBackend<F, Keccak256, 32>;
37-
pub type PairSha3_256Backend<F> = FieldElementPairBackend<F, Sha3_256, 32>;
38-
pub type PairSha2_256Backend<F> = FieldElementPairBackend<F, Sha256, 32>;

crypto/math/Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,7 @@ num-traits = { version = "0.2.19", default-features = false }
2525
[dev-dependencies]
2626
rand_chacha = "0.3.1"
2727
criterion = "0.5.1"
28-
const-random = "0.1.15"
29-
iai-callgrind = "0.3.1"
3028
proptest = "1.1.0"
31-
pprof = { version = "0.13.0", features = ["criterion", "flamegraph"] }
3229
rand = { version = "0.8.5", features = ["std"] }
3330

3431
[features]
@@ -40,6 +37,7 @@ lambdaworks-serde-binary = ["dep:serde", "alloc"]
4037
lambdaworks-serde-string = ["dep:serde", "dep:serde_json", "alloc"]
4138
proptest = ["dep:proptest"]
4239
instruments = []
40+
test-utils = []
4341

4442
[target.wasm32-unknown-unknown.dependencies]
4543
getrandom = { version = "0.2.15", features = ["js"] }

crypto/math/src/fft/cpu/bowers_fft.rs

Lines changed: 0 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828
//!
2929
//! Based on Plonky3's implementation and academic literature on FFT optimization.
3030
31-
#[cfg(feature = "alloc")]
32-
use crate::fft::cpu::bit_reversing::in_place_bit_reverse_permute;
3331
#[cfg(feature = "alloc")]
3432
use crate::fft::errors::FFTError;
3533
#[cfg(feature = "alloc")]
@@ -53,98 +51,6 @@ const MAX_FFT_ORDER: u64 = 31;
5351
// STRUCTURE OF ARRAYS (SoA) FFT
5452
// =====================================================
5553

56-
/// Matrix representation for batch FFT with Structure of Arrays layout
57-
///
58-
/// SoA layout stores multiple polynomials contiguously:
59-
/// ```text
60-
/// [poly0[0], poly0[1], ..., poly0[n-1], poly1[0], poly1[1], ..., poly1[n-1], ...]
61-
/// ```
62-
///
63-
/// This layout provides better cache utilization when processing multiple
64-
/// polynomials simultaneously.
65-
#[cfg(feature = "alloc")]
66-
pub struct FftMatrix<E: IsField> {
67-
/// Flat storage for all polynomial coefficients
68-
pub data: Vec<FieldElement<E>>,
69-
/// Number of columns (polynomial length)
70-
pub width: usize,
71-
/// Number of rows (number of polynomials)
72-
pub height: usize,
73-
}
74-
75-
#[cfg(feature = "alloc")]
76-
impl<E: IsField> FftMatrix<E> {
77-
/// Create a new FFT matrix from a list of polynomials
78-
///
79-
/// # Panics
80-
/// Panics if polynomials have different lengths.
81-
pub fn from_polynomials(polys: Vec<Vec<FieldElement<E>>>) -> Self {
82-
if polys.is_empty() {
83-
return Self {
84-
data: Vec::new(),
85-
width: 0,
86-
height: 0,
87-
};
88-
}
89-
90-
let height = polys.len();
91-
let width = polys[0].len();
92-
93-
// Flatten in row-major order (SoA layout)
94-
let mut data = Vec::with_capacity(height * width);
95-
for poly in polys {
96-
assert_eq!(poly.len(), width, "All polynomials must have same length");
97-
data.extend(poly);
98-
}
99-
100-
Self {
101-
data,
102-
width,
103-
height,
104-
}
105-
}
106-
107-
/// Get a mutable slice for polynomial at index `row`
108-
///
109-
/// # Panics
110-
/// Panics if `row >= self.height`.
111-
pub fn row_mut(&mut self, row: usize) -> &mut [FieldElement<E>] {
112-
assert!(
113-
row < self.height,
114-
"Row index out of bounds: {} >= {}",
115-
row,
116-
self.height
117-
);
118-
let start = row.checked_mul(self.width).expect("Row index overflow");
119-
let end = start + self.width;
120-
&mut self.data[start..end]
121-
}
122-
123-
/// Get an immutable slice for polynomial at index `row`
124-
///
125-
/// # Panics
126-
/// Panics if `row >= self.height`.
127-
pub fn row(&self, row: usize) -> &[FieldElement<E>] {
128-
assert!(
129-
row < self.height,
130-
"Row index out of bounds: {} >= {}",
131-
row,
132-
self.height
133-
);
134-
let start = row.checked_mul(self.width).expect("Row index overflow");
135-
let end = start + self.width;
136-
&self.data[start..end]
137-
}
138-
139-
/// Convert back to list of polynomials
140-
pub fn to_polynomials(self) -> Vec<Vec<FieldElement<E>>> {
141-
self.data
142-
.chunks(self.width)
143-
.map(|chunk| chunk.to_vec())
144-
.collect()
145-
}
146-
}
147-
14854
// =====================================================
14955
// PARALLEL BOWERS FFT
15056
// =====================================================
@@ -1185,29 +1091,3 @@ where
11851091

11861092
Ok(())
11871093
}
1188-
1189-
/// Batch FFT using optimized Bowers algorithm with LayerTwiddles
1190-
///
1191-
/// # Errors
1192-
/// Returns `FFTError::InputError` if polynomial width is not a power of two.
1193-
#[cfg(feature = "alloc")]
1194-
pub fn bowers_batch_fft_opt<F, E>(
1195-
matrix: &mut FftMatrix<E>,
1196-
layer_twiddles: &LayerTwiddles<F>,
1197-
) -> Result<(), FFTError>
1198-
where
1199-
F: IsFFTField + IsSubFieldOf<E>,
1200-
E: IsField,
1201-
{
1202-
if matrix.height == 0 || matrix.width <= 1 {
1203-
return Ok(());
1204-
}
1205-
1206-
for row in 0..matrix.height {
1207-
let poly = matrix.row_mut(row);
1208-
bowers_fft_opt_fused(poly, layer_twiddles)?;
1209-
in_place_bit_reverse_permute(poly);
1210-
}
1211-
1212-
Ok(())
1213-
}

0 commit comments

Comments
 (0)