evm

package
v2.3.0-rc7 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2025 License: Apache-2.0 Imports: 35 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// CodeKVNameSpace is the bucket name for code
	CodeKVNameSpace = state.CodeKVNameSpace
	// ContractKVNameSpace is the bucket name for contract data storage
	ContractKVNameSpace = state.ContractKVNameSpace
	// PreimageKVNameSpace is the bucket name for preimage data storage
	PreimageKVNameSpace = state.PreimageKVNameSpace
)

Variables

View Source
var (

	// ErrInconsistentNonce is the error that the nonce is different from executor's nonce
	ErrInconsistentNonce = errors.New("Nonce is not identical to executor nonce")
)

Functions

func CanTransfer

func CanTransfer(db vm.StateDB, fromHash common.Address, balance *uint256.Int) bool

CanTransfer checks whether the from account has enough balance

func ExecuteContract

func ExecuteContract(
	ctx context.Context,
	sm protocol.StateManager,
	execution action.TxData,
) ([]byte, *action.Receipt, error)

ExecuteContract processes a transfer which contains a contract

func ExtractRevertMessage added in v2.3.0

func ExtractRevertMessage(ret []byte) string

ExtractRevertMessage extracts the revert message from the return value

func MakeTransfer

func MakeTransfer(db vm.StateDB, fromHash, toHash common.Address, amount *uint256.Int)

MakeTransfer transfers account

func NewChainConfig added in v2.3.0

func NewChainConfig(ctx context.Context) (*params.ChainConfig, error)

NewChainConfig creates a new chain config

func NewErigonRules added in v2.3.0

func NewErigonRules(rules *params.Rules) *erigonchain.Rules

NewErigonRules creates a new Erigon rules

func NewTracerWrapper added in v2.3.0

func NewTracerWrapper(tracer vm.EVMLogger) vm.EVMLogger

NewTracerWrapper wraps the EVMLogger

func ReadContractCode added in v2.3.0

func ReadContractCode(
	ctx context.Context,
	sm protocol.StateManager,
	contract address.Address,
) ([]byte, error)

ReadContractCode reads contract's code

func ReadContractStorage

func ReadContractStorage(
	ctx context.Context,
	sm protocol.StateManager,
	contract address.Address,
	key []byte,
) ([]byte, error)

ReadContractStorage reads contract's storage

func SimulateExecution

func SimulateExecution(
	ctx context.Context,
	sm protocol.StateManager,
	caller address.Address,
	ex action.TxDataForSimulation,
	opts ...protocol.SimulateOption,
) ([]byte, *action.Receipt, error)

SimulateExecution simulates the execution in evm

func TraceEnd added in v2.3.0

func TraceEnd(ctx context.Context, ws protocol.StateManager, elp action.Envelope, receipt *action.Receipt)

TraceEnd ends tracing the execution of the action in the sealed envelope

func TraceStart added in v2.3.0

func TraceStart(ctx context.Context, ws protocol.StateManager, elp action.Envelope) error

TraceStart starts tracing the execution of the action in the sealed envelope

func WithHelperCtx

func WithHelperCtx(ctx context.Context, hctx HelperContext) context.Context

WithHelperCtx returns a new context with helper context

func WithTracerCtx added in v2.3.0

func WithTracerCtx(ctx context.Context, tctx TracerContext) context.Context

WithTracerCtx returns a new context with tracer context

Types

type Contract

type Contract interface {
	GetCommittedState(hash.Hash256) ([]byte, error)
	GetState(hash.Hash256) ([]byte, error)
	SetState(hash.Hash256, []byte) error
	GetCode() ([]byte, error)
	SetCode(hash.Hash256, []byte)
	SelfState() *state.Account
	Commit() error
	LoadRoot() error
	Iterator() (trie.Iterator, error)
	Snapshot() Contract
}

Contract is a special type of account with code and storage trie.

type ErigonStateDBAdapter added in v2.3.0

type ErigonStateDBAdapter struct {
	*StateDBAdapter
	// contains filtered or unexported fields
}

ErigonStateDBAdapter is an adapter for persisted both in erigon intra block state and statedb reads are based on statedb

func NewErigonStateDBAdapter added in v2.3.0

