types

package
v0.0.5-unstable Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2020 License: Apache-2.0 Imports: 15 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrOutOfGas                 = errors.New("out of gas")
	ErrCodeStoreOutOfGas        = errors.New("contract creation code storage out of gas")
	ErrDepth                    = errors.New("max call depth exceeded")
	ErrTraceLimitReached        = errors.New("the number of logs reached the specified limit")
	ErrInsufficientBalance      = errors.New("insufficient balance for transfer")
	ErrContractAddressCollision = errors.New("contract address collision")
	ErrNoCompatibleInterpreter  = errors.New("no compatible interpreter")
)

List execution errors

View Source
var (
	ErrWriteProtection       = errors.New("ovm: write protection")
	ErrReturnDataOutOfBounds = errors.New("ovm: return data out of bounds")
	ErrExecutionReverted     = errors.New("ovm: execution reverted")
	ErrMaxCodeSizeExceeded   = errors.New("ovm: max code size exceeded")
)
View Source
var (
	// ErrGasLimitReached is returned by the gas pool if the amount of gas required
	// by a transaction is higher than what's left in the block.
	ErrGasLimitReached = errors.New("gas limit reached")
)

Functions

This section is empty.

Types

type AccountRef

type AccountRef ogTypes.Address20

AccountRef implements ContractRef.

Account references are used during OVM initialisation and it's primary use is to fetch addresses. Removing this object proves difficult because of the cached jump destinations which are fetched from the parent contract (i.e. the caller), which is a ContractRef.

func (AccountRef) Address

func (ar AccountRef) Address() ogTypes.Address20

Address casts AccountRef to a Address

type Caller

type Caller interface {
	// Call another contract
	Call(me ContractRef, addr ogTypes.Address20, data []byte, gas uint64, value *big.Int, txCall bool) (resp []byte, leftOverGas uint64, err error)
	// Take another's contract code and execute within our own context
	CallCode(me ContractRef, addr ogTypes.Address20, data []byte, gas uint64, value *big.Int) (resp []byte, leftOverGas uint64, err error)
	// Same as CallCode except sender and value is propagated from parent to child scope
	DelegateCall(me ContractRef, addr ogTypes.Address20, data []byte, gas uint64) (resp []byte, leftOverGas uint64, err error)
	// Create a new contract
	Create(me ContractRef, data []byte, gas uint64, value *big.Int, txCall bool) (resp []byte, contractAddr ogTypes.Address20, leftOverGas uint64, err error)
	// Create a new contract use sha3
	Create2(caller ContractRef, code []byte, gas uint64, endowment *big.Int, salt *big.Int, txCall bool) (ret []byte, contractAddr ogTypes.Address20, leftOverGas uint64, err error)

	StaticCall(caller ContractRef, addr ogTypes.Address20, input []byte, gas uint64) (ret []byte, leftOverGas uint64, err error)
}

Caller provides a basic interface for the OVM calling conventions. The OVM depends on this context being implemented for doing subcalls and initialising new OVM contracts.

type CanTransferFunc

type CanTransferFunc func(StateDB, ogTypes.Address20, *big.Int) bool

CanTransferFunc is the signature of a transfer guard function

type CodeAndHash

type CodeAndHash struct {
	Code []byte
	// contains filtered or unexported fields
}

func (*CodeAndHash) Hash

func (c *CodeAndHash) Hash() ogTypes.Hash32

type Context

type Context struct {
	// CanTransfer returns whether the account contains
	// sufficient ether to transfer the value
	CanTransfer CanTransferFunc
	// Transfer transfers ether from one account to the other
	Transfer TransferFunc
	// GetHash returns the hash corresponding to n
	//GetHash GetHashFunc
	StateDB     StateDB
	CallGasTemp uint64
	// Depth is the current call stack
	Depth int

	// abort is used to abort the OVM calling operations
	// NOTE: must be set atomically
	Abort int32
}

