mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-05-19 22:40:31 +00:00
core/vm: added CALLF,RETF opcodes
This commit is contained in:
parent
866ad956a4
commit
026306218b
1 changed files with 36 additions and 2 deletions
|
|
@ -16,6 +16,13 @@
|
||||||
|
|
||||||
package vm
|
package vm
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/binary"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/ethereum/go-ethereum/common/math"
|
||||||
|
)
|
||||||
|
|
||||||
// opRjump implements the RJUMP opcode.
|
// opRjump implements the RJUMP opcode.
|
||||||
func opRjump(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
func opRjump(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
||||||
var (
|
var (
|
||||||
|
|
@ -61,12 +68,39 @@ func opRjumpv(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]b
|
||||||
|
|
||||||
// opCallf implements the CALLF opcode
|
// opCallf implements the CALLF opcode
|
||||||
func opCallf(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
func opCallf(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
||||||
panic("not implemented")
|
var (
|
||||||
|
code = scope.Contract.CodeAt(scope.CodeSection)
|
||||||
|
idx = binary.BigEndian.Uint16(code[*pc+1:])
|
||||||
|
typ = scope.Contract.Container.types[idx]
|
||||||
|
)
|
||||||
|
if scope.Stack.len()+int(typ.maxStackHeight)-int(typ.inputs) > 1024 {
|
||||||
|
return nil, fmt.Errorf("stack overflow")
|
||||||
|
}
|
||||||
|
if scope.ReturnStack.Len() > 1024 {
|
||||||
|
return nil, fmt.Errorf("return stack overflow")
|
||||||
|
}
|
||||||
|
retCtx := &ReturnContext{
|
||||||
|
Section: scope.CodeSection,
|
||||||
|
Pc: *pc + 3,
|
||||||
|
StackHeight: scope.Stack.len() - int(typ.inputs),
|
||||||
|
}
|
||||||
|
scope.ReturnStack = append(scope.ReturnStack, retCtx)
|
||||||
|
scope.CodeSection = uint64(idx)
|
||||||
|
*pc = uint64(math.MaxUint64)
|
||||||
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// opRetf implements the RETF opcode
|
// opRetf implements the RETF opcode
|
||||||
func opRetf(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
func opRetf(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
||||||
panic("not implemented")
|
retCtx := scope.ReturnStack.Pop()
|
||||||
|
scope.CodeSection = retCtx.Section
|
||||||
|
*pc = retCtx.Pc - 1
|
||||||
|
|
||||||
|
// If returning from top frame, exit cleanly.
|
||||||
|
if scope.ReturnStack.Len() == 0 {
|
||||||
|
return nil, errStopToken
|
||||||
|
}
|
||||||
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// opJumpf implements the JUMPF opcode
|
// opJumpf implements the JUMPF opcode
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue