Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(vm): Use the one interface for all vms #277

Merged
merged 33 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
cce0d1b
Just new interface
Deniallugo Oct 18, 2023
4563b0a
Remove redundant trait from DefaultTracer
Deniallugo Oct 18, 2023
3c579ca
Fix interface of tracer
Deniallugo Oct 18, 2023
7ac263e
Fix interface of tracer
Deniallugo Oct 18, 2023
547e8ea
HistoryMode in the latest vm works correcly
Deniallugo Oct 19, 2023
d956403
Use the only tracer
Deniallugo Oct 19, 2023
cb916ed
Start migrating vm virtual blocks
Deniallugo Oct 19, 2023
c191286
auto impl for traits
Deniallugo Oct 20, 2023
241e518
Move call tracer and remove old multi tracer
Deniallugo Oct 20, 2023
6bad2fa
Move storage invocation tracer
Deniallugo Oct 20, 2023
40aac00
Fully migrate vm virtual blocks to the new interface
Deniallugo Oct 20, 2023
27625a6
Use tracer dispatcher
Deniallugo Oct 25, 2023
0a42fdf
Use tracer dispatcher for vm intance
Deniallugo Oct 25, 2023
2025ab0
Use tracer pointer
Deniallugo Oct 25, 2023
ba30de8
Clunky implementation with clone
Deniallugo Oct 25, 2023
7f2b1cc
some more fixes
Deniallugo Oct 26, 2023
89fca24
Move validation tracer
Deniallugo Oct 26, 2023
de06cc9
Migrate the core server to the new interface
Deniallugo Oct 26, 2023
403b4ab
Fix lints
Deniallugo Oct 26, 2023
245af44
Restore tests for vm latest
Deniallugo Oct 26, 2023
b0cf6e2
Recover tests for vm virtual blocks
Deniallugo Oct 26, 2023
44a41f0
Add inlines
Deniallugo Oct 26, 2023
3278584
Change refcell to box
Deniallugo Oct 26, 2023
3594c0f
Use boxes instead of rc ref cell
Deniallugo Oct 27, 2023
cafa23c
Get rid of pub crate in tracer dispatcher
Deniallugo Oct 27, 2023
6db2e23
Remove useless multivm tracer trait
Deniallugo Oct 27, 2023
59313c4
Improve comments
Deniallugo Oct 30, 2023
a5279b4
Fix nits and fix call tracers
Deniallugo Nov 1, 2023
7569bdf
Rename vm -> vm_instance
Deniallugo Nov 1, 2023
20a09e7
Merge branch 'main' into deniallugo-vm-interface
Deniallugo Nov 2, 2023
fe6aaef
Merge branch 'main' into deniallugo-vm-interface
Deniallugo Nov 6, 2023
aaf24a9
Apply interface for latest and vm refunds enhancement
Deniallugo Nov 7, 2023
466742d
Fix tests
Deniallugo Nov 7, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 24 additions & 27 deletions core/bin/system-constants-generator/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
use multivm::interface::{L1BatchEnv, L2BlockEnv, SystemEnv, TxExecutionMode, VmExecutionMode};
use multivm::vm_latest::{
constants::{BLOCK_GAS_LIMIT, BOOTLOADER_HEAP_PAGE},
BootloaderState, BoxedTracer, DynTracer, HistoryEnabled, HistoryMode, Vm,
VmExecutionStopReason, VmTracer, ZkSyncVmState,
};
use once_cell::sync::Lazy;
use std::cell::RefCell;
use std::rc::Rc;

