Skip to content

Commit 8eec56c

Browse files
committed
merge latest changes from main
1 parent c39f0ff commit 8eec56c

81 files changed

Lines changed: 2670 additions & 2041 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: 22 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ members = [
2020
"crates/backend/sumcheck",
2121
"crates/backend/system-info",
2222
"crates/backend/zk-alloc",
23+
"crates/backend/parallel",
2324
]
2425

2526
[workspace.lints]
@@ -63,12 +64,12 @@ leansig_wrapper = { path = "crates/leansig_wrapper" }
6364
backend = { path = "crates/backend" }
6465
zk-alloc = { path = "crates/backend/zk-alloc" }
6566
system-info = { path = "crates/backend/system-info" }
67+
parallel = { path = "crates/backend/parallel" }
6668

6769
# External
6870
sha3 = "0.11.0"
6971
clap = { version = "4.5.59", features = ["derive"] }
7072
rand = "0.10.0"
71-
rayon = "1.11.0"
7273
pest = "2.7"
7374
pest_derive = "2.7"
7475
itertools = "0.14.0"
@@ -86,12 +87,12 @@ include_dir = "0.7"
8687
[features]
8788
prox-gaps-conjecture = ["rec_aggregation/prox-gaps-conjecture"]
8889
test-config = ["rec_aggregation/test-config"]
89-
standard-alloc = ["rec_aggregation/standard-alloc"]
9090

9191
[dependencies]
9292
clap.workspace = true
9393
rec_aggregation.workspace = true
9494
zk-alloc.workspace = true
95+
parallel.workspace = true
9596
rand.workspace = true
9697
sub_protocols.workspace = true
9798
utils.workspace = true
@@ -107,3 +108,4 @@ serde.workspace = true
107108

108109
[profile.release]
109110
lto = "thin"
111+
codegen-units = 1

crates/backend/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ poly = { path = "poly", package = "mt-poly" }
99
sumcheck = { path = "sumcheck", package = "mt-sumcheck" }
1010
field = { path = "field", package = "mt-field" }
1111
air = { path = "air", package = "mt-air" }
12-
rayon.workspace = true
12+
parallel.workspace = true
1313
whir = { path = "../whir", package = "mt-whir" }
1414
tracing.workspace = true
1515
fiat-shamir = { path = "fiat-shamir", package = "mt-fiat-shamir" }
1616
koala-bear = { path = "koala-bear", package = "mt-koala-bear" }
1717
utils = { path = "utils", package = "mt-utils" }
18+
zk-alloc.workspace = true

crates/backend/air/src/constraint_folder/normal.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,14 @@ where
4747
self.shift
4848
}
4949

50-
#[inline]
50+
#[inline(always)]
5151
fn assert_zero(&mut self, x: IF) {
5252
let alpha_power = self.extra_data.alpha_powers()[self.constraint_index];
5353
self.accumulator += alpha_power * x;
5454
self.constraint_index += 1;
5555
}
5656

57-
#[inline]
57+
#[inline(always)]
5858
fn assert_zero_ef(&mut self, x: EF) {
5959
let alpha_power = self.extra_data.alpha_powers()[self.constraint_index];
6060
self.accumulator += alpha_power * x;

crates/backend/air/src/constraint_folder/packed.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,21 +57,21 @@ where
5757
self.shift
5858
}
5959

60-
#[inline]
60+
#[inline(always)]
6161
fn assert_zero(&mut self, x: IF) {
6262
let alpha_power = self.extra_data.alpha_powers()[self.constraint_index];
6363
self.accumulator += EFPacking::<EF>::from(alpha_power) * x;
6464
self.constraint_index += 1;
6565
}
6666

67-
#[inline]
67+
#[inline(always)]
6868
fn assert_zero_ef(&mut self, x: EFPacking<EF>) {
6969
let alpha_power = self.extra_data.alpha_powers()[self.constraint_index];
7070
self.accumulator += EFPacking::<EF>::from(alpha_power) * x;
7171
self.constraint_index += 1;
7272
}
7373

74-
#[inline]
74+
#[inline(always)]
7575
fn assert_eq_low(&mut self, x: IF, y: IF) {
7676
let alpha_power = self.extra_data.alpha_powers()[self.constraint_index];
7777
let contrib = EFPacking::<EF>::from(alpha_power) * (x - y);
@@ -80,7 +80,7 @@ where
8080
self.constraint_index += 1;
8181
}
8282

83-
#[inline]
83+
#[inline(always)]
8484
fn low_degree_block<F>(&mut self, state: &mut [IF], block: F)
8585
where
8686
F: FnOnce(&mut Self, &mut [IF]),

crates/backend/air/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,24 @@ pub trait AirBuilder: Sized {
5656
fn assert_zero(&mut self, x: Self::IF);
5757
fn assert_zero_ef(&mut self, x: Self::EF);
5858

59+
#[inline(always)]
5960
fn assert_eq(&mut self, x: Self::IF, y: Self::IF) {
6061
self.assert_zero(x - y);
6162
}
6263

64+
#[inline(always)]
6365
fn assert_bool(&mut self, x: Self::IF) {
6466
self.assert_zero(x.bool_check());
6567
}
6668

69+
#[inline(always)]
6770
fn assert_eq_low(&mut self, x: Self::IF, y: Self::IF) {
6871
self.assert_eq(x, y);
6972
}
7073

7174
/// Execute `block` as a low-degree sub-region whose post-state is "cacheable"
7275
/// = linear in z without the low-degree constraints
76+
#[inline(always)]
7377
fn low_degree_block<F>(&mut self, state: &mut [Self::IF], block: F)
7478
where
7579
F: FnOnce(&mut Self, &mut [Self::IF]),

crates/backend/air/src/symbolic.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,15 @@ fn alloc_node<F: Field>(node: SymbolicNode<F>) -> u32 {
9292
})
9393
}
9494

95-
pub fn get_node<F: Field>(idx: u32) -> SymbolicNode<F> {
95+
/// # Safety
96+
/// `idx` must be an offset returned by `alloc_node::<F>` for the current (same `F`, uncleared) arena.
97+
pub unsafe fn get_node<F: Field>(idx: u32) -> SymbolicNode<F> {
9698
ARENA.with(|arena| {
9799
let bytes = arena.borrow();
100+
assert!(
101+
idx as usize + std::mem::size_of::<SymbolicNode<F>>() <= bytes.len(),
102+
"arena index out of bounds"
103+
);
98104
unsafe { std::ptr::read_unaligned(bytes.as_ptr().add(idx as usize) as *const SymbolicNode<F>) }
99105
})
100106
}

crates/backend/fiat-shamir/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ symetric = { path = "../symetric", package = "mt-symetric" }
1010
utils = { path = "../utils", package = "mt-utils" }
1111
tracing.workspace = true
1212
serde.workspace = true
13-
rayon.workspace = true
13+
parallel.workspace = true

crates/backend/fiat-shamir/src/prover.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ use field::PrimeCharacteristicRing;
99
use field::integers::QuotientMap;
1010
use field::{ExtensionField, PrimeField64};
1111
use koala_bear::symmetric::Permutation;
12-
use rayon::prelude::*;
13-
use std::sync::atomic::{AtomicU64, Ordering};
12+
use std::sync::atomic::{AtomicBool, AtomicU64, Ordering};
1413
use std::time::Duration;
1514
use std::{fmt::Debug, sync::Mutex, time::Instant};
1615

@@ -132,9 +131,16 @@ where
132131
let witness_found = Mutex::<Option<PF<EF>>>::new(None);
133132
// each batch tests lanes witnesses simultaneously
134133
let num_batches = PF::<EF>::ORDER_U64.div_ceil(lanes as u64);
135-
(0..num_batches)
136-
.into_par_iter()
137-
.find_any(|&batch| {
134+
// Work-stealing parallel search: each worker pulls batches from a shared counter and
135+
// stops once any worker has found a witness (`found`).
136+
let next_batch = AtomicU64::new(0);
137+
let found = AtomicBool::new(false);
138+
parallel::for_each_index(parallel::num_threads(), |_| {
139+
while !found.load(Ordering::Relaxed) {
140+
let batch = next_batch.fetch_add(1, Ordering::Relaxed);
141+
if batch >= num_batches {
142+
break;
143+
}
138144
let base = batch * lanes as u64;
139145

140146
let packed_witnesses = Packed::<EF>::from_fn(|lane| {
@@ -159,14 +165,14 @@ where
159165
let rand_usize = sample.as_canonical_u64() as usize;
160166
if (rand_usize & ((1 << bits) - 1)) == 0 {
161167
*witness_found.lock().unwrap() = Some(*witness);
162-
return true;
168+
found.store(true, Ordering::Relaxed);
169+
break;
163170
}
164171
}
165-
false
166-
})
167-
.expect("failed to find witness");
172+
}
173+
});
168174

169-
let witness = witness_found.lock().unwrap().unwrap();
175+
let witness = witness_found.lock().unwrap().expect("failed to find witness");
170176

171177
self.challenger.observe_many(&[witness]);
172178
assert!(self.challenger.state[CAPACITY].as_canonical_u64() & ((1 << bits) - 1) == 0);

crates/backend/field/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ itertools.workspace = true
1010
num-bigint = "*"
1111
paste = "*"
1212
rand.workspace = true
13-
rayon.workspace = true
13+
parallel.workspace = true
1414
serde.workspace = true
1515
tracing.workspace = true

0 commit comments

Comments
 (0)