From 2ebfff0ba67a75aea2d7a3a4f8e0af21916e76d6 Mon Sep 17 00:00:00 2001 From: AztecBot Date: Wed, 15 Jul 2026 06:37:04 +0000 Subject: [PATCH] fix: pass barretenberg debug checks --- .../components_check.cpp | 3 +++ .../components_check.test.cpp | 5 +++-- .../execution_trace/execution_trace_block.hpp | 19 ++++++++++++++++++- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/acir_components_check/components_check.cpp b/barretenberg/cpp/src/barretenberg/acir_components_check/components_check.cpp index 46496ed3d917..2ebb06a70cd0 100644 --- a/barretenberg/cpp/src/barretenberg/acir_components_check/components_check.cpp +++ b/barretenberg/cpp/src/barretenberg/acir_components_check/components_check.cpp @@ -44,6 +44,9 @@ template void ComponentsChecker_::build_circuit_comp // Collect range_list variables for (const auto& [_, range_list] : builder_.range_lists) { for (auto var_idx : range_list.variable_indices) { + if (var_idx >= builder_.real_variable_index.size()) { + continue; + } range_list_vars_.insert(builder_.real_variable_index[var_idx]); } } diff --git a/barretenberg/cpp/src/barretenberg/acir_components_check/components_check.test.cpp b/barretenberg/cpp/src/barretenberg/acir_components_check/components_check.test.cpp index 40e7d8fa16e2..015a9aa28035 100644 --- a/barretenberg/cpp/src/barretenberg/acir_components_check/components_check.test.cpp +++ b/barretenberg/cpp/src/barretenberg/acir_components_check/components_check.test.cpp @@ -559,8 +559,9 @@ TEST_F(AcirComponentsCheckTest, DetectsUnconstrainedWitnesses) auto constraints = circuit_serde_to_acir_format(circuit, IsMegaBuilder); AcirProgram program{ .constraints = constraints, .witness = {} }; auto builder = create_circuit(program); - // Corrupt the circuit - builder.real_variable_index.resize(9); + // Remove the synthesized gate while leaving the builder's witness map internally valid. + builder.blocks.arithmetic.tiles.clear(); + builder.blocks.arithmetic.num_rows_ = 0; acir_components_check::ComponentsChecker checker(circuit, builder); auto errors = checker.check(); diff --git a/barretenberg/cpp/src/barretenberg/honk/execution_trace/execution_trace_block.hpp b/barretenberg/cpp/src/barretenberg/honk/execution_trace/execution_trace_block.hpp index ac6aa3212750..e3a347ff80a6 100644 --- a/barretenberg/cpp/src/barretenberg/honk/execution_trace/execution_trace_block.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/execution_trace/execution_trace_block.hpp @@ -30,7 +30,12 @@ struct BbStackTrace : backward::StackTrace { struct StackTraces { std::vector stack_traces; void populate() { stack_traces.emplace_back(); } - void print(size_t gate_idx) const { backward::Printer{}.print(stack_traces.at(gate_idx)); } + void print(size_t gate_idx) const + { + if (gate_idx < stack_traces.size()) { + backward::Printer{}.print(stack_traces[gate_idx]); + } + } // Don't interfere with equality semantics of structs that include this in debug builds bool operator==(const StackTraces& other) const { @@ -397,6 +402,9 @@ template class ExecutionTraceBlock { , tiles(other.tiles) , num_rows_(other.num_rows_) { +#ifdef CHECK_CIRCUIT_STACKTRACES + stack_traces = other.stack_traces; +#endif copy_gate_columns_from(other); } ExecutionTraceBlock& operator=(const ExecutionTraceBlock& other) @@ -404,6 +412,9 @@ template class ExecutionTraceBlock { if (this == &other) { return *this; } +#ifdef CHECK_CIRCUIT_STACKTRACES + stack_traces = other.stack_traces; +#endif cached_size_ = other.cached_size_; data_freed_ = other.data_freed_; trace_offset_ = other.trace_offset_; @@ -419,6 +430,9 @@ template class ExecutionTraceBlock { , tiles(std::move(other.tiles)) , num_rows_(other.num_rows_) { +#ifdef CHECK_CIRCUIT_STACKTRACES + stack_traces = std::move(other.stack_traces); +#endif copy_gate_columns_from(other); } ExecutionTraceBlock& operator=(ExecutionTraceBlock&& other) noexcept @@ -426,6 +440,9 @@ template class ExecutionTraceBlock { cached_size_ = other.cached_size_; data_freed_ = other.data_freed_; trace_offset_ = other.trace_offset_; +#ifdef CHECK_CIRCUIT_STACKTRACES + stack_traces = std::move(other.stack_traces); +#endif tiles = std::move(other.tiles); num_rows_ = other.num_rows_; copy_gate_columns_from(other);