Skip to content

Commit

Permalink
chore(vm): Bump zksync_vm2 revision (#2838)
Browse files Browse the repository at this point in the history
## 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`.
  • Loading branch information
slowli authored Sep 12, 2024
1 parent fee0c2a commit 3609ea6
Show file tree
Hide file tree
Showing 21 changed files with 133 additions and 118 deletions.
42 changes: 21 additions & 21 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion core/lib/multivm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion core/lib/multivm/src/versions/vm_fast/circuits_tracer.rs
Original file line number Diff line number Diff line change
@@ -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::*;
Expand Down
2 changes: 1 addition & 1 deletion core/lib/multivm/src/versions/vm_fast/events.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
6 changes: 3 additions & 3 deletions core/lib/multivm/src/versions/vm_fast/glue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 2 additions & 4 deletions core/lib/multivm/src/versions/vm_fast/tests/bootloader.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand All @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion core/lib/multivm/src/versions/vm_fast/tests/code_oracle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
4 changes: 2 additions & 2 deletions core/lib/multivm/src/versions/vm_fast/tests/default_aa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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!(
Expand Down
2 changes: 1 addition & 1 deletion core/lib/multivm/src/versions/vm_fast/tests/gas_limit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion core/lib/multivm/src/versions/vm_fast/tests/rollbacks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::fmt;

use zksync_types::{ExecuteTransactionCommon, Transaction, H160, U256};

use super::VmTester;
Expand All @@ -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)]
Expand Down Expand Up @@ -186,12 +188,12 @@ impl TransactionTestInfo {
// TODO this doesn't include all the state of ModifiedWorld
#[derive(Debug)]
struct VmStateDump<S> {
state: vm2::State<CircuitsTracer, World<S, CircuitsTracer>>,
state: S,
storage_writes: Vec<((H160, U256), U256)>,
events: Box<[vm2::Event]>,
events: Box<[zksync_vm2::Event]>,
}

impl<S> PartialEq for VmStateDump<S> {
impl<S: PartialEq> PartialEq for VmStateDump<S> {
fn eq(&self, other: &Self) -> bool {
self.state == other.state
&& self.storage_writes == other.storage_writes
Expand All @@ -200,17 +202,17 @@ impl<S> PartialEq for VmStateDump<S> {
}

impl<S: ReadStorage> Vm<S> {
fn dump_state(&self) -> VmStateDump<S> {
fn dump_state(&self) -> VmStateDump<impl PartialEq + fmt::Debug> {
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(),
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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::{
Expand All @@ -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::{
Expand Down Expand Up @@ -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);
}

Expand All @@ -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));
}
Expand Down
2 changes: 1 addition & 1 deletion core/lib/multivm/src/versions/vm_fast/tests/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions core/lib/multivm/src/versions/vm_fast/tests/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
);
}

Expand Down Expand Up @@ -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(),
);
}

Expand Down
8 changes: 4 additions & 4 deletions core/lib/multivm/src/versions/vm_fast/tests/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand All @@ -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<BaseSystemContracts> =
Lazy::new(BaseSystemContracts::load_from_disk);

pub(crate) fn verify_required_memory<T, W>(
state: &State<T, W>,
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);
}
}
Expand Down
Loading

0 comments on commit 3609ea6

Please sign in to comment.