diff --git a/executor/src/witgen/machines/double_sorted_witness_machine.rs b/executor/src/witgen/machines/double_sorted_witness_machine.rs index 652f39a384..574b456178 100644 --- a/executor/src/witgen/machines/double_sorted_witness_machine.rs +++ b/executor/src/witgen/machines/double_sorted_witness_machine.rs @@ -4,6 +4,7 @@ use std::iter::once; use itertools::Itertools; use super::Machine; +use crate::constant_evaluator::MIN_DEGREE_LOG; use crate::witgen::rows::RowPair; use crate::witgen::util::try_to_simple_poly; use crate::witgen::{EvalResult, FixedData, MutableState, QueryCallback}; @@ -52,10 +53,13 @@ pub struct DoubleSortedWitnesses<'a, T: FieldElement> { //witness_positions: HashMap, /// (addr, step) -> value trace: BTreeMap<(T, T), Operation>, + /// A map addr -> value, the current content of the memory. data: BTreeMap, is_initialized: BTreeMap, namespace: String, name: String, + /// The set of witness columns that are actually part of this machine. + witness_cols: HashSet, /// If the machine has the `m_diff_upper` and `m_diff_lower` columns, this is the base of the /// two digits. diff_columns_base: Option, @@ -153,6 +157,7 @@ impl<'a, T: FieldElement> DoubleSortedWitnesses<'a, T> { let diff_columns_base = Some(max.to_degree() + 1); Some(Self { name, + witness_cols: witness_cols.clone(), namespace, fixed: fixed_data, degree, @@ -170,6 +175,7 @@ impl<'a, T: FieldElement> DoubleSortedWitnesses<'a, T> { } else { Some(Self { name, + witness_cols: witness_cols.clone(), namespace, fixed: fixed_data, degree, @@ -263,6 +269,21 @@ impl<'a, T: FieldElement> Machine<'a, T> for DoubleSortedWitnesses<'a, T> { is_bootloader_write.push(0.into()); set_selector(None); } + + if self.fixed.is_variable_size(&self.witness_cols) { + let current_size = addr.len(); + let new_size = current_size.next_power_of_two() as DegreeType; + let new_size = new_size.max(1 << MIN_DEGREE_LOG); + log::info!( + "Resizing variable length machine '{}': {} -> {} (rounded up from {})", + self.name, + self.degree, + new_size, + current_size + ); + self.degree = new_size; + } + while addr.len() < self.degree as usize { addr.push(*addr.last().unwrap()); step.push(*step.last().unwrap() + T::from(1));