Skip to content

Commit

Permalink
initial integration to world
Browse files Browse the repository at this point in the history
  • Loading branch information
juan518munoz committed Aug 15, 2024
2 parents 0e8e466 + 08cf08f commit 7066bdc
Show file tree
Hide file tree
Showing 9 changed files with 239 additions and 121 deletions.
4 changes: 2 additions & 2 deletions core/lib/multivm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ zk_evm_1_4_0.workspace = true
zk_evm_1_3_3.workspace = true
zk_evm_1_3_1.workspace = true
vm2.workspace = true
# era_vm = {path = "../../../../era_vm"}
era_vm = {git = "https://github.com/lambdaclass/era_vm.git", branch = "main"}
era_vm = { path = "../../../../era_vm" }
# era_vm = {git = "https://github.com/lambdaclass/era_vm.git", branch = "main"}

circuit_sequencer_api_1_3_3.workspace = true
circuit_sequencer_api_1_4_0.workspace = true
Expand Down
6 changes: 3 additions & 3 deletions core/lib/multivm/src/versions/era_vm/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<&era_vm::store::L2ToL1Log> for SystemL2ToL1Log {
fn glue_from(value: &era_vm::store::L2ToL1Log) -> Self {
let era_vm::store::L2ToL1Log {
impl GlueFrom<&era_vm::state::L2ToL1Log> for SystemL2ToL1Log {
fn glue_from(value: &era_vm::state::L2ToL1Log) -> Self {
let era_vm::state::L2ToL1Log {
key,
value,
is_service,
Expand Down
11 changes: 5 additions & 6 deletions core/lib/multivm/src/versions/era_vm/snapshot.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use era_vm::store::SnapShot;
use era_vm::state::StateSnapshot;
use zksync_types::H256;

use super::bootloader_state::BootloaderStateSnapshot;
Expand All @@ -12,9 +12,8 @@ pub(crate) struct L2BlockSnapshot {
}

pub struct VmSnapshot {
pub(crate) storage_snapshot: SnapShot,
pub(crate) transient_storage_snapshot: SnapShot,
pub(crate) bootloader_snapshot: BootloaderStateSnapshot,
pub(crate) suspended_at: u16,
pub(crate) gas_for_account_validation: u32,
pub execution: StateSnapshot,
pub bootloader_snapshot: BootloaderStateSnapshot,
pub suspended_at: u16,
pub gas_for_account_validation: u32,
}
38 changes: 19 additions & 19 deletions core/lib/multivm/src/versions/era_vm/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
mod bootloader;
mod bytecode_publishing;
mod code_oracle;
mod default_aa;
mod gas_limit;
mod get_used_contracts;
mod is_write_initial;
mod l1_tx_execution;
mod l2_blocks;
mod nonce_holder;
mod refunds;
mod require_eip712;
mod rollbacks;
mod sekp256r1;
mod simple_execution;
mod storage;
// mod bootloader;
// mod bytecode_publishing;
// mod code_oracle;
// mod default_aa;
// mod gas_limit;
// mod get_used_contracts;
// mod is_write_initial;
// mod l1_tx_execution;
// mod l2_blocks;
// mod nonce_holder;
// mod refunds;
// mod require_eip712;
// mod rollbacks;
// mod sekp256r1;
// mod simple_execution;
// mod storage;
mod tester;
mod tracing_execution_error;
mod transfer;
mod upgrade;
// mod tracing_execution_error;
// mod transfer;
// mod upgrade;
mod utils;
2 changes: 1 addition & 1 deletion core/lib/multivm/src/versions/era_vm/tests/tester/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ pub(crate) use transaction_test_info::{ExpectedError, TransactionTestInfo, TxMod
pub(crate) use vm_tester::{default_l1_batch, get_empty_storage, VmTester, VmTesterBuilder};
pub(crate) use zksync_test_account::{Account, DeployContractsTx, TxType};

mod transaction_test_info;
pub mod transaction_test_info;
mod vm_tester;
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use era_vm::state::Event;
use zksync_state::{InMemoryStorage, WriteStorage};
use zksync_state::{InMemoryStorage, ReadStorage, WriteStorage};
use zksync_types::{ExecuteTransactionCommon, Transaction, H160, U256};

use super::VmTester;
Expand Down Expand Up @@ -185,25 +185,28 @@ impl TransactionTestInfo {
}

// TODO this doesn't include all the state of ModifiedWorld
#[derive(Debug, PartialEq)]
#[derive(Debug)]
struct VmStateDump {
state: era_vm::state::VMState,
storage_writes: Vec<((H160, U256), U256)>,
events: Vec<Event>,
}

impl Vm<InMemoryStorage> {
impl PartialEq for VmStateDump {
fn eq(&self, other: &Self) -> bool {
self.state == other.state
&& self.storage_writes == other.storage_writes
&& self.events == other.events
}
}

impl<S: ReadStorage + 'static> Vm<S> {
fn dump_state(&self) -> VmStateDump {
// TODO: only dumps state, should also dump storage writes and events
VmStateDump {
state: self.inner.state.clone(),
storage_writes: self
.inner
.state_storage
.storage_changes
.iter()
.map(|(k, v)| ((k.address, k.key), *v))
.collect(),
events: self.inner.state.events.clone(),
storage_writes: vec![], //self.storage_writes.clone(),
events: vec![], //self.inner.state.events.clone(),
}
}
}
Expand Down
14 changes: 7 additions & 7 deletions core/lib/multivm/src/versions/era_vm/tests/tester/vm_tester.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use crate::{
},
vm_latest::{constants::BATCH_COMPUTATIONAL_GAS_LIMIT, utils::l2_blocks::load_last_l2_block},
};
use era_vm::rollbacks::{RollbackableHashMap, RollbackableVec};

pub(crate) struct VmTester {
pub(crate) vm: Vm<InMemoryStorage>,
Expand Down Expand Up @@ -50,12 +51,12 @@ impl VmTester {
self.test_contract = Some(deployed_address);
}
pub(crate) fn reset_with_empty_storage(&mut self) {
let contracts = self.vm.inner.contract_storage.clone();
let contracts = self.vm.inner.state.contracts_storage.clone();
// self.storage = World::new(Rc::new(RefCell::new(HashMap::new())), contracts);
self.storage = Rc::new(RefCell::new(get_empty_storage()));
self.vm.inner.state_storage.storage_changes = HashMap::default();
self.vm.inner.transient_storage.storage_changes = HashMap::default();
self.vm.inner.state.events = vec![];
self.vm.inner.state.storage_changes = RollbackableHashMap::new();
self.vm.inner.state.transient_storage = RollbackableHashMap::new();
self.vm.inner.state.events = RollbackableVec::new();
self.reset_state(false);
}

Expand All @@ -76,11 +77,10 @@ impl VmTester {
// `insert_contracts(&mut self.storage, &self.custom_contracts);`
}

let mut storage = self.storage.clone();
let storage = self.storage.clone();
{
let mut storage = storage.borrow_mut();
// Commit pending storage changes (old VM versions commit them on successful execution)
for (key, value) in self.vm.inner.state_storage.storage_changes.clone() {
for (key, value) in self.vm.inner.state.storage_changes.map.clone() {
let key = StorageKey::new(AccountTreeId::new(key.address), u256_to_h256(key.key));
storage
.as_ref()
Expand Down
9 changes: 6 additions & 3 deletions core/lib/multivm/src/versions/era_vm/tests/utils.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::collections::HashMap;

use era_vm::{state::VMState, store::StorageKey};
use era_vm::{execution::Execution, store::StorageKey};
use ethabi::Contract;
use once_cell::sync::Lazy;
use vm2::HeapId;
Expand Down Expand Up @@ -28,9 +28,12 @@ pub fn zk_storage_key_to_lambda(key: &ZKStorageKey) -> StorageKey {
}
}

pub(crate) fn verify_required_memory(state: &VMState, required_values: Vec<(U256, HeapId, u32)>) {
pub(crate) fn verify_required_memory(
execution: &Execution,
required_values: Vec<(U256, HeapId, u32)>,
) {
for (required_value, memory_page, cell) in required_values {
let current_value = state
let current_value = execution
.heaps
.get(memory_page.to_u32())
.unwrap()
Expand Down
Loading

0 comments on commit 7066bdc

Please sign in to comment.