Documentation ¶
Index ¶
- Variables
- func CanTransfer(db vmtypes.StateDB, addr ogTypes.Address, amount *big.Int) bool
- func NewOVMContext(chainContext ChainContext, coinBase ogTypes.Address, stateDB vmtypes.StateDB) *vmtypes.Context
- func RunPrecompiledContract(p PrecompiledContract, input []byte, contract *vmtypes.Contract) (ret []byte, err error)
- func Transfer(db vmtypes.StateDB, sender, recipient ogTypes.Address, amount *big.Int)
- type ChainConfig
- type ChainContext
- type ConfigCompatError
- type DefaultChainContext
- type GasPool
- type Interpreter
- type LayerStateDB
- func (l *LayerStateDB) AddBalance(addr common.Address, value *math.BigInt)
- func (l *LayerStateDB) AddLog(log *vmtypes.Log)
- func (l *LayerStateDB) AddPreimage(hash types.Hash, code []byte)
- func (l *LayerStateDB) AddRefund(value uint64)
- func (l *LayerStateDB) CreateAccount(addr common.Address)
- func (l *LayerStateDB) CurrentLayer() int
- func (l *LayerStateDB) Empty(addr common.Address) bool
- func (l *LayerStateDB) Exist(addr common.Address) bool
- func (l *LayerStateDB) ForEachStorage(addr common.Address, f func(types.Hash, types.Hash) bool)
- func (l *LayerStateDB) GetBalance(addr common.Address) *math.BigInt
- func (l *LayerStateDB) GetCode(addr common.Address) []byte
- func (l *LayerStateDB) GetCodeHash(addr common.Address) types.Hash
- func (l *LayerStateDB) GetCodeSize(addr common.Address) int
- func (l *LayerStateDB) GetCommittedState(addr common.Address, hash types.Hash) types.Hash
- func (l *LayerStateDB) GetNonce(addr common.Address) uint64
- func (l *LayerStateDB) GetRefund() uint64
- func (l *LayerStateDB) GetState(addr common.Address, key types.Hash) types.Hash
- func (l *LayerStateDB) GetStateObject(addr common.Address) *vmtypes.StateObject
- func (l *LayerStateDB) HasSuicided(addr common.Address) bool
- func (l *LayerStateDB) MergeChanges()
- func (l *LayerStateDB) NewLayer() (index int, err error)
- func (l *LayerStateDB) PopLayer(index int) (err error)
- func (l *LayerStateDB) RevertToSnapshot(i int)
- func (l *LayerStateDB) SetCode(addr common.Address, code []byte)
- func (l *LayerStateDB) SetNonce(addr common.Address, nonce uint64)
- func (l *LayerStateDB) SetState(addr common.Address, key types.Hash, value types.Hash)
- func (l *LayerStateDB) SetStateObject(addr common.Address, stateObject *vmtypes.StateObject)
- func (l *LayerStateDB) Snapshot() int
- func (l *LayerStateDB) String() string
- func (l *LayerStateDB) SubBalance(addr common.Address, value *math.BigInt)
- func (l *LayerStateDB) SubRefund(value uint64)
- func (l *LayerStateDB) Suicide(addr common.Address) bool
- type MemoryStateDB
- func (m *MemoryStateDB) AddBalance(addr common.Address, v *math.BigInt)
- func (m *MemoryStateDB) AddLog(*vmtypes.Log)
- func (m *MemoryStateDB) AddPreimage(hash types.Hash, preImage []byte)
- func (m *MemoryStateDB) AddRefund(v uint64)
- func (m *MemoryStateDB) CreateAccount(addr common.Address)
- func (m *MemoryStateDB) Empty(addr common.Address) bool
- func (m *MemoryStateDB) Exist(addr common.Address) bool
- func (m *MemoryStateDB) ForEachStorage(addr common.Address, cb func(key, value types.Hash) bool)
- func (m *MemoryStateDB) GetBalance(addr common.Address) *math.BigInt
- func (m *MemoryStateDB) GetCode(addr common.Address) []byte
- func (m *MemoryStateDB) GetCodeHash(addr common.Address) types.Hash
- func (m *MemoryStateDB) GetCodeSize(addr common.Address) int
- func (m *MemoryStateDB) GetCommittedState(addr common.Address, hash types.Hash) types.Hash
- func (m *MemoryStateDB) GetNonce(addr common.Address) uint64
- func (m *MemoryStateDB) GetRefund() uint64
- func (m *MemoryStateDB) GetState(addr common.Address, key types.Hash) types.Hash
- func (m *MemoryStateDB) GetStateObject(addr common.Address) *vmtypes.StateObject
- func (m *MemoryStateDB) HasSuicided(addr common.Address) bool
- func (m *MemoryStateDB) RevertToSnapshot(int)
- func (m *MemoryStateDB) SetCode(addr common.Address, code []byte)
- func (m *MemoryStateDB) SetNonce(addr common.Address, nonce uint64)
- func (m *MemoryStateDB) SetState(addr common.Address, key types.Hash, value types.Hash)
- func (m *MemoryStateDB) SetStateObject(addr common.Address, stateObject *vmtypes.StateObject)
- func (m *MemoryStateDB) Snapshot() int
- func (m *MemoryStateDB) String() string
- func (m *MemoryStateDB) SubBalance(addr common.Address, v *math.BigInt)
- func (m *MemoryStateDB) SubRefund(v uint64)
- func (m *MemoryStateDB) Suicide(addr common.Address) bool
- type OVM
- func (ovm *OVM) Call(caller vmtypes.ContractRef, addr ogTypes.Address20, input []byte, gas uint64, ...) (ret []byte, leftOverGas uint64, err error)
- func (ovm *OVM) CallCode(caller vmtypes.ContractRef, addr ogTypes.Address20, input []byte, gas uint64, ...) (ret []byte, leftOverGas uint64, err error)
- func (ovm *OVM) Cancel()
- func (ovm *OVM) Create(caller vmtypes.ContractRef, code []byte, gas uint64, value *big.Int, ...) (ret []byte, contractAddr ogTypes.Address20, leftOverGas uint64, err error)
- func (ovm *OVM) Create2(caller vmtypes.ContractRef, code []byte, gas uint64, endowment *big.Int, ...) (ret []byte, contractAddr ogTypes.Address20, leftOverGas uint64, err error)
- func (ovm *OVM) DelegateCall(caller vmtypes.ContractRef, addr ogTypes.Address20, input []byte, gas uint64) (ret []byte, leftOverGas uint64, err error)
- func (ovm *OVM) StaticCall(caller vmtypes.ContractRef, addr ogTypes.Address20, input []byte, gas uint64) (ret []byte, leftOverGas uint64, err error)
- type OVMConfig
- type PrecompiledContract
- type TxContext
- type VM
Constants ¶
This section is empty.
Variables ¶
var FAST_FAIL = false
var MAX_LAYER = 1024
var PrecompiledContractsByzantium = map[ogTypes.Address20]PrecompiledContract{ *ogTypes.BytesToAddress20([]byte{1}): &ecrecover{}, *ogTypes.BytesToAddress20([]byte{2}): &sha256hash{}, *ogTypes.BytesToAddress20([]byte{3}): &ripemd160hash{}, *ogTypes.BytesToAddress20([]byte{4}): &dataCopy{}, *ogTypes.BytesToAddress20([]byte{5}): &bigModExp{}, *ogTypes.BytesToAddress20([]byte{6}): &bn256Add{}, *ogTypes.BytesToAddress20([]byte{7}): &bn256ScalarMul{}, *ogTypes.BytesToAddress20([]byte{8}): &bn256Pairing{}, }
PrecompiledContractsByzantium contains the default set of pre-compiled Ethereum contracts used in the Byzantium release.
var TestChainConfig = &ChainConfig{0}
Functions ¶
func CanTransfer ¶
CanTransfer checks whether there are enough funds in the address' account to make a transfer. This does not take the necessary gas in to account to make the transfer valid.
func NewOVMContext ¶
func NewOVMContext(chainContext ChainContext, coinBase ogTypes.Address, stateDB vmtypes.StateDB) *vmtypes.Context
NewOVMContext creates a new context for use in the OVM.
func RunPrecompiledContract ¶
func RunPrecompiledContract(p PrecompiledContract, input []byte, contract *vmtypes.Contract) (ret []byte, err error)
RunPrecompiledContract runs and evaluates the output of a precompiled contract.
Types ¶
type ChainConfig ¶
type ChainConfig struct {
ChainID uint32 `json:"chainId"` // chainId identifies the current chain and is used for replay protection
}
ChainConfig is the core config which determines the blockchain settings.
ChainConfig is stored in the database on a per block basis. This means that any network, identified by its genesis block, can have its own set of configuration options.
func (*ChainConfig) String ¶
func (c *ChainConfig) String() string
String implements the fmt.Stringer interface.
type ChainContext ¶
type ChainContext interface { }
ChainContext supports retrieving headers and consensus parameters from the current blockchain to be used during transaction processing.
type ConfigCompatError ¶
type ConfigCompatError struct { What string // block numbers of the stored and new configurations StoredConfig, NewConfig *big.Int // the block number to which the local chain must be rewound to correct the error RewindTo uint64 }
ConfigCompatError is raised if the locally-stored blockchain is initialised with a ChainConfig that would alter the past.
func (*ConfigCompatError) Error ¶
func (err *ConfigCompatError) Error() string
type DefaultChainContext ¶
type DefaultChainContext struct { }
type GasPool ¶
type GasPool uint64
GasPool tracks the amount of gas available during execution of the transactions in a block. The zero value is a pool with zero gas available.
type Interpreter ¶
type Interpreter interface { // Run loops and evaluates the vmtypes.Contract's code with the given input data and returns // the return byte-slice and an error if one occurred. Run(Contract *types.Contract, input []byte, static bool) ([]byte, error) // CanRun tells if the vmtypes.Contract, passed as an argument, can be // run by the current interpreter. This is meant so that the // caller can do something like: // // “`golang // for _, interpreter := range interpreters { // if interpreter.CanRun(vmtypes.Contract.code) { // interpreter.Run(vmtypes.Contract.code, input) // } // } // “` CanRun([]byte) bool // SetCaller will be called when OVM is initializing this intepreter. // OVM will tell which caller interpreter should use if there is a inter-contract call SetCaller(caller types.Caller) }
Interpreter is used to run Ethereum based vmtypes.Contracts and will utilise the passed environment to query external sources for state information. The Interpreter will run the byte code VM based on the passed configuration.
type LayerStateDB ¶
type LayerStateDB struct { Layers []vmtypes.StateDBDebug // contains filtered or unexported fields }
LayerStateDB is the cascading storage for contracts. It consists of multiple layers, each of which represents the result of a contract. e.g. -.-#-+-#----- <- Latest changes after contract --+-------+-- <- ... ----.----.--- <- first contract ------------- <- StateDB (on disk) When accessing, watch from the top to the bottom. Same mechanism as Docker image layers. Add a layer each time a new contract is run
func NewLayerDB ¶
func NewLayerDB(baseLayer vmtypes.StateDBDebug) *LayerStateDB
func (*LayerStateDB) AddBalance ¶
func (l *LayerStateDB) AddBalance(addr common.Address, value *math.BigInt)
func (*LayerStateDB) AddLog ¶
func (l *LayerStateDB) AddLog(log *vmtypes.Log)
func (*LayerStateDB) AddPreimage ¶
func (l *LayerStateDB) AddPreimage(hash types.Hash, code []byte)
func (*LayerStateDB) AddRefund ¶
func (l *LayerStateDB) AddRefund(value uint64)
func (*LayerStateDB) CreateAccount ¶
func (l *LayerStateDB) CreateAccount(addr common.Address)
func (*LayerStateDB) CurrentLayer ¶
func (l *LayerStateDB) CurrentLayer() int
func (*LayerStateDB) ForEachStorage ¶
func (*LayerStateDB) GetBalance ¶
func (l *LayerStateDB) GetBalance(addr common.Address) *math.BigInt
func (*LayerStateDB) GetCodeHash ¶
func (l *LayerStateDB) GetCodeHash(addr common.Address) types.Hash
func (*LayerStateDB) GetCodeSize ¶
func (l *LayerStateDB) GetCodeSize(addr common.Address) int
func (*LayerStateDB) GetCommittedState ¶
func (*LayerStateDB) GetRefund ¶
func (l *LayerStateDB) GetRefund() uint64
func (*LayerStateDB) GetStateObject ¶
func (l *LayerStateDB) GetStateObject(addr common.Address) *vmtypes.StateObject
func (*LayerStateDB) HasSuicided ¶
func (l *LayerStateDB) HasSuicided(addr common.Address) bool
func (*LayerStateDB) MergeChanges ¶
func (l *LayerStateDB) MergeChanges()
MergeChanges merges all layers that are above the bottom layer to one layer
func (*LayerStateDB) NewLayer ¶
func (l *LayerStateDB) NewLayer() (index int, err error)
func (*LayerStateDB) PopLayer ¶
func (l *LayerStateDB) PopLayer(index int) (err error)
func (*LayerStateDB) RevertToSnapshot ¶
func (l *LayerStateDB) RevertToSnapshot(i int)
func (*LayerStateDB) SetStateObject ¶
func (l *LayerStateDB) SetStateObject(addr common.Address, stateObject *vmtypes.StateObject)
func (*LayerStateDB) Snapshot ¶
func (l *LayerStateDB) Snapshot() int
func (*LayerStateDB) String ¶
func (l *LayerStateDB) String() string
func (*LayerStateDB) SubBalance ¶
func (l *LayerStateDB) SubBalance(addr common.Address, value *math.BigInt)
func (*LayerStateDB) SubRefund ¶
func (l *LayerStateDB) SubRefund(value uint64)
type MemoryStateDB ¶
type MemoryStateDB struct {
// contains filtered or unexported fields
}
func NewMemoryStateDB ¶
func NewMemoryStateDB() *MemoryStateDB
func (*MemoryStateDB) AddBalance ¶
func (m *MemoryStateDB) AddBalance(addr common.Address, v *math.BigInt)
func (*MemoryStateDB) AddLog ¶
func (m *MemoryStateDB) AddLog(*vmtypes.Log)
func (*MemoryStateDB) AddPreimage ¶
func (m *MemoryStateDB) AddPreimage(hash types.Hash, preImage []byte)
func (*MemoryStateDB) AddRefund ¶
func (m *MemoryStateDB) AddRefund(v uint64)
func (*MemoryStateDB) CreateAccount ¶
func (m *MemoryStateDB) CreateAccount(addr common.Address)
func (*MemoryStateDB) ForEachStorage ¶
func (*MemoryStateDB) GetBalance ¶
func (m *MemoryStateDB) GetBalance(addr common.Address) *math.BigInt
func (*MemoryStateDB) GetCodeHash ¶
func (m *MemoryStateDB) GetCodeHash(addr common.Address) types.Hash
func (*MemoryStateDB) GetCodeSize ¶
func (m *MemoryStateDB) GetCodeSize(addr common.Address) int
func (*MemoryStateDB) GetCommittedState ¶
func (*MemoryStateDB) GetRefund ¶
func (m *MemoryStateDB) GetRefund() uint64
func (*MemoryStateDB) GetStateObject ¶
func (m *MemoryStateDB) GetStateObject(addr common.Address) *vmtypes.StateObject
func (*MemoryStateDB) HasSuicided ¶
func (m *MemoryStateDB) HasSuicided(addr common.Address) bool
func (*MemoryStateDB) RevertToSnapshot ¶
func (m *MemoryStateDB) RevertToSnapshot(int)
func (*MemoryStateDB) SetNonce ¶
func (m *MemoryStateDB) SetNonce(addr common.Address, nonce uint64)
func (*MemoryStateDB) SetStateObject ¶
func (m *MemoryStateDB) SetStateObject(addr common.Address, stateObject *vmtypes.StateObject)
func (*MemoryStateDB) Snapshot ¶
func (m *MemoryStateDB) Snapshot() int
func (*MemoryStateDB) String ¶
func (m *MemoryStateDB) String() string
func (*MemoryStateDB) SubBalance ¶
func (m *MemoryStateDB) SubBalance(addr common.Address, v *math.BigInt)
func (*MemoryStateDB) SubRefund ¶
func (m *MemoryStateDB) SubRefund(v uint64)
type OVM ¶
type OVM struct { // Context provides auxiliary blockchain related information VMContext *vmtypes.Context // chainConfig contains information about the current chain // ChainConfig *params.ChainConfig // chain rules contains the chain rules for the current epoch // chainRules params.Rules // virtual machine configuration options used to initialise the // evm. OVMConfigs *OVMConfig // global (to this context) ethereum virtual machine // used throughout the execution of the tx. Interpreters []Interpreter Interpreter Interpreter }
OVM is the Ethereum Virtual Machine base object and provides the necessary tools to run a contract on the given state with the provided context. It should be noted that any error generated through any of the calls should be considered a revert-state-and-consume-all-gas operation, no checks on specific errors should ever be performed. The interpreter makes sure that any errors generated are to be considered faulty Code.
The OVM should never be reused and is not thread safe.
func NewOVM ¶
func NewOVM(ctx *vmtypes.Context, supportInterpreters []Interpreter, ovmConfig *OVMConfig) *OVM
NewOVM returns a new OVM. The returned OVM is not thread safe and should only ever be used *once*.
func (*OVM) Call ¶
func (ovm *OVM) Call(caller vmtypes.ContractRef, addr ogTypes.Address20, input []byte, gas uint64, value *big.Int, txCall bool) (ret []byte, leftOverGas uint64, err error)
Call executes the contract associated with the addr with the given input as parameters. It also handles any necessary value transfer required and takes the necessary steps to create accounts and reverses the state in case of an execution error or failed value transfer.
func (*OVM) CallCode ¶
func (ovm *OVM) CallCode(caller vmtypes.ContractRef, addr ogTypes.Address20, input []byte, gas uint64, value *big.Int) (ret []byte, leftOverGas uint64, err error)
CallCode executes the contract associated with the addr with the given input as parameters. It also handles any necessary value transfer required and takes the necessary steps to create accounts and reverses the state in case of an execution error or failed value transfer.
CallCode differs from Call in the sense that it executes the given address' Code with the caller as context.
func (*OVM) Cancel ¶
func (ovm *OVM) Cancel()
Cancel cancels any running OVM operation. This may be called concurrently and it's safe to be called multiple times.
func (*OVM) Create ¶
func (ovm *OVM) Create(caller vmtypes.ContractRef, code []byte, gas uint64, value *big.Int, txCall bool) (ret []byte, contractAddr ogTypes.Address20, leftOverGas uint64, err error)
Create creates a new contract using Code as deployment Code.
func (*OVM) Create2 ¶
func (ovm *OVM) Create2(caller vmtypes.ContractRef, code []byte, gas uint64, endowment *big.Int, salt *big.Int, txCall bool) (ret []byte, contractAddr ogTypes.Address20, leftOverGas uint64, err error)
Create2 creates a new contract using Code as deployment Code.
The different between Create2 with Create is Create2 uses sha3(0xff ++ msg.sender ++ salt ++ sha3(init_code))[12:] instead of the usual sender-and-Nonce-hash as the address where the contract is initialized at.
func (*OVM) DelegateCall ¶
func (ovm *OVM) DelegateCall(caller vmtypes.ContractRef, addr ogTypes.Address20, input []byte, gas uint64) (ret []byte, leftOverGas uint64, err error)
DelegateCall executes the contract associated with the addr with the given input as parameters. It reverses the state in case of an execution error.
DelegateCall differs from CallCode in the sense that it executes the given address' Code with the caller as context and the caller is set to the caller of the caller.
func (*OVM) StaticCall ¶
func (ovm *OVM) StaticCall(caller vmtypes.ContractRef, addr ogTypes.Address20, input []byte, gas uint64) (ret []byte, leftOverGas uint64, err error)
StaticCall executes the contract associated with the addr with the given input as parameters while disallowing any modifications to the state during the call. Opcodes that attempt to perform such modifications will result in exceptions instead of performing the modifications.
type OVMConfig ¶
type OVMConfig struct { // NoRecursion disabled Interpreter call, callcode, // delegate call and create. NoRecursion bool }
type PrecompiledContract ¶
type PrecompiledContract interface { RequiredGas(input []byte) uint64 // RequiredPrice calculates the contract gas use Run(input []byte) ([]byte, error) // Run runs the precompiled contract }
PrecompiledContract is the basic interface for native Go contracts. The implementation requires a deterministic gas count based on the input size of the Run method of the contract.
type TxContext ¶
type TxContext struct { From *ogTypes.Address20 To *ogTypes.Address20 Value *math.BigInt Data []byte // Temporarily keep using gas as resource billing GasLimit uint64 GasPrice *math.BigInt Coinbase *ogTypes.Address20 // Provides information for COINBASE SequenceID uint64 // Provides information for SequenceID }
TxContext represents all information that evm needs to know about the tx current processing.
type VM ¶
type VM interface { // Cancel cancels any running VM operation. This may be called concurrently and // it's safe to be called multiple times. Cancel() // Interpreter returns the current interpreter Interpreter() Interpreter // Call executes the vmtypes.Contract associated with the addr with the given input as // parameters. It also handles any necessary Value transfer required and takes // the necessary steps to create accounts and reverses the state in case of an // execution error or failed Value transfer. Call(caller vmtypes.ContractRef, addr common.Address, input []byte, gas uint64, value *big.Int) (ret []byte, leftOverGas uint64, err error) // CallCode executes the vmtypes.Contract associated with the addr with the given input // as parameters. It also handles any necessary Value transfer required and takes // the necessary steps to create accounts and reverses the state in case of an // execution error or failed Value transfer. // // CallCode differs from Call in the sense that it executes the given address' // Code with the caller as context. CallCode(caller vmtypes.ContractRef, addr common.Address, input []byte, gas uint64, value *big.Int) (ret []byte, leftOverGas uint64, err error) // DelegateCall executes the vmtypes.Contract associated with the addr with the given input // as parameters. It reverses the state in case of an execution error. // // DelegateCall differs from CallCode in the sense that it executes the given address' // Code with the caller as context and the caller is set to the caller of the caller. DelegateCall(caller vmtypes.ContractRef, addr common.Address, input []byte, gas uint64) (ret []byte, leftOverGas uint64, err error) // StaticCall executes the vmtypes.Contract associated with the addr with the given input // as parameters while disallowing any modifications to the state during the call. // Opcodes that attempt to perform such modifications will result in exceptions // instead of performing the modifications. StaticCall(caller vmtypes.ContractRef, addr common.Address, input []byte, gas uint64) (ret []byte, leftOverGas uint64, err error) // Create creates a new vmtypes.Contract using Code as deployment Code. Create(caller vmtypes.ContractRef, code []byte, gas uint64, value *big.Int) (ret []byte, ContractAddr common.Address, leftOverGas uint64, err error) // Create2 creates a new vmtypes.Contract using Code as deployment Code. // // The different between Create2 with Create is Create2 uses sha3(0xff ++ msg.sender ++ salt ++ sha3(init_code))[12:] // instead of the usual sender-and-Nonce-hash as the address where the vmtypes.Contract is initialized at. Create2(caller vmtypes.ContractRef, code []byte, gas uint64, endowment *big.Int, salt *big.Int) (ret []byte, ContractAddr common.Address, leftOverGas uint64, err error) }