diff --git a/Cargo.lock b/Cargo.lock index 32520521e0..50b43a5275 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2417,7 +2417,6 @@ name = "revm-primitives" version = "1.3.0" dependencies = [ "alloy-primitives", - "alloy-rlp", "auto_impl", "bitflags 2.4.1", "bitvec", diff --git a/bins/revme/Cargo.toml b/bins/revme/Cargo.toml index 03f34cb563..fad281a9ea 100644 --- a/bins/revme/Cargo.toml +++ b/bins/revme/Cargo.toml @@ -21,7 +21,8 @@ revm = { path = "../../crates/revm", version = "3.5.0", default-features = false "c-kzg", ] } alloy-rlp = { version = "0.3", default-features = false, features = [ - "arrayvec", + "arrayvec", + "derive", ] } serde = { version = "1.0", features = ["derive", "rc"] } serde_json = { version = "1.0", features = ["preserve_order"] } diff --git a/crates/interpreter/src/host.rs b/crates/interpreter/src/host.rs index 8170f1e339..87000e7aaa 100644 --- a/crates/interpreter/src/host.rs +++ b/crates/interpreter/src/host.rs @@ -1,8 +1,7 @@ use crate::{ - primitives::{Address, Bytecode, Bytes, Env, B256, U256}, + primitives::{Address, Bytecode, Env, Log, B256, U256}, SelfDestructResult, }; -use alloc::vec::Vec; mod dummy; pub use dummy::DummyHost; @@ -48,8 +47,8 @@ pub trait Host { /// Set the transient storage value of `address` at `index`. fn tstore(&mut self, address: Address, index: U256, value: U256); - /// Emit a log owned by `address` with given `topics` and `data`. - fn log(&mut self, address: Address, topics: Vec, data: Bytes); + /// Emit a log owned by `address` with given `LogData`. + fn log(&mut self, log: Log); /// Mark `address` to be deleted, with funds transferred to `target`. fn selfdestruct(&mut self, address: Address, target: Address) -> Option; diff --git a/crates/interpreter/src/host/dummy.rs b/crates/interpreter/src/host/dummy.rs index d6b1f57c06..da365a550a 100644 --- a/crates/interpreter/src/host/dummy.rs +++ b/crates/interpreter/src/host/dummy.rs @@ -1,4 +1,4 @@ -use crate::primitives::{hash_map::Entry, Bytecode, Bytes, HashMap, U256}; +use crate::primitives::{hash_map::Entry, Bytecode, HashMap, U256}; use crate::{ primitives::{Address, Env, Log, B256, KECCAK_EMPTY}, Host, SelfDestructResult, @@ -106,12 +106,8 @@ impl Host for DummyHost { } #[inline] - fn log(&mut self, address: Address, topics: Vec, data: Bytes) { - self.log.push(Log { - address, - topics, - data, - }) + fn log(&mut self, log: Log) { + self.log.push(log) } #[inline] diff --git a/crates/interpreter/src/instructions/host.rs b/crates/interpreter/src/instructions/host.rs index 9cdfbccb8e..59b119e2a4 100644 --- a/crates/interpreter/src/instructions/host.rs +++ b/crates/interpreter/src/instructions/host.rs @@ -1,7 +1,7 @@ use crate::{ gas::{self, COLD_ACCOUNT_ACCESS_COST, WARM_STORAGE_READ_COST}, interpreter::{Interpreter, InterpreterAction}, - primitives::{Address, Bytes, Spec, SpecId::*, B256, U256}, + primitives::{Address, Bytes, Log, LogData, Spec, SpecId::*, B256, U256}, CallContext, CallInputs, CallScheme, CreateInputs, CreateScheme, Host, InstructionResult, Transfer, MAX_INITCODE_SIZE, }; @@ -211,7 +211,12 @@ pub fn log(interpreter: &mut Interpreter, host: &mut H) topics.push(B256::from(unsafe { interpreter.stack.pop_unsafe() })); } - host.log(interpreter.contract.address, topics, data); + let log = Log { + address: interpreter.contract.address, + data: LogData::new(topics, data).expect("LogData should have <=4 topics"), + }; + + host.log(log); } pub fn selfdestruct(interpreter: &mut Interpreter, host: &mut H) { diff --git a/crates/precompile/src/lib.rs b/crates/precompile/src/lib.rs index aa99a81776..6addef49e2 100644 --- a/crates/precompile/src/lib.rs +++ b/crates/precompile/src/lib.rs @@ -27,7 +27,7 @@ use once_cell::race::OnceBox; pub use revm_primitives as primitives; pub use revm_primitives::{ precompile::{PrecompileError as Error, *}, - Address, Bytes, HashMap, B256, + Address, Bytes, HashMap, Log, B256, }; pub fn calc_linear_cost_u32(len: usize, base: u64, word: u64) -> u64 { @@ -41,13 +41,6 @@ pub struct PrecompileOutput { pub logs: Vec, } -#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)] -pub struct Log { - pub address: Address, - pub topics: Vec, - pub data: Bytes, -} - impl PrecompileOutput { pub fn without_logs(cost: u64, output: Vec) -> Self { Self { diff --git a/crates/primitives/Cargo.toml b/crates/primitives/Cargo.toml index f57f7001f9..e20e00f541 100644 --- a/crates/primitives/Cargo.toml +++ b/crates/primitives/Cargo.toml @@ -20,7 +20,6 @@ rustdoc-args = ["--cfg", "docsrs"] alloy-primitives = { version = "0.6", default-features = false, features = [ "rlp", ] } -alloy-rlp = { version = "0.3", default-features = false, features = ["derive"] } hashbrown = "0.14" auto_impl = "1.1" bitvec = { version = "1", default-features = false, features = ["alloc"] } @@ -44,7 +43,6 @@ hex = "0.4" default = ["std", "c-kzg"] std = [ "alloy-primitives/std", - "alloy-rlp/std", "hex/std", "bitvec/std", "bitflags/std", diff --git a/crates/primitives/src/lib.rs b/crates/primitives/src/lib.rs index d721b4bef8..f2a6c049cc 100644 --- a/crates/primitives/src/lib.rs +++ b/crates/primitives/src/lib.rs @@ -15,7 +15,6 @@ pub mod db; pub mod env; #[cfg(feature = "c-kzg")] pub mod kzg; -mod log; pub mod precompile; pub mod result; pub mod specification; @@ -24,7 +23,7 @@ pub mod utilities; pub use alloy_primitives::{ self, address, b256, bytes, fixed_bytes, hex, hex_literal, ruint, uint, Address, Bytes, - FixedBytes, B256, I256, U256, + FixedBytes, Log, LogData, B256, I256, U256, }; pub use bitvec; pub use bytecode::*; @@ -33,7 +32,6 @@ pub use env::*; pub use hashbrown::{hash_map, hash_set, HashMap, HashSet}; #[cfg(feature = "c-kzg")] pub use kzg::{EnvKzgSettings, KzgSettings}; -pub use log::*; pub use precompile::*; pub use result::*; pub use specification::*; diff --git a/crates/primitives/src/log.rs b/crates/primitives/src/log.rs deleted file mode 100644 index d359fbe3af..0000000000 --- a/crates/primitives/src/log.rs +++ /dev/null @@ -1,11 +0,0 @@ -use crate::{Address, Bytes, B256}; -use alloc::vec::Vec; -use alloy_rlp::{RlpDecodable, RlpEncodable}; - -#[derive(Clone, Debug, Default, PartialEq, Eq, Hash, RlpDecodable, RlpEncodable)] -#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] -pub struct Log { - pub address: Address, - pub topics: Vec, - pub data: Bytes, -} diff --git a/crates/revm/src/evm.rs b/crates/revm/src/evm.rs index 521c754242..ce0dd8d453 100644 --- a/crates/revm/src/evm.rs +++ b/crates/revm/src/evm.rs @@ -7,8 +7,8 @@ use crate::{ SelfDestructResult, SharedMemory, }, primitives::{ - specification::SpecId, Address, Bytecode, Bytes, EVMError, EVMResult, Env, ExecutionResult, - Log, Output, ResultAndState, TransactTo, B256, U256, + specification::SpecId, Address, Bytecode, EVMError, EVMResult, Env, ExecutionResult, Log, + Output, ResultAndState, TransactTo, B256, U256, }, CallStackFrame, Context, FrameOrResult, }; @@ -343,12 +343,8 @@ impl Host for Evm<'_, EXT, DB> { self.context.evm.tstore(address, index, value) } - fn log(&mut self, address: Address, topics: Vec, data: Bytes) { - self.context.evm.journaled_state.log(Log { - address, - topics, - data, - }); + fn log(&mut self, log: Log) { + self.context.evm.journaled_state.log(log); } fn selfdestruct(&mut self, address: Address, target: Address) -> Option {