core/vm: speed up push1, push2

This commit is contained in:
MariusVanDerWijden 2025-05-08 11:45:21 +02:00
parent 1e101b39fd
commit 8125479ad8

View file

@ -955,13 +955,13 @@ func makeLog(size int) executionFunc {
func opPush1(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
var (
codeLen = uint64(len(scope.Contract.Code))
integer = new(uint256.Int)
elem = scope.Stack.get()
)
*pc += 1
if *pc < codeLen {
scope.Stack.push(integer.SetUint64(uint64(scope.Contract.Code[*pc])))
elem.SetUint64(uint64(scope.Contract.Code[*pc]))
} else {
scope.Stack.push(integer.Clear())
elem.Clear()
}
return nil, nil
}
@ -970,14 +970,14 @@ func opPush1(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]by
func opPush2(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
var (
codeLen = uint64(len(scope.Contract.Code))
integer = new(uint256.Int)
elem = scope.Stack.get()
)
if *pc+2 < codeLen {
scope.Stack.push(integer.SetBytes2(scope.Contract.Code[*pc+1 : *pc+3]))
elem.SetBytes2(scope.Contract.Code[*pc+1 : *pc+3])
} else if *pc+1 < codeLen {
scope.Stack.push(integer.SetUint64(uint64(scope.Contract.Code[*pc+1]) << 8))
elem.SetUint64(uint64(scope.Contract.Code[*pc+1]) << 8)
} else {
scope.Stack.push(integer.Clear())
elem.Clear()
}
*pc += 2
return nil, nil