Skip to content

Commit 15de4b2

Browse files
Enable_using_secure_run_in_proof_mode (#2113)
1 parent bdf604f commit 15de4b2

File tree

1 file changed

+63
-6
lines changed

1 file changed

+63
-6
lines changed

vm/src/vm/runners/cairo_runner.rs

Lines changed: 63 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,18 +1009,32 @@ impl CairoRunner {
10091009
Ok(())
10101010
}
10111011

1012-
// Returns a map from builtin base's segment index to stop_ptr offset
1013-
// Aka the builtin's segment number and its maximum offset
1012+
/// Returns a tuple of builtin base's segment index and stop_ptr offset
1013+
/// Aka the builtin's segment number and its maximum offset
10141014
pub fn get_builtin_segments_info(&self) -> Result<Vec<(usize, usize)>, RunnerError> {
1015+
let proof_mode = self.is_proof_mode();
10151016
let mut builtin_segment_info = Vec::new();
10161017

10171018
for builtin in &self.vm.builtin_runners {
10181019
let (index, stop_ptr) = builtin.get_memory_segment_addresses();
10191020

1020-
builtin_segment_info.push((
1021-
index,
1022-
stop_ptr.ok_or_else(|| RunnerError::NoStopPointer(Box::new(builtin.name())))?,
1023-
));
1021+
match (proof_mode, stop_ptr) {
1022+
// Segment present (same handling in both modes).
1023+
(_, Some(sp)) => builtin_segment_info.push((index, sp)),
1024+
1025+
// If non proof-mode, only builtins in the program are present and they must
1026+
// point to a segment (so `stop_ptr` must be set). Throw an error if not.
1027+
(false, None) => {
1028+
return Err(RunnerError::NoStopPointer(Box::new(
1029+
builtin.name().to_owned(),
1030+
)));
1031+
}
1032+
1033+
// In proof‐mode there are builtin runners for all builtins in the layout, but only
1034+
// the ones that are in the program point to a segment (so `stop_ptr` is set).
1035+
// Only collect those and silently ignore the rest.
1036+
(true, None) => {}
1037+
}
10241038
}
10251039

10261040
Ok(builtin_segment_info)
@@ -3915,6 +3929,49 @@ mod tests {
39153929
);
39163930
}
39173931

3932+
#[test]
3933+
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
3934+
fn get_builtin_segments_info_non_proof_mode() {
3935+
let program_data =
3936+
include_bytes!("../../../../cairo_programs/proof_programs/assert_nn.json");
3937+
let cairo_run_config = CairoRunConfig {
3938+
entrypoint: "main",
3939+
trace_enabled: false,
3940+
relocate_mem: false,
3941+
layout: LayoutName::small,
3942+
proof_mode: false,
3943+
secure_run: Some(true),
3944+
..Default::default()
3945+
};
3946+
let mut hint_executor = BuiltinHintProcessor::new_empty();
3947+
let runner = cairo_run(program_data, &cairo_run_config, &mut hint_executor).unwrap();
3948+
// Only the range_check builtin is used in this program, and in non-proof mode, it will
3949+
// be the first and only builtin segment initialized (and used).
3950+
assert_eq!(runner.get_builtin_segments_info(), Ok(vec![(2, 6)]));
3951+
}
3952+
3953+
#[test]
3954+
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
3955+
fn get_builtin_segments_info_proof_mode() {
3956+
let program_data =
3957+
include_bytes!("../../../../cairo_programs/proof_programs/assert_nn.json");
3958+
let cairo_run_config = CairoRunConfig {
3959+
entrypoint: "main",
3960+
trace_enabled: false,
3961+
relocate_mem: false,
3962+
layout: LayoutName::small,
3963+
proof_mode: true,
3964+
secure_run: Some(true),
3965+
..Default::default()
3966+
};
3967+
let mut hint_executor = BuiltinHintProcessor::new_empty();
3968+
let runner = cairo_run(program_data, &cairo_run_config, &mut hint_executor).unwrap();
3969+
// Only the range_check builtin is used in this program, and in proof mode, it will
3970+
// be the first and only builtin segment used, but initialized after the other builtins
3971+
// in the layout.
3972+
assert_eq!(runner.get_builtin_segments_info(), Ok(vec![(4, 6)]));
3973+
}
3974+
39183975
#[test]
39193976
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
39203977
fn get_execution_resources_trace_not_enabled() {

0 commit comments

Comments
 (0)