diff --git a/etherlink/kernel_latest/revm/src/code_storage.rs b/etherlink/kernel_latest/revm/src/code_storage.rs index 26f4da13f792428e10bb10904402e5173146bf6a..500558df27bd57b7fe065097df39e848535c75e8 100644 --- a/etherlink/kernel_latest/revm/src/code_storage.rs +++ b/etherlink/kernel_latest/revm/src/code_storage.rs @@ -13,7 +13,7 @@ use tezos_evm_runtime::runtime::Runtime; use tezos_smart_rollup_host::path::{OwnedPath, RefPath}; use crate::{ - helpers::{bytes_hash, concat, read_u64_le_default, write_u64_le}, + helpers::storage::{bytes_hash, concat, read_u64_le_default, write_u64_le}, Error, }; @@ -127,7 +127,7 @@ impl CodeStorage { #[cfg(test)] mod test { use super::{CodeStorage, REFERENCE_PATH}; - use crate::helpers::{concat, read_u64_le}; + use crate::helpers::storage::{concat, read_u64_le}; use revm::{ primitives::{Bytes, KECCAK_EMPTY}, diff --git a/etherlink/kernel_latest/revm/src/helpers/legacy.rs b/etherlink/kernel_latest/revm/src/helpers/legacy.rs new file mode 100644 index 0000000000000000000000000000000000000000..0582815aca2e35e14a62d5c1792b0637a34b0017 --- /dev/null +++ b/etherlink/kernel_latest/revm/src/helpers/legacy.rs @@ -0,0 +1,41 @@ +// SPDX-FileCopyrightText: 2025 Functori +// SPDX-FileCopyrightText: 2025 Nomadic Labs +// +// SPDX-License-Identifier: MIT + +use crate::{custom, Error}; +use alloy_primitives::{self, Address}; +use primitive_types::{H160, H256, U256}; +use rlp::{Decodable, Rlp, RlpDecodable, RlpEncodable}; + +#[derive(Debug, PartialEq, Clone, RlpEncodable, RlpDecodable)] +pub(crate) struct FaDepositWithProxy { + pub amount: U256, + pub receiver: H160, + pub proxy: H160, + pub ticket_hash: H256, + pub inbox_level: u32, + pub inbox_msg_id: u32, +} + +impl FaDepositWithProxy { + pub(crate) fn from_raw(raw_deposit: Vec) -> Result { + FaDepositWithProxy::decode(&Rlp::new(&raw_deposit)).map_err(custom) + } +} + +pub fn u256_to_le_bytes(value: U256) -> Vec { + let mut bytes = vec![0u8; 32]; + value.to_little_endian(&mut bytes); + bytes +} + +pub fn u256_to_alloy(value: &U256) -> Option { + Some(alloy_primitives::U256::from_le_bytes::<32>( + u256_to_le_bytes(*value).try_into().ok()?, + )) +} + +pub fn h160_to_alloy(value: &H160) -> alloy_primitives::Address { + Address::from_slice(&value.to_fixed_bytes()) +} diff --git a/etherlink/kernel_latest/revm/src/helpers/mod.rs b/etherlink/kernel_latest/revm/src/helpers/mod.rs new file mode 100644 index 0000000000000000000000000000000000000000..133b1ac6e0fd9270fadec368ba4cdc02f4e30c5a --- /dev/null +++ b/etherlink/kernel_latest/revm/src/helpers/mod.rs @@ -0,0 +1,7 @@ +// SPDX-FileCopyrightText: 2025 Functori +// +// SPDX-License-Identifier: MIT + +pub mod legacy; +pub mod rlp; +pub mod storage; diff --git a/etherlink/kernel_latest/revm/src/helpers/rlp.rs b/etherlink/kernel_latest/revm/src/helpers/rlp.rs new file mode 100644 index 0000000000000000000000000000000000000000..d86f16f84d8b1f79b5c77932794c9420601a101e --- /dev/null +++ b/etherlink/kernel_latest/revm/src/helpers/rlp.rs @@ -0,0 +1,51 @@ +// SPDX-FileCopyrightText: 2025 Functori +// +// SPDX-License-Identifier: MIT + +use revm::primitives::{Address, U256}; +use rlp::RlpStream; + +pub fn append_u16_le<'a>(stream: &'a mut RlpStream, v: &u16) -> &'a mut RlpStream { + stream.append(&v.to_le_bytes().to_vec()) +} + +pub fn append_u64_le<'a>(stream: &'a mut RlpStream, v: &u64) -> &'a mut RlpStream { + stream.append(&v.to_le_bytes().to_vec()) +} + +pub fn append_address<'a>( + stream: &'a mut RlpStream, + address: &Address, +) -> &'a mut RlpStream { + stream.append(&address.to_vec()) +} + +pub fn append_option_canonical<'a, T, Enc>( + stream: &'a mut rlp::RlpStream, + v: &Option, + append: Enc, +) where + Enc: Fn(&'a mut RlpStream, &T) -> &'a mut RlpStream, +{ + match v { + None => { + stream.begin_list(0); + } + Some(value) => { + stream.begin_list(1); + append(stream, value); + } + } +} + +pub fn append_option_u64_le(stream: &mut rlp::RlpStream, v: &Option) { + append_option_canonical(stream, v, append_u64_le) +} + +pub fn append_option_address(stream: &mut rlp::RlpStream, address: &Option
) { + append_option_canonical(stream, address, append_address) +} + +pub fn append_u256_le<'a>(stream: &'a mut RlpStream, v: &U256) -> &'a mut RlpStream { + stream.append(&v.to_le_bytes::<32>().to_vec()) +} diff --git a/etherlink/kernel_latest/revm/src/helpers.rs b/etherlink/kernel_latest/revm/src/helpers/storage.rs similarity index 58% rename from etherlink/kernel_latest/revm/src/helpers.rs rename to etherlink/kernel_latest/revm/src/helpers/storage.rs index 78c2b0bb7a0717a70fa94e9406a1e35c3dcb45f1..f27193c66b165d6b8e996536ecdd7ed146311255 100644 --- a/etherlink/kernel_latest/revm/src/helpers.rs +++ b/etherlink/kernel_latest/revm/src/helpers/storage.rs @@ -122,92 +122,3 @@ pub fn u256_to_le_bytes(value: primitive_types::U256) -> Vec { pub fn u256_to_bigint(value: U256) -> BigInt { BigInt::from_bytes_be(Sign::Plus, &value.to_be_bytes::<{ U256::BYTES }>()) } - -pub mod legacy { - use crate::{custom, Error}; - use alloy_primitives::{self, Address}; - use primitive_types::{H160, H256, U256}; - use rlp::{Decodable, Rlp, RlpDecodable, RlpEncodable}; - - #[derive(Debug, PartialEq, Clone, RlpEncodable, RlpDecodable)] - pub(crate) struct FaDepositWithProxy { - pub amount: U256, - pub receiver: H160, - pub proxy: H160, - pub ticket_hash: H256, - pub inbox_level: u32, - pub inbox_msg_id: u32, - } - - impl FaDepositWithProxy { - pub(crate) fn from_raw(raw_deposit: Vec) -> Result { - FaDepositWithProxy::decode(&Rlp::new(&raw_deposit)).map_err(custom) - } - } - - pub fn u256_to_le_bytes(value: U256) -> Vec { - let mut bytes = vec![0u8; 32]; - value.to_little_endian(&mut bytes); - bytes - } - - pub fn u256_to_alloy(value: &U256) -> Option { - Some(alloy_primitives::U256::from_le_bytes::<32>( - u256_to_le_bytes(*value).try_into().ok()?, - )) - } - - pub fn h160_to_alloy(value: &H160) -> alloy_primitives::Address { - Address::from_slice(&value.to_fixed_bytes()) - } -} - -pub mod rlp { - use revm::primitives::{Address, U256}; - use rlp::RlpStream; - - pub fn append_u16_le<'a>(stream: &'a mut RlpStream, v: &u16) -> &'a mut RlpStream { - stream.append(&v.to_le_bytes().to_vec()) - } - - pub fn append_u64_le<'a>(stream: &'a mut RlpStream, v: &u64) -> &'a mut RlpStream { - stream.append(&v.to_le_bytes().to_vec()) - } - - pub fn append_address<'a>( - stream: &'a mut RlpStream, - address: &Address, - ) -> &'a mut RlpStream { - stream.append(&address.to_vec()) - } - - pub fn append_option_canonical<'a, T, Enc>( - stream: &'a mut rlp::RlpStream, - v: &Option, - append: Enc, - ) where - Enc: Fn(&'a mut RlpStream, &T) -> &'a mut RlpStream, - { - match v { - None => { - stream.begin_list(0); - } - Some(value) => { - stream.begin_list(1); - append(stream, value); - } - } - } - - pub fn append_option_u64_le(stream: &mut rlp::RlpStream, v: &Option) { - append_option_canonical(stream, v, append_u64_le) - } - - pub fn append_option_address(stream: &mut rlp::RlpStream, address: &Option
) { - append_option_canonical(stream, address, append_address) - } - - pub fn append_u256_le<'a>(stream: &'a mut RlpStream, v: &U256) -> &'a mut RlpStream { - stream.append(&v.to_le_bytes::<32>().to_vec()) - } -} diff --git a/etherlink/kernel_latest/revm/src/inspectors/storage.rs b/etherlink/kernel_latest/revm/src/inspectors/storage.rs index 728505c30d53d3732f0962803bcde1e65c870a8b..886b6c1b17345fcfb5829f47b2e577bb18440c7e 100644 --- a/etherlink/kernel_latest/revm/src/inspectors/storage.rs +++ b/etherlink/kernel_latest/revm/src/inspectors/storage.rs @@ -3,7 +3,7 @@ // SPDX-License-Identifier: MIT use super::call_tracer::CallTrace; -use crate::{helpers::concat, Error}; +use crate::{helpers::storage::concat, Error}; use revm::primitives::B256; use tezos_evm_logging::{log, Level::Debug}; diff --git a/etherlink/kernel_latest/revm/src/lib.rs b/etherlink/kernel_latest/revm/src/lib.rs index 2049d405167797ca51a499bfeccdd17fc884ace4..4067f33b5cfc6cef9f8ec37daa8898d9e8972a0c 100644 --- a/etherlink/kernel_latest/revm/src/lib.rs +++ b/etherlink/kernel_latest/revm/src/lib.rs @@ -5,7 +5,7 @@ use crate::{database::PrecompileDatabase, send_outbox_message::Withdrawal}; use database::EtherlinkVMDB; -use helpers::u256_to_le_bytes; +use helpers::storage::u256_to_le_bytes; use inspectors::{ call_tracer::CallTracer, noop::NoInspector, CallTracerInput, EtherlinkInspector, EvmInspection, TracerInput, diff --git a/etherlink/kernel_latest/revm/src/send_outbox_message.rs b/etherlink/kernel_latest/revm/src/send_outbox_message.rs index 3fe6734872b07503fcb3bf147399391cd5278f13..82f8afe81cc07090f33b765c03ec797f8fa2383f 100644 --- a/etherlink/kernel_latest/revm/src/send_outbox_message.rs +++ b/etherlink/kernel_latest/revm/src/send_outbox_message.rs @@ -24,7 +24,7 @@ use tezos_smart_rollup_encoding::{ use crate::{ constants::{FA_WITHDRAWAL_SOL_ADDR, PRECOMPILE_BASE_COST, WITHDRAWAL_SOL_ADDR}, database::PrecompileDatabase, - helpers::u256_to_bigint, + helpers::storage::u256_to_bigint, }; sol! { diff --git a/etherlink/kernel_latest/revm/src/world_state_handler.rs b/etherlink/kernel_latest/revm/src/world_state_handler.rs index ff0ea0e88b96902e9678c69639ac7f125fa8fa10..641a014bcd0ca76ce7c2a9e20e43a721768fb47d 100644 --- a/etherlink/kernel_latest/revm/src/world_state_handler.rs +++ b/etherlink/kernel_latest/revm/src/world_state_handler.rs @@ -18,7 +18,7 @@ use tezos_smart_rollup_storage::storage::Storage; use crate::{ code_storage::CodeStorage, helpers::legacy::FaDepositWithProxy, - helpers::{ + helpers::storage::{ concat, read_b256_be_default, read_u256_be_default, read_u256_le_default, read_u64_le_default, write_u256_le, },