Skip to content

Commit 642ea1e

Browse files
[BREAKING] Compute_missing_builtin_cells_only_in_proof_mode
1 parent dc1c49b commit 642ea1e

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
@@ -103,9 +103,9 @@ pub fn cairo_run_program_with_initial_scope(
103103
cairo_run_config.disable_trace_padding,
104104
false,
105105
hint_processor,
106+
cairo_run_config.proof_mode,
106107
)?;
107108

108-
cairo_runner.vm.verify_auto_deductions()?;
109109
cairo_runner.read_return_values(allow_missing_builtins)?;
110110
if cairo_run_config.proof_mode {
111111
cairo_runner.finalize_segments()?;
@@ -208,9 +208,9 @@ pub fn cairo_run_pie(
208208
cairo_run_config.disable_trace_padding,
209209
false,
210210
hint_processor,
211+
cairo_run_config.proof_mode,
211212
)?;
212213

213-
cairo_runner.vm.verify_auto_deductions()?;
214214
cairo_runner.read_return_values(allow_missing_builtins)?;
215215

216216
if secure_run {
@@ -258,9 +258,8 @@ pub fn cairo_run_fuzzed_program(
258258

259259
res.map_err(|err| VmException::from_vm_error(&cairo_runner, err))?;
260260

261-
cairo_runner.end_run(false, false, hint_processor)?;
261+
cairo_runner.end_run(false, false, hint_processor, cairo_run_config.proof_mode)?;
262262

263-
cairo_runner.vm.verify_auto_deductions()?;
264263
cairo_runner.read_return_values(allow_missing_builtins)?;
265264
if cairo_run_config.proof_mode {
266265
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(());
@@ -1155,7 +1156,7 @@ impl CairoRunner {
11551156

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

11601161
if verify_secure {
11611162
verify_secure_runner(self, false, program_segment_size)?;
@@ -3875,7 +3876,7 @@ mod tests {
38753876

38763877
cairo_runner.run_ended = true;
38773878
assert_matches!(
3878-
cairo_runner.end_run(true, false, &mut hint_processor),
3879+
cairo_runner.end_run(true, false, &mut hint_processor, false),
38793880
Err(VirtualMachineError::RunnerError(
38803881
RunnerError::EndRunCalledTwice
38813882
))
@@ -3891,14 +3892,14 @@ mod tests {
38913892
let mut cairo_runner = cairo_runner!(program);
38923893

38933894
assert_matches!(
3894-
cairo_runner.end_run(true, false, &mut hint_processor),
3895+
cairo_runner.end_run(true, false, &mut hint_processor, false),
38953896
Ok(())
38963897
);
38973898

38983899
cairo_runner.run_ended = false;
38993900
cairo_runner.relocated_memory.clear();
39003901
assert_matches!(
3901-
cairo_runner.end_run(true, true, &mut hint_processor),
3902+
cairo_runner.end_run(true, true, &mut hint_processor, false),
39023903
Ok(())
39033904
);
39043905
assert!(!cairo_runner.run_ended);
@@ -3912,16 +3913,16 @@ mod tests {
39123913
Some("main"),
39133914
)
39143915
.unwrap();
3915-
3916+
let proof_mode = true;
39163917
let mut hint_processor = BuiltinHintProcessor::new_empty();
3917-
let mut cairo_runner = cairo_runner!(program, LayoutName::all_cairo, true, true);
3918+
let mut cairo_runner = cairo_runner!(program, LayoutName::all_cairo, proof_mode, true);
39183919

39193920
let end = cairo_runner.initialize(false).unwrap();
39203921
cairo_runner
39213922
.run_until_pc(end, &mut hint_processor)
39223923
.expect("Call to `CairoRunner::run_until_pc()` failed.");
39233924
assert_matches!(
3924-
cairo_runner.end_run(false, false, &mut hint_processor),
3925+
cairo_runner.end_run(false, false, &mut hint_processor, proof_mode),
39253926
Ok(())
39263927
);
39273928
}
@@ -5665,7 +5666,8 @@ mod tests {
56655666
.unwrap();
56665667

56675668
let mut hint_processor = BuiltinHintProcessor::new_empty();
5668-
let mut cairo_runner = cairo_runner!(program, LayoutName::all_cairo, true, true);
5669+
let proof_mode = true;
5670+
let mut cairo_runner = cairo_runner!(program, LayoutName::all_cairo, proof_mode, true);
56695671

56705672
let end = cairo_runner.initialize(false).unwrap();
56715673
cairo_runner
@@ -5676,7 +5678,7 @@ mod tests {
56765678
assert!(cairo_runner.vm.segments.memory.data[6].len() as u32 % CELLS_PER_BITWISE != 0);
56775679
assert!(cairo_runner.vm.segments.memory.data[8].len() as u32 % CELLS_PER_KECCAK != 0);
56785680
assert_matches!(
5679-
cairo_runner.end_run(false, false, &mut hint_processor),
5681+
cairo_runner.end_run(false, false, &mut hint_processor, proof_mode),
56805682
Ok(())
56815683
);
56825684

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
@@ -859,8 +859,16 @@ impl VirtualMachine {
859859
Ok(())
860860
}
861861

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

46234631
assert_matches!(
4624-
vm.end_run(scopes),
4632+
vm.end_run(scopes, false),
46254633
Err(VirtualMachineError::MainScopeError(
46264634
ExecScopeError::NoScopeError
46274635
))

0 commit comments

Comments
 (0)