Documentation ¶
Index ¶
- Variables
- type AccountRef
- type Caller
- type CanTransferFunc
- type CodeAndHash
- type Context
- type Contract
- func (c *Contract) Address() ogTypes.Address20
- func (c *Contract) AsDelegate() *Contract
- func (c *Contract) Caller() ogTypes.Address20
- func (c *Contract) GetByte(n uint64) byte
- func (c *Contract) GetOp(n uint64) instruction.OpCode
- func (c *Contract) SetCallCode(addr ogTypes.Address20, hash ogTypes.Hash32, code []byte)
- func (c *Contract) SetCodeOptionalHash(addr ogTypes.Address20, codeAndHash *CodeAndHash)
- func (c *Contract) UseGas(gas uint64) (ok bool)
- func (c *Contract) ValidJumpdest(dest *big.Int) bool
- func (c *Contract) Value() *big.Int
- type ContractRef
- type GetHashFunc
- type Log
- type LogForStorage
- type Resource
- type StateDB
- type StateObject
- type Storage
- type TransferFunc
Constants ¶
This section is empty.
Variables ¶
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
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") )
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 ¶
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 ¶
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) AsDelegate ¶
AsDelegate sets the contract to be a delegate call and returns the current contract (for chaining calls)
func (*Contract) Caller ¶
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) GetOp ¶
func (c *Contract) GetOp(n uint64) instruction.OpCode
GetOp returns the n'th element in the contract's byte array
func (*Contract) SetCallCode ¶
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
type ContractRef ¶
ContractRef is a reference to the contract's backing object
type GetHashFunc ¶
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.
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.
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