Skip to content

Commit 1acacb8

Browse files
authored
EVM/Monorepo: Verkle Decoupling (#3462)
* EVM: Replace direct StatelessVerkleStateManager (SVSM) cast with verkle-extended interface usage * Add experimental AccessWitnessInterface to Common, use interface for AccessWitness implementation in StateManager * Use AccessWitnessInterface in EVM * Add verkle module to Util, replace EVM function calls, remove @ethereumjs/verkle dependency * Rebuild package-lock.json * Move VerkleCrypto type from verkle-cryptography-wasm to Util * Make verkleCrypto passing in mandatory in StatelessVerkleStateManager, remove async create constructor, move verkle-cryptography-wasm to dev dependenciew * Replace additional StatelessVerkleStateManager create() constructor instantiations, add verkle-cryptography-wasm to Client package.json * Rebuild package-lock.json * Move verkle helper functionality to Util verkle module, fully remove @ethereumjs/verkle usages * Update VerkleExecutionWitness, VerkleProof type imports moved to Util * Remove @ethereumjs/verkle dependency from VM * Rebuild package-lock.json * Additional import fix * Yet another fix * Merge remote-tracking branch 'origin/master' into verkle-statemanager-interface-and-evm-dependency-removal
1 parent b570ca1 commit 1acacb8

27 files changed

+371
-136
lines changed

package-lock.json

Lines changed: 4 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/block/src/block.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ import type {
3838
JsonBlock,
3939
JsonRpcBlock,
4040
RequestsBytes,
41-
VerkleExecutionWitness,
4241
WithdrawalsBytes,
4342
} from './types.js'
4443
import type { Common } from '@ethereumjs/common'
@@ -53,6 +52,7 @@ import type {
5352
EthersProvider,
5453
PrefixedHexString,
5554
RequestBytes,
55+
VerkleExecutionWitness,
5656
WithdrawalBytes,
5757
} from '@ethereumjs/util'
5858

packages/block/src/from-beacon-payload.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { bigIntToHex } from '@ethereumjs/util'
22

3-
import type { ExecutionPayload, VerkleExecutionWitness } from './types.js'
4-
import type { PrefixedHexString } from '@ethereumjs/util'
3+
import type { ExecutionPayload } from './types.js'
4+
import type { PrefixedHexString, VerkleExecutionWitness } from '@ethereumjs/util'
55

66
type BeaconWithdrawal = {
77
index: PrefixedHexString

packages/block/src/types.ts

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import type {
1111
JsonRpcWithdrawal,
1212
PrefixedHexString,
1313
RequestBytes,
14+
VerkleExecutionWitness,
1415
WithdrawalBytes,
1516
WithdrawalData,
1617
WithdrawalRequestV1,
@@ -78,45 +79,6 @@ export interface BlockOptions {
7879
executionWitness?: VerkleExecutionWitness
7980
}
8081

81-
export interface VerkleProof {
82-
commitmentsByPath: PrefixedHexString[]
83-
d: PrefixedHexString
84-
depthExtensionPresent: PrefixedHexString
85-
ipaProof: {
86-
cl: PrefixedHexString[]
87-
cr: PrefixedHexString[]
88-
finalEvaluation: PrefixedHexString
89-
}
90-
otherStems: PrefixedHexString[]
91-
}
92-
93-
export interface VerkleStateDiff {
94-
stem: PrefixedHexString
95-
suffixDiffs: {
96-
currentValue: PrefixedHexString | null
97-
newValue: PrefixedHexString | null
98-
suffix: number | string
99-
}[]
100-
}
101-
102-
/**
103-
* Experimental, object format could eventual change.
104-
* An object that provides the state and proof necessary for verkle stateless execution
105-
* */
106-
export interface VerkleExecutionWitness {
107-
/**
108-
* An array of state diffs.
109-
* Each item corresponding to state accesses or state modifications of the block.
110-
* In the current design, it also contains the resulting state of the block execution (post-state).
111-
*/
112-
stateDiff: VerkleStateDiff[]
113-
/**
114-
* The verkle proof for the block.
115-
* Proves that the provided stateDiff belongs to the canonical verkle tree.
116-
*/
117-
verkleProof: VerkleProof
118-
}
119-
12082
/**
12183
* A block header's data.
12284
*/

packages/block/test/from-beacon-payload.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import * as payload87335 from './testdata/payload-slot-87335.json'
1010
import * as payload87475 from './testdata/payload-slot-87475.json'
1111
import * as testnetVerkleKaustinen from './testdata/testnetVerkleKaustinen.json'
1212

13-
import type { BeaconPayloadJson, VerkleExecutionWitness } from '../src/index.js'
13+
import type { BeaconPayloadJson } from '../src/index.js'
14+
import type { VerkleExecutionWitness } from '@ethereumjs/util'
1415

1516
describe('[fromExecutionPayloadJson]: 4844 devnet 5', () => {
1617
let common: Common

packages/client/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
"level": "^8.0.0",
8888
"memory-level": "^1.0.0",
8989
"prom-client": "^15.1.0",
90+
"verkle-cryptography-wasm": "^0.4.2",
9091
"winston": "^3.3.3",
9192
"winston-daily-rotate-file": "^4.5.5",
9293
"yargs": "^17.7.1"

packages/client/src/execution/vmexecution.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
} from '@ethereumjs/util'
2424
import { VM } from '@ethereumjs/vm'
2525
import { writeFileSync } from 'fs'
26+
import { loadVerkleCrypto } from 'verkle-cryptography-wasm'
2627

2728
import { Event } from '../types.js'
2829
import { debugCodeReplayBlock } from '../util/debug.js'
@@ -190,8 +191,10 @@ export class VMExecution extends Execution {
190191
return
191192
}
192193
this.config.logger.info(`Setting up verkleVM`)
193-
const stateManager = await StatelessVerkleStateManager.create({
194+
const verkleCrypto = await loadVerkleCrypto()
195+
const stateManager = new StatelessVerkleStateManager({
194196
initialStateRoot: this.config.initialVerkleStateRoot,
197+
verkleCrypto,
195198
})
196199
this.verkleVM = await VM.create({
197200
common: this.config.execCommon,

packages/client/test/rpc/engine/kaustinen6.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ import genesisJSON from '../../testdata/geth-genesis/kaustinen6.json'
99
import { getRpcClient, setupChain } from '../helpers.js'
1010

1111
import type { Chain } from '../../../src/blockchain/index.js'
12-
import type { BeaconPayloadJson, VerkleExecutionWitness } from '@ethereumjs/block'
12+
import type { BeaconPayloadJson } from '@ethereumjs/block'
1313
import type { Common } from '@ethereumjs/common'
14+
import type { VerkleExecutionWitness } from '@ethereumjs/util'
1415
import type { HttpClient } from 'jayson/promise'
1516
const genesisVerkleStateRoot = '0x1fbf85345a3cbba9a6d44f991b721e55620a22397c2a93ee8d5011136ac300ee'
1617
const genesisVerkleBlockHash = '0x3fe165c03e7a77d1e3759362ebeeb16fd964cb411ce11fbe35c7032fab5b9a8a'

packages/common/src/interfaces.ts

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,64 @@ export type AccessListBytesItem = [Uint8Array, Uint8Array[]]
6565
export type AccessListBytes = AccessListBytesItem[]
6666
export type AccessList = AccessListItem[]
6767

68+
/**
69+
* Verkle related
70+
*
71+
* Experimental (do not implement)
72+
*/
73+
export type AccessEventFlags = {
74+
stemRead: boolean
75+
stemWrite: boolean
76+
chunkRead: boolean
77+
chunkWrite: boolean
78+
chunkFill: boolean
79+
}
80+
81+
/**
82+
* Verkle related
83+
*
84+
* Experimental (do not implement)
85+
*/
86+
export interface AccessWitnessInterface {
87+
touchAndChargeProofOfAbsence(address: Address): bigint
88+
touchAndChargeMessageCall(address: Address): bigint
89+
touchAndChargeValueTransfer(caller: Address, target: Address): bigint
90+
touchAndChargeContractCreateInit(address: Address): bigint
91+
touchAndChargeContractCreateCompleted(address: Address): bigint
92+
touchTxOriginAndComputeGas(origin: Address): bigint
93+
touchTxTargetAndComputeGas(target: Address, { sendsValue }: { sendsValue?: boolean }): bigint
94+
touchCodeChunksRangeOnReadAndChargeGas(contact: Address, startPc: number, endPc: number): bigint
95+
touchCodeChunksRangeOnWriteAndChargeGas(contact: Address, startPc: number, endPc: number): bigint
96+
touchAddressOnWriteAndComputeGas(
97+
address: Address,
98+
treeIndex: number | bigint,
99+
subIndex: number | Uint8Array
100+
): bigint
101+
touchAddressOnReadAndComputeGas(
102+
address: Address,
103+
treeIndex: number | bigint,
104+
subIndex: number | Uint8Array
105+
): bigint
106+
touchAddressAndChargeGas(
107+
address: Address,
108+
treeIndex: number | bigint,
109+
subIndex: number | Uint8Array,
110+
{ isWrite }: { isWrite?: boolean }
111+
): bigint
112+
touchAddress(
113+
address: Address,
114+
treeIndex: number | bigint,
115+
subIndex: number | Uint8Array,
116+
{ isWrite }: { isWrite?: boolean }
117+
): AccessEventFlags
118+
shallowCopy(): AccessWitnessInterface
119+
merge(accessWitness: AccessWitnessInterface): void
120+
}
121+
122+
/*
123+
* Generic StateManager interface corresponding with the @ethereumjs/statemanager package
124+
*
125+
*/
68126
export interface StateManagerInterface {
69127
getAccount(address: Address): Promise<Account | undefined>
70128
putAccount(address: Address, account?: Account): Promise<void>
@@ -85,6 +143,13 @@ export interface StateManagerInterface {
85143
hasStateRoot(root: Uint8Array): Promise<boolean> // only used in client
86144
shallowCopy(downlevelCaches?: boolean): StateManagerInterface
87145
getAppliedKey?(address: Uint8Array): Uint8Array
146+
147+
/*
148+
* The following optional methods are Verkle related
149+
*
150+
* Experimental (do not implement)
151+
*/
152+
checkChunkWitnessPresent?(contract: Address, programCounter: number): Promise<boolean>
88153
}
89154

90155
export interface EVMStateManagerInterface extends StateManagerInterface {

packages/evm/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
"@ethereumjs/statemanager": "^2.3.0",
5959
"@ethereumjs/tx": "^5.3.0",
6060
"@ethereumjs/util": "^9.0.3",
61-
"@ethereumjs/verkle": "^0.0.2",
6261
"@types/debug": "^4.1.9",
6362
"debug": "^4.3.3",
6463
"ethereum-cryptography": "^2.1.3",

0 commit comments

Comments
 (0)