Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VM, Client: Remove ProofStateManager interface #1660

Merged
merged 2 commits into from
Jan 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions packages/client/lib/rpc/modules/eth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion packages/vm/src/state/index.ts
Original file line number Diff line number Diff line change
@@ -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'
12 changes: 2 additions & 10 deletions packages/vm/src/state/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export interface StateManager {
accountExists(address: Address): Promise<boolean>
cleanupTouchedAccounts(): Promise<void>
clearOriginalStorageCache(): void
getProof?(address: Address, storageSlots: Buffer[]): Promise<Proof>
verifyProof?(proof: Proof): Promise<boolean>
}

export interface EIP2929StateManager extends StateManager {
Expand All @@ -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:
* <EIP2929StateManager & ProofStateManager>(StateManager)
*/
export interface ProofStateManager extends StateManager {
getProof(address: Address, storageSlots: Buffer[]): Promise<Proof>
verifyProof(proof: Proof): Promise<boolean>
}