From 3609ea6f1b6d767c0f1d64a9303f0331db920931 Mon Sep 17 00:00:00 2001 From: Alex Ostrovski Date: Thu, 12 Sep 2024 18:43:53 +0300 Subject: [PATCH] chore(vm): Bump `zksync_vm2` revision (#2838) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## What ❔ Updates the fast VM revision to incorporate latest changes. ## Why ❔ Mainly to check that these changes work. ## Checklist - [x] PR title corresponds to the body of PR (we generate changelog entries from PRs). - [x] Tests for the changes have been added / updated. - [x] Code has been formatted via `zk fmt` and `zk lint`. --- Cargo.lock | 42 ++++----- Cargo.toml | 2 +- core/lib/multivm/Cargo.toml | 2 +- .../src/versions/vm_fast/circuits_tracer.rs | 2 +- .../multivm/src/versions/vm_fast/events.rs | 2 +- core/lib/multivm/src/versions/vm_fast/glue.rs | 6 +- .../src/versions/vm_fast/tests/bootloader.rs | 6 +- .../src/versions/vm_fast/tests/code_oracle.rs | 2 +- .../src/versions/vm_fast/tests/default_aa.rs | 4 +- .../src/versions/vm_fast/tests/gas_limit.rs | 2 +- .../versions/vm_fast/tests/l1_tx_execution.rs | 2 +- .../versions/vm_fast/tests/require_eip712.rs | 2 +- .../src/versions/vm_fast/tests/rollbacks.rs | 2 +- .../tests/tester/transaction_test_info.rs | 18 ++-- .../vm_fast/tests/tester/vm_tester.rs | 6 +- .../src/versions/vm_fast/tests/transfer.rs | 2 +- .../src/versions/vm_fast/tests/upgrade.rs | 4 +- .../src/versions/vm_fast/tests/utils.rs | 8 +- core/lib/multivm/src/versions/vm_fast/vm.rs | 90 +++++++++++-------- prover/Cargo.lock | 42 ++++----- .../src/gpu_prover_job_processor.rs | 5 +- 21 files changed, 133 insertions(+), 118 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9d7b19b424b..59b464f8501 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2177,14 +2177,6 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" -[[package]] -name = "eravm-stable-interface" -version = "0.1.0" -source = "git+https://github.com/matter-labs/vm2.git?rev=4ef15d46410ffc11744771a3a6c7c09dd9470c90#4ef15d46410ffc11744771a3a6c7c09dd9470c90" -dependencies = [ - "primitive-types", -] - [[package]] name = "errno" version = "0.3.9" @@ -8356,18 +8348,6 @@ dependencies = [ "zksync_vlog", ] -[[package]] -name = "vm2" -version = "0.1.0" -source = "git+https://github.com/matter-labs/vm2.git?rev=4ef15d46410ffc11744771a3a6c7c09dd9470c90#4ef15d46410ffc11744771a3a6c7c09dd9470c90" -dependencies = [ - "enum_dispatch", - "eravm-stable-interface", - "primitive-types", - "zk_evm_abstractions 0.150.5", - "zkevm_opcode_defs 0.150.5", -] - [[package]] name = "walkdir" version = "2.4.0" @@ -10156,7 +10136,6 @@ dependencies = [ "tokio", "tracing", "vise", - "vm2", "zk_evm 0.131.0-rc.2", "zk_evm 0.133.0", "zk_evm 0.140.0", @@ -10168,6 +10147,7 @@ dependencies = [ "zksync_test_account", "zksync_types", "zksync_utils", + "zksync_vm2", "zksync_vm_interface", ] @@ -10966,6 +10946,26 @@ dependencies = [ "vise-exporter", ] +[[package]] +name = "zksync_vm2" +version = "0.1.0" +source = "git+https://github.com/matter-labs/vm2.git?rev=cd6136c42ec56856e0abcf2a98d1a9e120161482#cd6136c42ec56856e0abcf2a98d1a9e120161482" +dependencies = [ + "enum_dispatch", + "primitive-types", + "zk_evm_abstractions 0.150.5", + "zkevm_opcode_defs 0.150.5", + "zksync_vm2_interface", +] + +[[package]] +name = "zksync_vm2_interface" +version = "0.1.0" +source = "git+https://github.com/matter-labs/vm2.git?rev=cd6136c42ec56856e0abcf2a98d1a9e120161482#cd6136c42ec56856e0abcf2a98d1a9e120161482" +dependencies = [ + "primitive-types", +] + [[package]] name = "zksync_vm_executor" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index 6ee04692d8c..5eb862f0bcb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -226,7 +226,7 @@ zk_evm_1_4_1 = { package = "zk_evm", version = "0.141" } zk_evm_1_5_0 = { package = "zk_evm", version = "=0.150.5" } # New VM; pinned to a specific commit because of instability -vm2 = { git = "https://github.com/matter-labs/vm2.git", rev = "4ef15d46410ffc11744771a3a6c7c09dd9470c90" } +zksync_vm2 = { git = "https://github.com/matter-labs/vm2.git", rev = "cd6136c42ec56856e0abcf2a98d1a9e120161482" } # Consensus dependencies. zksync_concurrency = "=0.1.1" diff --git a/core/lib/multivm/Cargo.toml b/core/lib/multivm/Cargo.toml index 4711eefa0d6..5e76c10f53e 100644 --- a/core/lib/multivm/Cargo.toml +++ b/core/lib/multivm/Cargo.toml @@ -16,7 +16,7 @@ zk_evm_1_4_1.workspace = true zk_evm_1_4_0.workspace = true zk_evm_1_3_3.workspace = true zk_evm_1_3_1.workspace = true -vm2.workspace = true +zksync_vm2.workspace = true circuit_sequencer_api_1_3_3.workspace = true circuit_sequencer_api_1_4_0.workspace = true diff --git a/core/lib/multivm/src/versions/vm_fast/circuits_tracer.rs b/core/lib/multivm/src/versions/vm_fast/circuits_tracer.rs index 061d91be60b..de6ead71e65 100644 --- a/core/lib/multivm/src/versions/vm_fast/circuits_tracer.rs +++ b/core/lib/multivm/src/versions/vm_fast/circuits_tracer.rs @@ -1,5 +1,5 @@ use circuit_sequencer_api_1_5_0::{geometry_config::get_geometry_config, toolset::GeometryConfig}; -use vm2::{CycleStats, Opcode, OpcodeType, StateInterface, Tracer}; +use zksync_vm2::{CycleStats, Opcode, OpcodeType, StateInterface, Tracer}; use zksync_vm_interface::CircuitStatistic; use crate::vm_latest::tracers::circuits_capacity::*; diff --git a/core/lib/multivm/src/versions/vm_fast/events.rs b/core/lib/multivm/src/versions/vm_fast/events.rs index 798a1e12bdd..2312c3d97b4 100644 --- a/core/lib/multivm/src/versions/vm_fast/events.rs +++ b/core/lib/multivm/src/versions/vm_fast/events.rs @@ -1,6 +1,6 @@ -use vm2::Event; use zksync_types::{L1BatchNumber, H256}; use zksync_utils::h256_to_account_address; +use zksync_vm2::Event; use crate::interface::VmEvent; diff --git a/core/lib/multivm/src/versions/vm_fast/glue.rs b/core/lib/multivm/src/versions/vm_fast/glue.rs index cbf22f9122b..f24c82af11e 100644 --- a/core/lib/multivm/src/versions/vm_fast/glue.rs +++ b/core/lib/multivm/src/versions/vm_fast/glue.rs @@ -3,9 +3,9 @@ use zksync_utils::u256_to_h256; use crate::glue::GlueFrom; -impl GlueFrom<&vm2::L2ToL1Log> for SystemL2ToL1Log { - fn glue_from(value: &vm2::L2ToL1Log) -> Self { - let vm2::L2ToL1Log { +impl GlueFrom<&zksync_vm2::L2ToL1Log> for SystemL2ToL1Log { + fn glue_from(value: &zksync_vm2::L2ToL1Log) -> Self { + let zksync_vm2::L2ToL1Log { key, value, is_service, diff --git a/core/lib/multivm/src/versions/vm_fast/tests/bootloader.rs b/core/lib/multivm/src/versions/vm_fast/tests/bootloader.rs index 8e1a273bc7b..5c1158a5909 100644 --- a/core/lib/multivm/src/versions/vm_fast/tests/bootloader.rs +++ b/core/lib/multivm/src/versions/vm_fast/tests/bootloader.rs @@ -1,5 +1,6 @@ use assert_matches::assert_matches; use zksync_types::U256; +use zksync_vm2::HeapId; use crate::{ interface::{ExecutionResult, Halt, TxExecutionMode, VmExecutionMode, VmInterfaceExt}, @@ -25,10 +26,7 @@ fn test_dummy_bootloader() { let correct_first_cell = U256::from_str_radix("123123123", 16).unwrap(); - verify_required_memory( - &vm.vm.inner.state, - vec![(correct_first_cell, vm2::FIRST_HEAP, 0)], - ); + verify_required_memory(&vm.vm.inner, vec![(correct_first_cell, HeapId::FIRST, 0)]); } #[test] diff --git a/core/lib/multivm/src/versions/vm_fast/tests/code_oracle.rs b/core/lib/multivm/src/versions/vm_fast/tests/code_oracle.rs index 836603d77d8..caea07617dd 100644 --- a/core/lib/multivm/src/versions/vm_fast/tests/code_oracle.rs +++ b/core/lib/multivm/src/versions/vm_fast/tests/code_oracle.rs @@ -210,7 +210,7 @@ fn refunds_in_code_oracle() { let account = &mut vm.rich_accounts[0]; if decommit { - let (_, is_fresh) = vm.vm.inner.world_diff.decommit_opcode( + let (_, is_fresh) = vm.vm.inner.world_diff_mut().decommit_opcode( &mut vm.vm.world, &mut CircuitsTracer::default(), h256_to_u256(normal_zkevm_bytecode_hash), diff --git a/core/lib/multivm/src/versions/vm_fast/tests/default_aa.rs b/core/lib/multivm/src/versions/vm_fast/tests/default_aa.rs index f809af81b16..c2ce02d39fe 100644 --- a/core/lib/multivm/src/versions/vm_fast/tests/default_aa.rs +++ b/core/lib/multivm/src/versions/vm_fast/tests/default_aa.rs @@ -61,7 +61,7 @@ fn test_default_aa_interaction() { verify_required_storage( &expected_slots, &mut vm.vm.world.storage, - vm.vm.inner.world_diff.get_storage_state(), + vm.vm.inner.world_diff().get_storage_state(), ); let expected_fee = maximal_fee @@ -71,7 +71,7 @@ fn test_default_aa_interaction() { AccountTreeId::new(L2_BASE_TOKEN_ADDRESS), &vm.fee_account, &mut vm.vm.world.storage, - vm.vm.inner.world_diff.get_storage_state(), + vm.vm.inner.world_diff().get_storage_state(), ); assert_eq!( diff --git a/core/lib/multivm/src/versions/vm_fast/tests/gas_limit.rs b/core/lib/multivm/src/versions/vm_fast/tests/gas_limit.rs index e0c55c5a685..b7a2154bdc7 100644 --- a/core/lib/multivm/src/versions/vm_fast/tests/gas_limit.rs +++ b/core/lib/multivm/src/versions/vm_fast/tests/gas_limit.rs @@ -27,7 +27,7 @@ fn test_tx_gas_limit_offset() { vm.vm.push_transaction(tx); - assert!(vm.vm.inner.state.previous_frames.is_empty()); + assert!(!vm.vm.has_previous_far_calls()); let gas_limit_from_memory = vm .vm .read_word_from_bootloader_heap(TX_DESCRIPTION_OFFSET + TX_GAS_LIMIT_OFFSET); diff --git a/core/lib/multivm/src/versions/vm_fast/tests/l1_tx_execution.rs b/core/lib/multivm/src/versions/vm_fast/tests/l1_tx_execution.rs index f1399a1b4e6..3b58565098d 100644 --- a/core/lib/multivm/src/versions/vm_fast/tests/l1_tx_execution.rs +++ b/core/lib/multivm/src/versions/vm_fast/tests/l1_tx_execution.rs @@ -82,7 +82,7 @@ fn test_l1_tx_execution() { ] { assert_eq!( expected_value, - vm.vm.inner.world_diff.get_storage_state()[&( + vm.vm.inner.world_diff().get_storage_state()[&( *storage_location.address(), h256_to_u256(*storage_location.key()) )] diff --git a/core/lib/multivm/src/versions/vm_fast/tests/require_eip712.rs b/core/lib/multivm/src/versions/vm_fast/tests/require_eip712.rs index fe94189ed7c..68e49b202a9 100644 --- a/core/lib/multivm/src/versions/vm_fast/tests/require_eip712.rs +++ b/core/lib/multivm/src/versions/vm_fast/tests/require_eip712.rs @@ -26,7 +26,7 @@ impl VmTester { ); self.vm .inner - .world_diff + .world_diff() .get_storage_state() .get(&(L2_BASE_TOKEN_ADDRESS, h256_to_u256(*key.key()))) .copied() diff --git a/core/lib/multivm/src/versions/vm_fast/tests/rollbacks.rs b/core/lib/multivm/src/versions/vm_fast/tests/rollbacks.rs index c530c5af18e..a677a61c602 100644 --- a/core/lib/multivm/src/versions/vm_fast/tests/rollbacks.rs +++ b/core/lib/multivm/src/versions/vm_fast/tests/rollbacks.rs @@ -56,7 +56,7 @@ fn test_vm_rollbacks() { TransactionTestInfo::new_rejected(tx_0, TxModifier::NonceReused.into()), ]); - assert_eq!(result_without_rollbacks, result_with_rollbacks); + pretty_assertions::assert_eq!(result_without_rollbacks, result_with_rollbacks); } #[test] diff --git a/core/lib/multivm/src/versions/vm_fast/tests/tester/transaction_test_info.rs b/core/lib/multivm/src/versions/vm_fast/tests/tester/transaction_test_info.rs index 105bc5f2fd4..ce45390260c 100644 --- a/core/lib/multivm/src/versions/vm_fast/tests/tester/transaction_test_info.rs +++ b/core/lib/multivm/src/versions/vm_fast/tests/tester/transaction_test_info.rs @@ -1,3 +1,5 @@ +use std::fmt; + use zksync_types::{ExecuteTransactionCommon, Transaction, H160, U256}; use super::VmTester; @@ -7,7 +9,7 @@ use crate::{ VmExecutionMode, VmExecutionResultAndLogs, VmInterface, VmInterfaceExt, VmInterfaceHistoryEnabled, VmRevertReason, }, - vm_fast::{circuits_tracer::CircuitsTracer, vm::World, Vm}, + vm_fast::Vm, }; #[derive(Debug, Clone)] @@ -186,12 +188,12 @@ impl TransactionTestInfo { // TODO this doesn't include all the state of ModifiedWorld #[derive(Debug)] struct VmStateDump { - state: vm2::State>, + state: S, storage_writes: Vec<((H160, U256), U256)>, - events: Box<[vm2::Event]>, + events: Box<[zksync_vm2::Event]>, } -impl PartialEq for VmStateDump { +impl PartialEq for VmStateDump { fn eq(&self, other: &Self) -> bool { self.state == other.state && self.storage_writes == other.storage_writes @@ -200,17 +202,17 @@ impl PartialEq for VmStateDump { } impl Vm { - fn dump_state(&self) -> VmStateDump { + fn dump_state(&self) -> VmStateDump { VmStateDump { - state: self.inner.state.clone(), + state: self.inner.dump_state(), storage_writes: self .inner - .world_diff + .world_diff() .get_storage_state() .iter() .map(|(k, v)| (*k, *v)) .collect(), - events: self.inner.world_diff.events().into(), + events: self.inner.world_diff().events().into(), } } } diff --git a/core/lib/multivm/src/versions/vm_fast/tests/tester/vm_tester.rs b/core/lib/multivm/src/versions/vm_fast/tests/tester/vm_tester.rs index 335ec752c7d..8071bcf51d4 100644 --- a/core/lib/multivm/src/versions/vm_fast/tests/tester/vm_tester.rs +++ b/core/lib/multivm/src/versions/vm_fast/tests/tester/vm_tester.rs @@ -1,6 +1,5 @@ use std::{cell::RefCell, rc::Rc}; -use vm2::WorldDiff; use zksync_contracts::BaseSystemContracts; use zksync_test_account::{Account, TxType}; use zksync_types::{ @@ -13,6 +12,7 @@ use zksync_types::{ StorageKey, U256, }; use zksync_utils::{bytecode::hash_bytecode, u256_to_h256}; +use zksync_vm2::WorldDiff; use crate::{ interface::{ @@ -53,7 +53,7 @@ impl VmTester { pub(crate) fn reset_with_empty_storage(&mut self) { self.storage = Rc::new(RefCell::new(get_empty_storage())); - self.vm.inner.world_diff = WorldDiff::default(); + *self.vm.inner.world_diff_mut() = WorldDiff::default(); self.reset_state(false); } @@ -78,7 +78,7 @@ impl VmTester { { let mut storage = storage.borrow_mut(); // Commit pending storage changes (old VM versions commit them on successful execution) - for (&(address, slot), &value) in self.vm.inner.world_diff.get_storage_state() { + for (&(address, slot), &value) in self.vm.inner.world_diff().get_storage_state() { let key = StorageKey::new(AccountTreeId::new(address), u256_to_h256(slot)); storage.set_value(key, u256_to_h256(value)); } diff --git a/core/lib/multivm/src/versions/vm_fast/tests/transfer.rs b/core/lib/multivm/src/versions/vm_fast/tests/transfer.rs index 3327012801c..57877854031 100644 --- a/core/lib/multivm/src/versions/vm_fast/tests/transfer.rs +++ b/core/lib/multivm/src/versions/vm_fast/tests/transfer.rs @@ -92,7 +92,7 @@ fn test_send_or_transfer(test_option: TestOptions) { AccountTreeId::new(L2_BASE_TOKEN_ADDRESS), &recipient_address, &mut vm.vm.world.storage, - vm.vm.inner.world_diff.get_storage_state(), + vm.vm.inner.world_diff().get_storage_state(), ); assert_eq!(new_recipient_balance, value); diff --git a/core/lib/multivm/src/versions/vm_fast/tests/upgrade.rs b/core/lib/multivm/src/versions/vm_fast/tests/upgrade.rs index f972b29cda8..dd25c209740 100644 --- a/core/lib/multivm/src/versions/vm_fast/tests/upgrade.rs +++ b/core/lib/multivm/src/versions/vm_fast/tests/upgrade.rs @@ -164,7 +164,7 @@ fn test_force_deploy_upgrade() { verify_required_storage( &expected_slots, &mut *vm.storage.borrow_mut(), - vm.vm.inner.world_diff.get_storage_state(), + vm.vm.inner.world_diff().get_storage_state(), ); } @@ -223,7 +223,7 @@ fn test_complex_upgrader() { verify_required_storage( &expected_slots, &mut *vm.storage.borrow_mut(), - vm.vm.inner.world_diff.get_storage_state(), + vm.vm.inner.world_diff().get_storage_state(), ); } diff --git a/core/lib/multivm/src/versions/vm_fast/tests/utils.rs b/core/lib/multivm/src/versions/vm_fast/tests/utils.rs index d75ae12c30c..d91e1307651 100644 --- a/core/lib/multivm/src/versions/vm_fast/tests/utils.rs +++ b/core/lib/multivm/src/versions/vm_fast/tests/utils.rs @@ -2,7 +2,6 @@ use std::collections::BTreeMap; use ethabi::Contract; use once_cell::sync::Lazy; -use vm2::{instruction_handlers::HeapInterface, HeapId, State}; use zksync_contracts::{ load_contract, read_bytecode, read_zbin_bytecode, BaseSystemContracts, SystemContractCode, }; @@ -11,18 +10,19 @@ use zksync_types::{ U256, }; use zksync_utils::{bytecode::hash_bytecode, bytes_to_be_words, h256_to_u256, u256_to_h256}; +use zksync_vm2::{HeapId, StateInterface}; use crate::interface::storage::ReadStorage; pub(crate) static BASE_SYSTEM_CONTRACTS: Lazy = Lazy::new(BaseSystemContracts::load_from_disk); -pub(crate) fn verify_required_memory( - state: &State, +pub(crate) fn verify_required_memory( + state: &impl StateInterface, required_values: Vec<(U256, HeapId, u32)>, ) { for (required_value, memory_page, cell) in required_values { - let current_value = state.heaps[memory_page].read_u256(cell * 32); + let current_value = state.read_heap_u256(memory_page, cell * 32); assert_eq!(current_value, required_value); } } diff --git a/core/lib/multivm/src/versions/vm_fast/vm.rs b/core/lib/multivm/src/versions/vm_fast/vm.rs index d8816cfaf2a..5a73ce49b06 100644 --- a/core/lib/multivm/src/versions/vm_fast/vm.rs +++ b/core/lib/multivm/src/versions/vm_fast/vm.rs @@ -1,9 +1,5 @@ use std::{collections::HashMap, fmt}; -use vm2::{ - decode::decode_program, fat_pointer::FatPointer, instruction_handlers::HeapInterface, - ExecutionEnd, Program, Settings, Tracer, VirtualMachine, -}; use zk_evm_1_5_0::zkevm_opcode_defs::system_params::INITIAL_FRAME_FORMAL_EH_LOCATION; use zksync_contracts::SystemContractCode; use zksync_types::{ @@ -19,6 +15,10 @@ use zksync_types::{ L2_BASE_TOKEN_ADDRESS, U256, }; use zksync_utils::{bytecode::hash_bytecode, h256_to_u256, u256_to_h256}; +use zksync_vm2::{ + decode::decode_program, CallframeInterface, ExecutionEnd, FatPointer, HeapId, Program, + Settings, StateInterface, Tracer, VirtualMachine, +}; use super::{ bootloader_state::{BootloaderState, BootloaderStateSnapshot}, @@ -79,7 +79,7 @@ impl Vm { operator_suggested_refund: 0, }; let mut last_tx_result = None; - let mut pubdata_before = self.inner.world_diff.pubdata() as u32; + let mut pubdata_before = self.inner.world_diff().pubdata() as u32; let result = loop { let hook = match self.inner.run(&mut self.world, tracer) { @@ -93,7 +93,7 @@ impl Vm { } ExecutionEnd::Panicked => { break ExecutionResult::Halt { - reason: if self.inner.state.current_frame.gas == 0 { + reason: if self.gas_remaining() == 0 { Halt::BootloaderOutOfGas } else { Halt::VMPanic @@ -125,7 +125,7 @@ impl Vm { ) .as_u64(); - let pubdata_published = self.inner.world_diff.pubdata() as u32; + let pubdata_published = self.inner.world_diff().pubdata() as u32; refunds.operator_suggested_refund = compute_refund( &self.batch_env, @@ -161,10 +161,7 @@ impl Vm { let result = self.get_hook_params()[0]; let value = self.get_hook_params()[1]; let fp = FatPointer::from(value); - assert_eq!(fp.offset, 0); - - let return_data = self.inner.state.heaps[fp.memory_page] - .read_range_big_endian(fp.start..fp.start + fp.length); + let return_data = self.read_bytes_from_heap(fp); last_tx_result = Some(if result.is_zero() { ExecutionResult::Revert { @@ -190,7 +187,7 @@ impl Vm { } let events = - merge_events(self.inner.world_diff.events(), self.batch_env.number); + merge_events(self.inner.world_diff().events(), self.batch_env.number); let published_bytecodes = events .iter() @@ -276,7 +273,20 @@ impl Vm { /// Should only be used when the bootloader is executing (e.g., when handling hooks). pub(crate) fn read_word_from_bootloader_heap(&self, word: usize) -> U256 { - self.inner.state.heaps[vm2::FIRST_HEAP].read_u256(word as u32 * 32) + let start_address = word as u32 * 32; + self.inner.read_heap_u256(HeapId::FIRST, start_address) + } + + fn read_bytes_from_heap(&self, ptr: FatPointer) -> Vec { + assert_eq!(ptr.offset, 0); + (ptr.start..ptr.start + ptr.length) + .map(|addr| self.inner.read_heap_byte(ptr.memory_page, addr)) + .collect() + } + + pub(crate) fn has_previous_far_calls(&mut self) -> bool { + let callframe_count = self.inner.number_of_callframes(); + (1..callframe_count).any(|i| !self.inner.callframe(i).is_near_call()) } /// Should only be used when the bootloader is executing (e.g., when handling hooks). @@ -284,12 +294,15 @@ impl Vm { &mut self, memory: impl IntoIterator, ) { - assert!(self.inner.state.previous_frames.is_empty()); + assert!( + !self.has_previous_far_calls(), + "Cannot write to bootloader heap when not in root call frame" + ); + for (slot, value) in memory { + let start_address = slot as u32 * 32; self.inner - .state - .heaps - .write_u256(vm2::FIRST_HEAP, slot as u32 * 32, value); + .write_heap_u256(HeapId::FIRST, start_address, value); } } @@ -317,7 +330,7 @@ impl Vm { } else { compress_bytecodes(&tx.factory_deps, |hash| { self.inner - .world_diff + .world_diff() .get_storage_state() .get(&(KNOWN_CODES_STORAGE_ADDRESS, h256_to_u256(hash))) .map(|x| !x.is_zero()) @@ -351,7 +364,7 @@ impl Vm { } let storage = &mut self.world.storage; - let diffs = self.inner.world_diff.get_storage_changes().map( + let diffs = self.inner.world_diff().get_storage_changes().map( move |((address, key), (initial_value, final_value))| { let storage_key = StorageKey::new(AccountTreeId::new(address), u256_to_h256(key)); StateDiffRecord { @@ -375,11 +388,11 @@ impl Vm { } pub(crate) fn decommitted_hashes(&self) -> impl Iterator + '_ { - self.inner.world_diff.decommitted_hashes() + self.inner.world_diff().decommitted_hashes() } - pub(super) fn gas_remaining(&self) -> u32 { - self.inner.state.current_frame.gas + pub(super) fn gas_remaining(&mut self) -> u32 { + self.inner.current_frame().gas() } } @@ -418,12 +431,13 @@ impl Vm { }, ); - inner.state.current_frame.sp = 0; - + inner.current_frame().set_stack_pointer(0); // The bootloader writes results to high addresses in its heap, so it makes sense to preallocate it. - inner.state.current_frame.heap_size = u32::MAX; - inner.state.current_frame.aux_heap_size = u32::MAX; - inner.state.current_frame.exception_handler = INITIAL_FRAME_FORMAL_EH_LOCATION; + inner.current_frame().set_heap_bound(u32::MAX); + inner.current_frame().set_aux_heap_bound(u32::MAX); + inner + .current_frame() + .set_exception_handler(INITIAL_FRAME_FORMAL_EH_LOCATION); let mut this = Self { world: World::new(storage, program_cache), @@ -446,7 +460,7 @@ impl Vm { // visible for testing pub(super) fn get_current_execution_state(&self) -> CurrentExecutionState { - let world_diff = &self.inner.world_diff; + let world_diff = self.inner.world_diff(); let events = merge_events(world_diff.events(), self.batch_env.number); let user_l2_to_l1_logs = extract_l2tol1logs_from_l1_messenger(&events) @@ -478,7 +492,7 @@ impl Vm { } fn delete_history_if_appropriate(&mut self) { - if self.snapshot.is_none() && self.inner.state.previous_frames.is_empty() { + if self.snapshot.is_none() && !self.has_previous_far_calls() { self.inner.delete_history(); } } @@ -504,8 +518,8 @@ impl VmInterface for Vm { } let mut tracer = CircuitsTracer::default(); - let start = self.inner.world_diff.snapshot(); - let pubdata_before = self.inner.world_diff.pubdata(); + let start = self.inner.world_diff().snapshot(); + let pubdata_before = self.inner.world_diff().pubdata(); let gas_before = self.gas_remaining(); let (result, refunds) = self.run(execution_mode, &mut tracer, track_refunds); @@ -519,7 +533,7 @@ impl VmInterface for Vm { } else { let storage_logs = self .inner - .world_diff + .world_diff() .get_storage_changes_after(&start) .map(|((address, key), change)| StorageLogWithPreviousValue { log: StorageLog { @@ -535,7 +549,7 @@ impl VmInterface for Vm { }) .collect(); let events = merge_events( - self.inner.world_diff.events_after(&start), + self.inner.world_diff().events_after(&start), self.batch_env.number, ); let user_l2_to_l1_logs = extract_l2tol1logs_from_l1_messenger(&events) @@ -545,7 +559,7 @@ impl VmInterface for Vm { .collect(); let system_l2_to_l1_logs = self .inner - .world_diff + .world_diff() .l2_to_l1_logs_after(&start) .iter() .map(|x| x.glue_into()) @@ -559,7 +573,7 @@ impl VmInterface for Vm { } }; - let pubdata_after = self.inner.world_diff.pubdata(); + let pubdata_after = self.inner.world_diff().pubdata(); let circuit_statistic = tracer.circuit_statistic(); let gas_remaining = self.gas_remaining(); VmExecutionResultAndLogs { @@ -634,7 +648,7 @@ impl VmInterface for Vm { #[derive(Debug)] struct VmSnapshot { - vm_snapshot: vm2::Snapshot, + vm_snapshot: zksync_vm2::Snapshot, bootloader_snapshot: BootloaderStateSnapshot, gas_for_account_validation: u32, } @@ -744,7 +758,7 @@ impl World { } } -impl vm2::StorageInterface for World { +impl zksync_vm2::StorageInterface for World { fn read_storage(&mut self, contract: H160, key: U256) -> Option { let key = &StorageKey::new(AccountTreeId::new(contract), u256_to_h256(key)); if self.storage.is_write_initial(key) { @@ -789,7 +803,7 @@ impl vm2::StorageInterface for World { } } -impl vm2::World for World { +impl zksync_vm2::World for World { fn decommit(&mut self, hash: U256) -> Program { self.program_cache .entry(hash) diff --git a/prover/Cargo.lock b/prover/Cargo.lock index 17f27737aa2..d29f0110f21 100644 --- a/prover/Cargo.lock +++ b/prover/Cargo.lock @@ -1700,14 +1700,6 @@ dependencies = [ "serde_json", ] -[[package]] -name = "eravm-stable-interface" -version = "0.1.0" -source = "git+https://github.com/matter-labs/vm2.git?rev=4ef15d46410ffc11744771a3a6c7c09dd9470c90#4ef15d46410ffc11744771a3a6c7c09dd9470c90" -dependencies = [ - "primitive-types", -] - [[package]] name = "errno" version = "0.3.9" @@ -6544,18 +6536,6 @@ dependencies = [ "syn 2.0.66", ] -[[package]] -name = "vm2" -version = "0.1.0" -source = "git+https://github.com/matter-labs/vm2.git?rev=4ef15d46410ffc11744771a3a6c7c09dd9470c90#4ef15d46410ffc11744771a3a6c7c09dd9470c90" -dependencies = [ - "enum_dispatch", - "eravm-stable-interface", - "primitive-types", - "zk_evm_abstractions 0.150.5", - "zkevm_opcode_defs 0.150.5", -] - [[package]] name = "wait-timeout" version = "0.2.0" @@ -7690,7 +7670,6 @@ dependencies = [ "thiserror", "tracing", "vise", - "vm2", "zk_evm 0.131.0-rc.2", "zk_evm 0.133.0", "zk_evm 0.140.0", @@ -7700,6 +7679,7 @@ dependencies = [ "zksync_system_constants", "zksync_types", "zksync_utils", + "zksync_vm2", "zksync_vm_interface", ] @@ -8102,6 +8082,26 @@ dependencies = [ "vise-exporter", ] +[[package]] +name = "zksync_vm2" +version = "0.1.0" +source = "git+https://github.com/matter-labs/vm2.git?rev=cd6136c42ec56856e0abcf2a98d1a9e120161482#cd6136c42ec56856e0abcf2a98d1a9e120161482" +dependencies = [ + "enum_dispatch", + "primitive-types", + "zk_evm_abstractions 0.150.5", + "zkevm_opcode_defs 0.150.5", + "zksync_vm2_interface", +] + +[[package]] +name = "zksync_vm2_interface" +version = "0.1.0" +source = "git+https://github.com/matter-labs/vm2.git?rev=cd6136c42ec56856e0abcf2a98d1a9e120161482#cd6136c42ec56856e0abcf2a98d1a9e120161482" +dependencies = [ + "primitive-types", +] + [[package]] name = "zksync_vm_interface" version = "0.1.0" diff --git a/prover/crates/bin/prover_fri/src/gpu_prover_job_processor.rs b/prover/crates/bin/prover_fri/src/gpu_prover_job_processor.rs index be28f2bd97e..cfd588c2666 100644 --- a/prover/crates/bin/prover_fri/src/gpu_prover_job_processor.rs +++ b/prover/crates/bin/prover_fri/src/gpu_prover_job_processor.rs @@ -8,8 +8,9 @@ pub mod gpu_prover { ProverContextConfig, }; use tokio::task::JoinHandle; - use zksync_config::configs::fri_prover::SetupLoadMode as SetupLoadModeConfig; - use zksync_config::configs::FriProverConfig; + use zksync_config::configs::{ + fri_prover::SetupLoadMode as SetupLoadModeConfig, FriProverConfig, + }; use zksync_object_store::ObjectStore; use zksync_prover_dal::{ConnectionPool, ProverDal}; use zksync_prover_fri_types::{