Skip to content

Commit 22746a1

Browse files
gabrocheleaug11techacolytec3
authored
verkle: migrate to verkle-cryptography-wasm (#3356)
* cleanly apply stem changes from gabriels commit * fix exports [no ci] * statemanager: update kaustinen block test data * statemanager: update account balance and nonce * evm: fix failing tests * client: update kaustinen6 data * genesis: fix test * block: undo FromBeaconPayload export addition * Cleanup, add browser tests * Fix type export --------- Co-authored-by: harkamal <[email protected]> Co-authored-by: acolytec3 <[email protected]>
1 parent babbe20 commit 22746a1

File tree

26 files changed

+2639
-621
lines changed

26 files changed

+2639
-621
lines changed

.github/workflows/browser.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,6 @@ jobs:
4747
- run: npm run test:browser -w=@ethereumjs/statemanager
4848
- run: npm run test:browser -w=@ethereumjs/evm
4949
- run: npm run test:browser -w=@ethereumjs/vm
50+
- run: npm run test:browser -w=@ethereumjs/verkle
51+
5052

package-lock.json

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

packages/block/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export { Block } from './block.js'
2-
export { executionPayloadFromBeaconPayload } from './from-beacon-payload.js'
2+
export { type BeaconPayloadJson, executionPayloadFromBeaconPayload } from './from-beacon-payload.js'
33
export { BlockHeader } from './header.js'
44
export { getDifficulty, valuesArrayToHeaderData } from './helpers.js'
55
export * from './types.js'

packages/client/src/execution/vmexecution.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,8 @@ export class VMExecution extends Execution {
188188
if (this.verkleVM !== undefined) {
189189
return
190190
}
191-
192191
this.config.logger.info(`Setting up verkleVM`)
193-
const stateManager = new StatelessVerkleStateManager()
192+
const stateManager = await StatelessVerkleStateManager.create()
194193
this.verkleVM = await VM.create({
195194
common: this.config.execCommon,
196195
blockchain: this.chain.blockchain,

packages/client/test/rpc/engine/kaustinen5.spec.ts renamed to packages/client/test/rpc/engine/kaustinen6.spec.ts

Lines changed: 44 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,40 +5,51 @@ import * as td from 'testdouble'
55
import { assert, describe, it } from 'vitest'
66

77
import blocks from '../../testdata/blocks/kaustinen4.json'
8-
import genesisJSON from '../../testdata/geth-genesis/kaustinen5.json'
8+
import genesisJSON from '../../testdata/geth-genesis/kaustinen6.json'
99
import { getRpcClient, setupChain } from '../helpers.js'
1010

1111
import type { Chain } from '../../../src/blockchain'
1212
import type { BeaconPayloadJson } from '@ethereumjs/block'
1313
import type { Common } from '@ethereumjs/common'
1414
import type { HttpClient } from 'jayson/promise'
15-
const genesisVerkleStateRoot = '0x382960711d9ccf58b9db20122e2253eb9bfa99d513f8c9d4e85b55971721f4de'
16-
const genesisVerkleBlockHash = '0x086326f2922364dba375e7c9bed375d622845615c0974ffd1d3be0e34edbfbc3'
15+
const genesisVerkleStateRoot = '0x1fbf85345a3cbba9a6d44f991b721e55620a22397c2a93ee8d5011136ac300ee'
16+
const genesisVerkleBlockHash = '0x3fe165c03e7a77d1e3759362ebeeb16fd964cb411ce11fbe35c7032fab5b9a8a'
1717

1818
/**
19-
* One can run this test in two formats:
20-
* 1. On the saved blocks, comma separated which are limited (353,368,374,467)
19+
* One can run this test in this format:
20+
* 1. Directly pull slots from a kaustinen beacon url
21+
* `TEST_ONLINE_SLOTS=15 PEER_BEACON_URL=https://beacon.verkle-gen-devnet-6.ethpandaops.io DEBUG=ethjs,vm:*,evm:*,statemanager:verkle* npx vitest run test/rpc/engine/kaustinen6.spec.ts`
22+
*
23+
* However there are other ways to run the test with save data and testvectors but they are from old versions but
24+
* can be updated to make it work
25+
*
26+
* a. On the saved blocks, comma separated (were produced for kaustinen4 )
2127
* `TEST_SAVED_NUMBERS=353,368,374,467 npx vitest run test/rpc/engine/kaustinen5.spec.ts`
22-
* 2. Directly pull slots from a kaustinen beacon url
23-
* `TEST_ONLINE_SLOTS=15 PEER_BEACON_URL=https://beacon.verkle-gen-devnet-5.ethpandaops.io DEBUG=ethjs,vm:*,evm:*,statemanager:verkle* npx vitest run test/rpc/engine/kaustinen5.spec.ts`
24-
* 3. Geth produced testvectors
25-
* `TEST_GETH_VEC_DIR=test/testdata/gethk5vecs DEBUG=ethjs,vm:*,evm:*,statemanager:verkle* npx vitest run test/rpc/engine/kaustinen5.spec.ts`
28+
* b. Geth produced testvectors (were produced for kaustinen5)
29+
* `TEST_GETH_VEC_DIR=test/testdata/gethk5vecs DEBUG=ethjs,vm:*,evm:*,statemanager:verkle* npx vitest run test/rpc/engine/kaustinen6.spec.ts`
2630
*/
2731

2832
const originalValidate = (BlockHeader as any).prototype._consensusFormatValidation
2933

3034
async function fetchExecutionPayload(
3135
peerBeaconUrl: string,
3236
slot: number | string
33-
): Promise<BeaconPayloadJson> {
34-
const beaconBlock = await (await fetch(`${peerBeaconUrl}/eth/v2/beacon/blocks/${slot}`)).json()
35-
return beaconBlock.data.message.body.execution_payload
37+
): Promise<BeaconPayloadJson | undefined> {
38+
let beaconPayload: BeaconPayloadJson | undefined = undefined
39+
try {
40+
const beaconBlock = await (await fetch(`${peerBeaconUrl}/eth/v2/beacon/blocks/${slot}`)).json()
41+
beaconPayload = beaconBlock.data.message.body.execution_payload
42+
// eslint-disable-next-line no-empty
43+
} catch (_e) {}
44+
45+
return beaconPayload
3646
}
3747

3848
async function runBlock(
3949
{ chain, rpc, common }: { chain: Chain; rpc: HttpClient; common: Common },
4050
{ execute, parent }: { execute: any; parent: any },
41-
isBeaconData: boolean
51+
isBeaconData: boolean,
52+
context: any
4253
) {
4354
const blockCache = chain.blockCache
4455

@@ -51,6 +62,11 @@ async function runBlock(
5162
const executePayload =
5263
isBeaconData === true ? executionPayloadFromBeaconPayload(execute as any) : execute
5364
const res = await rpc.request('engine_newPayloadV2', [executePayload])
65+
66+
// if the block was not executed mark as skip so it shows in test
67+
if (res.result.status === 'ACCEPTED') {
68+
context.skip()
69+
}
5470
assert.equal(res.result.status, 'VALID', 'valid status should be received')
5571
}
5672

@@ -75,21 +91,22 @@ describe(`valid verkle network setup`, async () => {
7591
const savedTestCases = process.env.TEST_SAVED_NUMBERS?.split(',') ?? []
7692

7793
for (const testCase of savedTestCases) {
78-
it(`run saved block ${testCase}`, async () => {
94+
it(`run saved block ${testCase}`, async (context) => {
7995
let testData
8096
let isBeaconData
8197
if (process.env.SAVED_DATA_DIR !== undefined) {
8298
const fileName = `${process.env.SAVED_DATA_DIR}/${testCase}.json`
83-
testData = JSON.parse(readFileSync(fileName))[testCase]
99+
testData = JSON.parse(readFileSync(fileName, 'utf8'))[testCase]
84100
isBeaconData = false
85101
} else {
102+
// @ts-expect-error -- Typescript complains that `testCase` can't index the `blocks` object
86103
testData = blocks[testCase]
87104
isBeaconData = true
88105
}
89106
if (testData === undefined) {
90107
throw Error('unavailable data')
91108
}
92-
await runBlock({ common, chain, rpc }, testData, isBeaconData)
109+
await runBlock({ common, chain, rpc }, testData, isBeaconData, context)
93110
})
94111
}
95112

@@ -107,9 +124,14 @@ describe(`valid verkle network setup`, async () => {
107124
let parent = await fetchExecutionPayload(process.env.PEER_BEACON_URL, startSlot - 1)
108125
for (let i = startSlot; i <= endSlot; i++) {
109126
const execute = await fetchExecutionPayload(process.env.PEER_BEACON_URL, i)
110-
it(`run fetched block slot: ${i} number: ${execute.block_number}`, async () => {
127+
if (execute === undefined) {
128+
// may be there was no block on this slot
129+
continue
130+
}
131+
132+
it(`run fetched block slot: ${i} number: ${execute.block_number}`, async (context) => {
111133
try {
112-
await runBlock({ common, chain, rpc }, { parent, execute }, true)
134+
await runBlock({ common, chain, rpc }, { parent, execute }, true, context)
113135
} finally {
114136
parent = execute
115137
}
@@ -123,8 +145,8 @@ describe(`valid verkle network setup`, async () => {
123145
let parent = gethVecs[0]
124146
for (let i = 1; i < gethVecs.length; i++) {
125147
const execute = gethVecs[i]
126-
it(`run geth vector: ${execute.blockNumber}`, async () => {
127-
await runBlock({ common, chain, rpc }, { parent, execute }, false)
148+
it(`run geth vector: ${execute.blockNumber}`, async (context) => {
149+
await runBlock({ common, chain, rpc }, { parent, execute }, false, context)
128150
parent = execute
129151
})
130152
}
@@ -139,8 +161,8 @@ describe(`valid verkle network setup`, async () => {
139161

140162
async function loadGethVectors(vectorsDirPath: string, opts: { common: Common }) {
141163
// set chain id to 1 for geth vectors
142-
opts.common._chainParams.chainId = BigInt(1)
143-
const stateDiffVec = JSON.parse(readFileSync(`${vectorsDirPath}/statediffs.json`))
164+
opts.common['_chainParams'].chainId = BigInt(1)
165+
const stateDiffVec = JSON.parse(readFileSync(`${vectorsDirPath}/statediffs.json`, 'utf8'))
144166
const executionWitness0 = {
145167
stateDiff: [],
146168
verkleProof: {

packages/client/test/testdata/geth-genesis/kaustinen5.json renamed to packages/client/test/testdata/geth-genesis/kaustinen6.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -897,5 +897,5 @@
897897
"nonce": "0x1234",
898898
"mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
899899
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
900-
"timestamp": "1711712640"
900+
"timestamp": "1712918460"
901901
}

packages/common/src/chains.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -570,23 +570,23 @@ export const chains: ChainsDict = {
570570
'enrtree://AKA3AM6LPBYEUDMVNU3BSVQJ5AD45Y7YPOHJLEF6W26QOE4VTUDPE@all.holesky.ethdisco.net',
571571
],
572572
},
573-
kaustinen5: {
574-
name: 'kaustinen5',
573+
kaustinen6: {
574+
name: 'kaustinen6',
575575
chainId: 69420,
576576
networkId: 69420,
577577
defaultHardfork: 'prague',
578578
consensus: {
579579
type: 'pos',
580580
algorithm: 'casper',
581581
},
582-
comment: 'Verkle kaustinen testnet 3 (likely temporary, do not hard-wire into production code)',
582+
comment: 'Verkle kaustinen testnet 6 (likely temporary, do not hard-wire into production code)',
583583
url: 'https://github.com/eth-clients/kaustinen/',
584584
genesis: {
585585
difficulty: '0x01',
586586
extraData: '0x',
587587
gasLimit: '0x17D7840',
588588
nonce: '0x0000000000001234',
589-
timestamp: '0x6606a9bc',
589+
timestamp: '0x66190fbc',
590590
},
591591
hardforks: [
592592
{
@@ -646,7 +646,7 @@ export const chains: ChainsDict = {
646646
{
647647
name: 'prague',
648648
block: null,
649-
timestamp: '1711712640',
649+
timestamp: '1712848500',
650650
},
651651
],
652652
bootstrapNodes: [],

packages/common/src/enums.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export enum Chain {
55
Goerli = 5,
66
Sepolia = 11155111,
77
Holesky = 17000,
8-
Kaustinen5 = 69420,
8+
Kaustinen6 = 69420,
99
}
1010

1111
/**
@@ -44,10 +44,10 @@ export const ChainGenesis: Record<Chain, GenesisState> = {
4444
blockNumber: BIGINT_0,
4545
stateRoot: hexToBytes('0x69d8c9d72f6fa4ad42d4702b433707212f90db395eb54dc20bc85de253788783'),
4646
},
47-
[Chain.Kaustinen5]: {
48-
name: 'kaustinen5',
47+
[Chain.Kaustinen6]: {
48+
name: 'kaustinen6',
4949
blockNumber: BIGINT_0,
50-
stateRoot: hexToBytes('0x382960711d9ccf58b9db20122e2253eb9bfa99d513f8c9d4e85b55971721f4de'),
50+
stateRoot: hexToBytes('0x1fbf85345a3cbba9a6d44f991b721e55620a22397c2a93ee8d5011136ac300ee'),
5151
},
5252
}
5353

packages/evm/src/interpreter.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,11 +270,11 @@ export class Interpreter {
270270
this._runState.env.chargeCodeAccesses === true
271271
) {
272272
const contract = this._runState.interpreter.getAddress()
273+
273274
if (
274-
!(this._runState.stateManager as StatelessVerkleStateManager).checkChunkWitnessPresent(
275-
contract,
276-
programCounter
277-
)
275+
!(await (
276+
this._runState.stateManager as StatelessVerkleStateManager
277+
).checkChunkWitnessPresent(contract, programCounter))
278278
) {
279279
throw Error(`Invalid witness with missing codeChunk for pc=${programCounter}`)
280280
}

packages/evm/test/precompiles/0f-bls12-g2mul.spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ describe('Precompiles: BLS12-G2-MUL', () => {
7676
const evm = await EVM.create({
7777
common,
7878
})
79-
console.log(getActivePrecompiles(common))
8079
const BLS12G2MUL = getActivePrecompiles(common).get('000000000000000000000000000000000000000f')!
8180

8281
for (const testVector of testData) {

0 commit comments

Comments
 (0)