From 92947f63a44baea56c7d76998a96d72f93f951b9 Mon Sep 17 00:00:00 2001 From: Pierrick Couderc Date: Mon, 9 Sep 2024 09:35:59 +0200 Subject: [PATCH 1/3] EVM/Eval: host implements Runtime and uses KernelHost --- etherlink/kernel_evm/Cargo.lock | 1 + .../kernel_evm/evm_evaluation/Cargo.toml | 1 + .../kernel_evm/evm_evaluation/src/evalhost.rs | 241 ++++++++++++------ 3 files changed, 163 insertions(+), 80 deletions(-) diff --git a/etherlink/kernel_evm/Cargo.lock b/etherlink/kernel_evm/Cargo.lock index e6fc4f045392..275adcdaa9b9 100644 --- a/etherlink/kernel_evm/Cargo.lock +++ b/etherlink/kernel_evm/Cargo.lock @@ -697,6 +697,7 @@ dependencies = [ "serde_yaml", "structopt", "tezos-evm-logging", + "tezos-evm-runtime", "tezos-smart-rollup-core", "tezos-smart-rollup-host", "tezos-smart-rollup-mock", diff --git a/etherlink/kernel_evm/evm_evaluation/Cargo.toml b/etherlink/kernel_evm/evm_evaluation/Cargo.toml index 59a477543e3a..841471ee6386 100644 --- a/etherlink/kernel_evm/evm_evaluation/Cargo.toml +++ b/etherlink/kernel_evm/evm_evaluation/Cargo.toml @@ -14,6 +14,7 @@ thiserror.workspace = true evm-execution = { workspace = true, features = ["debug"] } tezos_ethereum.workspace = true tezos-evm-logging.workspace = true +tezos-evm-runtime.workspace = true tezos-smart-rollup-mock.workspace = true tezos-smart-rollup-host.workspace = true tezos-smart-rollup-core.workspace = true diff --git a/etherlink/kernel_evm/evm_evaluation/src/evalhost.rs b/etherlink/kernel_evm/evm_evaluation/src/evalhost.rs index df8e9849936d..0d1440293c0f 100644 --- a/etherlink/kernel_evm/evm_evaluation/src/evalhost.rs +++ b/etherlink/kernel_evm/evm_evaluation/src/evalhost.rs @@ -4,13 +4,24 @@ use std::{cell::RefCell, io::Write}; +use tezos_evm_runtime::{ + internal_runtime::{ExtendedRuntime, InternalRuntime}, + mock_internal::MockInternal, + runtime::KernelHost, +}; +use tezos_smart_rollup_host::{ + dal_parameters::RollupDalParameters, + input::Message, + metadata::RollupMetadata, + path::Path, + runtime::{Runtime as SdkRuntime, RuntimeError, ValueType}, +}; use tezos_smart_rollup_mock::MockHost; -use core::slice::from_raw_parts; -use tezos_smart_rollup_core::smart_rollup_core::{ReadInputMessageInfo, SmartRollupCore}; +use tezos_smart_rollup_core::{smart_rollup_core::SmartRollupCore, PREIMAGE_HASH_SIZE}; pub struct EvalHost { - pub host: MockHost, + pub host: KernelHost, pub buffer: RefCell>, } @@ -18,123 +29,193 @@ impl EvalHost { /// Create a new instance of the `MockHost`, additionally provide the buffer /// where the logs will be outputed. pub fn default_with_buffer(buffer: RefCell>) -> Self { - let host = MockHost::default(); + let host = KernelHost::::default(); Self { host, buffer } } } -unsafe impl SmartRollupCore for EvalHost { - unsafe fn read_input( - &self, - message_info: *mut ReadInputMessageInfo, - dst: *mut u8, - max_bytes: usize, - ) -> i32 { - self.host.read_input(message_info, dst, max_bytes) +impl SdkRuntime for EvalHost { + #[inline(always)] + fn write_output(&mut self, from: &[u8]) -> Result<(), RuntimeError> { + self.host.write_output(from) } - unsafe fn write_debug(&self, src: *const u8, num_bytes: usize) { - let debug_out = from_raw_parts(src, num_bytes).to_vec(); - - let debug = String::from_utf8(debug_out).expect("unexpected non-utf8 debug log"); - + #[inline(always)] + fn write_debug(&self, data: &str) { let mut unboxed_buffer = self.buffer.borrow_mut(); - if let Err(e) = write!(*unboxed_buffer, "{}", &debug) { + if let Err(e) = write!(*unboxed_buffer, "{}", data) { eprint!("Error due to: {}", e) } } - unsafe fn write_output(&self, src: *const u8, num_bytes: usize) -> i32 { - self.host.write_output(src, num_bytes) + #[inline(always)] + fn read_input(&mut self) -> Result, RuntimeError> { + self.host.read_input() } - unsafe fn store_has(&self, path: *const u8, len: usize) -> i32 { - self.host.store_has(path, len) + #[inline(always)] + fn store_has(&self, path: &T) -> Result, RuntimeError> { + self.host.store_has(path) } - unsafe fn store_read( + #[inline(always)] + fn store_read( &self, - path: *const u8, - len: usize, - offset: usize, - dst: *mut u8, + path: &T, + from_offset: usize, max_bytes: usize, - ) -> i32 { - self.host.store_read(path, len, offset, dst, max_bytes) + ) -> Result, RuntimeError> { + self.host.store_read(path, from_offset, max_bytes) } - unsafe fn store_write( + #[inline(always)] + fn store_read_slice( &self, - path: *const u8, - len: usize, - offset: usize, - src: *const u8, - num_bytes: usize, - ) -> i32 { - self.host.store_write(path, len, offset, src, num_bytes) + path: &T, + from_offset: usize, + buffer: &mut [u8], + ) -> Result { + self.host.store_read_slice(path, from_offset, buffer) } - unsafe fn store_delete(&self, path: *const u8, len: usize) -> i32 { - self.host.store_delete(path, len) + #[inline(always)] + fn store_read_all(&self, path: &impl Path) -> Result, RuntimeError> { + self.host.store_read_all(path) } - unsafe fn store_delete_value(&self, path: *const u8, len: usize) -> i32 { - self.host.store_delete_value(path, len) + #[inline(always)] + fn store_write( + &mut self, + path: &T, + src: &[u8], + at_offset: usize, + ) -> Result<(), RuntimeError> { + self.host.store_write(path, src, at_offset) } - unsafe fn store_list_size(&self, path: *const u8, len: usize) -> i64 { - self.host.store_list_size(path, len) + #[inline(always)] + fn store_write_all( + &mut self, + path: &T, + src: &[u8], + ) -> Result<(), RuntimeError> { + self.host.store_write_all(path, src) } - unsafe fn store_move( - &self, - from_path: *const u8, - from_path_len: usize, - to_path: *const u8, - to_path_len: usize, - ) -> i32 { - self.host - .store_move(from_path, from_path_len, to_path, to_path_len) + #[inline(always)] + fn store_delete(&mut self, path: &T) -> Result<(), RuntimeError> { + self.host.store_delete(path) + } + + #[inline(always)] + fn store_delete_value(&mut self, path: &T) -> Result<(), RuntimeError> { + self.host.store_delete_value(path) + } + + #[inline(always)] + fn store_count_subkeys(&self, prefix: &T) -> Result { + self.host.store_count_subkeys(prefix) + } + + #[inline(always)] + fn store_move( + &mut self, + from_path: &impl Path, + to_path: &impl Path, + ) -> Result<(), RuntimeError> { + self.host.store_move(from_path, to_path) + } + + #[inline(always)] + fn store_copy( + &mut self, + from_path: &impl Path, + to_path: &impl Path, + ) -> Result<(), RuntimeError> { + self.host.store_copy(from_path, to_path) } - unsafe fn store_copy( + #[inline(always)] + fn reveal_preimage( &self, - from_path: *const u8, - from_path_len: usize, - to_path: *const u8, - to_path_len: usize, - ) -> i32 { - self.host - .store_copy(from_path, from_path_len, to_path, to_path_len) + hash: &[u8; PREIMAGE_HASH_SIZE], + destination: &mut [u8], + ) -> Result { + self.host.reveal_preimage(hash, destination) + } + + #[inline(always)] + fn store_value_size(&self, path: &impl Path) -> Result { + self.host.store_value_size(path) } - unsafe fn reveal_preimage( + #[inline(always)] + fn mark_for_reboot(&mut self) -> Result<(), RuntimeError> { + self.host.mark_for_reboot() + } + + #[inline(always)] + fn reveal_metadata(&self) -> RollupMetadata { + self.host.reveal_metadata() + } + + #[inline(always)] + fn reveal_dal_page( &self, - hash_addr: *const u8, - hash_len: usize, - destination_addr: *mut u8, - max_bytes: usize, - ) -> i32 { + published_level: i32, + slot_index: u8, + page_index: i16, + destination: &mut [u8], + ) -> Result { self.host - .reveal_preimage(hash_addr, hash_len, destination_addr, max_bytes) + .reveal_dal_page(published_level, slot_index, page_index, destination) } - unsafe fn store_value_size(&self, path: *const u8, path_len: usize) -> i32 { - self.host.store_value_size(path, path_len) + #[inline(always)] + fn reveal_dal_parameters(&self) -> RollupDalParameters { + self.host.reveal_dal_parameters() } - unsafe fn reveal_metadata(&self, destination_addr: *mut u8, max_bytes: usize) -> i32 { - self.host.reveal_metadata(destination_addr, max_bytes) + #[inline(always)] + fn last_run_aborted(&self) -> Result { + self.host.last_run_aborted() } - unsafe fn reveal( - &self, - _payload_addr: *const u8, - _payload_len: usize, - _destination_addr: *mut u8, - _max_bytes: usize, - ) -> i32 { - // TODO: https://gitlab.com/tezos/tezos/-/issues/6171 - unimplemented!("The `reveal` host function is not yet mocked.") + #[inline(always)] + fn upgrade_failed(&self) -> Result { + self.host.upgrade_failed() + } + + #[inline(always)] + fn restart_forced(&self) -> Result { + self.host.restart_forced() + } + + #[inline(always)] + fn reboot_left(&self) -> Result { + self.host.reboot_left() + } + + #[inline(always)] + fn runtime_version(&self) -> Result { + self.host.runtime_version() + } +} + +impl InternalRuntime for EvalHost { + fn __internal_store_get_hash( + &mut self, + path: &T, + ) -> Result, tezos_smart_rollup_host::runtime::RuntimeError> { + self.host.__internal_store_get_hash(path) + } +} + +impl ExtendedRuntime for EvalHost { + fn store_get_hash( + &mut self, + path: &T, + ) -> Result, tezos_smart_rollup_host::runtime::RuntimeError> { + self.host.store_get_hash(path) } } -- GitLab From 079c10a5502bc0877024b89a6bf323f27b43fd06 Mon Sep 17 00:00:00 2001 From: Pierrick Couderc Date: Mon, 9 Sep 2024 09:36:36 +0200 Subject: [PATCH 2/3] EVM/Kernel: Runtime, Runtime everywhere --- etherlink/kernel_evm/Cargo.lock | 3 +++ etherlink/kernel_evm/evm_execution/Cargo.toml | 1 + .../kernel_evm/evm_execution/src/account_storage.rs | 3 ++- .../kernel_evm/evm_execution/src/fa_bridge/mod.rs | 2 +- .../evm_execution/src/fa_bridge/ticket_table.rs | 6 ++---- etherlink/kernel_evm/evm_execution/src/handler.rs | 2 +- etherlink/kernel_evm/evm_execution/src/lib.rs | 3 ++- .../kernel_evm/evm_execution/src/precompiles/blake2.rs | 2 +- .../kernel_evm/evm_execution/src/precompiles/ecdsa.rs | 2 +- .../evm_execution/src/precompiles/fa_bridge.rs | 4 ++-- .../kernel_evm/evm_execution/src/precompiles/hash.rs | 2 +- .../evm_execution/src/precompiles/identity.rs | 2 +- .../kernel_evm/evm_execution/src/precompiles/mod.rs | 2 +- .../kernel_evm/evm_execution/src/precompiles/modexp.rs | 2 +- .../evm_execution/src/precompiles/withdrawal.rs | 4 ++-- .../evm_execution/src/precompiles/zero_knowledge.rs | 2 +- etherlink/kernel_evm/evm_execution/src/storage.rs | 3 ++- .../kernel_evm/evm_execution/src/withdrawal_counter.rs | 4 +++- etherlink/kernel_evm/indexable_storage/Cargo.toml | 1 + etherlink/kernel_evm/indexable_storage/src/lib.rs | 10 ++++++---- etherlink/kernel_evm/kernel/src/apply.rs | 2 +- etherlink/kernel_evm/kernel/src/block_storage.rs | 3 ++- etherlink/kernel_evm/kernel/src/bridge.rs | 6 ++---- etherlink/kernel_evm/kernel/src/dal.rs | 2 +- etherlink/kernel_evm/kernel/src/event.rs | 2 +- etherlink/kernel_evm/kernel/src/fallback_upgrade.rs | 2 +- etherlink/kernel_evm/kernel/src/fees.rs | 2 +- etherlink/kernel_evm/kernel/src/gas_price.rs | 2 +- etherlink/kernel_evm/kernel/src/linked_list.rs | 6 ++---- etherlink/kernel_evm/kernel/src/migration.rs | 3 ++- etherlink/kernel_evm/kernel/src/parsing.rs | 2 +- etherlink/kernel_evm/kernel/src/storage.rs | 3 ++- etherlink/kernel_evm/storage/Cargo.toml | 1 + etherlink/kernel_evm/storage/src/lib.rs | 3 ++- 34 files changed, 55 insertions(+), 44 deletions(-) diff --git a/etherlink/kernel_evm/Cargo.lock b/etherlink/kernel_evm/Cargo.lock index 275adcdaa9b9..9631ee1fbdac 100644 --- a/etherlink/kernel_evm/Cargo.lock +++ b/etherlink/kernel_evm/Cargo.lock @@ -729,6 +729,7 @@ dependencies = [ "sha3", "substrate-bn", "tezos-evm-logging", + "tezos-evm-runtime", "tezos-indexable-storage", "tezos-smart-rollup-core", "tezos-smart-rollup-debug", @@ -2240,6 +2241,7 @@ version = "0.1.0" dependencies = [ "rlp", "tezos-evm-logging", + "tezos-evm-runtime", "tezos-smart-rollup-host", "tezos-smart-rollup-mock", "tezos-smart-rollup-storage", @@ -2389,6 +2391,7 @@ dependencies = [ "primitive-types", "rlp", "sha3", + "tezos-evm-runtime", "tezos-smart-rollup-host", "tezos-smart-rollup-storage", "tezos_crypto_rs", diff --git a/etherlink/kernel_evm/evm_execution/Cargo.toml b/etherlink/kernel_evm/evm_execution/Cargo.toml index d2ba7bb84b56..e0257f30c966 100644 --- a/etherlink/kernel_evm/evm_execution/Cargo.toml +++ b/etherlink/kernel_evm/evm_execution/Cargo.toml @@ -38,6 +38,7 @@ bn.workspace = true tezos_ethereum.workspace = true tezos-evm-logging.workspace = true +tezos-evm-runtime.workspace = true tezos-indexable-storage.workspace = true tezos-storage.workspace = true diff --git a/etherlink/kernel_evm/evm_execution/src/account_storage.rs b/etherlink/kernel_evm/evm_execution/src/account_storage.rs index c37ce6617135..bba4439609a1 100644 --- a/etherlink/kernel_evm/evm_execution/src/account_storage.rs +++ b/etherlink/kernel_evm/evm_execution/src/account_storage.rs @@ -7,9 +7,10 @@ use const_decoder::Decoder; use host::path::{concat, OwnedPath, Path, RefPath}; -use host::runtime::{Runtime, RuntimeError, ValueType}; +use host::runtime::{RuntimeError, ValueType}; use primitive_types::{H160, H256, U256}; use rlp::DecoderError; +use tezos_evm_runtime::runtime::Runtime; use tezos_smart_rollup_storage::storage::Storage; use tezos_storage::{ error::Error as GenStorageError, read_u256_le_default, read_u64_le_default, diff --git a/etherlink/kernel_evm/evm_execution/src/fa_bridge/mod.rs b/etherlink/kernel_evm/evm_execution/src/fa_bridge/mod.rs index cab05b268535..a985573571f1 100644 --- a/etherlink/kernel_evm/evm_execution/src/fa_bridge/mod.rs +++ b/etherlink/kernel_evm/evm_execution/src/fa_bridge/mod.rs @@ -35,10 +35,10 @@ use std::borrow::Cow; use deposit::FaDeposit; use evm::{Config, ExitReason}; -use host::runtime::Runtime; use primitive_types::{H160, U256}; use tezos_ethereum::block::BlockConstants; use tezos_evm_logging::{log, Level::Info}; +use tezos_evm_runtime::runtime::Runtime; use ticket_table::TicketTable; use withdrawal::FaWithdrawal; diff --git a/etherlink/kernel_evm/evm_execution/src/fa_bridge/ticket_table.rs b/etherlink/kernel_evm/evm_execution/src/fa_bridge/ticket_table.rs index 34c2326a1025..524a34f7b1b2 100644 --- a/etherlink/kernel_evm/evm_execution/src/fa_bridge/ticket_table.rs +++ b/etherlink/kernel_evm/evm_execution/src/fa_bridge/ticket_table.rs @@ -9,10 +9,8 @@ use crate::account_storage::{account_path, AccountStorageError, EthereumAccount}; use primitive_types::{H160, H256, U256}; -use tezos_smart_rollup_host::{ - path::{concat, OwnedPath, RefPath}, - runtime::Runtime, -}; +use tezos_evm_runtime::runtime::Runtime; +use tezos_smart_rollup_host::path::{concat, OwnedPath, RefPath}; use tezos_storage::{path_from_h256, read_u256_le_default, write_u256_le}; /// Path where global ticket table is stored diff --git a/etherlink/kernel_evm/evm_execution/src/handler.rs b/etherlink/kernel_evm/evm_execution/src/handler.rs index 0ebf73a48ce4..e524c0e4d01b 100644 --- a/etherlink/kernel_evm/evm_execution/src/handler.rs +++ b/etherlink/kernel_evm/evm_execution/src/handler.rs @@ -36,13 +36,13 @@ use evm::{ CallScheme, Capture, Config, Context, CreateScheme, ExitError, ExitFatal, ExitReason, ExitRevert, ExitSucceed, Handler, Opcode, Resolve, Stack, Transfer, }; -use host::runtime::Runtime; use primitive_types::{H160, H256, U256}; use sha3::{Digest, Keccak256}; use std::cmp::min; use std::fmt::Debug; use tezos_ethereum::block::BlockConstants; use tezos_evm_logging::{log, Level::*}; +use tezos_evm_runtime::runtime::Runtime; use tezos_smart_rollup_encoding::michelson::ticket::FA2_1Ticket; use tezos_smart_rollup_encoding::michelson::{MichelsonContract, MichelsonPair}; use tezos_smart_rollup_encoding::outbox::OutboxMessage; diff --git a/etherlink/kernel_evm/evm_execution/src/lib.rs b/etherlink/kernel_evm/evm_execution/src/lib.rs index 684d56ef9946..3e59591fefd7 100644 --- a/etherlink/kernel_evm/evm_execution/src/lib.rs +++ b/etherlink/kernel_evm/evm_execution/src/lib.rs @@ -14,10 +14,11 @@ use alloc::collections::TryReserveError; use crypto::hash::{ContractKt1Hash, HashTrait}; use evm::executor::stack::PrecompileFailure; use handler::{EvmHandler, ExecutionResult}; -use host::{path::RefPath, runtime::Runtime}; +use host::path::RefPath; use primitive_types::{H160, H256, U256}; use tezos_ethereum::block::BlockConstants; use tezos_evm_logging::{log, Level::*}; +use tezos_evm_runtime::runtime::Runtime; use tezos_smart_rollup_storage::StorageError; use thiserror::Error; diff --git a/etherlink/kernel_evm/evm_execution/src/precompiles/blake2.rs b/etherlink/kernel_evm/evm_execution/src/precompiles/blake2.rs index 415975584323..7dc032392128 100644 --- a/etherlink/kernel_evm/evm_execution/src/precompiles/blake2.rs +++ b/etherlink/kernel_evm/evm_execution/src/precompiles/blake2.rs @@ -12,9 +12,9 @@ use crate::{handler::EvmHandler, precompiles::PrecompileOutcome, EthereumError}; use alloc::borrow::Cow; use evm::{executor::stack::PrecompileFailure, ExitError}; use evm::{Context, ExitReason, ExitSucceed, Transfer}; -use host::runtime::Runtime; use tezos_evm_logging::log; use tezos_evm_logging::Level::{Debug, Info}; +use tezos_evm_runtime::runtime::Runtime; /// The precomputed values for BLAKE2b [from the spec](https://tools.ietf.org/html/rfc7693#section-2.7) /// There are 10 16-byte arrays - one for each round diff --git a/etherlink/kernel_evm/evm_execution/src/precompiles/ecdsa.rs b/etherlink/kernel_evm/evm_execution/src/precompiles/ecdsa.rs index e00883ae43f1..93b505082685 100644 --- a/etherlink/kernel_evm/evm_execution/src/precompiles/ecdsa.rs +++ b/etherlink/kernel_evm/evm_execution/src/precompiles/ecdsa.rs @@ -8,13 +8,13 @@ use crate::precompiles::tick_model; use crate::{handler::EvmHandler, precompiles::PrecompileOutcome, EthereumError}; use evm::{Context, Transfer}; use evm::{ExitReason, ExitSucceed}; -use host::runtime::Runtime; use libsecp256k1::{recover, Message, RecoveryId, Signature}; use sha2::Digest; use sha3::Keccak256; use std::cmp::min; use tezos_evm_logging::log; use tezos_evm_logging::Level::{Debug, Info}; +use tezos_evm_runtime::runtime::Runtime; macro_rules! unwrap_ecrecover { ($expr : expr) => { diff --git a/etherlink/kernel_evm/evm_execution/src/precompiles/fa_bridge.rs b/etherlink/kernel_evm/evm_execution/src/precompiles/fa_bridge.rs index 2433e64a05d1..9aaf440d34be 100644 --- a/etherlink/kernel_evm/evm_execution/src/precompiles/fa_bridge.rs +++ b/etherlink/kernel_evm/evm_execution/src/precompiles/fa_bridge.rs @@ -13,7 +13,7 @@ use evm::{Context, Handler, Transfer}; use primitive_types::{H160, U256}; -use tezos_smart_rollup_host::runtime::Runtime; +use tezos_evm_runtime::runtime::Runtime; use crate::{ fa_bridge::{execute_fa_withdrawal, withdrawal::FaWithdrawal}, @@ -45,7 +45,7 @@ pub const FA_WITHDRAWAL_PRECOMPILE_TICKS_SLOPE: u64 = 700; /// /// An execution of a single outbox message carrying a FA withdrawal /// costs around 0.0025ꜩ on L1; the equivalent amount of gas units on L2 is: -/// +/// /// 0.0025 * 10^18 / GAS_PRICE /// /// Multiplying the numerator by 2 for a safe reserve and this is our cost in Wei. diff --git a/etherlink/kernel_evm/evm_execution/src/precompiles/hash.rs b/etherlink/kernel_evm/evm_execution/src/precompiles/hash.rs index 21edc8885e05..6330919ecf3c 100644 --- a/etherlink/kernel_evm/evm_execution/src/precompiles/hash.rs +++ b/etherlink/kernel_evm/evm_execution/src/precompiles/hash.rs @@ -7,11 +7,11 @@ use crate::fail_if_too_much; use crate::precompiles::{tick_model, PrecompileOutcome}; use crate::{handler::EvmHandler, EthereumError}; use evm::{Context, ExitReason, ExitSucceed, Transfer}; -use host::runtime::Runtime; use ripemd::Ripemd160; use sha2::{Digest, Sha256}; use tezos_evm_logging::log; use tezos_evm_logging::Level::Debug; +use tezos_evm_runtime::runtime::Runtime; // Implementation of 0x03 precompiled (sha256) pub fn sha256_precompile( diff --git a/etherlink/kernel_evm/evm_execution/src/precompiles/identity.rs b/etherlink/kernel_evm/evm_execution/src/precompiles/identity.rs index 001006520b25..73c54e4dbc94 100644 --- a/etherlink/kernel_evm/evm_execution/src/precompiles/identity.rs +++ b/etherlink/kernel_evm/evm_execution/src/precompiles/identity.rs @@ -8,9 +8,9 @@ use crate::precompiles::tick_model; use crate::{handler::EvmHandler, precompiles::PrecompileOutcome, EthereumError}; use evm::{Context, Transfer}; use evm::{ExitReason, ExitSucceed}; -use host::runtime::Runtime; use tezos_evm_logging::log; use tezos_evm_logging::Level::Debug; +use tezos_evm_runtime::runtime::Runtime; // Implementation of 0x02 precompiled (identity) pub fn identity_precompile( diff --git a/etherlink/kernel_evm/evm_execution/src/precompiles/mod.rs b/etherlink/kernel_evm/evm_execution/src/precompiles/mod.rs index 76a9a7f27927..eeeccb9cb396 100644 --- a/etherlink/kernel_evm/evm_execution/src/precompiles/mod.rs +++ b/etherlink/kernel_evm/evm_execution/src/precompiles/mod.rs @@ -30,10 +30,10 @@ use ecdsa::ecrecover_precompile; use evm::{Context, ExitReason, Handler, Transfer}; use fa_bridge::fa_bridge_precompile; use hash::{ripemd160_precompile, sha256_precompile}; -use host::runtime::Runtime; use identity::identity_precompile; use modexp::modexp_precompile; use primitive_types::H160; +use tezos_evm_runtime::runtime::Runtime; use withdrawal::withdrawal_precompile; use zero_knowledge::{ecadd_precompile, ecmul_precompile, ecpairing_precompile}; diff --git a/etherlink/kernel_evm/evm_execution/src/precompiles/modexp.rs b/etherlink/kernel_evm/evm_execution/src/precompiles/modexp.rs index e24b15477913..132bafe5163b 100644 --- a/etherlink/kernel_evm/evm_execution/src/precompiles/modexp.rs +++ b/etherlink/kernel_evm/evm_execution/src/precompiles/modexp.rs @@ -16,10 +16,10 @@ use crate::{ }; use aurora_engine_modexp::modexp; use evm::{Context, ExitError, ExitReason, ExitSucceed, Transfer}; -use host::runtime::Runtime; use primitive_types::U256; use tezos_evm_logging::log; use tezos_evm_logging::Level::Debug; +use tezos_evm_runtime::runtime::Runtime; fn calculate_iteration_count(exp_length: u64, exp_highp: &U256) -> u64 { let mut iteration_count: u64 = 0; diff --git a/etherlink/kernel_evm/evm_execution/src/precompiles/withdrawal.rs b/etherlink/kernel_evm/evm_execution/src/precompiles/withdrawal.rs index 687900e930b5..6cf22727846d 100644 --- a/etherlink/kernel_evm/evm_execution/src/precompiles/withdrawal.rs +++ b/etherlink/kernel_evm/evm_execution/src/precompiles/withdrawal.rs @@ -19,7 +19,6 @@ use crate::withdrawal_counter::WithdrawalCounter; use crate::{abi, fail_if_too_much, EthereumError}; use evm::Handler; use evm::{Context, ExitReason, ExitRevert, ExitSucceed, Transfer}; -use host::runtime::Runtime; use primitive_types::H160; use primitive_types::H256; use primitive_types::U256; @@ -29,6 +28,7 @@ use tezos_ethereum::wei::ErrorMutezFromWei; use tezos_ethereum::Log; use tezos_evm_logging::log; use tezos_evm_logging::Level::Info; +use tezos_evm_runtime::runtime::Runtime; use tezos_smart_rollup_encoding::contract::Contract; use tezos_smart_rollup_encoding::entrypoint::Entrypoint; use tezos_smart_rollup_encoding::michelson::ticket::FA2_1Ticket; @@ -46,7 +46,7 @@ use tezos_smart_rollup_encoding::outbox::{OutboxMessage, OutboxMessageTransactio /// /// An execution of a single outbox message carrying a XTZ withdrawal /// costs around 0.0025ꜩ on L1; the equivalent amount of gas units on L2 is: -/// +/// /// 0.0025 * 10^18 / GAS_PRICE /// /// Multiplying the numerator by 2 for a safe reserve and this is our cost in Wei. diff --git a/etherlink/kernel_evm/evm_execution/src/precompiles/zero_knowledge.rs b/etherlink/kernel_evm/evm_execution/src/precompiles/zero_knowledge.rs index fdaecf3e151b..c351d7cb53fa 100644 --- a/etherlink/kernel_evm/evm_execution/src/precompiles/zero_knowledge.rs +++ b/etherlink/kernel_evm/evm_execution/src/precompiles/zero_knowledge.rs @@ -9,10 +9,10 @@ use alloc::vec::Vec; use bn::{FieldError, GroupError}; use evm::{executor::stack::PrecompileFailure, ExitError, ExitReason, ExitSucceed}; use evm::{Context, Transfer}; -use host::runtime::Runtime; use primitive_types::U256; use tezos_evm_logging::log; use tezos_evm_logging::Level::Debug; +use tezos_evm_runtime::runtime::Runtime; /// Input length for the add operation. const ADD_INPUT_LEN: usize = 128; diff --git a/etherlink/kernel_evm/evm_execution/src/storage.rs b/etherlink/kernel_evm/evm_execution/src/storage.rs index 763b7076526b..11f5c431bca8 100644 --- a/etherlink/kernel_evm/evm_execution/src/storage.rs +++ b/etherlink/kernel_evm/evm_execution/src/storage.rs @@ -6,12 +6,13 @@ pub mod tracer { use host::{ path::{OwnedPath, RefPath}, - runtime::{Runtime, RuntimeError}, + runtime::RuntimeError, }; use primitive_types::H256; use tezos_evm_logging::log; use tezos_evm_logging::Level::Debug; + use tezos_evm_runtime::runtime::Runtime; use tezos_indexable_storage::{IndexableStorage, IndexableStorageError}; use tezos_smart_rollup_host::path::*; use thiserror::Error; diff --git a/etherlink/kernel_evm/evm_execution/src/withdrawal_counter.rs b/etherlink/kernel_evm/evm_execution/src/withdrawal_counter.rs index a0cb00dfe164..c3b355b839e2 100644 --- a/etherlink/kernel_evm/evm_execution/src/withdrawal_counter.rs +++ b/etherlink/kernel_evm/evm_execution/src/withdrawal_counter.rs @@ -11,7 +11,9 @@ //! revertable updates (if withdrawal fails the counter won't increment). use primitive_types::U256; -use tezos_smart_rollup_host::{path::RefPath, runtime::Runtime}; + +use tezos_evm_runtime::runtime::Runtime; +use tezos_smart_rollup_host::path::RefPath; use tezos_storage::{read_u256_le_default, write_u256_le}; use crate::account_storage::{AccountStorageError, EthereumAccount}; diff --git a/etherlink/kernel_evm/indexable_storage/Cargo.toml b/etherlink/kernel_evm/indexable_storage/Cargo.toml index 951bf3e44f7f..a1d92959bc84 100644 --- a/etherlink/kernel_evm/indexable_storage/Cargo.toml +++ b/etherlink/kernel_evm/indexable_storage/Cargo.toml @@ -12,6 +12,7 @@ license = "MIT" thiserror.workspace = true rlp.workspace = true tezos-evm-logging.workspace = true +tezos-evm-runtime.workspace = true tezos-smart-rollup-host.workspace = true tezos-smart-rollup-mock.workspace = true tezos-smart-rollup-storage.workspace = true diff --git a/etherlink/kernel_evm/indexable_storage/src/lib.rs b/etherlink/kernel_evm/indexable_storage/src/lib.rs index 4140190fe31b..15128d47f86a 100644 --- a/etherlink/kernel_evm/indexable_storage/src/lib.rs +++ b/etherlink/kernel_evm/indexable_storage/src/lib.rs @@ -6,8 +6,9 @@ use rlp::DecoderError; use tezos_evm_logging::log; use tezos_evm_logging::Level::Error; +use tezos_evm_runtime::runtime::Runtime; use tezos_smart_rollup_host::path::{concat, OwnedPath, PathError, RefPath}; -use tezos_smart_rollup_host::runtime::{Runtime, RuntimeError}; +use tezos_smart_rollup_host::runtime::RuntimeError; use tezos_smart_rollup_storage::StorageError; use tezos_storage::{error::Error as GenStorageError, read_u64_le, write_u64_le}; use thiserror::Error; @@ -164,12 +165,13 @@ impl IndexableStorage { #[cfg(test)] mod tests { use super::*; + use tezos_evm_runtime::{mock_internal::MockInternal, runtime::KernelHost}; use tezos_smart_rollup_host::path::RefPath; use tezos_smart_rollup_mock::MockHost; #[test] fn test_indexable_empty() { - let host = MockHost::default(); + let host = KernelHost::::default(); let values = RefPath::assert_from(b"/values"); let storage = IndexableStorage::new(&values).expect("Path to index is invalid"); @@ -178,7 +180,7 @@ mod tests { #[test] fn test_indexing_new_value() { - let mut host = MockHost::default(); + let mut host = KernelHost::::default(); let values = RefPath::assert_from(b"/values"); let storage = IndexableStorage::new(&values).expect("Path to index is invalid"); @@ -195,7 +197,7 @@ mod tests { #[test] fn test_get_out_of_bounds() { - let mut host = MockHost::default(); + let mut host = KernelHost::::default(); let values = RefPath::assert_from(b"/values"); let storage = IndexableStorage::new(&values).expect("Path to index is invalid"); diff --git a/etherlink/kernel_evm/kernel/src/apply.rs b/etherlink/kernel_evm/kernel/src/apply.rs index 1339173162b2..1ed5aa032358 100644 --- a/etherlink/kernel_evm/kernel/src/apply.rs +++ b/etherlink/kernel_evm/kernel/src/apply.rs @@ -26,9 +26,9 @@ use tezos_ethereum::transaction::{TransactionHash, TransactionType}; use tezos_ethereum::tx_common::EthereumTransactionCommon; use tezos_ethereum::tx_signature::TxSignature; use tezos_evm_logging::{log, Level::*}; +use tezos_evm_runtime::runtime::Runtime; use tezos_smart_rollup::outbox::{OutboxMessage, OutboxQueue}; use tezos_smart_rollup_host::path::{Path, RefPath}; -use tezos_smart_rollup_host::runtime::Runtime; use crate::bridge::{execute_deposit, Deposit}; use crate::configuration::Limits; diff --git a/etherlink/kernel_evm/kernel/src/block_storage.rs b/etherlink/kernel_evm/kernel/src/block_storage.rs index e0010b7d6815..b423f3565b24 100644 --- a/etherlink/kernel_evm/kernel/src/block_storage.rs +++ b/etherlink/kernel_evm/kernel/src/block_storage.rs @@ -6,10 +6,11 @@ use primitive_types::{H256, U256}; use tezos_ethereum::block::L2Block; use tezos_ethereum::rlp_helpers::VersionedEncoding; use tezos_evm_logging::{log, Level::Info}; +use tezos_evm_runtime::runtime::Runtime; use tezos_indexable_storage::IndexableStorage; +use tezos_smart_rollup_host::path::concat; use tezos_smart_rollup_host::path::OwnedPath; use tezos_smart_rollup_host::path::RefPath; -use tezos_smart_rollup_host::{path::concat, runtime::Runtime}; use tezos_storage::{read_h256_be, read_u256_le, write_h256_be, write_u256_le}; mod path { diff --git a/etherlink/kernel_evm/kernel/src/bridge.rs b/etherlink/kernel_evm/kernel/src/bridge.rs index 5f1bf96da0f3..df71f8d3ae64 100644 --- a/etherlink/kernel_evm/kernel/src/bridge.rs +++ b/etherlink/kernel_evm/kernel/src/bridge.rs @@ -22,10 +22,8 @@ use tezos_ethereum::{ wei::eth_from_mutez, }; use tezos_evm_logging::{log, Level::Info}; -use tezos_smart_rollup::{ - host::Runtime, - michelson::{ticket::FA2_1Ticket, MichelsonBytes}, -}; +use tezos_evm_runtime::runtime::Runtime; +use tezos_smart_rollup::michelson::{ticket::FA2_1Ticket, MichelsonBytes}; use crate::tick_model; diff --git a/etherlink/kernel_evm/kernel/src/dal.rs b/etherlink/kernel_evm/kernel/src/dal.rs index db309d28701d..749d632073a5 100644 --- a/etherlink/kernel_evm/kernel/src/dal.rs +++ b/etherlink/kernel_evm/kernel/src/dal.rs @@ -8,7 +8,7 @@ use rlp::{DecoderError, PayloadInfo}; use tezos_evm_logging::{log, Level::*}; use tezos_smart_rollup_host::dal_parameters::RollupDalParameters; -use tezos_smart_rollup_host::runtime::Runtime; +use tezos_evm_runtime::runtime::Runtime; const TAG_SIZE: usize = 1; diff --git a/etherlink/kernel_evm/kernel/src/event.rs b/etherlink/kernel_evm/kernel/src/event.rs index bc8ab65d6e50..0a20b5a7c027 100644 --- a/etherlink/kernel_evm/kernel/src/event.rs +++ b/etherlink/kernel_evm/kernel/src/event.rs @@ -6,7 +6,7 @@ use crate::{inbox::Transaction, storage, upgrade}; use primitive_types::{H256, U256}; use rlp::{Encodable, RlpStream}; use tezos_ethereum::rlp_helpers::append_u256_le; -use tezos_smart_rollup_host::runtime::Runtime; +use tezos_evm_runtime::runtime::Runtime; pub const UPGRADE_TAG: u8 = 0x01; pub const SEQUENCER_UPGRADE_TAG: u8 = 0x02; diff --git a/etherlink/kernel_evm/kernel/src/fallback_upgrade.rs b/etherlink/kernel_evm/kernel/src/fallback_upgrade.rs index 87306be6d26d..d1a8caecfb6f 100644 --- a/etherlink/kernel_evm/kernel/src/fallback_upgrade.rs +++ b/etherlink/kernel_evm/kernel/src/fallback_upgrade.rs @@ -3,8 +3,8 @@ // SPDX-License-Identifier: MIT use tezos_evm_logging::{log, Level::*}; +use tezos_evm_runtime::runtime::Runtime; use tezos_smart_rollup_core::PREIMAGE_HASH_SIZE; -use tezos_smart_rollup_host::runtime::Runtime; use tezos_smart_rollup_host::{path::RefPath, runtime::RuntimeError, KERNEL_BOOT_PATH}; use crate::upgrade::KERNEL_ROOT_HASH; diff --git a/etherlink/kernel_evm/kernel/src/fees.rs b/etherlink/kernel_evm/kernel/src/fees.rs index e12a619d3ffe..7e0e1a5a1592 100644 --- a/etherlink/kernel_evm/kernel/src/fees.rs +++ b/etherlink/kernel_evm/kernel/src/fees.rs @@ -24,7 +24,7 @@ use primitive_types::{H160, H256, U256}; use tezos_ethereum::access_list::AccessListItem; use tezos_ethereum::block::BlockFees; use tezos_ethereum::tx_common::EthereumTransactionCommon; -use tezos_smart_rollup_host::runtime::Runtime; +use tezos_evm_runtime::runtime::Runtime; use std::mem::size_of; diff --git a/etherlink/kernel_evm/kernel/src/gas_price.rs b/etherlink/kernel_evm/kernel/src/gas_price.rs index cdf383111224..78b946b9990f 100644 --- a/etherlink/kernel_evm/kernel/src/gas_price.rs +++ b/etherlink/kernel_evm/kernel/src/gas_price.rs @@ -10,8 +10,8 @@ use crate::storage::{read_minimum_base_fee_per_gas, store_base_fee_per_gas}; use primitive_types::U256; use softfloat::F64; use tezos_ethereum::block::BlockFees; +use tezos_evm_runtime::runtime::Runtime; use tezos_smart_rollup_encoding::timestamp::Timestamp; -use tezos_smart_rollup_host::runtime::Runtime; // actual ~34M, allow some overhead for less effecient ERC20 transfers. const ERC20_TICKS: u64 = 40_000_000; diff --git a/etherlink/kernel_evm/kernel/src/linked_list.rs b/etherlink/kernel_evm/kernel/src/linked_list.rs index ded7142c4b24..69abd0812021 100644 --- a/etherlink/kernel_evm/kernel/src/linked_list.rs +++ b/etherlink/kernel_evm/kernel/src/linked_list.rs @@ -4,10 +4,8 @@ use anyhow::{Context, Result}; use rlp::{Decodable, DecoderError, Encodable, Rlp, RlpIterator, RlpStream}; use std::marker::PhantomData; use tezos_ethereum::rlp_helpers::{append_option, decode_field, decode_option, next}; -use tezos_smart_rollup_host::{ - path::{concat, OwnedPath, Path}, - runtime::Runtime, -}; +use tezos_evm_runtime::runtime::Runtime; +use tezos_smart_rollup_host::path::{concat, OwnedPath, Path}; use tezos_storage::{read_optional_rlp, read_rlp, store_rlp}; /// Doubly linked list using the durable storage. diff --git a/etherlink/kernel_evm/kernel/src/migration.rs b/etherlink/kernel_evm/kernel/src/migration.rs index 5e9a45d2af3c..67654e9484a5 100644 --- a/etherlink/kernel_evm/kernel/src/migration.rs +++ b/etherlink/kernel_evm/kernel/src/migration.rs @@ -15,9 +15,10 @@ use crate::storage::{ use evm_execution::NATIVE_TOKEN_TICKETER_PATH; use primitive_types::U256; use tezos_evm_logging::{log, Level::*}; +use tezos_evm_runtime::runtime::Runtime; use tezos_smart_rollup::storage::path::RefPath; use tezos_smart_rollup_host::path::OwnedPath; -use tezos_smart_rollup_host::runtime::{Runtime, RuntimeError}; +use tezos_smart_rollup_host::runtime::RuntimeError; #[derive(Eq, PartialEq)] pub enum MigrationStatus { diff --git a/etherlink/kernel_evm/kernel/src/parsing.rs b/etherlink/kernel_evm/kernel/src/parsing.rs index d9fa272c46b3..8dd82ed7f2a2 100644 --- a/etherlink/kernel_evm/kernel/src/parsing.rs +++ b/etherlink/kernel_evm/kernel/src/parsing.rs @@ -30,6 +30,7 @@ use tezos_ethereum::{ tx_common::EthereumTransactionCommon, }; use tezos_evm_logging::{log, Level::*}; +use tezos_evm_runtime::runtime::Runtime; use tezos_smart_rollup_encoding::{ contract::Contract, inbox::{ @@ -39,7 +40,6 @@ use tezos_smart_rollup_encoding::{ public_key::PublicKey, }; use tezos_smart_rollup_host::input::Message; -use tezos_smart_rollup_host::runtime::Runtime; /// On an option, either the value, or if `None`, interrupt and return the /// default value of the return type instead. diff --git a/etherlink/kernel_evm/kernel/src/storage.rs b/etherlink/kernel_evm/kernel/src/storage.rs index 80d6eba83f09..3df67ca122c0 100644 --- a/etherlink/kernel_evm/kernel/src/storage.rs +++ b/etherlink/kernel_evm/kernel/src/storage.rs @@ -16,12 +16,13 @@ use num_derive::{FromPrimitive, ToPrimitive}; use num_traits::{FromPrimitive, ToPrimitive}; use tezos_crypto_rs::hash::ContractKt1Hash; use tezos_evm_logging::{log, Level::*}; +use tezos_evm_runtime::runtime::Runtime; use tezos_indexable_storage::IndexableStorage; use tezos_smart_rollup_core::MAX_FILE_CHUNK_SIZE; use tezos_smart_rollup_encoding::public_key::PublicKey; use tezos_smart_rollup_encoding::timestamp::Timestamp; use tezos_smart_rollup_host::path::*; -use tezos_smart_rollup_host::runtime::{Runtime, ValueType}; +use tezos_smart_rollup_host::runtime::ValueType; use tezos_storage::{ read_b58_kt1, read_u256_le, read_u64_le, store_read_slice, write_u256_le, write_u64_le, diff --git a/etherlink/kernel_evm/storage/Cargo.toml b/etherlink/kernel_evm/storage/Cargo.toml index 7b07958d35e7..f4429eb742bb 100644 --- a/etherlink/kernel_evm/storage/Cargo.toml +++ b/etherlink/kernel_evm/storage/Cargo.toml @@ -21,5 +21,6 @@ tezos_crypto_rs.workspace = true sha3.workspace = true tezos_ethereum.workspace = true +tezos-evm-runtime.workspace = true tezos-smart-rollup-host.workspace = true tezos-smart-rollup-storage.workspace = true diff --git a/etherlink/kernel_evm/storage/src/lib.rs b/etherlink/kernel_evm/storage/src/lib.rs index c1733cb7ae03..11ad7f23f8f5 100644 --- a/etherlink/kernel_evm/storage/src/lib.rs +++ b/etherlink/kernel_evm/storage/src/lib.rs @@ -15,8 +15,9 @@ use rlp::{Decodable, Encodable}; use tezos_crypto_rs::hash::{ContractKt1Hash, HashTrait}; use tezos_ethereum::rlp_helpers::FromRlpBytes; +use tezos_evm_runtime::runtime::Runtime; use tezos_smart_rollup_host::path::*; -use tezos_smart_rollup_host::runtime::{Runtime, RuntimeError, ValueType}; +use tezos_smart_rollup_host::runtime::{RuntimeError, ValueType}; /// The size of one 256 bit word. Size in bytes. pub const WORD_SIZE: usize = 32usize; -- GitLab From 517684366c68c5e848214c37ecf341526fcb455c Mon Sep 17 00:00:00 2001 From: Pierrick Couderc Date: Mon, 9 Sep 2024 10:24:20 +0200 Subject: [PATCH 3/3] EVM/Kernel: all the tests are using MockKernelHost --- .../kernel_evm/evm_evaluation/src/evalhost.rs | 10 +- .../evm_execution/src/account_storage.rs | 37 ++-- .../evm_execution/src/code_storage.rs | 12 +- .../evm_execution/src/fa_bridge/test_utils.rs | 18 +- .../evm_execution/src/fa_bridge/tests.rs | 16 +- .../src/fa_bridge/ticket_table.rs | 6 +- .../kernel_evm/evm_execution/src/handler.rs | 152 +++++++------- etherlink/kernel_evm/evm_execution/src/lib.rs | 186 +++++++++--------- .../src/precompiles/fa_bridge.rs | 22 +-- .../evm_execution/src/precompiles/mod.rs | 10 +- .../evm_execution/src/withdrawal_counter.rs | 4 +- .../kernel_evm/indexable_storage/src/lib.rs | 9 +- etherlink/kernel_evm/kernel/src/apply.rs | 19 +- .../kernel/src/blueprint_storage.rs | 2 +- etherlink/kernel_evm/kernel/src/bridge.rs | 6 +- etherlink/kernel_evm/kernel/src/fees.rs | 12 +- etherlink/kernel_evm/kernel/src/lib.rs | 9 +- .../kernel_evm/kernel/src/linked_list.rs | 40 ++-- etherlink/kernel_evm/kernel/src/parsing.rs | 4 +- etherlink/kernel_evm/kernel/src/storage.rs | 4 +- 20 files changed, 293 insertions(+), 285 deletions(-) diff --git a/etherlink/kernel_evm/evm_evaluation/src/evalhost.rs b/etherlink/kernel_evm/evm_evaluation/src/evalhost.rs index 0d1440293c0f..0ae2f6876fbc 100644 --- a/etherlink/kernel_evm/evm_evaluation/src/evalhost.rs +++ b/etherlink/kernel_evm/evm_evaluation/src/evalhost.rs @@ -6,8 +6,7 @@ use std::{cell::RefCell, io::Write}; use tezos_evm_runtime::{ internal_runtime::{ExtendedRuntime, InternalRuntime}, - mock_internal::MockInternal, - runtime::KernelHost, + runtime::MockKernelHost, }; use tezos_smart_rollup_host::{ dal_parameters::RollupDalParameters, @@ -16,12 +15,11 @@ use tezos_smart_rollup_host::{ path::Path, runtime::{Runtime as SdkRuntime, RuntimeError, ValueType}, }; -use tezos_smart_rollup_mock::MockHost; -use tezos_smart_rollup_core::{smart_rollup_core::SmartRollupCore, PREIMAGE_HASH_SIZE}; +use tezos_smart_rollup_core::PREIMAGE_HASH_SIZE; pub struct EvalHost { - pub host: KernelHost, + pub host: MockKernelHost, pub buffer: RefCell>, } @@ -29,7 +27,7 @@ impl EvalHost { /// Create a new instance of the `MockHost`, additionally provide the buffer /// where the logs will be outputed. pub fn default_with_buffer(buffer: RefCell>) -> Self { - let host = KernelHost::::default(); + let host = MockKernelHost::default(); Self { host, buffer } } } diff --git a/etherlink/kernel_evm/evm_execution/src/account_storage.rs b/etherlink/kernel_evm/evm_execution/src/account_storage.rs index bba4439609a1..77946172a3a7 100644 --- a/etherlink/kernel_evm/evm_execution/src/account_storage.rs +++ b/etherlink/kernel_evm/evm_execution/src/account_storage.rs @@ -527,13 +527,14 @@ mod test { use super::*; use host::path::RefPath; use primitive_types::U256; - use tezos_smart_rollup_mock::MockHost; + use tezos_evm_runtime::runtime::MockKernelHost; + use tezos_smart_rollup_host::runtime::Runtime as SdkRuntime; // Used for use tezos_storage::helpers::bytes_hash; use tezos_storage::write_u256_le; #[test] fn test_account_nonce_update() { - let mut host = MockHost::default(); + let mut host = MockKernelHost::default(); let mut storage = init_account_storage().expect("Could not create EVM accounts storage API"); @@ -569,7 +570,7 @@ mod test { #[test] fn test_zero_account_balance_for_new_accounts() { - let mut host = MockHost::default(); + let mut host = MockKernelHost::default(); let mut storage = init_account_storage().expect("Could not create EVM accounts storage API"); @@ -607,7 +608,7 @@ mod test { #[test] fn test_account_balance_add() { - let mut host = MockHost::default(); + let mut host = MockKernelHost::default(); let mut storage = init_account_storage().expect("Could not create EVM accounts storage API"); @@ -651,7 +652,7 @@ mod test { #[test] fn test_account_balance_sub() { - let mut host = MockHost::default(); + let mut host = MockKernelHost::default(); let mut storage = init_account_storage().expect("Could not create EVM accounts storage API"); @@ -695,7 +696,7 @@ mod test { #[test] fn test_account_balance_underflow() { - let mut host = MockHost::default(); + let mut host = MockKernelHost::default(); let mut storage = init_account_storage().expect("Could not create EVM accounts storage API"); @@ -737,7 +738,7 @@ mod test { #[test] fn test_account_storage_zero_default() { - let mut host = MockHost::default(); + let mut host = MockKernelHost::default(); let mut storage = init_account_storage().expect("Could not create EVM accounts storage API"); @@ -764,7 +765,7 @@ mod test { #[test] fn test_account_storage_update() { - let mut host = MockHost::default(); + let mut host = MockKernelHost::default(); let mut storage = init_account_storage().expect("Could not create EVM accounts storage API"); @@ -805,7 +806,7 @@ mod test { #[test] fn test_account_storage_update_checked() { - let mut host = MockHost::default(); + let mut host = MockKernelHost::default(); let mut storage = init_account_storage().expect("Could not create EVM accounts storage API"); @@ -886,7 +887,7 @@ mod test { #[test] fn test_account_code_storage_initial_code_is_zero() { - let mut host = MockHost::default(); + let mut host = MockKernelHost::default(); let mut storage = init_account_storage().expect("Could not create EVM accounts storage API"); @@ -934,7 +935,7 @@ mod test { } fn test_account_code_storage_write_code_aux(sample_code: Vec) { - let mut host = MockHost::default(); + let mut host = MockKernelHost::default(); let mut storage = init_account_storage().expect("Could not create EVM accounts storage API"); @@ -994,7 +995,7 @@ mod test { #[test] fn test_account_code_storage_cant_be_overwritten() { - let mut host = MockHost::default(); + let mut host = MockKernelHost::default(); let mut storage = init_account_storage().expect("Could not create EVM accounts storage API"); @@ -1046,7 +1047,7 @@ mod test { #[test] fn test_account_code_storage_delete_code() { - let mut host = MockHost::default(); + let mut host = MockKernelHost::default(); let mut storage = init_account_storage().expect("Could not create EVM accounts storage API"); @@ -1100,7 +1101,7 @@ mod test { #[test] fn test_empty_contract_hash_matches_default() { - let mut host = MockHost::default(); + let mut host = MockKernelHost::default(); let mut storage = init_account_storage().expect("Could not create EVM accounts storage API"); @@ -1149,7 +1150,7 @@ mod test { #[test] fn test_read_u256_le_default_le() { - let mut host = MockHost::default(); + let mut host = MockKernelHost::default(); let path = RefPath::assert_from(b"/value"); assert_eq!( read_u256_le_default(&host, &path, U256::from(128)).unwrap(), @@ -1178,7 +1179,7 @@ mod test { #[test] fn test_write_u256_le_le() { - let mut host = MockHost::default(); + let mut host = MockKernelHost::default(); let path = RefPath::assert_from(b"/value"); write_u256_le(&mut host, &path, U256::from(255)).unwrap(); @@ -1193,7 +1194,7 @@ mod test { let sample_code: Vec = (0..100).collect(); let sample_code_hash: H256 = bytes_hash(&sample_code); - let mut host = MockHost::default(); + let mut host = MockKernelHost::default(); let mut storage = init_account_storage().expect("Could not create EVM accounts storage API"); @@ -1260,7 +1261,7 @@ mod test { let sample_code: Vec = (0..100).collect(); let sample_code_hash: H256 = bytes_hash(&sample_code); - let mut host = MockHost::default(); + let mut host = MockKernelHost::default(); let mut storage = init_account_storage().expect("Could not create EVM accounts storage API"); diff --git a/etherlink/kernel_evm/evm_execution/src/code_storage.rs b/etherlink/kernel_evm/evm_execution/src/code_storage.rs index 3d8adc93c1a7..6474eb67edd4 100644 --- a/etherlink/kernel_evm/evm_execution/src/code_storage.rs +++ b/etherlink/kernel_evm/evm_execution/src/code_storage.rs @@ -7,7 +7,7 @@ use host::path::{concat, OwnedPath, RefPath}; use primitive_types::{H256, U256}; -use tezos_smart_rollup_host::runtime::Runtime; +use tezos_evm_runtime::runtime::Runtime; use tezos_storage::helpers::bytes_hash; use tezos_storage::{error::Error as GenStorageError, read_u64_le, write_u64_le}; @@ -144,13 +144,13 @@ impl CodeStorage { #[cfg(test)] mod test { use crate::account_storage; - use tezos_smart_rollup_mock::MockHost; + use tezos_evm_runtime::runtime::MockKernelHost; use super::*; #[test] fn test_empty_contract_hash_matches_default() { - let mut host = MockHost::default(); + let mut host = MockKernelHost::default(); let empty_code: Vec = vec![]; let empty_code_hash: H256 = account_storage::CODE_HASH_DEFAULT; @@ -162,7 +162,7 @@ mod test { #[test] fn test_get_code_matches_given() { - let mut host = MockHost::default(); + let mut host = MockKernelHost::default(); let code: Vec = (0..100).collect(); let code_hash = CodeStorage::add(&mut host, &code).expect("Could not create code storage"); @@ -172,7 +172,7 @@ mod test { #[test] fn test_code_ref_is_incremented() { - let mut host = MockHost::default(); + let mut host = MockKernelHost::default(); let code: Vec = (0..100).collect(); let code_hash = CodeStorage::add(&mut host, &code).expect("Could not create code storage"); @@ -200,7 +200,7 @@ mod test { #[test] fn test_code_is_deleted() { - let mut host = MockHost::default(); + let mut host = MockKernelHost::default(); let code_hash: H256 = account_storage::CODE_HASH_DEFAULT; let code_storage = diff --git a/etherlink/kernel_evm/evm_execution/src/fa_bridge/test_utils.rs b/etherlink/kernel_evm/evm_execution/src/fa_bridge/test_utils.rs index 26996ecde22c..ed9860258ffc 100644 --- a/etherlink/kernel_evm/evm_execution/src/fa_bridge/test_utils.rs +++ b/etherlink/kernel_evm/evm_execution/src/fa_bridge/test_utils.rs @@ -7,18 +7,18 @@ pub use alloy_sol_types::SolCall; use alloy_sol_types::{sol, SolConstructor}; use crypto::hash::ContractKt1Hash; use evm::Config; -use host::runtime::Runtime; use primitive_types::{H160, H256, U256}; use tezos_data_encoding::enc::BinWriter; use tezos_ethereum::{ block::{BlockConstants, BlockFees}, Log, }; +use tezos_evm_runtime::runtime::MockKernelHost; +use tezos_evm_runtime::runtime::Runtime; use tezos_smart_rollup_encoding::{ contract::Contract, michelson::{ticket::FA2_1Ticket, MichelsonOption, MichelsonPair}, }; -use tezos_smart_rollup_mock::MockHost; use tezos_storage::read_u256_le_default; use crate::{ @@ -51,7 +51,7 @@ const MOCK_WRAPPER_BYTECODE: &[u8] = /// Create a smart contract in the storage with the mocked token code pub fn deploy_mock_wrapper( - host: &mut MockHost, + host: &mut MockKernelHost, evm_account_storage: &mut EthereumAccountStorage, ticket: &FA2_1Ticket, caller: &H160, @@ -67,7 +67,7 @@ pub fn deploy_mock_wrapper( )); let block = dummy_block_constants(); - let precompiles = precompile_set::(false); + let precompiles = precompile_set::(false); set_balance(host, evm_account_storage, caller, U256::from(1_000_000)); run_transaction( @@ -94,13 +94,13 @@ pub fn deploy_mock_wrapper( /// Execute FA deposit pub fn run_fa_deposit( - host: &mut MockHost, + host: &mut MockKernelHost, evm_account_storage: &mut EthereumAccountStorage, deposit: &FaDeposit, caller: &H160, ) -> ExecutionOutcome { let block = dummy_block_constants(); - let precompiles = precompile_set::(false); + let precompiles = precompile_set::(false); execute_fa_deposit( host, @@ -140,7 +140,7 @@ pub fn dummy_fa_deposit(ticket: FA2_1Ticket, proxy: Option) -> FaDeposit { /// } /// } pub fn get_storage_flag( - host: &MockHost, + host: &MockKernelHost, evm_account_storage: &EthereumAccountStorage, proxy: H160, ) -> u32 { @@ -323,13 +323,13 @@ pub fn dummy_fa_withdrawal( /// Execute FA withdrawal directly without going through the precompile pub fn fa_bridge_precompile_call_withdraw( - host: &mut MockHost, + host: &mut MockKernelHost, evm_account_storage: &mut EthereumAccountStorage, withdrawal: FaWithdrawal, caller: H160, ) -> ExecutionOutcome { let block = dummy_first_block(); - let precompiles = precompiles::precompile_set::(false); + let precompiles = precompiles::precompile_set::(false); let config = Config::shanghai(); let mut handler = EvmHandler::new( diff --git a/etherlink/kernel_evm/evm_execution/src/fa_bridge/tests.rs b/etherlink/kernel_evm/evm_execution/src/fa_bridge/tests.rs index fd142bbac57c..ca7891f1722e 100644 --- a/etherlink/kernel_evm/evm_execution/src/fa_bridge/tests.rs +++ b/etherlink/kernel_evm/evm_execution/src/fa_bridge/tests.rs @@ -6,7 +6,7 @@ use alloy_primitives::FixedBytes; use alloy_sol_types::SolEvent; use evm::ExitError; use primitive_types::{H160, U256}; -use tezos_smart_rollup_mock::MockHost; +use tezos_evm_runtime::runtime::MockKernelHost; use crate::{ account_storage::{account_path, init_account_storage}, @@ -21,7 +21,7 @@ use crate::{ #[test] fn fa_deposit_reached_wrapper_contract() { - let mut mock_runtime = MockHost::default(); + let mut mock_runtime = MockKernelHost::default(); let mut evm_account_storage = init_account_storage().unwrap(); let caller = H160::zero(); @@ -101,7 +101,7 @@ fn fa_deposit_reached_wrapper_contract() { #[test] fn fa_deposit_refused_due_non_existing_contract() { - let mut mock_runtime = MockHost::default(); + let mut mock_runtime = MockKernelHost::default(); let mut evm_account_storage = init_account_storage().unwrap(); let caller = H160::zero(); @@ -158,7 +158,7 @@ fn fa_deposit_refused_due_non_existing_contract() { #[test] fn fa_deposit_refused_non_compatible_interface() { - let mut mock_runtime = MockHost::default(); + let mut mock_runtime = MockKernelHost::default(); let mut evm_account_storage = init_account_storage().unwrap(); let caller = H160::zero(); @@ -222,7 +222,7 @@ fn fa_deposit_refused_non_compatible_interface() { #[test] fn fa_deposit_proxy_state_reverted_if_ticket_balance_overflows() { - let mut mock_runtime = MockHost::default(); + let mut mock_runtime = MockKernelHost::default(); let mut evm_account_storage = init_account_storage().unwrap(); let caller = H160::zero(); @@ -283,7 +283,7 @@ fn fa_deposit_proxy_state_reverted_if_ticket_balance_overflows() { #[test] fn fa_withdrawal_executed_via_l2_proxy_contract() { - let mut mock_runtime = MockHost::default(); + let mut mock_runtime = MockKernelHost::default(); let mut evm_account_storage = init_account_storage().unwrap(); let sender = H160::from_low_u64_be(1); @@ -371,7 +371,7 @@ fn fa_withdrawal_executed_via_l2_proxy_contract() { #[test] fn fa_withdrawal_fails_due_to_faulty_l2_proxy() { - let mut mock_runtime = MockHost::default(); + let mut mock_runtime = MockKernelHost::default(); let mut evm_account_storage = init_account_storage().unwrap(); let sender = H160::from_low_u64_be(1); @@ -424,7 +424,7 @@ fn fa_withdrawal_fails_due_to_faulty_l2_proxy() { #[test] fn fa_withdrawal_fails_due_to_insufficient_balance() { - let mut mock_runtime = MockHost::default(); + let mut mock_runtime = MockKernelHost::default(); let mut evm_account_storage = init_account_storage().unwrap(); let sender = H160::from_low_u64_be(1); diff --git a/etherlink/kernel_evm/evm_execution/src/fa_bridge/ticket_table.rs b/etherlink/kernel_evm/evm_execution/src/fa_bridge/ticket_table.rs index 524a34f7b1b2..119b9fa7886f 100644 --- a/etherlink/kernel_evm/evm_execution/src/fa_bridge/ticket_table.rs +++ b/etherlink/kernel_evm/evm_execution/src/fa_bridge/ticket_table.rs @@ -84,8 +84,8 @@ impl TicketTable for EthereumAccount { #[cfg(test)] mod tests { + use tezos_evm_runtime::runtime::MockKernelHost; use tezos_smart_rollup_host::path::RefPath; - use tezos_smart_rollup_mock::MockHost; use tezos_storage::read_u256_le_default; use crate::precompiles::SYSTEM_ACCOUNT_ADDRESS; @@ -94,7 +94,7 @@ mod tests { #[test] fn ticket_table_balance_add_succeeds() { - let mut host = MockHost::default(); + let mut host = MockKernelHost::default(); let mut account = EthereumAccount::from_address(&SYSTEM_ACCOUNT_ADDRESS).unwrap(); @@ -121,7 +121,7 @@ mod tests { #[test] fn ticket_table_balance_add_overflows() { - let mut host = MockHost::default(); + let mut host = MockKernelHost::default(); let mut account = EthereumAccount::from_address(&SYSTEM_ACCOUNT_ADDRESS).unwrap(); diff --git a/etherlink/kernel_evm/evm_execution/src/handler.rs b/etherlink/kernel_evm/evm_execution/src/handler.rs index e524c0e4d01b..d51a2ab7e88d 100644 --- a/etherlink/kernel_evm/evm_execution/src/handler.rs +++ b/etherlink/kernel_evm/evm_execution/src/handler.rs @@ -2620,28 +2620,36 @@ mod test { use std::str::FromStr; use std::vec; use tezos_ethereum::block::BlockFees; - use tezos_smart_rollup_mock::MockHost; + use tezos_evm_runtime::runtime::MockKernelHost; const DUMMY_ALLOCATED_TICKS: u64 = 1_000_000_000; - fn set_code(handler: &mut EvmHandler<'_, MockHost>, address: &H160, code: Vec) { + fn set_code( + handler: &mut EvmHandler<'_, MockKernelHost>, + address: &H160, + code: Vec, + ) { let mut account = handler.get_or_create_account(*address).unwrap(); account.delete_code(handler.borrow_host()).unwrap(); //first clean code if it exists. account.set_code(handler.borrow_host(), &code).unwrap(); } - fn set_nonce(handler: &mut EvmHandler<'_, MockHost>, address: &H160, nonce: u64) { + fn set_nonce( + handler: &mut EvmHandler<'_, MockKernelHost>, + address: &H160, + nonce: u64, + ) { let mut account = handler.get_or_create_account(*address).unwrap(); account.set_nonce(handler.borrow_host(), nonce).unwrap() } - fn get_balance(handler: &mut EvmHandler<'_, MockHost>, address: &H160) -> U256 { + fn get_balance(handler: &mut EvmHandler<'_, MockKernelHost>, address: &H160) -> U256 { let account = handler.get_or_create_account(*address).unwrap(); account.balance(handler.borrow_host()).unwrap() } fn set_balance( - handler: &mut EvmHandler<'_, MockHost>, + handler: &mut EvmHandler<'_, MockKernelHost>, address: &H160, new_balance: U256, ) { @@ -2665,7 +2673,7 @@ mod test { } fn get_durable_slot( - handler: &mut EvmHandler<'_, MockHost>, + handler: &mut EvmHandler<'_, MockKernelHost>, address: &H160, index: &H256, ) -> H256 { @@ -2690,9 +2698,9 @@ mod test { #[test] fn legacy_create_to_correct_address() { - let mut mock_runtime = MockHost::default(); + let mut mock_runtime = MockKernelHost::default(); let block = dummy_first_block(); - let precompiles = precompiles::precompile_set::(false); + let precompiles = precompiles::precompile_set::(false); let mut evm_account_storage = init_account_storage().unwrap(); let config = Config::shanghai(); @@ -2733,9 +2741,9 @@ mod test { #[test] fn create2_to_correct_address() { - let mut mock_runtime = MockHost::default(); + let mut mock_runtime = MockKernelHost::default(); let block = dummy_first_block(); - let precompiles = precompiles::precompile_set::(false); + let precompiles = precompiles::precompile_set::(false); let mut evm_account_storage = init_account_storage().unwrap(); let config = Config::shanghai(); let caller: H160 = @@ -2775,9 +2783,9 @@ mod test { #[test] fn create2_to_correct_address_nonzero_salt() { - let mut mock_runtime = MockHost::default(); + let mut mock_runtime = MockKernelHost::default(); let block = dummy_first_block(); - let precompiles = precompiles::precompile_set::(false); + let precompiles = precompiles::precompile_set::(false); let mut evm_account_storage = init_account_storage().unwrap(); let config = Config::shanghai(); @@ -2821,9 +2829,9 @@ mod test { #[test] fn origin_instruction_returns_origin_address() { - let mut mock_runtime = MockHost::default(); + let mut mock_runtime = MockKernelHost::default(); let block = dummy_first_block(); - let precompiles = precompiles::precompile_set::(false); + let precompiles = precompiles::precompile_set::(false); let mut evm_account_storage = init_account_storage().unwrap(); let config = Config::shanghai(); let caller = H160::from_low_u64_be(28349_u64); @@ -2886,9 +2894,9 @@ mod test { #[test] fn contract_call_produces_correct_output() { - let mut mock_runtime = MockHost::default(); + let mut mock_runtime = MockKernelHost::default(); let block = dummy_first_block(); - let precompiles = precompiles::precompile_set::(false); + let precompiles = precompiles::precompile_set::(false); let mut evm_account_storage = init_account_storage().unwrap(); let config = Config::shanghai(); let caller = H160::from_low_u64_be(28349_u64); @@ -2980,9 +2988,9 @@ mod test { #[test] fn contract_call_fails_beyond_max_stack_depth() { - let mut mock_runtime = MockHost::default(); + let mut mock_runtime = MockKernelHost::default(); let block = dummy_first_block(); - let precompiles = precompiles::precompile_set::(false); + let precompiles = precompiles::precompile_set::(false); let mut evm_account_storage = init_account_storage().unwrap(); let config = Config::shanghai(); let caller = H160::from_low_u64_be(2340); @@ -3075,9 +3083,9 @@ mod test { #[test] fn contract_call_succeeds_at_maximum_stack_depth() { - let mut mock_runtime = MockHost::default(); + let mut mock_runtime = MockKernelHost::default(); let block = dummy_first_block(); - let precompiles = precompiles::precompile_set::(false); + let precompiles = precompiles::precompile_set::(false); let mut evm_account_storage = init_account_storage().unwrap(); let config = Config::shanghai(); let caller = H160::from_low_u64_be(8213); @@ -3168,9 +3176,9 @@ mod test { #[test] fn contract_can_use_durable_storage() { - let mut mock_runtime = MockHost::default(); + let mut mock_runtime = MockKernelHost::default(); let block = dummy_first_block(); - let precompiles = precompiles::precompile_set::(false); + let precompiles = precompiles::precompile_set::(false); let mut evm_account_storage = init_account_storage().unwrap(); let config = Config::shanghai(); let caller = H160::from_low_u64_be(444); @@ -3240,9 +3248,9 @@ mod test { #[test] fn contract_create_can_use_durable_storage() { - let mut mock_runtime = MockHost::default(); + let mut mock_runtime = MockKernelHost::default(); let block = dummy_first_block(); - let precompiles = precompiles::precompile_set::(false); + let precompiles = precompiles::precompile_set::(false); let mut evm_account_storage = init_account_storage().unwrap(); let config = Config::shanghai(); let caller = H160::from_low_u64_be(117); @@ -3297,9 +3305,9 @@ mod test { #[test] fn contract_create_has_return_when_revert() { - let mut mock_runtime = MockHost::default(); + let mut mock_runtime = MockKernelHost::default(); let block = dummy_first_block(); - let precompiles = precompiles::precompile_set::(false); + let precompiles = precompiles::precompile_set::(false); let mut evm_account_storage = init_account_storage().unwrap(); let config = Config::shanghai(); let caller = H160::from_low_u64_be(117); @@ -3363,9 +3371,9 @@ mod test { #[test] fn contract_call_does_transfer() { - let mut mock_runtime = MockHost::default(); + let mut mock_runtime = MockKernelHost::default(); let block = dummy_first_block(); - let precompiles = precompiles::precompile_set::(false); + let precompiles = precompiles::precompile_set::(false); let mut evm_account_storage = init_account_storage().unwrap(); let config = Config::shanghai(); let caller = H160::from_low_u64_be(118); @@ -3426,9 +3434,9 @@ mod test { #[test] fn contract_call_fails_when_insufficient_funds_for_transfer() { - let mut mock_runtime = MockHost::default(); + let mut mock_runtime = MockKernelHost::default(); let block = dummy_first_block(); - let precompiles = precompiles::precompile_set::(false); + let precompiles = precompiles::precompile_set::(false); let mut evm_account_storage = init_account_storage().unwrap(); let config = Config::shanghai(); let caller = H160::from_low_u64_be(523_u64); @@ -3488,9 +3496,9 @@ mod test { #[test] fn revert_can_return_a_value() { - let mut mock_runtime = MockHost::default(); + let mut mock_runtime = MockKernelHost::default(); let block = dummy_first_block(); - let precompiles = precompiles::precompile_set::(false); + let precompiles = precompiles::precompile_set::(false); let mut evm_account_storage = init_account_storage().unwrap(); let config = Config::shanghai(); let caller = H160::from_low_u64_be(523_u64); @@ -3559,9 +3567,9 @@ mod test { #[test] fn return_hash_of_zero_for_unavailable_block() { - let mut mock_runtime = MockHost::default(); + let mut mock_runtime = MockKernelHost::default(); let block = dummy_first_block(); - let precompiles = precompiles::precompile_set::(false); + let precompiles = precompiles::precompile_set::(false); let mut evm_account_storage = init_account_storage().unwrap(); let config = Config::shanghai(); let caller = H160::from_low_u64_be(523_u64); @@ -3587,9 +3595,9 @@ mod test { #[test] fn transactions_fails_if_not_enough_allocated_ticks() { - let mut mock_runtime = MockHost::default(); + let mut mock_runtime = MockKernelHost::default(); let block = dummy_first_block(); - let precompiles = precompiles::precompile_set::(false); + let precompiles = precompiles::precompile_set::(false); let mut evm_account_storage = init_account_storage().unwrap(); let config = Config::london(); let caller = H160::from_low_u64_be(523_u64); @@ -3648,9 +3656,9 @@ mod test { #[test] fn store_after_offset_1024() { - let mut mock_runtime = MockHost::default(); + let mut mock_runtime = MockKernelHost::default(); let block = dummy_first_block(); - let precompiles = precompiles::precompile_set::(false); + let precompiles = precompiles::precompile_set::(false); let mut evm_account_storage = init_account_storage().unwrap(); let config = Config::shanghai(); let caller = H160::from_low_u64_be(523_u64); @@ -3700,9 +3708,9 @@ mod test { #[test] fn dont_crash_on_blockhash_instruction() { - let mut mock_runtime = MockHost::default(); + let mut mock_runtime = MockKernelHost::default(); let block = dummy_first_block(); - let precompiles = precompiles::precompile_set::(false); + let precompiles = precompiles::precompile_set::(false); let mut evm_account_storage = init_account_storage().unwrap(); let config = Config::shanghai(); let caller = H160::from_low_u64_be(523_u64); @@ -3768,9 +3776,9 @@ mod test { #[test] fn prevent_collision_create2_selfdestruct() { - let mut mock_runtime = MockHost::default(); + let mut mock_runtime = MockKernelHost::default(); let block = dummy_first_block(); - let precompiles = precompiles::precompile_set::(false); + let precompiles = precompiles::precompile_set::(false); let mut evm_account_storage = init_account_storage().unwrap(); let config = Config::shanghai(); @@ -3837,9 +3845,9 @@ mod test { #[test] fn create_contract_with_insufficient_funds() { //Init - let mut mock_runtime = MockHost::default(); + let mut mock_runtime = MockKernelHost::default(); let block = dummy_first_block(); - let precompiles = precompiles::precompile_set::(false); + let precompiles = precompiles::precompile_set::(false); let mut evm_account_storage = init_account_storage().unwrap(); let config = Config::shanghai(); @@ -3880,9 +3888,9 @@ mod test { #[test] fn inter_call_with_non_zero_transfer_value_gets_call_stipend() { - let mut mock_runtime = MockHost::default(); + let mut mock_runtime = MockKernelHost::default(); let block = dummy_first_block(); - let precompiles = precompiles::precompile_set::(false); + let precompiles = precompiles::precompile_set::(false); let mut evm_account_storage = init_account_storage().unwrap(); let config = Config::shanghai(); let caller = H160::from_low_u64_be(523_u64); @@ -3956,9 +3964,9 @@ mod test { #[test] fn code_hash_of_zero_for_non_existing_address() { - let mut mock_runtime = MockHost::default(); + let mut mock_runtime = MockKernelHost::default(); let block = dummy_first_block(); - let precompiles = precompiles::precompile_set::(false); + let precompiles = precompiles::precompile_set::(false); let mut evm_account_storage = init_account_storage().unwrap(); let config = Config::shanghai(); let caller = H160::from_low_u64_be(523_u64); @@ -3985,9 +3993,9 @@ mod test { #[test] fn create_contract_with_selfdestruct_init_code() { - let mut mock_runtime = MockHost::default(); + let mut mock_runtime = MockKernelHost::default(); let block = dummy_first_block(); - let precompiles = precompiles::precompile_set::(false); + let precompiles = precompiles::precompile_set::(false); let mut evm_account_storage = init_account_storage().unwrap(); let config = Config::shanghai(); @@ -4029,9 +4037,9 @@ mod test { #[test] fn contract_that_selfdestruct_not_deleted_within_same_transaction() { - let mut mock_runtime = MockHost::default(); + let mut mock_runtime = MockKernelHost::default(); let block = dummy_first_block(); - let precompiles = precompiles::precompile_set::(false); + let precompiles = precompiles::precompile_set::(false); let mut evm_account_storage = init_account_storage().unwrap(); let config = Config::shanghai(); let caller = H160::from_low_u64_be(523_u64); @@ -4112,9 +4120,9 @@ mod test { #[test] fn contract_that_selfdestruct_can_be_called_again_in_same_transaction() { - let mut mock_runtime = MockHost::default(); + let mut mock_runtime = MockKernelHost::default(); let block = dummy_first_block(); - let precompiles = precompiles::precompile_set::(false); + let precompiles = precompiles::precompile_set::(false); let mut evm_account_storage = init_account_storage().unwrap(); let config = Config::shanghai(); let caller = H160::from_low_u64_be(523_u64); @@ -4212,9 +4220,9 @@ mod test { #[test] fn contract_selfdestruct_itself_has_no_balance_left() { - let mut mock_runtime = MockHost::default(); + let mut mock_runtime = MockKernelHost::default(); let block = dummy_first_block(); - let precompiles = precompiles::precompile_set::(false); + let precompiles = precompiles::precompile_set::(false); let mut evm_account_storage = init_account_storage().unwrap(); let config = Config::shanghai(); @@ -4278,9 +4286,9 @@ mod test { // According EIP-2929, the created address should still be hot even if the creation fails #[test] fn address_still_marked_as_hot_after_creation_fails() { - let mut mock_runtime = MockHost::default(); + let mut mock_runtime = MockKernelHost::default(); let block = dummy_first_block(); - let precompiles = precompiles::precompile_set::(false); + let precompiles = precompiles::precompile_set::(false); let mut evm_account_storage = init_account_storage().unwrap(); let config = Config::shanghai(); @@ -4352,9 +4360,9 @@ mod test { #[test] fn precompile_failure_are_not_fatal() { - let mut host = MockHost::default(); + let mut host = MockKernelHost::default(); let block = dummy_first_block(); - let precompiles = precompiles::precompile_set::(false); + let precompiles = precompiles::precompile_set::(false); let mut evm_account_storage = init_account_storage().unwrap(); let config = Config::shanghai(); let caller = H160::from_low_u64_be(523_u64); @@ -4411,9 +4419,9 @@ mod test { #[test] fn inner_create_costs_gas() { - let mut mock_runtime = MockHost::default(); + let mut mock_runtime = MockKernelHost::default(); let block = dummy_first_block(); - let precompiles = precompiles::precompile_set::(false); + let precompiles = precompiles::precompile_set::(false); let mut evm_account_storage = init_account_storage().unwrap(); let config = Config::shanghai(); let caller = H160::from_low_u64_be(523_u64); @@ -4493,9 +4501,9 @@ mod test { #[test] fn exceed_max_create_init_code_size_fail_with_error() { - let mut mock_runtime = MockHost::default(); + let mut mock_runtime = MockKernelHost::default(); let block = dummy_first_block(); - let precompiles = precompiles::precompile_set::(false); + let precompiles = precompiles::precompile_set::(false); let mut evm_account_storage = init_account_storage().unwrap(); let config = Config::shanghai(); let caller = H160::from_low_u64_be(523_u64); @@ -4533,9 +4541,9 @@ mod test { #[test] fn create_fails_with_max_nonce() { - let mut mock_runtime = MockHost::default(); + let mut mock_runtime = MockKernelHost::default(); let block = dummy_first_block(); - let precompiles = precompiles::precompile_set::(false); + let precompiles = precompiles::precompile_set::(false); let mut evm_account_storage = init_account_storage().unwrap(); let config = Config::shanghai(); @@ -4575,9 +4583,9 @@ mod test { #[test] fn record_call_stipend_when_balance_not_enough_for_inner_call() { - let mut mock_runtime = MockHost::default(); + let mut mock_runtime = MockKernelHost::default(); let block = dummy_first_block(); - let precompiles = precompiles::precompile_set::(false); + let precompiles = precompiles::precompile_set::(false); let mut evm_account_storage = init_account_storage().unwrap(); let config = Config::shanghai(); let caller = H160::from_low_u64_be(523_u64); @@ -4653,9 +4661,9 @@ mod test { // eip-161 #[test] fn eip161_gas_consumption_rules_for_suicide() { - let mut mock_runtime = MockHost::default(); + let mut mock_runtime = MockKernelHost::default(); let block = dummy_first_block(); - let precompiles = precompiles::precompile_set::(false); + let precompiles = precompiles::precompile_set::(false); let mut evm_account_storage = init_account_storage().unwrap(); let config = Config::shanghai(); let caller = H160::from_low_u64_be(111_u64); @@ -4725,9 +4733,9 @@ mod test { #[test] fn eip161_gas_consumption_rules_for_call() { - let mut mock_runtime = MockHost::default(); + let mut mock_runtime = MockKernelHost::default(); let block = dummy_first_block(); - let precompiles = precompiles::precompile_set::(false); + let precompiles = precompiles::precompile_set::(false); let mut evm_account_storage = init_account_storage().unwrap(); let config = Config::shanghai(); let caller = H160::from_low_u64_be(111_u64); diff --git a/etherlink/kernel_evm/evm_execution/src/lib.rs b/etherlink/kernel_evm/evm_execution/src/lib.rs index 3e59591fefd7..63ee524e761b 100644 --- a/etherlink/kernel_evm/evm_execution/src/lib.rs +++ b/etherlink/kernel_evm/evm_execution/src/lib.rs @@ -377,13 +377,13 @@ mod test { use evm::executor::stack::Log; use evm::{ExitError, ExitSucceed, Opcode}; use handler::ExecutionOutcome; - use host::runtime::Runtime; use primitive_types::{H160, H256}; use std::str::FromStr; use std::vec; use tezos_ethereum::block::BlockFees; use tezos_ethereum::tx_common::EthereumTransactionCommon; - use tezos_smart_rollup_mock::MockHost; + use tezos_evm_runtime::runtime::MockKernelHost; + use tezos_evm_runtime::runtime::Runtime; // The compiled initialization code for the Ethereum demo contract given // as an example in kernel_evm/solidity_examples/storage.sol @@ -409,7 +409,7 @@ mod test { const DUMMY_ALLOCATED_TICKS: u64 = 1_000_000_000; fn set_balance( - host: &mut MockHost, + host: &mut MockKernelHost, evm_account_storage: &mut EthereumAccountStorage, address: &H160, balance: U256, @@ -430,7 +430,7 @@ mod test { } fn set_storage( - host: &mut MockHost, + host: &mut MockKernelHost, evm_account_storage: &mut EthereumAccountStorage, address: &H160, index: &H256, @@ -443,7 +443,7 @@ mod test { } fn get_storage( - host: &mut MockHost, + host: &mut MockKernelHost, evm_account_storage: &mut EthereumAccountStorage, address: &H160, index: &H256, @@ -455,7 +455,7 @@ mod test { } fn get_balance( - host: &mut MockHost, + host: &mut MockKernelHost, evm_account_storage: &mut EthereumAccountStorage, address: &H160, ) -> U256 { @@ -478,7 +478,7 @@ mod test { } fn get_code( - host: &mut MockHost, + host: &mut MockKernelHost, evm_account_storage: &mut EthereumAccountStorage, address: &H160, ) -> Vec { @@ -499,7 +499,7 @@ mod test { } fn get_nonce( - host: &mut MockHost, + host: &mut MockKernelHost, evm_account_storage: &mut EthereumAccountStorage, address: &H160, ) -> u64 { @@ -526,9 +526,9 @@ mod test { #[test] fn transfer_without_sufficient_funds_fails() { - let mut mock_runtime = MockHost::default(); + let mut mock_runtime = MockKernelHost::default(); let block = dummy_first_block(); - let precompiles = precompiles::precompile_set::(false); + let precompiles = precompiles::precompile_set::(false); let mut evm_account_storage = init_evm_account_storage().unwrap(); let callee = H160::from_low_u64_be(234213); @@ -591,9 +591,9 @@ mod test { #[test] fn transfer_funds_with_sufficient_balance() { - let mut mock_runtime = MockHost::default(); + let mut mock_runtime = MockKernelHost::default(); let block = dummy_first_block(); - let precompiles = precompiles::precompile_set::(false); + let precompiles = precompiles::precompile_set::(false); let mut evm_account_storage = init_evm_account_storage().unwrap(); let callee = H160::from_low_u64_be(82193); @@ -657,9 +657,9 @@ mod test { #[test] fn create_contract_fails_with_insufficient_funds() { - let mut mock_runtime = MockHost::default(); + let mut mock_runtime = MockKernelHost::default(); let block = dummy_first_block(); - let precompiles = precompiles::precompile_set::(false); + let precompiles = precompiles::precompile_set::(false); let mut evm_account_storage = init_evm_account_storage().unwrap(); let callee = None; @@ -711,9 +711,9 @@ mod test { #[test] fn create_contract_succeeds_with_valid_initialization() { - let mut mock_runtime = MockHost::default(); + let mut mock_runtime = MockKernelHost::default(); let block = dummy_first_block(); - let precompiles = precompiles::precompile_set::(false); + let precompiles = precompiles::precompile_set::(false); let mut evm_account_storage = init_evm_account_storage().unwrap(); let callee = None; @@ -872,9 +872,9 @@ mod test { #[test] fn create_contract_erc20_succeeds() { - let mut mock_runtime = MockHost::default(); + let mut mock_runtime = MockKernelHost::default(); let block = dummy_first_block(); - let precompiles = precompiles::precompile_set::(false); + let precompiles = precompiles::precompile_set::(false); let mut evm_account_storage = init_evm_account_storage().unwrap(); let callee = None; @@ -928,9 +928,9 @@ mod test { #[test] fn create_contract_fails_when_initialization_fails() { - let mut mock_runtime = MockHost::default(); + let mut mock_runtime = MockKernelHost::default(); let block = dummy_first_block(); - let precompiles = precompiles::precompile_set::(false); + let precompiles = precompiles::precompile_set::(false); let mut evm_account_storage = init_evm_account_storage().unwrap(); let callee = None; @@ -986,9 +986,9 @@ mod test { #[test] fn call_non_existing_contract() { // Arange - let mut mock_runtime = MockHost::default(); + let mut mock_runtime = MockKernelHost::default(); let block = dummy_first_block(); - let precompiles = precompiles::precompile_set::(false); + let precompiles = precompiles::precompile_set::(false); let mut evm_account_storage = init_evm_account_storage().unwrap(); let target = H160::from_low_u64_be(117u64); let caller = H160::from_low_u64_be(118u64); @@ -1123,9 +1123,9 @@ mod test { #[test] fn call_simple_return_contract() { // Arrange - let mut mock_runtime = MockHost::default(); + let mut mock_runtime = MockKernelHost::default(); let block = dummy_first_block(); - let precompiles = precompiles::precompile_set::(false); + let precompiles = precompiles::precompile_set::(false); let mut evm_account_storage = init_evm_account_storage().unwrap(); let target = H160::from_low_u64_be(117u64); let caller = H160::from_low_u64_be(118u64); @@ -1185,9 +1185,9 @@ mod test { #[test] fn call_simple_revert_contract() { // Arrange - let mut mock_runtime = MockHost::default(); + let mut mock_runtime = MockKernelHost::default(); let block = dummy_first_block(); - let precompiles = precompiles::precompile_set::(false); + let precompiles = precompiles::precompile_set::(false); let mut evm_account_storage = init_evm_account_storage().unwrap(); let target = H160::from_low_u64_be(117u64); let caller = H160::from_low_u64_be(118u64); @@ -1254,9 +1254,9 @@ mod test { #[test] fn call_contract_with_invalid_opcode() { // Arrange - let mut mock_runtime = MockHost::default(); + let mut mock_runtime = MockKernelHost::default(); let block = dummy_first_block(); - let precompiles = precompiles::precompile_set::(false); + let precompiles = precompiles::precompile_set::(false); let mut evm_account_storage = init_evm_account_storage().unwrap(); let target = H160::from_low_u64_be(117u64); let caller = H160::from_low_u64_be(118u64); @@ -1306,9 +1306,9 @@ mod test { #[test] fn no_transfer_when_contract_call_fails() { - let mut mock_runtime = MockHost::default(); + let mut mock_runtime = MockKernelHost::default(); let block = dummy_first_block(); - let precompiles = precompiles::precompile_set::(false); + let precompiles = precompiles::precompile_set::(false); let mut evm_account_storage = init_evm_account_storage().unwrap(); let caller = H160::from_low_u64_be(118_u64); let gas_price = U256::from(21000); @@ -1371,9 +1371,9 @@ mod test { #[test] fn call_precompiled_contract() { // Arrange - let mut mock_runtime = MockHost::default(); + let mut mock_runtime = MockKernelHost::default(); let block = dummy_first_block(); - let precompiles = precompiles::precompile_set::(false); + let precompiles = precompiles::precompile_set::(false); let target = H160::from_low_u64_be(4u64); // identity contract let mut evm_account_storage = init_evm_account_storage().unwrap(); let caller = H160::from_low_u64_be(118u64); @@ -1426,9 +1426,9 @@ mod test { #[test] fn call_ecrecover() { // Arrange - let mut mock_runtime = MockHost::default(); + let mut mock_runtime = MockKernelHost::default(); let block = dummy_first_block(); - let precompiles = precompiles::precompile_set::(false); + let precompiles = precompiles::precompile_set::(false); // example from https://www.evm.codes/precompiled?fork=shanghai let data_str = "456e9aea5e197a1f1af7a3e85a3212fa4049a3ba34c2289b4c860fc0b0c64ef3000000000000000000000000000000000000000000000000000000000000001c9242685bf161793cc25603c231bc2f568eb630ea16aa137d2664ac80388256084f8ae3bd7535248d0bd448298cc2e2071e56992d0774dc340c368ae950852ada"; let data = hex::decode(data_str) @@ -1488,9 +1488,9 @@ mod test { #[test] fn create_and_call_contract() { // Arrange - let mut mock_runtime = MockHost::default(); + let mut mock_runtime = MockKernelHost::default(); let block = dummy_first_block(); - let precompiles = precompiles::precompile_set::(false); + let precompiles = precompiles::precompile_set::(false); let mut evm_account_storage = init_evm_account_storage().unwrap(); let target = H160::from_low_u64_be(117u64); let caller = H160::from_low_u64_be(118u64); @@ -1590,9 +1590,9 @@ mod test { #[test] fn static_calls_cannot_update_storage() { - let mut mock_runtime = MockHost::default(); + let mut mock_runtime = MockKernelHost::default(); let block = dummy_first_block(); - let precompiles = precompiles::precompile_set::(false); + let precompiles = precompiles::precompile_set::(false); let mut evm_account_storage = init_evm_account_storage().unwrap(); let target = H160::from_low_u64_be(117_u64); let caller = H160::from_low_u64_be(118_u64); @@ -1684,9 +1684,9 @@ mod test { #[test] fn static_calls_fail_when_logging() { - let mut mock_runtime = MockHost::default(); + let mut mock_runtime = MockKernelHost::default(); let block = dummy_first_block(); - let precompiles = precompiles::precompile_set::(false); + let precompiles = precompiles::precompile_set::(false); let mut evm_account_storage = init_evm_account_storage().unwrap(); let target = H160::from_low_u64_be(117_u64); let caller = H160::from_low_u64_be(118_u64); @@ -1778,9 +1778,9 @@ mod test { #[test] fn logs_get_written_to_output() { - let mut mock_runtime = MockHost::default(); + let mut mock_runtime = MockKernelHost::default(); let block = dummy_first_block(); - let precompiles = precompiles::precompile_set::(false); + let precompiles = precompiles::precompile_set::(false); let mut evm_account_storage = init_evm_account_storage().unwrap(); let target = H160::from_low_u64_be(117_u64); let caller = H160::from_low_u64_be(118_u64); @@ -1899,9 +1899,9 @@ mod test { #[test] fn no_logs_when_contract_reverts() { - let mut mock_runtime = MockHost::default(); + let mut mock_runtime = MockKernelHost::default(); let block = dummy_first_block(); - let precompiles = precompiles::precompile_set::(false); + let precompiles = precompiles::precompile_set::(false); let mut evm_account_storage = init_evm_account_storage().unwrap(); let target = H160::from_low_u64_be(117_u64); let caller = H160::from_low_u64_be(118_u64); @@ -2005,9 +2005,9 @@ mod test { #[test] fn contract_selfdestruct_deletes_contract() { - let mut mock_runtime = MockHost::default(); + let mut mock_runtime = MockKernelHost::default(); let block = dummy_first_block(); - let precompiles = precompiles::precompile_set::(false); + let precompiles = precompiles::precompile_set::(false); let mut evm_account_storage = init_evm_account_storage().unwrap(); let target = H160::from_low_u64_be(42_u64); let caller = H160::from_low_u64_be(115_u64); @@ -2115,9 +2115,9 @@ mod test { #[test] fn selfdestruct_is_ignored_when_call_fails() { - let mut mock_runtime = MockHost::default(); + let mut mock_runtime = MockKernelHost::default(); let block = dummy_first_block(); - let precompiles = precompiles::precompile_set::(false); + let precompiles = precompiles::precompile_set::(false); let mut evm_account_storage = init_evm_account_storage().unwrap(); let target = H160::from_low_u64_be(42_u64); let caller = H160::from_low_u64_be(115_u64); @@ -2234,7 +2234,7 @@ mod test { #[test] fn test_chain_id() { // Arrange - let mut mock_runtime = MockHost::default(); + let mut mock_runtime = MockKernelHost::default(); let chain_id = U256::from(42); let mut chain_id_bytes = [0u8; 32]; chain_id.to_big_endian(&mut chain_id_bytes); @@ -2250,7 +2250,7 @@ mod test { u64::MAX, H160::zero(), ); - let precompiles = precompiles::precompile_set::(false); + let precompiles = precompiles::precompile_set::(false); let mut evm_account_storage = init_evm_account_storage().unwrap(); let target = H160::from_low_u64_be(117u64); let caller = H160::from_low_u64_be(118u64); @@ -2319,7 +2319,7 @@ mod test { #[test] fn test_base_fee_per_gas() { // Arrange - let mut mock_runtime = MockHost::default(); + let mut mock_runtime = MockKernelHost::default(); let base_fee_per_gas = U256::from(23000); let mut base_fee_per_gas_bytes = [0u8; 32]; base_fee_per_gas.to_big_endian(&mut base_fee_per_gas_bytes); @@ -2335,7 +2335,7 @@ mod test { u64::MAX, H160::zero(), ); - let precompiles = precompiles::precompile_set::(false); + let precompiles = precompiles::precompile_set::(false); let mut evm_account_storage = init_evm_account_storage().unwrap(); let target = H160::from_low_u64_be(117u64); let caller = H160::from_low_u64_be(118u64); @@ -2425,9 +2425,9 @@ mod test { #[test] fn evm_should_fail_gracefully_when_balance_overflow_occurs() { - let mut mock_runtime = MockHost::default(); + let mut mock_runtime = MockKernelHost::default(); let block = dummy_first_block(); - let precompiles = precompiles::precompile_set::(false); + let precompiles = precompiles::precompile_set::(false); let mut evm_account_storage = init_evm_account_storage().unwrap(); let caller = H160::from_low_u64_be(523); let target = H160::from_low_u64_be(210); @@ -2473,9 +2473,9 @@ mod test { #[test] fn create_contract_gas_cost() { - let mut mock_runtime = MockHost::default(); + let mut mock_runtime = MockKernelHost::default(); let block = dummy_first_block(); - let precompiles = precompiles::precompile_set::(false); + let precompiles = precompiles::precompile_set::(false); let mut evm_account_storage = init_evm_account_storage().unwrap(); let callee = None; @@ -2532,9 +2532,9 @@ mod test { #[test] fn create_contract_fail_gas_cost() { - let mut mock_runtime = MockHost::default(); + let mut mock_runtime = MockKernelHost::default(); let block = dummy_first_block(); - let precompiles = precompiles::precompile_set::(false); + let precompiles = precompiles::precompile_set::(false); let mut evm_account_storage = init_evm_account_storage().unwrap(); let callee = None; @@ -2590,7 +2590,7 @@ mod test { #[test] fn test_transaction_data_cost() { // Arrange - let mut mock_runtime = MockHost::default(); + let mut mock_runtime = MockKernelHost::default(); let base_fee_per_gas = U256::from(23000); let block_fees = BlockFees::new( U256::one(), @@ -2604,7 +2604,7 @@ mod test { u64::MAX, H160::zero(), ); - let precompiles = precompiles::precompile_set::(false); + let precompiles = precompiles::precompile_set::(false); let mut evm_account_storage = init_evm_account_storage().unwrap(); let target = H160::from_low_u64_be(117u64); let caller = H160::from_low_u64_be(118u64); @@ -2660,7 +2660,7 @@ mod test { #[test] fn test_transaction_data_cost_non_zero() { // Arrange - let mut mock_runtime = MockHost::default(); + let mut mock_runtime = MockKernelHost::default(); let base_fee_per_gas = U256::from(23000); let block_fees = BlockFees::new( U256::one(), @@ -2674,7 +2674,7 @@ mod test { u64::MAX, H160::zero(), ); - let precompiles = precompiles::precompile_set::(false); + let precompiles = precompiles::precompile_set::(false); let mut evm_account_storage = init_evm_account_storage().unwrap(); let target = H160::from_low_u64_be(117u64); let caller = H160::from_low_u64_be(118u64); @@ -2748,9 +2748,9 @@ mod test { all_the_gas: u64, ) -> Result, EthereumError> { // Arrange - let mut mock_runtime = MockHost::default(); + let mut mock_runtime = MockKernelHost::default(); let block = first_block(); - let precompiles = precompiles::precompile_set::(false); + let precompiles = precompiles::precompile_set::(false); let mut evm_account_storage = init_evm_account_storage().unwrap(); let caller = H160::from_low_u64_be(118u64); let gas_price = U256::from(1356); @@ -2828,9 +2828,9 @@ mod test { // Test case from https://eips.ethereum.org/EIPS/eip-684 #[test] fn test_create_to_address_with_code_returns_error() { - let mut mock_runtime = MockHost::default(); + let mut mock_runtime = MockKernelHost::default(); let block = dummy_first_block(); - let precompiles = precompiles::precompile_set::(false); + let precompiles = precompiles::precompile_set::(false); let mut evm_account_storage = init_evm_account_storage().unwrap(); let caller = @@ -2901,9 +2901,9 @@ mod test { // Caller nonce is bumped at each contract creation #[test] fn test_caller_nonce_after_create() { - let mut mock_runtime = MockHost::default(); + let mut mock_runtime = MockKernelHost::default(); let block = dummy_first_block(); - let precompiles = precompiles::precompile_set::(false); + let precompiles = precompiles::precompile_set::(false); let mut evm_account_storage = init_evm_account_storage().unwrap(); let caller = @@ -3001,9 +3001,9 @@ mod test { // The nonce of the caller 'contract' should still be incremented #[test] fn test_caller_nonce_after_create_collision() { - let mut mock_runtime = MockHost::default(); + let mut mock_runtime = MockKernelHost::default(); let block = dummy_first_block(); - let precompiles = precompiles::precompile_set::(false); + let precompiles = precompiles::precompile_set::(false); let mut evm_account_storage = init_evm_account_storage().unwrap(); let caller = @@ -3109,9 +3109,9 @@ mod test { // Test case from https://eips.ethereum.org/EIPS/eip-684 with modification #[test] fn test_create_to_address_with_non_zero_nonce_returns_error() { - let mut mock_runtime = MockHost::default(); + let mut mock_runtime = MockKernelHost::default(); let block = dummy_first_block(); - let precompiles = precompiles::precompile_set::(false); + let precompiles = precompiles::precompile_set::(false); let mut evm_account_storage = init_evm_account_storage().unwrap(); let caller = @@ -3174,9 +3174,9 @@ mod test { #[test] fn created_contract_start_at_nonce_one() { - let mut host = MockHost::default(); + let mut host = MockKernelHost::default(); let block = dummy_first_block(); - let precompiles = precompiles::precompile_set::(false); + let precompiles = precompiles::precompile_set::(false); let mut evm_account_storage = init_evm_account_storage().unwrap(); let callee = None; @@ -3219,9 +3219,9 @@ mod test { #[test] fn call_contract_create_contract_with_insufficient_funds() { - let mut host = MockHost::default(); + let mut host = MockKernelHost::default(); let block = dummy_first_block(); - let precompiles = precompiles::precompile_set::(false); + let precompiles = precompiles::precompile_set::(false); let mut evm_account_storage = init_evm_account_storage().unwrap(); let callee = H160::from_str("095e7baea6a6c7c4c2dfeb977efac326af552d87").unwrap(); @@ -3284,9 +3284,9 @@ mod test { #[test] fn nested_create_check_nonce_start_at_one() { - let mut host = MockHost::default(); + let mut host = MockKernelHost::default(); let block = dummy_first_block(); - let precompiles = precompiles::precompile_set::(false); + let precompiles = precompiles::precompile_set::(false); let mut evm_account_storage = init_evm_account_storage().unwrap(); let caller = H160::from_str("a94f5374fce5edbc8e2a8697c15331677e6ebf0b").unwrap(); @@ -3400,15 +3400,15 @@ mod test { fn out_of_tick_scenario( retriable: bool, ) -> ( - MockHost, + MockKernelHost, Result, EthereumError>, EthereumAccount, U256, u64, ) { - let mut host = MockHost::default(); + let mut host = MockKernelHost::default(); let block = dummy_first_block(); - let precompiles = precompiles::precompile_set::(false); + let precompiles = precompiles::precompile_set::(false); let mut evm_account_storage = init_evm_account_storage().unwrap(); let callee = None; let caller = H160::from_low_u64_be(117); @@ -3510,9 +3510,9 @@ mod test { #[test] #[ignore] fn multiple_call_all_the_way_to_1024() { - let mut host = MockHost::default(); + let mut host = MockKernelHost::default(); let block = dummy_first_block(); - let precompiles = precompiles::precompile_set::(false); + let precompiles = precompiles::precompile_set::(false); let mut evm_account_storage = init_evm_account_storage().unwrap(); let caller = H160::from_str("a94f5374fce5edbc8e2a8697c15331677e6ebf0b").unwrap(); @@ -3597,9 +3597,9 @@ mod test { // at 1024 we stop at 1025 (this should fail) #[test] fn multiple_call_fails_right_after_1024() { - let mut host = MockHost::default(); + let mut host = MockKernelHost::default(); let block = dummy_first_block(); - let precompiles = precompiles::precompile_set::(false); + let precompiles = precompiles::precompile_set::(false); let mut evm_account_storage = init_evm_account_storage().unwrap(); let caller = H160::from_str("a94f5374fce5edbc8e2a8697c15331677e6ebf0b").unwrap(); @@ -3682,9 +3682,9 @@ mod test { #[test] #[ignore] fn call_too_deep_not_revert() { - let mut host = MockHost::default(); + let mut host = MockKernelHost::default(); let block = dummy_first_block(); - let precompiles = precompiles::precompile_set::(false); + let precompiles = precompiles::precompile_set::(false); let mut evm_account_storage = init_evm_account_storage().unwrap(); let caller = H160::from_str("a94f5374fce5edbc8e2a8697c15331677e6ebf0b").unwrap(); @@ -3733,9 +3733,9 @@ mod test { // with the second data which is invalid (size wise) // The test was a bit tweaked so that the called contract transfer 1 WEI to the called contract. - let mut host = MockHost::default(); + let mut host = MockKernelHost::default(); let block = dummy_first_block(); - let precompiles = precompiles::precompile_set::(false); + let precompiles = precompiles::precompile_set::(false); let mut evm_account_storage = init_evm_account_storage().unwrap(); let address_1 = @@ -3838,9 +3838,9 @@ mod test { // ethereum/tests/GeneralStateTests/Shanghai/stSStoreTest/InitCollision.json // with the second data. - let mut host = MockHost::default(); + let mut host = MockKernelHost::default(); let block = dummy_first_block(); - let precompiles = precompiles::precompile_set::(false); + let precompiles = precompiles::precompile_set::(false); let mut evm_account_storage = init_evm_account_storage().unwrap(); let address_1 = @@ -3915,9 +3915,9 @@ mod test { #[test] fn nonce_bump_before_tx() { - let mut host = MockHost::default(); + let mut host = MockKernelHost::default(); let block = dummy_first_block(); - let precompiles = precompiles::precompile_set::(false); + let precompiles = precompiles::precompile_set::(false); let mut evm_account_storage = init_evm_account_storage().unwrap(); let caller = H160::from_str("a94f5374fce5edbc8e2a8697c15331677e6ebf0b").unwrap(); diff --git a/etherlink/kernel_evm/evm_execution/src/precompiles/fa_bridge.rs b/etherlink/kernel_evm/evm_execution/src/precompiles/fa_bridge.rs index 9aaf440d34be..a244e6879d12 100644 --- a/etherlink/kernel_evm/evm_execution/src/precompiles/fa_bridge.rs +++ b/etherlink/kernel_evm/evm_execution/src/precompiles/fa_bridge.rs @@ -160,7 +160,7 @@ mod tests { use alloy_sol_types::SolCall; use evm::{Config, ExitError}; use primitive_types::{H160, U256}; - use tezos_smart_rollup_mock::MockHost; + use tezos_evm_runtime::runtime::MockKernelHost; use crate::{ account_storage::{init_account_storage, EthereumAccountStorage}, @@ -178,7 +178,7 @@ mod tests { }; fn execute_precompile( - host: &mut MockHost, + host: &mut MockKernelHost, evm_account_storage: &mut EthereumAccountStorage, caller: H160, value: Option, @@ -190,7 +190,7 @@ mod tests { let config = Config::shanghai(); let callee = FA_BRIDGE_PRECOMPILE_ADDRESS; - let precompiles = precompiles::precompile_set::(true); + let precompiles = precompiles::precompile_set::(true); let mut handler = EvmHandler::new( host, @@ -212,7 +212,7 @@ mod tests { #[test] fn fa_bridge_precompile_fails_due_to_bad_selector() { - let mut mock_runtime = MockHost::default(); + let mut mock_runtime = MockKernelHost::default(); let mut evm_account_storage = init_account_storage().unwrap(); let outcome = execute_precompile( @@ -232,7 +232,7 @@ mod tests { #[test] fn fa_bridge_precompile_fails_due_to_low_gas_limit() { - let mut mock_runtime = MockHost::default(); + let mut mock_runtime = MockKernelHost::default(); let mut evm_account_storage = init_account_storage().unwrap(); let outcome = execute_precompile( @@ -253,7 +253,7 @@ mod tests { #[test] fn fa_bridge_precompile_fails_due_to_non_zero_value() { - let mut mock_runtime = MockHost::default(); + let mut mock_runtime = MockKernelHost::default(); let mut evm_account_storage = init_account_storage().unwrap(); let caller = H160::from_low_u64_be(1); @@ -281,7 +281,7 @@ mod tests { #[test] fn fa_bridge_precompile_fails_due_to_static_call() { - let mut mock_runtime = MockHost::default(); + let mut mock_runtime = MockKernelHost::default(); let mut evm_account_storage = init_account_storage().unwrap(); let caller = H160::from_low_u64_be(1); @@ -302,7 +302,7 @@ mod tests { #[test] fn fa_bridge_precompile_fails_due_to_delegate_call() { - let mut mock_runtime = MockHost::default(); + let mut mock_runtime = MockKernelHost::default(); let mut evm_account_storage = init_account_storage().unwrap(); let caller = H160::from_low_u64_be(1); @@ -310,7 +310,7 @@ mod tests { let block = dummy_first_block(); let config = Config::shanghai(); - let precompiles = precompiles::precompile_set::(true); + let precompiles = precompiles::precompile_set::(true); let mut handler = EvmHandler::new( &mut mock_runtime, @@ -344,7 +344,7 @@ mod tests { #[test] fn fa_bridge_precompile_fails_due_to_invalid_input() { - let mut mock_runtime = MockHost::default(); + let mut mock_runtime = MockKernelHost::default(); let mut evm_account_storage = init_account_storage().unwrap(); let outcome = execute_precompile( @@ -364,7 +364,7 @@ mod tests { #[test] fn fa_bridge_precompile_succeeds_without_l2_proxy_contract() { - let mut mock_runtime = MockHost::default(); + let mut mock_runtime = MockKernelHost::default(); let mut evm_account_storage = init_account_storage().unwrap(); let ticket_owner = H160::from_low_u64_be(1); diff --git a/etherlink/kernel_evm/evm_execution/src/precompiles/mod.rs b/etherlink/kernel_evm/evm_execution/src/precompiles/mod.rs index eeeccb9cb396..d669ea63a970 100644 --- a/etherlink/kernel_evm/evm_execution/src/precompiles/mod.rs +++ b/etherlink/kernel_evm/evm_execution/src/precompiles/mod.rs @@ -272,14 +272,14 @@ mod test_helpers { use primitive_types::{H160, U256}; use tezos_ethereum::block::BlockConstants; use tezos_ethereum::block::BlockFees; - use tezos_smart_rollup_mock::MockHost; + use tezos_evm_runtime::runtime::MockKernelHost; use super::precompile_set; const DUMMY_ALLOCATED_TICKS: u64 = 100_000_000; pub const DUMMY_TICKETER: &str = "KT1TxqZ8QtKvLu3V3JH7Gx58n7Co8pgtpQU5"; pub fn set_balance( - host: &mut MockHost, + host: &mut MockKernelHost, evm_account_storage: &mut EthereumAccountStorage, address: &H160, balance: U256, @@ -307,7 +307,7 @@ mod test_helpers { is_static: bool, ) -> Result { let caller = H160::from_low_u64_be(118u64); - let mut mock_runtime = MockHost::default(); + let mut mock_runtime = MockKernelHost::default(); let block_fees = BlockFees::new( U256::from(21000), U256::from(21000), @@ -321,7 +321,7 @@ mod test_helpers { H160::zero(), ); let mut evm_account_storage = init_evm_account_storage().unwrap(); - let precompiles = precompile_set::(false); + let precompiles = precompile_set::(false); let config = Config::shanghai(); let gas_price = U256::from(21000); @@ -365,7 +365,7 @@ mod test_helpers { ) } - fn set_ticketer(host: &mut MockHost, address: &str) { + fn set_ticketer(host: &mut MockKernelHost, address: &str) { host.store_write(&NATIVE_TOKEN_TICKETER_PATH, address.as_bytes(), 0) .unwrap(); } diff --git a/etherlink/kernel_evm/evm_execution/src/withdrawal_counter.rs b/etherlink/kernel_evm/evm_execution/src/withdrawal_counter.rs index c3b355b839e2..d40d220b32bb 100644 --- a/etherlink/kernel_evm/evm_execution/src/withdrawal_counter.rs +++ b/etherlink/kernel_evm/evm_execution/src/withdrawal_counter.rs @@ -49,8 +49,8 @@ impl WithdrawalCounter for EthereumAccount { #[cfg(test)] mod tests { use primitive_types::U256; + use tezos_evm_runtime::runtime::MockKernelHost; use tezos_smart_rollup_host::path::RefPath; - use tezos_smart_rollup_mock::MockHost; use tezos_storage::read_u256_le_default; use crate::{account_storage::EthereumAccount, precompiles::SYSTEM_ACCOUNT_ADDRESS}; @@ -59,7 +59,7 @@ mod tests { #[test] fn withdrawal_counter_initializes_and_increments() { - let mut mock_host = MockHost::default(); + let mut mock_host = MockKernelHost::default(); let mut account = EthereumAccount::from_address(&SYSTEM_ACCOUNT_ADDRESS).unwrap(); let path = b"/evm/world_state/eth_accounts/0000000000000000000000000000000000000000/withdrawal_counter"; diff --git a/etherlink/kernel_evm/indexable_storage/src/lib.rs b/etherlink/kernel_evm/indexable_storage/src/lib.rs index 15128d47f86a..383d87337623 100644 --- a/etherlink/kernel_evm/indexable_storage/src/lib.rs +++ b/etherlink/kernel_evm/indexable_storage/src/lib.rs @@ -165,13 +165,12 @@ impl IndexableStorage { #[cfg(test)] mod tests { use super::*; - use tezos_evm_runtime::{mock_internal::MockInternal, runtime::KernelHost}; + use tezos_evm_runtime::runtime::MockKernelHost; use tezos_smart_rollup_host::path::RefPath; - use tezos_smart_rollup_mock::MockHost; #[test] fn test_indexable_empty() { - let host = KernelHost::::default(); + let host = MockKernelHost::default(); let values = RefPath::assert_from(b"/values"); let storage = IndexableStorage::new(&values).expect("Path to index is invalid"); @@ -180,7 +179,7 @@ mod tests { #[test] fn test_indexing_new_value() { - let mut host = KernelHost::::default(); + let mut host = MockKernelHost::default(); let values = RefPath::assert_from(b"/values"); let storage = IndexableStorage::new(&values).expect("Path to index is invalid"); @@ -197,7 +196,7 @@ mod tests { #[test] fn test_get_out_of_bounds() { - let mut host = KernelHost::::default(); + let mut host = MockKernelHost::default(); let values = RefPath::assert_from(b"/values"); let storage = IndexableStorage::new(&values).expect("Path to index is invalid"); diff --git a/etherlink/kernel_evm/kernel/src/apply.rs b/etherlink/kernel_evm/kernel/src/apply.rs index 1ed5aa032358..03b4ddd22e97 100644 --- a/etherlink/kernel_evm/kernel/src/apply.rs +++ b/etherlink/kernel_evm/kernel/src/apply.rs @@ -693,7 +693,6 @@ pub fn apply_transaction( #[cfg(test)] mod tests { - use std::vec; use crate::{apply::Validity, configuration::Limits, fees::gas_for_fees}; use evm_execution::account_storage::{account_path, EthereumAccountStorage}; @@ -703,8 +702,8 @@ mod tests { transaction::TransactionType, tx_common::EthereumTransactionCommon, }; + use tezos_evm_runtime::runtime::MockKernelHost; use tezos_smart_rollup_encoding::timestamp::Timestamp; - use tezos_smart_rollup_mock::MockHost; use super::is_valid_ethereum_transaction_common; @@ -731,7 +730,7 @@ mod tests { } fn set_balance( - host: &mut MockHost, + host: &mut MockKernelHost, evm_account_storage: &mut EthereumAccountStorage, address: &H160, balance: U256, @@ -790,7 +789,7 @@ mod tests { #[test] fn test_tx_is_valid() { - let mut host = MockHost::default(); + let mut host = MockKernelHost::default(); let mut evm_account_storage = evm_execution::account_storage::init_account_storage().unwrap(); let block_constants = mock_block_constants(); @@ -823,7 +822,7 @@ mod tests { #[test] fn test_tx_is_invalid_cannot_prepay() { - let mut host = MockHost::default(); + let mut host = MockKernelHost::default(); let mut evm_account_storage = evm_execution::account_storage::init_account_storage().unwrap(); let block_constants = mock_block_constants(); @@ -858,7 +857,7 @@ mod tests { #[test] fn test_tx_is_invalid_signature() { - let mut host = MockHost::default(); + let mut host = MockKernelHost::default(); let mut evm_account_storage = evm_execution::account_storage::init_account_storage().unwrap(); let block_constants = mock_block_constants(); @@ -893,7 +892,7 @@ mod tests { #[test] fn test_tx_is_invalid_wrong_nonce() { - let mut host = MockHost::default(); + let mut host = MockKernelHost::default(); let mut evm_account_storage = evm_execution::account_storage::init_account_storage().unwrap(); let block_constants = mock_block_constants(); @@ -930,7 +929,7 @@ mod tests { #[test] fn test_tx_is_invalid_wrong_chain_id() { - let mut host = MockHost::default(); + let mut host = MockKernelHost::default(); let mut evm_account_storage = evm_execution::account_storage::init_account_storage().unwrap(); let block_constants = mock_block_constants(); @@ -965,7 +964,7 @@ mod tests { #[test] fn test_tx_is_invalid_max_fee_less_than_base_fee() { - let mut host = MockHost::default(); + let mut host = MockKernelHost::default(); let mut evm_account_storage = evm_execution::account_storage::init_account_storage().unwrap(); let block_constants = mock_block_constants(); @@ -1000,7 +999,7 @@ mod tests { #[test] fn test_tx_invalid_not_enough_gas_for_fee() { - let mut host = MockHost::default(); + let mut host = MockKernelHost::default(); let mut evm_account_storage = evm_execution::account_storage::init_account_storage().unwrap(); let block_constants = mock_block_constants(); diff --git a/etherlink/kernel_evm/kernel/src/blueprint_storage.rs b/etherlink/kernel_evm/kernel/src/blueprint_storage.rs index e74783f97578..690213da5cc7 100644 --- a/etherlink/kernel_evm/kernel/src/blueprint_storage.rs +++ b/etherlink/kernel_evm/kernel/src/blueprint_storage.rs @@ -494,7 +494,7 @@ mod tests { use tezos_ethereum::transaction::TRANSACTION_HASH_SIZE; use tezos_evm_runtime::runtime::MockKernelHost; use tezos_smart_rollup_encoding::public_key::PublicKey; - use tezos_smart_rollup_host::runtime::Runtime; + use tezos_smart_rollup_host::runtime::Runtime as SdkRuntime; // Used to put traits interface in the scope fn test_invalid_sequencer_blueprint_is_removed(enable_dal: bool) { let mut host = MockKernelHost::default(); diff --git a/etherlink/kernel_evm/kernel/src/bridge.rs b/etherlink/kernel_evm/kernel/src/bridge.rs index df71f8d3ae64..f32c1ef62fc0 100644 --- a/etherlink/kernel_evm/kernel/src/bridge.rs +++ b/etherlink/kernel_evm/kernel/src/bridge.rs @@ -222,7 +222,7 @@ mod tests { use evm_execution::account_storage::init_account_storage; use primitive_types::{H160, U256}; use rlp::Decodable; - use tezos_smart_rollup_mock::MockHost; + use tezos_evm_runtime::runtime::MockKernelHost; use crate::{bridge::DEPOSIT_EVENT_TOPIC, CONFIG}; @@ -273,7 +273,7 @@ mod tests { #[test] fn deposit_execution_outcome_contains_event() { - let mut host = MockHost::default(); + let mut host = MockKernelHost::default(); let mut evm_account_storage = init_account_storage().unwrap(); let deposit = dummy_deposit(); @@ -300,7 +300,7 @@ mod tests { #[test] fn deposit_execution_fails_due_to_balance_overflow() { - let mut host = MockHost::default(); + let mut host = MockKernelHost::default(); let mut evm_account_storage = init_account_storage().unwrap(); let mut deposit = dummy_deposit(); diff --git a/etherlink/kernel_evm/kernel/src/fees.rs b/etherlink/kernel_evm/kernel/src/fees.rs index 7e0e1a5a1592..c2a0e82bf416 100644 --- a/etherlink/kernel_evm/kernel/src/fees.rs +++ b/etherlink/kernel_evm/kernel/src/fees.rs @@ -311,7 +311,7 @@ mod tests { use evm::ExitSucceed; use evm_execution::account_storage::{account_path, EthereumAccountStorage}; use primitive_types::{H160, U256}; - use tezos_smart_rollup_mock::MockHost; + use tezos_evm_runtime::runtime::MockKernelHost; use proptest::prelude::*; @@ -362,7 +362,7 @@ mod tests { #[test] fn apply_updates_balances_no_sequencer() { // Arrange - let mut host = MockHost::default(); + let mut host = MockKernelHost::default(); let mut evm_account_storage = evm_execution::account_storage::init_account_storage().unwrap(); @@ -399,7 +399,7 @@ mod tests { #[test] fn apply_updates_balances_with_sequencer() { // Arrange - let mut host = MockHost::default(); + let mut host = MockKernelHost::default(); let sequencer_address = address_from_str("0123456789ABCDEF0123456789ABCDEF01234567"); @@ -456,7 +456,7 @@ mod tests { #[test] fn apply_fails_user_charge_too_large() { // Arrange - let mut host = MockHost::default(); + let mut host = MockKernelHost::default(); let mut evm_account_storage = evm_execution::account_storage::init_account_storage().unwrap(); @@ -510,7 +510,7 @@ mod tests { } fn get_balance( - host: &mut MockHost, + host: &mut MockKernelHost, evm_account_storage: &mut EthereumAccountStorage, address: H160, ) -> U256 { @@ -521,7 +521,7 @@ mod tests { } fn set_balance( - host: &mut MockHost, + host: &mut MockKernelHost, evm_account_storage: &mut EthereumAccountStorage, address: H160, balance: U256, diff --git a/etherlink/kernel_evm/kernel/src/lib.rs b/etherlink/kernel_evm/kernel/src/lib.rs index 9981d2a9bdaa..3bff17485ace 100644 --- a/etherlink/kernel_evm/kernel/src/lib.rs +++ b/etherlink/kernel_evm/kernel/src/lib.rs @@ -407,6 +407,7 @@ mod tests { use tezos_evm_runtime::runtime::MockKernelHost; use tezos_evm_runtime::safe_storage::SafeStorage; + use tezos_evm_runtime::runtime::Runtime; use tezos_smart_rollup::michelson::ticket::FA2_1Ticket; use tezos_smart_rollup::michelson::{ MichelsonBytes, MichelsonContract, MichelsonNat, MichelsonOption, MichelsonPair, @@ -414,11 +415,11 @@ mod tests { use tezos_smart_rollup::outbox::{OutboxMessage, OutboxMessageTransaction}; use tezos_smart_rollup::types::{Contract, Entrypoint}; use tezos_smart_rollup_core::PREIMAGE_HASH_SIZE; - use tezos_smart_rollup_debug::Runtime; use tezos_smart_rollup_encoding::inbox::ExternalMessageFrame; use tezos_smart_rollup_encoding::smart_rollup::SmartRollupAddress; use tezos_smart_rollup_encoding::timestamp::Timestamp; use tezos_smart_rollup_host::path::RefPath; + use tezos_smart_rollup_host::runtime::Runtime as SdkRuntime; // Used to put traits interface in the scope use tezos_smart_rollup_mock::TransferMetadata; const DUMMY_CHAIN_ID: U256 = U256::one(); @@ -675,10 +676,8 @@ mod tests { #[test] fn test_xtz_withdrawal_applied() { // init host - let mut mock_host = MockKernelHost::default(); - let mut safe_storage = SafeStorage { - host: &mut mock_host, - }; + let mut host = MockKernelHost::default(); + let mut safe_storage = SafeStorage { host: &mut host }; safe_storage .store_write_all( &NATIVE_TOKEN_TICKETER_PATH, diff --git a/etherlink/kernel_evm/kernel/src/linked_list.rs b/etherlink/kernel_evm/kernel/src/linked_list.rs index 69abd0812021..1986cdf401ff 100644 --- a/etherlink/kernel_evm/kernel/src/linked_list.rs +++ b/etherlink/kernel_evm/kernel/src/linked_list.rs @@ -450,9 +450,9 @@ mod tests { use rlp::{Decodable, DecoderError, Encodable}; use std::collections::HashMap; use tezos_ethereum::transaction::TRANSACTION_HASH_SIZE; + use tezos_evm_runtime::runtime::MockKernelHost; use tezos_smart_rollup_debug::Runtime; use tezos_smart_rollup_host::path::RefPath; - use tezos_smart_rollup_mock::MockHost; #[derive(Clone)] struct Hash([u8; TRANSACTION_HASH_SIZE]); @@ -479,7 +479,11 @@ mod tests { } } - fn assert_length(host: &MockHost, list: &LinkedList, expected_len: u64) { + fn assert_length( + host: &MockKernelHost, + list: &LinkedList, + expected_len: u64, + ) { // Both the linked list pointers and the element pointers lies under // the `list.path`. let keys = host.store_count_subkeys(&list.path).unwrap_or(0u64); @@ -493,7 +497,7 @@ mod tests { #[test] fn test_empty() { - let host = MockHost::default(); + let host = MockKernelHost::default(); let path = RefPath::assert_from(b"/list"); let list = LinkedList::::new(&path, &host).expect("list should be created"); @@ -502,7 +506,7 @@ mod tests { #[test] fn test_find_returns_none_when_empty() { - let host = MockHost::default(); + let host = MockKernelHost::default(); let path = RefPath::assert_from(b"/list"); let list = LinkedList::new(&path, &host).expect("list should be created"); let hash = Hash([0; TRANSACTION_HASH_SIZE]); @@ -512,7 +516,7 @@ mod tests { #[test] fn test_insert() { - let mut host = MockHost::default(); + let mut host = MockKernelHost::default(); let path = RefPath::assert_from(b"/list"); let mut list = LinkedList::new(&path, &host).expect("list should be created"); let id = Hash([0x0; TRANSACTION_HASH_SIZE]); @@ -531,7 +535,7 @@ mod tests { #[test] fn test_remove() { - let mut host = MockHost::default(); + let mut host = MockKernelHost::default(); let path = RefPath::assert_from(b"/list"); let mut list = LinkedList::new(&path, &host).expect("list should be created"); let id = Hash([0x0; TRANSACTION_HASH_SIZE]); @@ -551,7 +555,7 @@ mod tests { #[test] fn test_remove_nothing() { - let mut host = MockHost::default(); + let mut host = MockKernelHost::default(); let path = RefPath::assert_from(b"/list"); let mut list = LinkedList::new(&path, &host).expect("list should be created"); let id = Hash([0x0; TRANSACTION_HASH_SIZE]); @@ -564,7 +568,7 @@ mod tests { #[test] fn test_first() { - let mut host = MockHost::default(); + let mut host = MockKernelHost::default(); let path = RefPath::assert_from(b"/list"); let mut list = LinkedList::new(&path, &host).expect("list should be created"); let id = Hash([0x0; TRANSACTION_HASH_SIZE]); @@ -583,7 +587,7 @@ mod tests { #[test] fn test_first_when_only_two_elements() { - let mut host = MockHost::default(); + let mut host = MockKernelHost::default(); let path = RefPath::assert_from(b"/list"); let mut list = LinkedList::new(&path, &host).expect("list should be created"); let id_1 = Hash([0x0; TRANSACTION_HASH_SIZE]); @@ -604,7 +608,7 @@ mod tests { #[test] fn test_first_after_two_push() { - let mut host = MockHost::default(); + let mut host = MockKernelHost::default(); let path = RefPath::assert_from(b"/list"); let mut list = LinkedList::new(&path, &host).expect("list should be created"); let id_1 = Hash([0x0; TRANSACTION_HASH_SIZE]); @@ -626,7 +630,7 @@ mod tests { #[test] fn test_delete() { - let mut host = MockHost::default(); + let mut host = MockKernelHost::default(); let path = RefPath::assert_from(b"/list"); let mut list: LinkedList = LinkedList::new(&path, &host).expect("list should be created"); @@ -644,8 +648,8 @@ mod tests { fn fill_list( elements: &HashMap<[u8; TRANSACTION_HASH_SIZE], u8>, - ) -> (MockHost, LinkedList) { - let mut host = MockHost::default(); + ) -> (MockKernelHost, LinkedList) { + let mut host = MockKernelHost::default(); let path = RefPath::assert_from(b"/list"); let mut list = LinkedList::new(&path, &host).expect("list should be created"); for (id, elt) in elements { @@ -675,7 +679,7 @@ mod tests { #[test] fn test_push_element_create_non_empty_list(elements in elements()) { - let mut host = MockHost::default(); + let mut host = MockKernelHost::default(); let path = RefPath::assert_from(b"/list"); let mut list = LinkedList::new(&path, &host).expect("list should be created"); assert!(list.is_empty()); @@ -687,7 +691,7 @@ mod tests { #[test] fn test_remove_from_empty_creates_empty_list(elements: Vec<[u8; TRANSACTION_HASH_SIZE]>) { - let mut host = MockHost::default(); + let mut host = MockKernelHost::default(); let path = RefPath::assert_from(b"/list"); let mut list = LinkedList::new(&path, &host).expect("list should be created"); assert!(list.is_empty()); @@ -720,7 +724,7 @@ mod tests { #[test] fn test_list_is_kept_between_reboots(elements in elements()) { - let mut host = MockHost::default(); + let mut host = MockKernelHost::default(); let path = RefPath::assert_from(b"/list"); for (id, elt) in &elements { let mut list = LinkedList::new(&path, &host).expect("list should be created"); @@ -740,7 +744,7 @@ mod tests { #[test] fn test_pop_first_after_push(elements in elements()) { - let mut host = MockHost::default(); + let mut host = MockKernelHost::default(); let path = RefPath::assert_from(b"/list"); let mut list = LinkedList::new(&path, &host).expect("list should be created"); @@ -753,7 +757,7 @@ mod tests { #[test] fn test_pop_first_keep_the_order(elements in elements()) { - let mut host = MockHost::default(); + let mut host = MockKernelHost::default(); let path = RefPath::assert_from(b"/list"); let mut list = LinkedList::new(&path, &host).expect("list should be created"); diff --git a/etherlink/kernel_evm/kernel/src/parsing.rs b/etherlink/kernel_evm/kernel/src/parsing.rs index 8dd82ed7f2a2..3da5aa6847b3 100644 --- a/etherlink/kernel_evm/kernel/src/parsing.rs +++ b/etherlink/kernel_evm/kernel/src/parsing.rs @@ -813,14 +813,14 @@ impl InputResult { #[cfg(test)] mod tests { use super::*; + use tezos_evm_runtime::runtime::MockKernelHost; use tezos_smart_rollup_host::input::Message; - use tezos_smart_rollup_mock::MockHost; const ZERO_SMART_ROLLUP_ADDRESS: [u8; 20] = [0; 20]; #[test] fn parse_unparsable_transaction() { - let mut host = MockHost::default(); + let mut host = MockKernelHost::default(); let message = Message::new(0, 0, vec![1, 9, 32, 58, 59, 30]); assert_eq!( diff --git a/etherlink/kernel_evm/kernel/src/storage.rs b/etherlink/kernel_evm/kernel/src/storage.rs index 3df67ca122c0..692815c08b3b 100644 --- a/etherlink/kernel_evm/kernel/src/storage.rs +++ b/etherlink/kernel_evm/kernel/src/storage.rs @@ -937,12 +937,12 @@ pub fn read_delayed_transaction_bridge( #[cfg(test)] mod tests { - use tezos_smart_rollup_mock::MockHost; + use tezos_evm_runtime::runtime::MockKernelHost; #[test] fn update_burned_fees() { // Arrange - let mut host = MockHost::default(); + let mut host = MockKernelHost::default(); let fst = 17.into(); let snd = 19.into(); -- GitLab