use std::hash::{DefaultHasher, Hash, Hasher};
use primitive_types::{H160, U256};
pub use zksync_vm2_interface as interface;
use zksync_vm2_interface::Tracer;
#[cfg(feature = "single_instruction_test")]
pub(crate) use self::single_instruction_test::{heap, program, stack};
pub use self::{
fat_pointer::FatPointer,
instruction::{ExecutionEnd, Instruction},
mode_requirements::ModeRequirements,
predication::Predicate,
program::Program,
vm::{Settings, VirtualMachine},
world_diff::{Snapshot, StorageChange, WorldDiff},
};
pub mod addressing_modes;
#[cfg(not(feature = "single_instruction_test"))]
mod bitset;
mod callframe;
mod decode;
mod decommit;
mod fat_pointer;
#[cfg(not(feature = "single_instruction_test"))]
mod heap;
mod instruction;
mod instruction_handlers;
mod mode_requirements;
mod predication;
#[cfg(not(feature = "single_instruction_test"))]
mod program;
mod rollback;
#[cfg(feature = "single_instruction_test")]
pub mod single_instruction_test;
#[cfg(not(feature = "single_instruction_test"))]
mod stack;
mod state;
pub mod testonly;
#[cfg(all(test, not(feature = "single_instruction_test")))]
mod tests;
mod tracing;
mod vm;
mod world_diff;
#[derive(Debug, Clone, Copy)]
pub struct StorageSlot {
pub value: U256,
pub is_write_initial: bool,
}
impl StorageSlot {
pub const EMPTY: Self = Self {
value: U256([0; 4]),
is_write_initial: true,
};
}
pub trait StorageInterface {
fn read_storage(&mut self, contract: H160, key: U256) -> StorageSlot;
fn read_storage_value(&mut self, contract: H160, key: U256) -> U256 {
self.read_storage(contract, key).value
}
fn cost_of_writing_storage(&mut self, initial_slot: StorageSlot, new_value: U256) -> u32;
fn is_free_storage_slot(&self, contract: &H160, key: &U256) -> bool;
}
pub trait World<T: Tracer>: StorageInterface + Sized {
fn decommit(&mut self, hash: U256) -> Program<T, Self>;
fn decommit_code(&mut self, hash: U256) -> Vec<u8>;
}
#[cfg_attr(feature = "single_instruction_test", allow(dead_code))] pub(crate) fn hash_for_debugging(value: &impl Hash) -> u64 {
let mut hasher = DefaultHasher::new();
value.hash(&mut hasher);
hasher.finish()
}