vm

package
v0.7.10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 21, 2014 License: LGPL-2.1-or-later Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const MaxCallDepth = 1024

Variables

View Source
var (
	GasStep         = big.NewInt(1)
	GasSha          = big.NewInt(10)
	GasSLoad        = big.NewInt(20)
	GasSStore       = big.NewInt(100)
	GasSStoreRefund = big.NewInt(100)
	GasBalance      = big.NewInt(20)
	GasCreate       = big.NewInt(100)
	GasCall         = big.NewInt(20)
	GasCreateByte   = big.NewInt(5)
	GasSha3Byte     = big.NewInt(10)
	GasSha256Byte   = big.NewInt(50)
	GasRipemdByte   = big.NewInt(50)
	GasMemory       = big.NewInt(1)
	GasData         = big.NewInt(5)
	GasTx           = big.NewInt(500)
	GasLog          = big.NewInt(32)
	GasSha256       = big.NewInt(50)
	GasRipemd       = big.NewInt(50)
	GasEcrecover    = big.NewInt(500)

	Pow256 = ethutil.BigPow(2, 256)

	LogTyPretty byte = 0x1
	LogTyDiff   byte = 0x2

	U256 = ethutil.U256
	S256 = ethutil.S256
)
View Source
var Precompiled = map[string]*PrecompiledAccount{
	string(ethutil.LeftPadBytes([]byte{1}, 20)): &PrecompiledAccount{func(l int) *big.Int {
		return GasEcrecover
	}, ecrecoverFunc},
	string(ethutil.LeftPadBytes([]byte{2}, 20)): &PrecompiledAccount{func(l int) *big.Int {
		n := big.NewInt(int64(l+31)/32 + 1)
		n.Mul(n, GasSha256)
		return n
	}, sha256Func},
	string(ethutil.LeftPadBytes([]byte{3}, 20)): &PrecompiledAccount{func(l int) *big.Int {
		n := big.NewInt(int64(l+31)/32 + 1)
		n.Mul(n, GasRipemd)
		return n
	}, ripemd160Func},
}

Functions

func Disassemble

func Disassemble(script []byte) (asm []string)

func IsDepthErr

func IsDepthErr(err error) bool

func IsOOGErr

func IsOOGErr(err error) bool

func IsStack

func IsStack(err error) bool

func Transfer

func Transfer(from, to Account, amount *big.Int) error

generic transfer method

Types

type Account

type Account interface {
	SubBalance(amount *big.Int)
	AddBalance(amount *big.Int)
	Balance() *big.Int
}

type Address

type Address interface {
	Call(in []byte) []byte
}

type Closure

type Closure struct {
	Code []byte

	Gas, UsedGas, Price *big.Int

	Args []byte
	// contains filtered or unexported fields
}

func NewClosure

func NewClosure(msg *state.Message, caller ClosureRef, object ClosureRef, code []byte, gas, price *big.Int) *Closure

Create a new closure for the given data items

func (*Closure) Address

func (c *Closure) Address() []byte

* Set / Get

func (*Closure) GetByte

func (c *Closure) GetByte(x uint64) byte

func (*Closure) GetBytes

func (c *Closure) GetBytes(x, y int) []byte

func (*Closure) GetOp

func (c *Closure) GetOp(x uint64) OpCode

func (*Closure) GetRangeValue

func (c *Closure) GetRangeValue(x, y uint64) []byte

func (*Closure) Return

func (c *Closure) Return(ret []byte) []byte

func (*Closure) ReturnGas

func (c *Closure) ReturnGas(gas, price *big.Int)

Implement the caller interface

func (*Closure) SetCode

func (self *Closure) SetCode(code []byte)

func (*Closure) UseGas

func (c *Closure) UseGas(gas *big.Int) bool

* Gas functions

type ClosureRef

type ClosureRef interface {
	ReturnGas(*big.Int, *big.Int)
	Address() []byte
	SetCode([]byte)
}

type DebugVm

type DebugVm struct {

	// Debugging
	Dbg Debugger

	BreakPoints []int64
	Stepping    bool
	Fn          string

	Recoverable bool
	// contains filtered or unexported fields
}

func NewDebugVm

func NewDebugVm(env Environment) *DebugVm

func (*DebugVm) Endl

