diff --git a/cairo1-run/src/cairo_run.rs b/cairo1-run/src/cairo_run.rs index fbe0760d94..86fa37fd5f 100644 --- a/cairo1-run/src/cairo_run.rs +++ b/cairo1-run/src/cairo_run.rs @@ -267,7 +267,12 @@ pub fn cairo_run_program( runner.run_for_steps(1, &mut hint_processor)?; } - runner.end_run(false, false, &mut hint_processor)?; + runner.end_run( + false, + false, + &mut hint_processor, + cairo_run_config.proof_mode, + )?; let result_inner_type_size = result_inner_type_size(return_type_id, &sierra_program_registry, &type_sizes); diff --git a/vm/src/cairo_run.rs b/vm/src/cairo_run.rs index 63c40f19d1..cc1c91e6ce 100644 --- a/vm/src/cairo_run.rs +++ b/vm/src/cairo_run.rs @@ -103,9 +103,9 @@ pub fn cairo_run_program_with_initial_scope( cairo_run_config.disable_trace_padding, false, hint_processor, + cairo_run_config.proof_mode, )?; - cairo_runner.vm.verify_auto_deductions()?; cairo_runner.read_return_values(allow_missing_builtins)?; if cairo_run_config.proof_mode { cairo_runner.finalize_segments()?; @@ -208,9 +208,9 @@ pub fn cairo_run_pie( cairo_run_config.disable_trace_padding, false, hint_processor, + cairo_run_config.proof_mode, )?; - cairo_runner.vm.verify_auto_deductions()?; cairo_runner.read_return_values(allow_missing_builtins)?; if secure_run { @@ -258,9 +258,8 @@ pub fn cairo_run_fuzzed_program( res.map_err(|err| VmException::from_vm_error(&cairo_runner, err))?; - cairo_runner.end_run(false, false, hint_processor)?; + cairo_runner.end_run(false, false, hint_processor, cairo_run_config.proof_mode)?; - cairo_runner.vm.verify_auto_deductions()?; cairo_runner.read_return_values(allow_missing_builtins)?; if cairo_run_config.proof_mode { cairo_runner.finalize_segments()?; diff --git a/vm/src/tests/cairo_run_test.rs b/vm/src/tests/cairo_run_test.rs index 4e08fd25cb..6ef4faa976 100644 --- a/vm/src/tests/cairo_run_test.rs +++ b/vm/src/tests/cairo_run_test.rs @@ -1241,6 +1241,7 @@ fn run_program_with_custom_mod_builtin_params( cairo_run_config.disable_trace_padding, false, &mut hint_processor, + cairo_run_config.proof_mode, ) .unwrap(); diff --git a/vm/src/vm/runners/builtin_runner/modulo.rs b/vm/src/vm/runners/builtin_runner/modulo.rs index 85a8fe8070..6d0d711945 100644 --- a/vm/src/vm/runners/builtin_runner/modulo.rs +++ b/vm/src/vm/runners/builtin_runner/modulo.rs @@ -821,15 +821,25 @@ mod tests { let mut hint_processor = BuiltinHintProcessor::new_empty(); let program = Program::from_bytes(program_data, Some("main")).unwrap(); - let mut runner = - CairoRunner::new(&program, LayoutName::all_cairo, None, true, false, false).unwrap(); + let proof_mode = true; + let mut runner = CairoRunner::new( + &program, + LayoutName::all_cairo, + None, + proof_mode, + false, + false, + ) + .unwrap(); let end = runner.initialize(false).unwrap(); // Modify add_mod & mul_mod params runner.run_until_pc(end, &mut hint_processor).unwrap(); runner.run_for_steps(1, &mut hint_processor).unwrap(); - runner.end_run(false, false, &mut hint_processor).unwrap(); + runner + .end_run(false, false, &mut hint_processor, proof_mode) + .unwrap(); runner.read_return_values(false).unwrap(); runner.finalize_segments().unwrap(); diff --git a/vm/src/vm/runners/cairo_runner.rs b/vm/src/vm/runners/cairo_runner.rs index 30f7374e89..b643337d71 100644 --- a/vm/src/vm/runners/cairo_runner.rs +++ b/vm/src/vm/runners/cairo_runner.rs @@ -891,13 +891,14 @@ impl CairoRunner { disable_trace_padding: bool, disable_finalize_all: bool, hint_processor: &mut dyn HintProcessor, + proof_mode: bool, ) -> Result<(), VirtualMachineError> { if self.run_ended { return Err(RunnerError::EndRunCalledTwice.into()); } self.vm.segments.memory.relocate_memory()?; - self.vm.end_run(&self.exec_scopes)?; + self.vm.end_run(&self.exec_scopes, proof_mode)?; if disable_finalize_all { return Ok(()); @@ -1155,7 +1156,7 @@ impl CairoRunner { self.run_until_pc(end, hint_processor) .map_err(|err| VmException::from_vm_error(self, err))?; - self.end_run(true, false, hint_processor)?; + self.end_run(true, false, hint_processor, self.is_proof_mode())?; if verify_secure { verify_secure_runner(self, false, program_segment_size)?; @@ -3875,7 +3876,7 @@ mod tests { cairo_runner.run_ended = true; assert_matches!( - cairo_runner.end_run(true, false, &mut hint_processor), + cairo_runner.end_run(true, false, &mut hint_processor, false), Err(VirtualMachineError::RunnerError( RunnerError::EndRunCalledTwice )) @@ -3891,14 +3892,14 @@ mod tests { let mut cairo_runner = cairo_runner!(program); assert_matches!( - cairo_runner.end_run(true, false, &mut hint_processor), + cairo_runner.end_run(true, false, &mut hint_processor, false), Ok(()) ); cairo_runner.run_ended = false; cairo_runner.relocated_memory.clear(); assert_matches!( - cairo_runner.end_run(true, true, &mut hint_processor), + cairo_runner.end_run(true, true, &mut hint_processor, false), Ok(()) ); assert!(!cairo_runner.run_ended); @@ -3912,16 +3913,16 @@ mod tests { Some("main"), ) .unwrap(); - + let proof_mode = true; let mut hint_processor = BuiltinHintProcessor::new_empty(); - let mut cairo_runner = cairo_runner!(program, LayoutName::all_cairo, true, true); + let mut cairo_runner = cairo_runner!(program, LayoutName::all_cairo, proof_mode, true); let end = cairo_runner.initialize(false).unwrap(); cairo_runner .run_until_pc(end, &mut hint_processor) .expect("Call to `CairoRunner::run_until_pc()` failed."); assert_matches!( - cairo_runner.end_run(false, false, &mut hint_processor), + cairo_runner.end_run(false, false, &mut hint_processor, proof_mode), Ok(()) ); } @@ -5665,7 +5666,8 @@ mod tests { .unwrap(); let mut hint_processor = BuiltinHintProcessor::new_empty(); - let mut cairo_runner = cairo_runner!(program, LayoutName::all_cairo, true, true); + let proof_mode = true; + let mut cairo_runner = cairo_runner!(program, LayoutName::all_cairo, proof_mode, true); let end = cairo_runner.initialize(false).unwrap(); cairo_runner @@ -5676,7 +5678,7 @@ mod tests { assert!(cairo_runner.vm.segments.memory.data[6].len() as u32 % CELLS_PER_BITWISE != 0); assert!(cairo_runner.vm.segments.memory.data[8].len() as u32 % CELLS_PER_KECCAK != 0); assert_matches!( - cairo_runner.end_run(false, false, &mut hint_processor), + cairo_runner.end_run(false, false, &mut hint_processor, proof_mode), Ok(()) ); diff --git a/vm/src/vm/security.rs b/vm/src/vm/security.rs index 0dfdda8f23..08abc03198 100644 --- a/vm/src/vm/security.rs +++ b/vm/src/vm/security.rs @@ -150,7 +150,9 @@ mod test { runner.initialize(false).unwrap(); // runner.vm.segments.compute_effective_sizes(); let mut hint_processor = BuiltinHintProcessor::new_empty(); - runner.end_run(false, false, &mut hint_processor).unwrap(); + runner + .end_run(false, false, &mut hint_processor, false) + .unwrap(); // At the end of the run, the ret_fp should be the base of the new ret_fp segment we added // to the stack at the start of the run. runner.vm.run_context.fp = 0; @@ -215,7 +217,9 @@ mod test { runner.initialize(false).unwrap(); let mut hint_processor = BuiltinHintProcessor::new_empty(); - runner.end_run(false, false, &mut hint_processor).unwrap(); + runner + .end_run(false, false, &mut hint_processor, false) + .unwrap(); runner.vm.builtin_runners[0].set_stop_ptr(1); // Adding ((1, 1), (3, 0)) to the memory segment to simulate the ret_fp_segment. runner.vm.segments.memory = memory![((2, 0), 1), ((1, 1), (3, 0))]; diff --git a/vm/src/vm/vm_core.rs b/vm/src/vm/vm_core.rs index 177fa0eba7..502c0bb8cd 100644 --- a/vm/src/vm/vm_core.rs +++ b/vm/src/vm/vm_core.rs @@ -859,8 +859,16 @@ impl VirtualMachine { Ok(()) } - pub fn end_run(&mut self, exec_scopes: &ExecutionScopes) -> Result<(), VirtualMachineError> { - self.complete_builtin_auto_deductions()?; + pub fn end_run( + &mut self, + exec_scopes: &ExecutionScopes, + proof_mode: bool, + ) -> Result<(), VirtualMachineError> { + if proof_mode { + self.complete_builtin_auto_deductions()?; + } else { + self.verify_auto_deductions()?; + } self.run_finished = true; match exec_scopes.data.len() { 1 => Ok(()), @@ -4621,7 +4629,7 @@ mod tests { scopes.enter_scope(HashMap::new()); assert_matches!( - vm.end_run(scopes), + vm.end_run(scopes, false), Err(VirtualMachineError::MainScopeError( ExecScopeError::NoScopeError ))