From 8b0d700b4507f889abae28614026047ce42a98f4 Mon Sep 17 00:00:00 2001 From: jangko Date: Tue, 24 May 2022 10:43:31 +0700 Subject: [PATCH] fix EVM stack.[] bug --- nimbus/vm/stack.nim | 2 +- nimbus/vm2/stack.nim | 2 +- tests/test_op_env.nim | 15 +++++++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/nimbus/vm/stack.nim b/nimbus/vm/stack.nim index 2a9de72ea..d6641de05 100644 --- a/nimbus/vm/stack.nim +++ b/nimbus/vm/stack.nim @@ -124,7 +124,7 @@ proc `$`*(stack: Stack): string = &"Stack:\n{values}" proc `[]`*(stack: Stack, i: BackwardsIndex, T: typedesc): T = - # This should be used only for tracer/test/debugging + ensurePop(stack, int(i)) fromStackElement(stack.values[i], result) proc peekInt*(stack: Stack): UInt256 = diff --git a/nimbus/vm2/stack.nim b/nimbus/vm2/stack.nim index 2a9de72ea..d6641de05 100644 --- a/nimbus/vm2/stack.nim +++ b/nimbus/vm2/stack.nim @@ -124,7 +124,7 @@ proc `$`*(stack: Stack): string = &"Stack:\n{values}" proc `[]`*(stack: Stack, i: BackwardsIndex, T: typedesc): T = - # This should be used only for tracer/test/debugging + ensurePop(stack, int(i)) fromStackElement(stack.values[i], result) proc peekInt*(stack: Stack): UInt256 = diff --git a/tests/test_op_env.nim b/tests/test_op_env.nim index 0612141ea..368ba429b 100644 --- a/tests/test_op_env.nim +++ b/tests/test_op_env.nim @@ -8,6 +8,21 @@ proc opEnvMain*() = suite "Environmental Information Opcodes": let (vmState, chainDB) = initDatabase() + assembler: # EVM bug reported in discord + title: "stack's operator [] bug" + code: + PUSH1 "0x0A" + DUP1 + RETURNDATASIZE + MSIZE + ADDRESS + GAS + STATICCALL + CALL + fork: london + success: false + memory: "0x0000000000000000000000000000000000000000000000000000000000000000" + assembler: # CODECOPY OP title: "CODECOPY_1" code: