Skip to content

Commit df12864

Browse files
Fix_no_trace_padding_flow_in_proof_mode (#1909)
1 parent a0f8806 commit df12864

File tree

14 files changed

+175
-25
lines changed

14 files changed

+175
-25
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(BREAKING): Fix no trace padding flow in proof mode [#1909](https://github.com/lambdaclass/cairo-vm/pull/1909)
6+
57
* refactor: Limit ret opcode decodeing to Cairo0's standards. [#1925](https://github.com/lambdaclass/cairo-vm/pull/1925)
68

79
#### [2.0.0-rc4] - 2025-01-23

bench/criterion_benchmark.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ fn build_many_runners(c: &mut Criterion) {
3333
black_box(None),
3434
black_box(false),
3535
black_box(false),
36+
black_box(false),
3637
)
3738
.unwrap(),
3839
);
@@ -53,6 +54,7 @@ fn load_program_data(c: &mut Criterion) {
5354
None,
5455
false,
5556
false,
57+
false,
5658
)
5759
.unwrap()
5860
},

bench/iai_benchmark.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ fn build_runner() {
3737
None,
3838
false,
3939
false,
40+
false,
4041
)
4142
.unwrap();
4243
core::mem::drop(black_box(runner));
@@ -54,6 +55,7 @@ fn build_runner_helper() -> CairoRunner {
5455
None,
5556
false,
5657
false,
58+
false,
5759
)
5860
.unwrap()
5961
}

cairo1-run/src/cairo_run.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ pub fn cairo_run_program(
258258
cairo_run_config.dynamic_layout_params.clone(),
259259
runner_mode,
260260
cairo_run_config.trace_enabled,
261+
false,
261262
)?;
262263
let end = runner.initialize(cairo_run_config.proof_mode)?;
263264
load_arguments(&mut runner, &cairo_run_config, main_func, initial_gas)?;

hint_accountant/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ fn run() {
4949
whitelists.push(whitelist_file.allowed_hint_expressions);
5050
}
5151
}
52-
let mut vm = VirtualMachine::new(false);
52+
let mut vm = VirtualMachine::new(false, false);
5353
let mut hint_executor = BuiltinHintProcessor::new_empty();
5454
let (ap_tracking_data, reference_ids, references, mut exec_scopes, constants) = (
5555
ApTracking::default(),

vm/src/cairo_run.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ pub struct CairoRunConfig<'a> {
3434
pub dynamic_layout_params: Option<CairoLayoutParams>,
3535
pub proof_mode: bool,
3636
pub secure_run: Option<bool>,
37+
/// Disable padding of the trace.
38+
/// By default, the trace is padded to accommodate the expected builtins-n_steps relationships
39+
/// according to the layout.
40+
/// When the padding is disabled:
41+
/// - It doesn't modify/pad n_steps.
42+
/// - It still pads each builtin segment to the next power of 2 (w.r.t the number of used
43+
/// instances of the builtin) compared to their sizes at the end of the execution.
3744
pub disable_trace_padding: bool,
3845
pub allow_missing_builtins: Option<bool>,
3946
}
@@ -75,6 +82,7 @@ pub fn cairo_run_program_with_initial_scope(
7582
cairo_run_config.dynamic_layout_params.clone(),
7683
cairo_run_config.proof_mode,
7784
cairo_run_config.trace_enabled,
85+
cairo_run_config.disable_trace_padding,
7886
)?;
7987

8088
cairo_runner.exec_scopes = exec_scopes;
@@ -162,6 +170,7 @@ pub fn cairo_run_pie(
162170
cairo_run_config.dynamic_layout_params.clone(),
163171
false,
164172
cairo_run_config.trace_enabled,
173+
cairo_run_config.disable_trace_padding,
165174
)?;
166175

167176
let end = cairo_runner.initialize(allow_missing_builtins)?;
@@ -235,6 +244,7 @@ pub fn cairo_run_fuzzed_program(
235244
cairo_run_config.dynamic_layout_params.clone(),
236245
cairo_run_config.proof_mode,
237246
cairo_run_config.trace_enabled,
247+
cairo_run_config.disable_trace_padding,
238248
)?;
239249

240250
let _end = cairo_runner.initialize(allow_missing_builtins)?;

