evm

package
v0.0.0-...-739d23a Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2024 License: Apache-2.0 Imports: 43 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrAlreadyKnown is returned if the transactions is already contained
	// within the pool.
	ErrAlreadyKnown = errors.New("already known")

	ErrNotFoundReceipt = errors.New("receipt not found")
)

From geth/core/txpool/errors

Functions

func AdaptHash

func AdaptHash(ethHash common.Hash) yu_common.Hash

func ConvertBigIntToUint256

func ConvertBigIntToUint256(b *big.Int) *uint256.Int

func ConvertHashToYuHash

func ConvertHashToYuHash(hash common.Hash) (yu_common.Hash, error)

func LoadChainConfig

func LoadChainConfig(db ethdb.Database, genesis *Genesis) (*params.ChainConfig, error)

LoadChainConfig loads the stored chain config if it is already present in database, otherwise, return the config in the provided genesis specification.

func ObjToJson

func ObjToJson(obj interface{}) string

func SetupGenesisBlock

func SetupGenesisBlock(ethState *EthState, genesis *Genesis) (*params.ChainConfig, common.Hash, error)

SetupGenesisBlock writes or updates the genesis block in db. The block that will be used is:

                     genesis == nil       genesis != nil
                  +------------------------------------------
db has no genesis |  main-net default  |  genesis
db has genesis    |  from DB           |  genesis (if compatible)

The stored chain configuration will be updated if it is compatible (i.e. does not specify a fork block below the local head block). In case of a conflict, the error is a *params.ConfigCompatError and the new, unwritten config is returned.

The returned chain configuration is never nil.

func SetupGenesisBlockWithOverride

func SetupGenesisBlockWithOverride(ethState *EthState, genesis *Genesis, overrides *ChainOverrides) (*params.ChainConfig, common.Hash, error)

Types

type AccountInfo

type AccountInfo struct {
	Addr    *big.Int
	Balance *big.Int
	Misc    *struct {
		Nonce uint64
		Code  []byte
		Slots []struct {
			Key common.Hash
			Val common.Hash
		}
	} `rlp:"optional"`
}

type CallRequest

type CallRequest struct {
	Input    []byte         `json:"input"`
	Address  common.Address `json:"address"`
	Origin   common.Address `json:"origin"`
	GasLimit uint64         `json:"gasLimit"`
	GasPrice *big.Int       `json:"gasPrice"`
	Value    *big.Int       `json:"value"`
}

type CallResponse

type CallResponse struct {
	Ret         []byte `json:"ret"`
	LeftOverGas uint64 `json:"leftOverGas"`
	Err         error  `json:"err"`
}

type ChainOverrides

type ChainOverrides struct {
	OverrideCancun *uint64
	OverrideVerkle *uint64
}

ChainOverrides contains the changes to chain config.

type CreateRequest

type CreateRequest struct {
	Input    []byte         `json:"input"`
	Origin   common.Address `json:"origin"`
	GasLimit uint64         `json:"gasLimit"`
	GasPrice *big.Int       `json:"gasPrice"`
	Value    *big.Int       `json:"value"`
}

type EthState

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

func NewEthState

func NewEthState(cfg *config.Config, currentStateRoot common.Hash) (*EthState, error)

func (*EthState) Commit

func (s *EthState) Commit(blockNum uint64) (common.Hash, error)

func (*EthState) GenesisCommit

func (s *EthState) GenesisCommit() (common.Hash, error)

func (*EthState) GetNonce

func (s *EthState) GetNonce(addr common.Address) uint64

func (*EthState) Prepare

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

func (*EthState) SetNonce

func (s *EthState) SetNonce(addr common.Address, nonce uint64)

func (*EthState) SetStateDB

func (s *EthState) SetStateDB(d *state.StateDB)

func (*EthState) StateAt

func (s *EthState) StateAt(root common.Hash) (*state.StateDB, error)

func (*EthState) StateDB

func (s *EthState) StateDB() *state.StateDB

type Genesis

type Genesis struct {
	Config     *params.ChainConfig `json:"config"`
	Nonce      uint64              `json:"nonce"`
	Timestamp  uint64              `json:"timestamp"`
	ExtraData  []byte              `json:"extraData"`
	GasLimit   uint64              `json:"gasLimit"   gencodec:"required"`
	Difficulty *big.Int            `json:"difficulty" gencodec:"required"`
	Mixhash    common.Hash         `json:"mixHash"`
	Coinbase   common.Address      `json:"coinbase"`
	Alloc      types.GenesisAlloc  `json:"alloc"      gencodec:"required"`

	// These fields are used for consensus tests. Please don't use them
	// in actual genesis blocks.
	Number        uint64      `json:"number"`
	GasUsed       uint64      `json:"gasUsed"`
	ParentHash    common.Hash `json:"parentHash"`
	BaseFee       *big.Int    `json:"baseFeePerGas"` // EIP-1559
	ExcessBlobGas *uint64     `json:"excessBlobGas"` // EIP-4844
	BlobGasUsed   *uint64     `json:"blobGasUsed"`   // EIP-4844
}

