Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support no_std #250

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can use the alloc feature


# js-tracer
boa_engine = { version = "0.20", optional = true }
Expand All @@ -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 = []
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here we should also propagate std to everything

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this isn't required because this is the same as no-default-features

Suggested change
no_std = []

serde = ["dep:serde", "revm/serde"]
js-tracer = ["dep:boa_engine", "dep:boa_gc"]
7 changes: 5 additions & 2 deletions src/access_list.rs
Original file line number Diff line number Diff line change
@@ -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.
///
Expand Down
9 changes: 6 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move to L17

#![doc = include_str!("../README.md")]
#![doc(
html_logo_url = "https://raw.githubusercontent.com/paradigmxyz/reth/main/assets/reth-docs.png",
Expand All @@ -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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move below mods again


/// An inspector implementation for an EIP2930 Accesslist
pub mod access_list;

Expand All @@ -26,5 +31,3 @@ pub mod tracing;

/// An inspector for recording internal transfers.
pub mod transfer;

pub use colorchoice::ColorChoice;
3 changes: 2 additions & 1 deletion src/opcode.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use alloc::string::ToString;
use alloy_primitives::map::HashMap;
use alloy_rpc_types_trace::opcode::OpcodeGas;
use revm::{
interpreter::{
Expand All @@ -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)]
Expand Down
1 change: 1 addition & 0 deletions src/tracing/arena.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use super::types::{CallTrace, CallTraceNode, TraceMemberOrder};
use alloc::{vec, vec::Vec};

/// An arena of recorded traces.
///
Expand Down
12 changes: 6 additions & 6 deletions src/tracing/builder/geth.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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)]
Expand Down
3 changes: 2 additions & 1 deletion src/tracing/builder/parity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
///
Expand Down
2 changes: 1 addition & 1 deletion src/tracing/builder/walker.rs
Original file line number Diff line number Diff line change
@@ -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.
///
Expand Down
5 changes: 2 additions & 3 deletions src/tracing/fourbyte.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@
//! ```
//!
//! See also <https://geth.ethereum.org/docs/developers/evm-tracing/built-in-tracers>

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)]
Expand Down
4 changes: 2 additions & 2 deletions src/tracing/js/bindings.rs
Copy link
Member

@DaniPopes DaniPopes Jan 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please leave JS unchanged, it can never support no_std. It may look like it works because tests pass but that's because you're running on a target that has std, and it is used by dependencies regardless of the no_std status of this crate.

Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -948,7 +948,7 @@ pub(crate) struct JsDb<DB: DatabaseRef>(DB);
impl<DB> DatabaseRef for JsDb<DB>
where
DB: DatabaseRef,
DB::Error: std::fmt::Display,
DB::Error: core::fmt::Display,
{
type Error = String;

Expand Down
4 changes: 2 additions & 2 deletions src/tracing/js/builtins.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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 <https://github.com/peterolson/BigInteger.js>.
pub(crate) const BIG_INT_JS: &str = include_str!("bigint.js");
Expand Down
6 changes: 3 additions & 3 deletions src/tracing/js/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ impl JsInspector {
) -> Result<serde_json::Value, JsInspectorError>
where
DB: DatabaseRef,
<DB as DatabaseRef>::Error: std::fmt::Display,
<DB as DatabaseRef>::Error: core::fmt::Display,
{
let result = self.result(res, env, db)?;
Ok(to_serde_value(result, &mut self.ctx)?)
Expand All @@ -228,7 +228,7 @@ impl JsInspector {
) -> Result<JsValue, JsInspectorError>
where
DB: DatabaseRef,
<DB as DatabaseRef>::Error: std::fmt::Display,
<DB as DatabaseRef>::Error: core::fmt::Display,
{
let ResultAndState { result, state } = res;
let (db, _db_guard) = EvmDbRef::new(&state, db);
Expand Down Expand Up @@ -388,7 +388,7 @@ impl JsInspector {
impl<DB> Inspector<DB> for JsInspector
where
DB: Database + DatabaseRef,
<DB as DatabaseRef>::Error: std::fmt::Display,
<DB as DatabaseRef>::Error: core::fmt::Display,
{
fn step(&mut self, interp: &mut Interpreter, context: &mut EvmContext<DB>) {
if self.step_fn.is_none() {
Expand Down
1 change: 1 addition & 0 deletions src/tracing/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use crate::{
utils::gas_used,
},
};
use alloc::vec::Vec;
use alloy_primitives::{Address, Bytes, Log, B256, U256};
use revm::{
interpreter::{
Expand Down
5 changes: 5 additions & 0 deletions src/tracing/mux.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand Down Expand Up @@ -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}")]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this type works in no-std as long as the serde-json alloc feature is enabled

InvalidConfig(#[from] serde_json::Error),
#[cfg(not(feature = "std"))]
#[error("error deserializing config")]
InvalidConfigNoStd,
}
6 changes: 3 additions & 3 deletions src/tracing/types.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand All @@ -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)]
Expand Down Expand Up @@ -534,8 +534,8 @@ impl From<CallKind> 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())
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/tracing/utils.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand Down
11 changes: 6 additions & 5 deletions src/tracing/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here we should rather feature gate the code that depends on this I assume


const CHEATCODE_ADDRESS: Address = address!("7109709ECfa91a80626fF3989D68f67F5b1DD12D");

Expand Down
1 change: 1 addition & 0 deletions src/transfer.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand Down
Loading