Skip to content

Commit 622a92b

Browse files
Enable_using_secure_run_in_proof_mode
1 parent bdf604f commit 622a92b

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

vm/src/vm/runners/cairo_runner.rs

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ use super::{
5959
};
6060
use crate::types::instance_definitions::mod_instance_def::ModInstanceDef;
6161

62+
type ProcessBuiltinSegmentClosure =
63+
fn(usize, Option<usize>, BuiltinName) -> Result<Option<(usize, usize)>, RunnerError>;
64+
6265
#[derive(Clone, Debug, Eq, PartialEq)]
6366
pub enum CairoArg {
6467
Single(MaybeRelocatable),
@@ -1012,15 +1015,30 @@ impl CairoRunner {
10121015
// Returns a map from builtin base's segment index to stop_ptr offset
10131016
// Aka the builtin's segment number and its maximum offset
10141017
pub fn get_builtin_segments_info(&self) -> Result<Vec<(usize, usize)>, RunnerError> {
1015-
let mut builtin_segment_info = Vec::new();
1018+
let proof_mode = self.is_proof_mode();
1019+
1020+
// Closure to process each builtin's segment info based on whether we are in proof mode or not.
1021+
let process: ProcessBuiltinSegmentClosure = if proof_mode {
1022+
// In proof‐mode there are builtin runners for all builtins in the layout, but only the ones
1023+
// that are in the program point to a segment (so `stop_ptr` is set).
1024+
// Only collect those and silently ignore the rest.
1025+
|index, stop_ptr, _| Ok(stop_ptr.map(|sp| (index, sp)))
1026+
} else {
1027+
// If non proof-mode, only builtins in the program are present and they must
1028+
// point to a segment (so `stop_ptr` must be set). Throw an error if not.
1029+
|index, stop_ptr, name| {
1030+
let sp = stop_ptr
1031+
.ok_or_else(|| RunnerError::NoStopPointer(Box::new(name.to_owned())))?;
1032+
Ok(Some((index, sp)))
1033+
}
1034+
};
10161035

1036+
let mut builtin_segment_info = Vec::new();
10171037
for builtin in &self.vm.builtin_runners {
10181038
let (index, stop_ptr) = builtin.get_memory_segment_addresses();
1019-
1020-
builtin_segment_info.push((
1021-
index,
1022-
stop_ptr.ok_or_else(|| RunnerError::NoStopPointer(Box::new(builtin.name())))?,
1023-
));
1039+
if let Some(pair) = process(index, stop_ptr, builtin.name())? {
1040+
builtin_segment_info.push(pair);
1041+
}
10241042
}
10251043

10261044
Ok(builtin_segment_info)

0 commit comments

Comments
 (0)