Skip to content

Commit 4a2f6fb

Browse files
gballetjsign
andauthored
fix: charge stateless gas on jump (#530)
* fix: charge stateless gas on jump Signed-off-by: Guillaume Ballet <[email protected]> * instructions: only add JUMP(I) targets if we are not deploying a contract Signed-off-by: Ignacio Hagopian <[email protected]> --------- Signed-off-by: Guillaume Ballet <[email protected]> Signed-off-by: Ignacio Hagopian <[email protected]> Co-authored-by: Ignacio Hagopian <[email protected]>
1 parent f0d4c32 commit 4a2f6fb

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

core/vm/instructions.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -584,12 +584,14 @@ func opJump(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byt
584584
return nil, errStopToken
585585
}
586586
pos := scope.Stack.pop()
587-
if !scope.Contract.validJumpdest(&pos) {
587+
if interpreter.evm.chainRules.IsEIP4762 && !scope.Contract.IsDeployment {
588588
statelessGas, wanted := interpreter.evm.TxContext.Accesses.TouchCodeChunksRangeAndChargeGas(scope.Contract.CodeAddr[:], pos.Uint64(), 1, uint64(len(scope.Contract.Code)), false, scope.Contract.Gas)
589589
scope.Contract.UseGas(statelessGas)
590590
if statelessGas < wanted {
591591
return nil, ErrOutOfGas
592592
}
593+
}
594+
if !scope.Contract.validJumpdest(&pos) {
593595
return nil, ErrInvalidJump
594596
}
595597
*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
602604
}
603605
pos, cond := scope.Stack.pop(), scope.Stack.pop()
604606
if !cond.IsZero() {
605-
if !scope.Contract.validJumpdest(&pos) {
607+
if interpreter.evm.chainRules.IsEIP4762 && !scope.Contract.IsDeployment {
606608
statelessGas, wanted := interpreter.evm.TxContext.Accesses.TouchCodeChunksRangeAndChargeGas(scope.Contract.CodeAddr[:], pos.Uint64(), 1, uint64(len(scope.Contract.Code)), false, scope.Contract.Gas)
607609
scope.Contract.UseGas(statelessGas)
608610
if statelessGas < wanted {
609611
return nil, ErrOutOfGas
610612
}
613+
}
614+
if !scope.Contract.validJumpdest(&pos) {
611615
return nil, ErrInvalidJump
612616
}
613617
*pc = pos.Uint64() - 1 // pc will be increased by the interpreter loop

0 commit comments

Comments
 (0)