runtime

package
v1.2.5 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrOutOfGas                 = errors.New("out of gas")
	ErrStackOverflow            = errors.New("stack overflow")
	ErrStackUnderflow           = errors.New("stack underflow")
	ErrNotEnoughFunds           = errors.New("not enough funds")
	ErrInsufficientBalance      = errors.New("insufficient balance for transfer")
	ErrMaxCodeSizeExceeded      = errors.New("evm: max code size exceeded")
	ErrContractAddressCollision = errors.New("contract address collision")
	ErrDepth                    = errors.New("max call depth exceeded")
	ErrExecutionReverted        = errors.New("execution was reverted")
	ErrCodeStoreOutOfGas        = errors.New("contract creation code storage out of gas")
	ErrCodeEmpty                = errors.New("contract code empty")
	ErrStorageReadFailed        = errors.New("storage read failed")
)

Functions

func IsCallType added in v1.1.4

func IsCallType(typ CallType) bool

func IsCreateType added in v1.1.4

func IsCreateType(typ CallType) bool

Types

type CallType

type CallType int
const (
	Call CallType = iota
	CallCode
	DelegateCall
	StaticCall
	Create
	Create2
)

type Contract

type Contract struct {
	Code        []byte
	Type        CallType
	CodeAddress types.Address
	Address     types.Address
	Origin      types.Address
	Caller      types.Address
	Depth       int
	Value       *big.Int
	Input       []byte
	Gas         uint64
	Static      bool
}

Contract is the instance being called

func NewContract

func NewContract(
	depth int,
	origin types.Address,
	from types.Address,
	to types.Address,
	value *big.Int,
	gas uint64,
	code []byte,
) *Contract

func NewContractCall

func NewContractCall(
	depth int,
	origin types.Address,
	from types.Address,
	to types.Address,
	value *big.Int,
	gas uint64,
	code []byte,
	input []byte,
) *Contract

func NewContractCreation

func NewContractCreation(
	depth int,
	origin types.Address,
	from types.Address,
	to types.Address,
	value *big.Int,
	gas uint64,
	code []byte,
) *Contract

type DummyLogger added in v1.1.4

type DummyLogger struct{}

DummyLogger does nothing in state logging

func (*DummyLogger) CaptureEnd added in v1.1.4

func (d *DummyLogger) CaptureEnd(output []byte, gasUsed uint64, t time.Duration, err error)

func (*DummyLogger) CaptureEnter added in v1.1.4

func (d *DummyLogger) CaptureEnter(opCode int, from, to types.Address,
	input []byte, gas uint64, value *big.Int)

func (*DummyLogger) CaptureExit added in v1.1.4

func (d *DummyLogger) CaptureExit(output []byte, gasUsed uint64, err error)

func (*DummyLogger) CaptureFault added in v1.1.4

func (d *DummyLogger) CaptureFault(ctx *ScopeContext, pc uint64, opCode int,
	gas, cost uint64, depth int, err error)

func (*DummyLogger) CaptureStart added in v1.1.4

func (d *DummyLogger) CaptureStart(txn Txn, from, to types.Address, create bool,
	input []byte, gas uint64, value *big.Int)

func (*DummyLogger) CaptureState added in v1.1.4

func (d *DummyLogger) CaptureState(ctx *ScopeContext, pc uint64, opCode int,
	gas, cost uint64, rData []byte, depth int, err error)

type EVMLogger added in v1.1.4

type EVMLogger interface {
	CaptureStart(txn Txn, from, to types.Address, create bool, input []byte, gas uint64, value *big.Int)
	CaptureState(ctx *ScopeContext, pc uint64, opCode int, gas, cost uint64, rData []byte, depth int, err error)
	CaptureEnter(opCode int, from, to types.Address, input []byte, gas uint64, value *big.Int)
	CaptureExit(output []byte, gasUsed uint64, err error)
	CaptureFault(ctx *ScopeContext, pc uint64, opCode int, gas, cost uint64, depth int, err error)
	CaptureEnd(output []byte, gasUsed uint64, t time.Duration, err error)
}

