vm

package
v0.0.0-...-7c12c5a Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2015 License: GPL-2.0, GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GasSha3          int64 = 1
	GasGetAccount    int64 = 1
	GasStorageUpdate int64 = 1

	GasBaseOp  int64 = 0 // TODO: make this 1
	GasStackOp int64 = 1

	GasEcRecover     int64 = 1
	GasSha256Word    int64 = 1
	GasSha256Base    int64 = 1
	GasRipemd160Word int64 = 1
	GasRipemd160Base int64 = 1
	GasIdentityWord  int64 = 1
	GasIdentityBase  int64 = 1
)

Variables

View Source
var (
	ErrUnknownAddress      = errors.New("Unknown address")
	ErrInsufficientBalance = errors.New("Insufficient balance")
	ErrInvalidJumpDest     = errors.New("Invalid jump dest")
	ErrInsufficientGas     = errors.New("Insuffient gas")
	ErrMemoryOutOfBounds   = errors.New("Memory out of bounds")
	ErrCodeOutOfBounds     = errors.New("Code out of bounds")
	ErrInputOutOfBounds    = errors.New("Input out of bounds")
	ErrCallStackOverflow   = errors.New("Call stack overflow")
	ErrCallStackUnderflow  = errors.New("Call stack underflow")
	ErrDataStackOverflow   = errors.New("Data stack overflow")
	ErrDataStackUnderflow  = errors.New("Data stack underflow")
	ErrInvalidContract     = errors.New("Invalid contract")
)

Functions

func AnalyzeJumpDests

func AnalyzeJumpDests(code []byte) (dests *set.Set)

func HasPermission

func HasPermission(appState AppState, acc *Account, perm ptypes.PermFlag) bool

CONTRACT: it is the duty of the contract writer to call known permissions we do not convey if a permission is not set (unlike in state/execution, where we guarantee HasPermission is called on known permissions and panics else) If the perm is not defined in the acc nor set by default in GlobalPermissions, prints a log warning and returns false.

func RegisterNativeContract

func RegisterNativeContract(addr Word256, fn NativeContract) bool

func RegisteredNativeContract

func RegisteredNativeContract(addr Word256) bool

func S256

func S256(x *big.Int) *big.Int

func SetDebug

func SetDebug(d bool)

func U256

func U256(x *big.Int) *big.Int

func ValidPermN

func ValidPermN(n ptypes.PermFlag) bool

Checks if a permission flag is valid (a known base chain or snative permission)

Types

type Account

type Account struct {
	Address Word256
	Balance int64
	Code    []byte
	Nonce   int64
	Other   interface{} // For holding all other data.

	Permissions ptypes.AccountPermissions
}

func (*Account) String

func (acc *Account) String() string

type AppState

type AppState interface {

	// Accounts
	GetAccount(addr Word256) *Account
	UpdateAccount(*Account)
	RemoveAccount(*Account)
	CreateAccount(*Account) *Account

	// Storage
	GetStorage(Word256, Word256) Word256
	SetStorage(Word256, Word256, Word256) // Setting to Zero is deleting.

}

type Debug

type Debug bool

func (Debug) Printf

func (d Debug) Printf(s string, a ...interface{})

type ErrInvalidPermission

type ErrInvalidPermission struct {
	Address Word256
	SNative string
}

func (ErrInvalidPermission) Error

func (e ErrInvalidPermission) Error() string

type ErrPermission

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

func (ErrPermission) Error

func (err ErrPermission) Error() string

type NativeContract

type NativeContract func(appState AppState, caller *Account, input []byte, gas *int64) (output []byte, err error)

type OpCode

type OpCode byte
const (
	// Op codes
	// 0x0 range - arithmetic ops
	STOP OpCode = iota
	ADD
	MUL
	SUB
	DIV
	SDIV
	MOD
	SMOD
	ADDMOD
	MULMOD
	EXP
	SIGNEXTEND
)
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_DEPRECATED
	EXTCODESIZE
	EXTCODECOPY
)
const (

	// 0x40 range - block operations
	BLOCKHASH OpCode = 0x40 + iota
	COINBASE
	TIMESTAMP
	BLOCKHEIGHT
	DIFFICULTY_DEPRECATED
	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 Params

type Params struct {
	BlockHeight int64
	BlockHash   Word256
	BlockTime   int64
	GasLimit    int64
}

type Stack

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

Not goroutine safe

func NewStack

func NewStack(capacity int, gas *int64, err *error) *Stack

func (*Stack) Dup

func (st *Stack) Dup(n int)

func (*Stack) Len

func (st *Stack) Len() int

func (*Stack) Peek

func (st *Stack) Peek() Word256

Not an opcode, costs no gas.

func (*Stack) Pop

func (st *Stack) Pop() Word256

func (*Stack) Pop64

func (st *Stack) Pop64() int64

func (*Stack) PopBytes

func (st *Stack) PopBytes() []byte

func (*Stack) Print

func (st *Stack) Print(n int)

func (*Stack) Push

func (st *Stack) Push(d Word256)

func (*Stack) Push64

func (st *Stack) Push64(i int64)

func (*Stack) PushBytes

func (st *Stack) PushBytes(bz []byte)

currently only called after Sha3

func (*Stack) Swap

func (st *Stack) Swap(n int)

type VM

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

func NewVM

func NewVM(appState AppState, params Params, origin Word256, txid []byte) *VM

func (*VM) Call

func (vm *VM) Call(caller, callee *Account, code, input []byte, value int64, gas *int64) (output []byte, err error)

CONTRACT appState is aware of caller and callee, so we can just mutate them. CONTRACT code and input are not mutated. CONTRACT returned 'ret' is a new compact slice. value: To be transferred from caller to callee. Refunded upon error. gas: Available gas. No refunds for gas. code: May be nil, since the CALL opcode may be used to send value from contracts to accounts

func (*VM) SetFireable

func (vm *VM) SetFireable(evc events.Fireable)

satisfies events.Eventable

Directories

Path Synopsis
Package sha3 implements the SHA3 hash algorithm (formerly called Keccak) chosen by NIST in 2012.
Package sha3 implements the SHA3 hash algorithm (formerly called Keccak) chosen by NIST in 2012.

Jump to

Keyboard shortcuts

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