From fd1093e30a7b608638bc13b3674120a52f078172 Mon Sep 17 00:00:00 2001 From: steven Date: Sun, 29 Dec 2024 18:59:58 -0600 Subject: [PATCH 1/5] feat: support no_std --- Cargo.toml | 19 +++++++++++-------- src/access_list.rs | 7 +++++-- src/lib.rs | 9 ++++++--- src/opcode.rs | 3 ++- src/tracing/arena.rs | 1 + src/tracing/builder/geth.rs | 12 ++++++------ src/tracing/builder/parity.rs | 3 ++- src/tracing/builder/walker.rs | 2 +- src/tracing/fourbyte.rs | 5 ++--- src/tracing/js/bindings.rs | 4 ++-- src/tracing/js/builtins.rs | 4 ++-- src/tracing/js/mod.rs | 6 +++--- src/tracing/mod.rs | 1 + src/tracing/mux.rs | 5 +++++ src/tracing/types.rs | 6 +++--- src/tracing/utils.rs | 2 +- src/tracing/writer.rs | 11 ++++++----- src/transfer.rs | 1 + 18 files changed, 60 insertions(+), 41 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c021afd2..d7ca68a6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,19 +30,19 @@ clippy.lint_groups_priority = "allow" [dependencies] # eth -alloy-rpc-types-eth = "0.8" -alloy-rpc-types-trace = "0.8" -alloy-sol-types = "0.8" -alloy-primitives = { version = "0.8", features = ["map"] } +alloy-rpc-types-eth = { version = "0.8", default-features = false } +alloy-rpc-types-trace = {version = "0.8", default-features = false } +alloy-sol-types = {version = "0.8", default-features = false } +alloy-primitives = { version = "0.8", features = ["map"], default-features = false } revm = { version = "18.0.0", default-features = false, features = ["std"] } -anstyle = "1.0" -colorchoice = "1.0" -thiserror = "2.0" +anstyle = { version = "1.0", optional = true } +colorchoice = { version = "1.0", optional = true } +thiserror = { version = "2.0", default-features = false } # serde serde = { version = "1", optional = true, features = ["derive"] } -serde_json = "1.0" +serde_json = { version = "1.0", optional = true } # js-tracer boa_engine = { version = "0.20", optional = true } @@ -52,5 +52,8 @@ boa_gc = { version = "0.20", optional = true } snapbox = { version = "0.6", features = ["term-svg"] } [features] +default = ["std"] +std = ["anstyle", "colorchoice", "serde_json"] +no_std = [] serde = ["dep:serde", "revm/serde"] js-tracer = ["dep:boa_engine", "dep:boa_gc"] diff --git a/src/access_list.rs b/src/access_list.rs index de86ad68..7f39d56d 100644 --- a/src/access_list.rs +++ b/src/access_list.rs @@ -1,10 +1,13 @@ -use alloy_primitives::{Address, B256}; +use alloc::collections::BTreeSet; +use alloy_primitives::{ + map::{HashMap, HashSet}, + Address, B256, +}; use alloy_rpc_types_eth::{AccessList, AccessListItem}; use revm::{ interpreter::{opcode, Interpreter}, Database, EvmContext, Inspector, }; -use std::collections::{BTreeSet, HashMap, HashSet}; /// An [Inspector] that collects touched accounts and storage slots. /// diff --git a/src/lib.rs b/src/lib.rs index 2646036d..db553c39 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,7 +4,7 @@ //! //! - `js-tracer`: Enables a JavaScript tracer implementation. This pulls in extra dependencies //! (such as `boa`, `tokio` and `serde_json`). - +#![cfg_attr(not(feature = "std"), no_std)] #![doc = include_str!("../README.md")] #![doc( html_logo_url = "https://raw.githubusercontent.com/paradigmxyz/reth/main/assets/reth-docs.png", @@ -15,6 +15,11 @@ #![deny(unused_must_use, rust_2018_idioms)] #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] +extern crate alloc; + +#[cfg(feature = "std")] +pub use colorchoice::ColorChoice; + /// An inspector implementation for an EIP2930 Accesslist pub mod access_list; @@ -26,5 +31,3 @@ pub mod tracing; /// An inspector for recording internal transfers. pub mod transfer; - -pub use colorchoice::ColorChoice; diff --git a/src/opcode.rs b/src/opcode.rs index 59de9984..1337af0d 100644 --- a/src/opcode.rs +++ b/src/opcode.rs @@ -1,3 +1,5 @@ +use alloc::string::ToString; +use alloy_primitives::map::HashMap; use alloy_rpc_types_trace::opcode::OpcodeGas; use revm::{ interpreter::{ @@ -6,7 +8,6 @@ use revm::{ }, Database, EvmContext, Inspector, }; -use std::collections::HashMap; /// An Inspector that counts opcodes and measures gas usage per opcode. #[derive(Clone, Debug, Default)] diff --git a/src/tracing/arena.rs b/src/tracing/arena.rs index ebe97f01..7e59d90e 100644 --- a/src/tracing/arena.rs +++ b/src/tracing/arena.rs @@ -1,4 +1,5 @@ use super::types::{CallTrace, CallTraceNode, TraceMemberOrder}; +use alloc::{vec, vec::Vec}; /// An arena of recorded traces. /// diff --git a/src/tracing/builder/geth.rs b/src/tracing/builder/geth.rs index 9e7f1e21..16cd7a2e 100644 --- a/src/tracing/builder/geth.rs +++ b/src/tracing/builder/geth.rs @@ -1,10 +1,14 @@ //! Geth trace builder - use crate::tracing::{ types::{CallTraceNode, CallTraceStepStackItem}, utils::load_account_code, }; -use alloy_primitives::{Address, Bytes, B256, U256}; +use alloc::{ + borrow::Cow, + collections::{BTreeMap, VecDeque}, + vec::Vec, +}; +use alloy_primitives::{map::HashMap, Address, Bytes, B256, U256}; use alloy_rpc_types_trace::geth::{ AccountChangeKind, AccountState, CallConfig, CallFrame, DefaultFrame, DiffMode, GethDefaultTracingOptions, PreStateConfig, PreStateFrame, PreStateMode, StructLog, @@ -13,10 +17,6 @@ use revm::{ db::DatabaseRef, primitives::{EvmState, ResultAndState}, }; -use std::{ - borrow::Cow, - collections::{BTreeMap, HashMap, VecDeque}, -}; /// A type for creating geth style traces #[derive(Clone, Debug)] diff --git a/src/tracing/builder/parity.rs b/src/tracing/builder/parity.rs index 8ee82385..4a872805 100644 --- a/src/tracing/builder/parity.rs +++ b/src/tracing/builder/parity.rs @@ -4,14 +4,15 @@ use crate::tracing::{ utils::load_account_code, TracingInspectorConfig, }; +use alloc::{collections::VecDeque, vec, vec::Vec}; use alloy_primitives::{map::HashSet, Address, U256, U64}; use alloy_rpc_types_eth::TransactionInfo; use alloy_rpc_types_trace::parity::*; +use core::iter::Peekable; use revm::{ db::DatabaseRef, primitives::{Account, ExecutionResult, ResultAndState, SpecId, KECCAK_EMPTY}, }; -use std::{collections::VecDeque, iter::Peekable}; /// A type for creating parity style traces /// diff --git a/src/tracing/builder/walker.rs b/src/tracing/builder/walker.rs index c9022077..aa0503d2 100644 --- a/src/tracing/builder/walker.rs +++ b/src/tracing/builder/walker.rs @@ -1,5 +1,5 @@ use crate::tracing::types::CallTraceNode; -use std::collections::VecDeque; +use alloc::{collections::VecDeque, vec::Vec}; /// Traverses the internal tracing structure breadth-first. /// diff --git a/src/tracing/fourbyte.rs b/src/tracing/fourbyte.rs index ba5b22e6..a6419a44 100644 --- a/src/tracing/fourbyte.rs +++ b/src/tracing/fourbyte.rs @@ -20,14 +20,13 @@ //! ``` //! //! See also - -use alloy_primitives::{hex, Selector}; +use alloc::format; +use alloy_primitives::{hex, map::HashMap, Selector}; use alloy_rpc_types_trace::geth::FourByteFrame; use revm::{ interpreter::{CallInputs, CallOutcome}, Database, EvmContext, Inspector, }; -use std::collections::HashMap; /// Fourbyte tracing inspector that records all function selectors and their calldata sizes. #[derive(Clone, Debug, Default)] diff --git a/src/tracing/js/bindings.rs b/src/tracing/js/bindings.rs index 61162ccc..ec37281e 100644 --- a/src/tracing/js/bindings.rs +++ b/src/tracing/js/bindings.rs @@ -752,7 +752,7 @@ impl EvmDbRef { pub(crate) fn new<'a, 'b, DB>(state: &'a EvmState, db: &'b DB) -> (Self, EvmDbGuard<'a, 'b>) where DB: DatabaseRef, - DB::Error: std::fmt::Display, + DB::Error: core::fmt::Display, { let (state, state_guard) = StateRef::new(state); @@ -948,7 +948,7 @@ pub(crate) struct JsDb(DB); impl DatabaseRef for JsDb where DB: DatabaseRef, - DB::Error: std::fmt::Display, + DB::Error: core::fmt::Display, { type Error = String; diff --git a/src/tracing/js/builtins.rs b/src/tracing/js/builtins.rs index 088ae31a..f89a89a3 100644 --- a/src/tracing/js/builtins.rs +++ b/src/tracing/js/builtins.rs @@ -1,6 +1,7 @@ //! Builtin functions -use alloy_primitives::{hex, Address, FixedBytes, B256, U256}; +use alloc::borrow::Borrow; +use alloy_primitives::{hex, map::HashSet, Address, FixedBytes, B256, U256}; use boa_engine::{ builtins::{array_buffer::ArrayBuffer, typed_array::TypedArray}, js_string, @@ -9,7 +10,6 @@ use boa_engine::{ Context, JsArgs, JsError, JsNativeError, JsResult, JsString, JsValue, NativeFunction, Source, }; use boa_gc::{empty_trace, Finalize, Trace}; -use std::{borrow::Borrow, collections::HashSet}; /// bigIntegerJS is the minified version of . pub(crate) const BIG_INT_JS: &str = include_str!("bigint.js"); diff --git a/src/tracing/js/mod.rs b/src/tracing/js/mod.rs index b9c01516..43c55368 100644 --- a/src/tracing/js/mod.rs +++ b/src/tracing/js/mod.rs @@ -213,7 +213,7 @@ impl JsInspector { ) -> Result where DB: DatabaseRef, - ::Error: std::fmt::Display, + ::Error: core::fmt::Display, { let result = self.result(res, env, db)?; Ok(to_serde_value(result, &mut self.ctx)?) @@ -228,7 +228,7 @@ impl JsInspector { ) -> Result where DB: DatabaseRef, - ::Error: std::fmt::Display, + ::Error: core::fmt::Display, { let ResultAndState { result, state } = res; let (db, _db_guard) = EvmDbRef::new(&state, db); @@ -388,7 +388,7 @@ impl JsInspector { impl Inspector for JsInspector where DB: Database + DatabaseRef, - ::Error: std::fmt::Display, + ::Error: core::fmt::Display, { fn step(&mut self, interp: &mut Interpreter, context: &mut EvmContext) { if self.step_fn.is_none() { diff --git a/src/tracing/mod.rs b/src/tracing/mod.rs index b75fb9bf..99cb5632 100644 --- a/src/tracing/mod.rs +++ b/src/tracing/mod.rs @@ -9,6 +9,7 @@ use crate::{ utils::gas_used, }, }; +use alloc::vec::Vec; use alloy_primitives::{Address, Bytes, Log, B256, U256}; use revm::{ interpreter::{ diff --git a/src/tracing/mux.rs b/src/tracing/mux.rs index 481b0ddf..c55c2be0 100644 --- a/src/tracing/mux.rs +++ b/src/tracing/mux.rs @@ -1,4 +1,5 @@ use crate::tracing::{FourByteInspector, TracingInspector, TracingInspectorConfig}; +use alloc::vec::Vec; use alloy_primitives::{map::HashMap, Address, Log, U256}; use alloy_rpc_types_eth::TransactionInfo; use alloy_rpc_types_trace::geth::{ @@ -322,6 +323,10 @@ pub enum Error { #[error("expected config is missing for tracer '{0:?}'")] MissingConfig(GethDebugBuiltInTracerType), /// Error when deserializing the config + #[cfg(feature = "std")] #[error("error deserializing config: {0}")] InvalidConfig(#[from] serde_json::Error), + #[cfg(not(feature = "std"))] + #[error("error deserializing config")] + InvalidConfigNoStd, } diff --git a/src/tracing/types.rs b/src/tracing/types.rs index e9353b48..6b519137 100644 --- a/src/tracing/types.rs +++ b/src/tracing/types.rs @@ -1,6 +1,7 @@ //! Types for representing call trace items. use crate::tracing::{config::TraceStyle, utils, utils::convert_memory}; +use alloc::{collections::VecDeque, format, string::String, vec::Vec}; pub use alloy_primitives::Log; use alloy_primitives::{Address, Bytes, FixedBytes, LogData, U256}; use alloy_rpc_types_trace::{ @@ -11,7 +12,6 @@ use alloy_rpc_types_trace::{ }, }; use revm::interpreter::{opcode, CallScheme, CreateScheme, InstructionResult, OpCode}; -use std::collections::VecDeque; /// Decoded call data. #[derive(Clone, Debug, Default, PartialEq, Eq)] @@ -534,8 +534,8 @@ impl From for CreationMethod { } } -impl std::fmt::Display for CallKind { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl core::fmt::Display for CallKind { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { f.write_str(self.to_str()) } } diff --git a/src/tracing/utils.rs b/src/tracing/utils.rs index d859a2a4..12c43c57 100644 --- a/src/tracing/utils.rs +++ b/src/tracing/utils.rs @@ -1,5 +1,5 @@ //! Util functions for revm related ops - +use alloc::{string::String, vec::Vec}; use alloy_primitives::{hex, Bytes}; use alloy_sol_types::{ContractError, GenericRevertReason}; use revm::{ diff --git a/src/tracing/writer.rs b/src/tracing/writer.rs index c68ed91d..3ac91abc 100644 --- a/src/tracing/writer.rs +++ b/src/tracing/writer.rs @@ -5,13 +5,14 @@ use super::{ }, CallTraceArena, }; -use alloy_primitives::{address, hex, Address, B256, U256}; +use alloc::{format, string::String, vec::Vec}; +use alloy_primitives::{address, hex, map::HashMap, Address, B256, U256}; +#[cfg(feature = "std")] use anstyle::{AnsiColor, Color, Style}; +#[cfg(feature = "std")] use colorchoice::ColorChoice; -use std::{ - collections::HashMap, - io::{self, Write}, -}; +#[cfg(feature = "std")] +use std::io::{self, Write}; const CHEATCODE_ADDRESS: Address = address!("7109709ECfa91a80626fF3989D68f67F5b1DD12D"); diff --git a/src/transfer.rs b/src/transfer.rs index 834052ad..bab30126 100644 --- a/src/transfer.rs +++ b/src/transfer.rs @@ -1,3 +1,4 @@ +use alloc::{vec, vec::Vec}; use alloy_primitives::{address, b256, Address, Log, LogData, B256, U256}; use alloy_sol_types::SolValue; use revm::{ From b0865c828684868e6a6d928c21a1bf926f1a031a Mon Sep 17 00:00:00 2001 From: steven Date: Sat, 4 Jan 2025 15:42:34 -0600 Subject: [PATCH 2/5] nits --- Cargo.toml | 3 +-- src/lib.rs | 3 ++- src/tracing/builder/geth.rs | 5 +++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e3186ad5..c4eb0c8e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,7 +33,7 @@ clippy.lint_groups_priority = "allow" alloy-rpc-types-eth = "0.9" alloy-rpc-types-trace = "0.9" alloy-sol-types = "0.8" -alloy-primitives = { version = "0.8", features = ["map-hashbrown"] } +alloy-primitives = { version = "0.8", features = ["map"] } revm = { version = "19.0.0", default-features = false, features = ["std"] } anstyle = { version = "1.0", optional = true } @@ -54,6 +54,5 @@ snapbox = { version = "0.6", features = ["term-svg"] } [features] default = ["std"] std = ["alloy-primitives/std", "anstyle/std", "serde/std", "serde_json/std", "revm/std", "thiserror/std"] -no_std = [] serde = ["dep:serde", "revm/serde"] js-tracer = ["dep:boa_engine", "dep:boa_gc"] diff --git a/src/lib.rs b/src/lib.rs index 1425ea7b..074b77a0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,7 +4,7 @@ //! //! - `js-tracer`: Enables a JavaScript tracer implementation. This pulls in extra dependencies //! (such as `boa`, `tokio` and `serde_json`). -#![cfg_attr(not(feature = "std"), no_std)] + #![doc = include_str!("../README.md")] #![doc( html_logo_url = "https://raw.githubusercontent.com/paradigmxyz/reth/main/assets/reth-docs.png", @@ -14,6 +14,7 @@ #![cfg_attr(not(test), warn(unused_crate_dependencies))] #![deny(unused_must_use, rust_2018_idioms)] #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] +#![cfg_attr(not(feature = "std"), no_std)] extern crate alloc; diff --git a/src/tracing/builder/geth.rs b/src/tracing/builder/geth.rs index 16cd7a2e..4b66f659 100644 --- a/src/tracing/builder/geth.rs +++ b/src/tracing/builder/geth.rs @@ -111,7 +111,7 @@ impl<'a> GethTraceBuilder<'a> { let main_trace = &main_trace_node.trace; let mut struct_logs = Vec::new(); - let mut storage = HashMap::new(); + let mut storage = HashMap::default(); self.fill_geth_trace(main_trace_node, &opts, &mut storage, &mut struct_logs); DefaultFrame { @@ -267,7 +267,8 @@ impl<'a> GethTraceBuilder<'a> { ) -> Result { let account_diffs = state.iter().map(|(addr, acc)| (*addr, acc)); let mut state_diff = DiffMode::default(); - let mut account_change_kinds = HashMap::with_capacity(account_diffs.len()); + let mut account_change_kinds = + HashMap::with_capacity_and_hasher(account_diffs.len(), Default::default()); for (addr, changed_acc) in account_diffs { let db_acc = db.basic_ref(addr)?.unwrap_or_default(); From 17e23bacfa9e14c2d2dc4493d0200a2c82bf8813 Mon Sep 17 00:00:00 2001 From: steven Date: Sat, 4 Jan 2025 16:39:01 -0600 Subject: [PATCH 3/5] check --- src/tracing/js/bindings.rs | 14 ++++++++++---- src/tracing/js/builtins.rs | 3 ++- src/tracing/js/mod.rs | 19 ++++++++++++------- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/tracing/js/bindings.rs b/src/tracing/js/bindings.rs index ec37281e..c78c7011 100644 --- a/src/tracing/js/bindings.rs +++ b/src/tracing/js/bindings.rs @@ -8,6 +8,12 @@ use crate::tracing::{ types::CallKind, TransactionContext, }; +use alloc::{ + boxed::Box, + format, + rc::Rc, + string::{String, ToString}, +}; use alloy_primitives::{Address, Bytes, B256, U256}; use boa_engine::{ js_string, @@ -16,6 +22,7 @@ use boa_engine::{ Context, JsArgs, JsError, JsNativeError, JsObject, JsResult, JsValue, }; use boa_gc::{empty_trace, Finalize, Trace}; +use core::cell::RefCell; use revm::{ interpreter::{ opcode::{PUSH0, PUSH32}, @@ -24,7 +31,6 @@ use revm::{ primitives::{AccountInfo, Bytecode, EvmState, KECCAK_EMPTY}, DatabaseRef, }; -use std::{cell::RefCell, rc::Rc}; /// A macro that creates a native function that returns via [JsValue::from] macro_rules! js_value_getter { @@ -99,7 +105,7 @@ impl GuardedNullableGc { // SAFETY: guard enforces that the value is removed from the refcell before it is dropped. #[allow(clippy::missing_transmute_annotations)] - let this = Self { inner: unsafe { std::mem::transmute(inner) } }; + let this = Self { inner: unsafe { core::mem::transmute(inner) } }; (this, guard) } @@ -764,7 +770,7 @@ impl EvmDbRef { // the guard. let db = JsDb(db); let js_db = unsafe { - std::mem::transmute::< + core::mem::transmute::< Box + '_>, Box + 'static>, >(Box::new(db)) @@ -799,7 +805,7 @@ impl EvmDbRef { let acc = self.read_basic(address, ctx)?; let code_hash = acc.map(|acc| acc.code_hash).unwrap_or(KECCAK_EMPTY); if code_hash == KECCAK_EMPTY { - return JsUint8Array::from_iter(std::iter::empty(), ctx); + return JsUint8Array::from_iter(core::iter::empty(), ctx); } let Some(Ok(bytecode)) = self.inner.db.0.with_inner(|db| db.code_by_hash_ref(code_hash)) diff --git a/src/tracing/js/builtins.rs b/src/tracing/js/builtins.rs index f89a89a3..2dff253b 100644 --- a/src/tracing/js/builtins.rs +++ b/src/tracing/js/builtins.rs @@ -1,6 +1,7 @@ //! Builtin functions -use alloc::borrow::Borrow; +use crate::alloc::string::ToString; +use alloc::{borrow::Borrow, format, vec::Vec}; use alloy_primitives::{hex, map::HashSet, Address, FixedBytes, B256, U256}; use boa_engine::{ builtins::{array_buffer::ArrayBuffer, typed_array::TypedArray}, diff --git a/src/tracing/js/mod.rs b/src/tracing/js/mod.rs index 43c55368..20f61d01 100644 --- a/src/tracing/js/mod.rs +++ b/src/tracing/js/mod.rs @@ -1,15 +1,20 @@ //! Javascript inspector -use crate::tracing::{ - js::{ - bindings::{ - CallFrame, Contract, EvmDbRef, FrameResult, JsEvmContext, MemoryRef, StackRef, StepLog, +use crate::{ + alloc::string::ToString, + tracing::{ + js::{ + bindings::{ + CallFrame, Contract, EvmDbRef, FrameResult, JsEvmContext, MemoryRef, StackRef, + StepLog, + }, + builtins::{register_builtins, to_serde_value, PrecompileList}, }, - builtins::{register_builtins, to_serde_value, PrecompileList}, + types::CallKind, + TransactionContext, }, - types::CallKind, - TransactionContext, }; +use alloc::{format, string::String, vec::Vec}; use alloy_primitives::{Address, Bytes, Log, U256}; pub use boa_engine::vm::RuntimeLimits; use boa_engine::{js_string, Context, JsError, JsObject, JsResult, JsValue, Source}; From db94c7deeb9cd2b5bc15fbb408d8bc943e55cc13 Mon Sep 17 00:00:00 2001 From: steven Date: Sat, 4 Jan 2025 20:34:59 -0600 Subject: [PATCH 4/5] revert js changes --- src/tracing/js/bindings.rs | 18 ++++++------------ src/tracing/js/builtins.rs | 5 ++--- src/tracing/js/mod.rs | 25 ++++++++++--------------- 3 files changed, 18 insertions(+), 30 deletions(-) diff --git a/src/tracing/js/bindings.rs b/src/tracing/js/bindings.rs index c78c7011..61162ccc 100644 --- a/src/tracing/js/bindings.rs +++ b/src/tracing/js/bindings.rs @@ -8,12 +8,6 @@ use crate::tracing::{ types::CallKind, TransactionContext, }; -use alloc::{ - boxed::Box, - format, - rc::Rc, - string::{String, ToString}, -}; use alloy_primitives::{Address, Bytes, B256, U256}; use boa_engine::{ js_string, @@ -22,7 +16,6 @@ use boa_engine::{ Context, JsArgs, JsError, JsNativeError, JsObject, JsResult, JsValue, }; use boa_gc::{empty_trace, Finalize, Trace}; -use core::cell::RefCell; use revm::{ interpreter::{ opcode::{PUSH0, PUSH32}, @@ -31,6 +24,7 @@ use revm::{ primitives::{AccountInfo, Bytecode, EvmState, KECCAK_EMPTY}, DatabaseRef, }; +use std::{cell::RefCell, rc::Rc}; /// A macro that creates a native function that returns via [JsValue::from] macro_rules! js_value_getter { @@ -105,7 +99,7 @@ impl GuardedNullableGc { // SAFETY: guard enforces that the value is removed from the refcell before it is dropped. #[allow(clippy::missing_transmute_annotations)] - let this = Self { inner: unsafe { core::mem::transmute(inner) } }; + let this = Self { inner: unsafe { std::mem::transmute(inner) } }; (this, guard) } @@ -758,7 +752,7 @@ impl EvmDbRef { pub(crate) fn new<'a, 'b, DB>(state: &'a EvmState, db: &'b DB) -> (Self, EvmDbGuard<'a, 'b>) where DB: DatabaseRef, - DB::Error: core::fmt::Display, + DB::Error: std::fmt::Display, { let (state, state_guard) = StateRef::new(state); @@ -770,7 +764,7 @@ impl EvmDbRef { // the guard. let db = JsDb(db); let js_db = unsafe { - core::mem::transmute::< + std::mem::transmute::< Box + '_>, Box + 'static>, >(Box::new(db)) @@ -805,7 +799,7 @@ impl EvmDbRef { let acc = self.read_basic(address, ctx)?; let code_hash = acc.map(|acc| acc.code_hash).unwrap_or(KECCAK_EMPTY); if code_hash == KECCAK_EMPTY { - return JsUint8Array::from_iter(core::iter::empty(), ctx); + return JsUint8Array::from_iter(std::iter::empty(), ctx); } let Some(Ok(bytecode)) = self.inner.db.0.with_inner(|db| db.code_by_hash_ref(code_hash)) @@ -954,7 +948,7 @@ pub(crate) struct JsDb(DB); impl DatabaseRef for JsDb where DB: DatabaseRef, - DB::Error: core::fmt::Display, + DB::Error: std::fmt::Display, { type Error = String; diff --git a/src/tracing/js/builtins.rs b/src/tracing/js/builtins.rs index 2dff253b..088ae31a 100644 --- a/src/tracing/js/builtins.rs +++ b/src/tracing/js/builtins.rs @@ -1,8 +1,6 @@ //! Builtin functions -use crate::alloc::string::ToString; -use alloc::{borrow::Borrow, format, vec::Vec}; -use alloy_primitives::{hex, map::HashSet, Address, FixedBytes, B256, U256}; +use alloy_primitives::{hex, Address, FixedBytes, B256, U256}; use boa_engine::{ builtins::{array_buffer::ArrayBuffer, typed_array::TypedArray}, js_string, @@ -11,6 +9,7 @@ use boa_engine::{ Context, JsArgs, JsError, JsNativeError, JsResult, JsString, JsValue, NativeFunction, Source, }; use boa_gc::{empty_trace, Finalize, Trace}; +use std::{borrow::Borrow, collections::HashSet}; /// bigIntegerJS is the minified version of . pub(crate) const BIG_INT_JS: &str = include_str!("bigint.js"); diff --git a/src/tracing/js/mod.rs b/src/tracing/js/mod.rs index 20f61d01..b9c01516 100644 --- a/src/tracing/js/mod.rs +++ b/src/tracing/js/mod.rs @@ -1,20 +1,15 @@ //! Javascript inspector -use crate::{ - alloc::string::ToString, - tracing::{ - js::{ - bindings::{ - CallFrame, Contract, EvmDbRef, FrameResult, JsEvmContext, MemoryRef, StackRef, - StepLog, - }, - builtins::{register_builtins, to_serde_value, PrecompileList}, +use crate::tracing::{ + js::{ + bindings::{ + CallFrame, Contract, EvmDbRef, FrameResult, JsEvmContext, MemoryRef, StackRef, StepLog, }, - types::CallKind, - TransactionContext, + builtins::{register_builtins, to_serde_value, PrecompileList}, }, + types::CallKind, + TransactionContext, }; -use alloc::{format, string::String, vec::Vec}; use alloy_primitives::{Address, Bytes, Log, U256}; pub use boa_engine::vm::RuntimeLimits; use boa_engine::{js_string, Context, JsError, JsObject, JsResult, JsValue, Source}; @@ -218,7 +213,7 @@ impl JsInspector { ) -> Result where DB: DatabaseRef, - ::Error: core::fmt::Display, + ::Error: std::fmt::Display, { let result = self.result(res, env, db)?; Ok(to_serde_value(result, &mut self.ctx)?) @@ -233,7 +228,7 @@ impl JsInspector { ) -> Result where DB: DatabaseRef, - ::Error: core::fmt::Display, + ::Error: std::fmt::Display, { let ResultAndState { result, state } = res; let (db, _db_guard) = EvmDbRef::new(&state, db); @@ -393,7 +388,7 @@ impl JsInspector { impl Inspector for JsInspector where DB: Database + DatabaseRef, - ::Error: core::fmt::Display, + ::Error: std::fmt::Display, { fn step(&mut self, interp: &mut Interpreter, context: &mut EvmContext) { if self.step_fn.is_none() { From 254eab9a310b4a821f99d685886d64627399631f Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Sat, 18 Jan 2025 10:51:47 +0100 Subject: [PATCH 5/5] touchups --- src/tracing/js/bindings.rs | 18 ++++++++++++------ src/tracing/js/builtins.rs | 5 +++-- src/tracing/js/mod.rs | 11 ++++++++--- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/tracing/js/bindings.rs b/src/tracing/js/bindings.rs index 61162ccc..c78c7011 100644 --- a/src/tracing/js/bindings.rs +++ b/src/tracing/js/bindings.rs @@ -8,6 +8,12 @@ use crate::tracing::{ types::CallKind, TransactionContext, }; +use alloc::{ + boxed::Box, + format, + rc::Rc, + string::{String, ToString}, +}; use alloy_primitives::{Address, Bytes, B256, U256}; use boa_engine::{ js_string, @@ -16,6 +22,7 @@ use boa_engine::{ Context, JsArgs, JsError, JsNativeError, JsObject, JsResult, JsValue, }; use boa_gc::{empty_trace, Finalize, Trace}; +use core::cell::RefCell; use revm::{ interpreter::{ opcode::{PUSH0, PUSH32}, @@ -24,7 +31,6 @@ use revm::{ primitives::{AccountInfo, Bytecode, EvmState, KECCAK_EMPTY}, DatabaseRef, }; -use std::{cell::RefCell, rc::Rc}; /// A macro that creates a native function that returns via [JsValue::from] macro_rules! js_value_getter { @@ -99,7 +105,7 @@ impl GuardedNullableGc { // SAFETY: guard enforces that the value is removed from the refcell before it is dropped. #[allow(clippy::missing_transmute_annotations)] - let this = Self { inner: unsafe { std::mem::transmute(inner) } }; + let this = Self { inner: unsafe { core::mem::transmute(inner) } }; (this, guard) } @@ -752,7 +758,7 @@ impl EvmDbRef { pub(crate) fn new<'a, 'b, DB>(state: &'a EvmState, db: &'b DB) -> (Self, EvmDbGuard<'a, 'b>) where DB: DatabaseRef, - DB::Error: std::fmt::Display, + DB::Error: core::fmt::Display, { let (state, state_guard) = StateRef::new(state); @@ -764,7 +770,7 @@ impl EvmDbRef { // the guard. let db = JsDb(db); let js_db = unsafe { - std::mem::transmute::< + core::mem::transmute::< Box + '_>, Box + 'static>, >(Box::new(db)) @@ -799,7 +805,7 @@ impl EvmDbRef { let acc = self.read_basic(address, ctx)?; let code_hash = acc.map(|acc| acc.code_hash).unwrap_or(KECCAK_EMPTY); if code_hash == KECCAK_EMPTY { - return JsUint8Array::from_iter(std::iter::empty(), ctx); + return JsUint8Array::from_iter(core::iter::empty(), ctx); } let Some(Ok(bytecode)) = self.inner.db.0.with_inner(|db| db.code_by_hash_ref(code_hash)) @@ -948,7 +954,7 @@ pub(crate) struct JsDb(DB); impl DatabaseRef for JsDb where DB: DatabaseRef, - DB::Error: std::fmt::Display, + DB::Error: core::fmt::Display, { type Error = String; diff --git a/src/tracing/js/builtins.rs b/src/tracing/js/builtins.rs index 088ae31a..aa8c6593 100644 --- a/src/tracing/js/builtins.rs +++ b/src/tracing/js/builtins.rs @@ -1,6 +1,7 @@ //! Builtin functions -use alloy_primitives::{hex, Address, FixedBytes, B256, U256}; +use alloc::{format, string::ToString, vec::Vec}; +use alloy_primitives::{hex, map::HashSet, Address, FixedBytes, B256, U256}; use boa_engine::{ builtins::{array_buffer::ArrayBuffer, typed_array::TypedArray}, js_string, @@ -9,7 +10,7 @@ use boa_engine::{ Context, JsArgs, JsError, JsNativeError, JsResult, JsString, JsValue, NativeFunction, Source, }; use boa_gc::{empty_trace, Finalize, Trace}; -use std::{borrow::Borrow, collections::HashSet}; +use core::borrow::Borrow; /// bigIntegerJS is the minified version of . pub(crate) const BIG_INT_JS: &str = include_str!("bigint.js"); diff --git a/src/tracing/js/mod.rs b/src/tracing/js/mod.rs index b9c01516..a9ee4223 100644 --- a/src/tracing/js/mod.rs +++ b/src/tracing/js/mod.rs @@ -10,6 +10,11 @@ use crate::tracing::{ types::CallKind, TransactionContext, }; +use alloc::{ + format, + string::{String, ToString}, + vec::Vec, +}; use alloy_primitives::{Address, Bytes, Log, U256}; pub use boa_engine::vm::RuntimeLimits; use boa_engine::{js_string, Context, JsError, JsObject, JsResult, JsValue, Source}; @@ -213,7 +218,7 @@ impl JsInspector { ) -> Result where DB: DatabaseRef, - ::Error: std::fmt::Display, + ::Error: core::fmt::Display, { let result = self.result(res, env, db)?; Ok(to_serde_value(result, &mut self.ctx)?) @@ -228,7 +233,7 @@ impl JsInspector { ) -> Result where DB: DatabaseRef, - ::Error: std::fmt::Display, + ::Error: core::fmt::Display, { let ResultAndState { result, state } = res; let (db, _db_guard) = EvmDbRef::new(&state, db); @@ -388,7 +393,7 @@ impl JsInspector { impl Inspector for JsInspector where DB: Database + DatabaseRef, - ::Error: std::fmt::Display, + ::Error: core::fmt::Display, { fn step(&mut self, interp: &mut Interpreter, context: &mut EvmContext) { if self.step_fn.is_none() {