Skip to content

Commit

Permalink
update to match latest vm2
Browse files Browse the repository at this point in the history
  • Loading branch information
joonazan committed Apr 29, 2024
1 parent bc8d492 commit c49f552
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

25 changes: 15 additions & 10 deletions compiler_tester/src/vm/eravm/vm2_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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::<HashMap<_, _>>();
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..]);
Expand Down Expand Up @@ -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<Value> {
Expand Down Expand Up @@ -230,6 +234,7 @@ fn merge_events(events: &[vm2::Event]) -> Vec<Event> {
key,
value,
} = *message;
let tx_number = tx_number.into();

if !is_first {
if let Some((mut remaining_data_length, mut remaining_topics, mut event)) =
Expand Down

0 comments on commit c49f552

Please sign in to comment.