github.com/ethereum/go-ethereum@v1.14.4-0.20240516095835-473ee8fc07a3/core/vm/interface.go (about)

     1  // Copyright 2016 The go-ethereum Authors
     2  // This file is part of the go-ethereum library.
     3  //
     4  // The go-ethereum library is free software: you can redistribute it and/or modify
     5  // it under the terms of the GNU Lesser General Public License as published by
     6  // the Free Software Foundation, either version 3 of the License, or
     7  // (at your option) any later version.
     8  //
     9  // The go-ethereum library is distributed in the hope that it will be useful,
    10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    12  // GNU Lesser General Public License for more details.
    13  //
    14  // You should have received a copy of the GNU Lesser General Public License
    15  // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
    16  
    17  package vm
    18  
    19  import (
    20  	"math/big"
    21  
    22  	"github.com/ethereum/go-ethereum/common"
    23  	"github.com/ethereum/go-ethereum/core/tracing"
    24  	"github.com/ethereum/go-ethereum/core/types"
    25  	"github.com/ethereum/go-ethereum/params"
    26  	"github.com/ethereum/go-ethereum/trie/utils"
    27  	"github.com/holiman/uint256"
    28  )
    29  
    30  // StateDB is an EVM database for full state querying.
    31  type StateDB interface {
    32  	CreateAccount(common.Address)
    33  	CreateContract(common.Address)
    34  
    35  	SubBalance(common.Address, *uint256.Int, tracing.BalanceChangeReason)
    36  	AddBalance(common.Address, *uint256.Int, tracing.BalanceChangeReason)
    37  	GetBalance(common.Address) *uint256.Int
    38  
    39  	GetNonce(common.Address) uint64
    40  	SetNonce(common.Address, uint64)
    41  
    42  	GetCodeHash(common.Address) common.Hash
    43  	GetCode(common.Address) []byte
    44  	SetCode(common.Address, []byte)
    45  	GetCodeSize(common.Address) int
    46  
    47  	AddRefund(uint64)
    48  	SubRefund(uint64)
    49  	GetRefund() uint64
    50  
    51  	GetCommittedState(common.Address, common.Hash) common.Hash
    52  	GetState(common.Address, common.Hash) common.Hash
    53  	SetState(common.Address, common.Hash, common.Hash)
    54  	GetStorageRoot(addr common.Address) common.Hash
    55  
    56  	GetTransientState(addr common.Address, key common.Hash) common.Hash
    57  	SetTransientState(addr common.Address, key, value common.Hash)
    58  
    59  	SelfDestruct(common.Address)
    60  	HasSelfDestructed(common.Address) bool
    61  
    62  	Selfdestruct6780(common.Address)
    63  
    64  	// Exist reports whether the given account exists in state.
    65  	// Notably this should also return true for self-destructed accounts.
    66  	Exist(common.Address) bool
    67  	// Empty returns whether the given account is empty. Empty
    68  	// is defined according to EIP161 (balance = nonce = code = 0).
    69  	Empty(common.Address) bool
    70  
    71  	AddressInAccessList(addr common.Address) bool
    72  	SlotInAccessList(addr common.Address, slot common.Hash) (addressOk bool, slotOk bool)
    73  	// AddAddressToAccessList adds the given address to the access list. This operation is safe to perform
    74  	// even if the feature/fork is not active yet
    75  	AddAddressToAccessList(addr common.Address)
    76  	// AddSlotToAccessList adds the given (address,slot) to the access list. This operation is safe to perform
    77  	// even if the feature/fork is not active yet
    78  	AddSlotToAccessList(addr common.Address, slot common.Hash)
    79  
    80  	// PointCache returns the point cache used in computations
    81  	PointCache() *utils.PointCache
    82  
    83  	Prepare(rules params.Rules, sender, coinbase common.Address, dest *common.Address, precompiles []common.Address, txAccesses types.AccessList)
    84  
    85  	RevertToSnapshot(int)
    86  	Snapshot() int
    87  
    88  	AddLog(*types.Log)
    89  	AddPreimage(common.Hash, []byte)
    90  }
    91  
    92  // CallContext provides a basic interface for the EVM calling conventions. The EVM
    93  // depends on this context being implemented for doing subcalls and initialising new EVM contracts.
    94  type CallContext interface {
    95  	// Call calls another contract.
    96  	Call(env *EVM, me ContractRef, addr common.Address, data []byte, gas, value *big.Int) ([]byte, error)
    97  	// CallCode takes another contracts code and execute within our own context
    98  	CallCode(env *EVM, me ContractRef, addr common.Address, data []byte, gas, value *big.Int) ([]byte, error)
    99  	// DelegateCall is same as CallCode except sender and value is propagated from parent to child scope
   100  	DelegateCall(env *EVM, me ContractRef, addr common.Address, data []byte, gas *big.Int) ([]byte, error)
   101  	// Create creates a new contract
   102  	Create(env *EVM, me ContractRef, data []byte, gas, value *big.Int) ([]byte, common.Address, error)
   103  }