diff --git a/crates/prover/src/core/prover/mod.rs b/crates/prover/src/core/prover/mod.rs index 8b27bd813..82acd5f48 100644 --- a/crates/prover/src/core/prover/mod.rs +++ b/crates/prover/src/core/prover/mod.rs @@ -35,6 +35,9 @@ pub const LOG_LAST_LAYER_DEGREE_BOUND: u32 = 0; pub const PROOF_OF_WORK_BITS: u32 = 12; pub const N_QUERIES: usize = 3; +pub const BASE_TRACE: usize = 0; +pub const INTERACTION_TRACE: usize = 1; + #[derive(Debug)] pub struct StarkProof { pub commitments: TreeVec<::Hash>, @@ -204,11 +207,19 @@ pub fn verify( // Read trace commitment. let mut commitment_scheme = CommitmentSchemeVerifier::new(); let column_log_sizes = air.column_log_sizes(); - commitment_scheme.commit(proof.commitments[0], &column_log_sizes[0], channel); + commitment_scheme.commit( + proof.commitments[BASE_TRACE], + &column_log_sizes[BASE_TRACE], + channel, + ); let interaction_elements = air.interaction_elements(channel); if air.n_interaction_phases() == 2 { - commitment_scheme.commit(proof.commitments[1], &column_log_sizes[1], channel); + commitment_scheme.commit( + proof.commitments[INTERACTION_TRACE], + &column_log_sizes[INTERACTION_TRACE], + channel, + ); } channel.mix_felts( diff --git a/crates/prover/src/examples/fibonacci/component.rs b/crates/prover/src/examples/fibonacci/component.rs index d799f8a24..cbe24012c 100644 --- a/crates/prover/src/examples/fibonacci/component.rs +++ b/crates/prover/src/examples/fibonacci/component.rs @@ -14,6 +14,7 @@ use crate::core::fields::{ExtensionOf, FieldExpOps}; use crate::core::pcs::TreeVec; use crate::core::poly::circle::{CanonicCoset, CircleEvaluation}; use crate::core::poly::BitReversedOrder; +use crate::core::prover::BASE_TRACE; use crate::core::utils::bit_reverse_index; use crate::core::{ColumnVec, InteractionElements, LookupValues}; @@ -140,7 +141,7 @@ impl ComponentProver for FibonacciComponent { _interaction_elements: &InteractionElements, _lookup_values: &LookupValues, ) { - let poly = &trace.polys[0][0]; + let poly = &trace.polys[BASE_TRACE][0]; let trace_domain = CanonicCoset::new(self.log_size); let trace_eval_domain = CanonicCoset::new(self.log_size + 1).circle_domain(); let trace_eval = poly.evaluate(trace_eval_domain).bit_reverse(); diff --git a/crates/prover/src/examples/fibonacci/mod.rs b/crates/prover/src/examples/fibonacci/mod.rs index 338e3131b..8fac01513 100644 --- a/crates/prover/src/examples/fibonacci/mod.rs +++ b/crates/prover/src/examples/fibonacci/mod.rs @@ -125,7 +125,7 @@ mod tests { use crate::core::fields::qm31::SecureField; use crate::core::pcs::TreeVec; use crate::core::poly::circle::CanonicCoset; - use crate::core::prover::VerificationError; + use crate::core::prover::{VerificationError, BASE_TRACE}; use crate::core::queries::Queries; use crate::core::utils::bit_reverse; use crate::core::{InteractionElements, LookupValues}; @@ -167,7 +167,7 @@ mod tests { let point = CirclePoint::::get_point(98989892); let points = fib.air.mask_points(point); - let mask_values = zip(&component_traces[0].polys[0], &points[0]) + let mask_values = zip(&component_traces[0].polys[BASE_TRACE], &points[0]) .map(|(poly, points)| { points .iter() @@ -238,7 +238,8 @@ mod tests { let fib = Fibonacci::new(FIB_LOG_SIZE, m31!(443693538)); let mut invalid_proof = fib.prove().unwrap(); - invalid_proof.commitment_scheme_proof.queried_values.0[0][0][3] += BaseField::one(); + invalid_proof.commitment_scheme_proof.queried_values.0[BASE_TRACE][0][3] += + BaseField::one(); let error = fib.verify(invalid_proof).unwrap_err(); assert_matches!(error, VerificationError::Merkle(_)); @@ -268,7 +269,7 @@ mod tests { let fib = Fibonacci::new(FIB_LOG_SIZE, m31!(443693538)); let mut invalid_proof = fib.prove().unwrap(); - invalid_proof.commitment_scheme_proof.queried_values.0[0][0].pop(); + invalid_proof.commitment_scheme_proof.queried_values.0[BASE_TRACE][0].pop(); let error = fib.verify(invalid_proof).unwrap_err(); assert_matches!(error, VerificationError::Merkle(_)); diff --git a/crates/prover/src/examples/wide_fibonacci/constraint_eval.rs b/crates/prover/src/examples/wide_fibonacci/constraint_eval.rs index b4d15c65e..813d18b20 100644 --- a/crates/prover/src/examples/wide_fibonacci/constraint_eval.rs +++ b/crates/prover/src/examples/wide_fibonacci/constraint_eval.rs @@ -23,6 +23,7 @@ use crate::core::fields::FieldExpOps; use crate::core::pcs::TreeVec; use crate::core::poly::circle::{CanonicCoset, CircleDomain, CircleEvaluation, SecureCirclePoly}; use crate::core::poly::BitReversedOrder; +use crate::core::prover::{BASE_TRACE, INTERACTION_TRACE}; use crate::core::utils::{ bit_reverse, previous_bit_reversed_circle_domain_index, shifted_secure_combination, }; @@ -98,13 +99,13 @@ impl WideFibComponent { #[allow(clippy::needless_range_loop)] for i in 0..trace_eval_domain.size() { first_point_numerators[i] = accum.random_coeff_powers[self.n_columns() + 4] - * (trace_evals[0][0][i] - lookup_value_0) + * (trace_evals[BASE_TRACE][0][i] - lookup_value_0) + accum.random_coeff_powers[self.n_columns() + 3] - * (trace_evals[0][1][i] - lookup_value_1); + * (trace_evals[BASE_TRACE][1][i] - lookup_value_1); last_point_numerators[i] = accum.random_coeff_powers[self.n_columns() + 2] - * (trace_evals[0][self.n_columns() - 2][i] - lookup_value_n_minus_2) + * (trace_evals[BASE_TRACE][self.n_columns() - 2][i] - lookup_value_n_minus_2) + accum.random_coeff_powers[self.n_columns() + 1] - * (trace_evals[0][self.n_columns() - 1][i] - lookup_value_n_minus_1); + * (trace_evals[BASE_TRACE][self.n_columns() - 1][i] - lookup_value_n_minus_1); } for (i, (num, denom_inverse)) in first_point_numerators .iter() @@ -143,8 +144,9 @@ impl WideFibComponent { for i in 0..trace_eval_domain.size() { for j in 0..self.n_columns() - 2 { numerators[i] += accum.random_coeff_powers[self.n_columns() - 3 - j] - * (trace_evals[0][j][i].square() + trace_evals[0][j + 1][i].square() - - trace_evals[0][j + 2][i]); + * (trace_evals[BASE_TRACE][j][i].square() + + trace_evals[BASE_TRACE][j + 1][i].square() + - trace_evals[BASE_TRACE][j + 2][i]); } } for (i, (num, denom_inverse)) in numerators.iter().zip(denom_inverses.iter()).enumerate() { @@ -191,20 +193,20 @@ impl WideFibComponent { for i in 0..trace_eval_domain.size() { let value = SecureCirclePoly::::eval_from_partial_evals(std::array::from_fn(|j| { - trace_evals[1][j][i].into() + trace_evals[INTERACTION_TRACE][j][i].into() })); first_point_numerators[i] = accum.random_coeff_powers[self.n_columns() - 1] * ((value * shifted_secure_combination( &[ - trace_evals[0][self.n_columns() - 2][i], - trace_evals[0][self.n_columns() - 1][i], + trace_evals[BASE_TRACE][self.n_columns() - 2][i], + trace_evals[BASE_TRACE][self.n_columns() - 1][i], ], alpha, z, )) - shifted_secure_combination( - &[trace_evals[0][0][i], trace_evals[0][1][i]], + &[trace_evals[BASE_TRACE][0][i], trace_evals[BASE_TRACE][1][i]], alpha, z, )); @@ -259,7 +261,7 @@ impl WideFibComponent { for i in 0..trace_eval_domain.size() { let value = SecureCirclePoly::::eval_from_partial_evals(std::array::from_fn(|j| { - trace_evals[1][j][i].into() + trace_evals[INTERACTION_TRACE][j][i].into() })); let prev_index = previous_bit_reversed_circle_domain_index( i, @@ -268,21 +270,21 @@ impl WideFibComponent { ); let prev_value = SecureCirclePoly::::eval_from_partial_evals(std::array::from_fn(|j| { - trace_evals[1][j][prev_index].into() + trace_evals[INTERACTION_TRACE][j][prev_index].into() })); numerators[i] = accum.random_coeff_powers[self.n_columns()] * ((value * shifted_secure_combination( &[ - trace_evals[0][self.n_columns() - 2][i], - trace_evals[0][self.n_columns() - 1][i], + trace_evals[BASE_TRACE][self.n_columns() - 2][i], + trace_evals[BASE_TRACE][self.n_columns() - 1][i], ], alpha, z, )) - (prev_value * shifted_secure_combination( - &[trace_evals[0][0][i], trace_evals[0][1][i]], + &[trace_evals[BASE_TRACE][0][i], trace_evals[BASE_TRACE][1][i]], alpha, z, ))); @@ -342,7 +344,7 @@ impl ComponentProver for WideFibComponent { fn lookup_values(&self, trace: &ComponentTrace<'_, CpuBackend>) -> LookupValues { let domain = CanonicCoset::new(self.log_column_size()); - let trace_poly = &trace.polys[0]; + let trace_poly = &trace.polys[BASE_TRACE]; let values = BTreeMap::from_iter([ ( LOOKUP_VALUE_0_ID.to_string(), diff --git a/crates/prover/src/examples/wide_fibonacci/simd.rs b/crates/prover/src/examples/wide_fibonacci/simd.rs index 866bbb1c4..d5a6ae55c 100644 --- a/crates/prover/src/examples/wide_fibonacci/simd.rs +++ b/crates/prover/src/examples/wide_fibonacci/simd.rs @@ -23,6 +23,7 @@ use crate::core::fields::{FieldExpOps, FieldOps}; use crate::core::pcs::TreeVec; use crate::core::poly::circle::{CanonicCoset, CircleEvaluation}; use crate::core::poly::BitReversedOrder; +use crate::core::prover::BASE_TRACE; use crate::core::{ColumnVec, InteractionElements, LookupValues}; use crate::examples::wide_fibonacci::component::{ALPHA_ID, N_COLUMNS, Z_ID}; @@ -179,7 +180,7 @@ impl ComponentProver for SimdWideFibComponent { _interaction_elements: &InteractionElements, _lookup_values: &LookupValues, ) { - assert_eq!(trace.polys[0].len(), self.n_columns()); + assert_eq!(trace.polys[BASE_TRACE].len(), self.n_columns()); // TODO(spapini): Steal evaluation from commitment. let eval_domain = CanonicCoset::new(self.log_column_size() + 1).circle_domain(); let trace_eval = &trace.evals; @@ -204,14 +205,14 @@ impl ComponentProver for SimdWideFibComponent { for vec_row in 0..(1 << (eval_domain.log_size() - LOG_N_LANES)) { // Numerator. - let a = trace_eval[0][0].data[vec_row]; + let a = trace_eval[BASE_TRACE][0].data[vec_row]; let mut row_res = PackedSecureField::zero(); let mut a_sq = a.square(); - let mut b_sq = trace_eval[0][1].data[vec_row].square(); + let mut b_sq = trace_eval[BASE_TRACE][1].data[vec_row].square(); #[allow(clippy::needless_range_loop)] for i in 0..(self.n_columns() - 2) { unsafe { - let c = *trace_eval[0] + let c = *trace_eval[BASE_TRACE] .get_unchecked(i + 2) .data .get_unchecked(vec_row);