func NewErigonStateDBAdapter(adapter *StateDBAdapter,
	intra *erigonstate.IntraBlockState,
) *ErigonStateDBAdapter

NewErigonStateDBAdapter creates a new ErigonStateDBAdapter

func (*ErigonStateDBAdapter) AddAddressToAccessList added in v2.3.0

func (s *ErigonStateDBAdapter) AddAddressToAccessList(addr common.Address)

AddAddressToAccessList adds the given address to the access list

func (*ErigonStateDBAdapter) AddBalance added in v2.3.0

func (s *ErigonStateDBAdapter) AddBalance(evmAddr common.Address, v *uint256.Int)

AddBalance adds the balance of the given address by the given value

func (*ErigonStateDBAdapter) AddLog added in v2.3.0

func (s *ErigonStateDBAdapter) AddLog(l *types.Log)

AddLog adds a log to the state database

func (*ErigonStateDBAdapter) AddPreimage added in v2.3.0

func (s *ErigonStateDBAdapter) AddPreimage(k common.Hash, v []byte)

AddPreimage adds a preimage to the state database

func (*ErigonStateDBAdapter) AddRefund added in v2.3.0

func (s *ErigonStateDBAdapter) AddRefund(r uint64)

AddRefund adds the refund of the given address

func (*ErigonStateDBAdapter) AddSlotToAccessList added in v2.3.0

func (s *ErigonStateDBAdapter) AddSlotToAccessList(addr common.Address, slot common.Hash)

AddSlotToAccessList adds the given slot to the access list

func (*ErigonStateDBAdapter) CommitContracts added in v2.3.0

func (s *ErigonStateDBAdapter) CommitContracts() error

CommitContracts commits the contracts to the state database

func (*ErigonStateDBAdapter) CreateAccount added in v2.3.0

func (s *ErigonStateDBAdapter) CreateAccount(evmAddr common.Address)

CreateAccount creates a new account in the state database

func (*ErigonStateDBAdapter) Prepare added in v2.3.0

func (s *ErigonStateDBAdapter) Prepare(rules params.Rules, sender, coinbase common.Address, dest *common.Address, precompiles []common.Address, txAccesses types.AccessList)

Prepare prepares the state database

func (*ErigonStateDBAdapter) RevertToSnapshot added in v2.3.0

func (s *ErigonStateDBAdapter) RevertToSnapshot(sn int)

RevertToSnapshot reverts the state database to the given snapshot

func (*ErigonStateDBAdapter) SelfDestruct added in v2.3.0

func (s *ErigonStateDBAdapter) SelfDestruct(evmAddr common.Address)

SelfDestruct marks the given address for self-destruction

func (*ErigonStateDBAdapter) Selfdestruct6780 added in v2.3.0

func (s *ErigonStateDBAdapter) Selfdestruct6780(evmAddr common.Address)

Selfdestruct6780 marks the given address for self-destruction

func (*ErigonStateDBAdapter) SetCode added in v2.3.0

func (s *ErigonStateDBAdapter) SetCode(evmAddr common.Address, c []byte)

SetCode set the code of the given address

func (*ErigonStateDBAdapter) SetNonce added in v2.3.0

func (s *ErigonStateDBAdapter) SetNonce(evmAddr common.Address, n uint64)

SetNonce sets the nonce of the given address

func (*ErigonStateDBAdapter) SetState added in v2.3.0

func (s *ErigonStateDBAdapter) SetState(evmAddr common.Address, k common.Hash, v common.Hash)

SetState set the state of the given address

func (*ErigonStateDBAdapter) Snapshot added in v2.3.0

func (s *ErigonStateDBAdapter) Snapshot() int

Snapshot creates a snapshot of the state database

func (*ErigonStateDBAdapter) SubBalance added in v2.3.0

func (s *ErigonStateDBAdapter) SubBalance(evmAddr common.Address, v *uint256.Int)

SubBalance subtracts the balance of the given address by the given value

func (*ErigonStateDBAdapter) SubRefund added in v2.3.0

func (s *ErigonStateDBAdapter) SubRefund(r uint64)

SubRefund subtracts the refund of the given address

type ErigonStateDBAdapterDryrun added in v2.3.0

