Skip to content

Commit

Permalink
feat(vm): integrate new vm version (#1215)
Browse files Browse the repository at this point in the history
## What ❔

Integrates new VM version

## Why ❔

<!-- Why are these changes done? What goal do they contribute to? What
are the principles behind them? -->
<!-- Example: PR templates ensure PR reviewers, observers, and future
iterators are in context about the evolution of repos. -->

## Checklist

<!-- Check your PR fulfills the following items. -->
<!-- For draft PRs check the boxes as you complete them. -->

- [ ] 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`.
- [ ] Spellcheck has been run via `zk spellcheck`.
- [ ] Linkcheck has been run via `zk linkcheck`.
  • Loading branch information
perekopskiy authored Feb 23, 2024
1 parent a1c866c commit 63d1f52
Show file tree
Hide file tree
Showing 38 changed files with 635 additions and 149 deletions.
4 changes: 2 additions & 2 deletions core/lib/commitment_utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub fn events_queue_commitment(
.collect(),
),
)),
VmVersion::Vm1_4_1 => Some(H256(
VmVersion::Vm1_4_1 | VmVersion::Vm1_4_2 => Some(H256(
zkevm_test_harness_1_4_1::witness::utils::events_queue_commitment_fixed(
&events_queue
.iter()
Expand Down Expand Up @@ -55,7 +55,7 @@ pub fn bootloader_initial_content_commitment(
&full_bootloader_memory,
),
)),
VmVersion::Vm1_4_1 => Some(H256(
VmVersion::Vm1_4_1 | VmVersion::Vm1_4_2 => Some(H256(
zkevm_test_harness_1_4_1::witness::utils::initial_heap_content_commitment_fixed(
&full_bootloader_memory,
),
Expand Down
14 changes: 14 additions & 0 deletions core/lib/contracts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,13 @@ impl BaseSystemContracts {
BaseSystemContracts::load_with_bootloader(bootloader_bytecode)
}

pub fn playground_post_1_4_2() -> Self {
let bootloader_bytecode = read_zbin_bytecode(
"etc/multivm_bootloaders/vm_1_4_2/playground_batch.yul/playground_batch.yul.zbin",
);
BaseSystemContracts::load_with_bootloader(bootloader_bytecode)
}

pub fn estimate_gas_pre_virtual_blocks() -> Self {
let bootloader_bytecode = read_zbin_bytecode(
"etc/multivm_bootloaders/vm_1_3_2/fee_estimate.yul/fee_estimate.yul.zbin",
Expand Down Expand Up @@ -354,6 +361,13 @@ impl BaseSystemContracts {
BaseSystemContracts::load_with_bootloader(bootloader_bytecode)
}

pub fn estimate_gas_post_1_4_2() -> Self {
let bootloader_bytecode = read_zbin_bytecode(
"etc/multivm_bootloaders/vm_1_4_2/fee_estimate.yul/fee_estimate.yul.zbin",
);
BaseSystemContracts::load_with_bootloader(bootloader_bytecode)
}

pub fn hashes(&self) -> BaseSystemContractsHashes {
BaseSystemContractsHashes {
bootloader: self.bootloader.hash,
Expand Down
22 changes: 19 additions & 3 deletions core/lib/multivm/src/glue/history_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ pub trait HistoryMode:
+ GlueInto<Self::VmVirtualBlocksRefundsEnhancement>
+ GlueInto<Self::VmBoojumIntegration>
+ GlueInto<Self::Vm1_4_1>
+ GlueInto<Self::Vm1_4_2>
{
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_refunds_enhancement::HistoryMode;
type VmBoojumIntegration: crate::vm_boojum_integration::HistoryMode;
type Vm1_4_1: crate::vm_latest::HistoryMode;
type Vm1_4_1: crate::vm_1_4_1::HistoryMode;
type Vm1_4_2: crate::vm_latest::HistoryMode;
}

impl GlueFrom<crate::vm_latest::HistoryEnabled> for crate::vm_m6::HistoryEnabled {
Expand Down Expand Up @@ -47,6 +49,12 @@ impl GlueFrom<crate::vm_latest::HistoryEnabled> for crate::vm_boojum_integration
}
}

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

impl GlueFrom<crate::vm_latest::HistoryDisabled> for crate::vm_m6::HistoryDisabled {
fn glue_from(_: crate::vm_latest::HistoryDisabled) -> Self {
Self
Expand Down Expand Up @@ -79,13 +87,20 @@ impl GlueFrom<crate::vm_latest::HistoryDisabled> for crate::vm_boojum_integratio
}
}

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

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_refunds_enhancement::HistoryEnabled;
type VmBoojumIntegration = crate::vm_boojum_integration::HistoryEnabled;
type Vm1_4_1 = crate::vm_latest::HistoryEnabled;
type Vm1_4_1 = crate::vm_1_4_1::HistoryEnabled;
type Vm1_4_2 = crate::vm_latest::HistoryEnabled;
}

impl HistoryMode for crate::vm_latest::HistoryDisabled {
Expand All @@ -94,5 +109,6 @@ impl HistoryMode for crate::vm_latest::HistoryDisabled {
type VmVirtualBlocksMode = crate::vm_virtual_blocks::HistoryDisabled;
type VmVirtualBlocksRefundsEnhancement = crate::vm_refunds_enhancement::HistoryDisabled;
type VmBoojumIntegration = crate::vm_boojum_integration::HistoryDisabled;
type Vm1_4_1 = crate::vm_latest::HistoryDisabled;
type Vm1_4_1 = crate::vm_1_4_1::HistoryDisabled;
type Vm1_4_2 = crate::vm_latest::HistoryDisabled;
}
23 changes: 20 additions & 3 deletions core/lib/multivm/src/glue/tracers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ pub trait MultiVMTracer<S: WriteStorage, H: HistoryMode>:
+ IntoVmVirtualBlocksTracer<S, H>
+ IntoVmRefundsEnhancementTracer<S, H>
+ IntoVmBoojumIntegrationTracer<S, H>
+ IntoVm1_4_1IntegrationTracer<S, H>
+ IntoOldVmTracer
{
fn into_tracer_pointer(self) -> MultiVmTracerPointer<S, H>
Expand All @@ -52,7 +53,7 @@ pub trait MultiVMTracer<S: WriteStorage, H: HistoryMode>:
}

pub trait IntoLatestTracer<S: WriteStorage, H: HistoryMode> {
fn latest(&self) -> crate::vm_latest::TracerPointer<S, H::Vm1_4_1>;
fn latest(&self) -> crate::vm_latest::TracerPointer<S, H::Vm1_4_2>;
}

pub trait IntoVmVirtualBlocksTracer<S: WriteStorage, H: HistoryMode> {
Expand All @@ -73,6 +74,10 @@ pub trait IntoVmBoojumIntegrationTracer<S: WriteStorage, H: HistoryMode> {
) -> Box<dyn crate::vm_boojum_integration::VmTracer<S, H::VmBoojumIntegration>>;
}

pub trait IntoVm1_4_1IntegrationTracer<S: WriteStorage, H: HistoryMode> {
fn vm_1_4_1(&self) -> Box<dyn crate::vm_1_4_1::VmTracer<S, H::Vm1_4_1>>;
}

/// Into tracers for old VM versions.
/// Even though number of tracers is limited, we still need to have this trait to be able to convert
/// tracers to old VM tracers.
Expand All @@ -89,9 +94,9 @@ impl<S, T, H> IntoLatestTracer<S, H> for T
where
S: WriteStorage,
H: HistoryMode,
T: crate::vm_latest::VmTracer<S, H::Vm1_4_1> + Clone + 'static,
T: crate::vm_latest::VmTracer<S, H::Vm1_4_2> + Clone + 'static,
{
fn latest(&self) -> crate::vm_latest::TracerPointer<S, H::Vm1_4_1> {
fn latest(&self) -> crate::vm_latest::TracerPointer<S, H::Vm1_4_2> {
Box::new(self.clone())
}
}
Expand Down Expand Up @@ -138,6 +143,17 @@ where
}
}

impl<S, T, H> IntoVm1_4_1IntegrationTracer<S, H> for T
where
S: WriteStorage,
H: HistoryMode,
T: crate::vm_1_4_1::VmTracer<S, H::Vm1_4_1> + Clone + 'static,
{
fn vm_1_4_1(&self) -> Box<dyn crate::vm_1_4_1::VmTracer<S, H::Vm1_4_1>> {
Box::new(self.clone())
}
}

impl<S, H, T> MultiVMTracer<S, H> for T
where
S: WriteStorage,
Expand All @@ -146,6 +162,7 @@ where
+ IntoVmVirtualBlocksTracer<S, H>
+ IntoVmRefundsEnhancementTracer<S, H>
+ IntoVmBoojumIntegrationTracer<S, H>
+ IntoVm1_4_1IntegrationTracer<S, H>
+ IntoOldVmTracer,
{
}
9 changes: 9 additions & 0 deletions core/lib/multivm/src/glue/types/vm/storage_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ impl GlueFrom<crate::vm_boojum_integration::utils::logs::StorageLogQuery> for St
}
}

impl GlueFrom<crate::vm_1_4_1::utils::logs::StorageLogQuery> for StorageLogQuery {
fn glue_from(value: crate::vm_1_4_1::utils::logs::StorageLogQuery) -> Self {
Self {
log_query: value.log_query.glue_into(),
log_type: value.log_type,
}
}
}

impl GlueFrom<crate::vm_latest::utils::logs::StorageLogQuery> for StorageLogQuery {
fn glue_from(value: crate::vm_latest::utils::logs::StorageLogQuery) -> Self {
Self {
Expand Down
2 changes: 1 addition & 1 deletion core/lib/multivm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub use zkevm_test_harness_1_4_1 as zkevm_test_harness_latest;
pub use zksync_types::vm_version::VmVersion;

pub use self::versions::{
vm_1_3_2, vm_boojum_integration, vm_latest, vm_m5, vm_m6, vm_refunds_enhancement,
vm_1_3_2, vm_1_4_1, vm_boojum_integration, vm_latest, vm_m5, vm_m6, vm_refunds_enhancement,
vm_virtual_blocks,
};
pub use crate::{
Expand Down
1 change: 1 addition & 0 deletions core/lib/multivm/src/tracers/call_tracer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use zksync_types::vm_trace::Call;
use crate::{glue::tracers::IntoOldVmTracer, tracers::call_tracer::metrics::CALL_METRICS};

mod metrics;
pub mod vm_1_4_1;
pub mod vm_boojum_integration;
pub mod vm_latest;
pub mod vm_refunds_enhancement;
Expand Down
Loading

0 comments on commit 63d1f52

Please sign in to comment.