EVMLogger is used to collect execution traces from an EVM transaction execution. CaptureState is called for each step of the VM with the current VM state. Note that reference types are actual VM data structures; make copies if you need to retain them beyond the current call.

func NewDummyLogger added in v1.1.4

func NewDummyLogger() EVMLogger

type ExecutionResult

type ExecutionResult struct {
	ReturnValue []byte // Returned data from the runtime (function result or data supplied with revert opcode)
	GasLeft     uint64 // Total gas left as result of execution
	GasUsed     uint64 // Total gas used as result of execution
	Err         error  // Any error encountered during the execution, listed below
}

ExecutionResult includes all output after executing given evm message no matter the execution itself is successful or not.

func (*ExecutionResult) Failed

func (r *ExecutionResult) Failed() bool

func (*ExecutionResult) Return added in v1.1.4

func (r *ExecutionResult) Return() []byte

Return is a helper function to help caller distinguish between revert reason and function return. Return returns the data after execution if no error occurs.

func (*ExecutionResult) Revert added in v1.1.4

func (r *ExecutionResult) Revert() []byte

Revert returns the concrete revert reason if the execution is aborted by `REVERT` opcode. Note the reason can be nil if no data supplied with revert opcode.

func (*ExecutionResult) Reverted

func (r *ExecutionResult) Reverted() bool

func (*ExecutionResult) Succeeded

func (r *ExecutionResult) Succeeded() bool

func (*ExecutionResult) UpdateGasUsed

func (r *ExecutionResult) UpdateGasUsed(gasLimit uint64, refund uint64)

type Host

type Host interface {
	AccountExists(addr types.Address) bool
	GetStorage(addr types.Address, key types.Hash) (types.Hash, error)
	SetStorage(addr types.Address, key types.Hash, value types.Hash, config *chain.ForksInTime) StorageStatus
	GetBalance(addr types.Address) *big.Int
	GetCodeSize(addr types.Address) int
	GetCodeHash(addr types.Address) types.Hash
	GetCode(addr types.Address) []byte
	Selfdestruct(addr types.Address, beneficiary types.Address)
	GetTxContext() TxContext
	GetBlockHash(number int64) types.Hash
	EmitLog(addr types.Address, topics []types.Hash, data []byte)
	Callx(*Contract, Host) *ExecutionResult
	Empty(addr types.Address) bool
	GetNonce(addr types.Address) uint64
	GetEVMLogger() EVMLogger
}

Host is the execution host

type Runtime

type Runtime interface {
	Run(c *Contract, host Host, config *chain.ForksInTime) *ExecutionResult
	CanRun(c *Contract, host Host, config *chain.ForksInTime) bool
	Name() string
}

Runtime can process contracts

type ScopeContext added in v1.1.4

type ScopeContext struct {
	Memory          []byte
	Stack           []*big.Int
	ContractAddress types.Address
}

ScopeContext contains the things that are per-call, such as stack and memory, but not transients like pc and gas

type StorageStatus

type StorageStatus int

StorageStatus is the status of the storage access

const (
	// StorageUnchanged if the data has not changed
	StorageUnchanged StorageStatus = iota
	// StorageModified if the value has been modified
	StorageModified
	// StorageModifiedAgain if the value has been modified before in the txn
	StorageModifiedAgain
	// StorageAdded if this is a new entry in the storage
	StorageAdded
	// StorageDeleted if the storage was deleted
	StorageDeleted
	// StorageReadFailed if the storage read failed
	StorageReadFailed
)

func (StorageStatus) String

func (s StorageStatus) String() string

type TxContext

type TxContext struct {
	GasPrice   types.Hash
	Origin     types.Address
	Coinbase   types.Address
	Number     int64
	Timestamp  int64
	GasLimit   int64
	ChainID    int64
	Difficulty types.Hash
}

TxContext is the context of the transaction

type Txn added in v1.1.4

type Txn interface {
	GetState(addr types.Address, key types.Hash) (types.Hash, error)
	GetRefund() uint64
}

Txn is used to get an txn in current transition

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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