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

fix(execution): forbid calling cairo0 contract with cairo1 only builtins #2103

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading