Skip to content

Commit c71b496

Browse files
Enforce_disable_trace_padding_used_only_in_proof_mode (#1984)
1 parent 7278ee0 commit c71b496

File tree

4 files changed

+25
-4
lines changed

4 files changed

+25
-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
* feat: adding option to simulate builtins [#1956](https://github.com/lambdaclass/cairo-vm/pull/1956)
68

79
* feat: adding `all_cairo_stwo` layout to vm [#1957](https://github.com/lambdaclass/cairo-vm/pull/1957)

vm/src/tests/cairo_run_test.rs

Lines changed: 5 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,17 @@ 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+
// The following check is to ensure that the trace is not padded. For this specific program,
1039+
// the number of steps doesn't end up as a power of 2 and we make sure it stays that way.
1040+
assert!(!runner.vm.current_step.is_power_of_two());
10401041
}
10411042

10421043
#[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
@@ -230,6 +230,11 @@ impl CairoRunner {
230230
trace_enabled: bool,
231231
disable_trace_padding: bool,
232232
) -> Result<CairoRunner, RunnerError> {
233+
// `disable_trace_padding` can only be used in `proof_mode`, so we enforce this here to
234+
// avoid unintended behavior.
235+
if disable_trace_padding && !proof_mode {
236+
return Err(RunnerError::DisableTracePaddingWithoutProofMode);
237+
}
233238
if proof_mode {
234239
Self::new_v2(
235240
program,
@@ -5423,4 +5428,15 @@ mod tests {
54235428
})]
54245429
);
54255430
}
5431+
5432+
#[test]
5433+
fn test_disable_trace_padding_without_proof_mode() {
5434+
let program = program!();
5435+
// Attempt to create a runner in non-proof mode with trace padding disabled.
5436+
let result = CairoRunner::new(&program, LayoutName::plain, None, false, true, true);
5437+
match result {
5438+
Err(RunnerError::DisableTracePaddingWithoutProofMode) => { /* test passed */ }
5439+
_ => panic!("Expected DisableTracePaddingWithoutProofMode error"),
5440+
}
5441+
}
54265442
}

0 commit comments

Comments
 (0)