Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ classifiers = [
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
]
dynamic = ["version"]

[tool.poetry]
name = "pyrevm"
Expand Down
17 changes: 14 additions & 3 deletions src/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ pub struct EVM {
#[pyo3(get, set)]
tracing: bool,

/// whether to include memory field in the tracing output
#[pyo3(get, set)]
with_memory: bool,

/// Checkpoints for reverting state
/// We cannot use Revm's checkpointing mechanism as it is not serializable
checkpoints: HashMap<JournalCheckpoint, RevmCheckpoint>,
Expand All @@ -52,14 +56,15 @@ pub struct EVM {
impl EVM {
/// Create a new EVM instance.
#[new]
#[pyo3(signature = (env = None, fork_url = None, fork_block = None, gas_limit = 18446744073709551615, tracing = false, spec_id = "LATEST")
#[pyo3(signature = (env = None, fork_url = None, fork_block = None, gas_limit = 18446744073709551615, tracing = false, with_memory = false, spec_id = "LATEST")
)]
fn new(
env: Option<Env>,
fork_url: Option<&str>,
fork_block: Option<&str>,
gas_limit: u64,
tracing: bool,
with_memory: bool,
spec_id: &str,
) -> PyResult<Self> {
let spec = SpecId::from(spec_id);
Expand All @@ -74,6 +79,7 @@ impl EVM {
gas_limit: U256::from(gas_limit),
handler_cfg: HandlerCfg::new(spec),
tracing,
with_memory,
checkpoints: HashMap::new(),
result: None,
})
Expand Down Expand Up @@ -398,8 +404,13 @@ impl EVM {
self.context.env = Box::new(env);
let evm_context: EvmContext<DB> =
replace(&mut self.context, EvmContext::new(DB::new_memory()));
let (result, evm_context) =
call_evm(evm_context, self.handler_cfg, self.tracing, is_static);
let (result, evm_context) = call_evm(
evm_context,
self.handler_cfg,
self.tracing,
self.with_memory,
is_static,
);
self.context = evm_context;
self.result = result.as_ref().ok().cloned();
result
Expand Down
10 changes: 9 additions & 1 deletion src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,18 @@ pub(crate) fn call_evm(
evm_context: EvmContext<DB>,
handler_cfg: HandlerCfg,
tracing: bool,
with_memory: bool,
is_static: bool,
) -> (PyResult<ExecutionResult>, EvmContext<DB>) {
if tracing {
let tracer = TracerEip3155::new(Box::new(crate::pystdout::PySysStdout {}));
let tracer = {
let tracer = TracerEip3155::new(Box::new(crate::pystdout::PySysStdout {}));
if with_memory {
tracer.with_memory()
} else {
tracer
}
};
let mut evm = Evm::builder()
.with_context_with_handler_cfg(ContextWithHandlerCfg {
cfg: handler_cfg,
Expand Down