Context provides the OVM with auxiliary information. Once provided it shouldn't be modified.

type Contract

type Contract struct {
	// CallerAddress is the result of the caller which initialised this
	// contract. However when the "call method" is delegated this Value
	// needs to be initialised to that of the caller's caller.
	CallerAddress ogTypes.Address20

	Code     []byte
	CodeHash ogTypes.Hash32
	CodeAddr *ogTypes.Address20
	Input    []byte

	Gas uint64
	// contains filtered or unexported fields
}

Contract represents an general contract in the state database. It contains the contract code, calling arguments. Contract implements ContractRef

func NewContract

func NewContract(caller ContractRef, object ContractRef, value *big.Int, gas uint64) *Contract

NewContract returns a new contract environment for the execution of OVM.

func (*Contract) Address

func (c *Contract) Address() ogTypes.Address20

Address returns the contracts address

func (*Contract) AsDelegate

func (c *Contract) AsDelegate() *Contract

AsDelegate sets the contract to be a delegate call and returns the current contract (for chaining calls)

func (*Contract) Caller

func (c *Contract) Caller() ogTypes.Address20

Caller returns the caller of the contract.

Caller will recursively call caller when the contract is a delegate call, including that of caller's caller.

func (*Contract) GetByte

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

GetByte returns the n'th byte in the contract's byte array

func (*Contract) GetOp

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

GetOp returns the n'th element in the contract's byte array

func (*Contract) SetCallCode

func (c *Contract) SetCallCode(addr ogTypes.Address20, hash ogTypes.Hash32, code []byte)

SetCallCode sets the code of the contract and address of the backing data object

func (*Contract) SetCodeOptionalHash

func (c *Contract) SetCodeOptionalHash(addr ogTypes.Address20, codeAndHash *CodeAndHash)

SetCodeOptionalHash can be used to provide code, but it's optional to provide hash. In case hash is not provided, the jumpdest analysis will not be saved to the parent context

func (*Contract) UseGas

func (c *Contract) UseGas(gas uint64) (ok bool)

UseGas attempts the use gas and subtracts it and returns true on success

func (*Contract) ValidJumpdest

func (c *Contract) ValidJumpdest(dest *big.Int) bool

func (*Contract) Value

func (c *Contract) Value() *big.Int

