Skip to content

Commit

Permalink
sierra emu
Browse files Browse the repository at this point in the history
  • Loading branch information
edg-l committed Sep 17, 2024
1 parent dcae0b9 commit e7fb9f4
Show file tree
Hide file tree
Showing 24 changed files with 322 additions and 123 deletions.
4 changes: 3 additions & 1 deletion crates/blockifier/bench/blockifier_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
//! Run the benchmarks using `cargo bench --bench blockifier_bench`.
use blockifier::test_utils::transfers_generator::{
RecipientGeneratorType, TransfersGenerator, TransfersGeneratorConfig,
RecipientGeneratorType,
TransfersGenerator,
TransfersGeneratorConfig,
};
use criterion::{criterion_group, criterion_main, Criterion};

Expand Down
7 changes: 5 additions & 2 deletions crates/blockifier/src/bouncer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@ use serde::{Deserialize, Serialize};
use starknet_api::core::ClassHash;

use crate::blockifier::transaction_executor::{
TransactionExecutorError, TransactionExecutorResult,
TransactionExecutorError,
TransactionExecutorResult,
};
use crate::execution::call_info::ExecutionSummary;
use crate::fee::gas_usage::get_onchain_data_segment_length;
use crate::state::cached_state::{StateChangesKeys, StorageEntry};
use crate::state::state_api::StateReader;
use crate::transaction::errors::TransactionExecutionError;
use crate::transaction::objects::{
ExecutionResourcesTraits, TransactionExecutionResult, TransactionResources,
ExecutionResourcesTraits,
TransactionExecutionResult,
TransactionResources,
};

#[cfg(test)]
Expand Down
3 changes: 2 additions & 1 deletion crates/blockifier/src/bouncer_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ use starknet_api::{class_hash, contract_address, felt, patricia_key};

use super::BouncerConfig;
use crate::blockifier::transaction_executor::{
TransactionExecutorError, TransactionExecutorResult,
TransactionExecutorError,
TransactionExecutorResult,
};
use crate::bouncer::{verify_tx_weights_in_bounds, Bouncer, BouncerWeights, BuiltinCount};
use crate::context::BlockContext;
Expand Down
9 changes: 6 additions & 3 deletions crates/blockifier/src/execution/common_hints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ use std::ops::Shl;
use std::rc::Rc;

use cairo_vm::hint_processor::builtin_hint_processor::builtin_hint_processor_definition::{
BuiltinHintProcessor, HintFunc,
BuiltinHintProcessor,
HintFunc,
};
use cairo_vm::hint_processor::builtin_hint_processor::hint_utils::{
get_integer_from_var_name, insert_value_from_var_name,
get_integer_from_var_name,
insert_value_from_var_name,
};
use cairo_vm::hint_processor::hint_processor_definition::HintReference;
use cairo_vm::serde::deserialize_program::ApTracking;
Expand All @@ -18,7 +20,8 @@ use num_bigint::BigUint;
use starknet_types_core::felt::Felt;

use crate::execution::hint_code::{
NORMALIZE_ADDRESS_SET_IS_250_HINT, NORMALIZE_ADDRESS_SET_IS_SMALL_HINT,
NORMALIZE_ADDRESS_SET_IS_250_HINT,
NORMALIZE_ADDRESS_SET_IS_SMALL_HINT,
};