type ErigonStateDBAdapterDryrun struct {
	*ErigonStateDBAdapter
}

ErigonStateDBAdapterDryrun is an adapter for simulation reads are based on erigon intra block state, writes not persisted

func NewErigonStateDBAdapterDryrun added in v2.3.0

func NewErigonStateDBAdapterDryrun(adapter *StateDBAdapter,
	intra *erigonstate.IntraBlockState,
) *ErigonStateDBAdapterDryrun

NewErigonStateDBAdapterDryrun creates a new ErigonStateDBAdapterDryrun

func (*ErigonStateDBAdapterDryrun) GetCode added in v2.3.0

func (stateDB *ErigonStateDBAdapterDryrun) GetCode(evmAddr common.Address) []byte

GetCode gets the code saved in hash

func (*ErigonStateDBAdapterDryrun) GetCodeHash added in v2.3.0

func (stateDB *ErigonStateDBAdapterDryrun) GetCodeHash(evmAddr common.Address) common.Hash

GetCodeHash gets the code hash saved in hash

func (*ErigonStateDBAdapterDryrun) GetCodeSize added in v2.3.0

func (stateDB *ErigonStateDBAdapterDryrun) GetCodeSize(evmAddr common.Address) int

GetCodeSize gets the code size saved in hash

type GetBlockHash

type GetBlockHash func(uint64) (hash.Hash256, error)

GetBlockHash gets block hash by height

type GetBlockTime

type GetBlockTime func(uint64) (time.Time, error)

GetBlockTime gets block time by height

type HelperContext

type HelperContext struct {
	GetBlockHash   GetBlockHash
	GetBlockTime   GetBlockTime
	DepositGasFunc protocol.DepositGas
}

HelperContext is the context for EVM helper

type Params

type Params struct {
	// contains filtered or unexported fields
}

Params is the context and parameters

type StateDBAdapter

type StateDBAdapter struct {
	// contains filtered or unexported fields
}

StateDBAdapter represents the state db adapter for evm to access iotx blockchain

func NewStateDBAdapter

func NewStateDBAdapter(
	sm protocol.StateManager,
	blockHeight uint64,
	executionHash hash.Hash256,
	opts ...StateDBAdapterOption,
) (*StateDBAdapter, error)

NewStateDBAdapter creates a new state db with iotex blockchain

func (*StateDBAdapter) AddAddressToAccessList

func (stateDB *StateDBAdapter) AddAddressToAccessList(addr common.Address)

AddAddressToAccessList adds the given address to the access list. This operation is safe to perform even if the feature/fork is not active yet

func (*StateDBAdapter) AddBalance

func (stateDB *StateDBAdapter) AddBalance(evmAddr common.Address, a256 *uint256.Int)

AddBalance adds balance to account

func (*StateDBAdapter) AddLog

func (stateDB *StateDBAdapter) AddLog(evmLog *types.Log)

AddLog adds log whose transaction amount is larger than 0

func (*StateDBAdapter) AddPreimage

func (stateDB *StateDBAdapter) AddPreimage(hash common.Hash, preimage []byte)

AddPreimage adds the preimage of a hash

func (*StateDBAdapter) AddRefund

func (stateDB *StateDBAdapter) AddRefund(gas uint64)

AddRefund adds refund

func (*StateDBAdapter) AddSlotToAccessList

func (stateDB *StateDBAdapter) AddSlotToAccessList(addr common.Address, slot common.Hash)

AddSlotToAccessList adds the given (address,slot) to the access list. This operation is safe to perform even if the feature/fork is not active yet

func (*StateDBAdapter) AddressInAccessList

func (stateDB *StateDBAdapter) AddressInAccessList(addr common.Address) bool

AddressInAccessList returns true if the given address is in the access list

func (*StateDBAdapter) CommitContracts

func (stateDB *StateDBAdapter) CommitContracts() error

CommitContracts commits contract code to db and update pending contract account changes to trie

func (*StateDBAdapter) CreateAccount

func (stateDB *StateDBAdapter) CreateAccount(evmAddr common.Address)

CreateAccount creates an account in iotx blockchain

func (*StateDBAdapter) Empty

