From 7eda27ca0156225e965f29bc92748083d36ccf05 Mon Sep 17 00:00:00 2001 From: Danil Date: Fri, 13 Oct 2023 13:28:27 +0200 Subject: [PATCH] feat(multivm): Remove lifetime from multivm (#218) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # What ❔ Remove lifetime from multivm. Update zk_evm 1.3.1 to the version without lifetime ## Why ❔ For better compatibility with the new VM versions, i've updated zk-evm by removing lifetime from vm state ## Checklist - [ ] PR title corresponds to the body of PR (we generate changelog entries from PRs). - [ ] Tests for the changes have been added / updated. - [ ] Documentation comments have been added / updated. - [ ] Code has been formatted via `zk fmt` and `zk lint`. --------- Signed-off-by: Danil --- Cargo.lock | 2 +- core/lib/multivm/src/glue/init_vm.rs | 31 +++++-- core/lib/multivm/src/vm_instance.rs | 90 ++++++------------- .../src/api_server/execution_sandbox/apply.rs | 11 +-- .../src/state_keeper/batch_executor/mod.rs | 17 ++-- core/multivm_deps/vm_m5/Cargo.toml | 2 +- core/multivm_deps/vm_m5/src/pubdata_utils.rs | 2 +- core/multivm_deps/vm_m5/src/refunds.rs | 2 +- core/multivm_deps/vm_m5/src/test_utils.rs | 2 +- core/multivm_deps/vm_m5/src/vm.rs | 15 ++-- .../vm_m5/src/vm_with_bootloader.rs | 44 ++++----- core/multivm_deps/vm_m6/Cargo.toml | 2 +- core/multivm_deps/vm_m6/src/pubdata_utils.rs | 2 +- core/multivm_deps/vm_m6/src/refunds.rs | 2 +- core/multivm_deps/vm_m6/src/test_utils.rs | 2 +- core/multivm_deps/vm_m6/src/utils.rs | 2 +- core/multivm_deps/vm_m6/src/vm.rs | 17 ++-- .../vm_m6/src/vm_with_bootloader.rs | 44 ++++----- 18 files changed, 131 insertions(+), 158 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6fa750f187e6..26b754a84533 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7511,7 +7511,7 @@ checksum = "2a0956f1ba7c7909bfb66c2e9e4124ab6f6482560f6628b5aaeba39207c9aad9" [[package]] name = "zk_evm" version = "1.3.1" -source = "git+https://github.com/matter-labs/era-zk_evm.git?tag=v1.3.1-rc0#877ba31cc1d82316fd924e8d83a9f5f1a77b1b9a" +source = "git+https://github.com/matter-labs/era-zk_evm.git?tag=v1.3.1-rc1#cec6535e2bcb1e8f0bad1befaaddec8da7f11b24" dependencies = [ "blake2 0.10.6", "k256", diff --git a/core/lib/multivm/src/glue/init_vm.rs b/core/lib/multivm/src/glue/init_vm.rs index bd75c0fbec8d..cc74a2bae12f 100644 --- a/core/lib/multivm/src/glue/init_vm.rs +++ b/core/lib/multivm/src/glue/init_vm.rs @@ -6,19 +6,27 @@ use vm_latest::{L1BatchEnv, SystemEnv}; use zksync_state::ReadStorage; use zksync_utils::h256_to_u256; -impl<'a, S: ReadStorage, H: HistoryMode> VmInstance<'a, S, H> { +impl VmInstance { pub fn new( l1_batch_env: L1BatchEnv, system_env: SystemEnv, - initial_version: &'a mut VmInstanceData, + initial_version: VmInstanceData, ) -> Self { match initial_version { VmInstanceData::M5(data) => { + let oracle_tools = + vm_m5::OracleTools::new(data.storage_view.clone(), data.sub_version); + let block_properties = vm_m5::zk_evm::block_properties::BlockProperties { + default_aa_code_hash: h256_to_u256( + system_env.base_system_smart_contracts.default_aa.hash, + ), + zkporter_is_available: false, + }; let inner_vm = vm_m5::vm_with_bootloader::init_vm_with_gas_limit( data.sub_version, - data.oracle_tools.m5(), + oracle_tools, l1_batch_env.glue_into(), - data.block_properties.m5(), + block_properties, system_env.execution_mode.glue_into(), &system_env.base_system_smart_contracts.clone().glue_into(), system_env.gas_limit, @@ -30,11 +38,22 @@ impl<'a, S: ReadStorage, H: HistoryMode> VmInstance<'a, S, H> { } } VmInstanceData::M6(data) => { + let oracle_tools = vm_m6::OracleTools::new( + data.storage_view.clone(), + data.history_mode.glue_into(), + ); + let block_properties = vm_m6::zk_evm::block_properties::BlockProperties { + default_aa_code_hash: h256_to_u256( + system_env.base_system_smart_contracts.default_aa.hash, + ), + zkporter_is_available: false, + }; + let inner_vm = vm_m6::vm_with_bootloader::init_vm_with_gas_limit( data.sub_version, - data.oracle_tools.m6(), + oracle_tools, l1_batch_env.glue_into(), - data.block_properties.m6(), + block_properties, system_env.execution_mode.glue_into(), &system_env.base_system_smart_contracts.clone().glue_into(), system_env.gas_limit, diff --git a/core/lib/multivm/src/vm_instance.rs b/core/lib/multivm/src/vm_instance.rs index 30b410b52b53..dab7f186c8f5 100644 --- a/core/lib/multivm/src/vm_instance.rs +++ b/core/lib/multivm/src/vm_instance.rs @@ -6,23 +6,21 @@ use vm_latest::{ use zksync_state::{ReadStorage, StoragePtr, StorageView}; use zksync_types::VmVersion; use zksync_utils::bytecode::{hash_bytecode, CompressedBytecodeInfo}; -use zksync_utils::h256_to_u256; use crate::glue::history_mode::HistoryMode; use crate::glue::tracer::MultivmTracer; use crate::glue::GlueInto; -use crate::{BlockProperties, OracleTools}; -pub struct VmInstance<'a, S: ReadStorage, H: HistoryMode> { - pub(crate) vm: VmInstanceVersion<'a, S, H>, +pub struct VmInstance { + pub(crate) vm: VmInstanceVersion, pub(crate) system_env: SystemEnv, pub(crate) last_tx_compressed_bytecodes: Vec, } #[derive(Debug)] -pub(crate) enum VmInstanceVersion<'a, S: ReadStorage, H: HistoryMode> { - VmM5(Box>>), - VmM6(Box, H::VmM6Mode>>), +pub(crate) enum VmInstanceVersion { + VmM5(Box>>), + VmM6(Box, H::VmM6Mode>>), Vm1_3_2(Box, H::Vm1_3_2Mode>>), VmVirtualBlocks(Box, H::VmVirtualBlocksMode>>), VmVirtualBlocksRefundsEnhancement( @@ -30,7 +28,7 @@ pub(crate) enum VmInstanceVersion<'a, S: ReadStorage, H: HistoryMode> { ), } -impl<'a, S: ReadStorage, H: HistoryMode> VmInstance<'a, S, H> { +impl VmInstance { /// Push tx into memory for the future execution pub fn push_transaction(&mut self, tx: &zksync_types::Transaction) { match &mut self.vm { @@ -446,15 +444,15 @@ impl<'a, S: ReadStorage, H: HistoryMode> VmInstance<'a, S, H> { } pub struct M5NecessaryData { - pub oracle_tools: OracleTools, - pub block_properties: BlockProperties, + pub storage_view: StoragePtr>, pub sub_version: vm_m5::vm::MultiVMSubversion, + pub history_mode: H, } pub struct M6NecessaryData { - pub oracle_tools: OracleTools, - pub block_properties: BlockProperties, + pub storage_view: StoragePtr>, pub sub_version: vm_m6::vm::MultiVMSubversion, + pub history_mode: H, } pub struct Vm1_3_2NecessaryData { @@ -463,7 +461,7 @@ pub struct Vm1_3_2NecessaryData { } pub struct VmVirtualBlocksNecessaryData { - pub storage_view: zksync_state::StoragePtr>, + pub storage_view: StoragePtr>, pub history_mode: H, } @@ -477,25 +475,26 @@ pub enum VmInstanceData { impl VmInstanceData { fn m5( - oracle_tools: OracleTools, - block_properties: BlockProperties, + storage_view: StoragePtr>, sub_version: vm_m5::vm::MultiVMSubversion, + history_mode: H, ) -> Self { Self::M5(M5NecessaryData { - oracle_tools, - block_properties, + storage_view, sub_version, + history_mode, }) } + fn m6( - oracle_tools: OracleTools, - block_properties: BlockProperties, + storage_view: StoragePtr>, sub_version: vm_m6::vm::MultiVMSubversion, + history_mode: H, ) -> Self { Self::M6(M6NecessaryData { - oracle_tools, - block_properties, + storage_view, sub_version, + history_mode, }) } @@ -527,64 +526,27 @@ impl VmInstanceData { ) -> Self { let protocol_version = system_env.version; let vm_version: VmVersion = protocol_version.into(); - Self::new_for_specific_vm_version(storage_view, system_env, history, vm_version) + Self::new_for_specific_vm_version(storage_view, history, vm_version) } // In api we support only subset of vm versions, so we need to create vm instance for specific version pub fn new_for_specific_vm_version( storage_view: StoragePtr>, - system_env: &SystemEnv, history: H, vm_version: VmVersion, ) -> Self { match vm_version { VmVersion::M5WithoutRefunds => { - let oracle_tools = OracleTools::new(vm_version, storage_view, history); - let block_properties = BlockProperties::new( - vm_version, - h256_to_u256(system_env.base_system_smart_contracts.default_aa.hash), - ); - VmInstanceData::m5( - oracle_tools, - block_properties, - vm_m5::vm::MultiVMSubversion::V1, - ) + VmInstanceData::m5(storage_view, vm_m5::vm::MultiVMSubversion::V1, history) } VmVersion::M5WithRefunds => { - let oracle_tools = OracleTools::new(vm_version, storage_view, history); - let block_properties = BlockProperties::new( - vm_version, - h256_to_u256(system_env.base_system_smart_contracts.default_aa.hash), - ); - VmInstanceData::m5( - oracle_tools, - block_properties, - vm_m5::vm::MultiVMSubversion::V2, - ) + VmInstanceData::m5(storage_view, vm_m5::vm::MultiVMSubversion::V2, history) } VmVersion::M6Initial => { - let oracle_tools = OracleTools::new(vm_version, storage_view, history); - let block_properties = BlockProperties::new( - vm_version, - h256_to_u256(system_env.base_system_smart_contracts.default_aa.hash), - ); - VmInstanceData::m6( - oracle_tools, - block_properties, - vm_m6::vm::MultiVMSubversion::V1, - ) + VmInstanceData::m6(storage_view, vm_m6::vm::MultiVMSubversion::V1, history) } VmVersion::M6BugWithCompressionFixed => { - let oracle_tools = OracleTools::new(vm_version, storage_view, history); - let block_properties = BlockProperties::new( - vm_version, - h256_to_u256(system_env.base_system_smart_contracts.default_aa.hash), - ); - VmInstanceData::m6( - oracle_tools, - block_properties, - vm_m6::vm::MultiVMSubversion::V2, - ) + VmInstanceData::m6(storage_view, vm_m6::vm::MultiVMSubversion::V2, history) } VmVersion::Vm1_3_2 => VmInstanceData::vm1_3_2(storage_view, history), VmVersion::VmVirtualBlocks => VmInstanceData::vm_virtual_blocks(storage_view, history), @@ -595,7 +557,7 @@ impl VmInstanceData { } } -impl VmInstance<'_, S, vm_latest::HistoryEnabled> { +impl VmInstance { pub fn make_snapshot(&mut self) { match &mut self.vm { VmInstanceVersion::VmM5(vm) => vm.save_current_vm_as_snapshot(), diff --git a/core/lib/zksync_core/src/api_server/execution_sandbox/apply.rs b/core/lib/zksync_core/src/api_server/execution_sandbox/apply.rs index 703f990e0314..790a814a4cb8 100644 --- a/core/lib/zksync_core/src/api_server/execution_sandbox/apply.rs +++ b/core/lib/zksync_core/src/api_server/execution_sandbox/apply.rs @@ -36,7 +36,7 @@ pub(super) fn apply_vm_in_sandbox( connection_pool: &ConnectionPool, tx: Transaction, block_args: BlockArgs, - apply: impl FnOnce(&mut VmInstance<'_, PostgresStorage<'_>, HistoryDisabled>, Transaction) -> T, + apply: impl FnOnce(&mut VmInstance, HistoryDisabled>, Transaction) -> T, ) -> T { let stage_started_at = Instant::now(); let span = tracing::debug_span!("initialization").entered(); @@ -197,17 +197,12 @@ pub(super) fn apply_vm_in_sandbox( }; let storage_view = storage_view.to_rc_ptr(); - let mut initial_version = VmInstanceData::new_for_specific_vm_version( + let initial_version = VmInstanceData::new_for_specific_vm_version( storage_view.clone(), - &system_env, HistoryDisabled, protocol_version.into_api_vm_version(), ); - let mut vm = Box::new(VmInstance::new( - l1_batch_env, - system_env, - &mut initial_version, - )); + let mut vm = Box::new(VmInstance::new(l1_batch_env, system_env, initial_version)); metrics::histogram!("api.web3.sandbox", stage_started_at.elapsed(), "stage" => "initialization"); span.exit(); diff --git a/core/lib/zksync_core/src/state_keeper/batch_executor/mod.rs b/core/lib/zksync_core/src/state_keeper/batch_executor/mod.rs index 5ebb14f99b78..3f2517d32217 100644 --- a/core/lib/zksync_core/src/state_keeper/batch_executor/mod.rs +++ b/core/lib/zksync_core/src/state_keeper/batch_executor/mod.rs @@ -292,9 +292,8 @@ impl BatchExecutor { let storage_view = StorageView::new(secondary_storage).to_rc_ptr(); - let mut instance_data = - VmInstanceData::new(storage_view.clone(), &system_env, HistoryEnabled); - let mut vm = VmInstance::new(l1_batch_params, system_env, &mut instance_data); + let instance_data = VmInstanceData::new(storage_view.clone(), &system_env, HistoryEnabled); + let mut vm = VmInstance::new(l1_batch_params, system_env, instance_data); while let Some(cmd) = self.commands.blocking_recv() { match cmd { @@ -344,7 +343,7 @@ impl BatchExecutor { fn execute_tx( &self, tx: &Transaction, - vm: &mut VmInstance<'_, S, HistoryEnabled>, + vm: &mut VmInstance, ) -> TxExecutionResult { // Save pre-`execute_next_tx` VM snapshot. vm.make_snapshot(); @@ -414,7 +413,7 @@ impl BatchExecutor { } } - fn rollback_last_tx(&self, vm: &mut VmInstance<'_, S, HistoryEnabled>) { + fn rollback_last_tx(&self, vm: &mut VmInstance) { let stage_started_at = Instant::now(); vm.rollback_to_the_latest_snapshot(); metrics::histogram!( @@ -427,14 +426,14 @@ impl BatchExecutor { fn start_next_miniblock( &self, l2_block_env: L2BlockEnv, - vm: &mut VmInstance<'_, S, HistoryEnabled>, + vm: &mut VmInstance, ) { vm.start_new_l2_block(l2_block_env); } fn finish_batch( &self, - vm: &mut VmInstance<'_, S, HistoryEnabled>, + vm: &mut VmInstance, ) -> FinishedL1Batch { // The vm execution was paused right after the last transaction was executed. // There is some post-processing work that the VM needs to do before the block is fully processed. @@ -452,7 +451,7 @@ impl BatchExecutor { fn execute_tx_in_vm( &self, tx: &Transaction, - vm: &mut VmInstance<'_, S, HistoryEnabled>, + vm: &mut VmInstance, ) -> ( VmExecutionResultAndLogs, Vec, @@ -512,7 +511,7 @@ impl BatchExecutor { fn dryrun_block_tip( &self, - vm: &mut VmInstance<'_, S, HistoryEnabled>, + vm: &mut VmInstance, ) -> (VmExecutionResultAndLogs, ExecutionMetricsForCriteria) { let started_at = Instant::now(); let mut stage_started_at = Instant::now(); diff --git a/core/multivm_deps/vm_m5/Cargo.toml b/core/multivm_deps/vm_m5/Cargo.toml index 61a0b6e30162..a9bed97eeff5 100644 --- a/core/multivm_deps/vm_m5/Cargo.toml +++ b/core/multivm_deps/vm_m5/Cargo.toml @@ -17,7 +17,7 @@ zksync_config = { path = "../../lib/config" } zksync_state = { path = "../../lib/state" } zksync_storage = { path = "../../lib/storage" } -zk_evm = { git = "https://github.com/matter-labs/era-zk_evm.git", tag = "v1.3.1-rc0" } +zk_evm = { git = "https://github.com/matter-labs/era-zk_evm.git", tag = "v1.3.1-rc1" } zksync_contracts = { path = "../../lib/contracts" } hex = "0.4" diff --git a/core/multivm_deps/vm_m5/src/pubdata_utils.rs b/core/multivm_deps/vm_m5/src/pubdata_utils.rs index f2e1f94082bd..c3df97793833 100644 --- a/core/multivm_deps/vm_m5/src/pubdata_utils.rs +++ b/core/multivm_deps/vm_m5/src/pubdata_utils.rs @@ -11,7 +11,7 @@ use zksync_types::zkevm_test_harness::witness::sort_storage_access::sort_storage use zksync_types::{StorageKey, PUBLISH_BYTECODE_OVERHEAD, SYSTEM_CONTEXT_ADDRESS}; use zksync_utils::bytecode::bytecode_len_in_bytes; -impl<'a, S: Storage> VmInstance<'a, S> { +impl VmInstance { pub fn pubdata_published(&self, from_timestamp: Timestamp) -> u32 { let storage_writes_pubdata_published = self.pubdata_published_for_writes(from_timestamp); diff --git a/core/multivm_deps/vm_m5/src/refunds.rs b/core/multivm_deps/vm_m5/src/refunds.rs index 1764d5ec2503..b7cfb7e0ce94 100644 --- a/core/multivm_deps/vm_m5/src/refunds.rs +++ b/core/multivm_deps/vm_m5/src/refunds.rs @@ -8,7 +8,7 @@ use zk_evm::aux_structures::Timestamp; use zksync_types::U256; use zksync_utils::ceil_div_u256; -impl<'a, S: Storage> VmInstance<'a, S> { +impl VmInstance { pub(crate) fn tx_body_refund( &self, from_timestamp: Timestamp, diff --git a/core/multivm_deps/vm_m5/src/test_utils.rs b/core/multivm_deps/vm_m5/src/test_utils.rs index 83ef7575805e..b151ac457817 100644 --- a/core/multivm_deps/vm_m5/src/test_utils.rs +++ b/core/multivm_deps/vm_m5/src/test_utils.rs @@ -91,7 +91,7 @@ pub struct VmInstanceInnerState { local_state: VmLocalState, } -impl<'a, S: Storage> VmInstance<'a, S> { +impl VmInstance { /// This method is mostly to be used in tests. It dumps the inner state of all the oracles and the VM itself. pub fn dump_inner_state(&self) -> VmInstanceInnerState { let event_sink = self.state.event_sink.clone(); diff --git a/core/multivm_deps/vm_m5/src/vm.rs b/core/multivm_deps/vm_m5/src/vm.rs index d8244f203534..a55566214126 100644 --- a/core/multivm_deps/vm_m5/src/vm.rs +++ b/core/multivm_deps/vm_m5/src/vm.rs @@ -37,8 +37,7 @@ use crate::vm_with_bootloader::{ OPERATOR_REFUNDS_OFFSET, }; -pub type ZkSyncVmState<'a, S> = VmState< - 'a, +pub type ZkSyncVmState = VmState< StorageOracle, SimpleMemory, InMemoryEventSink, @@ -79,9 +78,9 @@ pub enum MultiVMSubversion { } #[derive(Debug)] -pub struct VmInstance<'a, S: Storage> { +pub struct VmInstance { pub gas_limit: u32, - pub state: ZkSyncVmState<'a, S>, + pub state: ZkSyncVmState, pub execution_mode: TxExecutionMode, pub block_context: DerivedBlockContext, pub(crate) bootloader_state: BootloaderState, @@ -188,7 +187,7 @@ fn vm_may_have_ended_inner( vm.local_state.callstack.get_current_stack().pc.as_u64(), ) { (true, 0) => { - let returndata = dump_memory_page_using_primitive_value(vm.memory, r1); + let returndata = dump_memory_page_using_primitive_value(&vm.memory, r1); Some(NewVmExecutionResult::Ok(returndata)) } @@ -198,7 +197,7 @@ fn vm_may_have_ended_inner( if vm.local_state.flags.overflow_or_less_than_flag { Some(NewVmExecutionResult::Panic) } else { - let returndata = dump_memory_page_using_primitive_value(vm.memory, r1); + let returndata = dump_memory_page_using_primitive_value(&vm.memory, r1); Some(NewVmExecutionResult::Revert(returndata)) } } @@ -319,7 +318,7 @@ pub struct VmSnapshot { bootloader_state: BootloaderState, } -impl<'a, S: Storage> VmInstance<'a, S> { +impl VmInstance { fn has_ended(&self) -> bool { match vm_may_have_ended_inner(&self.state) { None | Some(NewVmExecutionResult::MostLikelyDidNotFinish(_, _)) => false, @@ -858,7 +857,7 @@ impl<'a, S: Storage> VmInstance<'a, S> { // Reads the bootloader memory and checks whether the execution step of the transaction // has failed. -pub(crate) fn tx_has_failed(state: &ZkSyncVmState<'_, S>, tx_id: u32) -> bool { +pub(crate) fn tx_has_failed(state: &ZkSyncVmState, tx_id: u32) -> bool { let mem_slot = RESULT_SUCCESS_FIRST_SLOT + tx_id; let mem_value = state .memory diff --git a/core/multivm_deps/vm_m5/src/vm_with_bootloader.rs b/core/multivm_deps/vm_m5/src/vm_with_bootloader.rs index d0918ad1faf3..f8398729f9f1 100644 --- a/core/multivm_deps/vm_m5/src/vm_with_bootloader.rs +++ b/core/multivm_deps/vm_m5/src/vm_with_bootloader.rs @@ -177,14 +177,14 @@ impl Default for TxExecutionMode { } } -pub fn init_vm<'a, S: Storage>( +pub fn init_vm( refund_state: MultiVMSubversion, - oracle_tools: &'a mut OracleTools, + oracle_tools: OracleTools, block_context: BlockContextMode, - block_properties: &'a BlockProperties, + block_properties: BlockProperties, execution_mode: TxExecutionMode, base_system_contract: &BaseSystemContracts, -) -> Box> { +) -> Box> { init_vm_with_gas_limit( refund_state, oracle_tools, @@ -196,15 +196,15 @@ pub fn init_vm<'a, S: Storage>( ) } -pub fn init_vm_with_gas_limit<'a, S: Storage>( +pub fn init_vm_with_gas_limit( refund_state: MultiVMSubversion, - oracle_tools: &'a mut OracleTools, + oracle_tools: OracleTools, block_context: BlockContextMode, - block_properties: &'a BlockProperties, + block_properties: BlockProperties, execution_mode: TxExecutionMode, base_system_contract: &BaseSystemContracts, gas_limit: u32, -) -> Box> { +) -> Box> { init_vm_inner( refund_state, oracle_tools, @@ -293,15 +293,15 @@ impl BlockContextMode { // This method accepts a custom bootloader code. // It should be used only in tests. -pub fn init_vm_inner<'a, S: Storage>( +pub fn init_vm_inner( refund_state: MultiVMSubversion, - oracle_tools: &'a mut OracleTools, + mut oracle_tools: OracleTools, block_context: BlockContextMode, - block_properties: &'a BlockProperties, + block_properties: BlockProperties, gas_limit: u32, base_system_contract: &BaseSystemContracts, execution_mode: TxExecutionMode, -) -> Box> { +) -> Box> { oracle_tools.decommittment_processor.populate( vec![( h256_to_u256(base_system_contract.default_aa.hash), @@ -470,18 +470,18 @@ pub(crate) fn get_bootloader_memory_for_encoded_tx( memory } -fn get_default_local_state<'a, S: Storage>( - tools: &'a mut OracleTools, - block_properties: &'a BlockProperties, +fn get_default_local_state( + tools: OracleTools, + block_properties: BlockProperties, gas_limit: u32, -) -> ZkSyncVmState<'a, S> { +) -> ZkSyncVmState { let mut vm = VmState::empty_state( - &mut tools.storage, - &mut tools.memory, - &mut tools.event_sink, - &mut tools.precompiles_processor, - &mut tools.decommittment_processor, - &mut tools.witness_tracer, + tools.storage, + tools.memory, + tools.event_sink, + tools.precompiles_processor, + tools.decommittment_processor, + tools.witness_tracer, block_properties, ); diff --git a/core/multivm_deps/vm_m6/Cargo.toml b/core/multivm_deps/vm_m6/Cargo.toml index a22bdd755c03..9b4093a7cdb6 100644 --- a/core/multivm_deps/vm_m6/Cargo.toml +++ b/core/multivm_deps/vm_m6/Cargo.toml @@ -18,7 +18,7 @@ zksync_config = { path = "../../lib/config" } zksync_state = { path = "../../lib/state" } zksync_storage = { path = "../../lib/storage" } -zk_evm = { git = "https://github.com/matter-labs/era-zk_evm.git", tag = "v1.3.1-rc0" } +zk_evm = { git = "https://github.com/matter-labs/era-zk_evm.git", tag = "v1.3.1-rc1" } zksync_contracts = { path = "../../lib/contracts" } hex = "0.4" diff --git a/core/multivm_deps/vm_m6/src/pubdata_utils.rs b/core/multivm_deps/vm_m6/src/pubdata_utils.rs index 8f7348b53f29..721f5925f1d1 100644 --- a/core/multivm_deps/vm_m6/src/pubdata_utils.rs +++ b/core/multivm_deps/vm_m6/src/pubdata_utils.rs @@ -11,7 +11,7 @@ use zksync_types::zkevm_test_harness::witness::sort_storage_access::sort_storage use zksync_types::{StorageKey, PUBLISH_BYTECODE_OVERHEAD, SYSTEM_CONTEXT_ADDRESS}; use zksync_utils::bytecode::bytecode_len_in_bytes; -impl VmInstance<'_, S, H> { +impl VmInstance { pub fn pubdata_published(&self, from_timestamp: Timestamp) -> u32 { let storage_writes_pubdata_published = self.pubdata_published_for_writes(from_timestamp); diff --git a/core/multivm_deps/vm_m6/src/refunds.rs b/core/multivm_deps/vm_m6/src/refunds.rs index d61e46c4520d..f3aba742521f 100644 --- a/core/multivm_deps/vm_m6/src/refunds.rs +++ b/core/multivm_deps/vm_m6/src/refunds.rs @@ -8,7 +8,7 @@ use zk_evm::aux_structures::Timestamp; use zksync_types::U256; use zksync_utils::ceil_div_u256; -impl VmInstance<'_, S, H> { +impl VmInstance { pub(crate) fn tx_body_refund( &self, from_timestamp: Timestamp, diff --git a/core/multivm_deps/vm_m6/src/test_utils.rs b/core/multivm_deps/vm_m6/src/test_utils.rs index 7d7b98685ef1..5b881f3ade52 100644 --- a/core/multivm_deps/vm_m6/src/test_utils.rs +++ b/core/multivm_deps/vm_m6/src/test_utils.rs @@ -91,7 +91,7 @@ pub struct VmInstanceInnerState { local_state: VmLocalState, } -impl VmInstance<'_, S, H> { +impl VmInstance { /// This method is mostly to be used in tests. It dumps the inner state of all the oracles and the VM itself. pub fn dump_inner_state(&self) -> VmInstanceInnerState { let event_sink = self.state.event_sink.clone(); diff --git a/core/multivm_deps/vm_m6/src/utils.rs b/core/multivm_deps/vm_m6/src/utils.rs index cac347f00a67..ff6181561393 100644 --- a/core/multivm_deps/vm_m6/src/utils.rs +++ b/core/multivm_deps/vm_m6/src/utils.rs @@ -267,7 +267,7 @@ pub(crate) fn calculate_computational_gas_used< T: PubdataSpentTracer, H: HistoryMode, >( - vm: &VmInstance<'_, S, H>, + vm: &VmInstance, tracer: &T, gas_remaining_before: u32, spent_pubdata_counter_before: u32, diff --git a/core/multivm_deps/vm_m6/src/vm.rs b/core/multivm_deps/vm_m6/src/vm.rs index 956d474cd4a2..92ef020ba0f4 100644 --- a/core/multivm_deps/vm_m6/src/vm.rs +++ b/core/multivm_deps/vm_m6/src/vm.rs @@ -39,8 +39,7 @@ use crate::vm_with_bootloader::{ OPERATOR_REFUNDS_OFFSET, }; -pub type ZkSyncVmState<'a, S, H> = VmState< - 'a, +pub type ZkSyncVmState = VmState< StorageOracle, SimpleMemory, InMemoryEventSink, @@ -81,9 +80,9 @@ pub enum MultiVMSubversion { } #[derive(Debug)] -pub struct VmInstance<'a, S: Storage, H: HistoryMode> { +pub struct VmInstance { pub gas_limit: u32, - pub state: ZkSyncVmState<'a, S, H>, + pub state: ZkSyncVmState, pub execution_mode: TxExecutionMode, pub block_context: DerivedBlockContext, pub(crate) bootloader_state: BootloaderState, @@ -185,7 +184,7 @@ fn vm_may_have_ended_inner( vm.local_state.callstack.get_current_stack().pc.as_u64(), ) { (true, 0) => { - let returndata = dump_memory_page_using_primitive_value(vm.memory, r1); + let returndata = dump_memory_page_using_primitive_value(&vm.memory, r1); Some(NewVmExecutionResult::Ok(returndata)) } @@ -195,7 +194,7 @@ fn vm_may_have_ended_inner( if vm.local_state.flags.overflow_or_less_than_flag { Some(NewVmExecutionResult::Panic) } else { - let returndata = dump_memory_page_using_primitive_value(vm.memory, r1); + let returndata = dump_memory_page_using_primitive_value(&vm.memory, r1); Some(NewVmExecutionResult::Revert(returndata)) } } @@ -327,7 +326,7 @@ pub struct VmSnapshot { bootloader_state: BootloaderState, } -impl VmInstance<'_, S, H> { +impl VmInstance { fn has_ended(&self) -> bool { match vm_may_have_ended_inner(&self.state) { None | Some(NewVmExecutionResult::MostLikelyDidNotFinish(_, _)) => false, @@ -924,7 +923,7 @@ impl VmInstance<'_, S, H> { } } -impl VmInstance<'_, S, HistoryEnabled> { +impl VmInstance { /// Saves the snapshot of the current state of the VM that can be used /// to roll back its state later on. pub fn save_current_vm_as_snapshot(&mut self) { @@ -986,7 +985,7 @@ impl VmInstance<'_, S, HistoryEnabled> { // Reads the bootloader memory and checks whether the execution step of the transaction // has failed. pub(crate) fn tx_has_failed( - state: &ZkSyncVmState<'_, S, H>, + state: &ZkSyncVmState, tx_id: u32, ) -> bool { let mem_slot = RESULT_SUCCESS_FIRST_SLOT + tx_id; diff --git a/core/multivm_deps/vm_m6/src/vm_with_bootloader.rs b/core/multivm_deps/vm_m6/src/vm_with_bootloader.rs index a8e2440276ff..7362c9363780 100644 --- a/core/multivm_deps/vm_m6/src/vm_with_bootloader.rs +++ b/core/multivm_deps/vm_m6/src/vm_with_bootloader.rs @@ -212,14 +212,14 @@ impl Default for TxExecutionMode { } } -pub fn init_vm<'a, S: Storage, H: HistoryMode>( +pub fn init_vm( vm_subversion: MultiVMSubversion, - oracle_tools: &'a mut OracleTools, + oracle_tools: OracleTools, block_context: BlockContextMode, - block_properties: &'a BlockProperties, + block_properties: BlockProperties, execution_mode: TxExecutionMode, base_system_contract: &BaseSystemContracts, -) -> Box> { +) -> Box> { init_vm_with_gas_limit( vm_subversion, oracle_tools, @@ -231,15 +231,15 @@ pub fn init_vm<'a, S: Storage, H: HistoryMode>( ) } -pub fn init_vm_with_gas_limit<'a, S: Storage, H: HistoryMode>( +pub fn init_vm_with_gas_limit( vm_subversion: MultiVMSubversion, - oracle_tools: &'a mut OracleTools, + oracle_tools: OracleTools, block_context: BlockContextMode, - block_properties: &'a BlockProperties, + block_properties: BlockProperties, execution_mode: TxExecutionMode, base_system_contract: &BaseSystemContracts, gas_limit: u32, -) -> Box> { +) -> Box> { init_vm_inner( vm_subversion, oracle_tools, @@ -328,15 +328,15 @@ impl BlockContextMode { // This method accepts a custom bootloader code. // It should be used only in tests. -pub fn init_vm_inner<'a, S: Storage, H: HistoryMode>( +pub fn init_vm_inner( vm_subversion: MultiVMSubversion, - oracle_tools: &'a mut OracleTools, + mut oracle_tools: OracleTools, block_context: BlockContextMode, - block_properties: &'a BlockProperties, + block_properties: BlockProperties, gas_limit: u32, base_system_contract: &BaseSystemContracts, execution_mode: TxExecutionMode, -) -> Box> { +) -> Box> { oracle_tools.decommittment_processor.populate( vec![( h256_to_u256(base_system_contract.default_aa.hash), @@ -799,18 +799,18 @@ pub(crate) fn get_bootloader_memory_for_encoded_tx( memory } -fn get_default_local_state<'a, S: Storage, H: HistoryMode>( - tools: &'a mut OracleTools, - block_properties: &'a BlockProperties, +fn get_default_local_state( + tools: OracleTools, + block_properties: BlockProperties, gas_limit: u32, -) -> ZkSyncVmState<'a, S, H> { +) -> ZkSyncVmState { let mut vm = VmState::empty_state( - &mut tools.storage, - &mut tools.memory, - &mut tools.event_sink, - &mut tools.precompiles_processor, - &mut tools.decommittment_processor, - &mut tools.witness_tracer, + tools.storage, + tools.memory, + tools.event_sink, + tools.precompiles_processor, + tools.decommittment_processor, + tools.witness_tracer, block_properties, ); // Override ergs limit for the initial frame.