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 <fjl@twurst.com> Co-authored-by: Martin Holst Swende <martin@swende.se> Co-authored-by: Péter Szilágyi <peterke@gmail.com>
This commit is contained in:
parent
0a51028819
commit
92da96b7d5
|
@ -889,22 +889,17 @@ func opPush1(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]by
|
||||||
// make push instruction function
|
// make push instruction function
|
||||||
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)
|
var (
|
||||||
|
codeLen = len(scope.Contract.Code)
|
||||||
startMin := codeLen
|
start = min(codeLen, int(*pc+1))
|
||||||
if int(*pc+1) < startMin {
|
end = min(codeLen, start+pushByteSize)
|
||||||
startMin = int(*pc + 1)
|
)
|
||||||
}
|
scope.Stack.push(new(uint256.Int).SetBytes(
|
||||||
|
common.RightPadBytes(
|
||||||
endMin := codeLen
|
scope.Contract.Code[start:end],
|
||||||
if startMin+pushByteSize < endMin {
|
pushByteSize,
|
||||||
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
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue