Skip to content

Commit

Permalink
Merge vms
Browse files Browse the repository at this point in the history
Signed-off-by: Danil <deniallugo@gmail.com>
  • Loading branch information
Deniallugo committed Oct 17, 2023
1 parent f4442f4 commit 4d05a48
Show file tree
Hide file tree
Showing 365 changed files with 1,735 additions and 1,801 deletions.
263 changes: 89 additions & 174 deletions Cargo.lock

Large diffs are not rendered by default.

5 changes: 0 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,9 @@ members = [
"core/lib/utils",
"core/lib/vlog",
"core/lib/multivm",
"core/lib/vm",
"core/lib/web3_decl",
"core/lib/test_account",

# MultiVM dependencies
"core/multivm_deps/vm_m5",
"core/multivm_deps/vm_m6",

# Test infrastructure
"core/tests/cross_external_nodes_checker",
"core/tests/loadnext",
Expand Down
2 changes: 1 addition & 1 deletion core/bin/system-constants-generator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ zksync_state = { path = "../../lib/state" }
zksync_types = { path = "../../lib/types" }
zksync_utils = { path = "../../lib/utils" }
zksync_contracts = { path = "../../lib/contracts" }
vm = { path = "../../lib/vm" }
multivm = { path = "../../lib/multivm" }

codegen = "0.2.0"

Expand Down
2 changes: 1 addition & 1 deletion core/bin/system-constants-generator/src/intrinsic_costs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::utils::{
get_l2_txs,
};
use crate::utils::{metrics_from_txs, TransactionGenerator};
use vm::constants::BOOTLOADER_TX_ENCODING_SPACE;
use multivm::vm_latest::constants::BOOTLOADER_TX_ENCODING_SPACE;
use zksync_types::{ethabi::Address, IntrinsicSystemGasConstants, U256};

#[derive(Debug, Clone, Copy, PartialEq)]
Expand Down
2 changes: 1 addition & 1 deletion core/bin/system-constants-generator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ mod utils;

use codegen::Block;
use codegen::Scope;
use vm::constants::{
use multivm::vm_latest::constants::{
BLOCK_OVERHEAD_GAS, BLOCK_OVERHEAD_L1_GAS, BOOTLOADER_TX_ENCODING_SPACE, MAX_PUBDATA_PER_BLOCK,
};
use zksync_types::zkevm_test_harness::zk_evm::zkevm_opcode_defs::circuit_prices::{
Expand Down
10 changes: 5 additions & 5 deletions core/bin/system-constants-generator/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use once_cell::sync::Lazy;
use std::cell::RefCell;
use std::rc::Rc;
use vm::constants::{BLOCK_GAS_LIMIT, BOOTLOADER_HEAP_PAGE};
use vm::{
use multivm::vm_latest::constants::{BLOCK_GAS_LIMIT, BOOTLOADER_HEAP_PAGE};
use multivm::vm_latest::{
BootloaderState, BoxedTracer, DynTracer, HistoryEnabled, HistoryMode, L1BatchEnv, L2BlockEnv,
SystemEnv, TxExecutionMode, Vm, VmExecutionMode, VmExecutionStopReason, VmTracer,
ZkSyncVmState,
};
use once_cell::sync::Lazy;
use std::cell::RefCell;
use std::rc::Rc;
use zksync_contracts::{
load_sys_contract, read_bootloader_code, read_sys_contract_bytecode, read_zbin_bytecode,
BaseSystemContracts, ContractLanguage, SystemContractCode,
Expand Down
23 changes: 17 additions & 6 deletions core/lib/multivm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,26 @@ keywords = ["blockchain", "zksync"]
categories = ["cryptography"]

[dependencies]
vm_m5 = { path = "../../multivm_deps/vm_m5" }
vm_m6 = { path = "../../multivm_deps/vm_m6" }
vm_1_3_2 = { path = "../../multivm_deps/vm_1_3_2" }
vm_virtual_blocks= { path = "../../multivm_deps/vm_virtual_blocks" }
vm_latest = { path = "../vm", package = "vm" }
zk_evm_1_3_3 = { package = "zk_evm", git = "https://github.com/matter-labs/era-zk_evm.git", tag= "v1.3.3-rc1" }
zk_evm_1_3_1 = { package = "zk_evm", git = "https://github.com/matter-labs/era-zk_evm.git", tag= "v1.3.1-rc2" }

zksync_types = { path = "../types" }
zksync_state = { path = "../state" }
zksync_contracts = { path = "../contracts" }
zksync_utils = { path = "../utils" }
zksync_config = { path = "../../lib/config" }

vlog = { path = "../../lib/vlog" }
anyhow = "1.0"
hex = "0.4"
itertools = "0.10"
once_cell = "1.7"
thiserror = "1.0"
tracing = "0.1"
vise = { git = "https://github.com/matter-labs/vise.git", version = "0.1.0", rev = "dd05139b76ab0843443ab3ff730174942c825dae" }


[dev-dependencies]
tokio = { version = "1", features = ["time"] }
zksync_test_account = { path = "../test_account" }
ethabi = "18.0.0"
zksync_eth_signer = { path = "../eth_signer" }
14 changes: 7 additions & 7 deletions core/lib/multivm/src/glue/block_properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use zksync_types::{VmVersion, U256};
/// boilerplate leaving the necessary wrappers only.
pub enum BlockProperties {
// M5 & M6 are covered by this variant.
Vm1_3_1(vm_m6::zk_evm::block_properties::BlockProperties),
Vm1_3_2(vm_1_3_2::zk_evm::block_properties::BlockProperties),
Vm1_3_1(zk_evm_1_3_1::block_properties::BlockProperties),
Vm1_3_2(zk_evm_1_3_3::block_properties::BlockProperties),
}

impl BlockProperties {
Expand All @@ -20,14 +20,14 @@ impl BlockProperties {
| VmVersion::M5WithRefunds
| VmVersion::M6Initial
| VmVersion::M6BugWithCompressionFixed => {
let inner = vm_m6::zk_evm::block_properties::BlockProperties {
let inner = zk_evm_1_3_1::block_properties::BlockProperties {
zkporter_is_available: false,
default_aa_code_hash,
};
Self::Vm1_3_1(inner)
}
VmVersion::Vm1_3_2 => {
let inner = vm_1_3_2::zk_evm::block_properties::BlockProperties {
let inner = zk_evm_1_3_3::block_properties::BlockProperties {
zkporter_is_available: false,
default_aa_code_hash,
};
Expand All @@ -42,7 +42,7 @@ impl BlockProperties {
}
}

pub fn m5(&self) -> &vm_m5::zk_evm::block_properties::BlockProperties {
pub fn m5(&self) -> &zk_evm_1_3_1::block_properties::BlockProperties {
// This is not a typo, M5 is covered by this variant. See doc-comment for the enum.
if let BlockProperties::Vm1_3_1(inner) = self {
inner
Expand All @@ -51,7 +51,7 @@ impl BlockProperties {
}
}

pub fn m6(&self) -> &vm_m6::zk_evm::block_properties::BlockProperties {
pub fn m6(&self) -> &zk_evm_1_3_1::block_properties::BlockProperties {
// This is not a typo, M6 is covered by this variant. See doc-comment for the enum.
if let BlockProperties::Vm1_3_1(inner) = self {
inner
Expand All @@ -60,7 +60,7 @@ impl BlockProperties {
}
}

pub fn vm1_3_2(&self) -> &vm_1_3_2::zk_evm::block_properties::BlockProperties {
pub fn vm1_3_2(&self) -> &zk_evm_1_3_3::block_properties::BlockProperties {
if let BlockProperties::Vm1_3_2(inner) = self {
inner
} else {
Expand Down
52 changes: 26 additions & 26 deletions core/lib/multivm/src/glue/history_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,58 +7,58 @@ pub trait HistoryMode:
+ GlueInto<Self::VmVirtualBlocksMode>
+ GlueInto<Self::VmVirtualBlocksRefundsEnhancement>
{
type VmM6Mode: vm_m6::HistoryMode;
type Vm1_3_2Mode: vm_1_3_2::HistoryMode;
type VmVirtualBlocksMode: vm_virtual_blocks::HistoryMode;
type VmVirtualBlocksRefundsEnhancement: vm_latest::HistoryMode;
type VmM6Mode: crate::vm_m6::HistoryMode;
type Vm1_3_2Mode: crate::vm_1_3_2::HistoryMode;
type VmVirtualBlocksMode: crate::vm_virtual_blocks::HistoryMode;
type VmVirtualBlocksRefundsEnhancement: crate::vm_latest::HistoryMode;
}

impl GlueFrom<vm_latest::HistoryEnabled> for vm_m6::HistoryEnabled {
fn glue_from(_: vm_latest::HistoryEnabled) -> Self {
impl GlueFrom<crate::vm_latest::HistoryEnabled> for crate::vm_m6::HistoryEnabled {
fn glue_from(_: crate::vm_latest::HistoryEnabled) -> Self {
Self
}
}

impl GlueFrom<vm_latest::HistoryEnabled> for vm_1_3_2::HistoryEnabled {
fn glue_from(_: vm_latest::HistoryEnabled) -> Self {
impl GlueFrom<crate::vm_latest::HistoryEnabled> for crate::vm_1_3_2::HistoryEnabled {
fn glue_from(_: crate::vm_latest::HistoryEnabled) -> Self {
Self
}
}

impl GlueFrom<vm_latest::HistoryEnabled> for vm_virtual_blocks::HistoryEnabled {
fn glue_from(_: vm_latest::HistoryEnabled) -> Self {
impl GlueFrom<crate::vm_latest::HistoryEnabled> for crate::vm_virtual_blocks::HistoryEnabled {
fn glue_from(_: crate::vm_latest::HistoryEnabled) -> Self {
Self
}
}

impl GlueFrom<vm_latest::HistoryDisabled> for vm_m6::HistoryDisabled {
fn glue_from(_: vm_latest::HistoryDisabled) -> Self {
impl GlueFrom<crate::vm_latest::HistoryDisabled> for crate::vm_m6::HistoryDisabled {
fn glue_from(_: crate::vm_latest::HistoryDisabled) -> Self {
Self
}
}

impl GlueFrom<vm_latest::HistoryDisabled> for vm_1_3_2::HistoryDisabled {
fn glue_from(_: vm_latest::HistoryDisabled) -> Self {
impl GlueFrom<crate::vm_latest::HistoryDisabled> for crate::vm_1_3_2::HistoryDisabled {
fn glue_from(_: crate::vm_latest::HistoryDisabled) -> Self {
Self
}
}

impl GlueFrom<vm_latest::HistoryDisabled> for vm_virtual_blocks::HistoryDisabled {
fn glue_from(_: vm_latest::HistoryDisabled) -> Self {
impl GlueFrom<crate::vm_latest::HistoryDisabled> for crate::vm_virtual_blocks::HistoryDisabled {
fn glue_from(_: crate::vm_latest::HistoryDisabled) -> Self {
Self
}
}

impl HistoryMode for vm_latest::HistoryEnabled {
type VmM6Mode = vm_m6::HistoryEnabled;
type Vm1_3_2Mode = vm_1_3_2::HistoryEnabled;
type VmVirtualBlocksMode = vm_virtual_blocks::HistoryEnabled;
type VmVirtualBlocksRefundsEnhancement = vm_latest::HistoryEnabled;
impl HistoryMode for crate::vm_latest::HistoryEnabled {
type VmM6Mode = crate::vm_m6::HistoryEnabled;
type Vm1_3_2Mode = crate::vm_1_3_2::HistoryEnabled;
type VmVirtualBlocksMode = crate::vm_virtual_blocks::HistoryEnabled;
type VmVirtualBlocksRefundsEnhancement = crate::vm_latest::HistoryEnabled;
}

impl HistoryMode for vm_latest::HistoryDisabled {
type VmM6Mode = vm_m6::HistoryDisabled;
type Vm1_3_2Mode = vm_1_3_2::HistoryDisabled;
type VmVirtualBlocksMode = vm_virtual_blocks::HistoryDisabled;
type VmVirtualBlocksRefundsEnhancement = vm_latest::HistoryDisabled;
impl HistoryMode for crate::vm_latest::HistoryDisabled {
type VmM6Mode = crate::vm_m6::HistoryDisabled;
type Vm1_3_2Mode = crate::vm_1_3_2::HistoryDisabled;
type VmVirtualBlocksMode = crate::vm_virtual_blocks::HistoryDisabled;
type VmVirtualBlocksRefundsEnhancement = crate::vm_latest::HistoryDisabled;
}
52 changes: 28 additions & 24 deletions core/lib/multivm/src/glue/init_vm.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use super::GlueInto;
use crate::glue::history_mode::HistoryMode;
use crate::vm_instance::VmInstanceVersion;
use crate::vm_latest::{L1BatchEnv, SystemEnv};
use crate::VmInstance;
use vm_latest::{L1BatchEnv, SystemEnv};
use zksync_state::{ReadStorage, StoragePtr, StorageView};
use zksync_types::VmVersion;
use zksync_utils::h256_to_u256;
Expand All @@ -26,16 +26,18 @@ impl<S: ReadStorage, H: HistoryMode> VmInstance<S, H> {
) -> Self {
match vm_version {
VmVersion::M5WithoutRefunds => {
let oracle_tools =
vm_m5::OracleTools::new(storage_view.clone(), vm_m5::vm::MultiVMSubversion::V1);
let block_properties = vm_m5::zk_evm::block_properties::BlockProperties {
let oracle_tools = crate::vm_m5::OracleTools::new(
storage_view.clone(),
crate::vm_m5::vm::MultiVMSubversion::V1,
);
let block_properties = zk_evm_1_3_1::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(
vm_m5::vm::MultiVMSubversion::V1,
let inner_vm = crate::vm_m5::vm_with_bootloader::init_vm_with_gas_limit(
crate::vm_m5::vm::MultiVMSubversion::V1,
oracle_tools,
l1_batch_env.glue_into(),
block_properties,
Expand All @@ -50,16 +52,18 @@ impl<S: ReadStorage, H: HistoryMode> VmInstance<S, H> {
}
}
VmVersion::M5WithRefunds => {
let oracle_tools =
vm_m5::OracleTools::new(storage_view.clone(), vm_m5::vm::MultiVMSubversion::V2);
let block_properties = vm_m5::zk_evm::block_properties::BlockProperties {
let oracle_tools = crate::vm_m5::OracleTools::new(
storage_view.clone(),
crate::vm_m5::vm::MultiVMSubversion::V2,
);
let block_properties = zk_evm_1_3_1::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(
vm_m5::vm::MultiVMSubversion::V2,
let inner_vm = crate::vm_m5::vm_with_bootloader::init_vm_with_gas_limit(
crate::vm_m5::vm::MultiVMSubversion::V2,
oracle_tools,
l1_batch_env.glue_into(),
block_properties,
Expand All @@ -75,16 +79,16 @@ impl<S: ReadStorage, H: HistoryMode> VmInstance<S, H> {
}
VmVersion::M6Initial => {
let oracle_tools =
vm_m6::OracleTools::new(storage_view.clone(), H::VmM6Mode::default());
let block_properties = vm_m6::zk_evm::block_properties::BlockProperties {
crate::vm_m6::OracleTools::new(storage_view.clone(), H::VmM6Mode::default());
let block_properties = zk_evm_1_3_1::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(
vm_m6::vm::MultiVMSubversion::V1,
let inner_vm = crate::vm_m6::vm_with_bootloader::init_vm_with_gas_limit(
crate::vm_m6::vm::MultiVMSubversion::V1,
oracle_tools,
l1_batch_env.glue_into(),
block_properties,
Expand All @@ -100,16 +104,16 @@ impl<S: ReadStorage, H: HistoryMode> VmInstance<S, H> {
}
VmVersion::M6BugWithCompressionFixed => {
let oracle_tools =
vm_m6::OracleTools::new(storage_view.clone(), H::VmM6Mode::default());
let block_properties = vm_m6::zk_evm::block_properties::BlockProperties {
crate::vm_m6::OracleTools::new(storage_view.clone(), H::VmM6Mode::default());
let block_properties = zk_evm_1_3_1::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(
vm_m6::vm::MultiVMSubversion::V2,
let inner_vm = crate::vm_m6::vm_with_bootloader::init_vm_with_gas_limit(
crate::vm_m6::vm::MultiVMSubversion::V2,
oracle_tools,
l1_batch_env.glue_into(),
block_properties,
Expand All @@ -124,14 +128,14 @@ impl<S: ReadStorage, H: HistoryMode> VmInstance<S, H> {
}
}
VmVersion::Vm1_3_2 => {
let oracle_tools = vm_1_3_2::OracleTools::new(storage_view.clone());
let block_properties = vm_1_3_2::BlockProperties {
let oracle_tools = crate::vm_1_3_2::OracleTools::new(storage_view.clone());
let block_properties = crate::vm_1_3_2::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_1_3_2::vm_with_bootloader::init_vm_with_gas_limit(
let inner_vm = crate::vm_1_3_2::vm_with_bootloader::init_vm_with_gas_limit(
oracle_tools,
l1_batch_env.glue_into(),
block_properties,
Expand All @@ -146,7 +150,7 @@ impl<S: ReadStorage, H: HistoryMode> VmInstance<S, H> {
}
}
VmVersion::VmVirtualBlocks => {
let vm = vm_virtual_blocks::Vm::new(
let vm = crate::vm_virtual_blocks::Vm::new(
l1_batch_env.glue_into(),
system_env.clone().glue_into(),
storage_view.clone(),
Expand All @@ -160,7 +164,7 @@ impl<S: ReadStorage, H: HistoryMode> VmInstance<S, H> {
}
}
VmVersion::VmVirtualBlocksRefundsEnhancement => {
let vm = vm_latest::Vm::new(
let vm = crate::vm_latest::Vm::new(
l1_batch_env.glue_into(),
system_env.clone(),
storage_view.clone(),
Expand Down
Loading

0 comments on commit 4d05a48

Please sign in to comment.