From c6cfe14ef3225fcda3d029d2148f428143a12973 Mon Sep 17 00:00:00 2001 From: meship-starkware Date: Mon, 22 Jul 2024 14:19:42 +0300 Subject: [PATCH] fix(execution): forbid calling cairo0 contract with cairo1 only builtins --- .../deprecated_entry_point_execution.rs | 17 +++++++++++++++++ crates/blockifier/src/execution/errors.rs | 2 ++ 2 files changed, 19 insertions(+) diff --git a/crates/blockifier/src/execution/deprecated_entry_point_execution.rs b/crates/blockifier/src/execution/deprecated_entry_point_execution.rs index 4f84b19d03..eb77d6d840 100644 --- a/crates/blockifier/src/execution/deprecated_entry_point_execution.rs +++ b/crates/blockifier/src/execution/deprecated_entry_point_execution.rs @@ -1,3 +1,5 @@ +use std::collections::HashSet; + use cairo_vm::types::builtin_name::BuiltinName; use cairo_vm::types::layout_name::LayoutName; use cairo_vm::types::relocatable::{MaybeRelocatable, Relocatable}; @@ -27,6 +29,15 @@ pub struct VmExecutionContext<'a> { pub entry_point_pc: usize, } +pub const CAIRO0_BUILTINS_NAMES: [BuiltinName; 6] = [ + BuiltinName::range_check, + BuiltinName::pedersen, + BuiltinName::ecdsa, + BuiltinName::bitwise, + BuiltinName::ec_op, + BuiltinName::poseidon, +]; + /// Executes a specific call to a contract entry point and returns its output. pub fn execute_entry_point_call( call: CallEntryPoint, @@ -71,6 +82,12 @@ pub fn initialize_execution_context<'a>( ) -> Result, PreExecutionError> { // Resolve initial PC from EP indicator. let entry_point_pc = resolve_entry_point_pc(call, &contract_class)?; + let program_builtins_set: HashSet = + HashSet::from_iter(contract_class.program.iter_builtins().copied()); + let cairo0_builtins_set = HashSet::from_iter(CAIRO0_BUILTINS_NAMES.iter().copied()); + if !program_builtins_set.is_subset(&cairo0_builtins_set) { + return Err(PreExecutionError::UnsupportedCairo0Builtin); + } // Instantiate Cairo runner. let proof_mode = false; diff --git a/crates/blockifier/src/execution/errors.rs b/crates/blockifier/src/execution/errors.rs index 1fa6a1d5b2..276687f640 100644 --- a/crates/blockifier/src/execution/errors.rs +++ b/crates/blockifier/src/execution/errors.rs @@ -42,6 +42,8 @@ pub enum PreExecutionError { StateError(#[from] StateError), #[error("Requested contract address {:#064x} is not deployed.", .0.key())] UninitializedStorageAddress(ContractAddress), + #[error("Unsupported cairo0 builtin.")] + UnsupportedCairo0Builtin, } impl From for PreExecutionError {