/// Transaction execution mode.
Expand Down
2 changes: 1 addition & 1 deletion crates/blockifier/src/execution/contract_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ pub struct NativeContractClassV1Inner {
entry_points_by_type: NativeContractEntryPoints,
// Storing the raw sierra program and entry points to be able to fallback to the vm
sierra_program_raw: Vec<BigUintAsHex>,
program: cairo_lang_sierra::program::Program, // for sierra emu
pub program: cairo_lang_sierra::program::Program, // for sierra emu
fallback_entry_points_by_type: SierraContractEntryPoints,
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ use crate::execution::call_info::{CallExecution, CallInfo};
use crate::execution::contract_class::ContractClassV0;
use crate::execution::deprecated_syscalls::hint_processor::DeprecatedSyscallHintProcessor;
use crate::execution::entry_point::{
CallEntryPoint, EntryPointExecutionContext, EntryPointExecutionResult,
CallEntryPoint,
EntryPointExecutionContext,
EntryPointExecutionResult,
};
use crate::execution::errors::{PostExecutionError, PreExecutionError};
use crate::execution::execution_utils::{read_execution_retdata, Args, ReadOnlySegments};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ use rstest::rstest;
use starknet_api::core::{calculate_contract_address, ChainId, PatriciaKey};
use starknet_api::state::StorageKey;
use starknet_api::transaction::{
Calldata, ContractAddressSalt, EventContent, EventData, EventKey, Fee, TransactionHash,
Calldata,
ContractAddressSalt,
EventContent,
EventData,
EventKey,
Fee,
TransactionHash,
TransactionVersion,
};
use starknet_api::{calldata, felt};
Expand All @@ -27,13 +33,22 @@ use crate::state::state_api::StateReader;
use crate::test_utils::contracts::FeatureContract;
use crate::test_utils::initial_test_state::test_state;
use crate::test_utils::{
calldata_for_deploy_test, get_syscall_resources, trivial_external_entry_point_new,
CairoVersion, CHAIN_ID_NAME, CURRENT_BLOCK_NUMBER, CURRENT_BLOCK_NUMBER_FOR_VALIDATE,
CURRENT_BLOCK_TIMESTAMP, CURRENT_BLOCK_TIMESTAMP_FOR_VALIDATE, TEST_SEQUENCER_ADDRESS,
calldata_for_deploy_test,
get_syscall_resources,
trivial_external_entry_point_new,
CairoVersion,
CHAIN_ID_NAME,
CURRENT_BLOCK_NUMBER,
CURRENT_BLOCK_NUMBER_FOR_VALIDATE,
CURRENT_BLOCK_TIMESTAMP,
CURRENT_BLOCK_TIMESTAMP_FOR_VALIDATE,
TEST_SEQUENCER_ADDRESS,
};
use crate::transaction::constants::QUERY_VERSION_BASE_BIT;
use crate::transaction::objects::{
CommonAccountFields, DeprecatedTransactionInfo, TransactionInfo,
CommonAccountFields,
DeprecatedTransactionInfo,
TransactionInfo,
};
use crate::versioned_constants::VersionedConstants;
use crate::{check_entry_point_execution_error_for_custom_hint, nonce, retdata, storage_key};
Expand Down
29 changes: 24 additions & 5 deletions crates/blockifier/src/execution/deprecated_syscalls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,45 @@ use cairo_vm::vm::vm_core::VirtualMachine;
use serde::Deserialize;
use starknet_api::block::{BlockNumber, BlockTimestamp};
use starknet_api::core::{
calculate_contract_address, ClassHash, ContractAddress, EntryPointSelector, EthAddress,
calculate_contract_address,
ClassHash,
ContractAddress,
EntryPointSelector,
EthAddress,
};
use starknet_api::deprecated_contract_class::EntryPointType;
use starknet_api::state::StorageKey;
use starknet_api::transaction::{
Calldata, ContractAddressSalt, EventContent, EventData, EventKey, L2ToL1Payload,
Calldata,
ContractAddressSalt,
EventContent,
EventData,
EventKey,
L2ToL1Payload,
};
use starknet_types_core::felt::Felt;
use strum_macros::EnumIter;

use self::hint_processor::{
execute_inner_call, execute_library_call, felt_to_bool, read_call_params, read_calldata,
read_felt_array, DeprecatedSyscallExecutionError, DeprecatedSyscallHintProcessor,
execute_inner_call,
execute_library_call,
felt_to_bool,
read_call_params,
read_calldata,
read_felt_array,
DeprecatedSyscallExecutionError,
DeprecatedSyscallHintProcessor,
};
use super::syscalls::exceeds_event_size_limit;
use crate::execution::call_info::{MessageToL1, OrderedEvent, OrderedL2ToL1Message};
use crate::execution::common_hints::ExecutionMode;
use crate::execution::entry_point::{CallEntryPoint, CallType, ConstructorContext};
use crate::execution::execution_utils::{
execute_deployment, felt_from_ptr, write_felt, write_maybe_relocatable, ReadOnlySegment,
execute_deployment,
felt_from_ptr,
write_felt,
write_maybe_relocatable,
ReadOnlySegment,
};

#[cfg(test)]
Expand Down
13 changes: 10 additions & 3 deletions crates/blockifier/src/execution/execution_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ use std::env;

use cairo_lang_runner::casm_run::format_next_item;
use cairo_vm::serde::deserialize_program::{
deserialize_array_of_bigint_hex, Attribute, HintParams, Identifier, ReferenceManager,
deserialize_array_of_bigint_hex,
Attribute,
HintParams,
Identifier,
ReferenceManager,
};
use cairo_vm::types::builtin_name::BuiltinName;
use cairo_vm::types::errors::program_errors::ProgramError;
Expand All @@ -25,8 +29,11 @@ use super::errors::{ConstructorEntryPointExecutionError, EntryPointExecutionErro
use crate::execution::call_info::{CallInfo, Retdata};
use crate::execution::contract_class::ContractClass;
use crate::execution::entry_point::{
execute_constructor_entry_point, CallEntryPoint, ConstructorContext,
EntryPointExecutionContext, EntryPointExecutionResult,
execute_constructor_entry_point,
CallEntryPoint,
ConstructorContext,
EntryPointExecutionContext,
EntryPointExecutionResult,
};
use crate::execution::errors::PostExecutionError;
use crate::execution::native::entry_point_execution as native_entry_point_execution;
Expand Down
19 changes: 14 additions & 5 deletions crates/blockifier/src/execution/native/entry_point_execution.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
use cairo_vm::vm::runners::cairo_runner::ExecutionResources;
use std::sync::Arc;
use std::time::Instant;

use cairo_vm::vm::runners::cairo_runner::ExecutionResources;

use super::syscall_handler::NativeSyscallHandler;
use super::utils::run_native_executor;
use crate::execution::call_info::CallInfo;
use crate::execution::contract_class::NativeContractClassV1;
use crate::execution::entry_point::{
CallEntryPoint, EntryPointExecutionContext, EntryPointExecutionResult,
CallEntryPoint,
EntryPointExecutionContext,
EntryPointExecutionResult,
};
use crate::execution::native::utils::run_sierra_emu_executor;
use crate::state::state_api::State;

pub fn execute_entry_point_call(
Expand All @@ -20,7 +25,7 @@ pub fn execute_entry_point_call(
let function_id =
contract_class.get_entrypoint(call.entry_point_type, call.entry_point_selector)?;

let syscall_handler: NativeSyscallHandler<'_> = NativeSyscallHandler::new(
let mut syscall_handler: NativeSyscallHandler<'_> = NativeSyscallHandler::new(
state,
call.caller_address,
call.storage_address,
Expand All @@ -36,8 +41,12 @@ pub fn execute_entry_point_call(

let pre_execution_instant = Instant::now();

let result = if cfg!(feature = "use-sierra-emu") {
todo!()
let result = if cfg!(feature = "use-sierra-emu") {
let vm = sierra_emu::VirtualMachine::new_starknet(
Arc::new(contract_class.program.clone()),
&mut syscall_handler,
);
run_sierra_emu_executor(vm, function_id, call.clone())
} else {
run_native_executor(&contract_class.executor, function_id, call, syscall_handler)
};
Expand Down
Loading

0 comments on commit e7fb9f4

Please sign in to comment.