Value returns the contracts Value (sent to it from it's caller)

type ContractRef

type ContractRef interface {
	Address() ogTypes.Address20
}

ContractRef is a reference to the contract's backing object

type GetHashFunc

type GetHashFunc func(uint64) ogTypes.Hash

GetHashFunc returns the nth block hash in the blockchain and is used by the BLOCKHASH OVM op code.

type Log

type Log struct {
	// Consensus fields:
	// address of the contract that generated the event
	Address common.Address `json:"address" gencodec:"required"`
	// list of topics provided by the contract.
	Topics types.Hashes `json:"topics" gencodec:"required"`
	// supplied by the contract, usually ABI-encoded
	Data []byte `json:"data" gencodec:"required"`

	// Derived fields. These fields are filled in by the node
	// but not secured by consensus.
	// block in which the transaction was included
	SequenceID uint64 `json:"blockNumber"`
	// hash of the transaction
	TxHash types.Hash `json:"transactionHash" gencodec:"required"`
	// index of the transaction in the block
	TxIndex uint `json:"transactionIndex" gencodec:"required"`
	// hash of the block in which the transaction was included
	BlockHash types.Hash `json:"blockHash"`
	// index of the log in the block
	Index uint `json:"logIndex" gencodec:"required"`

	// The Removed field is true if this log was reverted due to a chain reorganisation.
	// You must pay attention to this field if you receive logs through a filter query.
	Removed bool `json:"removed"`
}

Log represents a contract log event. These events are generated by the LOG opcode and stored/indexed by the node.

func (*Log) DecodeRLP

func (l *Log) DecodeRLP(s *rlp.Stream) error

DecodeRLP implements rlp.Decoder.

func (*Log) EncodeRLP

func (l *Log) EncodeRLP(w io.Writer) error

EncodeRLP implements rlp.Encoder.

type LogForStorage

type LogForStorage Log

LogForStorage is a wrapper around a Log that flattens and parses the entire content of a log including non-consensus fields.

func (*LogForStorage) DecodeRLP

func (l *LogForStorage) DecodeRLP(s *rlp.Stream) error

DecodeRLP implements rlp.Decoder.

func (*LogForStorage) EncodeRLP

func (l *LogForStorage) EncodeRLP(w io.Writer) error

EncodeRLP implements rlp.Encoder.

type Resource

type Resource struct {
}

type StateDB

type StateDB interface {
	CreateAccount(ogTypes.Address)

	SubBalance(ogTypes.Address, *math.BigInt)
	AddBalance(ogTypes.Address, *math.BigInt)
	// Retrieve the balance from the given address or 0 if object not found
	GetBalance(ogTypes.Address) *math.BigInt

	GetNonce(ogTypes.Address) uint64
	SetNonce(ogTypes.Address, uint64)

	GetCodeHash(ogTypes.Address) ogTypes.Hash
	GetCode(ogTypes.Address) []byte
	SetCode(ogTypes.Address, []byte)
	GetCodeSize(ogTypes.Address) int

	// AddRefund adds gas to the refund counter
	AddRefund(uint64)
	// SubRefund removes gas from the refund counter.
	// This method will panic if the refund counter goes below zero
	SubRefund(uint64)
	// GetRefund returns the current value of the refund counter.
	GetRefund() uint64

	GetCommittedState(ogTypes.Address, ogTypes.Hash) ogTypes.Hash
	// GetState retrieves a value from the given account's storage trie.
	GetState(ogTypes.Address, ogTypes.Hash) ogTypes.Hash
	SetState(ogTypes.Address, ogTypes.Hash, ogTypes.Hash)

	// Suicide marks the given account as suicided.
	// This clears the account balance.
	//
	// The account's state object is still available until the state is committed,
	// getStateObject will return a non-nil account after Suicide.
	Suicide(ogTypes.Address) bool
	HasSuicided(ogTypes.Address) bool

	// IsAddressExists reports whether the given account exists in state.
	// Notably this should also return true for suicided accounts.
	Exist(ogTypes.Address) bool
	// Empty returns whether the given account is empty. Empty
	// is defined according to EIP161 (balance = nonce = code = 0).
	Empty(ogTypes.Address) bool

	// RevertToSnapshot reverts all state changes made since the given revision.
	RevertToSnapshot(int)
	// Snapshot creates a new revision
	Snapshot() int

	AddLog(*Log)
	AddPreimage(ogTypes.Hash, []byte)

	ForEachStorage(ogTypes.Address, func(ogTypes.Hash, ogTypes.Hash) bool)
	// for debug.
	String() string
}

StateDB is an OVM database for full state querying.

type StateObject

type StateObject struct {
	Balance  *big.Int
	Nonce    uint64
	Code     []byte
	CodeHash types.Hash
	Suicided bool
	Version  int

	DirtyCode bool
	DirtySO   bool
	// contains filtered or unexported fields
}

func NewStateObject

func NewStateObject() *StateObject

func (*StateObject) Copy

func (s *StateObject) Copy() (d *StateObject)

func (*StateObject) Empty

func (s *StateObject) Empty() bool

func (*StateObject) String

func (s *StateObject) String() string

type Storage

type Storage map[types.Hash]types.Hash

func NewStorage

func NewStorage() Storage

type TransferFunc

type TransferFunc func(StateDB, ogTypes.Address20, ogTypes.Address20, *big.Int)

TransferFunc is the signature of a transfer function

Jump to

Keyboard shortcuts

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