func (stateDB *StateDBAdapter) Empty(evmAddr common.Address) bool

Empty returns true if the contract is empty

func (*StateDBAdapter) Error

func (stateDB *StateDBAdapter) Error() error

Error returns the first stored error during evm contract execution

func (*StateDBAdapter) Exist

func (stateDB *StateDBAdapter) Exist(evmAddr common.Address) bool

Exist checks the existence of an address

func (*StateDBAdapter) ForEachStorage

func (stateDB *StateDBAdapter) ForEachStorage(addr common.Address, cb func(common.Hash, common.Hash) bool) error

ForEachStorage loops each storage

func (*StateDBAdapter) GetBalance

func (stateDB *StateDBAdapter) GetBalance(evmAddr common.Address) *uint256.Int

GetBalance gets the balance of account

func (*StateDBAdapter) GetCode

func (stateDB *StateDBAdapter) GetCode(evmAddr common.Address) []byte

GetCode returns contract's code

func (*StateDBAdapter) GetCodeHash

func (stateDB *StateDBAdapter) GetCodeHash(evmAddr common.Address) common.Hash

GetCodeHash returns contract's code hash

func (*StateDBAdapter) GetCodeSize

func (stateDB *StateDBAdapter) GetCodeSize(evmAddr common.Address) int

GetCodeSize gets the code size saved in hash

func (*StateDBAdapter) GetCommittedState

func (stateDB *StateDBAdapter) GetCommittedState(evmAddr common.Address, k common.Hash) common.Hash

GetCommittedState gets committed state

func (*StateDBAdapter) GetNonce

func (stateDB *StateDBAdapter) GetNonce(evmAddr common.Address) uint64

GetNonce gets the nonce of account

func (*StateDBAdapter) GetRefund

func (stateDB *StateDBAdapter) GetRefund() uint64

GetRefund gets refund

func (*StateDBAdapter) GetState

func (stateDB *StateDBAdapter) GetState(evmAddr common.Address, k common.Hash) common.Hash

GetState gets state

func (*StateDBAdapter) GetTransientState

func (stateDB *StateDBAdapter) GetTransientState(addr common.Address, key common.Hash) common.Hash

GetTransientState gets transient storage for a given account.

func (*StateDBAdapter) HasSelfDestructed

func (stateDB *StateDBAdapter) HasSelfDestructed(evmAddr common.Address) bool

HasSelfDestructed returns whether the contract has been killed

func (*StateDBAdapter) IsNewAccount

func (stateDB *StateDBAdapter) IsNewAccount(evmAddr common.Address) bool

IsNewAccount returns true if this is a new account

func (*StateDBAdapter) Logs

func (stateDB *StateDBAdapter) Logs() []*action.Log

Logs returns the logs

func (*StateDBAdapter) Prepare

func (stateDB *StateDBAdapter) Prepare(rules params.Rules, sender, coinbase common.Address, dst *common.Address, precompiles []common.Address, list types.AccessList)

Prepare handles the preparatory steps for executing a state transition with. This method must be invoked before state transition.

Berlin fork: - Add sender to access list (2929) - Add destination to access list (2929) - Add precompiles to access list (2929) - Add the contents of the optional tx access list (2930)

Potential EIPs: - Reset access list (Berlin) - Add coinbase to access list (EIP-3651) - Reset transient storage (EIP-1153)

func (*StateDBAdapter) RevertToSnapshot

func (stateDB *StateDBAdapter) RevertToSnapshot(snapshot int)

RevertToSnapshot reverts the state factory to the state at a given snapshot

func (*StateDBAdapter) SelfDestruct

func (stateDB *StateDBAdapter) SelfDestruct(evmAddr common.Address)

SelfDestruct kills the contract

func (*StateDBAdapter) Selfdestruct6780

func (stateDB *StateDBAdapter) Selfdestruct6780(evmAddr common.Address)

Selfdestruct6780 implements EIP-6780

func (*StateDBAdapter) SetCode

func (stateDB *StateDBAdapter) SetCode(evmAddr common.Address, code []byte)

SetCode sets contract's code

func (*StateDBAdapter) SetNonce

func (stateDB *StateDBAdapter) SetNonce(evmAddr common.Address, nonce uint64)

