From c49f552db3d6ff0c8d9f0418648954333d88b949 Mon Sep 17 00:00:00 2001 From: Joonatan Saarhelo Date: Mon, 29 Apr 2024 17:26:41 +0200 Subject: [PATCH] update to match latest vm2 --- Cargo.lock | 2 +- compiler_tester/src/vm/eravm/vm2_adapter.rs | 25 ++++++++++++--------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 59eaa7c5..15e8f451 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2582,7 +2582,7 @@ checksum = "2266fcb904c50fb17fda4c9a751a1715629ecf8b21f4c9d78b4890fb71525d71" [[package]] name = "vm2" version = "0.1.0" -source = "git+https://github.com/matter-labs/vm2#01b5d087cc49c0fc8589f46b62feee86f7a58da1" +source = "git+https://github.com/matter-labs/vm2#f745d472bdae30cffeb47a0422f5cde8e0af2a97" dependencies = [ "enum_dispatch", "primitive-types", diff --git a/compiler_tester/src/vm/eravm/vm2_adapter.rs b/compiler_tester/src/vm/eravm/vm2_adapter.rs index aa2e4847..97c6ef22 100644 --- a/compiler_tester/src/vm/eravm/vm2_adapter.rs +++ b/compiler_tester/src/vm/eravm/vm2_adapter.rs @@ -8,6 +8,7 @@ use std::collections::HashMap; use crate::vm::execution_result::ExecutionResult; use anyhow::anyhow; +use vm2::initial_decommit; use vm2::ExecutionEnd; use vm2::Program; use vm2::World; @@ -66,12 +67,16 @@ pub fn run_vm( let context = context.unwrap_or_default(); + let mut world = TestWorld { + storage, + contracts: known_contracts.clone(), + }; + let initial_program = initial_decommit(&mut world, entry_address); + let mut vm = vm2::VirtualMachine::new( - Box::new(TestWorld { - storage, - contracts: known_contracts.clone(), - }), + Box::new(world), entry_address, + initial_program, context.msg_sender, calldata.to_vec(), // zkevm_tester subtracts this constant, I don't know why @@ -109,18 +114,21 @@ pub fn run_vm( exception: true, events: vec![], }, + ExecutionEnd::SuspendedOnHook { .. } => unreachable!(), }; let storage_changes = vm .world .get_storage_changes() - .map(|((address, key), value)| (StorageKey { address, key }, H256::from_uint(&value))) + .iter() + .map(|(&(address, key), value)| (StorageKey { address, key }, H256::from_uint(value))) .collect::>(); let deployed_contracts = vm .world .get_storage_changes() + .iter() .filter_map(|((address, key), value)| { - if address == *zkevm_assembly::zkevm_opcode_defs::system_params::DEPLOYER_SYSTEM_CONTRACT_ADDRESS { + if *address == *zkevm_assembly::zkevm_opcode_defs::system_params::DEPLOYER_SYSTEM_CONTRACT_ADDRESS { let mut buffer = [0u8; 32]; key.to_big_endian(&mut buffer); let deployed_address = web3::ethabi::Address::from_slice(&buffer[12..]); @@ -191,10 +199,6 @@ impl World for TestWorld { .map(|h| h.into_uint()) .unwrap_or(U256::zero()) } - - fn handle_hook(&mut self, _: u32, _: &mut vm2::State) { - unreachable!() // There is no bootloader - } } fn chunk_return_data(bytes: &[u8]) -> Vec { @@ -230,6 +234,7 @@ fn merge_events(events: &[vm2::Event]) -> Vec { key, value, } = *message; + let tx_number = tx_number.into(); if !is_first { if let Some((mut remaining_data_length, mut remaining_topics, mut event)) =