Genesis specifies the header fields, state of a genesis block. It also defines hard fork switch-over blocks through the chain configuration.

func DefaultGenesisBlock

func DefaultGenesisBlock() *Genesis

DefaultGenesisBlock returns the Ethereum main net genesis block.

func DefaultGoerliGenesisBlock

func DefaultGoerliGenesisBlock() *Genesis

DefaultGoerliGenesisBlock returns the Görli network genesis block.

func DefaultHoleskyGenesisBlock

func DefaultHoleskyGenesisBlock() *Genesis

DefaultHoleskyGenesisBlock returns the Holesky network genesis block.

func DefaultSepoliaGenesisBlock

func DefaultSepoliaGenesisBlock() *Genesis

DefaultSepoliaGenesisBlock returns the Sepolia network genesis block.

func DeveloperGenesisBlock

func DeveloperGenesisBlock(gasLimit uint64, faucet *common.Address) *Genesis

DeveloperGenesisBlock returns the 'geth --dev' genesis block.

func ReadGenesis

func ReadGenesis(db ethdb.Database) (*Genesis, error)

func (*Genesis) Commit

func (g *Genesis) Commit(ethState *EthState) (*types.Block, error)

Commit writes the block and state of a genesis specification to the database. The block is committed as the canonical head block.

func (*Genesis) IsVerkle

func (g *Genesis) IsVerkle() bool

IsVerkle indicates whether the state is already stored in a verkle tree at genesis time.

func (*Genesis) MustCommit

func (g *Genesis) MustCommit(ethState *EthState) *types.Block

MustCommit writes the genesis block and state to db, panicking on error. The block is committed as the canonical head block.

func (*Genesis) ToBlock

func (g *Genesis) ToBlock() *types.Block

ToBlock returns the genesis block according to genesis specification.

type GenesisAccount deprecated

type GenesisAccount = types.Account

Deprecated: use types.Account instead.

type GenesisAlloc deprecated

type GenesisAlloc = types.GenesisAlloc

Deprecated: use types.GenesisAlloc instead.

type GenesisMismatchError

type GenesisMismatchError struct {
	Stored, New common.Hash
}

GenesisMismatchError is raised when trying to overwrite an existing genesis block with an incompatible one.

func (*GenesisMismatchError) Error

func (e *GenesisMismatchError) Error() string

type GethConfig

type GethConfig struct {
	ChainConfig *params.ChainConfig

	// BlockContext provides the EVM with auxiliary information. Once provided
	// it shouldn't be modified.
	GetHashFn   func(n uint64) common.Hash
	Coinbase    common.Address
	GasLimit    uint64
	BlockNumber *big.Int
	Time        uint64
	Difficulty  *big.Int
	BaseFee     *big.Int
	BlobBaseFee *big.Int
	Random      *common.Hash

	// TxContext provides the EVM with information about a transaction.
	// All fields can change between transactions.
	Origin     common.Address
	GasPrice   *big.Int
	BlobHashes []common.Hash
	BlobFeeCap *big.Int

	// StateDB gives access to the underlying state
	State *state.StateDB

	// Unknown
	Value     *big.Int
	Debug     bool
	EVMConfig vm.Config

	// Global config
	EnableEthRPC bool   `toml:"enable_eth_rpc"`
	EthHost      string `toml:"eth_host"`
	EthPort      string `toml:"eth_port"`
}

func LoadEvmConfig

func LoadEvmConfig(fpath string) *GethConfig

func SetDefaultGethConfig

func SetDefaultGethConfig() *GethConfig

sets defaults on the config

func (*GethConfig) Copy

func (gc *GethConfig) Copy() *GethConfig

type ReceiptRequest

type ReceiptRequest struct {
	Hash common.Hash `json:"hash"`
}

type ReceiptResponse

type ReceiptResponse struct {
	Receipt *types.Receipt `json:"receipt"`
	Err     error          `json:"err"`
}

type ReceiptsRequest

type ReceiptsRequest struct {
	Hashes []common.Hash `json:"hashes"`
}

type ReceiptsResponse

type ReceiptsResponse struct {
	Receipts []*types.Receipt `json:"receipts"`
	Err      error            `json:"err"`
}

type RevertError

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

RevertError is an API error that encompasses an EVM revert with JSON error code and a binary data blob.

func NewRevertError

func NewRevertError(revert []byte) *RevertError

NewRevertError creates a RevertError instance with the provided revert data.

func (*RevertError) ErrorCode

func (e *RevertError) ErrorCode() int

ErrorCode returns the JSON error code for a revert. See: https://github.com/ethereum/wiki/wiki/JSON-RPC-Error-Codes-Improvement-Proposal

func (*RevertError) ErrorData

func (e *RevertError) ErrorData() interface{}

ErrorData returns the hex encoded revert reason.

type Solidity

type Solidity struct {
	sync.RWMutex

	*tripod.Tripod
	// contains filtered or unexported fields
}

func NewSolidity

func NewSolidity(gethConfig *GethConfig) *Solidity

func (*Solidity) Call

func (s *Solidity) Call(ctx *context.ReadContext)

