Documentation
¶
Overview ¶
Package vm implements the Ethereum Virtual Machine.
The vm package implements two EVMs, a byte code VM and a JIT VM. The BC (Byte Code) VM loops over a set of bytes and executes them according to the set of rules defined in the MoacNode yellow paper. When the BC VM is invoked it invokes the JIT VM in a separate goroutine and compiles the byte code in JIT instructions.
The JIT VM, when invoked, loops around a set of pre-defined instructions until it either runs of gas, causes an internal error, returns or stops.
The JIT optimiser attempts to pre-compile instructions in to chunks or segments such as multiple PUSH operations and static JUMPs. It does this by analysing the opcodes and attempts to match certain regions to known sets. Whenever the optimiser finds said segments it creates a new instruction and replaces the first occurrence in the sequence.
Index ¶
- Constants
- func Run(evm *EVM, snapshot int, contract *Contract, input []byte, ...) ([]byte, error)
- func SetEVM(evm *EVM)
- type CTXPool
- type CanTransferFunc
- type Context
- type ContractCallStruct
- type ContractsInterface
- type EVM
- func (evm *EVM) ApplyFlushChanges(flushResult map[int]*pb.ScsPushMsg) (err error)
- func (evm *EVM) Call(caller ContractRef, addr common.Address, input []byte, gasLimit uint64, ...) (ret []byte, leftOverGas uint64, err error)
- func (evm *EVM) CallCode(caller ContractRef, addr common.Address, input []byte, gas uint64, ...) (ret []byte, leftOverGas uint64, err error)
- func (evm *EVM) Cancel()
- func (evm *EVM) ChainConfig() *params.ChainConfig
- func (evm *EVM) Create(caller ContractRef, code []byte, gasRemaining uint64, value *big.Int, ...) (ret []byte, contractAddr common.Address, leftOverGas uint64, err error)
- func (evm *EVM) CreateSystemContract(sysaddr common.Address, code []byte, precompiledContracts ContractsInterface, ...) (ret []byte, err error)
- func (evm *EVM) DelegateCall(caller ContractRef, addr common.Address, input []byte, gas uint64, ...) (ret []byte, leftOverGas uint64, err error)
- func (evm *EVM) Interpreter() *Interpreter
- func (evm *EVM) Query(addr common.Address) (ret []byte, leftOverGas uint64, err error)
- func (evm *EVM) StaticCall(caller ContractRef, addr common.Address, input []byte, gas uint64, ...) (ret []byte, leftOverGas uint64, err error)
- type GetHashFunc
- type NetworkRelayInterface
- type PrecompiledContract
- type QueryResult
- type TransferFunc
Constants ¶
const (
None = -1
)
Variables ¶
This section is empty.
Functions ¶
Types ¶
type CTXPool ¶
type CTXPool interface {
AddShardJoinCall(tx *types.Transaction) error
}
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 // Message information Origin common.Address // Provides information for ORIGIN GasPrice *big.Int // Provides information for GASPRICE // Block information Coinbase common.Address // Provides information for COINBASE GasLimit *big.Int // Provides information for GASLIMIT BlockNumber *big.Int // Provides information for NUMBER Time *big.Int // Provides information for TIME Difficulty *big.Int // Provides information for DIFFICULTY CtxTxpool CTXPool }
Context provides the EVM with auxiliary information. Once provided it shouldn't be modified.
type ContractCallStruct ¶
type ContractsInterface ¶
type ContractsInterface interface { PrecompiledContractsPangu() map[common.Address]PrecompiledContract PrecompiledContractsByzantium() map[common.Address]PrecompiledContract RunPrecompiledContract(evm *EVM, snapshot int, p PrecompiledContract, input []byte, contract *Contract, hash *common.Hash) (ret []byte, err error) SystemContractCallAddr() common.Address SystemContractEntryAddr(num *big.Int) common.Address IsSystemCaller(caller ContractRef) (ret bool) WhiteListCallAddr() common.Address }
type EVM ¶
type EVM struct { // Context provides auxiliary blockchain related information Context // StateDB gives access to the underlying state StateDB StateDB // virtual machine configuration options used to initialise the // evm. VmConfig Config // MOAC additions: // handle the network traffic with SCS servers. Nr NetworkRelayInterface // contains filtered or unexported fields }
EVM 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 EVM should never be reused and is not thread safe.
func NewEVM ¶
func NewEVM(ctx Context, statedb StateDB, chainConfig *params.ChainConfig, vmConfig Config, nr NetworkRelayInterface) *EVM
NewEVM retutrns a new EVM . The returned EVM is not thread safe and should only ever be used *once*.
func (*EVM) ApplyFlushChanges ¶
func (evm *EVM) ApplyFlushChanges(flushResult map[int]*pb.ScsPushMsg) (err error)
func (*EVM) Call ¶
func (evm *EVM) Call( caller ContractRef, addr common.Address, input []byte, gasLimit uint64, value *big.Int, synccall bool, shardingFlag uint64, precompiledContracts ContractsInterface, msgHash *common.Hash) ( 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 (*EVM) CallCode ¶
func (evm *EVM) CallCode(caller ContractRef, addr common.Address, input []byte, gas uint64, value *big.Int, precompiledContracts ContractsInterface, msgHash *common.Hash) (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 (*EVM) Cancel ¶
func (evm *EVM) Cancel()
Cancel cancels any running EVM operation. This may be called concurrently and it's safe to be called multiple times.
func (*EVM) ChainConfig ¶
func (evm *EVM) ChainConfig() *params.ChainConfig
ChainConfig returns the evmironment's chain configuration
func (*EVM) Create ¶
func (evm *EVM) Create(caller ContractRef, code []byte, gasRemaining uint64, value *big.Int, shardflag uint64, precompiledContracts ContractsInterface, msgHash *common.Hash) (ret []byte, contractAddr common.Address, leftOverGas uint64, err error)
Create creates a new contract using code as deployment code.
func (*EVM) CreateSystemContract ¶
func (evm *EVM) CreateSystemContract(sysaddr common.Address, code []byte, precompiledContracts ContractsInterface, msgHash *common.Hash) (ret []byte, err error)
Create creates a system contract using code as deployment code.
func (*EVM) DelegateCall ¶
func (evm *EVM) DelegateCall(caller ContractRef, addr common.Address, input []byte, gas uint64, precompiledContracts ContractsInterface, msgHash *common.Hash) (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 (*EVM) Interpreter ¶
func (evm *EVM) Interpreter() *Interpreter
Interpreter returns the EVM interpreter
func (*EVM) StaticCall ¶
func (evm *EVM) StaticCall(caller ContractRef, addr common.Address, input []byte, gas uint64, precompiledContracts ContractsInterface, msgHash *common.Hash) (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 GetHashFunc ¶
GetHashFunc returns the nth block hash in the blockchain and is used by the BLOCKHASH EVM op code.
type NetworkRelayInterface ¶
type PrecompiledContract ¶
type QueryResult ¶
type QueryResult struct {
// contains filtered or unexported fields
}