Skip to content

[BREAKING] Compute_missing_builtin_cells_only_in_proof_mode #2088

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion cairo1-run/src/cairo_run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 3 additions & 4 deletions vm/src/cairo_run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@
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()?;
Expand Down Expand Up @@ -208,9 +208,9 @@
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 {
Expand Down Expand Up @@ -258,9 +258,8 @@

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)?;

Check warning on line 261 in vm/src/cairo_run.rs

View check run for this annotation

Codecov / codecov/patch

vm/src/cairo_run.rs#L261

Added line #L261 was not covered by tests

cairo_runner.vm.verify_auto_deductions()?;
cairo_runner.read_return_values(allow_missing_builtins)?;
if cairo_run_config.proof_mode {
cairo_runner.finalize_segments()?;
Expand Down
1 change: 1 addition & 0 deletions vm/src/tests/cairo_run_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
16 changes: 13 additions & 3 deletions vm/src/vm/runners/builtin_runner/modulo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
22 changes: 12 additions & 10 deletions vm/src/vm/runners/cairo_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(());
Expand Down Expand Up @@ -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)?;
Expand Down Expand Up @@ -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
))
Expand All @@ -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);
Expand All @@ -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(())
);
}
Expand Down Expand Up @@ -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
Expand All @@ -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(())
);

Expand Down
8 changes: 6 additions & 2 deletions vm/src/vm/security.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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))];
Expand Down
14 changes: 11 additions & 3 deletions vm/src/vm/vm_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(()),
Expand Down Expand Up @@ -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
))
Expand Down
Loading