Skip to content

Commit

Permalink
Remove stack_top from edr_napi::trace::TracingStep
Browse files Browse the repository at this point in the history
  • Loading branch information
agostbiro committed May 10, 2024
1 parent 5c78cf7 commit e683f4e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
6 changes: 4 additions & 2 deletions .changeset/warm-glasses-prove.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
---
"@nomicfoundation/edr": patch
"@nomicfoundation/edr": minor
---

Added verbose tracing for hardhat-tracer
Added verbose tracing for hardhat-tracer. Breaking change: The `stack_top`
property of `edr_napi::trace::TracingStep` was removed and `stack` was added
instead. Please see the documentation of the struct for details.
24 changes: 13 additions & 11 deletions crates/edr_napi/src/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,31 +102,33 @@ pub struct TracingStep {
/// The executed op code
#[napi(readonly)]
pub opcode: String,
/// The top entry on the stack. None if the stack is empty.
/// The entries on the stack. It only contains the top element unless
/// verbose tracing is enabled. The vector is empty if there are no elements
/// on the stack.
#[napi(readonly)]
pub stack_top: Option<BigInt>,
/// The entries on the stack. None if verbose tracing is disabled.
#[napi(readonly)]
pub stack: Option<Vec<BigInt>>,
pub stack: Vec<BigInt>,
/// The memory at the step. None if verbose tracing is disabled.
#[napi(readonly)]
pub memory: Option<Buffer>,
}

impl TracingStep {
pub fn new(step: &edr_evm::trace::Step) -> Self {
let stack_top = step.stack.top().map(u256_to_bigint);
let stack = step
.stack
.full()
.map(|stack| stack.iter().map(u256_to_bigint).collect());
let stack = step.stack.full().map_or_else(
|| {
step.stack
.top()
.map(u256_to_bigint)
.map_or_else(Vec::default, |top| vec![top])
},
|stack| stack.iter().map(u256_to_bigint).collect(),
);
let memory = step.memory.as_ref().cloned().map(Buffer::from);

Self {
depth: step.depth as u8,
pc: BigInt::from(step.pc),
opcode: OpCode::name_by_op(step.opcode).to_string(),
stack_top,
stack,
memory,
}
Expand Down

0 comments on commit e683f4e

Please sign in to comment.