Documentation ¶
Overview ¶
Package vm implements the Ethereum Virtual Machine.
The vm package implements one EVM, a byte code VM. The BC (Byte Code) VM loops over a set of bytes and executes them according to the set of rules defined in the Ethereum yellow paper.
Index ¶
- Constants
- Variables
- func ActivateableEips() []string
- func ActivePrecompiles(rules *chain.Rules) []libcommon.Address
- func CheckCfg(code []byte, proof *CfgProof) bool
- func CompressProof(in []byte) []byte
- func DecompressProof(in []byte) []byte
- func EnableEIP(eipNum int, jt *JumpTable) error
- func Eq(st0 *astate, st1 *astate) bool
- func ExistsIn(values []AbsValue, value AbsValue) bool
- func Leq(st0 *astate, st1 *astate) bool
- func Lub(st0 *astate, st1 *astate) *astate
- func NewCodeAndHash(code []byte) *codeAndHash
- func RunPrecompiledContract(p PrecompiledContract, input []byte, suppliedGas uint64) (ret []byte, remainingGas uint64, err error)
- func StringifyAState(st *astate) [][]string
- func ToWordSize(size uint64) uint64
- func ValidEip(eipNum int) bool
- type AbsValue
- type AbsValueKind
- type AccountRef
- type Astmt
- type Block
- type CallContext
- type Cfg
- type CfgAbsSem
- type CfgCoverageStats
- type CfgMetrics
- type CfgOpSem
- type CfgProof
- type CfgProofBlock
- type CfgProofState
- type Config
- type Contract
- func (c *Contract) Address() libcommon.Address
- func (c *Contract) AsDelegate() *Contract
- func (c *Contract) Caller() libcommon.Address
- func (c *Contract) GetOp(n uint64) OpCode
- func (c *Contract) RefundGas(gas uint64, reason tracing.GasChangeReason)
- func (c *Contract) SetCallCode(addr *libcommon.Address, hash libcommon.Hash, code []byte)
- func (c *Contract) SetCodeOptionalHash(addr *libcommon.Address, codeAndHash *codeAndHash)
- func (c *Contract) UseGas(gas uint64, reason tracing.GasChangeReason) (ok bool)
- func (c *Contract) Value() *uint256.Int
- type ContractRef
- type EVM
- func (evm *EVM) Call(caller ContractRef, addr libcommon.Address, input []byte, gas uint64, ...) (ret []byte, leftOverGas uint64, err error)
- func (evm *EVM) CallCode(caller ContractRef, addr libcommon.Address, input []byte, gas uint64, ...) (ret []byte, leftOverGas uint64, err error)
- func (evm *EVM) CallGasTemp() uint64
- func (evm *EVM) Cancel()
- func (evm *EVM) Cancelled() bool
- func (evm *EVM) ChainConfig() *chain.Config
- func (evm *EVM) ChainRules() *chain.Rules
- func (evm *EVM) Config() Config
- func (evm *EVM) Create(caller ContractRef, code []byte, gasRemaining uint64, endowment *uint256.Int, ...) (ret []byte, contractAddr libcommon.Address, leftOverGas uint64, err error)
- func (evm *EVM) Create2(caller ContractRef, code []byte, gasRemaining uint64, endowment *uint256.Int, ...) (ret []byte, contractAddr libcommon.Address, leftOverGas uint64, err error)
- func (evm *EVM) DelegateCall(caller ContractRef, addr libcommon.Address, input []byte, gas uint64) (ret []byte, leftOverGas uint64, err error)
- func (evm *EVM) Interpreter() Interpreter
- func (evm *EVM) IntraBlockState() evmtypes.IntraBlockState
- func (evm *EVM) OverlayCreate(caller ContractRef, codeAndHash *codeAndHash, gas uint64, value *uint256.Int, ...) ([]byte, libcommon.Address, uint64, error)
- func (evm *EVM) Reset(txCtx evmtypes.TxContext, ibs evmtypes.IntraBlockState)
- func (evm *EVM) ResetBetweenBlocks(blockCtx evmtypes.BlockContext, txCtx evmtypes.TxContext, ...)
- func (evm *EVM) SetCallGasTemp(gas uint64)
- func (evm *EVM) StaticCall(caller ContractRef, addr libcommon.Address, input []byte, gas uint64) (ret []byte, leftOverGas uint64, err error)
- func (evm *EVM) SysCreate(caller ContractRef, code []byte, gas uint64, endowment *uint256.Int, ...) (ret []byte, leftOverGas uint64, err error)
- type EVMInterpreter
- type EVMLogger
- type ErrInvalidOpCode
- type ErrStackOverflow
- type ErrStackUnderflow
- type FlushableTracer
- type Interpreter
- type JumpDestCache
- type JumpTable
- type Memory
- func (m *Memory) Copy(dst, src, len uint64)
- func (m *Memory) Data() []byte
- func (m *Memory) GetCopy(offset, size int64) (cpy []byte)
- func (m *Memory) GetPtr(offset, size int64) []byte
- func (m *Memory) Len() int
- func (m *Memory) Reset()
- func (m *Memory) Resize(size uint64)
- func (m *Memory) Set(offset, size uint64, value []byte)
- func (m *Memory) Set32(offset uint64, val *uint256.Int)
- type OpCode
- type PrecompiledContract
- type Program
- type ScopeContext
- type VM
- type VMInterface
- type VMInterpreter
Constants ¶
const ( GasQuickStep uint64 = 2 GasFastestStep uint64 = 3 GasFastStep uint64 = 5 GasMidStep uint64 = 8 GasSlowStep uint64 = 10 GasExtStep uint64 = 20 )
Gas costs
Variables ¶
var ( PrecompiledAddressesPrague []libcommon.Address PrecompiledAddressesNapoli []libcommon.Address PrecompiledAddressesCancun []libcommon.Address PrecompiledAddressesBerlin []libcommon.Address PrecompiledAddressesIstanbul []libcommon.Address PrecompiledAddressesByzantium []libcommon.Address PrecompiledAddressesHomestead []libcommon.Address )
var ( // ErrInvalidSubroutineEntry means that a BEGINSUB was reached via iteration, // as opposed to from a JUMPSUB instruction ErrInvalidSubroutineEntry = errors.New("invalid subroutine entry") ErrOutOfGas = errors.New("out of gas") ErrCodeStoreOutOfGas = errors.New("contract creation code storage out of gas") ErrDepth = errors.New("max call depth exceeded") ErrInsufficientBalance = errors.New("insufficient balance for transfer") ErrContractAddressCollision = errors.New("contract address collision") ErrExecutionReverted = errors.New("execution reverted") ErrMaxCodeSizeExceeded = errors.New("max code size exceeded") ErrMaxInitCodeSizeExceeded = errors.New("max initcode size exceeded") ErrInvalidJump = errors.New("invalid jump destination") ErrWriteProtection = errors.New("write protection") ErrReturnDataOutOfBounds = errors.New("return data out of bounds") ErrGasUintOverflow = errors.New("gas uint64 overflow") ErrInvalidRetsub = errors.New("invalid retsub") ErrReturnStackExceeded = errors.New("return stack limit reached") ErrInvalidCode = errors.New("invalid code") ErrNonceUintOverflow = errors.New("nonce uint64 overflow") )
List evm execution errors
var PrecompiledContractsBerlin = map[libcommon.Address]PrecompiledContract{ libcommon.BytesToAddress([]byte{1}): &ecrecover{}, libcommon.BytesToAddress([]byte{2}): &sha256hash{}, libcommon.BytesToAddress([]byte{3}): &ripemd160hash{}, libcommon.BytesToAddress([]byte{4}): &dataCopy{}, libcommon.BytesToAddress([]byte{5}): &bigModExp{eip2565: true}, libcommon.BytesToAddress([]byte{6}): &bn256AddIstanbul{}, libcommon.BytesToAddress([]byte{7}): &bn256ScalarMulIstanbul{}, libcommon.BytesToAddress([]byte{8}): &bn256PairingIstanbul{}, libcommon.BytesToAddress([]byte{9}): &blake2F{}, }
PrecompiledContractsBerlin contains the default set of pre-compiled Ethereum contracts used in the Berlin release.
var PrecompiledContractsByzantium = map[libcommon.Address]PrecompiledContract{ libcommon.BytesToAddress([]byte{1}): &ecrecover{}, libcommon.BytesToAddress([]byte{2}): &sha256hash{}, libcommon.BytesToAddress([]byte{3}): &ripemd160hash{}, libcommon.BytesToAddress([]byte{4}): &dataCopy{}, libcommon.BytesToAddress([]byte{5}): &bigModExp{eip2565: false}, libcommon.BytesToAddress([]byte{6}): &bn256AddByzantium{}, libcommon.BytesToAddress([]byte{7}): &bn256ScalarMulByzantium{}, libcommon.BytesToAddress([]byte{8}): &bn256PairingByzantium{}, }
PrecompiledContractsByzantium contains the default set of pre-compiled Ethereum contracts used in the Byzantium release.
var PrecompiledContractsCancun = map[libcommon.Address]PrecompiledContract{ libcommon.BytesToAddress([]byte{0x01}): &ecrecover{}, libcommon.BytesToAddress([]byte{0x02}): &sha256hash{}, libcommon.BytesToAddress([]byte{0x03}): &ripemd160hash{}, libcommon.BytesToAddress([]byte{0x04}): &dataCopy{}, libcommon.BytesToAddress([]byte{0x05}): &bigModExp{eip2565: true}, libcommon.BytesToAddress([]byte{0x06}): &bn256AddIstanbul{}, libcommon.BytesToAddress([]byte{0x07}): &bn256ScalarMulIstanbul{}, libcommon.BytesToAddress([]byte{0x08}): &bn256PairingIstanbul{}, libcommon.BytesToAddress([]byte{0x09}): &blake2F{}, libcommon.BytesToAddress([]byte{0x0a}): &pointEvaluation{}, }
var PrecompiledContractsHomestead = map[libcommon.Address]PrecompiledContract{ libcommon.BytesToAddress([]byte{1}): &ecrecover{}, libcommon.BytesToAddress([]byte{2}): &sha256hash{}, libcommon.BytesToAddress([]byte{3}): &ripemd160hash{}, libcommon.BytesToAddress([]byte{4}): &dataCopy{}, }
PrecompiledContractsHomestead contains the default set of pre-compiled Ethereum contracts used in the Frontier and Homestead releases.
var PrecompiledContractsIstanbul = map[libcommon.Address]PrecompiledContract{ libcommon.BytesToAddress([]byte{1}): &ecrecover{}, libcommon.BytesToAddress([]byte{2}): &sha256hash{}, libcommon.BytesToAddress([]byte{3}): &ripemd160hash{}, libcommon.BytesToAddress([]byte{4}): &dataCopy{}, libcommon.BytesToAddress([]byte{5}): &bigModExp{eip2565: false}, libcommon.BytesToAddress([]byte{6}): &bn256AddIstanbul{}, libcommon.BytesToAddress([]byte{7}): &bn256ScalarMulIstanbul{}, libcommon.BytesToAddress([]byte{8}): &bn256PairingIstanbul{}, libcommon.BytesToAddress([]byte{9}): &blake2F{}, }
PrecompiledContractsIstanbul contains the default set of pre-compiled Ethereum contracts used in the Istanbul release.
var PrecompiledContractsNapoli = map[libcommon.Address]PrecompiledContract{ libcommon.BytesToAddress([]byte{0x01}): &ecrecover{}, libcommon.BytesToAddress([]byte{0x02}): &sha256hash{}, libcommon.BytesToAddress([]byte{0x03}): &ripemd160hash{}, libcommon.BytesToAddress([]byte{0x04}): &dataCopy{}, libcommon.BytesToAddress([]byte{0x05}): &bigModExp{eip2565: true}, libcommon.BytesToAddress([]byte{0x06}): &bn256AddIstanbul{}, libcommon.BytesToAddress([]byte{0x07}): &bn256ScalarMulIstanbul{}, libcommon.BytesToAddress([]byte{0x08}): &bn256PairingIstanbul{}, libcommon.BytesToAddress([]byte{0x09}): &blake2F{}, libcommon.BytesToAddress([]byte{0x01, 0x00}): &p256Verify{}, }
var PrecompiledContractsPrague = map[libcommon.Address]PrecompiledContract{ libcommon.BytesToAddress([]byte{0x01}): &ecrecover{}, libcommon.BytesToAddress([]byte{0x02}): &sha256hash{}, libcommon.BytesToAddress([]byte{0x03}): &ripemd160hash{}, libcommon.BytesToAddress([]byte{0x04}): &dataCopy{}, libcommon.BytesToAddress([]byte{0x05}): &bigModExp{eip2565: true}, libcommon.BytesToAddress([]byte{0x06}): &bn256AddIstanbul{}, libcommon.BytesToAddress([]byte{0x07}): &bn256ScalarMulIstanbul{}, libcommon.BytesToAddress([]byte{0x08}): &bn256PairingIstanbul{}, libcommon.BytesToAddress([]byte{0x09}): &blake2F{}, libcommon.BytesToAddress([]byte{0x0a}): &pointEvaluation{}, libcommon.BytesToAddress([]byte{0x0b}): &bls12381G1Add{}, libcommon.BytesToAddress([]byte{0x0c}): &bls12381G1Mul{}, libcommon.BytesToAddress([]byte{0x0d}): &bls12381G1MultiExp{}, libcommon.BytesToAddress([]byte{0x0e}): &bls12381G2Add{}, libcommon.BytesToAddress([]byte{0x0f}): &bls12381G2Mul{}, libcommon.BytesToAddress([]byte{0x10}): &bls12381G2MultiExp{}, libcommon.BytesToAddress([]byte{0x11}): &bls12381Pairing{}, libcommon.BytesToAddress([]byte{0x12}): &bls12381MapFpToG1{}, libcommon.BytesToAddress([]byte{0x13}): &bls12381MapFp2ToG2{}, }
Functions ¶
func ActivateableEips ¶
func ActivateableEips() []string
func ActivePrecompiles ¶
ActivePrecompiles returns the precompiles enabled with the current configuration.
func CompressProof ¶
func DecompressProof ¶
func EnableEIP ¶
EnableEIP enables the given EIP on the config. This operation writes in-place, and callers need to ensure that the globally defined jump tables are not polluted.
func NewCodeAndHash ¶
func NewCodeAndHash(code []byte) *codeAndHash
func RunPrecompiledContract ¶
func RunPrecompiledContract(p PrecompiledContract, input []byte, suppliedGas uint64, ) (ret []byte, remainingGas uint64, err error)
RunPrecompiledContract runs and evaluates the output of a precompiled contract. It returns - the returned bytes, - the _remaining_ gas, - any error that occurred
func StringifyAState ¶
func StringifyAState(st *astate) [][]string
func ToWordSize ¶
ToWordSize returns the ceiled word size required for memory expansion.
Types ¶
type AbsValue ¶
type AbsValue struct {
// contains filtered or unexported fields
}
func AbsValueConcrete ¶
func AbsValueDestringify ¶
func AbsValueInvalid ¶
func AbsValueInvalid() AbsValue
func AbsValueTop ¶
type AbsValueKind ¶
type AbsValueKind int
////////////////////////////////////////////////
const ( BotValue AbsValueKind = iota TopValue InvalidValue ConcreteValue )
func (AbsValueKind) String ¶
func (d AbsValueKind) String() string
type AccountRef ¶
AccountRef implements ContractRef.
Account references are used during EVM 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() libcommon.Address
Address casts AccountRef to a Address
type Astmt ¶
type Astmt struct {
// contains filtered or unexported fields
}
stmt is the representation of an executable instruction - extension of an opcode
type CallContext ¶
type CallContext interface { // Call another contract Call(env *EVM, me ContractRef, addr libcommon.Address, data []byte, gas, value *big.Int) ([]byte, error) // Take another's contract code and execute within our own context CallCode(env *EVM, me ContractRef, addr libcommon.Address, data []byte, gas, value *big.Int) ([]byte, error) // Same as CallCode except sender and value is propagated from parent to child scope DelegateCall(env *EVM, me ContractRef, addr libcommon.Address, data []byte, gas *big.Int) ([]byte, error) // Create a new contract Create(env *EVM, me ContractRef, data []byte, gas, value *big.Int) ([]byte, libcommon.Address, error) }
CallContext provides a basic interface for the EVM calling conventions. The EVM depends on this context being implemented for doing subcalls and initialising new EVM contracts.
type Cfg ¶
type Cfg struct { Program *Program BadJumps map[int]bool PrevEdgeMap map[int]map[int]bool D map[int]*astate Metrics *CfgMetrics ProofSerialized []byte }
func (*Cfg) GenerateProof ¶
func (*Cfg) GetCoverageStats ¶
func (cfg *Cfg) GetCoverageStats() CfgCoverageStats
func (*Cfg) PrintAnlyState ¶
func (cfg *Cfg) PrintAnlyState()
type CfgAbsSem ¶
func NewCfgAbsSem ¶
func NewCfgAbsSem() *CfgAbsSem
type CfgCoverageStats ¶
type CfgMetrics ¶
type CfgMetrics struct { Valid bool Panic bool Unresolved bool ShortStack bool AnlyCounterLimit bool LowCoverage bool BadJumpImprecision bool BadJumpInvalidOp bool BadJumpInvalidJumpDest bool StackCountLimitReached bool OOM bool Timeout bool Checker bool CheckerFailed bool AnlyCounter int NumStacks int ProofSizeBytes int Time time.Duration MemUsedMBs uint64 }
func (*CfgMetrics) GetBadJumpReason ¶
func (metrics *CfgMetrics) GetBadJumpReason() string
type CfgProofBlock ¶
type CfgProofBlock struct { Entry *CfgProofState Exit *CfgProofState Preds []int Succs []int }
type CfgProofState ¶
-1 block id is invalid jump
type Config ¶
type Config struct { Debug bool // Enables debugging Tracer EVMLogger // Opcode logger NoRecursion bool // Disables call, callcode, delegate call and create NoBaseFee bool // Forces the EIP-1559 baseFee to 0 (needed for 0 price calls) SkipAnalysis bool // Whether we can skip jumpdest analysis based on the checked history TraceJumpDest bool // Print transaction hashes where jumpdest analysis was useful NoReceipts bool // Do not calculate receipts ReadOnly bool // Do no perform any block finalisation StatelessExec bool // true is certain conditions (like state trie root hash matching) need to be relaxed for stateless EVM execution RestoreState bool // Revert all changes made to the state (useful for constant system calls) ExtraEips []int // Additional EIPS that are to be enabled }
Config are the configuration options for the Interpreter
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 libcommon.Address Code []byte CodeHash libcommon.Hash CodeAddr *libcommon.Address Input []byte Gas uint64 // contains filtered or unexported fields }
Contract represents an ethereum contract in the state database. It contains the contract code, calling arguments. Contract implements ContractRef
func NewContract ¶
func NewContract(caller ContractRef, addr libcommon.Address, value *uint256.Int, gas uint64, skipAnalysis bool, jumpDest *JumpDestCache) *Contract
NewContract returns a new contract environment for the execution of EVM.
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) RefundGas ¶
func (c *Contract) RefundGas(gas uint64, reason tracing.GasChangeReason)
RefundGas refunds gas to the contract
func (*Contract) SetCallCode ¶
SetCallCode sets the code of the contract and address of the backing data object
func (*Contract) SetCodeOptionalHash ¶
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 EVM ¶
type EVM struct { // Context provides auxiliary blockchain related information Context evmtypes.BlockContext evmtypes.TxContext JumpDestCache *JumpDestCache // 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(blockCtx evmtypes.BlockContext, txCtx evmtypes.TxContext, state evmtypes.IntraBlockState, chainConfig *chain.Config, vmConfig Config) *EVM
NewEVM returns a new EVM. The returned EVM is not thread safe and should only ever be used *once*.
func (*EVM) Call ¶
func (evm *EVM) Call(caller ContractRef, addr libcommon.Address, input []byte, gas uint64, value *uint256.Int, bailout 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 (*EVM) CallCode ¶
func (evm *EVM) CallCode(caller ContractRef, addr libcommon.Address, input []byte, gas uint64, value *uint256.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 (*EVM) CallGasTemp ¶
CallGasTemp returns the callGasTemp for the EVM
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 ¶
ChainConfig returns the environment's chain configuration
func (*EVM) ChainRules ¶
ChainRules returns the environment's chain rules
func (*EVM) Create ¶
func (evm *EVM) Create(caller ContractRef, code []byte, gasRemaining uint64, endowment *uint256.Int, bailout bool) (ret []byte, contractAddr libcommon.Address, leftOverGas uint64, err error)
Create creates a new contract using code as deployment code. DESCRIBED: docs/programmers_guide/guide.md#nonce
func (*EVM) Create2 ¶
func (evm *EVM) Create2(caller ContractRef, code []byte, gasRemaining uint64, endowment *uint256.Int, salt *uint256.Int, bailout bool) (ret []byte, contractAddr libcommon.Address, leftOverGas uint64, err error)
Create2 creates a new contract using code as deployment code.
The different between Create2 with Create is Create2 uses keccak256(0xff ++ msg.sender ++ salt ++ keccak256(init_code))[12:] instead of the usual sender-and-nonce-hash as the address where the contract is initialized at. DESCRIBED: docs/programmers_guide/guide.md#nonce
func (*EVM) DelegateCall ¶
func (evm *EVM) DelegateCall(caller ContractRef, addr libcommon.Address, 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 (*EVM) Interpreter ¶
func (evm *EVM) Interpreter() Interpreter
Interpreter returns the current interpreter
func (*EVM) IntraBlockState ¶
func (evm *EVM) IntraBlockState() evmtypes.IntraBlockState
IntraBlockState returns the EVM's IntraBlockState
func (*EVM) OverlayCreate ¶
func (*EVM) Reset ¶
func (evm *EVM) Reset(txCtx evmtypes.TxContext, ibs evmtypes.IntraBlockState)
Reset resets the EVM with a new transaction context.Reset This is not threadsafe and should only be done very cautiously.
func (*EVM) ResetBetweenBlocks ¶
func (evm *EVM) ResetBetweenBlocks(blockCtx evmtypes.BlockContext, txCtx evmtypes.TxContext, ibs evmtypes.IntraBlockState, vmConfig Config, chainRules *chain.Rules)
func (*EVM) SetCallGasTemp ¶
SetCallGasTemp sets the callGasTemp for the EVM
func (*EVM) StaticCall ¶
func (evm *EVM) StaticCall(caller ContractRef, addr libcommon.Address, 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.
func (*EVM) SysCreate ¶
func (evm *EVM) SysCreate(caller ContractRef, code []byte, gas uint64, endowment *uint256.Int, contractAddr libcommon.Address) (ret []byte, leftOverGas uint64, err error)
SysCreate is a special (system) contract creation methods for genesis constructors. Unlike the normal Create & Create2, it doesn't increment caller's nonce.
type EVMInterpreter ¶
type EVMInterpreter struct { *VM // contains filtered or unexported fields }
EVMInterpreter represents an EVM interpreter
func NewEVMInterpreter ¶
func NewEVMInterpreter(evm *EVM, cfg Config) *EVMInterpreter
NewEVMInterpreter returns a new instance of the Interpreter.
func (*EVMInterpreter) Depth ¶
func (in *EVMInterpreter) Depth() int
Depth returns the current call stack depth.
func (*EVMInterpreter) Run ¶
func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) (ret []byte, err error)
Run loops and evaluates the contract's code with the given input data and returns the return byte-slice and an error if one occurred.
It's important to note that any errors returned by the interpreter should be considered a revert-and-consume-all-gas operation except for ErrExecutionReverted which means revert-and-keep-gas-left.
type EVMLogger ¶
type EVMLogger interface { // Transaction level CaptureTxStart(gasLimit uint64) CaptureTxEnd(restGas uint64) // Top call frame CaptureStart(env *EVM, from libcommon.Address, to libcommon.Address, precompile bool, create bool, input []byte, gas uint64, value *uint256.Int, code []byte) CaptureEnd(output []byte, usedGas uint64, err error) // Rest of the frames CaptureEnter(typ OpCode, from libcommon.Address, to libcommon.Address, precompile bool, create bool, input []byte, gas uint64, value *uint256.Int, code []byte) CaptureExit(output []byte, usedGas uint64, err error) // Opcode level CaptureState(pc uint64, op OpCode, gas, cost uint64, scope *ScopeContext, rData []byte, depth int, err error) CaptureFault(pc uint64, op OpCode, gas, cost uint64, scope *ScopeContext, depth int, 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.
type ErrInvalidOpCode ¶
type ErrInvalidOpCode struct {
// contains filtered or unexported fields
}
ErrInvalidOpCode wraps an evm error when an invalid opcode is encountered.
func (*ErrInvalidOpCode) Error ¶
func (e *ErrInvalidOpCode) Error() string
type ErrStackOverflow ¶
type ErrStackOverflow struct {
// contains filtered or unexported fields
}
ErrStackOverflow wraps an evm error when the items on the stack exceeds the maximum allowance.
func (*ErrStackOverflow) Error ¶
func (e *ErrStackOverflow) Error() string
type ErrStackUnderflow ¶
type ErrStackUnderflow struct {
// contains filtered or unexported fields
}
ErrStackUnderflow wraps an evm error when the items on the stack less than the minimal requirement.
func (*ErrStackUnderflow) Error ¶
func (e *ErrStackUnderflow) Error() string
type FlushableTracer ¶
type FlushableTracer interface { EVMLogger Flush(tx types.Transaction) }
FlushableTracer is a Tracer extension whose accumulated traces has to be flushed once the tracing is completed.
type Interpreter ¶
type Interpreter interface { // Run loops and evaluates the contract's code with the given input data and returns // the return byte-slice and an error if one occurred. Run(contract *Contract, input []byte, static bool) ([]byte, error) // `Depth` returns the current call stack's depth. Depth() int }
Interpreter is used to run Ethereum based 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 JumpDestCache ¶
type JumpDestCache struct { *simplelru.LRU[libcommon.Hash, bitvec] // contains filtered or unexported fields }
func NewJumpDestCache ¶
func NewJumpDestCache() *JumpDestCache
func (*JumpDestCache) LogStats ¶
func (c *JumpDestCache) LogStats()
type JumpTable ¶
type JumpTable [256]*operation
JumpTable contains the EVM opcodes supported at a given fork.
type Memory ¶
type Memory struct {
// contains filtered or unexported fields
}
Memory implements a simple memory model for the ethereum virtual machine.
func (*Memory) Copy ¶
Copy copies data from the src position slice into the dst position. The source and destination may overlap. OBS: This operation assumes that any necessary memory expansion has already been performed, and this method may panic otherwise.
type OpCode ¶
type OpCode byte
OpCode is an EVM opcode
0x0 range - arithmetic ops.
const ( LT OpCode = iota + 0x10 GT SLT SGT EQ ISZERO AND OR XOR NOT BYTE SHL SHR SAR KECCAK256 OpCode = 0x20 )
0x10 range - comparison ops.
const ( ADDRESS OpCode = 0x30 + iota BALANCE ORIGIN CALLER CALLVALUE CALLDATALOAD CALLDATASIZE CALLDATACOPY CODESIZE CODECOPY GASPRICE EXTCODESIZE EXTCODECOPY RETURNDATASIZE RETURNDATACOPY EXTCODEHASH )
0x30 range - closure state.
const ( BLOCKHASH OpCode = 0x40 COINBASE OpCode = 0x41 TIMESTAMP OpCode = 0x42 NUMBER OpCode = 0x43 DIFFICULTY OpCode = 0x44 GASLIMIT OpCode = 0x45 CHAINID OpCode = 0x46 SELFBALANCE OpCode = 0x47 BASEFEE OpCode = 0x48 BLOBHASH OpCode = 0x49 BLOBBASEFEE OpCode = 0x4a )
0x40 range - block operations.
const ( POP OpCode = 0x50 MLOAD OpCode = 0x51 MSTORE OpCode = 0x52 MSTORE8 OpCode = 0x53 SLOAD OpCode = 0x54 SSTORE OpCode = 0x55 JUMP OpCode = 0x56 JUMPI OpCode = 0x57 PC OpCode = 0x58 MSIZE OpCode = 0x59 GAS OpCode = 0x5a JUMPDEST OpCode = 0x5b TLOAD OpCode = 0x5c TSTORE OpCode = 0x5d MCOPY OpCode = 0x5e PUSH0 OpCode = 0x5f )
0x50 range - 'storage' and execution.
const ( PUSH1 OpCode = 0x60 + iota PUSH2 PUSH3 PUSH4 PUSH5 PUSH6 PUSH7 PUSH8 PUSH9 PUSH10 PUSH11 PUSH12 PUSH13 PUSH14 PUSH15 PUSH16 PUSH17 PUSH18 PUSH19 PUSH20 PUSH21 PUSH22 PUSH23 PUSH24 PUSH25 PUSH26 PUSH27 PUSH28 PUSH29 PUSH30 PUSH31 PUSH32 DUP1 DUP2 DUP3 DUP4 DUP5 DUP6 DUP7 DUP8 DUP9 DUP10 DUP11 DUP12 DUP13 DUP14 DUP15 DUP16 SWAP1 SWAP2 SWAP3 SWAP4 SWAP5 SWAP6 SWAP7 SWAP8 SWAP9 SWAP10 SWAP11 SWAP12 SWAP13 SWAP14 SWAP15 SWAP16 )
0x60 range.
const ( CREATE OpCode = 0xf0 + iota CALL CALLCODE RETURN DELEGATECALL CREATE2 STATICCALL OpCode = 0xfa REVERT OpCode = 0xfd INVALID OpCode = 0xfe SELFDESTRUCT OpCode = 0xff )
0xf0 range - closures.
func StringToOp ¶
StringToOp finds the opcode whose name is stored in `str`.
func (OpCode) IsStaticJump ¶
IsStaticJump specifies if an opcode is JUMP.
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 Program ¶
type Program struct { Code []byte Stmts []*Astmt Blocks []*Block Entry2block map[int]*Block Exit2block map[int]*Block }
func (*Program) GetCodeHex ¶
type ScopeContext ¶
ScopeContext contains the things that are per-call, such as stack and memory, but not transients like pc and gas
type VM ¶
type VM struct {
// contains filtered or unexported fields
}
structcheck doesn't see embedding
type VMInterface ¶
type VMInterface interface { Reset(txCtx evmtypes.TxContext, ibs evmtypes.IntraBlockState) Create(caller ContractRef, code []byte, gas uint64, value *uint256.Int) (ret []byte, contractAddr libcommon.Address, leftOverGas uint64, err error) Call(caller ContractRef, addr libcommon.Address, input []byte, gas uint64, value *uint256.Int, bailout bool) (ret []byte, leftOverGas uint64, err error) Cancel() Config() Config ChainConfig() *chain.Config ChainRules() *chain.Rules Context() evmtypes.BlockContext IntraBlockState() evmtypes.IntraBlockState TxContext() evmtypes.TxContext }
VMInterface exposes the EVM interface for external callers.
type VMInterpreter ¶
type VMInterpreter interface { VMInterface Cancelled() bool SetCallGasTemp(gas uint64) CallGasTemp() uint64 StaticCall(caller ContractRef, addr libcommon.Address, input []byte, gas uint64) (ret []byte, leftOverGas uint64, err error) DelegateCall(caller ContractRef, addr libcommon.Address, input []byte, gas uint64) (ret []byte, leftOverGas uint64, err error) CallCode(caller ContractRef, addr libcommon.Address, input []byte, gas uint64, value *uint256.Int) (ret []byte, leftOverGas uint64, err error) Create2(caller ContractRef, code []byte, gas uint64, endowment *uint256.Int, salt *uint256.Int) (ret []byte, contractAddr libcommon.Address, leftOverGas uint64, err error) }
VMInterpreter exposes additional EVM methods for use in the interpreter.
Source Files ¶
- absint_cfg.go
- absint_cfg_proof_check.go
- absint_cfg_proof_gen.go
- analysis.go
- common.go
- contract.go
- contracts.go
- doc.go
- eips.go
- errors.go
- evm.go
- gas.go
- gas_table.go
- instructions.go
- interface.go
- interpreter.go
- jump_table.go
- logger.go
- memory.go
- memory_table.go
- mock_vm.go
- opcodes.go
- operations_acl.go
- stack_table.go