Skip to content

Commit

Permalink
Move preproccess trace to idx 0.
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyalesokhin-starkware committed Nov 7, 2024
1 parent 4aa5a22 commit dbe394d
Show file tree
Hide file tree
Showing 11 changed files with 122 additions and 86 deletions.
6 changes: 3 additions & 3 deletions crates/prover/src/constraint_framework/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ use crate::core::fields::qm31::SecureField;
use crate::core::fields::secure_column::SECURE_EXTENSION_DEGREE;
use crate::core::fields::FieldExpOps;

pub const ORIGINAL_TRACE_IDX: usize = 0;
pub const INTERACTION_TRACE_IDX: usize = 1;
pub const PREPROCESSED_TRACE_IDX: usize = 2;
pub const PREPROCESSED_TRACE_IDX: usize = 0;
pub const ORIGINAL_TRACE_IDX: usize = 1;
pub const INTERACTION_TRACE_IDX: usize = 2;

/// A trait for evaluating expressions at some point or row.
pub trait EvalAtRow {
Expand Down
1 change: 1 addition & 0 deletions crates/prover/src/core/prover/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ pub fn prove<B: BackendForChannel<MC>, MC: MerkleChannel>(

// Get mask sample points relative to oods point.
let mut sample_points = component_provers.components().mask_points(oods_point);

// Add the composition polynomial mask points.
sample_points.push(vec![vec![oods_point]; SECURE_EXTENSION_DEGREE]);

Expand Down
52 changes: 26 additions & 26 deletions crates/prover/src/examples/blake/air.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,28 @@ where
let channel = &mut MC::C::default();
let commitment_scheme = &mut CommitmentSchemeProver::new(config, &twiddles);

// Constant trace.
// TODO(ShaharS): share is_first column between components when constant columns support this.
let span = span!(Level::INFO, "Constant Trace").entered();
let mut tree_builder = commitment_scheme.tree_builder();
tree_builder.extend_evals(
chain![
vec![gen_is_first(log_size)],
ROUND_LOG_SPLIT
.iter()
.map(|l| gen_is_first(log_size + l))
.collect_vec(),
xor_table::generate_constant_trace::<12, 4>(),
xor_table::generate_constant_trace::<9, 2>(),
xor_table::generate_constant_trace::<8, 2>(),
xor_table::generate_constant_trace::<7, 2>(),
xor_table::generate_constant_trace::<4, 0>(),
]
.collect_vec(),
);
tree_builder.commit(channel);
span.exit();

let span = span!(Level::INFO, "Trace").entered();

// Scheduler.
Expand Down Expand Up @@ -362,28 +384,6 @@ where
tree_builder.commit(channel);
span.exit();

// Constant trace.
// TODO(ShaharS): share is_first column between components when constant columns support this.
let span = span!(Level::INFO, "Constant Trace").entered();
let mut tree_builder = commitment_scheme.tree_builder();
tree_builder.extend_evals(
chain![
vec![gen_is_first(log_size)],
ROUND_LOG_SPLIT
.iter()
.map(|l| gen_is_first(log_size + l))
.collect_vec(),
xor_table::generate_constant_trace::<12, 4>(),
xor_table::generate_constant_trace::<9, 2>(),
xor_table::generate_constant_trace::<8, 2>(),
xor_table::generate_constant_trace::<7, 2>(),
xor_table::generate_constant_trace::<4, 0>(),
]
.collect_vec(),
);
tree_builder.commit(channel);
span.exit();

assert_eq!(
commitment_scheme
.polynomials()
Expand Down Expand Up @@ -418,18 +418,18 @@ pub fn verify_blake<MC: MerkleChannel>(

let log_sizes = stmt0.log_sizes();

// Constant trace.
commitment_scheme.commit(stark_proof.commitments[0], &log_sizes[0], channel);

// Trace.
stmt0.mix_into(channel);
commitment_scheme.commit(stark_proof.commitments[0], &log_sizes[0], channel);
commitment_scheme.commit(stark_proof.commitments[1], &log_sizes[1], channel);

// Draw interaction elements.
let all_elements = AllElements::draw(channel);

// Interaction trace.
stmt1.mix_into(channel);
commitment_scheme.commit(stark_proof.commitments[1], &log_sizes[1], channel);

// Constant trace.
commitment_scheme.commit(stark_proof.commitments[2], &log_sizes[2], channel);

let components = BlakeComponents::new(&stmt0, &all_elements, &stmt1);
Expand Down
2 changes: 1 addition & 1 deletion crates/prover/src/examples/blake/round/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ mod tests {
&round_lookup_elements,
);

let trace = TreeVec::new(vec![trace, interaction_trace, vec![gen_is_first(LOG_SIZE)]]);
let trace = TreeVec::new(vec![vec![gen_is_first(LOG_SIZE)], trace, interaction_trace]);
let trace_polys = trace.map_cols(|c| c.interpolate());

let component = BlakeRoundEval {
Expand Down
2 changes: 1 addition & 1 deletion crates/prover/src/examples/blake/scheduler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ mod tests {
&blake_lookup_elements,
);

let trace = TreeVec::new(vec![trace, interaction_trace, vec![gen_is_first(LOG_SIZE)]]);
let trace = TreeVec::new(vec![vec![gen_is_first(LOG_SIZE)], trace, interaction_trace]);
let trace_polys = trace.map_cols(|c| c.interpolate());

let component = BlakeSchedulerEval {
Expand Down
2 changes: 1 addition & 1 deletion crates/prover/src/examples/blake/xor_table/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ mod tests {
generate_interaction_trace(lookup_data, &lookup_elements);
let constant_trace = generate_constant_trace::<ELEM_BITS, EXPAND_BITS>();

let trace = TreeVec::new(vec![trace, interaction_trace, constant_trace]);
let trace = TreeVec::new(vec![constant_trace, trace, interaction_trace]);
let trace_polys = trace.map_cols(|c| c.interpolate());

let component = XorTableEval::<ELEM_BITS, EXPAND_BITS> {
Expand Down
49 changes: 28 additions & 21 deletions crates/prover/src/examples/plonk/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,29 @@ pub fn prove_fibonacci_plonk(
let commitment_scheme =
&mut CommitmentSchemeProver::<_, Blake2sMerkleChannel>::new(config, &twiddles);

// Constant trace.
let span = span!(Level::INFO, "Constant").entered();
let mut tree_builder = commitment_scheme.tree_builder();
let is_first = gen_is_first(log_n_rows);
let mut constant_trace = [
circuit.a_wire.clone(),
circuit.b_wire.clone(),
circuit.c_wire.clone(),
circuit.op.clone(),
]
.into_iter()
.map(|col| {
CircleEvaluation::<SimdBackend, _, BitReversedOrder>::new(
CanonicCoset::new(log_n_rows).circle_domain(),
col,
)
})
.collect_vec();
constant_trace.insert(0, is_first);
let constants_trace_location = tree_builder.extend_evals(constant_trace);
tree_builder.commit(channel);
span.exit();

// Trace.
let span = span!(Level::INFO, "Trace").entered();
let trace = gen_trace(log_n_rows, &circuit);
Expand All @@ -218,24 +241,6 @@ pub fn prove_fibonacci_plonk(
tree_builder.commit(channel);
span.exit();

// Constant trace.
let span = span!(Level::INFO, "Constant").entered();
let mut tree_builder = commitment_scheme.tree_builder();
let is_first = gen_is_first(log_n_rows);
let mut constant_trace = [circuit.a_wire, circuit.b_wire, circuit.c_wire, circuit.op]
.into_iter()
.map(|col| {
CircleEvaluation::<SimdBackend, _, BitReversedOrder>::new(
CanonicCoset::new(log_n_rows).circle_domain(),
col,
)
})
.collect_vec();
constant_trace.insert(0, is_first);
let constants_trace_location = tree_builder.extend_evals(constant_trace);
tree_builder.commit(channel);
span.exit();

// Prove constraints.
let component = PlonkComponent::new(
&mut TraceLocationAllocator::default(),
Expand Down Expand Up @@ -300,14 +305,16 @@ mod tests {
// Decommit.
// Retrieve the expected column sizes in each commitment interaction, from the AIR.
let sizes = component.trace_log_degree_bounds();
// Trace columns.

// Constant columns.
commitment_scheme.commit(proof.commitments[0], &sizes[0], channel);

// Trace columns.
commitment_scheme.commit(proof.commitments[1], &sizes[1], channel);
// Draw lookup element.
let lookup_elements = LookupElements::<2>::draw(channel);
assert_eq!(lookup_elements, component.lookup_elements);
// Interaction columns.
commitment_scheme.commit(proof.commitments[1], &sizes[1], channel);
// Constant columns.
commitment_scheme.commit(proof.commitments[2], &sizes[2], channel);

verify(&[&component], channel, commitment_scheme, proof).unwrap();
Expand Down
26 changes: 13 additions & 13 deletions crates/prover/src/examples/poseidon/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,14 @@ pub fn prove_poseidon(
let commitment_scheme =
&mut CommitmentSchemeProver::<_, Blake2sMerkleChannel>::new(config, &twiddles);

// Constant trace.
let span = span!(Level::INFO, "Constant").entered();
let mut tree_builder = commitment_scheme.tree_builder();
let constant_trace = vec![gen_is_first(log_n_rows)];
tree_builder.extend_evals(constant_trace);
tree_builder.commit(channel);
span.exit();

// Trace.
let span = span!(Level::INFO, "Trace").entered();
let (trace, lookup_data) = gen_trace(log_n_rows);
Expand All @@ -370,14 +378,6 @@ pub fn prove_poseidon(
tree_builder.commit(channel);
span.exit();

// Constant trace.
let span = span!(Level::INFO, "Constant").entered();
let mut tree_builder = commitment_scheme.tree_builder();
let constant_trace = vec![gen_is_first(log_n_rows)];
tree_builder.extend_evals(constant_trace);
tree_builder.commit(channel);
span.exit();

// Prove constraints.
let component = PoseidonComponent::new(
&mut TraceLocationAllocator::default(),
Expand Down Expand Up @@ -479,7 +479,7 @@ mod tests {
let (trace1, total_sum) =
gen_interaction_trace(LOG_N_ROWS, interaction_data, &lookup_elements);

let traces = TreeVec::new(vec![trace0, trace1, vec![gen_is_first(LOG_N_ROWS)]]);
let traces = TreeVec::new(vec![vec![gen_is_first(LOG_N_ROWS)], trace0, trace1]);
let trace_polys =
traces.map(|trace| trace.into_iter().map(|c| c.interpolate()).collect_vec());
assert_constraints(&trace_polys, CanonicCoset::new(LOG_N_ROWS), |mut eval| {
Expand Down Expand Up @@ -520,15 +520,15 @@ mod tests {
// Decommit.
// Retrieve the expected column sizes in each commitment interaction, from the AIR.
let sizes = component.trace_log_degree_bounds();
// Trace columns.

// Constant columns.
commitment_scheme.commit(proof.commitments[0], &sizes[0], channel);
// Trace columns.
commitment_scheme.commit(proof.commitments[1], &sizes[1], channel);
// Draw lookup element.
let lookup_elements = PoseidonElements::draw(channel);
assert_eq!(lookup_elements, component.lookup_elements);
// Interaction columns.
commitment_scheme.commit(proof.commitments[1], &sizes[1], channel);

// Constant columns.
commitment_scheme.commit(proof.commitments[2], &sizes[2], channel);

verify(&[&component], channel, commitment_scheme, proof).unwrap();
Expand Down
25 changes: 13 additions & 12 deletions crates/prover/src/examples/state_machine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ pub fn prove_state_machine(
let commitment_scheme =
&mut CommitmentSchemeProver::<_, Blake2sMerkleChannel>::new(config, &twiddles);

// Constant trace.
let mut tree_builder = commitment_scheme.tree_builder();
tree_builder.extend_evals(vec![
gen_is_first(x_axis_log_rows),
gen_is_first(y_axis_log_rows),
]);
tree_builder.commit(channel);

// Trace.
let trace_op0 = gen_trace(x_axis_log_rows, initial_state, 0);
let trace_op1 = gen_trace(y_axis_log_rows, intermediate_state, 1);
Expand Down Expand Up @@ -86,14 +94,6 @@ pub fn prove_state_machine(
tree_builder.extend_evals(chain![interaction_trace_op0, interaction_trace_op1].collect_vec());
tree_builder.commit(channel);

// Constant trace.
let mut tree_builder = commitment_scheme.tree_builder();
tree_builder.extend_evals(vec![
gen_is_first(x_axis_log_rows),
gen_is_first(y_axis_log_rows),
]);
tree_builder.commit(channel);

// Prove constraints.
let mut tree_span_provider = &mut TraceLocationAllocator::default();
let component0 = StateMachineOp0Component::new(
Expand Down Expand Up @@ -138,9 +138,12 @@ pub fn verify_state_machine(
// Decommit.
// Retrieve the expected column sizes in each commitment interaction, from the AIR.
let sizes = proof.stmt0.log_sizes();

// Constant columns.
commitment_scheme.commit(proof.stark_proof.commitments[0], &sizes[0], channel);
// Trace columns.
proof.stmt0.mix_into(channel);
commitment_scheme.commit(proof.stark_proof.commitments[0], &sizes[0], channel);
commitment_scheme.commit(proof.stark_proof.commitments[1], &sizes[1], channel);

// Assert state machine statement.
let lookup_elements = StateMachineElements::draw(channel);
Expand All @@ -155,8 +158,6 @@ pub fn verify_state_machine(

// Interaction columns.
proof.stmt1.mix_into(channel);
commitment_scheme.commit(proof.stark_proof.commitments[1], &sizes[1], channel);
// Constant columns.
commitment_scheme.commit(proof.stark_proof.commitments[2], &sizes[2], channel);

verify(
Expand Down Expand Up @@ -209,9 +210,9 @@ mod tests {
);

let trace = TreeVec::new(vec![
vec![gen_is_first(log_n_rows)],
trace,
interaction_trace,
vec![gen_is_first(log_n_rows)],
]);
let trace_polys = trace.map_cols(|c| c.interpolate());
assert_constraints(&trace_polys, CanonicCoset::new(log_n_rows), |eval| {
Expand Down
17 changes: 15 additions & 2 deletions crates/prover/src/examples/wide_fibonacci/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ mod tests {
#[test]
fn test_wide_fibonacci_constraints() {
const LOG_N_INSTANCES: u32 = 6;
let traces = TreeVec::new(vec![generate_test_trace(LOG_N_INSTANCES)]);
let traces = TreeVec::new(vec![vec![], generate_test_trace(LOG_N_INSTANCES)]);
let trace_polys =
traces.map(|trace| trace.into_iter().map(|c| c.interpolate()).collect_vec());

Expand All @@ -156,7 +156,7 @@ mod tests {
let mut trace = generate_test_trace(LOG_N_INSTANCES);
// Modify the trace such that a constraint fail.
trace[17].values.set(2, BaseField::one());
let traces = TreeVec::new(vec![trace]);
let traces = TreeVec::new(vec![vec![], trace]);
let trace_polys =
traces.map(|trace| trace.into_iter().map(|c| c.interpolate()).collect_vec());

Expand Down Expand Up @@ -185,6 +185,11 @@ mod tests {
config, &twiddles,
);

// Preprocessed trace
let mut tree_builder = commitment_scheme.tree_builder();
tree_builder.extend_evals([]);
tree_builder.commit(prover_channel);

// Trace.
let trace = generate_test_trace(log_n_instances);
let mut tree_builder = commitment_scheme.tree_builder();
Expand Down Expand Up @@ -214,6 +219,7 @@ mod tests {
// Retrieve the expected column sizes in each commitment interaction, from the AIR.
let sizes = component.trace_log_degree_bounds();
commitment_scheme.commit(proof.commitments[0], &sizes[0], verifier_channel);
commitment_scheme.commit(proof.commitments[1], &sizes[1], verifier_channel);
verify(&[&component], verifier_channel, commitment_scheme, proof).unwrap();
}
}
Expand All @@ -237,6 +243,12 @@ mod tests {
config, &twiddles,
);

// TODO(ilya): remove the following once preproccessed columns are not mandatory.
// Preprocessed trace
let mut tree_builder = commitment_scheme.tree_builder();
tree_builder.extend_evals([]);
tree_builder.commit(prover_channel);

// Trace.
let trace = generate_test_trace(LOG_N_INSTANCES);
let mut tree_builder = commitment_scheme.tree_builder();
Expand Down Expand Up @@ -265,6 +277,7 @@ mod tests {
// Retrieve the expected column sizes in each commitment interaction, from the AIR.
let sizes = component.trace_log_degree_bounds();
commitment_scheme.commit(proof.commitments[0], &sizes[0], verifier_channel);
commitment_scheme.commit(proof.commitments[1], &sizes[1], verifier_channel);
verify(&[&component], verifier_channel, commitment_scheme, proof).unwrap();
}
}
Loading

0 comments on commit dbe394d

Please sign in to comment.