Skip to content

Commit c6019fa

Browse files
YairVaknin-starkwaregabrielbosio
authored andcommitted
[BREAKING] Compute_missing_builtin_cells_only_in_proof_mode (#2088)
1 parent 774933d commit c6019fa

File tree

7 files changed

+52
-23
lines changed

7 files changed

+52
-23
lines changed

cairo1-run/src/cairo_run.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,12 @@ pub fn cairo_run_program(
267267
runner.run_for_steps(1, &mut hint_processor)?;
268268
}
269269

270-
runner.end_run(false, false, &mut hint_processor)?;
270+
runner.end_run(
271+
false,
272+
false,
273+
&mut hint_processor,
274+
cairo_run_config.proof_mode,
275+
)?;
271276

272277
let result_inner_type_size =
273278
result_inner_type_size(return_type_id, &sierra_program_registry, &type_sizes);

vm/src/cairo_run.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ pub fn cairo_run_program_with_initial_scope(
104104
cairo_run_config.disable_trace_padding,
105105
false,
106106
hint_processor,
107+
cairo_run_config.proof_mode,
107108
)?;
108109

109-
cairo_runner.vm.verify_auto_deductions()?;
110110
cairo_runner.read_return_values(allow_missing_builtins)?;
111111
if cairo_run_config.proof_mode {
112112
cairo_runner.finalize_segments()?;
@@ -213,9 +213,9 @@ pub fn cairo_run_pie(
213213
cairo_run_config.disable_trace_padding,
214214
false,
215215
hint_processor,
216+
cairo_run_config.proof_mode,
216217
)?;
217218

218-
cairo_runner.vm.verify_auto_deductions()?;
219219
cairo_runner.read_return_values(allow_missing_builtins)?;
220220

221221
if secure_run {
@@ -264,9 +264,8 @@ pub fn cairo_run_fuzzed_program(
264264

265265
res.map_err(|err| VmException::from_vm_error(&cairo_runner, err))?;
266266

267-
cairo_runner.end_run(false, false, hint_processor)?;
267+
cairo_runner.end_run(false, false, hint_processor, cairo_run_config.proof_mode)?;
268268

269-
cairo_runner.vm.verify_auto_deductions()?;
270269
cairo_runner.read_return_values(allow_missing_builtins)?;
271270
if cairo_run_config.proof_mode {
272271
cairo_runner.finalize_segments()?;

vm/src/tests/cairo_run_test.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,6 +1241,7 @@ fn run_program_with_custom_mod_builtin_params(
12411241
cairo_run_config.disable_trace_padding,
12421242
false,
12431243
&mut hint_processor,
1244+
cairo_run_config.proof_mode,
12441245
)
12451246
.unwrap();
12461247

vm/src/vm/runners/builtin_runner/modulo.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -821,15 +821,25 @@ mod tests {
821821

822822
let mut hint_processor = BuiltinHintProcessor::new_empty();
823823
let program = Program::from_bytes(program_data, Some("main")).unwrap();
824-
let mut runner =
825-
CairoRunner::new(&program, LayoutName::all_cairo, None, true, false, false).unwrap();
824+
let proof_mode = true;
825+
let mut runner = CairoRunner::new(
826+
&program,
827+
LayoutName::all_cairo,
828+
None,
829+
proof_mode,
830+
false,
831+
false,
832+
)
833+
.unwrap();
826834

827835
let end = runner.initialize(false).unwrap();
828836
// Modify add_mod & mul_mod params
829837

830838
runner.run_until_pc(end, &mut hint_processor).unwrap();
831839
runner.run_for_steps(1, &mut hint_processor).unwrap();
832-
runner.end_run(false, false, &mut hint_processor).unwrap();
840+
runner
841+
.end_run(false, false, &mut hint_processor, proof_mode)
842+
.unwrap();
833843
runner.read_return_values(false).unwrap();
834844
runner.finalize_segments().unwrap();
835845

vm/src/vm/runners/cairo_runner.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -891,13 +891,14 @@ impl CairoRunner {
891891
disable_trace_padding: bool,
892892
disable_finalize_all: bool,
893893
hint_processor: &mut dyn HintProcessor,
894+
proof_mode: bool,
894895
) -> Result<(), VirtualMachineError> {
895896
if self.run_ended {
896897
return Err(RunnerError::EndRunCalledTwice.into());
897898
}
898899

899900
self.vm.segments.memory.relocate_memory()?;
900-
self.vm.end_run(&self.exec_scopes)?;
901+
self.vm.end_run(&self.exec_scopes, proof_mode)?;
901902

902903
if disable_finalize_all {
903904
return Ok(());
@@ -1156,7 +1157,7 @@ impl CairoRunner {
11561157

11571158
self.run_until_pc(end, hint_processor)
11581159
.map_err(|err| VmException::from_vm_error(self, err))?;
1159-
self.end_run(true, false, hint_processor)?;
1160+
self.end_run(true, false, hint_processor, self.is_proof_mode())?;
11601161

11611162
if verify_secure {
11621163
verify_secure_runner(self, false, program_segment_size)?;
@@ -3876,7 +3877,7 @@ mod tests {
38763877

38773878
cairo_runner.run_ended = true;
38783879
assert_matches!(
3879-
cairo_runner.end_run(true, false, &mut hint_processor),
3880+
cairo_runner.end_run(true, false, &mut hint_processor, false),
38803881
Err(VirtualMachineError::RunnerError(
38813882
RunnerError::EndRunCalledTwice
38823883
))
@@ -3892,14 +3893,14 @@ mod tests {
38923893
let mut cairo_runner = cairo_runner!(program);
38933894

38943895
assert_matches!(
3895-
cairo_runner.end_run(true, false, &mut hint_processor),
3896+
cairo_runner.end_run(true, false, &mut hint_processor, false),
38963897
Ok(())
38973898
);
38983899

38993900
cairo_runner.run_ended = false;
39003901
cairo_runner.relocated_memory.clear();
39013902
assert_matches!(
3902-
cairo_runner.end_run(true, true, &mut hint_processor),
3903+
cairo_runner.end_run(true, true, &mut hint_processor, false),
39033904
Ok(())
39043905
);
39053906
assert!(!cairo_runner.run_ended);
@@ -3913,16 +3914,16 @@ mod tests {
39133914
Some("main"),
39143915
)
39153916
.unwrap();
3916-
3917+
let proof_mode = true;
39173918
let mut hint_processor = BuiltinHintProcessor::new_empty();
3918-
let mut cairo_runner = cairo_runner!(program, LayoutName::all_cairo, true, true);
3919+
let mut cairo_runner = cairo_runner!(program, LayoutName::all_cairo, proof_mode, true);
39193920

39203921
let end = cairo_runner.initialize(false).unwrap();
39213922
cairo_runner
39223923
.run_until_pc(end, &mut hint_processor)
39233924
.expect("Call to `CairoRunner::run_until_pc()` failed.");
39243925
assert_matches!(
3925-
cairo_runner.end_run(false, false, &mut hint_processor),
3926+
cairo_runner.end_run(false, false, &mut hint_processor, proof_mode),
39263927
Ok(())
39273928
);
39283929
}
@@ -5669,7 +5670,8 @@ mod tests {
56695670
.unwrap();
56705671

56715672
let mut hint_processor = BuiltinHintProcessor::new_empty();
5672-
let mut cairo_runner = cairo_runner!(program, LayoutName::all_cairo, true, true);
5673+
let proof_mode = true;
5674+
let mut cairo_runner = cairo_runner!(program, LayoutName::all_cairo, proof_mode, true);
56735675

56745676
let end = cairo_runner.initialize(false).unwrap();
56755677
cairo_runner
@@ -5680,7 +5682,7 @@ mod tests {
56805682
assert!(cairo_runner.vm.segments.memory.data[6].len() as u32 % CELLS_PER_BITWISE != 0);
56815683
assert!(cairo_runner.vm.segments.memory.data[8].len() as u32 % CELLS_PER_KECCAK != 0);
56825684
assert_matches!(
5683-
cairo_runner.end_run(false, false, &mut hint_processor),
5685+
cairo_runner.end_run(false, false, &mut hint_processor, proof_mode),
56845686
Ok(())
56855687
);
56865688

vm/src/vm/security.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,9 @@ mod test {
150150
runner.initialize(false).unwrap();
151151
// runner.vm.segments.compute_effective_sizes();
152152
let mut hint_processor = BuiltinHintProcessor::new_empty();
153-
runner.end_run(false, false, &mut hint_processor).unwrap();
153+
runner
154+
.end_run(false, false, &mut hint_processor, false)
155+
.unwrap();
154156
// At the end of the run, the ret_fp should be the base of the new ret_fp segment we added
155157
// to the stack at the start of the run.
156158
runner.vm.run_context.fp = 0;
@@ -215,7 +217,9 @@ mod test {
215217

216218
runner.initialize(false).unwrap();
217219
let mut hint_processor = BuiltinHintProcessor::new_empty();
218-
runner.end_run(false, false, &mut hint_processor).unwrap();
220+
runner
221+
.end_run(false, false, &mut hint_processor, false)
222+
.unwrap();
219223
runner.vm.builtin_runners[0].set_stop_ptr(1);
220224
// Adding ((1, 1), (3, 0)) to the memory segment to simulate the ret_fp_segment.
221225
runner.vm.segments.memory = memory![((2, 0), 1), ((1, 1), (3, 0))];

vm/src/vm/vm_core.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -860,8 +860,16 @@ impl VirtualMachine {
860860
Ok(())
861861
}
862862

863-
pub fn end_run(&mut self, exec_scopes: &ExecutionScopes) -> Result<(), VirtualMachineError> {
864-
self.complete_builtin_auto_deductions()?;
863+
pub fn end_run(
864+
&mut self,
865+
exec_scopes: &ExecutionScopes,
866+
proof_mode: bool,
867+
) -> Result<(), VirtualMachineError> {
868+
if proof_mode {
869+
self.complete_builtin_auto_deductions()?;
870+
} else {
871+
self.verify_auto_deductions()?;
872+
}
865873
self.run_finished = true;
866874
match exec_scopes.data.len() {
867875
1 => Ok(()),
@@ -4638,7 +4646,7 @@ mod tests {
46384646
scopes.enter_scope(HashMap::new());
46394647

46404648
assert_matches!(
4641-
vm.end_run(scopes),
4649+
vm.end_run(scopes, false),
46424650
Err(VirtualMachineError::MainScopeError(
46434651
ExecScopeError::NoScopeError
46444652
))

0 commit comments

Comments
 (0)