Skip to content

Commit 46c82e6

Browse files
Enforce_disable_trace_padding_used_only_in_proof_mode
1 parent 3de653d commit 46c82e6

File tree

4 files changed

+23
-4
lines changed

4 files changed

+23
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
#### Upcoming Changes
44

5+
* fix: Enforce `disable_trace_padding` used only in `proof_mode` [#1984](https://github.com/lambdaclass/cairo-vm/pull/1984)
6+
57
#### [2.0.0] - 2025-02-26
68

79
* fix: Check overflow in cairo pie address calculation [#1945](https://github.com/lambdaclass/cairo-vm/pull/1945)

vm/src/tests/cairo_run_test.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ use crate::{
88
},
99
};
1010

11-
use num_traits::Zero;
12-
1311
#[test]
1412
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
1513
fn fibonacci() {
@@ -1029,14 +1027,15 @@ fn cairo_run_if_reloc_equal() {
10291027
#[test]
10301028
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
10311029
fn fibonacci_proof_mode_disable_trace_padding() {
1032-
let program_data = include_bytes!("../../../cairo_programs/fibonacci.json");
1030+
let program_data = include_bytes!("../../../cairo_programs/proof_programs/fibonacci.json");
10331031
let config = CairoRunConfig {
1032+
proof_mode: true,
10341033
disable_trace_padding: true,
10351034
..Default::default()
10361035
};
10371036
let mut hint_processor = BuiltinHintProcessor::new_empty();
10381037
let runner = cairo_run(program_data, &config, &mut hint_processor).unwrap();
1039-
assert!(runner.get_memory_holes().unwrap().is_zero());
1038+
assert!(!runner.vm.current_step.is_power_of_two());
10401039
}
10411040

10421041
#[test]

vm/src/vm/errors/runner_errors.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ pub enum RunnerError {
136136
MissingDynamicLayoutParams,
137137
#[error("dynamic layout {0} ratio should be 0 when disabled")]
138138
BadDynamicLayoutBuiltinRatio(BuiltinName),
139+
#[error("Initialization failure: Cannot run with trace padding disabled without proof mode")]
140+
DisableTracePaddingWithoutProofMode,
139141
}
140142

141143
#[cfg(test)]

vm/src/vm/runners/cairo_runner.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,11 @@ impl CairoRunner {
229229
trace_enabled: bool,
230230
disable_trace_padding: bool,
231231
) -> Result<CairoRunner, RunnerError> {
232+
// `disable_trace_padding` can only be used in `proof_mode`, so we enforce this here to
233+
// avoid unintended behavior.
234+
if disable_trace_padding && !proof_mode {
235+
return Err(RunnerError::DisableTracePaddingWithoutProofMode);
236+
}
232237
if proof_mode {
233238
Self::new_v2(
234239
program,
@@ -5399,4 +5404,15 @@ mod tests {
53995404
})]
54005405
);
54015406
}
5407+
5408+
#[test]
5409+
fn test_disable_trace_padding_without_proof_mode() {
5410+
let program = program!();
5411+
// Attempt to create a runner in non-proof mode with trace padding disabled.
5412+
let result = CairoRunner::new(&program, LayoutName::plain, None, false, true, true);
5413+
match result {
5414+
Err(RunnerError::DisableTracePaddingWithoutProofMode) => { /* test passed */ }
5415+
_ => panic!("Expected DisableTracePaddingWithoutProofMode error"),
5416+
}
5417+
}
54025418
}

0 commit comments

Comments
 (0)