Skip to content

Commit

Permalink
core/vm: refactor push-functions to use min builtin (ethereum#29515)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
4 people authored Apr 16, 2024
1 parent 0a51028 commit 92da96b
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions core/vm/instructions.go
Original file line number Diff line number Diff line change
Expand Up @@ -889,22 +889,17 @@ func opPush1(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]by
// make push instruction function
func makePush(size uint64, pushByteSize int) executionFunc {
return func(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
codeLen := len(scope.Contract.Code)

startMin := codeLen
if int(*pc+1) < startMin {
startMin = int(*pc + 1)
}

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)))

var (
codeLen = len(scope.Contract.Code)
start = min(codeLen, int(*pc+1))
end = min(codeLen, start+pushByteSize)
)
scope.Stack.push(new(uint256.Int).SetBytes(
common.RightPadBytes(
scope.Contract.Code[start:end],
pushByteSize,
)),
)
*pc += size
return nil, nil
}
Expand Down

0 comments on commit 92da96b

Please sign in to comment.