From b15612ffa12b6566504e8372d2cae4395430bd94 Mon Sep 17 00:00:00 2001 From: Holger Drewes Date: Sat, 22 Jan 2022 09:43:31 +0100 Subject: [PATCH] vm, client: removed ProofStateManager interface, added optional getProof, verifyProof methods to StateManager interface --- packages/client/lib/rpc/modules/eth.ts | 8 ++++++-- packages/vm/src/state/index.ts | 2 +- packages/vm/src/state/interface.ts | 12 ++---------- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/packages/client/lib/rpc/modules/eth.ts b/packages/client/lib/rpc/modules/eth.ts index eadd84a562..25eaca9368 100644 --- a/packages/client/lib/rpc/modules/eth.ts +++ b/packages/client/lib/rpc/modules/eth.ts @@ -31,7 +31,7 @@ import type { TxReceipt, } from '@ethereumjs/vm/dist/types' import type { Log } from '@ethereumjs/vm/dist/evm/types' -import type { Proof, ProofStateManager } from '@ethereumjs/vm/dist/state' +import type { Proof } from '@ethereumjs/vm/dist/state' import type { EthereumClient } from '../..' import type { Chain } from '../../blockchain' import type { EthProtocol } from '../../net/protocol' @@ -928,11 +928,15 @@ export class Eth { } const vm = this._vm.copy() + + if (!('getProof' in vm.stateManager)) { + throw new Error('getProof RPC method not supported with the StateManager provided') + } await vm.stateManager.setStateRoot(block.header.stateRoot) const address = Address.fromString(addressHex) const slots = slotsHex.map((slotHex) => setLengthLeft(toBuffer(slotHex), 32)) - const proof = await (vm.stateManager as ProofStateManager).getProof(address, slots) + const proof = await vm.stateManager.getProof!(address, slots) return proof } diff --git a/packages/vm/src/state/index.ts b/packages/vm/src/state/index.ts index d41ebe880e..50a9960b28 100644 --- a/packages/vm/src/state/index.ts +++ b/packages/vm/src/state/index.ts @@ -1,3 +1,3 @@ -export { StateManager, EIP2929StateManager, ProofStateManager } from './interface' +export { StateManager, EIP2929StateManager } from './interface' export { BaseStateManager } from './baseStateManager' export { default as DefaultStateManager, Proof } from './stateManager' diff --git a/packages/vm/src/state/interface.ts b/packages/vm/src/state/interface.ts index 349a803673..1e9179a514 100644 --- a/packages/vm/src/state/interface.ts +++ b/packages/vm/src/state/interface.ts @@ -34,6 +34,8 @@ export interface StateManager { accountExists(address: Address): Promise cleanupTouchedAccounts(): Promise clearOriginalStorageCache(): void + getProof?(address: Address, storageSlots: Buffer[]): Promise + verifyProof?(proof: Proof): Promise } export interface EIP2929StateManager extends StateManager { @@ -44,13 +46,3 @@ export interface EIP2929StateManager extends StateManager { clearWarmedAccounts(): void generateAccessList?(addressesRemoved: Address[], addressesOnlyStorage: Address[]): AccessList } - -/** - * Note: if a StateManager supports both EIP2929StateManager and - * the ProofStateManager interface, it can be cast as: - * (StateManager) - */ -export interface ProofStateManager extends StateManager { - getProof(address: Address, storageSlots: Buffer[]): Promise - verifyProof(proof: Proof): Promise -}