Call executes the code given by the contract's address. It will return the EVM's return value or an error if it failed.

func (*Solidity) Commit

func (s *Solidity) Commit(block *yu_types.Block)

func (*Solidity) EndBlock

func (s *Solidity) EndBlock(block *yu_types.Block)

func (*Solidity) ExecuteTxn

func (s *Solidity) ExecuteTxn(ctx *context.WriteContext) (err error)

ExecuteTxn executes the code using the input as call data during the execution. It returns the EVM's return value, the new state and an error if it failed.

Execute sets up an in-memory, temporary, environment for the execution of the given code. It makes sure that it's restored to its original state afterwards.

func (*Solidity) FinalizeBlock

func (s *Solidity) FinalizeBlock(block *yu_types.Block)

func (*Solidity) GetEthDB

func (s *Solidity) GetEthDB() ethdb.Database

func (*Solidity) GetReceipt

func (s *Solidity) GetReceipt(ctx *context.ReadContext)

func (*Solidity) GetReceipts

func (s *Solidity) GetReceipts(ctx *context.ReadContext)

func (*Solidity) InitChain

func (s *Solidity) InitChain(genesisBlock *yu_types.Block)

func (*Solidity) PreHandleTxn

func (s *Solidity) PreHandleTxn(txn *yu_types.SignedTxn) error

func (*Solidity) SetStateDB

func (s *Solidity) SetStateDB(d *state.StateDB)

func (*Solidity) StartBlock

func (s *Solidity) StartBlock(block *yu_types.Block)

func (*Solidity) StateAt

func (s *Solidity) StateAt(root common.Hash) (*state.StateDB, error)

func (*Solidity) StateDB

func (s *Solidity) StateDB() *state.StateDB

type TempTransactionArgs

type TempTransactionArgs struct {
	From                 *common.Address `json:"from"`
	To                   *common.Address `json:"to"`
	Gas                  *hexutil.Uint64 `json:"gas"`
	GasPrice             *hexutil.Big    `json:"gasPrice"`
	MaxFeePerGas         *hexutil.Big    `json:"maxFeePerGas"`
	MaxPriorityFeePerGas *hexutil.Big    `json:"maxPriorityFeePerGas"`
	Value                *hexutil.Big    `json:"value"`
	Nonce                *hexutil.Uint64 `json:"nonce"`

	// We accept "data" and "input" for backwards-compatibility reasons.
	// "input" is the newer name and should be preferred by clients.
	// Issue detail: https://github.com/ethereum/go-ethereum/issues/15628
	Data  *hexutil.Bytes `json:"data"`
	Input *hexutil.Bytes `json:"input"`

	// Introduced by AccessListTxType transaction.
	AccessList *types.AccessList `json:"accessList,omitempty"`
	ChainID    *hexutil.Big      `json:"chainId,omitempty"`

	// For BlobTxType
	BlobFeeCap *hexutil.Big  `json:"maxFeePerBlobGas"`
	BlobHashes []common.Hash `json:"blobVersionedHashes,omitempty"`

	// For BlobTxType transactions with blob sidecar
	Blobs       []kzg4844.Blob       `json:"blobs"`
	Commitments []kzg4844.Commitment `json:"commitments"`
	Proofs      []kzg4844.Proof      `json:"proofs"`
	// contains filtered or unexported fields
}

TransactionArgs represents the arguments to construct a new transaction or a message call.

func (*TempTransactionArgs) ToTransaction

func (args *TempTransactionArgs) ToTransaction(v, r, s *big.Int) *types.Transaction

ToTransaction converts the arguments to a transaction. This assumes that setDefaults has been called.

type TxIndexingError

type TxIndexingError struct{}

TxIndexingError is an API error that indicates the transaction indexing is not fully finished yet with JSON error code and a binary data blob.

func NewTxIndexingError

func NewTxIndexingError() *TxIndexingError

NewTxIndexingError creates a TxIndexingError instance.

func (*TxIndexingError) Error

func (e *TxIndexingError) Error() string

Error implement error interface, returning the error message.

func (*TxIndexingError) ErrorCode

func (e *TxIndexingError) ErrorCode() int

ErrorCode returns the JSON error code for a revert. See: https://github.com/ethereum/wiki/wiki/JSON-RPC-Error-Codes-Improvement-Proposal

func (*TxIndexingError) ErrorData

func (e *TxIndexingError) ErrorData() interface{}

ErrorData returns the hex encoded revert reason.

type TxRequest

type TxRequest struct {
	Input    []byte          `json:"input"`
	Address  *common.Address `json:"address"`
	Origin   common.Address  `json:"origin"`
	GasLimit uint64          `json:"gasLimit"`
	GasPrice *big.Int        `json:"gasPrice"`
	Value    *big.Int        `json:"value"`
	Hash     common.Hash     `json:"hash"`
	Nonce    uint64          `json:"nonce"`
	V        *big.Int        `json:"v"`
	R        *big.Int        `json:"r"`
	S        *big.Int        `json:"s"`

	OriginArgs []byte `json:"originArgs"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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