From 397baa7633b0d7c9a7422e55e659c1c1ed6d1026 Mon Sep 17 00:00:00 2001 From: Rodrigo Date: Mon, 11 Nov 2024 15:46:05 +0000 Subject: [PATCH 1/2] feat(blockifier): use AotContractExecutor --- .../src/execution/native/contract_class.rs | 8 ++++---- .../src/execution/native/entry_point_execution.rs | 2 +- crates/blockifier/src/test_utils/struct_impls.rs | 13 +++---------- 3 files changed, 8 insertions(+), 15 deletions(-) diff --git a/crates/blockifier/src/execution/native/contract_class.rs b/crates/blockifier/src/execution/native/contract_class.rs index c6e19f2129..b4ec966e9d 100644 --- a/crates/blockifier/src/execution/native/contract_class.rs +++ b/crates/blockifier/src/execution/native/contract_class.rs @@ -6,7 +6,7 @@ use cairo_lang_starknet_classes::contract_class::{ ContractClass as SierraContractClass, ContractEntryPoint as SierraContractEntryPoint, }; -use cairo_native::executor::AotNativeExecutor; +use cairo_native::executor::AotContractExecutor; use starknet_api::core::EntryPointSelector; use crate::execution::contract_class::{ContractClassV1, EntryPointsByType, HasSelector}; @@ -33,7 +33,7 @@ impl NativeContractClassV1 { /// executor must be derived from sierra_program which in turn must be derived from /// sierra_contract_class. pub fn new( - executor: AotNativeExecutor, + executor: AotContractExecutor, sierra_contract_class: SierraContractClass, casm: ContractClassV1, ) -> NativeContractClassV1 { @@ -54,14 +54,14 @@ impl NativeContractClassV1 { #[derive(Debug)] pub struct NativeContractClassV1Inner { - pub executor: AotNativeExecutor, + pub executor: AotContractExecutor, entry_points_by_type: EntryPointsByType, casm: ContractClassV1, } impl NativeContractClassV1Inner { fn new( - executor: AotNativeExecutor, + executor: AotContractExecutor, sierra_contract_class: SierraContractClass, casm: ContractClassV1, ) -> Self { diff --git a/crates/blockifier/src/execution/native/entry_point_execution.rs b/crates/blockifier/src/execution/native/entry_point_execution.rs index 2b1d22b19d..a7f9a614de 100644 --- a/crates/blockifier/src/execution/native/entry_point_execution.rs +++ b/crates/blockifier/src/execution/native/entry_point_execution.rs @@ -27,7 +27,7 @@ pub fn execute_entry_point_call( let mut syscall_handler: NativeSyscallHandler<'_> = NativeSyscallHandler::new(call, state, resources, context); - let execution_result = contract_class.executor.invoke_contract_dynamic( + let execution_result = contract_class.executor.run( &function_id, &syscall_handler.call.calldata.0.clone(), Some(syscall_handler.call.initial_gas.into()), diff --git a/crates/blockifier/src/test_utils/struct_impls.rs b/crates/blockifier/src/test_utils/struct_impls.rs index 6c73da4b9e..bc2fa03d99 100644 --- a/crates/blockifier/src/test_utils/struct_impls.rs +++ b/crates/blockifier/src/test_utils/struct_impls.rs @@ -4,7 +4,7 @@ use cairo_lang_starknet_classes::casm_contract_class::CasmContractClass; #[cfg(feature = "cairo_native")] use cairo_lang_starknet_classes::contract_class::ContractClass as SierraContractClass; #[cfg(feature = "cairo_native")] -use cairo_native::executor::AotNativeExecutor; +use cairo_native::executor::AotContractExecutor; use cairo_vm::vm::runners::cairo_runner::ExecutionResources; use serde_json::Value; use starknet_api::block::{BlockNumber, BlockTimestamp, NonzeroGasPrice}; @@ -250,15 +250,8 @@ impl NativeContractClassV1 { .extract_sierra_program() .expect("Cannot extract sierra program from sierra contract class"); - // Create a Cairo Native MLIR context. This structure handles MLIR initialization and - // compiles Sierra programs into an MLIR module - let native_context = cairo_native::context::NativeContext::new(); - // Compile the sierra program into a MLIR module - let native_program = native_context - .compile(&sierra_program, false) - .expect("Cannot compile sierra program into native program"); - let executor = - AotNativeExecutor::from_native_module(native_program, cairo_native::OptLevel::Default); + let executor = AotContractExecutor::new(&sierra_program, cairo_native::OptLevel::Default) + .expect("Cannot compile sierra into native"); // Compile the sierra contract class into casm let casm_contract_class = CasmContractClass::from_contract_class( From 9d3314ac4693ec1e9b630f56a509620e3ca1ca0d Mon Sep 17 00:00:00 2001 From: Rodrigo Date: Mon, 11 Nov 2024 15:50:42 +0000 Subject: [PATCH 2/2] chore(blockifier): update native expected gas --- .../src/execution/syscalls/syscall_tests/storage_read_write.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/blockifier/src/execution/syscalls/syscall_tests/storage_read_write.rs b/crates/blockifier/src/execution/syscalls/syscall_tests/storage_read_write.rs index bebde966a4..5368e047db 100644 --- a/crates/blockifier/src/execution/syscalls/syscall_tests/storage_read_write.rs +++ b/crates/blockifier/src/execution/syscalls/syscall_tests/storage_read_write.rs @@ -15,7 +15,7 @@ use crate::test_utils::{trivial_external_entry_point_new, CairoVersion, BALANCE} #[cfg_attr( feature = "cairo_native", - test_case(FeatureContract::TestContract(CairoVersion::Native), 27290; "Native") + test_case(FeatureContract::TestContract(CairoVersion::Native), 25920; "Native") )] #[test_case(FeatureContract::TestContract(CairoVersion::Cairo1), REQUIRED_GAS_STORAGE_READ_WRITE_TEST; "VM")] fn test_storage_read_write(test_contract: FeatureContract, expected_gas: u64) {