Skip to content

Commit 3fae126

Browse files
author
Gilad Chase
committed
refactor: use stwo_air_utils for par air generation
- follows current design in stwo-cairo for this opcode. - inline write_trace_row - add LookupData that wraps InteractionClaimGenerator fields, which also holds n_calls. - fix edge cases if input is smaller than LOG_N_LANES
1 parent f0a68be commit 3fae126

File tree

9 files changed

+213
-142
lines changed

9 files changed

+213
-142
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,18 @@ num-traits = "0.2.17"
2222
paste = "1.0"
2323
pretty_assertions = "1.4.1"
2424
rand = "0.8.5"
25+
rayon = { version = "1.10.0" }
2526
ruint = "1.12.3"
2627
serde = "1.0.207"
2728
serde_json = "1.0.1"
2829
sonic-rs = "0.3.10"
2930
starknet-ff = "0.3.7"
31+
stwo-air-utils = { git = "https://github.com/starkware-libs/stwo", rev = "bede666c" }
32+
stwo-air-utils-derive = { git = "https://github.com/starkware-libs/stwo", rev = "bede666c" }
3033
# TODO(ShaharS): take stwo version from the source repository.
31-
stwo-prover = { git = "https://github.com/starkware-libs/stwo", rev = "bede666c" }
34+
stwo-prover = { git = "https://github.com/starkware-libs/stwo", rev = "bede666c", features = [
35+
"parallel",
36+
] }
3237
thiserror = "1.0.63"
3338
tracing = "0.1.40"
3439
tracing-subscriber = "0.3.18"

crates/prover/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@ cairo-vm.workspace = true
1010
hex.workspace = true
1111
itertools.workspace = true
1212
num-traits.workspace = true
13+
rayon.workspace = true
1314
serde.workspace = true
1415
sonic-rs.workspace = true
16+
stwo-air-utils.workspace = true
17+
stwo-air-utils-derive.workspace = true
1518
stwo-prover.workspace = true
1619
thiserror.workspace = true
1720
tracing.workspace = true

crates/prover/src/components/add_mul_opcode/component.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ impl Eval {
3939

4040
impl FrameworkEval for Eval {
4141
fn log_size(&self) -> u32 {
42-
std::cmp::max(self.claim.n_calls.next_power_of_two().ilog2(), LOG_N_LANES)
42+
std::cmp::max(self.claim.n_rows.next_power_of_two().ilog2(), LOG_N_LANES)
4343
}
4444

4545
fn max_constraint_log_degree_bound(&self) -> u32 {
@@ -153,15 +153,15 @@ impl FrameworkEval for Eval {
153153

154154
#[derive(Clone, Serialize, Deserialize)]
155155
pub struct Claim {
156-
pub n_calls: usize,
156+
pub n_rows: usize,
157157
}
158158
impl Claim {
159159
pub fn mix_into(&self, channel: &mut impl Channel) {
160-
channel.mix_u64(self.n_calls as u64);
160+
channel.mix_u64(self.n_rows as u64);
161161
}
162162

163163
pub fn log_sizes(&self) -> TreeVec<Vec<u32>> {
164-
let log_size = self.n_calls.next_power_of_two().ilog2();
164+
let log_size = self.n_rows.next_power_of_two().ilog2();
165165
let preprocessed_log_sizes = vec![log_size];
166166
let interaction_1_log_sizes = vec![log_size; N_TRACE_COLUMNS];
167167
let interaction_2_log_sizes = vec![log_size; SECURE_EXTENSION_DEGREE * 3];

crates/prover/src/components/add_mul_opcode/prover.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,21 +71,21 @@ impl ClaimGenerator {
7171
});
7272
tree_builder.extend_evals(trace);
7373
let claim = Claim {
74-
n_calls: self.inputs.len() * N_LANES,
74+
n_rows: self.inputs.len() * N_LANES,
7575
};
7676
(claim, interaction_claim_generator)
7777
}
7878
}
7979

8080
pub struct InteractionClaimGenerator {
81-
pub n_calls: usize,
81+
pub n_rows: usize,
8282
pub memory: [Vec<[PackedM31; N_MEMORY_ELEMS]>; N_MEMORY_LOOKUPS],
8383
pub state: [Vec<[PackedM31; STATE_SIZE]>; N_STATE_LOOKUPS],
8484
}
8585
impl InteractionClaimGenerator {
8686
pub fn with_capacity(capacity: usize) -> Self {
8787
Self {
88-
n_calls: capacity,
88+
n_rows: capacity,
8989
memory: [
9090
Vec::with_capacity(capacity),
9191
Vec::with_capacity(capacity),
@@ -138,13 +138,13 @@ impl InteractionClaimGenerator {
138138
}
139139
col2.finalize_col();
140140

141-
let (trace, total_sum, claimed_sum) = if self.n_calls == 1 << log_size {
141+
let (trace, total_sum, claimed_sum) = if self.n_rows == 1 << log_size {
142142
let (trace, claimed_sum) = logup_gen.finalize_last();
143143
(trace, claimed_sum, None)
144144
} else {
145145
let (trace, [total_sum, claimed_sum]) =
146-
logup_gen.finalize_at([(1 << log_size) - 1, self.n_calls - 1]);
147-
(trace, total_sum, Some((claimed_sum, self.n_calls - 1)))
146+
logup_gen.finalize_at([(1 << log_size) - 1, self.n_rows - 1]);
147+
(trace, total_sum, Some((claimed_sum, self.n_rows - 1)))
148148
};
149149

150150
tree_builder.extend_evals(trace);

crates/prover/src/components/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ pub const LOOKUP_INTERACTION_PHASE: usize = 1;
77

88
#[cfg(test)]
99
mod tests {
10+
use itertools::Itertools;
1011
use pretty_assertions::assert_eq;
1112
use stwo_prover::core::backend::simd::SimdBackend;
1213
use stwo_prover::core::fields::m31::BaseField;
@@ -62,8 +63,11 @@ mod tests {
6263
ret_claim_generator.write_trace(&mut tree_builder, &mut memory_claim_generator);
6364

6465
let output = ret_interaction_prover
66+
.lookup_data
6567
.memory_outputs
66-
.map(|output| output[0].to_array()[0].to_m31_array()[0]);
68+
.into_iter()
69+
.map(|output| output.map(|x| x.to_array()[0].to_m31_array()[0]))
70+
.collect_vec()[0];
6771
assert_eq!(output, *expected_output);
6872
}
6973
}

0 commit comments

Comments
 (0)