Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions core/vm/instructions.go
Original file line number Diff line number Diff line change
Expand Up @@ -1216,6 +1216,23 @@ func opPush1(pc *uint64, interpreter *CVMInterpreter, scope *ScopeContext) ([]by
return nil, nil
}

// opPush2 is a specialized version of pushN
func opPush2(pc *uint64, interpreter *CVMInterpreter, scope *ScopeContext) ([]byte, error) {
var (
codeLen = uint64(len(scope.Contract.Code))
integer = new(uint256.Int)
)
if *pc+2 < codeLen {
scope.Stack.push(integer.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))
} else {
scope.Stack.push(integer.Clear())
}
*pc += 2
return nil, nil
}

// make push instruction function
func makePush(size uint64, pushByteSize int) executionFunc {
return func(pc *uint64, interpreter *CVMInterpreter, scope *ScopeContext) ([]byte, error) {
Expand Down
2 changes: 1 addition & 1 deletion core/vm/jump_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ func newFrontierInstructionSet() JumpTable {
validateStack: makeStackFunc(0, 1),
},
PUSH2: {
execute: makePush(2, 2),
execute: opPush2,
gasCost: gasPush,
validateStack: makeStackFunc(0, 1),
},
Expand Down