@ethereumjs/statemanager / DefaultStateManager
Default StateManager implementation for the VM.
The state manager abstracts from the underlying data store by providing higher level access to accounts, contract code and storage slots.
The default state manager implementation uses a
@ethereumjs/trie trie as a data backend.
EVMStateManagerInterface• new DefaultStateManager(opts?)
Instantiate the StateManager interface.
| Name | Type | 
|---|---|
opts | 
      DefaultStateManagerOpts | 
    
• Readonly common: Common
• originalStorageCache: OriginalStorageCache
EVMStateManagerInterface.originalStorageCache
▸ addProofData(proof, safe?): Promise<void>
Add proof(s) into an already existing trie
| Name | Type | Default value | Description | 
|---|---|---|---|
proof | 
      Proof | Proof[] | 
      undefined | 
      The proof(s) retrieved from getProof | 
    
safe | 
      boolean | 
      false | 
      - | 
Promise<void>
▸ checkpoint(): Promise<void>
Checkpoints the current state of the StateManager instance.
State changes that follow can then be committed by calling
commit or reverted by calling rollback.
Promise<void>
EVMStateManagerInterface.checkpoint
▸ clearCaches(): void
Clears all underlying caches
void
▸ clearContractStorage(address): Promise<void>
Clears all storage entries for the account corresponding to address.
| Name | Type | Description | 
|---|---|---|
address | 
      Address | 
      Address to clear the storage of | 
Promise<void>
EVMStateManagerInterface.clearContractStorage
▸ commit(): Promise<void>
Commits the current change-set to the instance since the last call to checkpoint.
Promise<void>
EVMStateManagerInterface.commit
▸ deleteAccount(address): Promise<void>
Deletes an account from state under the provided address.
| Name | Type | Description | 
|---|---|---|
address | 
      Address | 
      Address of the account which should be deleted | 
Promise<void>
EVMStateManagerInterface.deleteAccount
▸ dumpStorage(address): Promise<StorageDump>
Dumps the RLP-encoded storage values for an account specified by address.
| Name | Type | Description | 
|---|---|---|
address | 
      Address | 
      The address of the account to return storage for | 
    
Promise<StorageDump>
Object map.
Keys are are the storage keys, values are the storage values as strings.
Both are represented as hex strings without the 0x prefix.EVMStateManagerInterface.dumpStorage
▸ dumpStorageRange(address, startKey, limit): Promise<StorageRange>
Dumps a limited number of RLP-encoded storage values for an account specified by address,
starting from startKey or greater.
| Name | Type | Description | 
|---|---|---|
address | 
      Address | 
      The address of the account to return storage for. | 
    
startKey | 
      bigint | 
      The bigint representation of the smallest storage key that will be returned. | 
limit | 
      number | 
      The maximum number of storage values that will be returned. | 
Promise<StorageRange>
limit entries in its storage field.
The object will also contain nextKey, the next (hashed) storage key after the range included in storage.EVMStateManagerInterface.dumpStorageRange
▸ flush(): Promise<void>
Writes all cache items to the trie
Promise<void>
▸ generateCanonicalGenesis(initState): Promise<void>
Initializes the provided genesis state into the state trie. Will error if there are uncommitted checkpoints on the instance.
| Name | Type | Description | 
|---|---|---|
initState | 
      any | 
      address -> balance | [balance, code, storage] | 
Promise<void>
EVMStateManagerInterface.generateCanonicalGenesis
▸ getAccount(address): Promise<undefined | Account>
Gets the account associated with address or undefined if account does not exist
| Name | Type | Description | 
|---|---|---|
address | 
      Address | 
      Address of the account to get | 
    
Promise<undefined | Account>
EVMStateManagerInterface.getAccount
▸ getAppliedKey(address): Uint8Array
Returns the applied key for a given address Used for saving preimages
| Name | Type | Description | 
|---|---|---|
address | 
      Uint8Array | 
      The address to return the applied key | 
Uint8Array
EVMStateManagerInterface.getAppliedKey
▸ getContractCode(address): Promise<Uint8Array>
Gets the code corresponding to the provided address.
| Name | Type | Description | 
|---|---|---|
address | 
      Address | 
      Address to get the code for | 
    
Promise<Uint8Array>
Uint8Array if the account has no associated code.EVMStateManagerInterface.getContractCode
▸ getContractStorage(address, key): Promise<Uint8Array>
Gets the storage value associated with the provided address and key. This method returns
the shortest representation of the stored value.
| Name | Type | Description | 
|---|---|---|
address | 
      Address | 
      Address of the account to get the storage for | 
key | 
      Uint8Array | 
      Key in the account’s storage to get the value for. Must be 32 bytes long. | 
Promise<Uint8Array>
Uint8Array is returned.EVMStateManagerInterface.getContractStorage
▸ getProof(address, storageSlots?): Promise<Proof>
Get an EIP-1186 proof
| Name | Type | Default value | Description | 
|---|---|---|---|
address | 
      Address | 
      undefined | 
      address to get proof of | 
