github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/fvm/evm/types/state.go (about) 1 package types 2 3 import ( 4 "math/big" 5 6 gethCommon "github.com/onflow/go-ethereum/common" 7 gethTypes "github.com/onflow/go-ethereum/core/types" 8 gethVM "github.com/onflow/go-ethereum/core/vm" 9 ) 10 11 // StateDB acts as the main interface to the EVM runtime 12 type StateDB interface { 13 gethVM.StateDB 14 15 // Commit commits the changes 16 // setting `finalize` flag 17 // calls a subsequent call to Finalize 18 // defering finalization and calling it once at the end 19 // improves efficiency of batch operations. 20 Commit(finalize bool) error 21 22 // Finalize flushes all the changes 23 // to the permanent storage 24 Finalize() error 25 26 // Logs collects and prepares logs 27 Logs( 28 blockNumber uint64, 29 txHash gethCommon.Hash, 30 txIndex uint, 31 ) []*gethTypes.Log 32 33 // Preimages returns a map of preimages 34 Preimages() map[gethCommon.Hash][]byte 35 36 // Reset resets uncommitted changes and transient artifacts such as error, logs, 37 // preimages, access lists, ... 38 // The method is often called between execution of different transactions 39 Reset() 40 } 41 42 // ReadOnlyView provides a readonly view of the state 43 type ReadOnlyView interface { 44 // Exist returns true if the address exist in the state 45 Exist(gethCommon.Address) (bool, error) 46 // IsCreated returns true if address has been created in this tx 47 IsCreated(gethCommon.Address) bool 48 // HasSelfDestructed returns true if an address has self destructed 49 // it also returns the balance of address before selfdestruction call 50 HasSelfDestructed(gethCommon.Address) (bool, *big.Int) 51 // GetBalance returns the balance of an address 52 GetBalance(gethCommon.Address) (*big.Int, error) 53 // GetNonce returns the nonce of an address 54 GetNonce(gethCommon.Address) (uint64, error) 55 // GetCode returns the code of an address 56 GetCode(gethCommon.Address) ([]byte, error) 57 // GetCodeHash returns the code hash of an address 58 GetCodeHash(gethCommon.Address) (gethCommon.Hash, error) 59 // GetCodeSize returns the code size of an address 60 GetCodeSize(gethCommon.Address) (int, error) 61 // GetState returns values for an slot in the main storage 62 GetState(SlotAddress) (gethCommon.Hash, error) 63 // GetTransientState returns values for an slot transient storage 64 GetTransientState(SlotAddress) gethCommon.Hash 65 // GetRefund returns the total amount of (gas) refund 66 GetRefund() uint64 67 // AddressInAccessList checks if an address is in the access list 68 AddressInAccessList(gethCommon.Address) bool 69 // SlotInAccessList checks if a slot is in the access list 70 SlotInAccessList(SlotAddress) (addressOk bool, slotOk bool) 71 } 72 73 // HotView captures a high-level mutable view of the state 74 type HotView interface { 75 ReadOnlyView 76 77 // CreateAccount creates a new account 78 CreateAccount(gethCommon.Address) error 79 // SelfDestruct set the flag for destruction of the account after execution 80 SelfDestruct(gethCommon.Address) error 81 82 // SubBalance subtracts the amount from the balance the given address 83 SubBalance(gethCommon.Address, *big.Int) error 84 // AddBalance adds the amount to the balance of the given address 85 AddBalance(gethCommon.Address, *big.Int) error 86 // SetNonce sets the nonce for the given address 87 SetNonce(gethCommon.Address, uint64) error 88 // SetCode sets the code for the given address 89 SetCode(gethCommon.Address, []byte) error 90 91 // SetState sets a value for the given slot in the main storage 92 SetState(SlotAddress, gethCommon.Hash) error 93 // SetTransientState sets a value for the given slot in the transient storage 94 SetTransientState(SlotAddress, gethCommon.Hash) 95 96 // AddRefund adds the amount to the total (gas) refund 97 AddRefund(uint64) error 98 // SubRefund subtracts the amount from the total (gas) refund 99 SubRefund(uint64) error 100 101 // AddAddressToAccessList adds an address to the per-transaction access list 102 AddAddressToAccessList(addr gethCommon.Address) (addressAdded bool) 103 // AddSlotToAccessList adds a slot to the per-transaction access list 104 AddSlotToAccessList(SlotAddress) (addressAdded, slotAdded bool) 105 106 // AddLog append a log to the log collection 107 AddLog(*gethTypes.Log) 108 // AddPreimage adds a preimage to the list of preimages (input -> hash mapping) 109 AddPreimage(gethCommon.Hash, []byte) 110 } 111 112 // BaseView is a low-level mutable view of the state 113 // baseview is usually updated at the commit calls to the higher level view 114 type BaseView interface { 115 ReadOnlyView 116 117 // Creates a new account 118 CreateAccount( 119 addr gethCommon.Address, 120 balance *big.Int, 121 nonce uint64, 122 code []byte, 123 codeHash gethCommon.Hash, 124 ) error 125 126 // UpdateAccount updates a account 127 UpdateAccount( 128 addr gethCommon.Address, 129 balance *big.Int, 130 nonce uint64, 131 code []byte, 132 codeHash gethCommon.Hash, 133 ) error 134 135 // DeleteAccount deletes an account 136 DeleteAccount(addr gethCommon.Address) error 137 138 // UpdateSlot updates the value for the given slot in the main storage 139 UpdateSlot( 140 slot SlotAddress, 141 value gethCommon.Hash, 142 ) error 143 144 // Commit commits the changes 145 Commit() error 146 } 147 148 // SlotAddress captures an address to a storage slot 149 type SlotAddress struct { 150 Address gethCommon.Address 151 Key gethCommon.Hash 152 }