Skip to content

Commit 92da96b

Browse files
Devon Bearfjlholimankaralabe
authored
core/vm: refactor push-functions to use min builtin (#29515)
* optimize-push * revert push1 change * Update instructions.go * core/vm: go format * core/vm: fix nit --------- Co-authored-by: Felix Lange <[email protected]> Co-authored-by: Martin Holst Swende <[email protected]> Co-authored-by: Péter Szilágyi <[email protected]>
1 parent 0a51028 commit 92da96b

File tree

1 file changed

+11
-16
lines changed

1 file changed

+11
-16
lines changed

core/vm/instructions.go

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -889,22 +889,17 @@ func opPush1(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]by
889889
// make push instruction function
890890
func makePush(size uint64, pushByteSize int) executionFunc {
891891
return func(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
892-
codeLen := len(scope.Contract.Code)
893-
894-
startMin := codeLen
895-
if int(*pc+1) < startMin {
896-
startMin = int(*pc + 1)
897-
}
898-
899-
endMin := codeLen
900-
if startMin+pushByteSize < endMin {
901-
endMin = startMin + pushByteSize
902-
}
903-
904-
integer := new(uint256.Int)
905-
scope.Stack.push(integer.SetBytes(common.RightPadBytes(
906-
scope.Contract.Code[startMin:endMin], pushByteSize)))
907-
892+
var (
893+
codeLen = len(scope.Contract.Code)
894+
start = min(codeLen, int(*pc+1))
895+
end = min(codeLen, start+pushByteSize)
896+
)
897+
scope.Stack.push(new(uint256.Int).SetBytes(
898+
common.RightPadBytes(
899+
scope.Contract.Code[start:end],
900+
pushByteSize,
901+
)),
902+
)
908903
*pc += size
909904
return nil, nil
910905
}

0 commit comments

Comments
 (0)