evm

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2019 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StackLimit uint64 = 1024 // Maximum size of VM stack allowed.
)

Variables

View Source
var PrecompiledContracts = map[common.Uint160]PrecompiledContract{
	common.BytesToUint160([]byte{1}): &ecrecover{},
	common.BytesToUint160([]byte{2}): &sha256hash{},
	common.BytesToUint160([]byte{3}): &ripemd160hash{},
	common.BytesToUint160([]byte{4}): &dataCopy{},
}

Functions

This section is empty.

Types

type Contract

type Contract struct {
	Caller   common.Uint160
	Code     []byte
	CodeHash common.Uint160
	Input    []byte
	// contains filtered or unexported fields
}

func NewContract

func NewContract(caller common.Uint160) *Contract

func (*Contract) GetByte

func (c *Contract) GetByte(n uint64) byte

func (*Contract) GetOp

func (c *Contract) GetOp(n uint64) OpCode

func (*Contract) SetCallCode

func (c *Contract) SetCallCode(code, input []byte, codeHash common.Uint160)

func (*Contract) SetCode

func (c *Contract) SetCode(code []byte, codeHash common.Uint160)

type ExecutionEngine

type ExecutionEngine struct {
	DBCache storage.DBCache

	JumpTable [256]OpExec
	// contains filtered or unexported fields
}

func NewExecutionEngine

func NewExecutionEngine(dbCache storage.DBCache, time *big.Int, blockNumber *big.Int, gas common.Fixed64) *ExecutionEngine

func (*ExecutionEngine) Call

func (e *ExecutionEngine) Call(caller common.Uint160, codeHash common.Uint160, input []byte) (ret []byte, err error)

func (*ExecutionEngine) CallCode

func (e *ExecutionEngine) CallCode(codeHash common.Uint160, input []byte) (ret []byte, err error)

func (*ExecutionEngine) Create

func (e *ExecutionEngine) Create(caller common.Uint160, code []byte) (ret []byte, err error)

func (*ExecutionEngine) DelegateCall

func (e *ExecutionEngine) DelegateCall(codeHash common.Uint160, toAddr common.Uint160, input []byte) (ret []byte, err error)

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) (cpy []byte)

func (*Memory) GetPtr

func (m *Memory) GetPtr(offset, size int64) []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) error

type OpCode

type OpCode byte
const (
	// 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
	EXTCODESIZE
	EXTCODECOPY
)
const (

	// 0x40 range - block operations
	BLOCKHASH 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 (
	LOG0 OpCode = 0xa0 + iota
	LOG1
	LOG2
	LOG3
	LOG4
)
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 (
	PUSH OpCode = 0xb0 + iota
	DUP
	SWAP
)
const (
	// 0xf0 range - closures
	CREATE OpCode = 0xf0 + iota
	CALL
	CALLCODE
	RETURN
	DELEGATECALL

	SELFDESTRUCT = 0xff
)

type OpExec

type OpExec struct {
	Name string
	Exec executionFunc
	// contains filtered or unexported fields
}

func NewOpExecList

func NewOpExecList() [256]OpExec

type PrecompiledContract

type PrecompiledContract interface {
	Run(input []byte) ([]byte, error)
}

type Stack

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

func (*Stack) Back

func (s *Stack) Back(n int) *big.Int

func (*Stack) Data

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

func (*Stack) Print

func (s *Stack) Print()

type StateDB

type StateDB interface {
	GetState(common.Uint160, common.Hash) common.Hash
	SetState(common.Uint160, common.Hash, common.Hash)

	GetCode(common.Uint160) []byte
	SetCode(common.Uint160, []byte)
	GetCodeSize(common.Uint160) int

	GetBalance(common.Uint160) *big.Int
	AddBalance(common.Uint160, *big.Int)

	Suicide(common.Uint160) bool
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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