Skip to content

Commit

Permalink
Merge pull request #15 from lambdaclass/native_aot_builtincosts_entry…
Browse files Browse the repository at this point in the history
…_points

AotContractExecutor with builtincosts + entry points by type
  • Loading branch information
pefontana authored Nov 8, 2024
2 parents ebe222e + ea09d7c commit 71afaca
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 33 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ cairo-lang-sierra-to-casm = "2.8.4"
cairo-lang-starknet-classes = "2.8.4"
cairo-lang-utils = "2.8.4"
# This is a temporary dependency, will be removed once the new version of cairo-native is released to main.
cairo-native = { git = "https://github.com/lambdaclass/cairo_native", rev = "c80b41e4b6d8720a90e7aa6edd5d2d3a5e2d291e" }
cairo-native = { git = "https://github.com/lambdaclass/cairo_native", rev = "acc3a3b8c38c5ae52bad56c3388bad660bfadca6" }
cairo-vm = "1.0.1"
camelpaste = "0.1.0"
chrono = "0.4.26"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub fn execute_entry_point_call(
);
run_sierra_emu_executor(vm, function_id, call.clone())
} else {
run_native_executor(&contract_class.executor, function_id, call, syscall_handler)
run_native_executor(&contract_class.executor, call.entry_point_selector.0, call, syscall_handler)
};
let execution_time = pre_execution_instant.elapsed().as_millis();
tracing::info!(time = execution_time, "native contract execution finished");
Expand Down
5 changes: 3 additions & 2 deletions crates/blockifier/src/execution/native/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,15 @@ pub fn contract_entrypoint_to_entrypoint_selector(

pub fn run_native_executor(
native_executor: &AotContractExecutor,
function_id: &FunctionId,
selector: Felt,
call: CallEntryPoint,
mut syscall_handler: NativeSyscallHandler<'_>,
) -> EntryPointExecutionResult<CallInfo> {
let execution_result = native_executor.run(
function_id,
selector,
&call.calldata.0,
Some(call.initial_gas.into()),
None,
&mut syscall_handler,
);

Expand Down
39 changes: 13 additions & 26 deletions crates/blockifier/src/test_utils/struct_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,37 +15,21 @@ use crate::context::{BlockContext, ChainInfo, FeeTokenAddresses, TransactionCont
use crate::execution::call_info::{CallExecution, CallInfo, Retdata};
use crate::execution::contract_class::{ContractClassV0, ContractClassV1, NativeContractClassV1};
use crate::execution::entry_point::{
CallEntryPoint,
EntryPointExecutionContext,
EntryPointExecutionResult,
CallEntryPoint, EntryPointExecutionContext, EntryPointExecutionResult,
};
use crate::fee::fee_utils::get_fee_by_gas_vector;
use crate::state::state_api::State;
use crate::test_utils::{
get_raw_contract_class,
CHAIN_ID_NAME,
CURRENT_BLOCK_NUMBER,
CURRENT_BLOCK_TIMESTAMP,
DEFAULT_ETH_L1_DATA_GAS_PRICE,
DEFAULT_ETH_L1_GAS_PRICE,
DEFAULT_STRK_L1_DATA_GAS_PRICE,
DEFAULT_STRK_L1_GAS_PRICE,
TEST_ERC20_CONTRACT_ADDRESS,
TEST_ERC20_CONTRACT_ADDRESS2,
get_raw_contract_class, CHAIN_ID_NAME, CURRENT_BLOCK_NUMBER, CURRENT_BLOCK_TIMESTAMP,
DEFAULT_ETH_L1_DATA_GAS_PRICE, DEFAULT_ETH_L1_GAS_PRICE, DEFAULT_STRK_L1_DATA_GAS_PRICE,
DEFAULT_STRK_L1_GAS_PRICE, TEST_ERC20_CONTRACT_ADDRESS, TEST_ERC20_CONTRACT_ADDRESS2,
TEST_SEQUENCER_ADDRESS,
};
use crate::transaction::objects::{
DeprecatedTransactionInfo,
FeeType,
TransactionFeeResult,
TransactionInfo,
TransactionResources,
DeprecatedTransactionInfo, FeeType, TransactionFeeResult, TransactionInfo, TransactionResources,
};
use crate::versioned_constants::{
GasCosts,
OsConstants,
VersionedConstants,
VERSIONED_CONSTANTS_LATEST_JSON,
GasCosts, OsConstants, VersionedConstants, VERSIONED_CONSTANTS_LATEST_JSON,
};

impl CallEntryPoint {
Expand Down Expand Up @@ -249,9 +233,13 @@ impl NativeContractClassV1 {
// Compile the Sierra Program to native code and loads it into the process'
// memory space.
fn compile_and_load(
sierra_program: &cairo_lang_sierra::program::Program,
contract: &cairo_lang_starknet_classes::contract_class::ContractClass,
) -> Result<AotContractExecutor, cairo_native::error::Error> {
AotContractExecutor::new(sierra_program, cairo_native::OptLevel::Default)
AotContractExecutor::new(
&contract.extract_sierra_program().unwrap(),
&contract.entry_points_by_type,
cairo_native::OptLevel::Default,
)
}

let sierra_contract_class: cairo_lang_starknet_classes::contract_class::ContractClass =
Expand All @@ -262,8 +250,7 @@ impl NativeContractClassV1 {
// 1. Having access to the encoding/decoding functions
// 2. Refactoring the code on the Cairo mono-repo

let sierra_program = sierra_contract_class.extract_sierra_program()?;
let executor = compile_and_load(&sierra_program)?;
let executor = compile_and_load(&sierra_contract_class)?;

let executor = Arc::new(executor);
Ok(Self::new(executor, sierra_contract_class)?)
Expand Down

0 comments on commit 71afaca

Please sign in to comment.