use multivm::interface::{
dyn_tracers::vm_1_4_0::DynTracer, tracer::VmExecutionStopReason, L1BatchEnv, L2BlockEnv,
SystemEnv, TxExecutionMode, VmExecutionMode, VmInterface,
};
use multivm::vm_latest::{
constants::{BLOCK_GAS_LIMIT, BOOTLOADER_HEAP_PAGE},
BootloaderState, HistoryEnabled, HistoryMode, SimpleMemory, ToTracerPointer, Vm, VmTracer,
ZkSyncVmState,
};
use zksync_contracts::{
load_sys_contract, read_bootloader_code, read_sys_contract_bytecode, read_zbin_bytecode,
BaseSystemContracts, ContractLanguage, SystemContractCode,
};
use zksync_state::{InMemoryStorage, StorageView, WriteStorage};
use zksync_types::block::legacy_miniblock_hash;
use zksync_types::{
ethabi::Token, fee::Fee, l1::L1Tx, l2::L2Tx, utils::storage_key_for_eth_balance, AccountTreeId,
Address, Execute, L1BatchNumber, L1TxCommonData, L2ChainId, MiniblockNumber, Nonce,
ProtocolVersionId, StorageKey, Timestamp, Transaction, BOOTLOADER_ADDRESS, H256,
SYSTEM_CONTEXT_ADDRESS, SYSTEM_CONTEXT_GAS_PRICE_POSITION, SYSTEM_CONTEXT_TX_ORIGIN_POSITION,
U256, ZKPORTER_IS_AVAILABLE,
block::legacy_miniblock_hash, ethabi::Token, fee::Fee, l1::L1Tx, l2::L2Tx,
utils::storage_key_for_eth_balance, AccountTreeId, Address, Execute, L1BatchNumber,
L1TxCommonData, L2ChainId, MiniblockNumber, Nonce, ProtocolVersionId, StorageKey, Timestamp,
Transaction, BOOTLOADER_ADDRESS, H256, SYSTEM_CONTEXT_ADDRESS,
SYSTEM_CONTEXT_GAS_PRICE_POSITION, SYSTEM_CONTEXT_TX_ORIGIN_POSITION, U256,
ZKPORTER_IS_AVAILABLE,
};
use zksync_utils::{bytecode::hash_bytecode, bytes_to_be_words, u256_to_h256};

Expand All @@ -31,7 +35,7 @@ struct SpecialBootloaderTracer {
output: Rc<RefCell<u32>>,
}

impl<S: WriteStorage, H: HistoryMode> DynTracer<S, H> for SpecialBootloaderTracer {}
impl<S: WriteStorage, H: HistoryMode> DynTracer<S, SimpleMemory<H>> for SpecialBootloaderTracer {}

