From 287f96076fc52435a04cb70de8e92b45c8d33fb3 Mon Sep 17 00:00:00 2001 From: Gabriel Rocheleau Date: Thu, 7 Nov 2024 20:06:26 -0700 Subject: [PATCH] common: refactor verkleCrypto into customCrypto from common (#3790) * common: refactor verkleCrypto into customCrypto from common * vm: type issue * remove obsolete `await loadVerkleCrypto` references * fix code stem and code chunk suffix generation * fix suffix counts * fix tests * Update packages/statemanager/src/statelessVerkleStateManager.ts Co-authored-by: Jochem Brouwer --------- Co-authored-by: acolytec3 <17355484+acolytec3@users.noreply.github.com> Co-authored-by: Jochem Brouwer --- packages/client/src/execution/vmexecution.ts | 5 +- .../client/test/rpc/engine/kaustinen6.spec.ts | 2 + packages/common/src/types.ts | 9 +++- packages/evm/test/verkle.spec.ts | 22 ++++---- .../src/statefulVerkleStateManager.ts | 19 ++++--- .../src/statelessVerkleStateManager.ts | 20 +++++--- packages/statemanager/src/types.ts | 5 +- .../test/statefulVerkleStateManager.spec.ts | 51 ++++++++++++------- .../test/statelessVerkleStateManager.spec.ts | 26 +++++----- packages/util/src/verkle.ts | 18 +++---- packages/util/test/verkle.spec.ts | 9 +--- packages/verkle/examples/diyVerkle.ts | 5 +- packages/verkle/src/constructors.ts | 3 +- packages/verkle/test/internalNode.spec.ts | 27 ++++------ packages/verkle/test/interop.spec.ts | 11 ++-- packages/verkle/test/leafNode.spec.ts | 33 +++++------- packages/verkle/test/proof.spec.ts | 38 ++++++-------- packages/verkle/test/verkle.spec.ts | 34 +++++-------- packages/vm/src/runBlock.ts | 7 +-- packages/vm/src/types.ts | 6 --- .../vm/test/api/EIPs/eip-6800-verkle.spec.ts | 5 +- packages/vm/test/api/runBlock.spec.ts | 17 ++----- 22 files changed, 174 insertions(+), 198 deletions(-) diff --git a/packages/client/src/execution/vmexecution.ts b/packages/client/src/execution/vmexecution.ts index 74c0a5d6b5..8b4f0a86c7 100644 --- a/packages/client/src/execution/vmexecution.ts +++ b/packages/client/src/execution/vmexecution.ts @@ -26,7 +26,6 @@ import { import { createVM, runBlock, runTx } from '@ethereumjs/vm' import { writeFileSync } from 'fs' import * as mcl from 'mcl-wasm' -import * as verkle from 'micro-eth-signer/verkle' import { initRustBN } from 'rustbn-wasm' import { Event } from '../types.js' @@ -42,7 +41,6 @@ import type { ExecutionOptions } from './execution.js' import type { Block } from '@ethereumjs/block' import type { PrefixedHexString } from '@ethereumjs/util' import type { RunBlockOpts, TxReceipt, VM } from '@ethereumjs/vm' -const loadVerkleCrypto = () => Promise.resolve(verkle) export enum ExecStatus { VALID = 'VALID', @@ -202,9 +200,8 @@ export class VMExecution extends Execution { return } this.config.logger.info(`Setting up verkleVM`) - const verkleCrypto = await loadVerkleCrypto() const stateManager = new StatelessVerkleStateManager({ - verkleCrypto, + common: this.config.execCommon, }) await mcl.init(mcl.BLS12_381) const rustBN = await initRustBN() diff --git a/packages/client/test/rpc/engine/kaustinen6.spec.ts b/packages/client/test/rpc/engine/kaustinen6.spec.ts index b8a8c0ce41..464cb14982 100644 --- a/packages/client/test/rpc/engine/kaustinen6.spec.ts +++ b/packages/client/test/rpc/engine/kaustinen6.spec.ts @@ -6,6 +6,7 @@ import { } from '@ethereumjs/block' import { hexToBytes } from '@ethereumjs/util' import { readFileSync } from 'fs' +import * as verkle from 'micro-eth-signer' import * as td from 'testdouble' import { assert, describe, it } from 'vitest' @@ -80,6 +81,7 @@ describe(`valid verkle network setup`, async () => { const { server, chain, common } = await setupChain(kaustinen6Data, 'post-merge', { engine: true, genesisStateRoot: genesisVerkleStateRoot, + customCrypto: { verkleCrypto: verkle }, }) const rpc = getRPCClient(server) it('genesis should be correctly setup', async () => { diff --git a/packages/common/src/types.ts b/packages/common/src/types.ts index 7737ca4996..ed6bc980fd 100644 --- a/packages/common/src/types.ts +++ b/packages/common/src/types.ts @@ -1,5 +1,11 @@ import type { ConsensusAlgorithm, ConsensusType, Hardfork } from './enums.js' -import type { BigIntLike, ECDSASignature, KZG, PrefixedHexString } from '@ethereumjs/util' +import type { + BigIntLike, + ECDSASignature, + KZG, + PrefixedHexString, + VerkleCrypto, +} from '@ethereumjs/util' export interface ChainName { [chainId: string]: string @@ -89,6 +95,7 @@ export interface CustomCrypto { ecdsaSign?: (msg: Uint8Array, pk: Uint8Array) => { signature: Uint8Array; recid: number } ecdsaRecover?: (sig: Uint8Array, recId: number, hash: Uint8Array) => Uint8Array kzg?: KZG + verkleCrypto?: VerkleCrypto } export interface BaseOpts { diff --git a/packages/evm/test/verkle.spec.ts b/packages/evm/test/verkle.spec.ts index ff514c4591..24689af3a5 100644 --- a/packages/evm/test/verkle.spec.ts +++ b/packages/evm/test/verkle.spec.ts @@ -9,29 +9,29 @@ import { } from '@ethereumjs/util' import { createVerkleTree } from '@ethereumjs/verkle' import * as verkle from 'micro-eth-signer/verkle' -import { assert, beforeAll, describe, it } from 'vitest' +import { assert, describe, it } from 'vitest' import { VerkleAccessWitness, createEVM } from '../src/index.js' -import type { VerkleCrypto } from '@ethereumjs/util' -const loadVerkleCrypto = () => Promise.resolve(verkle) - describe('verkle tests', () => { - let verkleCrypto: VerkleCrypto - beforeAll(async () => { - verkleCrypto = await loadVerkleCrypto() - }) it('should execute bytecode and update the state', async () => { // This tests executes some very simple bytecode that stores the value 1 in slot 2 - const common = new Common({ chain: Mainnet, eips: [6800], hardfork: Hardfork.Cancun }) + const common = new Common({ + chain: Mainnet, + customCrypto: { verkleCrypto: verkle }, + eips: [6800], + hardfork: Hardfork.Cancun, + }) const trie = await createVerkleTree() - const sm = new StatefulVerkleStateManager({ trie, verkleCrypto }) + const sm = new StatefulVerkleStateManager({ common, trie }) const address = createAddressFromString('0x9e5ef720fa2cdfa5291eb7e711cfd2e62196f4b3') const account = createAccount({ nonce: 3n, balance: 0xffffffffn }) await sm.putAccount(address, account) const evm = await createEVM({ common, stateManager: sm }) // Initialize verkleAccess Witness manually (in real context, it is done by the VM, but we are bypassing that here) - evm.verkleAccessWitness = new VerkleAccessWitness({ verkleCrypto }) + evm.verkleAccessWitness = new VerkleAccessWitness({ + verkleCrypto: verkle, + }) const code = hexToBytes('0x6001600255') // PUSH1 01 PUSH1 02 SSTORE const res = await evm.runCall({ code, diff --git a/packages/statemanager/src/statefulVerkleStateManager.ts b/packages/statemanager/src/statefulVerkleStateManager.ts index d487e548c0..4d437a9c1f 100644 --- a/packages/statemanager/src/statefulVerkleStateManager.ts +++ b/packages/statemanager/src/statefulVerkleStateManager.ts @@ -1,4 +1,4 @@ -import { Common, Mainnet, VerkleAccessedStateType } from '@ethereumjs/common' +import { VerkleAccessedStateType } from '@ethereumjs/common' import { RLP } from '@ethereumjs/rlp' import { Account, @@ -41,6 +41,7 @@ import type { Caches } from './cache/caches.js' import type { StatefulVerkleStateManagerOpts, VerkleState } from './types.js' import type { AccountFields, + Common, StateManagerInterface, StorageDump, StorageRange, @@ -80,7 +81,6 @@ export class StatefulVerkleStateManager implements StateManagerInterface { protected readonly DEBUG: boolean = false private keccakFunction: Function - constructor(opts: StatefulVerkleStateManagerOpts) { // Skip DEBUG calls unless 'ethjs' included in environmental DEBUG variables // Additional window check is to prevent vite browser bundling (and potentially other) to break @@ -89,14 +89,19 @@ export class StatefulVerkleStateManager implements StateManagerInterface { this._checkpointCount = 0 - if (opts.common?.isActivatedEIP(6800) === false) + if (opts.common.isActivatedEIP(6800) === false) { throw new Error('EIP-6800 required for verkle state management') + } + + if (opts.common.customCrypto.verkleCrypto === undefined) { + throw new Error('verkle crypto required') + } - this.common = opts.common ?? new Common({ chain: Mainnet, eips: [6800] }) + this.common = opts.common this._trie = opts.trie ?? new VerkleTree({ - verkleCrypto: opts.verkleCrypto, + verkleCrypto: opts.common.customCrypto.verkleCrypto, db: new MapDB(), useRootPersistence: false, cacheSize: 0, @@ -104,8 +109,8 @@ export class StatefulVerkleStateManager implements StateManagerInterface { this._debug = debugDefault('statemanager:verkle:stateful') this.originalStorageCache = new OriginalStorageCache(this.getStorage.bind(this)) this._caches = opts.caches - this.keccakFunction = opts.common?.customCrypto.keccak256 ?? keccak256 - this.verkleCrypto = opts.verkleCrypto + this.keccakFunction = opts.common.customCrypto.keccak256 ?? keccak256 + this.verkleCrypto = opts.common.customCrypto.verkleCrypto } /** diff --git a/packages/statemanager/src/statelessVerkleStateManager.ts b/packages/statemanager/src/statelessVerkleStateManager.ts index 0557b15932..900b1e0594 100644 --- a/packages/statemanager/src/statelessVerkleStateManager.ts +++ b/packages/statemanager/src/statelessVerkleStateManager.ts @@ -33,6 +33,7 @@ import type { StatelessVerkleStateManagerOpts, VerkleState } from './index.js' import type { MerkleStateManager } from './merkleStateManager.js' import type { AccountFields, + Common, StateManagerInterface, VerkleAccessWitnessInterface, VerkleAccessedStateWithAddress, @@ -76,6 +77,8 @@ export class StatelessVerkleStateManager implements StateManagerInterface { protected _debug: Debugger + public readonly common: Common + /** * StateManager is run in DEBUG mode (default: false) * Taken from DEBUG environment variable @@ -112,14 +115,19 @@ export class StatelessVerkleStateManager implements StateManagerInterface { this._caches = opts.caches - this.keccakFunction = opts.common?.customCrypto.keccak256 ?? keccak256 - - this._debug = debugDefault('statemanager:verkle:stateless') + if (opts.common.isActivatedEIP(6800) === false) { + throw new Error('EIP-6800 required for stateless verkle state management') + } - if (opts.verkleCrypto === undefined) { + if (opts.common.customCrypto.verkleCrypto === undefined) { throw new Error('verkle crypto required') } - this.verkleCrypto = opts.verkleCrypto + + this.common = opts.common + this.keccakFunction = opts.common.customCrypto.keccak256 ?? keccak256 + this.verkleCrypto = opts.common.customCrypto.verkleCrypto + + this._debug = debugDefault('statemanager:verkle:stateless') // Skip DEBUG calls unless 'ethjs' included in environmental DEBUG variables // Additional window check is to prevent vite browser bundling (and potentially other) to break @@ -211,7 +219,7 @@ export class StatelessVerkleStateManager implements StateManagerInterface { shallowCopy(downlevelCaches = true): StatelessVerkleStateManager { const stateManager = new StatelessVerkleStateManager({ caches: this._caches?.shallowCopy(downlevelCaches), - verkleCrypto: this.verkleCrypto, + common: this.common, }) return stateManager } diff --git a/packages/statemanager/src/types.ts b/packages/statemanager/src/types.ts index 7cb7e1a483..49c0102ae0 100644 --- a/packages/statemanager/src/types.ts +++ b/packages/statemanager/src/types.ts @@ -3,7 +3,6 @@ import { type PrefixedHexString } from '@ethereumjs/util' import type { Caches } from './index.js' import type { Common } from '@ethereumjs/common' import type { MerklePatriciaTrie } from '@ethereumjs/mpt' -import type { VerkleCrypto } from '@ethereumjs/util' import type { VerkleTree } from '@ethereumjs/verkle' /** * Basic state manager options (not to be used directly) @@ -69,12 +68,12 @@ export interface MerkleStateManagerOpts extends BaseStateManagerOpts { * Options dictionary. */ export interface StatelessVerkleStateManagerOpts extends BaseStateManagerOpts { - verkleCrypto: VerkleCrypto + common: Common // Common required since it provides verkleCrypto through customCrypto caches?: Caches } export interface StatefulVerkleStateManagerOpts extends BaseStateManagerOpts { - verkleCrypto: VerkleCrypto + common: Common // Common required since it provides verkleCrypto through customCrypto trie?: VerkleTree caches?: Caches } diff --git a/packages/statemanager/test/statefulVerkleStateManager.spec.ts b/packages/statemanager/test/statefulVerkleStateManager.spec.ts index dbd13daa2f..54e0de0c2c 100644 --- a/packages/statemanager/test/statefulVerkleStateManager.spec.ts +++ b/packages/statemanager/test/statefulVerkleStateManager.spec.ts @@ -1,3 +1,4 @@ +import { Common, Mainnet } from '@ethereumjs/common' import { Account, VerkleLeafType, @@ -11,22 +12,22 @@ import { } from '@ethereumjs/util' import { createVerkleTree } from '@ethereumjs/verkle' import * as verkle from 'micro-eth-signer/verkle' -import { assert, beforeAll, describe, it } from 'vitest' +import { assert, describe, it } from 'vitest' import { Caches } from '../src/index.js' import { StatefulVerkleStateManager } from '../src/statefulVerkleStateManager.js' -import type { PrefixedHexString, VerkleCrypto } from '@ethereumjs/util' -const loadVerkleCrypto = () => Promise.resolve(verkle) +import type { PrefixedHexString } from '@ethereumjs/util' describe('Verkle Tree API tests', () => { - let verkleCrypto: VerkleCrypto - beforeAll(async () => { - verkleCrypto = await loadVerkleCrypto() - }) it('should put/get/delete an account (with no storage/code from the trie)', async () => { const trie = await createVerkleTree() - const sm = new StatefulVerkleStateManager({ trie, verkleCrypto }) + const common = new Common({ + chain: Mainnet, + eips: [6800], + customCrypto: { verkleCrypto: verkle }, + }) + const sm = new StatefulVerkleStateManager({ common, trie }) const address = createAddressFromString('0x9e5ef720fa2cdfa5291eb7e711cfd2e62196f4b3') const account = createAccount({ nonce: 3n, balance: 0xfffn }) await sm.putAccount(address, account) @@ -40,7 +41,12 @@ describe('Verkle Tree API tests', () => { it('should return same stateRoot when putting and then deleting account', async () => { const trie = await createVerkleTree() - const sm = new StatefulVerkleStateManager({ trie, verkleCrypto }) + const common = new Common({ + chain: Mainnet, + eips: [6800], + customCrypto: { verkleCrypto: verkle }, + }) + const sm = new StatefulVerkleStateManager({ common, trie }) const address1 = createAddressFromString('0x9e5ef720fa2cdfa5291eb7e711cfd2e62196f4b3') const account1 = createAccount({ nonce: 3n, balance: 0xfffn }) @@ -61,7 +67,12 @@ describe('Verkle Tree API tests', () => { it('should put and get code', async () => { const trie = await createVerkleTree() - const sm = new StatefulVerkleStateManager({ trie, verkleCrypto }) + const common = new Common({ + chain: Mainnet, + eips: [6800], + customCrypto: { verkleCrypto: verkle }, + }) + const sm = new StatefulVerkleStateManager({ common, trie }) const address = createAddressFromString('0x9e5ef720fa2cdfa5291eb7e711cfd2e62196f4b3') const code = hexToBytes('0x6001') // PUSH 01 await sm.putCode(address, code) @@ -90,7 +101,12 @@ describe('Verkle Tree API tests', () => { const zeroSlot = setLengthLeft(bigIntToBytes(0n), 32) const zeroSlotValue = hexToBytes('0x1') const trie = await createVerkleTree() - const sm = new StatefulVerkleStateManager({ trie, verkleCrypto }) + const common = new Common({ + chain: Mainnet, + eips: [6800], + customCrypto: { verkleCrypto: verkle }, + }) + const sm = new StatefulVerkleStateManager({ common, trie }) const address = createAddressFromString('0x9e5ef720fa2cdfa5291eb7e711cfd2e62196f4b3') await sm.putAccount(address, new Account(0n, 1n)) await sm.putStorage(address, zeroSlot, zeroSlotValue) @@ -100,19 +116,20 @@ describe('Verkle Tree API tests', () => { }) describe('caching functionality works', () => { - let verkleCrypto: VerkleCrypto - beforeAll(async () => { - verkleCrypto = await loadVerkleCrypto() - }) it('should cache accounts and then write to trie', async () => { const trie = await createVerkleTree() - const sm = new StatefulVerkleStateManager({ trie, verkleCrypto, caches: new Caches() }) + const common = new Common({ + chain: Mainnet, + eips: [6800], + customCrypto: { verkleCrypto: verkle }, + }) + const sm = new StatefulVerkleStateManager({ common, trie, caches: new Caches() }) const address = createAddressFromString('0x9e5ef720fa2cdfa5291eb7e711cfd2e62196f4b3') const account = createAccount({ nonce: 3n, balance: 0xfffn }) await sm.putAccount(address, account) // Confirm account doesn't exist in trie - const stem = getVerkleStem(verkleCrypto, address, 0) + const stem = getVerkleStem(verkle, address, 0) const accountData = await sm['_trie'].get(stem, [ VerkleLeafType.BasicData, VerkleLeafType.CodeHash, diff --git a/packages/statemanager/test/statelessVerkleStateManager.spec.ts b/packages/statemanager/test/statelessVerkleStateManager.spec.ts index 0582ba478f..a78fda81ed 100644 --- a/packages/statemanager/test/statelessVerkleStateManager.spec.ts +++ b/packages/statemanager/test/statelessVerkleStateManager.spec.ts @@ -14,24 +14,18 @@ import { randomBytes, } from '@ethereumjs/util' import * as verkle from 'micro-eth-signer/verkle' -import { assert, beforeAll, describe, it, test } from 'vitest' +import { assert, describe, it, test } from 'vitest' import { CacheType, Caches, StatelessVerkleStateManager } from '../src/index.js' import { testnetVerkleKaustinenData } from './testdata/testnetVerkleKaustinen.js' import { verkleKaustinen6Block72Data } from './testdata/verkleKaustinen6Block72.js' -import type { VerkleCrypto } from '@ethereumjs/util' -const loadVerkleCrypto = () => Promise.resolve(verkle) - describe('StatelessVerkleStateManager: Kaustinen Verkle Block', () => { - let verkleCrypto: VerkleCrypto - beforeAll(async () => { - verkleCrypto = await loadVerkleCrypto() - }) const common = createCommonFromGethGenesis(testnetVerkleKaustinenData, { chain: 'customChain', eips: [2935, 4895, 6800], + customCrypto: { verkleCrypto: verkle }, }) const decodedTxs = verkleKaustinen6Block72Data.transactions?.map((tx) => @@ -45,7 +39,8 @@ describe('StatelessVerkleStateManager: Kaustinen Verkle Block', () => { ) it('initPreState()', async () => { - const stateManager = new StatelessVerkleStateManager({ verkleCrypto }) + common.customCrypto.verkleCrypto = verkle + const stateManager = new StatelessVerkleStateManager({ common }) stateManager.initVerkleExecutionWitness(block.header.number, block.executionWitness) assert.ok(Object.keys(stateManager['_state']).length !== 0, 'should initialize with state') @@ -53,7 +48,8 @@ describe('StatelessVerkleStateManager: Kaustinen Verkle Block', () => { // TODO: Turn back on once we have kaustinen7 data it.skip('getAccount()', async () => { - const stateManager = new StatelessVerkleStateManager({ common, verkleCrypto }) + common.customCrypto.verkleCrypto = verkle + const stateManager = new StatelessVerkleStateManager({ common }) stateManager.initVerkleExecutionWitness(block.header.number, block.executionWitness) const account = await stateManager.getAccount( @@ -71,10 +67,10 @@ describe('StatelessVerkleStateManager: Kaustinen Verkle Block', () => { }) it('put/delete/modify account', async () => { + common.customCrypto.verkleCrypto = verkle const stateManager = new StatelessVerkleStateManager({ common, caches: new Caches(), - verkleCrypto, }) stateManager.initVerkleExecutionWitness(block.header.number, block.executionWitness) @@ -121,7 +117,8 @@ describe('StatelessVerkleStateManager: Kaustinen Verkle Block', () => { }) it('getKey function', async () => { - const stateManager = new StatelessVerkleStateManager({ common, verkleCrypto }) + common.customCrypto.verkleCrypto = verkle + const stateManager = new StatelessVerkleStateManager({ common }) stateManager.initVerkleExecutionWitness(block.header.number, block.executionWitness) const address = createAddressFromString('0x6177843db3138ae69679a54b95cf345ed759450d') @@ -144,6 +141,7 @@ describe('StatelessVerkleStateManager: Kaustinen Verkle Block', () => { }) it(`copy()`, async () => { + common.customCrypto.verkleCrypto = verkle const stateManager = new StatelessVerkleStateManager({ caches: new Caches({ account: { @@ -154,7 +152,6 @@ describe('StatelessVerkleStateManager: Kaustinen Verkle Block', () => { }, }), common, - verkleCrypto, }) stateManager.initVerkleExecutionWitness(block.header.number, block.executionWitness) @@ -174,7 +171,8 @@ describe('StatelessVerkleStateManager: Kaustinen Verkle Block', () => { // TODO contract storage functions not yet completely implemented test.skip('get/put/clear contract storage', async () => { - const stateManager = new StatelessVerkleStateManager({ common, verkleCrypto }) + common.customCrypto.verkleCrypto = verkle + const stateManager = new StatelessVerkleStateManager({ common }) stateManager.initVerkleExecutionWitness(block.header.number, block.executionWitness) const contractAddress = createAddressFromString('0x4242424242424242424242424242424242424242') diff --git a/packages/util/src/verkle.ts b/packages/util/src/verkle.ts index 15fb1607bc..9b652e5cbc 100644 --- a/packages/util/src/verkle.ts +++ b/packages/util/src/verkle.ts @@ -354,16 +354,12 @@ export function encodeVerkleLeafBasicData(account: Account): Uint8Array { export const generateChunkSuffixes = (numChunks: number) => { if (numChunks === 0) return [] const chunkSuffixes: number[] = new Array(numChunks) - const firstChunksSet = numChunks > VERKLE_CODE_OFFSET ? VERKLE_CODE_OFFSET : numChunks - for (let x = 0; x < firstChunksSet; x++) { - // Fill up to first 128 suffixes - chunkSuffixes[x] = x + VERKLE_CODE_OFFSET - } - if (numChunks > VERKLE_CODE_OFFSET) { - for (let x = VERKLE_CODE_OFFSET; x < numChunks; x++) { - // Fill subsequent chunk suffixes up to 256 and then start over since a single node - chunkSuffixes[x] = x - Math.floor(x / VERKLE_NODE_WIDTH) * VERKLE_NODE_WIDTH - } + let currentSuffix = VERKLE_CODE_OFFSET + for (let x = 0; x < numChunks; x++) { + chunkSuffixes[x] = currentSuffix + currentSuffix++ + // Reset suffix to 0 if exceeds VERKLE_NODE_WIDTH + if (currentSuffix >= VERKLE_NODE_WIDTH) currentSuffix = 0 } return chunkSuffixes @@ -388,7 +384,7 @@ export const generateCodeStems = async ( // the first leaf node and 256 chunks in up to 3 additional leaf nodes) // So, instead of computing every single leaf key (which is a heavy async operation), we just compute the stem for the first // chunk in each leaf node and can then know that the chunks in between have tree keys in monotonically increasing order - const numStems = Math.ceil(numChunks / VERKLE_NODE_WIDTH) + const numStems = numChunks > VERKLE_CODE_OFFSET ? Math.ceil(numChunks / VERKLE_NODE_WIDTH) + 1 : 1 const chunkStems = new Array(numStems) // Compute the stem for the initial set of code chunks chunkStems[0] = (await getVerkleTreeKeyForCodeChunk(address, 0, verkleCrypto)).slice(0, 31) diff --git a/packages/util/test/verkle.spec.ts b/packages/util/test/verkle.spec.ts index ffc573f0fe..caad795885 100644 --- a/packages/util/test/verkle.spec.ts +++ b/packages/util/test/verkle.spec.ts @@ -1,11 +1,10 @@ import * as verkle from 'micro-eth-signer/verkle' -import { assert, beforeAll, describe, it } from 'vitest' +import { assert, describe, it } from 'vitest' import { verkleKaustinen6Block72Data } from '../../statemanager/test/testdata/verkleKaustinen6Block72.js' import { Account, VERKLE_CODE_CHUNK_SIZE, - type VerkleCrypto, type VerkleExecutionWitness, VerkleLeafType, bytesToHex, @@ -22,14 +21,8 @@ import { randomBytes, verifyVerkleProof, } from '../src/index.js' -const loadVerkleCrypto = () => Promise.resolve(verkle) describe('Verkle cryptographic helpers', () => { - let verkle: VerkleCrypto - beforeAll(async () => { - verkle = await loadVerkleCrypto() - }) - it('getVerkleStem(): returns the expected stems', () => { // Empty address assert.equal( diff --git a/packages/verkle/examples/diyVerkle.ts b/packages/verkle/examples/diyVerkle.ts index c2f6679a05..eb9319cbb6 100644 --- a/packages/verkle/examples/diyVerkle.ts +++ b/packages/verkle/examples/diyVerkle.ts @@ -1,16 +1,13 @@ import { MapDB, bytesToHex } from '@ethereumjs/util' import { VerkleTree } from '@ethereumjs/verkle' import * as verkle from 'micro-eth-signer/verkle' -const loadVerkleCrypto = () => Promise.resolve(verkle) - -const verkleCrypto = await loadVerkleCrypto() const main = async () => { const tree = new VerkleTree({ cacheSize: 0, db: new MapDB(), useRootPersistence: false, - verkleCrypto, + verkleCrypto: verkle, }) await tree.createRootNode() console.log(bytesToHex(tree.root())) // 0x0000000000000000000000000000000000000000000000000000000000000000 diff --git a/packages/verkle/src/constructors.ts b/packages/verkle/src/constructors.ts index ade0c3e30c..39ed900dfb 100644 --- a/packages/verkle/src/constructors.ts +++ b/packages/verkle/src/constructors.ts @@ -5,7 +5,6 @@ import { ROOT_DB_KEY } from './types.js' import { VerkleTree } from './verkleTree.js' import type { VerkleTreeOpts } from './types.js' -const loadVerkleCrypto = () => Promise.resolve(verkle) export async function createVerkleTree(opts?: Partial) { const key = ROOT_DB_KEY @@ -14,7 +13,7 @@ export async function createVerkleTree(opts?: Partial) { const parsedOptions = { ...opts, db: opts?.db ?? new MapDB(), - verkleCrypto: opts?.verkleCrypto ?? (await loadVerkleCrypto()), + verkleCrypto: opts?.verkleCrypto ?? verkle, useRootPersistence: opts?.useRootPersistence ?? false, cacheSize: opts?.cacheSize ?? 0, } diff --git a/packages/verkle/test/internalNode.spec.ts b/packages/verkle/test/internalNode.spec.ts index 8b4081f2f1..4d5f7ebd48 100644 --- a/packages/verkle/test/internalNode.spec.ts +++ b/packages/verkle/test/internalNode.spec.ts @@ -1,6 +1,6 @@ -import { type VerkleCrypto, equalsBytes, randomBytes } from '@ethereumjs/util' +import { equalsBytes, randomBytes } from '@ethereumjs/util' import * as verkle from 'micro-eth-signer/verkle' -import { assert, beforeAll, describe, it } from 'vitest' +import { assert, describe, it } from 'vitest' import { NODE_WIDTH, @@ -9,16 +9,11 @@ import { isInternalVerkleNode, } from '../src/node/index.js' import { InternalVerkleNode } from '../src/node/internalNode.js' -const loadVerkleCrypto = () => Promise.resolve(verkle) describe('verkle node - internal', () => { - let verkleCrypto: VerkleCrypto - beforeAll(async () => { - verkleCrypto = await loadVerkleCrypto() - }) it('constructor should create an internal node', async () => { const commitment = randomBytes(32) - const node = new InternalVerkleNode({ commitment, verkleCrypto }) + const node = new InternalVerkleNode({ commitment, verkleCrypto: verkle }) assert.ok(isInternalVerkleNode(node), 'typeguard should return true') assert.equal(node.type, VerkleNodeType.Internal, 'type should be set') @@ -33,12 +28,12 @@ describe('verkle node - internal', () => { }) it('create method should create an internal node', async () => { - const node = InternalVerkleNode.create(verkleCrypto) + const node = InternalVerkleNode.create(verkle) assert.equal(node.type, VerkleNodeType.Internal, 'type should be set') assert.deepEqual( node.commitment, - verkleCrypto.zeroCommitment, + verkle.zeroCommitment, 'commitment should be set to point identity', ) @@ -58,21 +53,21 @@ describe('verkle node - internal', () => { children[0] = child const node = new InternalVerkleNode({ children, - verkleCrypto, - commitment: verkleCrypto.zeroCommitment, + verkleCrypto: verkle, + commitment: verkle.zeroCommitment, }) const serialized = node.serialize() - const decoded = decodeVerkleNode(serialized, verkleCrypto) + const decoded = decodeVerkleNode(serialized, verkle) assert.deepEqual((decoded as InternalVerkleNode).children[0]?.commitment, child.commitment) }) it('should serialize and deserialize a node with no children', async () => { const node = new InternalVerkleNode({ - verkleCrypto, - commitment: verkleCrypto.zeroCommitment, + verkleCrypto: verkle, + commitment: verkle.zeroCommitment, }) const serialized = node.serialize() - const decoded = decodeVerkleNode(serialized, verkleCrypto) + const decoded = decodeVerkleNode(serialized, verkle) assert.equal((decoded as InternalVerkleNode).children[0], null) }) }) diff --git a/packages/verkle/test/interop.spec.ts b/packages/verkle/test/interop.spec.ts index 0b662ba3b9..03dfb67a07 100644 --- a/packages/verkle/test/interop.spec.ts +++ b/packages/verkle/test/interop.spec.ts @@ -1,15 +1,10 @@ import { MapDB, bytesToHex } from '@ethereumjs/util' import * as verkle from 'micro-eth-signer/verkle' -import { assert, beforeAll, describe, it } from 'vitest' +import { assert, describe, it } from 'vitest' import { createVerkleTree } from '../src/constructors.js' -const loadVerkleCrypto = () => Promise.resolve(verkle) describe('rust-verkle test vectors', () => { - let verkleCrypto: Awaited> - beforeAll(async () => { - verkleCrypto = await loadVerkleCrypto() - }) it('should produce the correct commitment', async () => { // Test from python implementation //https://github.com/crate-crypto/verkle-trie-ref/blob/483f40c737f27bc8f059870f862cf6c244159cd4/verkle/verkle_test.py#L63 @@ -18,7 +13,7 @@ describe('rust-verkle test vectors', () => { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, ]) - const trie = await createVerkleTree({ verkleCrypto, db: new MapDB() }) + const trie = await createVerkleTree({ verkleCrypto: verkle, db: new MapDB() }) await trie.put(key.slice(0, 31), [key[31]], [key]) const path = await trie.findPath(key.slice(0, 31)) @@ -40,7 +35,7 @@ describe('rust-verkle test vectors', () => { 27, 28, 29, 30, 31, 32, ]) const stem = key.slice(0, 31) - const trie = await createVerkleTree({ verkleCrypto, db: new MapDB() }) + const trie = await createVerkleTree({ verkleCrypto: verkle, db: new MapDB() }) await trie.put(stem, [key[31]], [new Uint8Array(32)]) let path = await trie.findPath(stem) assert.equal( diff --git a/packages/verkle/test/leafNode.spec.ts b/packages/verkle/test/leafNode.spec.ts index b08551a53c..6cfa517370 100644 --- a/packages/verkle/test/leafNode.spec.ts +++ b/packages/verkle/test/leafNode.spec.ts @@ -1,6 +1,6 @@ -import { type VerkleCrypto, equalsBytes, randomBytes, setLengthRight } from '@ethereumjs/util' +import { equalsBytes, randomBytes, setLengthRight } from '@ethereumjs/util' import * as verkle from 'micro-eth-signer/verkle' -import { assert, beforeAll, describe, it } from 'vitest' +import { assert, describe, it } from 'vitest' import { LeafVerkleNodeValue, @@ -10,13 +10,8 @@ import { isLeafVerkleNode, } from '../src/node/index.js' import { LeafVerkleNode } from '../src/node/leafNode.js' -const loadVerkleCrypto = () => Promise.resolve(verkle) describe('verkle node - leaf', () => { - let verkleCrypto = undefined as never as VerkleCrypto - beforeAll(async () => { - verkleCrypto = await loadVerkleCrypto() - }) it('constructor should create an leaf node', async () => { const commitment = randomBytes(64) const c1 = randomBytes(64) @@ -29,7 +24,7 @@ describe('verkle node - leaf', () => { commitment, stem, values, - verkleCrypto, + verkleCrypto: verkle, }) assert.ok(isLeafVerkleNode(node), 'typeguard should return true') @@ -53,13 +48,13 @@ describe('verkle node - leaf', () => { const values = new Array(256).fill(new Uint8Array(32)) values[2] = value const stem = key.slice(0, 31) - const node = await LeafVerkleNode.create(stem, verkleCrypto, values) + const node = await LeafVerkleNode.create(stem, verkle, values) assert.ok(node instanceof LeafVerkleNode) }) it('should create a leafnode with default values', async () => { const key = randomBytes(32) - const node = await LeafVerkleNode.create(key.slice(0, 31), verkleCrypto) + const node = await LeafVerkleNode.create(key.slice(0, 31), verkle) assert.ok(node instanceof LeafVerkleNode) assert.equal(node.getValue(0), undefined) node.setValue(0, setLengthRight(Uint8Array.from([5]), 32)) @@ -70,7 +65,7 @@ describe('verkle node - leaf', () => { it('should set the leaf marker on a touched value', async () => { const key = randomBytes(32) - const node = await LeafVerkleNode.create(key.slice(0, 31), verkleCrypto) + const node = await LeafVerkleNode.create(key.slice(0, 31), verkle) node.setValue(0, LeafVerkleNodeValue.Deleted) const c1Values = createCValues(node.values.slice(0, 128)) assert.equal(c1Values[0][16], 1) @@ -79,14 +74,14 @@ describe('verkle node - leaf', () => { it('should update a commitment when setting a value', async () => { const key = randomBytes(32) const stem = key.slice(0, 31) - const node = await LeafVerkleNode.create(stem, verkleCrypto) + const node = await LeafVerkleNode.create(stem, verkle) const hash = node.hash() - assert.deepEqual(node.c1, verkleCrypto.zeroCommitment) + assert.deepEqual(node.c1, verkle.zeroCommitment) node.setValue(0, randomBytes(32)) - assert.notDeepEqual(node.c1, verkleCrypto.zeroCommitment) + assert.notDeepEqual(node.c1, verkle.zeroCommitment) assert.notDeepEqual(node.hash(), hash) node.setValue(0, LeafVerkleNodeValue.Untouched) - assert.deepEqual(node.c1, verkleCrypto.zeroCommitment) + assert.deepEqual(node.c1, verkle.zeroCommitment) assert.deepEqual(node.hash(), hash) }) @@ -94,14 +89,14 @@ describe('verkle node - leaf', () => { const key = randomBytes(32) const stem = key.slice(0, 31) const values = new Array(256).fill(new Uint8Array(32)) - const node = await LeafVerkleNode.create(stem, verkleCrypto, values) + const node = await LeafVerkleNode.create(stem, verkle, values) const serialized = node.serialize() - const decodedNode = decodeVerkleNode(serialized, verkleCrypto) + const decodedNode = decodeVerkleNode(serialized, verkle) assert.deepEqual(node, decodedNode) - const defaultNode = await LeafVerkleNode.create(randomBytes(31), verkleCrypto) + const defaultNode = await LeafVerkleNode.create(randomBytes(31), verkle) - assert.deepEqual(defaultNode, decodeVerkleNode(defaultNode.serialize(), verkleCrypto)) + assert.deepEqual(defaultNode, decodeVerkleNode(defaultNode.serialize(), verkle)) }) }) diff --git a/packages/verkle/test/proof.spec.ts b/packages/verkle/test/proof.spec.ts index acff960f62..5e924c33d4 100644 --- a/packages/verkle/test/proof.spec.ts +++ b/packages/verkle/test/proof.spec.ts @@ -1,20 +1,14 @@ import { MapDB, bigIntToBytes, hexToBytes, randomBytes, setLengthRight } from '@ethereumjs/util' import * as verkle from 'micro-eth-signer/verkle' -import { assert, beforeAll, describe, it } from 'vitest' +import { assert, describe, it } from 'vitest' import { createVerkleTree } from '../src/constructors.js' import { LeafVerkleNode } from '../src/index.js' -import type { PrefixedHexString, VerkleCrypto } from '@ethereumjs/util' +import type { PrefixedHexString } from '@ethereumjs/util' import type { ProverInput, VerifierInput } from 'micro-eth-signer/verkle' -const loadVerkleCrypto = () => Promise.resolve(verkle) - describe('lets make proofs', () => { - let verkleCrypto: VerkleCrypto - beforeAll(async () => { - verkleCrypto = await loadVerkleCrypto() - }) it.skip('should generate a proof of a specific state root and then verify it', async () => { const keys = [ // Two keys with the same stem but different suffixes @@ -48,41 +42,41 @@ describe('lets make proofs', () => { valuesArray.push(value) } const proofInput: ProverInput = { - serializedCommitment: verkleCrypto.serializeCommitment(leafNode.commitment), // serialized (not hashed!) node commitment + serializedCommitment: verkle.serializeCommitment(leafNode.commitment), // serialized (not hashed!) node commitment vector: valuesArray, // All values from node indices: [1], // Position in values array (aka "z value") } - const proof = verkleCrypto.createProof([proofInput]) + const proof = verkle.createProof([proofInput]) const verificationInput: VerifierInput = { - serializedCommitment: verkleCrypto.serializeCommitment(leafNode.commitment), // serialized leafNode commitment + serializedCommitment: verkle.serializeCommitment(leafNode.commitment), // serialized leafNode commitment indexValuePairs: [{ index: 1, value: leafNode.getValue(1)! }], // Position in values array (aka "z value") } try { - const res = verkleCrypto.verifyProof(proof, [verificationInput]) + const res = verkle.verifyProof(proof, [verificationInput]) assert.ok(res) } catch (err) { assert.fail(`Failed to verify proof: ${err}`) } }) it('should pass for empty trie', async () => { - const trie = await createVerkleTree({ verkleCrypto, db: new MapDB() }) + const trie = await createVerkleTree({ verkleCrypto: verkle, db: new MapDB() }) - const proof = verkleCrypto.createProof([ + const proof = verkle.createProof([ { // Get commitment from root node - serializedCommitment: verkleCrypto.serializeCommitment( + serializedCommitment: verkle.serializeCommitment( (await trie.findPath(new Uint8Array(31))).stack![0][0].commitment, ), vector: new Array(256).fill(new Uint8Array(32)), indices: [0], }, ]) - const res = verkleCrypto.verifyProof(proof, [ + const res = verkle.verifyProof(proof, [ { - serializedCommitment: verkleCrypto.serializeCommitment( + serializedCommitment: verkle.serializeCommitment( (await trie.findPath(new Uint8Array(31))).stack![0][0].commitment, ), indexValuePairs: [{ index: 0, value: new Uint8Array(32) }], @@ -91,7 +85,7 @@ describe('lets make proofs', () => { assert.ok(res) }) it.skip('should verify proof for single leaf node', async () => { - const node = await LeafVerkleNode.create(randomBytes(31), verkleCrypto) + const node = await LeafVerkleNode.create(randomBytes(31), verkle) node.setValue(0, setLengthRight(bigIntToBytes(1n), 32)) const valuesArray = new Array(256) for (let x = 0; x < 256; x++) { @@ -100,17 +94,17 @@ describe('lets make proofs', () => { valuesArray[x] = value } - const proof = verkleCrypto.createProof([ + const proof = verkle.createProof([ { - serializedCommitment: verkleCrypto.serializeCommitment(node.commitment), + serializedCommitment: verkle.serializeCommitment(node.commitment), vector: valuesArray, indices: [0], }, ]) - const res = verkleCrypto.verifyProof(proof, [ + const res = verkle.verifyProof(proof, [ { - serializedCommitment: verkleCrypto.serializeCommitment(node.commitment), + serializedCommitment: verkle.serializeCommitment(node.commitment), indexValuePairs: [{ index: 0, value: node.getValue(0)! }], }, ]) diff --git a/packages/verkle/test/verkle.spec.ts b/packages/verkle/test/verkle.spec.ts index 0df6d4e20f..2c02769a4d 100644 --- a/packages/verkle/test/verkle.spec.ts +++ b/packages/verkle/test/verkle.spec.ts @@ -1,6 +1,6 @@ import { MapDB, equalsBytes, hexToBytes, matchingBytesLength } from '@ethereumjs/util' import * as verkle from 'micro-eth-signer/verkle' -import { assert, beforeAll, describe, it } from 'vitest' +import { assert, describe, it } from 'vitest' import { InternalVerkleNode, @@ -12,15 +12,9 @@ import { } from '../src/index.js' import type { VerkleNode } from '../src/index.js' -import type { PrefixedHexString, VerkleCrypto } from '@ethereumjs/util' -const loadVerkleCrypto = () => Promise.resolve(verkle) +import type { PrefixedHexString } from '@ethereumjs/util' describe('Verkle tree', () => { - let verkleCrypto: VerkleCrypto - beforeAll(async () => { - verkleCrypto = await loadVerkleCrypto() - }) - it('should instantiate with verkle crypto and a MapDB if no options are provided', async () => { const tree = await createVerkleTree() assert.ok(tree['_db'].db instanceof MapDB) @@ -94,7 +88,7 @@ describe('Verkle tree', () => { ].map((key) => hexToBytes(key as PrefixedHexString)) const tree = await createVerkleTree({ - verkleCrypto, + verkleCrypto: verkle, }) const res = await tree.findPath(presentKeys[0]) @@ -123,7 +117,7 @@ describe('Verkle tree', () => { const pathToNonExistentNode = await tree.findPath(absentKeys[0]) assert.equal(pathToNonExistentNode.node, null) assert.deepEqual( - verkleCrypto.serializeCommitment(pathToNonExistentNode.stack[0][0].commitment), + verkle.serializeCommitment(pathToNonExistentNode.stack[0][0].commitment), tree.root(), 'contains the root node in the stack', ) @@ -145,12 +139,12 @@ describe('Verkle tree', () => { '0x0000000000000000000000000000000000000000000000000000000000000000', '0x0300000000000000000000000000000000000000000000000000000000000000', ].map((key) => hexToBytes(key as PrefixedHexString)) - const trie = await createVerkleTree({ verkleCrypto }) + const trie = await createVerkleTree({ verkleCrypto: verkle }) let putStack: [Uint8Array, VerkleNode][] = [] const stem1 = keys[0].slice(0, 31) // Create first leaf node - const leafNode1 = await LeafVerkleNode.create(stem1, verkleCrypto) + const leafNode1 = await LeafVerkleNode.create(stem1, verkle) leafNode1.setValue(keys[0][31], values[0]) leafNode1.setValue(keys[1][31], values[1]) @@ -159,10 +153,10 @@ describe('Verkle tree', () => { // Pull root node from DB const rawNode = await trie['_db'].get(trie.root()) - const rootNode = decodeVerkleNode(rawNode!, verkleCrypto) as InternalVerkleNode + const rootNode = decodeVerkleNode(rawNode!, verkle) as InternalVerkleNode // Update root node with commitment from leaf node rootNode.setChild(stem1[0], { commitment: leafNode1.commitment, path: stem1 }) - trie.root(verkleCrypto.serializeCommitment(rootNode.commitment)) + trie.root(verkle.serializeCommitment(rootNode.commitment)) putStack.push([trie.root(), rootNode]) await trie.saveStack(putStack) @@ -185,7 +179,7 @@ describe('Verkle tree', () => { assert.equal(foundPath.node, null) // Create new leaf node - const leafNode2 = await LeafVerkleNode.create(stem2, verkleCrypto) + const leafNode2 = await LeafVerkleNode.create(stem2, verkle) leafNode2.setValue(keys[2][31], values[2]) putStack.push([leafNode2.hash(), leafNode2]) @@ -199,7 +193,7 @@ describe('Verkle tree', () => { // Find the path to the new internal node (the matching portion of stem1 and stem2) const internalNode1Path = stem1.slice(0, partialMatchingStemIndex) // Create new internal node - const internalNode1 = InternalVerkleNode.create(verkleCrypto) + const internalNode1 = InternalVerkleNode.create(verkle) // Update the child references for leafNode1 and leafNode 2 internalNode1.setChild(stem1[partialMatchingStemIndex], { @@ -221,7 +215,7 @@ describe('Verkle tree', () => { commitment: internalNode1.commitment, path: internalNode1Path, }) - trie.root(verkleCrypto.serializeCommitment(rootNodeFromPath.commitment)) + trie.root(verkle.serializeCommitment(rootNodeFromPath.commitment)) putStack.push([trie.root(), rootNodeFromPath]) await trie.saveStack(putStack) let res2 = await trie.findPath(stem1) @@ -251,7 +245,7 @@ describe('Verkle tree', () => { '0x0000000000000000000000000000000000000000000000000000000000000000', '0x0300000000000000000000000000000000000000000000000000000000000000', ].map((key) => hexToBytes(key as PrefixedHexString)) - const trie = await createVerkleTree({ verkleCrypto }) + const trie = await createVerkleTree({ verkleCrypto: verkle }) const keyWithMultipleValues = keys[0].slice(0, 31) await trie.put(keyWithMultipleValues, [keys[0][31], keys[1][31]], [values[0], values[1]]) @@ -270,7 +264,7 @@ describe('Verkle tree', () => { it('should put zeros in leaf node when del called with stem that was not in the trie before', async () => { const keys = [hexToBytes('0x318dea512b6f3237a2d4763cf49bf26de3b617fb0cabe38a97807a5549df4d01')] - const trie = await createVerkleTree({ verkleCrypto }) + const trie = await createVerkleTree({ verkleCrypto: verkle }) assert.deepEqual(await trie.get(keys[0].slice(0, 31), [keys[0][31]]), []) @@ -292,7 +286,7 @@ describe('Verkle tree', () => { '0x320122e8584be00d000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000000000000000000001', ].map((key) => hexToBytes(key as PrefixedHexString)) - const trie = await createVerkleTree({ verkleCrypto }) + const trie = await createVerkleTree({ verkleCrypto: verkle }) await trie.put(keys[0].slice(0, 31), [keys[0][31]], [values[0]]) await trie.put(keys[1].slice(0, 31), [keys[1][31]], [values[1]]) const root2 = trie.root() diff --git a/packages/vm/src/runBlock.ts b/packages/vm/src/runBlock.ts index 4ccb52434e..24b0926335 100644 --- a/packages/vm/src/runBlock.ts +++ b/packages/vm/src/runBlock.ts @@ -48,7 +48,6 @@ import type { import type { VM } from './vm.js' import type { Block } from '@ethereumjs/block' import type { Common } from '@ethereumjs/common' -import type { StatefulVerkleStateManager } from '@ethereumjs/statemanager' import type { CLRequest, CLRequestType, PrefixedHexString } from '@ethereumjs/util' const debug = debugDefault('vm:block') @@ -137,10 +136,12 @@ export async function runBlock(vm: VM, opts: RunBlockOpts): Promise Promise.resolve(verkle) const customChainParams = { name: 'custom', chainId: 69420 } const common = createCustomCommon(customChainParams, Mainnet, { hardfork: Hardfork.Cancun, eips: [2935, 4895, 6800], + customCrypto: { verkleCrypto: verkle }, }) const decodedTxs = verkleKaustinen6Block72Data.transactions?.map((tx) => createTxFromRLP(hexToBytes(tx), { common }), @@ -34,11 +34,10 @@ const block = createBlock( describe('EIP 6800 tests', () => { // TODO: Turn back on once we have kaustinen7 block data it.skip('successfully run transactions statelessly using the block witness', async () => { - const verkleCrypto = await loadVerkleCrypto() + common.customCrypto.verkleCrypto = verkle const verkleStateManager = new StatelessVerkleStateManager({ caches: new Caches(), common, - verkleCrypto, }) const evm = await createEVM({ common, stateManager: verkleStateManager }) const vm = await createVM({ diff --git a/packages/vm/test/api/runBlock.spec.ts b/packages/vm/test/api/runBlock.spec.ts index e4b285c3ff..b7b65af2ea 100644 --- a/packages/vm/test/api/runBlock.spec.ts +++ b/packages/vm/test/api/runBlock.spec.ts @@ -35,7 +35,7 @@ import { } from '@ethereumjs/util' import { keccak256 } from 'ethereum-cryptography/keccak' import * as verkle from 'micro-eth-signer/verkle' -import { assert, beforeAll, describe, it } from 'vitest' +import { assert, describe, it } from 'vitest' import { createVM, runBlock } from '../../src/index.js' import { getDAOCommon, setupPreConditions } from '../util.js' @@ -53,13 +53,7 @@ import type { } from '../../src/types.js' import type { Block, BlockBytes } from '@ethereumjs/block' import type { AuthorizationListBytesItem, TypedTransaction } from '@ethereumjs/tx' -import type { - NestedUint8Array, - PrefixedHexString, - VerkleCrypto, - VerkleExecutionWitness, -} from '@ethereumjs/util' -const loadVerkleCrypto = () => Promise.resolve(verkle) +import type { NestedUint8Array, PrefixedHexString, VerkleExecutionWitness } from '@ethereumjs/util' const common = new Common({ chain: Mainnet, hardfork: Hardfork.Berlin }) describe('runBlock() -> successful API parameter usage', async () => { @@ -687,10 +681,6 @@ describe('runBlock() -> tx types', async () => { }) describe.skip('run a verkle block', () => { - let verkleCrypto: VerkleCrypto - beforeAll(async () => { - verkleCrypto = await loadVerkleCrypto() - }) it('should execute a verkle block and produce an executionWitness', async () => { const verkleJSONWithoutValue = (await import('./testdata/verkleBlock.js')).block const verkleJSONWithValue = (await import('./testdata/verkleBlockWithValue.js')).block @@ -698,6 +688,7 @@ describe.skip('run a verkle block', () => { const common = new Common({ chain: Mainnet, + customCrypto: { verkleCrypto: verkle }, hardfork: Hardfork.Shanghai, eips: [2935, 3607, 6800], }) @@ -708,7 +699,7 @@ describe.skip('run a verkle block', () => { const blockRlp = hexToBytes(verkleJSON.blocks[0].rlp as PrefixedHexString) const block = createBlockFromRLP(blockRlp, { common }) - const sm = new StatefulVerkleStateManager({ verkleCrypto }) + const sm = new StatefulVerkleStateManager({ common }) await sm['_trie'].createRootNode() const blockchain = await createBlockchain({ common }) const vm = await setupVM({ common, stateManager: sm, blockchain, genesisBlock })