storageSlots | 
      Uint8Array[] | 
      [] | 
      storage slots to get proof of | 
Promise<Proof>
EVMStateManagerInterface.getProof
▸ getStateRoot(): Promise<Uint8Array>
Gets the state-root of the Merkle-Patricia trie representation of the state of this StateManager. Will error if there are uncommitted checkpoints on the instance.
Promise<Uint8Array>
StateManagerEVMStateManagerInterface.getStateRoot
▸ hasStateRoot(root): Promise<boolean>
Checks whether there is a state corresponding to a stateRoot
| Name | Type | 
|---|---|
root | 
      Uint8Array | 
    
Promise<boolean>
EVMStateManagerInterface.hasStateRoot
▸ modifyAccountFields(address, accountFields): Promise<void>
Gets the account associated with address, modifies the given account
fields, then saves the account into state. Account fields can include
nonce, balance, storageRoot, and codeHash.
| Name | Type | Description | 
|---|---|---|
address | 
      Address | 
      Address of the account to modify | 
accountFields | 
      Partial<Pick<Account, "nonce" | "balance" | "storageRoot" | "codeHash">> | 
      Object containing account fields and values to modify | 
Promise<void>
EVMStateManagerInterface.modifyAccountFields
▸ putAccount(address, account): Promise<void>
Saves an account into state under the provided address.
| Name | Type | Description | 
|---|---|---|
address | 
      Address | 
      Address under which to store account | 
    
account | 
      undefined | Account | 
      The account to store or undefined if to be deleted | 
Promise<void>
EVMStateManagerInterface.putAccount
▸ putContractCode(address, value): Promise<void>
Adds value to the state trie as code, and sets codeHash on the account
corresponding to address to reference this.
| Name | Type | Description | 
|---|---|---|
address | 
      Address | 
      Address of the account to add the code for | 
    
value | 
      Uint8Array | 
      The value of the code | 
    
Promise<void>
EVMStateManagerInterface.putContractCode
▸ putContractStorage(address, key, value): Promise<void>
Adds value to the state trie for the account
corresponding to address at the provided key.
| Name | Type | Description | 
|---|---|---|
address | 
      Address | 
      Address to set a storage value for | 
key | 
      Uint8Array | 
      Key to set the value at. Must be 32 bytes long. | 
value | 
      Uint8Array | 
      Value to set at key for account corresponding to address. Cannot be more than 32 bytes. Leading zeros are stripped. If it is a empty or filled with zeros, deletes the value. | 
    
Promise<void>
EVMStateManagerInterface.putContractStorage
▸ revert(): Promise<void>
Reverts the current change-set to the instance since the last call to checkpoint.
Promise<void>
EVMStateManagerInterface.revert
▸ setStateRoot(stateRoot, clearCache?): Promise<void>
Sets the state of the instance to that represented
by the provided stateRoot. Will error if there are uncommitted
checkpoints on the instance or if the state root does not exist in
the state trie.
| Name | Type | Default value | Description | 
|---|---|---|---|
stateRoot | 
      Uint8Array | 
      undefined | 
      The state-root to reset the instance to | 
clearCache | 
      boolean | 
      true | 
      - | 
Promise<void>
EVMStateManagerInterface.setStateRoot
▸ shallowCopy(downlevelCaches?): DefaultStateManager
Copies the current instance of the StateManager
at the last fully committed point, i.e. as if all current
checkpoints were reverted.
Caches are downleveled (so: adopted for short-term usage) by default.
This means in particular:
Both adoptions can be deactivated by setting downlevelCaches to
false.
Cache values are generally not copied along regardless of the
downlevelCaches setting.
| Name | Type | Default value | 
|---|---|---|
downlevelCaches | 
      boolean | 
      true | 
    
EVMStateManagerInterface.shallowCopy
▸ verifyProof(proof): Promise<boolean>
Verify an EIP-1186 proof. Throws if proof is invalid, otherwise returns true.
| Name | Type | Description | 
|---|---|---|
proof | 
      Proof | 
      the proof to prove | 
Promise<boolean>
▸ Static fromProof(proof, safe?, opts?): Promise<DefaultStateManager>
Create a StateManager and initialize this with proof(s) gotten previously from getProof This generates a (partial) StateManager where one can retrieve all items from the proof
| Name | Type | Default value | Description | 
|---|---|---|---|
proof | 
      Proof | Proof[] | 
      undefined | 
      Either a proof retrieved from getProof, or an array of those proofs | 
    
safe | 
      boolean | 
      false | 
      Whether or not to verify that the roots of the proof items match the reported roots | 
opts | 
      DefaultStateManagerOpts | 
      {} | 
      a dictionary of StateManager opts | 
Promise<DefaultStateManager>
A new DefaultStateManager with elements from the given proof included in its backing state trie