diff --git a/core/lib/multivm/src/lib.rs b/core/lib/multivm/src/lib.rs index 170a9f821a5..b4ec4a38582 100644 --- a/core/lib/multivm/src/lib.rs +++ b/core/lib/multivm/src/lib.rs @@ -12,8 +12,8 @@ pub use crate::{ tracers::{MultiVMTracer, MultiVmTracerPointer}, }, versions::{ - vm_1_3_2, vm_1_4_1, vm_1_4_2, vm_boojum_integration, vm_fast, vm_latest, vm_m5, vm_m6, - vm_refunds_enhancement, vm_virtual_blocks, era_vm, + era_vm, vm_1_3_2, vm_1_4_1, vm_1_4_2, vm_boojum_integration, vm_fast, vm_latest, vm_m5, + vm_m6, vm_refunds_enhancement, vm_virtual_blocks, }, vm_instance::VmInstance, }; diff --git a/core/lib/multivm/src/versions/era_vm/snapshot.rs b/core/lib/multivm/src/versions/era_vm/snapshot.rs index 092522eb944..b172a6fcab3 100644 --- a/core/lib/multivm/src/versions/era_vm/snapshot.rs +++ b/core/lib/multivm/src/versions/era_vm/snapshot.rs @@ -25,7 +25,7 @@ pub(crate) struct L2BlockSnapshot { } pub struct VmSnapshot { - state: era_vm::VMState, + execution: era_vm::execution::Execution, // TODO: Implement snapshots in era vm // world_snapshot: vm2::ExternalSnapshot, diff --git a/core/lib/multivm/src/versions/era_vm/vm.rs b/core/lib/multivm/src/versions/era_vm/vm.rs index 9343664b066..402be9c6dac 100644 --- a/core/lib/multivm/src/versions/era_vm/vm.rs +++ b/core/lib/multivm/src/versions/era_vm/vm.rs @@ -1,12 +1,12 @@ -use std::{cell::RefCell, collections::HashMap, fmt::Write, io::Read, rc::Rc, str::FromStr}; +use std::{cell::RefCell, collections::HashMap, rc::Rc}; use era_vm::{ - store::{L2ToL1Log, StorageError, StorageKey as EraStorageKey}, + state::{L2ToL1Log, VMState}, + store::{StorageError, StorageKey as EraStorageKey}, vm::ExecutionOutput, - EraVM, VMState, + EraVM, Execution, }; -use once_cell::sync::Lazy; -use zksync_state::{InMemoryStorage, ReadStorage, StoragePtr, StorageView, WriteStorage}; +use zksync_state::{ReadStorage, StoragePtr}; use zksync_types::{ l1::is_l1_tx_type, AccountTreeId, StorageKey, Transaction, BOOTLOADER_ADDRESS, H160, KNOWN_CODES_STORAGE_ADDRESS, U256, @@ -25,13 +25,15 @@ use super::{ }; use crate::{ era_vm::{bytecode::compress_bytecodes, transaction_data::TransactionData}, - interface::{Halt, TxRevertReason, VmFactory, VmInterface, VmInterfaceHistoryEnabled, VmRevertReason}, + interface::{ + Halt, TxRevertReason, VmFactory, VmInterface, VmInterfaceHistoryEnabled, VmRevertReason, + }, vm_latest::{ constants::{ get_vm_hook_position, get_vm_hook_start_position_latest, VM_HOOK_PARAMS_COUNT, }, - BootloaderMemory, CurrentExecutionState, ExecutionResult, HistoryEnabled, L1BatchEnv, - L2BlockEnv, SystemEnv, VmExecutionLogs, VmExecutionMode, VmExecutionResultAndLogs, + BootloaderMemory, CurrentExecutionState, ExecutionResult, L1BatchEnv, L2BlockEnv, + SystemEnv, VmExecutionLogs, VmExecutionMode, VmExecutionResultAndLogs, }, }; @@ -66,7 +68,7 @@ impl VmFactory for Vm { let vm_hook_position = get_vm_hook_position(crate::vm_latest::MultiVMSubversion::IncreasedBootloaderMemory) * 32; - let vm_state = VMState::new( + let vm_execution = Execution::new( bootloader_code.to_owned(), Vec::new(), BOOTLOADER_ADDRESS, @@ -87,12 +89,7 @@ impl VmFactory for Vm { ); let pre_contract_storage = Rc::new(RefCell::new(HashMap::new())); pre_contract_storage.borrow_mut().insert( - h256_to_u256( - system_env - .base_system_smart_contracts - .default_aa - .hash, - ), + h256_to_u256(system_env.base_system_smart_contracts.default_aa.hash), system_env .base_system_smart_contracts .default_aa @@ -102,7 +99,7 @@ impl VmFactory for Vm { let world_storage1 = World::new(storage.clone(), pre_contract_storage.clone()); let world_storage2 = World::new(storage.clone(), pre_contract_storage.clone()); let mut vm = EraVM::new( - vm_state, + vm_execution, Rc::new(RefCell::new(world_storage1)), Rc::new(RefCell::new(world_storage2)), ); @@ -111,22 +108,21 @@ impl VmFactory for Vm { // The bootloader shouldn't pay for growing memory and it writes results // to the end of its heap, so it makes sense to preallocate it in its entirety. const BOOTLOADER_MAX_MEMORY_SIZE: u32 = 59000000; - vm.state + vm.execution .heaps - .get_mut(era_vm::state::FIRST_HEAP) + .get_mut(era_vm::execution::FIRST_HEAP) .unwrap() .expand_memory(BOOTLOADER_MAX_MEMORY_SIZE); - vm.state + vm.execution .heaps - .get_mut(era_vm::state::FIRST_HEAP + 1) + .get_mut(era_vm::execution::FIRST_HEAP + 1) .unwrap() .expand_memory(BOOTLOADER_MAX_MEMORY_SIZE); let mut mv = Self { inner: vm, suspended_at: 0, - gas_for_account_validation: system_env - .default_validation_computational_gas_limit, + gas_for_account_validation: system_env.default_validation_computational_gas_limit, last_tx_result: None, bootloader_state: BootloaderState::new( system_env.execution_mode.clone(), @@ -143,7 +139,6 @@ impl VmFactory for Vm { mv.write_to_bootloader_heap(bootloader_memory); mv } - } impl Vm { @@ -160,7 +155,7 @@ impl Vm { }, ExecutionOutput::Panic => { return ExecutionResult::Halt { - reason: if self.inner.state.gas_left().unwrap() == 0 { + reason: if self.inner.execution.gas_left().unwrap() == 0 { Halt::BootloaderOutOfGas } else { Halt::VMPanic @@ -226,9 +221,9 @@ impl Vm { Hook::DebugLog => { let heap = self .inner - .state + .execution .heaps - .get(self.inner.state.current_context().unwrap().heap_id) + .get(self.inner.execution.current_context().unwrap().heap_id) .unwrap(); let vm_hook_params: Vec<_> = self .get_vm_hook_params(heap) @@ -254,16 +249,18 @@ impl Vm { } Hook::TxHasEnded => { // println!("TX HAS ENDED"); - if let (VmExecutionMode::OneTx, Some(result)) = (execution_mode, self.last_tx_result.take()) { + if let (VmExecutionMode::OneTx, Some(result)) = + (execution_mode, self.last_tx_result.take()) + { return result; } } } - self.inner.state.current_frame_mut().unwrap().pc = self.suspended_at as u64; + self.inner.execution.current_frame_mut().unwrap().pc = self.suspended_at as u64; } } - fn get_vm_hook_params(&self, heap: &era_vm::state::Heap) -> Vec { + fn get_vm_hook_params(&self, heap: &era_vm::execution::Heap) -> Vec { (get_vm_hook_start_position_latest()..get_vm_hook_start_position_latest() + 2) .map(|word| { let res = heap.read((word * 32) as u32); @@ -310,26 +307,26 @@ impl Vm { fn read_heap_word(&self, word: usize) -> U256 { let heap = self .inner - .state + .execution .heaps - .get(self.inner.state.current_context().unwrap().heap_id) + .get(self.inner.execution.current_context().unwrap().heap_id) .unwrap(); heap.read((word * 32) as u32) } #[cfg(test)] /// Returns the current state of the VM in a format that can be compared for equality. - pub(crate) fn dump_state(&self) -> VMState { - self.inner.state.clone() + pub(crate) fn dump_state(&self) -> Execution { + self.inner.execution.clone() } fn write_to_bootloader_heap(&mut self, memory: impl IntoIterator) { - assert!(self.inner.state.running_contexts.len() == 1); // No on-going far calls + assert!(self.inner.execution.running_contexts.len() == 1); // No on-going far calls if let Some(heap) = &mut self .inner - .state + .execution .heaps - .get_mut(self.inner.state.current_context().unwrap().heap_id) + .get_mut(self.inner.execution.current_context().unwrap().heap_id) { for (slot, value) in memory { let end = (slot + 1) * 32; @@ -355,7 +352,7 @@ impl VmInterface for Vm { } else { compress_bytecodes(&tx.factory_deps, |hash| { self.inner - .state_storage + .state .storage_read(EraStorageKey::new( KNOWN_CODES_STORAGE_ADDRESS, h256_to_u256(hash), @@ -400,7 +397,7 @@ impl VmInterface for Vm { result, logs: VmExecutionLogs { storage_logs: Default::default(), - events: merge_events(&self.inner.state.events, self.batch_env.number), + events: merge_events(self.inner.state.events(), self.batch_env.number), user_l2_to_l1_logs: Default::default(), system_l2_to_l1_logs: Default::default(), total_log_queries_count: 0, // This field is unused @@ -443,7 +440,7 @@ impl VmInterface for Vm { } fn gas_remaining(&self) -> u32 { - self.inner.state.current_frame().unwrap().gas_left.0 + self.inner.execution.current_frame().unwrap().gas_left.0 } } @@ -535,7 +532,6 @@ impl era_vm::store::ContractStorage for World { #[cfg(test)] mod tests { - use super::*; use std::{cell::RefCell, path::PathBuf, rc::Rc}; use once_cell::sync::Lazy; @@ -554,6 +550,7 @@ mod tests { }; use zksync_utils::bytecode::hash_bytecode; + use super::*; use crate::{ era_vm::vm::Vm, interface::{ diff --git a/core/lib/multivm/src/versions/mod.rs b/core/lib/multivm/src/versions/mod.rs index da3cdaea1a2..6708f5512eb 100644 --- a/core/lib/multivm/src/versions/mod.rs +++ b/core/lib/multivm/src/versions/mod.rs @@ -1,5 +1,5 @@ -pub mod shadow; pub mod era_vm; +pub mod shadow; pub mod vm_1_3_2; pub mod vm_1_4_1; pub mod vm_1_4_2;