From e683f4e4648972870ce4bfd01a4d48ffd1f7ac74 Mon Sep 17 00:00:00 2001 From: Agost Biro Date: Fri, 10 May 2024 13:56:07 +0200 Subject: [PATCH] Remove `stack_top` from `edr_napi::trace::TracingStep` --- .changeset/warm-glasses-prove.md | 6 ++++-- crates/edr_napi/src/trace.rs | 24 +++++++++++++----------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/.changeset/warm-glasses-prove.md b/.changeset/warm-glasses-prove.md index 190457c71..c19eb33eb 100644 --- a/.changeset/warm-glasses-prove.md +++ b/.changeset/warm-glasses-prove.md @@ -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. diff --git a/crates/edr_napi/src/trace.rs b/crates/edr_napi/src/trace.rs index 91e8bf0db..11d9959b0 100644 --- a/crates/edr_napi/src/trace.rs +++ b/crates/edr_napi/src/trace.rs @@ -102,12 +102,11 @@ 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, - /// The entries on the stack. None if verbose tracing is disabled. - #[napi(readonly)] - pub stack: Option>, + pub stack: Vec, /// The memory at the step. None if verbose tracing is disabled. #[napi(readonly)] pub memory: Option, @@ -115,18 +114,21 @@ pub struct TracingStep { 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, }