From 9b476e926e0d4ad3a29cd3e3b2a09a56cc4520ab Mon Sep 17 00:00:00 2001 From: Guillaume Ballet <3272758+gballet@users.noreply.github.com> Date: Mon, 6 Jan 2025 17:35:41 +0100 Subject: [PATCH] fix: charge stateless gas on jump Signed-off-by: Guillaume Ballet <3272758+gballet@users.noreply.github.com> --- core/vm/instructions.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/core/vm/instructions.go b/core/vm/instructions.go index 20a05c6cbe0c..f90ceec42167 100644 --- a/core/vm/instructions.go +++ b/core/vm/instructions.go @@ -584,12 +584,14 @@ func opJump(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byt return nil, errStopToken } pos := scope.Stack.pop() - if !scope.Contract.validJumpdest(&pos) { + if interpreter.evm.chainRules.IsEIP4762 { statelessGas, wanted := interpreter.evm.TxContext.Accesses.TouchCodeChunksRangeAndChargeGas(scope.Contract.CodeAddr[:], pos.Uint64(), 1, uint64(len(scope.Contract.Code)), false, scope.Contract.Gas) scope.Contract.UseGas(statelessGas) if statelessGas < wanted { return nil, ErrOutOfGas } + } + if !scope.Contract.validJumpdest(&pos) { return nil, ErrInvalidJump } *pc = pos.Uint64() - 1 // pc will be increased by the interpreter loop @@ -602,12 +604,14 @@ func opJumpi(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]by } pos, cond := scope.Stack.pop(), scope.Stack.pop() if !cond.IsZero() { - if !scope.Contract.validJumpdest(&pos) { + if interpreter.evm.chainRules.IsEIP4762 { statelessGas, wanted := interpreter.evm.TxContext.Accesses.TouchCodeChunksRangeAndChargeGas(scope.Contract.CodeAddr[:], pos.Uint64(), 1, uint64(len(scope.Contract.Code)), false, scope.Contract.Gas) scope.Contract.UseGas(statelessGas) if statelessGas < wanted { return nil, ErrOutOfGas } + } + if !scope.Contract.validJumpdest(&pos) { return nil, ErrInvalidJump } *pc = pos.Uint64() - 1 // pc will be increased by the interpreter loop