Skip to content

Commit 05352b1

Browse files
authored
feat: specify initial value for exec_scopes (#1772)
* feat: specify initial value for exec_scopes Context: bootloader and Starknet OS support. Added an `exec_scopes` parameter to `cairo_run_program` to pass variables to the hints of the program being run. We need a way to set initial variables inside the execution scopes to pass bootloader/OS arguments. The Python VM relies on a program input file and uses hints to deserialize this input. In most cases we do not want to have to deserialize these input types, but rather pass them directly as variables inside the root execution scope. We did not extend this feature to `cairo_run` to keep the PR minimal for discussion, TBD if it is desirable. * changelog * cairo_run_program_with_initial_scope * fix: revert change to call to cairo_run_program
1 parent cc9baac commit 05352b1

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
* Checks that only `Array<Felt252>` can be received by the program main function when running with with either `--proof_mode` or `--append_return_values`.
99
* Copies the input value to the output segment right after the output in the format `[array_len, arr[0], arr[1],.., arr[n]]`.
1010

11+
* feat: specify initial value for `exec_scopes` in `cairo_run_program` [1772](https://github.com/lambdaclass/cairo-vm/pull/1772)
12+
1113
* fix: make MemorySegmentManager.finalize() public [#1771](https://github.com/lambdaclass/cairo-vm/pull/1771)
1214

1315
* feat: load Cairo PIE from bytes [#1773](https://github.com/lambdaclass/cairo-vm/pull/1773)

vm/src/cairo_run.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use bincode::enc::write::Writer;
1515

1616
use thiserror_no_std::Error;
1717

18+
use crate::types::exec_scope::ExecutionScopes;
1819
#[cfg(feature = "test_utils")]
1920
use arbitrary::{self, Arbitrary};
2021

@@ -46,10 +47,12 @@ impl<'a> Default for CairoRunConfig<'a> {
4647
}
4748
}
4849

49-
pub fn cairo_run_program(
50+
/// Runs a program with a customized execution scope.
51+
pub fn cairo_run_program_with_initial_scope(
5052
program: &Program,
5153
cairo_run_config: &CairoRunConfig,
5254
hint_processor: &mut dyn HintProcessor,
55+
exec_scopes: ExecutionScopes,
5356
) -> Result<CairoRunner, CairoRunError> {
5457
let secure_run = cairo_run_config
5558
.secure_run
@@ -66,6 +69,8 @@ pub fn cairo_run_program(
6669
cairo_run_config.trace_enabled,
6770
)?;
6871

72+
cairo_runner.exec_scopes = exec_scopes;
73+
6974
let end = cairo_runner.initialize(allow_missing_builtins)?;
7075
// check step calculation
7176

@@ -95,6 +100,19 @@ pub fn cairo_run_program(
95100
Ok(cairo_runner)
96101
}
97102

103+
pub fn cairo_run_program(
104+
program: &Program,
105+
cairo_run_config: &CairoRunConfig,
106+
hint_processor: &mut dyn HintProcessor,
107+
) -> Result<CairoRunner, CairoRunError> {
108+
cairo_run_program_with_initial_scope(
109+
program,
110+
cairo_run_config,
111+
hint_processor,
112+
ExecutionScopes::new(),
113+
)
114+
}
115+
98116
pub fn cairo_run(
99117
program_content: &[u8],
100118
cairo_run_config: &CairoRunConfig,

0 commit comments

Comments
 (0)