diff --git a/Dockerfile b/Dockerfile index ed40d57697..30b0c4b551 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,12 +1,12 @@ # Stage 1: Build golang dependencies and binaries -FROM ubuntu:24.04 AS build +FROM ubuntu:24.10 AS build ARG VM_DEBUG -# Install Alpine Dependencies -# removal is temp. to fix https://github.com/orgs/community/discussions/120966 -RUN apt-get update && \ - apt-get install build-essential cargo git golang upx-ucl libjemalloc-dev libjemalloc2 -y + +RUN apt-get -qq update && \ + apt-get -qq install curl build-essential git golang upx-ucl libjemalloc-dev libjemalloc2 -y +RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -q -y WORKDIR /app @@ -14,13 +14,13 @@ WORKDIR /app COPY . . # Build the project -RUN VM_DEBUG=${VM_DEBUG} make juno +RUN bash -c 'source ~/.cargo/env && VM_DEBUG=${VM_DEBUG} make juno' # Compress the executable with UPX RUN upx-ucl /app/build/juno # Stage 2: Build Docker image -FROM ubuntu:23.10 AS runtime +FROM ubuntu:24.10 AS runtime RUN apt-get update && apt-get install -y ca-certificates curl gawk grep libjemalloc-dev libjemalloc2 diff --git a/node/node.go b/node/node.go index fedc9a79e7..592cffd743 100644 --- a/node/node.go +++ b/node/node.go @@ -172,7 +172,7 @@ func New(cfg *Config, version string) (*Node, error) { //nolint:gocyclo,funlen services = append(services, synchronizer) } - throttledVM := NewThrottledVM(vm.New(log), cfg.MaxVMs, int32(cfg.MaxVMQueue)) + throttledVM := NewThrottledVM(vm.New(false, log), cfg.MaxVMs, int32(cfg.MaxVMQueue)) var syncReader sync.Reader = &sync.NoopSynchronizer{} if synchronizer != nil { diff --git a/node/throttled_vm.go b/node/throttled_vm.go index f502d134d9..7151867c00 100644 --- a/node/throttled_vm.go +++ b/node/throttled_vm.go @@ -31,7 +31,8 @@ func (tvm *ThrottledVM) Call(callInfo *vm.CallInfo, blockInfo *vm.BlockInfo, sta } func (tvm *ThrottledVM) Execute(txns []core.Transaction, declaredClasses []core.Class, paidFeesOnL1 []*felt.Felt, - blockInfo *vm.BlockInfo, state core.StateReader, network *utils.Network, skipChargeFee, skipValidate, errOnRevert, useBlobData bool, + blockInfo *vm.BlockInfo, state core.StateReader, network *utils.Network, skipChargeFee, skipValidate, errOnRevert, + useBlobData bool, ) ([]*felt.Felt, []*felt.Felt, []vm.TransactionTrace, error) { var ret []*felt.Felt var traces []vm.TransactionTrace diff --git a/rpc/trace_test.go b/rpc/trace_test.go index b575531745..b1a4debaf2 100644 --- a/rpc/trace_test.go +++ b/rpc/trace_test.go @@ -245,7 +245,8 @@ func TestTraceTransaction(t *testing.T) { consumedGas := []*felt.Felt{new(felt.Felt).SetUint64(1)} overallFee := []*felt.Felt{new(felt.Felt).SetUint64(1)} mockVM.EXPECT().Execute([]core.Transaction{tx}, []core.Class{declaredClass.Class}, []*felt.Felt{}, - &vm.BlockInfo{Header: header}, gomock.Any(), &utils.Mainnet, false, false, false, true).Return(overallFee, consumedGas, []vm.TransactionTrace{*vmTrace}, nil) + &vm.BlockInfo{Header: header}, gomock.Any(), &utils.Mainnet, false, false, false, true). + Return(overallFee, consumedGas, []vm.TransactionTrace{*vmTrace}, nil) trace, err := handler.TraceTransaction(context.Background(), *hash) require.Nil(t, err) @@ -324,7 +325,8 @@ func TestTraceTransactionV0_6(t *testing.T) { vmTrace := new(vm.TransactionTrace) require.NoError(t, json.Unmarshal(vmTraceJSON, vmTrace)) mockVM.EXPECT().Execute([]core.Transaction{tx}, []core.Class{declaredClass.Class}, []*felt.Felt{}, - &vm.BlockInfo{Header: header}, gomock.Any(), &utils.Mainnet, false, false, false, false).Return(nil, nil, []vm.TransactionTrace{*vmTrace}, nil) + &vm.BlockInfo{Header: header}, gomock.Any(), &utils.Mainnet, false, false, false, false). + Return(nil, nil, []vm.TransactionTrace{*vmTrace}, nil) trace, err := handler.TraceTransactionV0_6(context.Background(), *hash) require.Nil(t, err) @@ -379,7 +381,8 @@ func TestTraceTransactionV0_6(t *testing.T) { vmTrace := new(vm.TransactionTrace) require.NoError(t, json.Unmarshal(vmTraceJSON, vmTrace)) mockVM.EXPECT().Execute([]core.Transaction{tx}, []core.Class{declaredClass.Class}, []*felt.Felt{}, - &vm.BlockInfo{Header: header}, gomock.Any(), &utils.Mainnet, false, false, false, false).Return(nil, nil, []vm.TransactionTrace{*vmTrace}, nil) + &vm.BlockInfo{Header: header}, gomock.Any(), &utils.Mainnet, false, false, false, false). + Return(nil, nil, []vm.TransactionTrace{*vmTrace}, nil) trace, err := handler.TraceTransactionV0_6(context.Background(), *hash) require.Nil(t, err) @@ -470,7 +473,8 @@ func TestTraceBlockTransactions(t *testing.T) { vmTrace := vm.TransactionTrace{} require.NoError(t, json.Unmarshal(vmTraceJSON, &vmTrace)) mockVM.EXPECT().Execute(block.Transactions, []core.Class{declaredClass.Class}, paidL1Fees, &vm.BlockInfo{Header: header}, - gomock.Any(), n, false, false, false, false).Return(nil, []vm.TransactionTrace{vmTrace, vmTrace}, nil) + gomock.Any(), n, false, false, false, false). + Return(nil, []vm.TransactionTrace{vmTrace, vmTrace}, nil) result, err := handler.TraceBlockTransactions(context.Background(), rpc.BlockID{Hash: blockHash}) require.Nil(t, err) @@ -536,7 +540,8 @@ func TestTraceBlockTransactions(t *testing.T) { vmTrace := vm.TransactionTrace{} require.NoError(t, json.Unmarshal(vmTraceJSON, &vmTrace)) mockVM.EXPECT().Execute([]core.Transaction{tx}, []core.Class{declaredClass.Class}, []*felt.Felt{}, &vm.BlockInfo{Header: header}, - gomock.Any(), n, false, false, false, false).Return(nil, []vm.TransactionTrace{vmTrace}, nil) + gomock.Any(), n, false, false, false, false). + Return(nil, []vm.TransactionTrace{vmTrace}, nil) expectedResult := []rpc.TracedBlockTransaction{ { diff --git a/starknet/rust/Cargo.toml b/starknet/rust/Cargo.toml index 10fdc905dc..5a84b57548 100644 --- a/starknet/rust/Cargo.toml +++ b/starknet/rust/Cargo.toml @@ -8,7 +8,7 @@ edition = "2021" [dependencies] serde = "1.0.171" serde_json = { version = "1.0.96", features = ["raw_value"] } -cairo-lang-starknet-classes = "=2.6.0" +cairo-lang-starknet-classes = "=2.7.0-rc.3" [lib] crate-type = ["staticlib"] diff --git a/vm/rust/Cargo.toml b/vm/rust/Cargo.toml index fe134dc3cb..fc79bc297f 100644 --- a/vm/rust/Cargo.toml +++ b/vm/rust/Cargo.toml @@ -8,9 +8,10 @@ edition = "2021" [dependencies] serde = "1.0.171" serde_json = { version = "1.0.96", features = ["raw_value"] } -blockifier = "=0.6.0-rc.2" -starknet_api = "=0.10.0" -cairo-vm = "=0.9.2" +blockifier = "=0.8.0-rc.1" +starknet_api = "=0.13.0-rc.0" +cairo-vm = "=1.0.0-rc5" +starknet-types-core = { version = "0.1.5", features = ["hash", "prime-bigint"] } indexmap = "2.1.0" cached = "0.46.1" once_cell = "1.18.0" diff --git a/vm/rust/src/jsonrpc.rs b/vm/rust/src/jsonrpc.rs index 04984300f0..aa84f58a80 100644 --- a/vm/rust/src/jsonrpc.rs +++ b/vm/rust/src/jsonrpc.rs @@ -1,20 +1,19 @@ use blockifier; -use blockifier::execution::entry_point::CallType; use blockifier::execution::call_info::OrderedL2ToL1Message; -use cairo_vm::vm::runners::builtin_runner::{ - BITWISE_BUILTIN_NAME, EC_OP_BUILTIN_NAME, HASH_BUILTIN_NAME, - POSEIDON_BUILTIN_NAME, RANGE_CHECK_BUILTIN_NAME, SIGNATURE_BUILTIN_NAME, KECCAK_BUILTIN_NAME, - SEGMENT_ARENA_BUILTIN_NAME, -}; -use blockifier::state::cached_state::TransactionalState; +use blockifier::execution::entry_point::CallType; +use blockifier::state::cached_state::CachedState; +use blockifier::state::cached_state::{CommitmentStateDiff, TransactionalState}; use blockifier::state::errors::StateError; -use blockifier::state::state_api::{State, StateReader}; +use blockifier::state::state_api::StateReader; +use cairo_vm::types::builtin_name::BuiltinName; use serde::Serialize; -use starknet_api::core::{ClassHash, ContractAddress, EntryPointSelector, PatriciaKey, EthAddress}; +use starknet_api::core::{ClassHash, ContractAddress, EntryPointSelector, EthAddress, PatriciaKey}; use starknet_api::deprecated_contract_class::EntryPointType; -use starknet_api::hash::StarkFelt; use starknet_api::transaction::{Calldata, EventContent, L2ToL1Payload}; use starknet_api::transaction::{DeclareTransaction, Transaction as StarknetApiTransaction}; +use starknet_types_core::felt::Felt; + +type StarkFelt = Felt; use crate::juno_state_reader::JunoStateReader; @@ -22,7 +21,8 @@ use crate::juno_state_reader::JunoStateReader; #[serde(rename_all = "UPPERCASE")] pub enum TransactionType { // dummy type for implementing Default trait - #[default] Unknown, + #[default] + Unknown, Invoke, Declare, #[serde(rename = "DEPLOY_ACCOUNT")] @@ -104,10 +104,10 @@ type BlockifierTxInfo = blockifier::transaction::objects::TransactionExecutionIn pub fn new_transaction_trace( tx: &StarknetApiTransaction, info: BlockifierTxInfo, - state: &mut TransactionalState, + state: &mut TransactionalState>, ) -> Result { let mut trace = TransactionTrace::default(); - let mut deprecated_declared_class: Option = None; + let mut deprecated_declared_class_hash: Option = None; match tx { StarknetApiTransaction::L1Handler(_) => { trace.function_invocation = info.execute_call_info.map(|v| v.into()); @@ -134,7 +134,7 @@ pub fn new_transaction_trace( trace.validate_invocation = info.validate_call_info.map(|v| v.into()); trace.fee_transfer_invocation = info.fee_transfer_call_info.map(|v| v.into()); trace.r#type = TransactionType::Declare; - deprecated_declared_class = if info.revert_error.is_none() { + deprecated_declared_class_hash = if info.revert_error.is_none() { match declare_txn { DeclareTransaction::V0(_) => Some(declare_txn.class_hash()), DeclareTransaction::V1(_) => Some(declare_txn.class_hash()), @@ -150,7 +150,7 @@ pub fn new_transaction_trace( } }; - trace.state_diff = make_state_diff(state, deprecated_declared_class)?; + trace.state_diff = make_state_diff(state, deprecated_declared_class_hash)?; Ok(trace) } @@ -205,14 +205,38 @@ impl From for ExecutionResources { } else { None }, - range_check_builtin_applications: val.builtin_instance_counter.get(RANGE_CHECK_BUILTIN_NAME).cloned(), - pedersen_builtin_applications: val.builtin_instance_counter.get(HASH_BUILTIN_NAME).cloned(), - poseidon_builtin_applications: val.builtin_instance_counter.get(POSEIDON_BUILTIN_NAME).cloned(), - ec_op_builtin_applications: val.builtin_instance_counter.get(EC_OP_BUILTIN_NAME).cloned(), - ecdsa_builtin_applications: val.builtin_instance_counter.get(SIGNATURE_BUILTIN_NAME).cloned(), - bitwise_builtin_applications: val.builtin_instance_counter.get(BITWISE_BUILTIN_NAME).cloned(), - keccak_builtin_applications: val.builtin_instance_counter.get(KECCAK_BUILTIN_NAME).cloned(), - segment_arena_builtin: val.builtin_instance_counter.get(SEGMENT_ARENA_BUILTIN_NAME).cloned(), + range_check_builtin_applications: val + .builtin_instance_counter + .get(&BuiltinName::range_check) + .cloned(), + pedersen_builtin_applications: val + .builtin_instance_counter + .get(&BuiltinName::pedersen) + .cloned(), + poseidon_builtin_applications: val + .builtin_instance_counter + .get(&BuiltinName::poseidon) + .cloned(), + ec_op_builtin_applications: val + .builtin_instance_counter + .get(&BuiltinName::ec_op) + .cloned(), + ecdsa_builtin_applications: val + .builtin_instance_counter + .get(&BuiltinName::ecdsa) + .cloned(), + bitwise_builtin_applications: val + .builtin_instance_counter + .get(&BuiltinName::bitwise) + .cloned(), + keccak_builtin_applications: val + .builtin_instance_counter + .get(&BuiltinName::keccak) + .cloned(), + segment_arena_builtin: val + .builtin_instance_counter + .get(&BuiltinName::segment_arena) + .cloned(), } } } @@ -298,33 +322,35 @@ impl From for OrderedMessage { pub struct Retdata(pub Vec); fn make_state_diff( - state: &mut TransactionalState, - deprecated_declared_class: Option, + state: &mut TransactionalState>, + deprecated_declared_class_hash: Option, ) -> Result { - let diff = state.to_state_diff(); + let diff: CommitmentStateDiff = state.to_state_diff()?.into(); let mut deployed_contracts = Vec::new(); let mut replaced_classes = Vec::new(); - for pair in diff.address_to_class_hash { - let existing_class_hash = state.state.get_class_hash_at(pair.0)?; + for (addr, class_hash) in diff.address_to_class_hash { + let existing_class_hash = state.state.get_class_hash_at(addr)?; + let addr: StarkFelt = addr.into(); + if existing_class_hash == ClassHash::default() { #[rustfmt::skip] deployed_contracts.push(DeployedContract { - address: *pair.0.0.key(), - class_hash: pair.1.0, + address: addr, + class_hash: class_hash.0, }); } else { #[rustfmt::skip] replaced_classes.push(ReplacedClass { - contract_address: *pair.0.0.key(), - class_hash: pair.1.0, + contract_address: addr, + class_hash: class_hash.0, }); } } - let mut deprecated_declared_classes = Vec::default(); - if let Some(v) = deprecated_declared_class { - deprecated_declared_classes.push(v.0) + let mut deprecated_declared_class_hashes = Vec::default(); + if let Some(v) = deprecated_declared_class_hash { + deprecated_declared_class_hashes.push(v.0) } Ok(StateDiff { deployed_contracts, @@ -341,7 +367,7 @@ fn make_state_diff( class_hash: v.0.0, compiled_class_hash: v.1.0, }).collect(), - deprecated_declared_classes, + deprecated_declared_classes: deprecated_declared_class_hashes, #[rustfmt::skip] nonces: diff.address_to_nonce.into_iter().map(| v | Nonce { contract_address: *v.0.0.key(), diff --git a/vm/rust/src/juno_state_reader.rs b/vm/rust/src/juno_state_reader.rs index af662ea008..231fcfc36f 100644 --- a/vm/rust/src/juno_state_reader.rs +++ b/vm/rust/src/juno_state_reader.rs @@ -6,16 +6,23 @@ use std::{ use blockifier::execution::contract_class::ContractClass; use blockifier::state::errors::StateError; +use blockifier::state::state_api::UpdatableState; use blockifier::{ - execution::contract_class::{ClassInfo as BlockifierClassInfo, ContractClassV0, ContractClassV1}, + execution::contract_class::{ + ClassInfo as BlockifierClassInfo, ContractClassV0, ContractClassV1, + }, + state::cached_state::{ContractClassMapping, StateMaps}, state::state_api::{StateReader, StateResult}, }; use cached::{Cached, SizedCache}; use once_cell::sync::Lazy; use serde::Deserialize; use starknet_api::core::{ClassHash, CompiledClassHash, ContractAddress, Nonce}; -use starknet_api::hash::StarkFelt; use starknet_api::state::StorageKey; +use starknet_types_core::felt::Felt; +use std::collections::{HashMap, HashSet}; + +type StarkFelt = Felt; extern "C" { fn JunoFree(ptr: *const c_void); @@ -58,7 +65,7 @@ impl JunoStateReader { impl StateReader for JunoStateReader { fn get_storage_at( - &mut self, + &self, contract_address: ContractAddress, key: StorageKey, ) -> StateResult { @@ -82,7 +89,7 @@ impl StateReader for JunoStateReader { /// Returns the nonce of the given contract instance. /// Default: 0 for an uninitialized contract address. - fn get_nonce_at(&mut self, contract_address: ContractAddress) -> StateResult { + fn get_nonce_at(&self, contract_address: ContractAddress) -> StateResult { let addr = felt_to_byte_array(contract_address.0.key()); let ptr = unsafe { JunoStateGetNonceAt(self.handle, addr.as_ptr()) }; if ptr.is_null() { @@ -99,7 +106,7 @@ impl StateReader for JunoStateReader { /// Returns the class hash of the contract class at the given contract instance. /// Default: 0 (uninitialized class hash) for an uninitialized contract address. - fn get_class_hash_at(&mut self, contract_address: ContractAddress) -> StateResult { + fn get_class_hash_at(&self, contract_address: ContractAddress) -> StateResult { let addr = felt_to_byte_array(contract_address.0.key()); let ptr = unsafe { JunoStateGetClassHashAt(self.handle, addr.as_ptr()) }; if ptr.is_null() { @@ -116,10 +123,7 @@ impl StateReader for JunoStateReader { } /// Returns the contract class of the given class hash. - fn get_compiled_contract_class( - &mut self, - class_hash: ClassHash, - ) -> StateResult { + fn get_compiled_contract_class(&self, class_hash: ClassHash) -> StateResult { if let Some(cached_class) = CLASS_CACHE.lock().unwrap().cache_get(&class_hash) { // skip the cache if it comes from a height higher than ours. Class might be undefined on the height // that we are reading from right now. @@ -157,7 +161,7 @@ impl StateReader for JunoStateReader { unsafe { JunoFree(ptr as *const c_void) }; - class_info_res.map(| ci | ci.contract_class()).map_err(| err | { + class_info_res.map(|ci| ci.contract_class()).map_err(|err| { StateError::StateReadError(format!( "parsing JSON string for class hash {}: {}", class_hash.0, err @@ -167,22 +171,31 @@ impl StateReader for JunoStateReader { } /// Returns the compiled class hash of the given class hash. - fn get_compiled_class_hash( + fn get_compiled_class_hash(&self, _class_hash: ClassHash) -> StateResult { + unimplemented!() + } +} + +impl UpdatableState for JunoStateReader { + fn apply_writes( &mut self, - _class_hash: ClassHash, - ) -> StateResult { + _writes: &StateMaps, + _class_hash_to_class: &ContractClassMapping, + _visited_pcs: &HashMap>, + ) { unimplemented!() } } pub fn felt_to_byte_array(felt: &StarkFelt) -> [u8; 32] { - felt.bytes().try_into().expect("StarkFelt not [u8; 32]") + felt.to_bytes_be() + .try_into() + .expect("StarkFelt not [u8; 32]") } pub fn ptr_to_felt(bytes: *const c_uchar) -> StarkFelt { let slice = unsafe { slice::from_raw_parts(bytes, 32) }; - StarkFelt::new(slice.try_into().expect("Juno felt not [u8; 32]")) - .expect("cannot new Starkfelt from Juno bytes") + StarkFelt::from_bytes_be_slice(slice) } #[derive(Deserialize)] @@ -193,15 +206,22 @@ pub struct ClassInfo { } pub fn class_info_from_json_str(raw_json: &str) -> Result { - let class_info: ClassInfo = serde_json::from_str(raw_json).map_err(|err| format!("failed parsing class info: {:?}", err))?; - let class_def = class_info.contract_class.to_string(); - - let class: ContractClass = if let Ok(class) = ContractClassV0::try_from_json_string(class_def.as_str()) { - class.into() - } else if let Ok(class) = ContractClassV1::try_from_json_string(class_def.as_str()) { - class.into() - } else { - return Err("not a valid contract class".to_string()) - }; - return Ok(BlockifierClassInfo::new(&class.into(), class_info.sierra_program_length, class_info.abi_length).unwrap()); + let class_info: ClassInfo = serde_json::from_str(raw_json) + .map_err(|err| format!("failed parsing class info: {:?}", err))?; + let class_def = class_info.contract_class.to_string(); + + let class: ContractClass = + if let Ok(class) = ContractClassV0::try_from_json_string(class_def.as_str()) { + class.into() + } else if let Ok(class) = ContractClassV1::try_from_json_string(class_def.as_str()) { + class.into() + } else { + return Err("not a valid contract class".to_string()); + }; + return Ok(BlockifierClassInfo::new( + &class.into(), + class_info.sierra_program_length, + class_info.abi_length, + ) + .unwrap()); } diff --git a/vm/rust/src/lib.rs b/vm/rust/src/lib.rs index 2a7207c9f4..440de3e3b8 100644 --- a/vm/rust/src/lib.rs +++ b/vm/rust/src/lib.rs @@ -6,36 +6,55 @@ extern crate lazy_static; use crate::juno_state_reader::{ptr_to_felt, JunoStateReader}; use std::{ - collections::HashMap, ffi::{c_char, c_longlong, c_uchar, c_ulonglong, c_void, CStr, CString}, num::NonZeroU128, slice, sync::Arc + collections::HashMap, + ffi::{c_char, c_longlong, c_uchar, c_ulonglong, c_void, CStr, CString}, + num::NonZeroU128, + slice, + sync::Arc, }; +use blockifier::abi::constants::STORED_BLOCK_HASH_BUFFER; +use blockifier::blockifier::block::{ + pre_process_block, BlockInfo as BlockifierBlockInfo, BlockNumberHashPair, GasPrices, +}; +use blockifier::bouncer::BouncerConfig; +use blockifier::fee::{fee_utils, gas_usage}; +use blockifier::transaction::objects::GasVector; use blockifier::{ - block::{pre_process_block, BlockInfo as BlockifierBlockInfo, BlockNumberHashPair, GasPrices}, context::{BlockContext, ChainInfo, FeeTokenAddresses, TransactionContext}, execution::{ + context::{BlockContext, ChainInfo, FeeTokenAddresses, TransactionContext}, + execution::{ contract_class::ClassInfo, entry_point::{CallEntryPoint, CallType, EntryPointExecutionContext}, - }, fee::fee_utils::calculate_tx_fee, state::{cached_state::{CachedState, GlobalContractCache}, state_api::State}, transaction::{ + }, + state::{cached_state::CachedState, state_api::State}, + transaction::{ errors::TransactionExecutionError::{ - ContractConstructorExecutionFailed, - ExecutionError, - ValidateTransactionError, - }, objects::{DeprecatedTransactionInfo, HasRelatedFeeType, TransactionInfo}, transaction_execution::Transaction, transactions::ExecutableTransaction - }, versioned_constants::VersionedConstants + ContractConstructorExecutionFailed, ExecutionError, ValidateTransactionError, + }, + objects::{DeprecatedTransactionInfo, HasRelatedFeeType, TransactionInfo}, + transaction_execution::Transaction, + transactions::ExecutableTransaction, + }, + versioned_constants::VersionedConstants, }; use cairo_vm::vm::runners::cairo_runner::ExecutionResources; use juno_state_reader::{class_info_from_json_str, felt_to_byte_array}; use serde::Deserialize; -use starknet_api::{block::BlockHash, core::PatriciaKey, transaction::{Calldata, Transaction as StarknetApiTransaction, TransactionHash}}; use starknet_api::{ + block::BlockHash, + core::PatriciaKey, deprecated_contract_class::EntryPointType, - hash::StarkFelt, - transaction::Fee, + transaction::{Calldata, Fee, Transaction as StarknetApiTransaction, TransactionHash}, }; use starknet_api::{ core::{ChainId, ClassHash, ContractAddress, EntryPointSelector}, hash::StarkHash, }; +use starknet_types_core::felt::Felt; use std::str::FromStr; +type StarkFelt = Felt; + extern "C" { fn JunoReportError(reader_handle: usize, txnIndex: c_longlong, err: *const c_char); fn JunoAppendTrace(reader_handle: usize, json_trace: *const c_void, len: usize); @@ -51,7 +70,7 @@ pub struct CallInfo { pub class_hash: [c_uchar; 32], pub entry_point_selector: [c_uchar; 32], pub calldata: *const *const c_uchar, - pub len_calldata: usize + pub len_calldata: usize, } #[repr(C)] @@ -76,23 +95,25 @@ pub extern "C" fn cairoVMCall( reader_handle: usize, chain_id: *const c_char, max_steps: c_ulonglong, + concurrency_mode: c_uchar, ) { let block_info = unsafe { *block_info_ptr }; let call_info = unsafe { *call_info_ptr }; let reader = JunoStateReader::new(reader_handle, block_info.block_number); - let contract_addr_felt = StarkFelt::new(call_info.contract_address).unwrap(); + let contract_addr_felt = StarkFelt::from_bytes_be(&call_info.contract_address); let class_hash = if call_info.class_hash == [0; 32] { None } else { - Some(ClassHash(StarkFelt::new(call_info.class_hash).unwrap())) + Some(ClassHash(StarkFelt::from_bytes_be(&call_info.class_hash))) }; - let entry_point_selector_felt = StarkFelt::new(call_info.entry_point_selector).unwrap(); + let entry_point_selector_felt = StarkFelt::from_bytes_be(&call_info.entry_point_selector); let chain_id_str = unsafe { CStr::from_ptr(chain_id) }.to_str().unwrap(); let mut calldata_vec: Vec = Vec::with_capacity(call_info.len_calldata); if call_info.len_calldata > 0 { - let calldata_slice = unsafe { slice::from_raw_parts(call_info.calldata, call_info.len_calldata) }; + let calldata_slice = + unsafe { slice::from_raw_parts(call_info.calldata, call_info.len_calldata) }; for ptr in calldata_slice { let data = ptr_to_felt(ptr.cast()); calldata_vec.push(data); @@ -108,14 +129,21 @@ pub extern "C" fn cairoVMCall( class_hash: class_hash, code_address: None, caller_address: ContractAddress::default(), - initial_gas: get_versioned_constants(block_info.version).gas_cost("initial_gas_cost"), + initial_gas: get_versioned_constants(block_info.version).tx_initial_gas(), }; - let mut state = CachedState::new(reader, GlobalContractCache::new(1)); + let concurrency_mode = concurrency_mode == 1; + let mut state = CachedState::new(reader); let mut resources = ExecutionResources::default(); let context = EntryPointExecutionContext::new_invoke( Arc::new(TransactionContext { - block_context: build_block_context(&mut state, &block_info, chain_id_str, Some(max_steps)), + block_context: build_block_context( + &mut state, + &block_info, + chain_id_str, + Some(max_steps), + concurrency_mode, + ), tx_info: TransactionInfo::Deprecated(DeprecatedTransactionInfo::default()), }), false, @@ -153,7 +181,8 @@ pub extern "C" fn cairoVMExecute( chain_id: *const c_char, skip_charge_fee: c_uchar, skip_validate: c_uchar, - err_on_revert: c_uchar + err_on_revert: c_uchar, + concurrency_mode: c_uchar, ) { let block_info = unsafe { *block_info_ptr }; let reader = JunoStateReader::new(reader_handle, block_info.block_number); @@ -187,10 +216,17 @@ pub extern "C" fn cairoVMExecute( } }; - let mut state = CachedState::new(reader, GlobalContractCache::new(1)); + let mut state = CachedState::new(reader); let txns_and_query_bits = txns_and_query_bits.unwrap(); let mut classes = classes.unwrap(); - let block_context: BlockContext = build_block_context(&mut state, &block_info, chain_id_str, None); + let concurrency_mode = concurrency_mode == 1; + let block_context: BlockContext = build_block_context( + &mut state, + &block_info, + chain_id_str, + None, + concurrency_mode, + ); let charge_fee = skip_charge_fee == 0; let validate = skip_validate == 0; @@ -240,13 +276,17 @@ pub extern "C" fn cairoVMExecute( let mut txn_state = CachedState::create_transactional(&mut state); let fee_type; + let minimal_l1_gas_amount_vector: Option; let res = match txn.unwrap() { Transaction::AccountTransaction(t) => { fee_type = t.fee_type(); + minimal_l1_gas_amount_vector = + Some(gas_usage::estimate_minimal_gas_vector(&block_context, &t).unwrap()); t.execute(&mut txn_state, &block_context, charge_fee, validate) } Transaction::L1HandlerTransaction(t) => { fee_type = t.fee_type(); + minimal_l1_gas_amount_vector = None; t.execute(&mut txn_state, &block_context, charge_fee, validate) } }; @@ -254,20 +294,20 @@ pub extern "C" fn cairoVMExecute( match res { Err(error) => { let err_string = match &error { - ContractConstructorExecutionFailed(e) - | ExecutionError(e) - | ValidateTransactionError(e) => format!("{error} {e}"), - other => other.to_string() + ContractConstructorExecutionFailed(e) => format!("{error} {e}"), + ExecutionError { error: e, .. } | ValidateTransactionError { error: e, .. } => { + format!("{error} {e}") + } + other => other.to_string(), }; report_error( reader_handle, format!( "failed txn {} reason: {}", - txn_and_query_bit.txn_hash, - err_string, + txn_and_query_bit.txn_hash, err_string, ) .as_str(), - txn_index as i64 + txn_index as i64, ); return; } @@ -275,20 +315,39 @@ pub extern "C" fn cairoVMExecute( if t.is_reverted() && err_on_revert != 0 { report_error( reader_handle, - format!("reverted: {}", t.revert_error.unwrap()) - .as_str(), - txn_index as i64 + format!("reverted: {}", t.revert_error.unwrap()).as_str(), + txn_index as i64, ); return; } // we are estimating fee, override actual fee calculation - if t.actual_fee.0 == 0 { - t.actual_fee = calculate_tx_fee(&t.actual_resources, &block_context, &fee_type).unwrap(); + if t.transaction_receipt.fee.0 == 0 { + let minimal_l1_gas_amount_vector = + minimal_l1_gas_amount_vector.unwrap_or_default(); + let gas_consumed = t + .transaction_receipt + .gas + .l1_gas + .max(minimal_l1_gas_amount_vector.l1_gas); + let data_gas_consumed = t + .transaction_receipt + .gas + .l1_data_gas + .max(minimal_l1_gas_amount_vector.l1_data_gas); + + t.transaction_receipt.fee = fee_utils::get_fee_by_gas_vector( + block_context.block_info(), + GasVector { + l1_data_gas: data_gas_consumed, + l1_gas: gas_consumed, + }, + &fee_type, + ) } - let actual_fee = t.actual_fee.0.into(); - let data_gas_consumed = t.da_gas.l1_data_gas.into(); + let actual_fee = t.transaction_receipt.fee.0.into(); + let data_gas_consumed = t.transaction_receipt.da_gas.l1_data_gas.into(); let trace = jsonrpc::new_transaction_trace(&txn_and_query_bit.txn, t, &mut txn_state); @@ -300,14 +359,17 @@ pub extern "C" fn cairoVMExecute( trace.err().unwrap() ) .as_str(), - txn_index as i64 + txn_index as i64, ); return; } unsafe { JunoAppendActualFee(reader_handle, felt_to_byte_array(&actual_fee).as_ptr()); - JunoAppendDataGasConsumed(reader_handle, felt_to_byte_array(&data_gas_consumed).as_ptr()); + JunoAppendDataGasConsumed( + reader_handle, + felt_to_byte_array(&data_gas_consumed).as_ptr(), + ); } append_trace(reader_handle, trace.as_ref().unwrap(), &mut trace_buffer); } @@ -317,7 +379,8 @@ pub extern "C" fn cairoVMExecute( } fn felt_to_u128(felt: StarkFelt) -> u128 { - let bytes = felt.bytes(); + // todo find Into trait or similar + let bytes = felt.to_bytes_be(); let mut arr = [0u8; 16]; arr.copy_from_slice(&bytes[16..32]); @@ -380,19 +443,25 @@ fn build_block_context( block_info: &BlockInfo, chain_id_str: &str, max_steps: Option, + _concurrency_mode: bool, ) -> BlockContext { - let sequencer_addr = StarkFelt::new(block_info.sequencer_address).unwrap(); - let gas_price_wei_felt = StarkFelt::new(block_info.gas_price_wei).unwrap(); - let gas_price_fri_felt = StarkFelt::new(block_info.gas_price_fri).unwrap(); - let data_gas_price_wei_felt = StarkFelt::new(block_info.data_gas_price_wei).unwrap(); - let data_gas_price_fri_felt = StarkFelt::new(block_info.data_gas_price_fri).unwrap(); + let sequencer_addr = StarkFelt::from_bytes_be(&block_info.sequencer_address); + let gas_price_wei_felt = StarkFelt::from_bytes_be(&block_info.gas_price_wei); + let gas_price_fri_felt = StarkFelt::from_bytes_be(&block_info.gas_price_fri); + let data_gas_price_wei_felt = StarkFelt::from_bytes_be(&block_info.data_gas_price_wei); + let data_gas_price_fri_felt = StarkFelt::from_bytes_be(&block_info.data_gas_price_fri); let default_gas_price = NonZeroU128::new(1).unwrap(); let mut old_block_number_and_hash: Option = None; - if block_info.block_number >= 10 { - old_block_number_and_hash = Some(BlockNumberHashPair{ - number: starknet_api::block::BlockNumber(block_info.block_number - 10), - hash: BlockHash(StarkFelt::new(block_info.block_hash_to_be_revealed).unwrap()), + // STORED_BLOCK_HASH_BUFFER const is 10 for now + if block_info.block_number >= STORED_BLOCK_HASH_BUFFER { + old_block_number_and_hash = Some(BlockNumberHashPair { + number: starknet_api::block::BlockNumber( + block_info.block_number - STORED_BLOCK_HASH_BUFFER, + ), + hash: BlockHash(StarkFelt::from_bytes_be( + &block_info.block_hash_to_be_revealed, + )), }) } let mut constants = get_versioned_constants(block_info.version); @@ -400,35 +469,62 @@ fn build_block_context( constants.invoke_tx_max_n_steps = max_steps as u32; } - pre_process_block(state, old_block_number_and_hash, BlockifierBlockInfo{ + let block_info = BlockifierBlockInfo { block_number: starknet_api::block::BlockNumber(block_info.block_number), block_timestamp: starknet_api::block::BlockTimestamp(block_info.block_timestamp), sequencer_address: ContractAddress(PatriciaKey::try_from(sequencer_addr).unwrap()), gas_prices: GasPrices { - eth_l1_gas_price: NonZeroU128::new(felt_to_u128(gas_price_wei_felt)).unwrap_or(default_gas_price), - strk_l1_gas_price: NonZeroU128::new(felt_to_u128(gas_price_fri_felt)).unwrap_or(default_gas_price), - eth_l1_data_gas_price: NonZeroU128::new(felt_to_u128(data_gas_price_wei_felt)).unwrap_or(default_gas_price), - strk_l1_data_gas_price: NonZeroU128::new(felt_to_u128(data_gas_price_fri_felt)).unwrap_or(default_gas_price), + eth_l1_gas_price: NonZeroU128::new(felt_to_u128(gas_price_wei_felt)) + .unwrap_or(default_gas_price), + strk_l1_gas_price: NonZeroU128::new(felt_to_u128(gas_price_fri_felt)) + .unwrap_or(default_gas_price), + eth_l1_data_gas_price: NonZeroU128::new(felt_to_u128(data_gas_price_wei_felt)) + .unwrap_or(default_gas_price), + strk_l1_data_gas_price: NonZeroU128::new(felt_to_u128(data_gas_price_fri_felt)) + .unwrap_or(default_gas_price), }, use_kzg_da: block_info.use_blob_data == 1, - }, ChainInfo{ - chain_id: ChainId(chain_id_str.to_string()), + }; + let chain_info = ChainInfo { + chain_id: ChainId::from(chain_id_str.to_string()), fee_token_addresses: FeeTokenAddresses { // both addresses are the same for all networks - eth_fee_token_address: ContractAddress::try_from(StarkHash::try_from("0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7").unwrap()).unwrap(), - strk_fee_token_address: ContractAddress::try_from(StarkHash::try_from("0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d").unwrap()).unwrap(), + eth_fee_token_address: ContractAddress::try_from( + StarkHash::from_hex( + "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7", + ) + .unwrap(), + ) + .unwrap(), + strk_fee_token_address: ContractAddress::try_from( + StarkHash::from_hex( + "0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d", + ) + .unwrap(), + ) + .unwrap(), }, - }, constants).unwrap() -} - - + }; + pre_process_block(state, old_block_number_and_hash, block_info.block_number).unwrap(); + BlockContext::new(block_info, chain_info, constants, BouncerConfig::max()) +} lazy_static! { static ref CONSTANTS: HashMap = { let mut m = HashMap::new(); - m.insert("0.13.0".to_string(), serde_json::from_slice(include_bytes!("../versioned_constants_13_0.json")).unwrap()); - m.insert("0.13.1".to_string(), serde_json::from_slice(include_bytes!("../versioned_constants_13_1.json")).unwrap()); + m.insert( + "0.13.0".to_string(), + serde_json::from_slice(include_bytes!("../versioned_constants_13_0.json")).unwrap(), + ); + m.insert( + "0.13.1".to_string(), + serde_json::from_slice(include_bytes!("../versioned_constants_13_1.json")).unwrap(), + ); + m.insert( + "0.13.1.1".to_string(), + serde_json::from_slice(include_bytes!("../versioned_constants_13_1_1.json")).unwrap(), + ); m }; } @@ -436,20 +532,22 @@ lazy_static! { #[allow(static_mut_refs)] fn get_versioned_constants(version: *const c_char) -> VersionedConstants { let version_str = unsafe { CStr::from_ptr(version) }.to_str().unwrap(); - let version = StarknetVersion::from_str(&version_str).unwrap_or(StarknetVersion::from_str(&"0.0.0").unwrap()); + let version = StarknetVersion::from_str(&version_str) + .unwrap_or(StarknetVersion::from_str(&"0.0.0").unwrap()); - if let Some(constants) = unsafe{ &CUSTOM_VERSIONED_CONSTANTS } { + if let Some(constants) = unsafe { &CUSTOM_VERSIONED_CONSTANTS } { constants.clone() } else if version < StarknetVersion::from_str(&"0.13.1").unwrap() { CONSTANTS.get(&"0.13.0".to_string()).unwrap().to_owned() } else if version < StarknetVersion::from_str(&"0.13.1.1").unwrap() { CONSTANTS.get(&"0.13.1".to_string()).unwrap().to_owned() + } else if version < StarknetVersion::from_str(&"0.13.2").unwrap() { + CONSTANTS.get(&"0.13.1.1".to_string()).unwrap().to_owned() } else { VersionedConstants::latest_constants().to_owned() } } - #[derive(Default, PartialEq, Eq, PartialOrd, Ord)] pub struct StarknetVersion(u8, u8, u8, u8); @@ -490,14 +588,18 @@ pub extern "C" fn setVersionedConstants(json_bytes: *const c_char) -> *const c_c let json_str = unsafe { match CStr::from_ptr(json_bytes).to_str() { Ok(s) => s, - Err(_) => return CString::new("Failed to convert JSON bytes to string").unwrap().into_raw(), + Err(_) => { + return CString::new("Failed to convert JSON bytes to string") + .unwrap() + .into_raw() + } } }; match serde_json::from_str(json_str) { Ok(parsed) => unsafe { CUSTOM_VERSIONED_CONSTANTS = Some(parsed); - CString::new("").unwrap().into_raw() // No error, return an empty string + CString::new("").unwrap().into_raw() // No error, return an empty string }, Err(_) => CString::new("Failed to parse JSON").unwrap().into_raw(), } @@ -513,4 +615,4 @@ pub extern "C" fn freeString(s: *mut c_char) { drop(CString::from_raw(s)); } } -} \ No newline at end of file +} diff --git a/vm/rust/versioned_constants_13_0.json b/vm/rust/versioned_constants_13_0.json index 28bec8d829..1531f6fc13 100644 --- a/vm/rust/versioned_constants_13_0.json +++ b/vm/rust/versioned_constants_13_0.json @@ -137,6 +137,11 @@ "syscall_base_gas_cost": 1 }, "keccak_round_cost_gas_cost": 180000, + "sha256_process_block_gas_cost": { + "step_gas_cost": 0, + "range_check_gas_cost": 0, + "syscall_base_gas_cost": 0 + }, "error_block_number_out_of_range": "Block number out of range", "error_out_of_gas": "Out of gas", "error_invalid_input_len": "Invalid input length", @@ -333,6 +338,11 @@ "n_memory_holes": 0, "n_steps": 84 }, + "Sha256ProcessBlock": { + "builtin_instance_counter": {}, + "n_memory_holes": 0, + "n_steps": 0 + }, "StorageRead": { "builtin_instance_counter": {}, "n_memory_holes": 0, @@ -346,49 +356,189 @@ }, "execute_txs_inner": { "Declare": { - "builtin_instance_counter": { - "pedersen_builtin": 15, - "range_check_builtin": 63 + "resources": { + "constant": { + "builtin_instance_counter": { + "pedersen_builtin": 15, + "range_check_builtin": 63 + }, + "n_memory_holes": 0, + "n_steps": 2711 + }, + "calldata_factor": { + "n_steps": 0, + "builtin_instance_counter": {}, + "n_memory_holes": 0 + } }, - "n_memory_holes": 0, - "n_steps": 2711 + "deprecated_resources": { + "constant": { + "builtin_instance_counter": { + "pedersen_builtin": 15, + "range_check_builtin": 63 + }, + "n_memory_holes": 0, + "n_steps": 2711 + }, + "calldata_factor": { + "n_steps": 0, + "builtin_instance_counter": {}, + "n_memory_holes": 0 + } + } }, "DeployAccount": { - "builtin_instance_counter": { - "pedersen_builtin": 23, - "range_check_builtin": 83 + "resources": { + "constant": { + "builtin_instance_counter": { + "pedersen_builtin": 23, + "range_check_builtin": 83 + }, + "n_memory_holes": 0, + "n_steps": 3628 + }, + "calldata_factor": { + "n_steps": 0, + "builtin_instance_counter": {}, + "n_memory_holes": 0 + } }, - "n_memory_holes": 0, - "n_steps": 3628 + "deprecated_resources": { + "constant": { + "builtin_instance_counter": { + "pedersen_builtin": 23, + "range_check_builtin": 83 + }, + "n_memory_holes": 0, + "n_steps": 3628 + }, + "calldata_factor": { + "n_steps": 0, + "builtin_instance_counter": {}, + "n_memory_holes": 0 + } + } }, "InvokeFunction": { - "builtin_instance_counter": { - "pedersen_builtin": 16, - "range_check_builtin": 80 + "resources": { + "constant": { + "builtin_instance_counter": { + "pedersen_builtin": 16, + "range_check_builtin": 80 + }, + "n_memory_holes": 0, + "n_steps": 3382 + }, + "calldata_factor": { + "n_steps": 0, + "builtin_instance_counter": {}, + "n_memory_holes": 0 + } }, - "n_memory_holes": 0, - "n_steps": 3382 + "deprecated_resources": { + "constant": { + "builtin_instance_counter": { + "pedersen_builtin": 16, + "range_check_builtin": 80 + }, + "n_memory_holes": 0, + "n_steps": 3382 + }, + "calldata_factor": { + "n_steps": 0, + "builtin_instance_counter": {}, + "n_memory_holes": 0 + } + } }, "L1Handler": { - "builtin_instance_counter": { - "pedersen_builtin": 11, - "range_check_builtin": 17 + "resources": { + "constant": { + "builtin_instance_counter": { + "pedersen_builtin": 11, + "range_check_builtin": 17 + }, + "n_memory_holes": 0, + "n_steps": 1069 + }, + "calldata_factor": { + "n_steps": 0, + "builtin_instance_counter": {}, + "n_memory_holes": 0 + } }, - "n_memory_holes": 0, - "n_steps": 1069 + "deprecated_resources": { + "constant": { + "builtin_instance_counter": { + "pedersen_builtin": 11, + "range_check_builtin": 17 + }, + "n_memory_holes": 0, + "n_steps": 1069 + }, + "calldata_factor": { + "n_steps": 0, + "builtin_instance_counter": {}, + "n_memory_holes": 0 + } + } } + }, + "compute_os_kzg_commitment_info": { + "n_steps": 0, + "builtin_instance_counter": {}, + "n_memory_holes": 0 } }, "validate_max_n_steps": 1000000, "vm_resource_fee_cost": { - "bitwise_builtin": 0.32, - "ec_op_builtin": 5.12, - "ecdsa_builtin": 10.24, - "keccak_builtin": 10.24, - "n_steps": 0.005, - "output_builtin": 0, - "pedersen_builtin": 0.16, - "poseidon_builtin": 0.16, - "range_check_builtin": 0.08 + "add_mod_builtin": [ + 0, + 1 + ], + "bitwise_builtin": [ + 32, + 100 + ], + "ec_op_builtin": [ + 512, + 100 + ], + "ecdsa_builtin": [ + 1024, + 100 + ], + "keccak_builtin": [ + 1024, + 100 + ], + "mul_mod_builtin": [ + 0, + 1 + ], + "n_steps": [ + 5, + 1000 + ], + "output_builtin": [ + 0, + 1 + ], + "pedersen_builtin": [ + 16, + 100 + ], + "poseidon_builtin": [ + 16, + 100 + ], + "range_check_builtin": [ + 8, + 100 + ], + "range_check96_builtin": [ + 0, + 1 + ] } } diff --git a/vm/rust/versioned_constants_13_1.json b/vm/rust/versioned_constants_13_1.json index e66c7fb8d5..4e28f7b711 100644 --- a/vm/rust/versioned_constants_13_1.json +++ b/vm/rust/versioned_constants_13_1.json @@ -10,9 +10,18 @@ }, "invoke_tx_max_n_steps": 4000000, "l2_resource_gas_costs": { - "milligas_per_data_felt": 128, - "event_key_factor": 2, - "milligas_per_code_byte": 875 + "gas_per_data_felt": [ + 128, + 1000 + ], + "event_key_factor": [ + 2, + 1 + ], + "gas_per_code_byte": [ + 875, + 1000 + ] }, "max_recursion_depth": 50, "os_constants": { @@ -149,6 +158,11 @@ "syscall_base_gas_cost": 1 }, "keccak_round_cost_gas_cost": 180000, + "sha256_process_block_gas_cost": { + "step_gas_cost": 0, + "range_check_gas_cost": 0, + "syscall_base_gas_cost": 0 + }, "error_block_number_out_of_range": "Block number out of range", "error_out_of_gas": "Out of gas", "error_invalid_input_len": "Invalid input length", @@ -363,6 +377,11 @@ }, "n_memory_holes": 0 }, + "Sha256ProcessBlock": { + "builtin_instance_counter": {}, + "n_memory_holes": 0, + "n_steps": 0 + }, "StorageRead": { "n_steps": 87, "builtin_instance_counter": { @@ -380,83 +399,201 @@ }, "execute_txs_inner": { "Declare": { - "constant": { - "n_steps": 2839, - "builtin_instance_counter": { - "pedersen_builtin": 16, - "range_check_builtin": 63 + "resources": { + "constant": { + "n_steps": 2839, + "builtin_instance_counter": { + "pedersen_builtin": 16, + "range_check_builtin": 63 + }, + "n_memory_holes": 0 }, - "n_memory_holes": 0 + "calldata_factor": { + "n_steps": 0, + "builtin_instance_counter": {}, + "n_memory_holes": 0 + } }, - "calldata_factor": { - "n_steps": 0, - "builtin_instance_counter": {}, - "n_memory_holes": 0 + "deprecated_resources": { + "constant": { + "n_steps": 2839, + "builtin_instance_counter": { + "pedersen_builtin": 16, + "range_check_builtin": 63 + }, + "n_memory_holes": 0 + }, + "calldata_factor": { + "n_steps": 0, + "builtin_instance_counter": {}, + "n_memory_holes": 0 + } } }, "DeployAccount": { - "constant": { - "n_steps": 3792, - "builtin_instance_counter": { - "pedersen_builtin": 23, - "range_check_builtin": 83 + "resources": { + "constant": { + "n_steps": 3792, + "builtin_instance_counter": { + "pedersen_builtin": 23, + "range_check_builtin": 83 + }, + "n_memory_holes": 0 }, - "n_memory_holes": 0 + "calldata_factor": { + "n_steps": 21, + "builtin_instance_counter": { + "pedersen_builtin": 2 + }, + "n_memory_holes": 0 + } }, - "calldata_factor": { - "n_steps": 21, - "builtin_instance_counter": { - "pedersen_builtin": 2 + "deprecated_resources": { + "constant": { + "n_steps": 3792, + "builtin_instance_counter": { + "pedersen_builtin": 23, + "range_check_builtin": 83 + }, + "n_memory_holes": 0 }, - "n_memory_holes": 0 + "calldata_factor": { + "n_steps": 21, + "builtin_instance_counter": { + "pedersen_builtin": 2 + }, + "n_memory_holes": 0 + } } }, "InvokeFunction": { - "constant": { - "n_steps": 3546, - "builtin_instance_counter": { - "pedersen_builtin": 14, - "range_check_builtin": 80 + "resources": { + "constant": { + "n_steps": 3546, + "builtin_instance_counter": { + "pedersen_builtin": 14, + "range_check_builtin": 80 + }, + "n_memory_holes": 0 }, - "n_memory_holes": 0 + "calldata_factor": { + "n_steps": 8, + "builtin_instance_counter": { + "pedersen_builtin": 1 + }, + "n_memory_holes": 0 + } }, - "calldata_factor": { - "n_steps": 8, - "builtin_instance_counter": { - "pedersen_builtin": 1 + "deprecated_resources": { + "constant": { + "n_steps": 3546, + "builtin_instance_counter": { + "pedersen_builtin": 14, + "range_check_builtin": 80 + }, + "n_memory_holes": 0 }, - "n_memory_holes": 0 + "calldata_factor": { + "n_steps": 8, + "builtin_instance_counter": { + "pedersen_builtin": 1 + }, + "n_memory_holes": 0 + } } }, "L1Handler": { - "constant": { - "n_steps": 1146, - "builtin_instance_counter": { - "pedersen_builtin": 11, - "range_check_builtin": 17 + "resources": { + "constant": { + "n_steps": 1146, + "builtin_instance_counter": { + "pedersen_builtin": 11, + "range_check_builtin": 17 + }, + "n_memory_holes": 0 }, - "n_memory_holes": 0 + "calldata_factor": { + "n_steps": 13, + "builtin_instance_counter": { + "pedersen_builtin": 1 + }, + "n_memory_holes": 0 + } }, - "calldata_factor": { - "n_steps": 13, - "builtin_instance_counter": { - "pedersen_builtin": 1 + "deprecated_resources": { + "constant": { + "n_steps": 1146, + "builtin_instance_counter": { + "pedersen_builtin": 11, + "range_check_builtin": 17 + }, + "n_memory_holes": 0 }, - "n_memory_holes": 0 + "calldata_factor": { + "n_steps": 13, + "builtin_instance_counter": { + "pedersen_builtin": 1 + }, + "n_memory_holes": 0 + } } } + }, + "compute_os_kzg_commitment_info": { + "n_steps": 0, + "builtin_instance_counter": {}, + "n_memory_holes": 0 } }, "validate_max_n_steps": 1000000, "vm_resource_fee_cost": { - "bitwise_builtin": 0.16, - "ec_op_builtin": 2.56, - "ecdsa_builtin": 5.12, - "keccak_builtin": 5.12, - "n_steps": 0.0025, - "output_builtin": 0, - "pedersen_builtin": 0.08, - "poseidon_builtin": 0.08, - "range_check_builtin": 0.04 + "add_mod_builtin": [ + 0, + 1 + ], + "bitwise_builtin": [ + 16, + 100 + ], + "ec_op_builtin": [ + 256, + 100 + ], + "ecdsa_builtin": [ + 512, + 100 + ], + "keccak_builtin": [ + 512, + 100 + ], + "mul_mod_builtin": [ + 0, + 1 + ], + "n_steps": [ + 25, + 10000 + ], + "output_builtin": [ + 0, + 1 + ], + "pedersen_builtin": [ + 8, + 100 + ], + "poseidon_builtin": [ + 8, + 100 + ], + "range_check_builtin": [ + 4, + 100 + ], + "range_check96_builtin": [ + 0, + 1 + ] } -} \ No newline at end of file +} diff --git a/vm/rust/versioned_constants_13_1_1.json b/vm/rust/versioned_constants_13_1_1.json new file mode 100644 index 0000000000..791dac8b9b --- /dev/null +++ b/vm/rust/versioned_constants_13_1_1.json @@ -0,0 +1,599 @@ +{ + "tx_event_limits": { + "max_data_length": 300, + "max_keys_length": 50, + "max_n_emitted_events": 1000 + }, + "gateway": { + "max_calldata_length": 5000, + "max_contract_bytecode_size": 81920 + }, + "invoke_tx_max_n_steps": 4000000, + "l2_resource_gas_costs": { + "gas_per_data_felt": [ + 128, + 1000 + ], + "event_key_factor": [ + 2, + 1 + ], + "gas_per_code_byte": [ + 32, + 1000 + ] + }, + "max_recursion_depth": 50, + "os_constants": { + "nop_entry_point_offset": -1, + "entry_point_type_external": 0, + "entry_point_type_l1_handler": 1, + "entry_point_type_constructor": 2, + "l1_handler_version": 0, + "sierra_array_len_bound": 4294967296, + "constructor_entry_point_selector": "0x28ffe4ff0f226a9107253e17a904099aa4f63a02a5621de0576e5aa71bc5194", + "execute_entry_point_selector": "0x15d40a3d6ca2ac30f4031e42be28da9b056fef9bb7357ac5e85627ee876e5ad", + "validate_entry_point_selector": "0x162da33a4585851fe8d3af3c2a9c60b557814e221e0d4f30ff0b2189d9c7775", + "validate_declare_entry_point_selector": "0x289da278a8dc833409cabfdad1581e8e7d40e42dcaed693fa4008dcdb4963b3", + "validate_deploy_entry_point_selector": "0x36fcbf06cd96843058359e1a75928beacfac10727dab22a3972f0af8aa92895", + "transfer_entry_point_selector": "0x83afd3f4caedc6eebf44246fe54e38c95e3179a5ec9ea81740eca5b482d12e", + "default_entry_point_selector": 0, + "block_hash_contract_address": 1, + "stored_block_hash_buffer": 10, + "step_gas_cost": 100, + "range_check_gas_cost": 70, + "memory_hole_gas_cost": 10, + "initial_gas_cost": { + "step_gas_cost": 100000000 + }, + "entry_point_initial_budget": { + "step_gas_cost": 100 + }, + "syscall_base_gas_cost": { + "step_gas_cost": 100 + }, + "entry_point_gas_cost": { + "entry_point_initial_budget": 1, + "step_gas_cost": 500 + }, + "fee_transfer_gas_cost": { + "entry_point_gas_cost": 1, + "step_gas_cost": 100 + }, + "transaction_gas_cost": { + "entry_point_gas_cost": 2, + "fee_transfer_gas_cost": 1, + "step_gas_cost": 100 + }, + "call_contract_gas_cost": { + "syscall_base_gas_cost": 1, + "step_gas_cost": 10, + "entry_point_gas_cost": 1 + }, + "deploy_gas_cost": { + "syscall_base_gas_cost": 1, + "step_gas_cost": 200, + "entry_point_gas_cost": 1 + }, + "get_block_hash_gas_cost": { + "syscall_base_gas_cost": 1, + "step_gas_cost": 50 + }, + "get_execution_info_gas_cost": { + "syscall_base_gas_cost": 1, + "step_gas_cost": 10 + }, + "library_call_gas_cost": { + "call_contract_gas_cost": 1 + }, + "replace_class_gas_cost": { + "syscall_base_gas_cost": 1, + "step_gas_cost": 50 + }, + "storage_read_gas_cost": { + "syscall_base_gas_cost": 1, + "step_gas_cost": 50 + }, + "storage_write_gas_cost": { + "syscall_base_gas_cost": 1, + "step_gas_cost": 50 + }, + "emit_event_gas_cost": { + "syscall_base_gas_cost": 1, + "step_gas_cost": 10 + }, + "send_message_to_l1_gas_cost": { + "syscall_base_gas_cost": 1, + "step_gas_cost": 50 + }, + "secp256k1_add_gas_cost": { + "step_gas_cost": 406, + "range_check_gas_cost": 29 + }, + "secp256k1_get_point_from_x_gas_cost": { + "step_gas_cost": 391, + "range_check_gas_cost": 30, + "memory_hole_gas_cost": 20 + }, + "secp256k1_get_xy_gas_cost": { + "step_gas_cost": 239, + "range_check_gas_cost": 11, + "memory_hole_gas_cost": 40 + }, + "secp256k1_mul_gas_cost": { + "step_gas_cost": 76501, + "range_check_gas_cost": 7045, + "memory_hole_gas_cost": 2 + }, + "secp256k1_new_gas_cost": { + "step_gas_cost": 475, + "range_check_gas_cost": 35, + "memory_hole_gas_cost": 40 + }, + "secp256r1_add_gas_cost": { + "step_gas_cost": 589, + "range_check_gas_cost": 57 + }, + "secp256r1_get_point_from_x_gas_cost": { + "step_gas_cost": 510, + "range_check_gas_cost": 44, + "memory_hole_gas_cost": 20 + }, + "secp256r1_get_xy_gas_cost": { + "step_gas_cost": 241, + "range_check_gas_cost": 11, + "memory_hole_gas_cost": 40 + }, + "secp256r1_mul_gas_cost": { + "step_gas_cost": 125340, + "range_check_gas_cost": 13961, + "memory_hole_gas_cost": 2 + }, + "secp256r1_new_gas_cost": { + "step_gas_cost": 594, + "range_check_gas_cost": 49, + "memory_hole_gas_cost": 40 + }, + "keccak_gas_cost": { + "syscall_base_gas_cost": 1 + }, + "keccak_round_cost_gas_cost": 180000, + "sha256_process_block_gas_cost": { + "step_gas_cost": 0, + "range_check_gas_cost": 0, + "syscall_base_gas_cost": 0 + }, + "error_block_number_out_of_range": "Block number out of range", + "error_out_of_gas": "Out of gas", + "error_invalid_input_len": "Invalid input length", + "error_invalid_argument": "Invalid argument", + "validated": "VALID", + "l1_gas": "L1_GAS", + "l2_gas": "L2_GAS", + "l1_gas_index": 0, + "l2_gas_index": 1, + "validate_rounding_consts": { + "validate_block_number_rounding": 100, + "validate_timestamp_rounding": 3600 + } + }, + "os_resources": { + "execute_syscalls": { + "CallContract": { + "n_steps": 760, + "builtin_instance_counter": { + "range_check_builtin": 20 + }, + "n_memory_holes": 0 + }, + "DelegateCall": { + "n_steps": 713, + "builtin_instance_counter": { + "range_check_builtin": 19 + }, + "n_memory_holes": 0 + }, + "DelegateL1Handler": { + "n_steps": 692, + "builtin_instance_counter": { + "range_check_builtin": 15 + }, + "n_memory_holes": 0 + }, + "Deploy": { + "n_steps": 1012, + "builtin_instance_counter": { + "pedersen_builtin": 7, + "range_check_builtin": 19 + }, + "n_memory_holes": 0 + }, + "EmitEvent": { + "n_steps": 61, + "builtin_instance_counter": { + "range_check_builtin": 1 + }, + "n_memory_holes": 0 + }, + "GetBlockHash": { + "n_steps": 104, + "builtin_instance_counter": { + "range_check_builtin": 2 + }, + "n_memory_holes": 0 + }, + "GetBlockNumber": { + "n_steps": 40, + "builtin_instance_counter": {}, + "n_memory_holes": 0 + }, + "GetBlockTimestamp": { + "n_steps": 38, + "builtin_instance_counter": {}, + "n_memory_holes": 0 + }, + "GetCallerAddress": { + "n_steps": 64, + "builtin_instance_counter": { + "range_check_builtin": 1 + }, + "n_memory_holes": 0 + }, + "GetContractAddress": { + "n_steps": 64, + "builtin_instance_counter": { + "range_check_builtin": 1 + }, + "n_memory_holes": 0 + }, + "GetExecutionInfo": { + "n_steps": 64, + "builtin_instance_counter": { + "range_check_builtin": 1 + }, + "n_memory_holes": 0 + }, + "GetSequencerAddress": { + "n_steps": 34, + "builtin_instance_counter": {}, + "n_memory_holes": 0 + }, + "GetTxInfo": { + "n_steps": 64, + "builtin_instance_counter": { + "range_check_builtin": 1 + }, + "n_memory_holes": 0 + }, + "GetTxSignature": { + "n_steps": 44, + "builtin_instance_counter": {}, + "n_memory_holes": 0 + }, + "Keccak": { + "n_steps": 381, + "builtin_instance_counter": { + "bitwise_builtin": 6, + "keccak_builtin": 1, + "range_check_builtin": 56 + }, + "n_memory_holes": 0 + }, + "LibraryCall": { + "n_steps": 751, + "builtin_instance_counter": { + "range_check_builtin": 20 + }, + "n_memory_holes": 0 + }, + "LibraryCallL1Handler": { + "n_steps": 659, + "builtin_instance_counter": { + "range_check_builtin": 15 + }, + "n_memory_holes": 0 + }, + "ReplaceClass": { + "n_steps": 98, + "builtin_instance_counter": { + "range_check_builtin": 1 + }, + "n_memory_holes": 0 + }, + "Secp256k1Add": { + "n_steps": 408, + "builtin_instance_counter": { + "range_check_builtin": 29 + }, + "n_memory_holes": 0 + }, + "Secp256k1GetPointFromX": { + "n_steps": 393, + "builtin_instance_counter": { + "range_check_builtin": 30 + }, + "n_memory_holes": 0 + }, + "Secp256k1GetXy": { + "n_steps": 205, + "builtin_instance_counter": { + "range_check_builtin": 11 + }, + "n_memory_holes": 0 + }, + "Secp256k1Mul": { + "n_steps": 76503, + "builtin_instance_counter": { + "range_check_builtin": 7045 + }, + "n_memory_holes": 0 + }, + "Secp256k1New": { + "n_steps": 459, + "builtin_instance_counter": { + "range_check_builtin": 35 + }, + "n_memory_holes": 0 + }, + "Secp256r1Add": { + "n_steps": 591, + "builtin_instance_counter": { + "range_check_builtin": 57 + }, + "n_memory_holes": 0 + }, + "Secp256r1GetPointFromX": { + "n_steps": 512, + "builtin_instance_counter": { + "range_check_builtin": 44 + }, + "n_memory_holes": 0 + }, + "Secp256r1GetXy": { + "n_steps": 207, + "builtin_instance_counter": { + "range_check_builtin": 11 + }, + "n_memory_holes": 0 + }, + "Secp256r1Mul": { + "n_steps": 125342, + "builtin_instance_counter": { + "range_check_builtin": 13961 + }, + "n_memory_holes": 0 + }, + "Secp256r1New": { + "n_steps": 578, + "builtin_instance_counter": { + "range_check_builtin": 49 + }, + "n_memory_holes": 0 + }, + "SendMessageToL1": { + "n_steps": 139, + "builtin_instance_counter": { + "range_check_builtin": 1 + }, + "n_memory_holes": 0 + }, + "Sha256ProcessBlock": { + "builtin_instance_counter": {}, + "n_memory_holes": 0, + "n_steps": 0 + }, + "StorageRead": { + "n_steps": 87, + "builtin_instance_counter": { + "range_check_builtin": 1 + }, + "n_memory_holes": 0 + }, + "StorageWrite": { + "n_steps": 89, + "builtin_instance_counter": { + "range_check_builtin": 1 + }, + "n_memory_holes": 0 + } + }, + "execute_txs_inner": { + "Declare": { + "resources": { + "constant": { + "n_steps": 2839, + "builtin_instance_counter": { + "pedersen_builtin": 16, + "range_check_builtin": 63 + }, + "n_memory_holes": 0 + }, + "calldata_factor": { + "n_steps": 0, + "builtin_instance_counter": {}, + "n_memory_holes": 0 + } + }, + "deprecated_resources": { + "constant": { + "n_steps": 2839, + "builtin_instance_counter": { + "pedersen_builtin": 16, + "range_check_builtin": 63 + }, + "n_memory_holes": 0 + }, + "calldata_factor": { + "n_steps": 0, + "builtin_instance_counter": {}, + "n_memory_holes": 0 + } + } + }, + "DeployAccount": { + "resources": { + "constant": { + "n_steps": 3792, + "builtin_instance_counter": { + "pedersen_builtin": 23, + "range_check_builtin": 83 + }, + "n_memory_holes": 0 + }, + "calldata_factor": { + "n_steps": 21, + "builtin_instance_counter": { + "pedersen_builtin": 2 + }, + "n_memory_holes": 0 + } + }, + "deprecated_resources": { + "constant": { + "n_steps": 3792, + "builtin_instance_counter": { + "pedersen_builtin": 23, + "range_check_builtin": 83 + }, + "n_memory_holes": 0 + }, + "calldata_factor": { + "n_steps": 21, + "builtin_instance_counter": { + "pedersen_builtin": 2 + }, + "n_memory_holes": 0 + } + } + }, + "InvokeFunction": { + "resources": { + "constant": { + "n_steps": 3546, + "builtin_instance_counter": { + "pedersen_builtin": 14, + "range_check_builtin": 80 + }, + "n_memory_holes": 0 + }, + "calldata_factor": { + "n_steps": 8, + "builtin_instance_counter": { + "pedersen_builtin": 1 + }, + "n_memory_holes": 0 + } + }, + "deprecated_resources": { + "constant": { + "n_steps": 3546, + "builtin_instance_counter": { + "pedersen_builtin": 14, + "range_check_builtin": 80 + }, + "n_memory_holes": 0 + }, + "calldata_factor": { + "n_steps": 8, + "builtin_instance_counter": { + "pedersen_builtin": 1 + }, + "n_memory_holes": 0 + } + } + }, + "L1Handler": { + "resources": { + "constant": { + "n_steps": 1146, + "builtin_instance_counter": { + "pedersen_builtin": 11, + "range_check_builtin": 17 + }, + "n_memory_holes": 0 + }, + "calldata_factor": { + "n_steps": 13, + "builtin_instance_counter": { + "pedersen_builtin": 1 + }, + "n_memory_holes": 0 + } + }, + "deprecated_resources": { + "constant": { + "n_steps": 1146, + "builtin_instance_counter": { + "pedersen_builtin": 11, + "range_check_builtin": 17 + }, + "n_memory_holes": 0 + }, + "calldata_factor": { + "n_steps": 13, + "builtin_instance_counter": { + "pedersen_builtin": 1 + }, + "n_memory_holes": 0 + } + } + } + }, + "compute_os_kzg_commitment_info": { + "n_steps": 0, + "builtin_instance_counter": {}, + "n_memory_holes": 0 + } + }, + "validate_max_n_steps": 1000000, + "vm_resource_fee_cost": { + "add_mod_builtin": [ + 0, + 1 + ], + "bitwise_builtin": [ + 16, + 100 + ], + "ec_op_builtin": [ + 256, + 100 + ], + "ecdsa_builtin": [ + 512, + 100 + ], + "keccak_builtin": [ + 512, + 100 + ], + "mul_mod_builtin": [ + 0, + 1 + ], + "n_steps": [ + 25, + 10000 + ], + "output_builtin": [ + 0, + 1 + ], + "pedersen_builtin": [ + 8, + 100 + ], + "poseidon_builtin": [ + 8, + 100 + ], + "range_check_builtin": [ + 4, + 100 + ], + "range_check96_builtin": [ + 0, + 1 + ] + } +} diff --git a/vm/trace.go b/vm/trace.go index bd284767b3..f17257ff41 100644 --- a/vm/trace.go +++ b/vm/trace.go @@ -232,6 +232,9 @@ type ComputationResources struct { Keccak uint64 `json:"keccak_builtin_applications,omitempty"` Poseidon uint64 `json:"poseidon_builtin_applications,omitempty"` SegmentArena uint64 `json:"segment_arena_builtin,omitempty"` + AddMod uint64 `json:"add_mod_builtin,omitempty"` + MulMod uint64 `json:"mul_mod_builtin,omitempty"` + RangeCheck96 uint64 `json:"range_check_96_builtin,omitempty"` } type DataAvailability struct { diff --git a/vm/vm.go b/vm/vm.go index d0e677c351..ba952ee1f7 100644 --- a/vm/vm.go +++ b/vm/vm.go @@ -29,11 +29,12 @@ typedef struct BlockInfo { } BlockInfo; extern void cairoVMCall(CallInfo* call_info_ptr, BlockInfo* block_info_ptr, uintptr_t readerHandle, char* chain_id, - unsigned long long max_steps); + unsigned long long max_steps, unsigned char concurrency_mode); extern void cairoVMExecute(char* txns_json, char* classes_json, char* paid_fees_on_l1_json, BlockInfo* block_info_ptr, uintptr_t readerHandle, char* chain_id, - unsigned char skip_charge_fee, unsigned char skip_validate, unsigned char err_on_revert); + unsigned char skip_charge_fee, unsigned char skip_validate, unsigned char err_on_revert, + unsigned char concurrency_mode); extern char* setVersionedConstants(char* json); extern void freeString(char* str); @@ -60,19 +61,22 @@ import ( //go:generate mockgen -destination=../mocks/mock_vm.go -package=mocks github.com/NethermindEth/juno/vm VM type VM interface { - Call(callInfo *CallInfo, blockInfo *BlockInfo, state core.StateReader, network *utils.Network, maxSteps uint64, useBlobData bool) ([]*felt.Felt, error) //nolint:lll + Call(callInfo *CallInfo, blockInfo *BlockInfo, state core.StateReader, network *utils.Network, + maxSteps uint64, useBlobData bool) ([]*felt.Felt, error) Execute(txns []core.Transaction, declaredClasses []core.Class, paidFeesOnL1 []*felt.Felt, blockInfo *BlockInfo, state core.StateReader, network *utils.Network, skipChargeFee, skipValidate, errOnRevert, useBlobData bool, ) ([]*felt.Felt, []*felt.Felt, []TransactionTrace, error) } type vm struct { - log utils.SimpleLogger + log utils.SimpleLogger + concurrencyMode bool } -func New(log utils.SimpleLogger) VM { +func New(concurrencyMode bool, log utils.SimpleLogger) VM { return &vm{ - log: log, + log: log, + concurrencyMode: concurrencyMode, } } @@ -225,6 +229,10 @@ func (v *vm) Call(callInfo *CallInfo, blockInfo *BlockInfo, state core.StateRead handle := cgo.NewHandle(context) defer handle.Delete() + var concurrencyModeByte byte + if v.concurrencyMode { + concurrencyModeByte = 1 + } C.setVersionedConstants(C.CString("my_json")) cCallInfo, callInfoPinner := makeCCallInfo(callInfo) @@ -235,7 +243,8 @@ func (v *vm) Call(callInfo *CallInfo, blockInfo *BlockInfo, state core.StateRead &cBlockInfo, C.uintptr_t(handle), chainID, - C.ulonglong(maxSteps), //nolint:gocritic + C.ulonglong(maxSteps), //nolint:gocritic + C.uchar(concurrencyModeByte), //nolint:gocritic ) callInfoPinner.Unpin() C.free(unsafe.Pointer(chainID)) @@ -288,6 +297,11 @@ func (v *vm) Execute(txns []core.Transaction, declaredClasses []core.Class, paid errOnRevertByte = 1 } + var concurrencyModeByte byte + if v.concurrencyMode { + concurrencyModeByte = 1 + } + cBlockInfo := makeCBlockInfo(blockInfo, useBlobData) chainID := C.CString(network.L2ChainID) C.cairoVMExecute(txnsJSONCstr, @@ -298,7 +312,8 @@ func (v *vm) Execute(txns []core.Transaction, declaredClasses []core.Class, paid chainID, C.uchar(skipChargeFeeByte), C.uchar(skipValidateByte), - C.uchar(errOnRevertByte), //nolint:gocritic + C.uchar(errOnRevertByte), //nolint:gocritic + C.uchar(concurrencyModeByte), //nolint:gocritic ) C.free(unsafe.Pointer(classesJSONCStr)) diff --git a/vm/vm_test.go b/vm/vm_test.go index dc65cb2179..63c830debb 100644 --- a/vm/vm_test.go +++ b/vm/vm_test.go @@ -50,7 +50,7 @@ func TestV0Call(t *testing.T) { entryPoint := utils.HexToFelt(t, "0x39e11d48192e4333233c7eb19d10ad67c362bb28580c604d67884c85da39695") - ret, err := New(nil).Call(&CallInfo{ + ret, err := New(false, nil).Call(&CallInfo{ ContractAddress: contractAddr, ClassHash: classHash, Selector: entryPoint, @@ -70,7 +70,7 @@ func TestV0Call(t *testing.T) { }, }, nil)) - ret, err = New(nil).Call(&CallInfo{ + ret, err = New(false, nil).Call(&CallInfo{ ContractAddress: contractAddr, ClassHash: classHash, Selector: entryPoint, @@ -116,7 +116,7 @@ func TestV1Call(t *testing.T) { // test_storage_read entryPoint := utils.HexToFelt(t, "0x5df99ae77df976b4f0e5cf28c7dcfe09bd6e81aab787b19ac0c08e03d928cf") storageLocation := utils.HexToFelt(t, "0x44") - ret, err := New(log).Call(&CallInfo{ + ret, err := New(false, log).Call(&CallInfo{ ContractAddress: contractAddr, Selector: entryPoint, Calldata: []felt.Felt{ @@ -138,7 +138,7 @@ func TestV1Call(t *testing.T) { }, }, nil)) - ret, err = New(log).Call(&CallInfo{ + ret, err = New(false, log).Call(&CallInfo{ ContractAddress: contractAddr, Selector: entryPoint, Calldata: []felt.Felt{ @@ -182,7 +182,7 @@ func TestCall_MaxSteps(t *testing.T) { entryPoint := utils.HexToFelt(t, "0x39e11d48192e4333233c7eb19d10ad67c362bb28580c604d67884c85da39695") - _, err = New(nil).Call(&CallInfo{ + _, err = New(false, nil).Call(&CallInfo{ ContractAddress: contractAddr, ClassHash: classHash, Selector: entryPoint, @@ -203,7 +203,7 @@ func TestExecute(t *testing.T) { state := core.NewState(txn) t.Run("empty transaction list", func(t *testing.T) { - _, _, _, err := New(nil).Execute([]core.Transaction{}, []core.Class{}, []*felt.Felt{}, &BlockInfo{ + _, _, _, err := New(false, nil).Execute([]core.Transaction{}, []core.Class{}, []*felt.Felt{}, &BlockInfo{ Header: &core.Header{ Timestamp: 1666877926, SequencerAddress: utils.HexToFelt(t, "0x46a89ae102987331d369645031b49c27738ed096f2789c24449966da4c6de6b"), @@ -215,7 +215,7 @@ func TestExecute(t *testing.T) { require.NoError(t, err) }) t.Run("zero data", func(t *testing.T) { - _, _, _, err := New(nil).Execute(nil, nil, []*felt.Felt{}, &BlockInfo{ + _, _, _, err := New(false, nil).Execute(nil, nil, []*felt.Felt{}, &BlockInfo{ Header: &core.Header{ SequencerAddress: &felt.Zero, GasPrice: &felt.Zero,