optimize-push

This commit is contained in:
itsdevbear 2024-04-12 01:28:50 -04:00
parent bd91810462
commit 06ba0c9e1a

View file

@ -875,13 +875,12 @@ func makeLog(size int) executionFunc {
func opPush1(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) { func opPush1(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
var ( var (
codeLen = uint64(len(scope.Contract.Code)) codeLen = uint64(len(scope.Contract.Code))
integer = new(uint256.Int)
) )
*pc += 1 *pc += 1
if *pc < codeLen { if *pc < codeLen {
scope.Stack.push(integer.SetUint64(uint64(scope.Contract.Code[*pc]))) scope.Stack.push(new(uint256.Int).SetUint64(uint64(scope.Contract.Code[*pc])))
} else { } else {
scope.Stack.push(integer.Clear()) scope.Stack.push(new(uint256.Int).Clear())
} }
return nil, nil return nil, nil
} }
@ -890,20 +889,14 @@ func opPush1(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]by
func makePush(size uint64, pushByteSize int) executionFunc { func makePush(size uint64, pushByteSize int) executionFunc {
return func(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) { return func(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
codeLen := len(scope.Contract.Code) codeLen := len(scope.Contract.Code)
startMin := min(codeLen, int(*pc+1))
startMin := codeLen endMin := min(startMin+pushByteSize, codeLen)
if int(*pc+1) < startMin { scope.Stack.push(new(uint256.Int).SetBytes(
startMin = int(*pc + 1) common.RightPadBytes(
} scope.Contract.Code[startMin:endMin],
pushByteSize,
endMin := codeLen )),
if startMin+pushByteSize < endMin { )
endMin = startMin + pushByteSize
}
integer := new(uint256.Int)
scope.Stack.push(integer.SetBytes(common.RightPadBytes(
scope.Contract.Code[startMin:endMin], pushByteSize)))
*pc += size *pc += size
return nil, nil return nil, nil