vm/src/hint_processor/builtin_hint_processor/secp/cairo0_hints.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ mod tests {
372372
#[test]
373373
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
374374
fn test_is_on_curve_2() {
375-
let mut vm = VirtualMachine::new(false);
375+
let mut vm = VirtualMachine::new(false, false);
376376
vm.set_fp(1);
377377
let ids_data = non_continuous_ids_data![("is_on_curve", -1)];
378378
vm.segments = segments![((1, 0), 1)];
@@ -404,7 +404,7 @@ mod tests {
404404
#[test]
405405
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
406406
fn test_compute_q_mod_prime() {
407-
let mut vm = VirtualMachine::new(false);
407+
let mut vm = VirtualMachine::new(false, false);
408408

409409
let ap_tracking = ApTracking::default();
410410

@@ -431,7 +431,7 @@ mod tests {
431431
#[test]
432432
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
433433
fn test_compute_ids_high_low() {
434-
let mut vm = VirtualMachine::new(false);
434+
let mut vm = VirtualMachine::new(false, false);
435435

436436
let value = BigInt::from(25);
437437
let shift = BigInt::from(12);
@@ -501,7 +501,7 @@ mod tests {
501501
#[test]
502502
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
503503
fn test_r1_get_point_from_x() {
504-
let mut vm = VirtualMachine::new(false);
504+
let mut vm = VirtualMachine::new(false, false);
505505
vm.set_fp(10);
506506

507507
let ids_data = non_continuous_ids_data![("x", -10), ("v", -7)];
@@ -560,7 +560,7 @@ mod tests {
560560
#[test]
561561
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
562562
fn test_reduce_value() {
563-
let mut vm = VirtualMachine::new(false);
563+
let mut vm = VirtualMachine::new(false, false);
564564

565565
//Initialize fp
566566
vm.run_context.fp = 10;
@@ -616,7 +616,7 @@ mod tests {
616616
#[test]
617617
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
618618
fn test_reduce_x() {
619-
let mut vm = VirtualMachine::new(false);
619+
let mut vm = VirtualMachine::new(false, false);
620620

621621
//Initialize fp
622622
vm.run_context.fp = 10;

vm/src/tests/cairo_run_test.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,6 +1185,7 @@ fn run_program_with_custom_mod_builtin_params(
11851185
cairo_run_config.dynamic_layout_params,
11861186
cairo_run_config.proof_mode,
11871187
cairo_run_config.trace_enabled,
1188+
cairo_run_config.disable_trace_padding,
11881189
)
11891190
.unwrap();
11901191

vm/src/tests/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ fn run_cairo_1_entrypoint(
116116
None,
117117
false,
118118
false,
119+
false,
119120
)
120121
.unwrap();
121122

@@ -221,6 +222,7 @@ fn run_cairo_1_entrypoint_with_run_resources(
221222
None,
222223
false,
223224
false,
225+
false,
224226
)
225227
.unwrap();
226228

vm/src/utils.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ pub mod test_utils {
234234

235235
macro_rules! vm_with_range_check {
236236
() => {{
237-
let mut vm = VirtualMachine::new(false);
237+
let mut vm = VirtualMachine::new(false, false);
238238
vm.builtin_runners = vec![
239239
$crate::vm::runners::builtin_runner::RangeCheckBuiltinRunner::<8>::new(
240240
Some(8),
@@ -255,12 +255,13 @@ pub mod test_utils {
255255
None,
256256
false,
257257
false,
258+
false,
258259
)
259260
.unwrap()
260261
};
261262
($program:expr, $layout:expr) => {
262263
crate::vm::runners::cairo_runner::CairoRunner::new(
263-
&$program, $layout, None, false, false,
264+
&$program, $layout, None, false, false, false,
264265
)
265266
.unwrap()
266267
};
@@ -271,6 +272,7 @@ pub mod test_utils {
271272
None,
272273
$proof_mode,
273274
false,
275+
false,
274276
)
275277
.unwrap()
276278
};
@@ -281,6 +283,7 @@ pub mod test_utils {
281283
None,
282284
$proof_mode,
283285
$trace_enabled,
286+
false,
284287
)
285288
.unwrap()
286289
};
@@ -405,11 +408,11 @@ pub mod test_utils {
405408

406409
macro_rules! vm {
407410
() => {{
408-
crate::vm::vm_core::VirtualMachine::new(false)
411+
crate::vm::vm_core::VirtualMachine::new(false, false)
409412
}};
410413

411414
($use_trace:expr) => {{
412-
crate::vm::vm_core::VirtualMachine::new($use_trace)
415+
crate::vm::vm_core::VirtualMachine::new($use_trace, false)
413416
}};
414417
}
415418
pub(crate) use vm;

0 commit comments

Comments
 (0)