Skip to content

Commit 997cd58

Browse files
committed
polish, add more tests
1 parent b6cebb4 commit 997cd58

File tree

4 files changed

+19
-9
lines changed

4 files changed

+19
-9
lines changed

ast/src/analyzed/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ impl<T> Analyzed<T> {
102102
self.declaration_type_count(PolynomialType::Committed)
103103
}
104104

105+
/// @returns the number of committed polynomials (with multiplicities for arrays) in a specific stage
105106
pub fn stage_commitment_count(&self, stage: Option<u32>) -> usize {
106107
self.stage_declaration_type_count(PolynomialType::Committed, stage)
107108
}

backend/src/stwo/circuit_builder.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use stwo_prover::core::poly::circle::{CircleDomain, CircleEvaluation};
1818
use stwo_prover::core::poly::BitReversedOrder;
1919
use stwo_prover::core::utils::{bit_reverse_index, coset_index_to_circle_domain_index};
2020

21+
pub const PREPROCESSED_TRACE_IDX: usize = 0;
2122
pub const STAGE0_TRACE_IDX: usize = 1;
2223
pub const STAGE1_TRACE_IDX: usize = 2;
2324

@@ -85,6 +86,10 @@ impl PowdrEval {
8586
.filter(|(symbol, _)| symbol.stage == Some(1))
8687
.flat_map(|(symbol, _)| symbol.array_elements())
8788
.enumerate()
89+
// During the circuit-building phase, stage1 witness columns are indexed after stage0 witness columns,
90+
// resulting in a concatenation of witness columns from both stages.
91+
// In the proving phase, all stage1 witness columns are appended after stage0 witness columns
92+
// to maintain consistency with the circuit-building phase.
8893
.map(|(index, (_, id))| (id, index + witness_columns_stage0.len()))
8994
.collect();
9095

@@ -217,7 +222,9 @@ impl FrameworkEval for PowdrEval {
217222
.iter()
218223
.map(|(k, v)| (*k, E::F::from(into_stwo_field(v))))
219224
.collect();
225+
// concatenate stage0 and stage1 witness columns
220226
witness_eval_stage0.extend(witness_eval_stage1);
227+
221228
let intermediate_definitions = self.analyzed.intermediate_definitions();
222229
let data = Data {
223230
witness_eval: &witness_eval_stage0,

backend/src/stwo/prover.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ use std::{fmt, io};
2020

2121
use crate::stwo::circuit_builder::{
2222
gen_stwo_circle_column, get_constant_with_next_list, PowdrComponent, PowdrEval,
23-
STAGE0_TRACE_IDX, STAGE1_TRACE_IDX,
23+
PREPROCESSED_TRACE_IDX, STAGE0_TRACE_IDX, STAGE1_TRACE_IDX,
2424
};
2525
use crate::stwo::proof::{
2626
Proof, SerializableStarkProvingKey, StarkProvingKey, TableProvingKey, TableProvingKeyCollection,
2727
};
2828

29-
use stwo_prover::constraint_framework::{TraceLocationAllocator, PREPROCESSED_TRACE_IDX};
29+
use stwo_prover::constraint_framework::TraceLocationAllocator;
3030

3131
use stwo_prover::core::air::{Component, ComponentProver};
3232
use stwo_prover::core::backend::{Backend, BackendForChannel};
@@ -459,6 +459,7 @@ where
459459
let mut stage0_witness_col_log_sizes = vec![];
460460
let mut stage1_witness_col_log_sizes = vec![];
461461

462+
// get the column sizes for stage 0 and stage 1, used by verifier to read the commitments from the proof
462463
self.split
463464
.iter()
464465
.zip_eq(proof.machine_log_sizes.iter())
@@ -477,6 +478,7 @@ where
477478
},
478479
);
479480

481+
// Verifier gets the commitments of the constant columns and stage 0 witness columns (two Merkle tree roots)
480482
commitment_scheme.commit(
481483
proof.stark_proof.commitments[PREPROCESSED_TRACE_IDX],
482484
&constant_col_log_sizes,
@@ -489,10 +491,10 @@ where
489491
verifier_channel,
490492
);
491493

492-
// TODO: make the challenge sound, now the challenge is built the same way in prover.
494+
// Get challenges based on the commitments of constant columns and stage 0 witness columns
493495
let stage0_challenges = get_challenges::<MC>(&self.analyzed, verifier_channel);
494496

495-
let mut components = self
497+
let components = self
496498
.split
497499
.iter()
498500
.zip_eq(proof.machine_log_sizes.iter())
@@ -519,13 +521,11 @@ where
519521
)
520522
.collect::<Vec<_>>();
521523

522-
let mut components_slice: Vec<&dyn Component> = components
523-
.iter_mut()
524+
let components_slice: Vec<&dyn Component> = components
525+
.iter()
524526
.map(|component| component as &dyn Component)
525527
.collect();
526528

527-
let components_slice = components_slice.as_mut_slice();
528-
529529
if self.analyzed.stage_count() > 1 {
530530
commitment_scheme.commit(
531531
proof.stark_proof.commitments[STAGE1_TRACE_IDX],
@@ -535,7 +535,7 @@ where
535535
}
536536

537537
stwo_prover::core::prover::verify(
538-
components_slice,
538+
&components_slice,
539539
verifier_channel,
540540
commitment_scheme,
541541
proof.stark_proof,

pipeline/tests/asm.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ fn second_phase_hint() {
7373
let pipeline = make_simple_prepared_pipeline::<GoldilocksField>(f, LinkerMode::Bus);
7474
test_mock_backend(pipeline.clone());
7575
test_plonky3_pipeline(pipeline);
76+
let pipeline = make_simple_prepared_pipeline::<Mersenne31Field>(f, LinkerMode::Bus);
77+
test_stwo_pipeline(pipeline);
7678
}
7779

7880
#[test]

0 commit comments

Comments
 (0)