Skip to content

Commit

Permalink
core/vm: merge opJumpdest to opJump/opJumpi
Browse files Browse the repository at this point in the history
Make opJumpdest to be executed right after opJump/opJumpi:
- Reduce time of unnecessary checking for opJumpdest properties
- Reduce overhead of fail branch predicting from opJump/opJumpi to opJumpdest (since it is always opJumpdest after)
  • Loading branch information
Francesco4203 committed Jul 8, 2024
1 parent 9051408 commit 66ec8c7
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions core/vm/instructions.go
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,13 @@ func opJump(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byt
return nil, ErrInvalidJump
}
*pc = pos.Uint64()

// Next instruction is definitely opJumpDest, which does nothing, so execute it immediately by consuming the gas required and skipping it
interpreter.evm.Context.Counter++
if !scope.Contract.UseGas(params.JumpdestGas) {
return nil, ErrOutOfGas
}
*pc++
return nil, nil
}

Expand All @@ -536,6 +543,13 @@ func opJumpi(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]by
return nil, ErrInvalidJump
}
*pc = pos.Uint64()

// Next instruction is definitely opJumpDest, which does nothing, so execute it immediately by consuming the gas required and skipping it
interpreter.evm.Context.Counter++
if !scope.Contract.UseGas(params.JumpdestGas) {
return nil, ErrOutOfGas
}
*pc++
} else {
*pc++
}
Expand Down

0 comments on commit 66ec8c7

Please sign in to comment.