impl<S: WriteStorage, H: HistoryMode> VmTracer<S, H> for SpecialBootloaderTracer {
fn initialize_tracer(&mut self, state: &mut ZkSyncVmState<S, H>) {
Expand Down Expand Up @@ -247,14 +251,11 @@ pub(super) fn execute_internal_transfer_test() -> u32 {
let tracer = SpecialBootloaderTracer {
input,
output: tracer_result.clone(),
};
let mut vm = Vm::new(
l1_batch,
system_env,
Rc::new(RefCell::new(storage_view)),
HistoryEnabled,
);
let result = vm.inspect(vec![tracer.into_boxed()], VmExecutionMode::Bootloader);
}
.into_tracer_pointer();
let mut vm: Vm<_, HistoryEnabled> =
Vm::new(l1_batch, system_env, Rc::new(RefCell::new(storage_view)));
let result = vm.inspect(tracer.into(), VmExecutionMode::Bootloader);

assert!(!result.result.is_failed(), "The internal call has reverted");
tracer_result.take()
Expand Down Expand Up @@ -307,12 +308,8 @@ pub(super) fn execute_user_txs_in_test_gas_vm(
chain_id: L2ChainId::default(),
};

let mut vm = Vm::new(
l1_batch,
system_env,
Rc::new(RefCell::new(storage_view)),
HistoryEnabled,
);
let mut vm: Vm<_, HistoryEnabled> =
Vm::new(l1_batch, system_env, Rc::new(RefCell::new(storage_view)));

let mut total_gas_refunded = 0;
for tx in txs {
Expand Down
17 changes: 7 additions & 10 deletions core/lib/multivm/src/glue/init_vm.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::GlueInto;
use crate::glue::history_mode::HistoryMode;
use crate::interface::{L1BatchEnv, SystemEnv};
use crate::interface::{L1BatchEnv, SystemEnv, VmInterface};
use crate::vm_instance::VmInstanceVersion;
use crate::VmInstance;
use zksync_state::{ReadStorage, StoragePtr, StorageView};
Expand Down Expand Up @@ -28,7 +28,7 @@ impl<S: ReadStorage, H: HistoryMode> VmInstance<S, H> {
VmVersion::M5WithoutRefunds => {
let oracle_tools = crate::vm_m5::OracleTools::new(
storage_view.clone(),
crate::vm_m5::vm::MultiVMSubversion::V1,
crate::vm_m5::vm_instance::MultiVMSubversion::V1,
);
let block_properties = zk_evm_1_3_1::block_properties::BlockProperties {
default_aa_code_hash: h256_to_u256(
Expand All @@ -37,7 +37,7 @@ impl<S: ReadStorage, H: HistoryMode> VmInstance<S, H> {
zkporter_is_available: false,
};
let inner_vm = crate::vm_m5::vm_with_bootloader::init_vm_with_gas_limit(
crate::vm_m5::vm::MultiVMSubversion::V1,
crate::vm_m5::vm_instance::MultiVMSubversion::V1,
oracle_tools,
l1_batch_env.glue_into(),
block_properties,
Expand All @@ -54,7 +54,7 @@ impl<S: ReadStorage, H: HistoryMode> VmInstance<S, H> {
VmVersion::M5WithRefunds => {
let oracle_tools = crate::vm_m5::OracleTools::new(
storage_view.clone(),
crate::vm_m5::vm::MultiVMSubversion::V2,
crate::vm_m5::vm_instance::MultiVMSubversion::V2,
);
let block_properties = zk_evm_1_3_1::block_properties::BlockProperties {
default_aa_code_hash: h256_to_u256(
Expand All @@ -63,7 +63,7 @@ impl<S: ReadStorage, H: HistoryMode> VmInstance<S, H> {
zkporter_is_available: false,
};
let inner_vm = crate::vm_m5::vm_with_bootloader::init_vm_with_gas_limit(
crate::vm_m5::vm::MultiVMSubversion::V2,
crate::vm_m5::vm_instance::MultiVMSubversion::V2,
oracle_tools,
l1_batch_env.glue_into(),
block_properties,
Expand All @@ -88,7 +88,7 @@ impl<S: ReadStorage, H: HistoryMode> VmInstance<S, H> {
};

let inner_vm = crate::vm_m6::vm_with_bootloader::init_vm_with_gas_limit(
crate::vm_m6::vm::MultiVMSubversion::V1,
crate::vm_m6::vm_instance::MultiVMSubversion::V1,
oracle_tools,
l1_batch_env.glue_into(),
block_properties,
Expand All @@ -113,7 +113,7 @@ impl<S: ReadStorage, H: HistoryMode> VmInstance<S, H> {
};

let inner_vm = crate::vm_m6::vm_with_bootloader::init_vm_with_gas_limit(
crate::vm_m6::vm::MultiVMSubversion::V2,
crate::vm_m6::vm_instance::MultiVMSubversion::V2,
oracle_tools,
l1_batch_env.glue_into(),
block_properties,
Expand Down Expand Up @@ -154,7 +154,6 @@ impl<S: ReadStorage, H: HistoryMode> VmInstance<S, H> {
l1_batch_env.glue_into(),
system_env.clone().glue_into(),
storage_view.clone(),
H::VmVirtualBlocksMode::default(),
);
let vm = VmInstanceVersion::VmVirtualBlocks(Box::new(vm));
Self {
Expand All @@ -168,7 +167,6 @@ impl<S: ReadStorage, H: HistoryMode> VmInstance<S, H> {
l1_batch_env.glue_into(),
system_env.clone(),
storage_view.clone(),
H::VmVirtualBlocksRefundsEnhancement::default(),
);
let vm = VmInstanceVersion::VmVirtualBlocksRefundsEnhancement(Box::new(vm));
Self {
Expand All @@ -182,7 +180,6 @@ impl<S: ReadStorage, H: HistoryMode> VmInstance<S, H> {
l1_batch_env.glue_into(),
system_env.clone(),
storage_view.clone(),
H::VmBoojumIntegration::default(),
);
let vm = VmInstanceVersion::VmBoojumIntegration(Box::new(vm));
Self {
Expand Down
2 changes: 1 addition & 1 deletion core/lib/multivm/src/glue/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub(crate) mod block_properties;
pub(crate) mod history_mode;
pub(crate) mod init_vm;
pub(crate) mod oracle_tools;
pub(crate) mod tracer;
pub mod tracers;
mod types;

/// This trait is a workaround on the Rust'c [orphan rule](orphan_rule).
Expand Down
12 changes: 8 additions & 4 deletions core/lib/multivm/src/glue/oracle_tools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@ where
pub fn new(version: VmVersion, state: StoragePtr<StorageView<S>>, history: H) -> Self {
match version {
VmVersion::M5WithoutRefunds => {
let oracle_tools =
crate::vm_m5::OracleTools::new(state, crate::vm_m5::vm::MultiVMSubversion::V1);
let oracle_tools = crate::vm_m5::OracleTools::new(
state,
crate::vm_m5::vm_instance::MultiVMSubversion::V1,
);
OracleTools::M5(oracle_tools)
}
VmVersion::M5WithRefunds => {
let oracle_tools =
crate::vm_m5::OracleTools::new(state, crate::vm_m5::vm::MultiVMSubversion::V2);
let oracle_tools = crate::vm_m5::OracleTools::new(
state,
crate::vm_m5::vm_instance::MultiVMSubversion::V2,
);
OracleTools::M5(oracle_tools)
}
VmVersion::M6Initial | VmVersion::M6BugWithCompressionFixed => {
Expand Down
112 changes: 0 additions & 112 deletions core/lib/multivm/src/glue/tracer/implementations.rs

This file was deleted.

Loading
Loading