Skip to content

Commit 2a4792c

Browse files
Add run_from_entrypoint_v2
1 parent 73afcc1 commit 2a4792c

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

vm/src/vm/runners/cairo_runner.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1523,6 +1523,38 @@ impl CairoRunner {
15231523
Ok(())
15241524
}
15251525

1526+
#[allow(clippy::result_large_err)]
1527+
/// Runs a cairo program from a give entrypoint, indicated by its pc offset, with the given arguments.
1528+
/// If `verify_secure` is set to true, [verify_secure_runner] will be called to run extra verifications.
1529+
/// `program_segment_size` is only used by the [verify_secure_runner] function and will be ignored if `verify_secure` is set to false.
1530+
pub fn run_from_entrypoint_v2(
1531+
&mut self,
1532+
entrypoint: usize,
1533+
args: &[&CairoArg],
1534+
verify_secure: bool,
1535+
program_segment_size: Option<usize>,
1536+
hint_processor: &mut dyn HintProcessor,
1537+
) -> Result<(), CairoRunError> {
1538+
let stack = args
1539+
.iter()
1540+
.map(|arg| self.vm.segments.gen_cairo_arg(arg))
1541+
.collect::<Result<Vec<MaybeRelocatable>, VirtualMachineError>>()?;
1542+
let return_fp = MaybeRelocatable::from(0);
1543+
let end = self.initialize_function_entrypoint(entrypoint, stack, return_fp)?;
1544+
1545+
self.initialize_vm()?;
1546+
1547+
self.run_until_pc_v2(end, hint_processor)
1548+
.map_err(|err| VmException::from_vm_error(self, err))?;
1549+
self.end_run(true, false, hint_processor)?;
1550+
1551+
if verify_secure {
1552+
verify_secure_runner(self, false, program_segment_size)?;
1553+
}
1554+
1555+
Ok(())
1556+
}
1557+
15261558
// Returns Ok(()) if there are enough allocated cells for the builtins.
15271559
// If not, the number of steps should be increased or a different layout should be used.
15281560
pub fn check_used_cells(&self) -> Result<(), VirtualMachineError> {

0 commit comments

Comments
 (0)