func (self *DebugVm) Endl() VirtualMachine

func (*DebugVm) Env

func (self *DebugVm) Env() Environment

func (*DebugVm) Printf

func (self *DebugVm) Printf(format string, v ...interface{}) VirtualMachine

func (*DebugVm) Run

func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *big.Int, callData []byte) (ret []byte, err error)

func (*DebugVm) RunPrecompiled

func (self *DebugVm) RunPrecompiled(p *PrecompiledAccount, callData []byte, closure *Closure) (ret []byte, err error)

type Debugger

type Debugger interface {
	BreakHook(step int, op OpCode, mem *Memory, stack *Stack, object *state.StateObject) bool
	StepHook(step int, op OpCode, mem *Memory, stack *Stack, object *state.StateObject) bool
	BreakPoints() []int64
	SetCode(byteCode []byte)
}

type DepthError

type DepthError struct{}

func (DepthError) Error

func (self DepthError) Error() string

type Environment

type Environment interface {
	State() *state.StateDB

	Origin() []byte
	BlockNumber() *big.Int
	PrevHash() []byte
	Coinbase() []byte
	Time() int64
	Difficulty() *big.Int
	BlockHash() []byte
	GasLimit() *big.Int
	Transfer(from, to Account, amount *big.Int) error
	AddLog(state.Log)

	Depth() int
	SetDepth(i int)

	Call(me ClosureRef, addr, data []byte, gas, price, value *big.Int) ([]byte, error)
	CallCode(me ClosureRef, addr, data []byte, gas, price, value *big.Int) ([]byte, error)
	Create(me ClosureRef, addr, data []byte, gas, price, value *big.Int) ([]byte, error, ClosureRef)
}

type Log

type Log struct {
	// contains filtered or unexported fields
}

func (*Log) Address

func (self *Log) Address() []byte

func (*Log) Data

func (self *Log) Data() []byte

func (*Log) RlpData

func (self *Log) RlpData() interface{}

func (*Log) String

func (self *Log) String() string

func (*Log) Topics

func (self *Log) Topics() [][]byte

type Memory

type Memory struct {
	// contains filtered or unexported fields
}

func NewMemory

func NewMemory() *Memory

func (*Memory) Data

func (m *Memory) Data() []byte

func (*Memory) Get

func (m *Memory) Get(offset, size int64) []byte

func (*Memory) Geti

func (self *Memory) Geti(offset, size int64) (cpy []byte)

func (*Memory) Len

func (m *Memory) Len() int

func (*Memory) Print

func (m *Memory) Print()

func (*Memory) Resize

func (m *Memory) Resize(size uint64)

func (*Memory) Set

func (m *Memory) Set(offset, size uint64, value []byte)

type Object

type Object interface {
	GetStorage(key *big.Int) *ethutil.Value
	SetStorage(key *big.Int, value *ethutil.Value)
}

type OpCode

type OpCode byte
const (
	// 0x0 range - arithmetic ops
	STOP OpCode = iota
	ADD
	MUL
	SUB
	DIV
	SDIV
	MOD
	SMOD
	ADDMOD
	MULMOD
	EXP
	SIGNEXTEND
)

Op codes

