engine

package
v0.0.0-...-2935fa7 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2021 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GasSha3          uint64 = 1
	GasGetAccount    uint64 = 1
	GasStorageUpdate uint64 = 1
	GasCreateAccount uint64 = 1

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

	GasEcRecover     uint64 = 1
	GasSha256Word    uint64 = 1
	GasSha256Base    uint64 = 1
	GasRipemd160Word uint64 = 1
	GasRipemd160Base uint64 = 1
	GasExpModWord    uint64 = 1
	GasExpModBase    uint64 = 1
	GasIdentityWord  uint64 = 1
	GasIdentityBase  uint64 = 1
)

Variables

This section is empty.

Functions

func AddressFromName

func AddressFromName(name string) (address crypto.Address)

func Call

func Call(state State, params CallParams, execute func(State, CallParams) ([]byte, error)) ([]byte, error)

Call provides a standard wrapper for implementing Callable.Call with appropriate error handling and event firing.

func CallFromSite

func CallFromSite(st State, dispatcher Dispatcher, site CallParams, target CallParams) ([]byte, error)

func Connect

func Connect(eds ...ExternalDispatcher)

Connect ExternalDispatchers eds to each other so that the underlying engines can mutually call contracts hosted by other dispatchers

func CreateAccount

func CreateAccount(st acmstate.ReaderWriter, address crypto.Address) error

func EnsurePermission

func EnsurePermission(callFrame *CallFrame, address crypto.Address, perm permission.PermFlag) error

func FireCallEvent

func FireCallEvent(callFrame *CallFrame, callErr error, eventSink exec.EventSink, output []byte,
	params CallParams) error

func GetAccount

func GetAccount(st acmstate.Reader, m Maybe, address crypto.Address) *acm.Account

func HasPermission

func HasPermission(st acmstate.Reader, address crypto.Address, perm permission.PermFlag) (bool, error)

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, this function returns false.

func InitChildCode

func InitChildCode(st acmstate.ReaderWriter, address crypto.Address, parent crypto.Address, code []byte) error

func InitEVMCode

func InitEVMCode(st acmstate.ReaderWriter, address crypto.Address, code []byte) error

func InitWASMCode

func InitWASMCode(st acmstate.ReaderWriter, address crypto.Address, code []byte) error

func MustAccount

func MustAccount(st acmstate.Reader, address crypto.Address) (*acm.Account, error)

func MustGetAccount

func MustGetAccount(st acmstate.Reader, m Maybe, address crypto.Address) *acm.Account

Guaranteed to return a non-nil account, if the account does not exist returns a pointer to the zero-value of Account and pushes an error.

func RemoveAccount

func RemoveAccount(st acmstate.ReaderWriter, address crypto.Address) error

func Transfer

func Transfer(st acmstate.ReaderWriter, from, to crypto.Address, amount *big.Int) error

TODO: consider pushing big.Int usage all the way to account balance

func UpdateAccount

func UpdateAccount(st acmstate.ReaderWriter, address crypto.Address, updater func(acc *acm.Account) error) error

func UpdateContractMeta

func UpdateContractMeta(st acmstate.ReaderWriter, metaSt acmstate.MetadataWriter, address crypto.Address, payloadMeta []*payload.ContractMeta) error

func UseGasNegative

func UseGasNegative(gasLeft *big.Int, gasToUse uint64) errors.CodedError

Try to deduct gasToUse from gasLeft. If ok return false, otherwise set err and return true.

Types

type Blockchain

type Blockchain interface {
	LastBlockHeight() uint64
	LastBlockTime() time.Time
	BlockHash(height uint64) ([]byte, error)
	ChainID() string
}

type CallFrame

type CallFrame struct {
	// Cache this State wraps
	*acmstate.Cache
	// contains filtered or unexported fields
}

func NewCallFrame

func NewCallFrame(st acmstate.ReaderWriter, cacheOptions ...acmstate.CacheOption) *CallFrame

Create a new CallFrame to hold state updates at a particular level in the call stack

func (*CallFrame) CallStackDepth

func (st *CallFrame) CallStackDepth() uint64

func (*CallFrame) CreateAccount

func (st *CallFrame) CreateAccount(creator, address crypto.Address) error

func (*CallFrame) NewFrame

func (st *CallFrame) NewFrame(cacheOptions ...acmstate.CacheOption) (*CallFrame, error)

func (*CallFrame) ReadOnly

func (st *CallFrame) ReadOnly() *CallFrame

Put this CallFrame in permanent read-only mode

func (*CallFrame) Sync

func (st *CallFrame) Sync() error

func (*CallFrame) WithMaxCallStackDepth

func (st *CallFrame) WithMaxCallStackDepth(max uint64) *CallFrame

type CallParams

