From cf438d91bdeb14be803e1b35d2c92ba0ce0d24bb Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Wed, 1 Nov 2023 18:46:54 +0100 Subject: [PATCH] fix: peek returns nth element from the top of the stack (#5262) --- crates/revm/revm-inspectors/src/tracing/js/bindings.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/crates/revm/revm-inspectors/src/tracing/js/bindings.rs b/crates/revm/revm-inspectors/src/tracing/js/bindings.rs index 25d4cfc962..fd794570c7 100644 --- a/crates/revm/revm-inspectors/src/tracing/js/bindings.rs +++ b/crates/revm/revm-inspectors/src/tracing/js/bindings.rs @@ -280,6 +280,7 @@ impl StackObj { .length(0) .build(); + // peek returns the nth-from-the-top element of the stack. let peek = FunctionObjectBuilder::new( context, NativeFunction::from_copy_closure_with_captures( @@ -293,6 +294,9 @@ impl StackObj { ), ))) } + // idx is from the top of the stack, so we need to reverse it + // SAFETY: bounds checked above + let idx = len - idx - 1; stack_arr.get(idx as u64, ctx) }, stack_arr,