SetNonce sets the nonce of account

func (*StateDBAdapter) SetState

func (stateDB *StateDBAdapter) SetState(evmAddr common.Address, k, v common.Hash)

SetState sets state

func (*StateDBAdapter) SetTransientState

func (stateDB *StateDBAdapter) SetTransientState(addr common.Address, key, value common.Hash)

SetTransientState sets transient storage for a given account

func (*StateDBAdapter) SlotInAccessList

func (stateDB *StateDBAdapter) SlotInAccessList(addr common.Address, slot common.Hash) (addressOk bool, slotOk bool)

SlotInAccessList returns true if the given (address, slot)-tuple is in the access list

func (*StateDBAdapter) Snapshot

func (stateDB *StateDBAdapter) Snapshot() int

Snapshot returns the snapshot id

func (*StateDBAdapter) SubBalance

func (stateDB *StateDBAdapter) SubBalance(evmAddr common.Address, a256 *uint256.Int)

SubBalance subtracts balance from account

func (*StateDBAdapter) SubRefund

func (stateDB *StateDBAdapter) SubRefund(gas uint64)

SubRefund subtracts refund

func (*StateDBAdapter) TransactionLogs

func (stateDB *StateDBAdapter) TransactionLogs() []*action.TransactionLog

TransactionLogs returns the transaction logs

type StateDBAdapterOption

type StateDBAdapterOption func(*StateDBAdapter) error

StateDBAdapterOption set StateDBAdapter construction param

func AsyncContractTrieOption

func AsyncContractTrieOption() StateDBAdapterOption

AsyncContractTrieOption set asyncContractTrie as true

func DisableSortCachedContractsOption

func DisableSortCachedContractsOption() StateDBAdapterOption

DisableSortCachedContractsOption set disable sort cached contracts as true

func EnableCancunEVMOption

func EnableCancunEVMOption() StateDBAdapterOption

EnableCancunEVMOption indicates that Cancun EVM is activated

func FixRevertSnapshotOption added in v2.0.7

func FixRevertSnapshotOption() StateDBAdapterOption

FixRevertSnapshotOption set fixRevertSnapshot as true

func FixSnapshotOrderOption

func FixSnapshotOrderOption() StateDBAdapterOption

FixSnapshotOrderOption set fixSnapshotOrder as true

func LegacyNonceAccountOption

func LegacyNonceAccountOption() StateDBAdapterOption

LegacyNonceAccountOption set legacyNonceAccount as true

func ManualCorrectGasRefundOption

func ManualCorrectGasRefundOption() StateDBAdapterOption

ManualCorrectGasRefundOption set manualCorrectGasRefund as true

func NotFixTopicCopyBugOption

func NotFixTopicCopyBugOption() StateDBAdapterOption

NotFixTopicCopyBugOption set notFixTopicCopyBug as true

func PanicUnrecoverableErrorOption

func PanicUnrecoverableErrorOption() StateDBAdapterOption

PanicUnrecoverableErrorOption set panicUnrecoverableError as true

func RevertLogOption

func RevertLogOption() StateDBAdapterOption

RevertLogOption set revertLog as true

func SuicideTxLogMismatchPanicOption

func SuicideTxLogMismatchPanicOption() StateDBAdapterOption

SuicideTxLogMismatchPanicOption set suicideTxLogMismatchPanic as true

func UseConfirmedNonceOption

func UseConfirmedNonceOption() StateDBAdapterOption

UseConfirmedNonceOption set usePendingNonce as true

func WithContext added in v2.1.1

func WithContext(ctx context.Context) StateDBAdapterOption

func ZeroNonceForFreshAccountOption

func ZeroNonceForFreshAccountOption() StateDBAdapterOption

ZeroNonceForFreshAccountOption set zeroNonceForFreshAccount as true

type TracerContext added in v2.3.0

type TracerContext struct {
	CaptureTx func([]byte, *action.Receipt)
}

TracerContext is the context for EVM tracer

func GetTracerCtx added in v2.3.0

func GetTracerCtx(ctx context.Context) (TracerContext, bool)

GetTracerCtx returns the tracer context from the context

Jump to

Keyboard shortcuts

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