const (
	LT OpCode = iota + 0x10
	GT
	SLT
	SGT
	EQ
	ISZERO
	AND
	OR
	XOR
	NOT
	BYTE

	SHA3 = 0x20
)
const (
	// 0x30 range - closure state
	ADDRESS OpCode = 0x30 + iota
	BALANCE
	ORIGIN
	CALLER
	CALLVALUE
	CALLDATALOAD
	CALLDATASIZE
	CALLDATACOPY
	CODESIZE
	CODECOPY
	GASPRICE
	EXTCODESIZE
	EXTCODECOPY
)
const (

	// 0x40 range - block operations
	PREVHASH OpCode = 0x40 + iota
	COINBASE
	TIMESTAMP
	NUMBER
	DIFFICULTY
	GASLIMIT
)
const (
	// 0x50 range - 'storage' and execution
	POP OpCode = 0x50 + iota
	MLOAD
	MSTORE
	MSTORE8
	SLOAD
	SSTORE
	JUMP
	JUMPI
	PC
	MSIZE
	GAS
	JUMPDEST
)
const (
	// 0x60 range
	PUSH1 OpCode = 0x60 + iota
	PUSH2
	PUSH3
	PUSH4
	PUSH5
	PUSH6
	PUSH7
	PUSH8
	PUSH9
	PUSH10
	PUSH11
	PUSH12
	PUSH13
	PUSH14
	PUSH15
	PUSH16
	PUSH17
	PUSH18
	PUSH19
	PUSH20
	PUSH21
	PUSH22
	PUSH23
	PUSH24
	PUSH25
	PUSH26
	PUSH27
	PUSH28
	PUSH29
	PUSH30
	PUSH31
	PUSH32
	DUP1
	DUP2
	DUP3
	DUP4
	DUP5
	DUP6
	DUP7
	DUP8
	DUP9
	DUP10
	DUP11
	DUP12
	DUP13
	DUP14
	DUP15
	DUP16
	SWAP1
	SWAP2
	SWAP3
	SWAP4
	SWAP5
	SWAP6
	SWAP7
	SWAP8
	SWAP9
	SWAP10
	SWAP11
	SWAP12
	SWAP13
	SWAP14
	SWAP15
	SWAP16
)
const (
	LOG0 OpCode = 0xa0 + iota
	LOG1
	LOG2
	LOG3
	LOG4
)
const (
	// 0xf0 range - closures
	CREATE OpCode = 0xf0 + iota
	CALL
	CALLCODE
	RETURN

	// 0x70 range - other
	SUICIDE = 0xff
)

func (OpCode) String

func (o OpCode) String() string

type OpType

type OpType int

type OutOfGasError

type OutOfGasError struct {
	// contains filtered or unexported fields
}

func OOG

func OOG(req, has *big.Int) OutOfGasError

func (OutOfGasError) Error

func (self OutOfGasError) Error() string

type PrecompiledAccount

type PrecompiledAccount struct {
	Gas func(l int) *big.Int
	// contains filtered or unexported fields
}

func (PrecompiledAccount) Call

func (self PrecompiledAccount) Call(in []byte) []byte

type Stack

type Stack struct {
	// contains filtered or unexported fields
}

Simple push/pop stack mechanism

func NewStack

func NewStack() *Stack

func (*Stack) Data

func (st *Stack) Data() []*big.Int

func (*Stack) Dupn

func (st *Stack) Dupn(n int) *big.Int

func (*Stack) Get

func (st *Stack) Get(amount *big.Int) []*big.Int

func (*Stack) Len

func (st *Stack) Len() int

func (*Stack) Peek

func (st *Stack) Peek() *big.Int

func (*Stack) Peekn

func (st *Stack) Peekn() (*big.Int, *big.Int)

func (*Stack) Pop

func (st *Stack) Pop() *big.Int

func (*Stack) Popn

func (st *Stack) Popn() (*big.Int, *big.Int)

func (*Stack) Print

func (st *Stack) Print()

func (*Stack) Push

func (st *Stack) Push(d *big.Int)

func (*Stack) Swapn

func (st *Stack) Swapn(n int) (*big.Int, *big.Int)

type StackError

type StackError struct {
	// contains filtered or unexported fields
}

func StackErr

func StackErr(req, has int) StackError

func (StackError) Error

func (self StackError) Error() string

type TxCallback

type TxCallback func(opType OpType) bool

type Type

type Type int
const (
	StandardVmTy Type = iota
	DebugVmTy

	MaxVmTy
)

type VirtualMachine

type VirtualMachine interface {
	Env() Environment
	Run(me, caller ClosureRef, code []byte, value, gas, price *big.Int, data []byte) ([]byte, error)
	Printf(string, ...interface{}) VirtualMachine
	Endl() VirtualMachine
}

func New

func New(env Environment, typ Type) VirtualMachine

type Vm

type Vm struct {
	// contains filtered or unexported fields
}

func (*Vm) Depth

func (self *Vm) Depth() int

func (*Vm) Endl

func (self *Vm) Endl() VirtualMachine

func (*Vm) Env

func (self *Vm) Env() Environment

func (*Vm) Printf

func (self *Vm) Printf(format string, v ...interface{}) VirtualMachine

func (*Vm) Run

func (self *Vm) Run(me, caller ClosureRef, code []byte, value, gas, price *big.Int, data []byte) (ret []byte, err error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL