github.com/0xPolygon/supernets2-node@v0.0.0-20230711153321-2fe574524eaa/state/runtime/fakevm/fakedb.go (about)

     1  package fakevm
     2  
     3  import (
     4  	"math/big"
     5  
     6  	"github.com/ethereum/go-ethereum/common"
     7  	"github.com/ethereum/go-ethereum/core/types"
     8  	"github.com/ethereum/go-ethereum/params"
     9  )
    10  
    11  // FakeDB is the interface state access for the FakeEVM
    12  type FakeDB interface {
    13  	SetStateRoot(stateRoot []byte)
    14  	CreateAccount(common.Address)
    15  
    16  	SubBalance(common.Address, *big.Int)
    17  	AddBalance(common.Address, *big.Int)
    18  	GetBalance(common.Address) *big.Int
    19  
    20  	GetNonce(common.Address) uint64
    21  	SetNonce(common.Address, uint64)
    22  
    23  	GetCodeHash(common.Address) common.Hash
    24  	GetCode(common.Address) []byte
    25  	SetCode(common.Address, []byte)
    26  	GetCodeSize(common.Address) int
    27  
    28  	AddRefund(uint64)
    29  	SubRefund(uint64)
    30  	GetRefund() uint64
    31  
    32  	GetCommittedState(common.Address, common.Hash) common.Hash
    33  	GetState(common.Address, common.Hash) common.Hash
    34  	SetState(common.Address, common.Hash, common.Hash)
    35  
    36  	GetTransientState(addr common.Address, key common.Hash) common.Hash
    37  	SetTransientState(addr common.Address, key, value common.Hash)
    38  
    39  	Suicide(common.Address) bool
    40  	HasSuicided(common.Address) bool
    41  
    42  	// Exist reports whether the given account exists in state.
    43  	// Notably this should also return true for suicided accounts.
    44  	Exist(common.Address) bool
    45  	// Empty returns whether the given account is empty. Empty
    46  	// is defined according to EIP161 (balance = nonce = code = 0).
    47  	Empty(common.Address) bool
    48  
    49  	AddressInAccessList(addr common.Address) bool
    50  	SlotInAccessList(addr common.Address, slot common.Hash) (addressOk bool, slotOk bool)
    51  	// AddAddressToAccessList adds the given address to the access list. This operation is safe to perform
    52  	// even if the feature/fork is not active yet
    53  	AddAddressToAccessList(addr common.Address)
    54  	// AddSlotToAccessList adds the given (address,slot) to the access list. This operation is safe to perform
    55  	// even if the feature/fork is not active yet
    56  	AddSlotToAccessList(addr common.Address, slot common.Hash)
    57  	Prepare(rules params.Rules, sender, coinbase common.Address, dest *common.Address, precompiles []common.Address, txAccesses types.AccessList)
    58  
    59  	RevertToSnapshot(int)
    60  	Snapshot() int
    61  
    62  	AddLog(*types.Log)
    63  	AddPreimage(common.Hash, []byte)
    64  }
    65  
    66  // CallContext provides a basic interface for the EVM calling conventions. The EVM
    67  // depends on this context being implemented for doing subcalls and initialising new EVM contracts.
    68  type CallContext interface {
    69  	// Call calls another contract.
    70  	Call(env *FakeEVM, me ContractRef, addr common.Address, data []byte, gas, value *big.Int) ([]byte, error)
    71  	// CallCode takes another contracts code and execute within our own context
    72  	CallCode(env *FakeEVM, me ContractRef, addr common.Address, data []byte, gas, value *big.Int) ([]byte, error)
    73  	// DelegateCall is same as CallCode except sender and value is propagated from parent to child scope
    74  	DelegateCall(env *FakeEVM, me ContractRef, addr common.Address, data []byte, gas *big.Int) ([]byte, error)
    75  	// Create creates a new contract
    76  	Create(env *FakeEVM, me ContractRef, data []byte, gas, value *big.Int) ([]byte, common.Address, error)
    77  }