From 66ec8c71cc994b9e8423392ab437355d91dfe388 Mon Sep 17 00:00:00 2001 From: Francesco4203 Date: Mon, 8 Jul 2024 17:56:17 +0700 Subject: [PATCH] core/vm: merge opJumpdest to opJump/opJumpi 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) --- core/vm/instructions.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/core/vm/instructions.go b/core/vm/instructions.go index 0ead197a10..e618132785 100644 --- a/core/vm/instructions.go +++ b/core/vm/instructions.go @@ -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 } @@ -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++ }