type CallParams struct {
	CallType exec.CallType
	Origin   crypto.Address
	Caller   crypto.Address
	Callee   crypto.Address
	Input    []byte
	Value    big.Int
	Gas      *big.Int
}

type Callable

type Callable interface {
	Call(state State, params CallParams) (output []byte, err error)
}

Effectively a contract, but can either represent a single function or a contract with multiple functions and a selector

type CallableFunc

type CallableFunc func(st State, params CallParams) (output []byte, err error)

func (CallableFunc) Call

func (c CallableFunc) Call(state State, params CallParams) (output []byte, err error)

type Dispatcher

type Dispatcher interface {
	// If this Dispatcher is capable of dispatching this account (e.g. if it has the correct bytecode) then return a
	// Callable that wraps the function, otherwise return nil
	Dispatch(acc *acm.Account) Callable
}

type DispatcherFunc

type DispatcherFunc func(acc *acm.Account) Callable

func (DispatcherFunc) Dispatch

func (d DispatcherFunc) Dispatch(acc *acm.Account) Callable

type Dispatchers

type Dispatchers []Dispatcher

func NewDispatchers

func NewDispatchers(dispatchers ...Dispatcher) Dispatchers

func (Dispatchers) Dispatch

func (ds Dispatchers) Dispatch(acc *acm.Account) Callable

type ExternalDispatcher

type ExternalDispatcher interface {
	Dispatcher
	SetExternals(externals Dispatcher)
}

An ExternalDispatcher is able to Dispatch accounts to external engines as well as Dispatch to itself

type Externals

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

An ExternalDispatcher is able to Dispatch accounts to external engines as well as Dispatch to itself

func (*Externals) Dispatch

func (ed *Externals) Dispatch(acc *acm.Account) Callable

func (*Externals) SetExternals

func (ed *Externals) SetExternals(externals Dispatcher)

type ExternalsStorage

type ExternalsStorage struct {
}

type Maybe

type Maybe interface {
	PushError(err error) bool
	Error() error
}

type Memory

type Memory interface {
	// Read a value from the memory store starting at offset
	// (index of first byte will equal offset). The value will be returned as a
	// length-bytes byte slice. Returns an error if the memory cannot be read or
	// is not allocated.
	//
	// The value returned should be copy of any underlying memory, not a reference
	// to the underlying store.
	Read(offset, length *big.Int) []byte
	// Write a value to the memory starting at offset (the index of the first byte
	// written will equal offset). The value is provided as bytes to be written
	// consecutively to the memory store. Return an error if the memory cannot be
	// written or allocated.
	Write(offset *big.Int, value []byte)
	// Returns the current capacity of the memory. For dynamically allocating
	// memory this capacity can be used as a write offset that is guaranteed to be
	// unused. Solidity in particular makes this assumption when using MSIZE to
	// get the current allocated memory.
	Capacity() *big.Int
}

Interface for a bounded linear memory indexed by a single *big.Int parameter for each byte in the memory.

func DefaultDynamicMemoryProvider

func DefaultDynamicMemoryProvider(errSink errors.Sink) Memory

func NewDynamicMemory

func NewDynamicMemory(initialCapacity, maximumCapacity uint64, errSink errors.Sink) Memory

Get a new DynamicMemory (note that although we take a maximumCapacity of uint64 we currently limit the maximum to int32 at runtime because we are using a single slice which we cannot guarantee to be indexable above int32 or all validators

type Native

type Native interface {
	Callable
	SetExternals(externals Dispatcher)
	ContractMeta() []*acm.ContractMeta
	FullName() string
	Address() crypto.Address
}

type Natives

type Natives interface {
	ExternalDispatcher
	GetByAddress(address crypto.Address) Native
}

type Options

type Options struct {
	MemoryProvider           func(errors.Sink) Memory
	Natives                  Natives
	Nonce                    []byte
	DebugOpcodes             bool
	DumpTokens               bool
	CallStackMaxDepth        uint64
	DataStackInitialCapacity uint64
	DataStackMaxDepth        uint64
	Logger                   *logging.Logger
}

Options are parameters that are generally stable across a hsc configuration. Defaults will be used for any zero values.

type State

type State struct {
	*CallFrame
	Blockchain
	exec.EventSink
}

type TestBlockchain

type TestBlockchain struct {
	BlockHeight uint64
	BlockTime   time.Time
}

func (*TestBlockchain) BlockHash

func (b *TestBlockchain) BlockHash(height uint64) ([]byte, error)

func (*TestBlockchain) ChainID

func (V *TestBlockchain) ChainID() string

func (*TestBlockchain) LastBlockHeight

func (b *TestBlockchain) LastBlockHeight() uint64

func (*TestBlockchain) LastBlockTime

func (b *TestBlockchain) LastBlockTime() time.Time

Jump to

Keyboard shortcuts

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