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 1/2] 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 From f7d80fc7b39cbda8599ae986eacc424911a789a7 Mon Sep 17 00:00:00 2001 From: Ignacio Hagopian Date: Mon, 6 Jan 2025 18:43:56 -0300 Subject: [PATCH 2/2] instructions: only add JUMP(I) targets if we are not deploying a contract Signed-off-by: Ignacio Hagopian --- core/vm/instructions.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/vm/instructions.go b/core/vm/instructions.go index f90ceec42167..6feb77ae8ba3 100644 --- a/core/vm/instructions.go +++ b/core/vm/instructions.go @@ -584,7 +584,7 @@ func opJump(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byt return nil, errStopToken } pos := scope.Stack.pop() - if interpreter.evm.chainRules.IsEIP4762 { + if interpreter.evm.chainRules.IsEIP4762 && !scope.Contract.IsDeployment { 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 { @@ -604,7 +604,7 @@ func opJumpi(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]by } pos, cond := scope.Stack.pop(), scope.Stack.pop() if !cond.IsZero() { - if interpreter.evm.chainRules.IsEIP4762 { + if interpreter.evm.chainRules.IsEIP4762 && !scope.Contract.IsDeployment { 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 {