Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Commit

Permalink
fix(execution): forbid calling cairo0 contract with cairo1 only builtins
Browse files Browse the repository at this point in the history
  • Loading branch information
meship-starkware committed Jul 23, 2024
1 parent 08da831 commit c6cfe14
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -71,6 +82,12 @@ pub fn initialize_execution_context<'a>(
) -> Result<VmExecutionContext<'a>, PreExecutionError> {
// Resolve initial PC from EP indicator.
let entry_point_pc = resolve_entry_point_pc(call, &contract_class)?;
let program_builtins_set: HashSet<BuiltinName> =
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;
Expand Down
2 changes: 2 additions & 0 deletions crates/blockifier/src/execution/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<RunnerError> for PreExecutionError {
Expand Down

0 comments on commit c6cfe14

Please sign in to comment.