diff --git a/stwo_cairo_prover/src/components/memory/component.rs b/stwo_cairo_prover/src/components/memory/component.rs index a1dd83ab..43e1385a 100644 --- a/stwo_cairo_prover/src/components/memory/component.rs +++ b/stwo_cairo_prover/src/components/memory/component.rs @@ -30,14 +30,14 @@ pub const MEMORY_LOOKUP_VALUE_1: &str = "MEMORY_LOOKUP_1"; pub const MEMORY_LOOKUP_VALUE_2: &str = "MEMORY_LOOKUP_2"; pub const MEMORY_LOOKUP_VALUE_3: &str = "MEMORY_LOOKUP_3"; -pub const N_M31_IN_FELT252: usize = 21; -pub const MULTIPLICITY_COLUMN: usize = 22; +pub const N_M31_IN_FELT252: usize = 28; +pub const MULTIPLICITY_COLUMN_OFFSET: usize = N_M31_IN_FELT252 + 1; // TODO(AlonH): Make memory size configurable. pub const LOG_MEMORY_ADDRESS_BOUND: u32 = 3; pub const MEMORY_ADDRESS_BOUND: usize = 1 << LOG_MEMORY_ADDRESS_BOUND; /// Addresses are continuous and start from 0. -/// Values are Felt252 stored as `N_M31_IN_FELT252` M31 values (each value contain 12 bits). +/// Values are Felt252 stored as `N_M31_IN_FELT252` M31 values (each value containing 9 bits). pub struct MemoryTraceGenerator { // TODO(AlonH): Consider to change values to be Felt252. pub values: Vec<[BaseField; N_M31_IN_FELT252]>, @@ -104,7 +104,7 @@ impl ComponentTraceGenerator for MemoryTraceGenerator { for (j, value) in values.iter().enumerate() { trace[j + 1][i] = BaseField::from_u32_unchecked(value.0); } - trace[MULTIPLICITY_COLUMN][i] = BaseField::from_u32_unchecked(*multiplicity); + trace[MULTIPLICITY_COLUMN_OFFSET][i] = BaseField::from_u32_unchecked(*multiplicity); } let domain = CanonicCoset::new(LOG_MEMORY_ADDRESS_BOUND).circle_domain(); @@ -142,7 +142,7 @@ impl ComponentTraceGenerator for MemoryTraceGenerator { log_size, ); let interaction_value = - last + (denom_inverses[index] * trace[MULTIPLICITY_COLUMN].values[index]); + last + (denom_inverses[index] * trace[MULTIPLICITY_COLUMN_OFFSET].values[index]); logup_values[index] = interaction_value; last = interaction_value; } @@ -207,7 +207,7 @@ impl Component for MemoryComponent { let address_and_value: [SecureField; N_M31_IN_FELT252 + 1] = std::array::from_fn(|i| mask[BASE_TRACE][i][0]); let numerator = value * shifted_secure_combination(&address_and_value, alpha, z) - - mask[BASE_TRACE][MULTIPLICITY_COLUMN][0]; + - mask[BASE_TRACE][MULTIPLICITY_COLUMN_OFFSET][0]; let denom = point_vanishing(constraint_zero_domain.at(0), point); evaluation_accumulator.accumulate(numerator / denom); @@ -227,7 +227,7 @@ impl Component for MemoryComponent { SecureField::from_partial_evals(std::array::from_fn(|i| mask[INTERACTION_TRACE][i][1])); let numerator = (value - prev_value) * shifted_secure_combination(&address_and_value, alpha, z) - - mask[BASE_TRACE][22][0]; + - mask[BASE_TRACE][MULTIPLICITY_COLUMN_OFFSET][0]; let denom = coset_vanishing(constraint_zero_domain, point) / point_excluder(constraint_zero_domain.at(0), point); evaluation_accumulator.accumulate(numerator / denom); diff --git a/stwo_cairo_prover/src/components/memory/component_prover.rs b/stwo_cairo_prover/src/components/memory/component_prover.rs index 814bf6fd..26e93b67 100644 --- a/stwo_cairo_prover/src/components/memory/component_prover.rs +++ b/stwo_cairo_prover/src/components/memory/component_prover.rs @@ -19,7 +19,8 @@ use stwo_prover::trace_generation::{BASE_TRACE, INTERACTION_TRACE}; use super::component::{ MemoryComponent, MEMORY_ALPHA, MEMORY_LOOKUP_VALUE_0, MEMORY_LOOKUP_VALUE_1, - MEMORY_LOOKUP_VALUE_2, MEMORY_LOOKUP_VALUE_3, MEMORY_Z, MULTIPLICITY_COLUMN, N_M31_IN_FELT252, + MEMORY_LOOKUP_VALUE_2, MEMORY_LOOKUP_VALUE_3, MEMORY_Z, MULTIPLICITY_COLUMN_OFFSET, + N_M31_IN_FELT252, }; impl ComponentProver for MemoryComponent { @@ -84,12 +85,12 @@ impl ComponentProver for MemoryComponent { let first_point_numerator = accum.random_coeff_powers[2] * (value * shifted_secure_combination(&address_and_value, alpha, z) - - trace_evals[BASE_TRACE][MULTIPLICITY_COLUMN][i]); + - trace_evals[BASE_TRACE][MULTIPLICITY_COLUMN_OFFSET][i]); let last_point_numerator = accum.random_coeff_powers[1] * (value - lookup_value); let step_numerator = accum.random_coeff_powers[0] * ((value - prev_value) * shifted_secure_combination(&address_and_value, alpha, z) - - trace_evals[BASE_TRACE][MULTIPLICITY_COLUMN][i]); + - trace_evals[BASE_TRACE][MULTIPLICITY_COLUMN_OFFSET][i]); accum.accumulate( i, first_point_numerator * first_point_denom_inverse