From c9aa8498f7081c3b833e88d1c31d14a1a698bcd4 Mon Sep 17 00:00:00 2001 From: Holger Drewes Date: Tue, 18 Jun 2024 12:56:09 +0200 Subject: [PATCH 01/15] EVM: Replace direct StatelessVerkleStateManager (SVSM) cast with verkle-extended interface usage --- packages/common/src/interfaces.ts | 11 +++++++++++ packages/evm/src/interpreter.ts | 6 ++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/packages/common/src/interfaces.ts b/packages/common/src/interfaces.ts index c9731207cd..534ea123d1 100644 --- a/packages/common/src/interfaces.ts +++ b/packages/common/src/interfaces.ts @@ -65,6 +65,10 @@ export type AccessListBytesItem = [Uint8Array, Uint8Array[]] export type AccessListBytes = AccessListBytesItem[] export type AccessList = AccessListItem[] +/* + * Generic StateManager interface corresponding with the @ethereumjs/statemanager package + * + */ export interface StateManagerInterface { getAccount(address: Address): Promise putAccount(address: Address, account?: Account): Promise @@ -85,6 +89,13 @@ export interface StateManagerInterface { hasStateRoot(root: Uint8Array): Promise // only used in client shallowCopy(downlevelCaches?: boolean): StateManagerInterface getAppliedKey?(address: Uint8Array): Uint8Array + + /* + * The following optional methods are Verkle related + * + * Experimental (do not implement) + */ + checkChunkWitnessPresent?(contract: Address, programCounter: number): Promise } export interface EVMStateManagerInterface extends StateManagerInterface { diff --git a/packages/evm/src/interpreter.ts b/packages/evm/src/interpreter.ts index b5c592ba35..c4fcd418d2 100644 --- a/packages/evm/src/interpreter.ts +++ b/packages/evm/src/interpreter.ts @@ -24,7 +24,7 @@ import type { Journal } from './journal.js' import type { AsyncOpHandler, Opcode, OpcodeMapEntry } from './opcodes/index.js' import type { Block, Blockchain, EVMProfilerOpts, EVMResult, Log } from './types.js' import type { Common, EVMStateManagerInterface } from '@ethereumjs/common' -import type { AccessWitness, StatelessVerkleStateManager } from '@ethereumjs/statemanager' +import type { AccessWitness } from '@ethereumjs/statemanager' import type { Address, PrefixedHexString } from '@ethereumjs/util' const { debug: createDebugLogger } = debugDefault @@ -272,9 +272,7 @@ export class Interpreter { const contract = this._runState.interpreter.getAddress() if ( - !(await ( - this._runState.stateManager as StatelessVerkleStateManager - ).checkChunkWitnessPresent(contract, programCounter)) + !(await this._runState.stateManager.checkChunkWitnessPresent!(contract, programCounter)) ) { throw Error(`Invalid witness with missing codeChunk for pc=${programCounter}`) } From 7cad2fb319f78f625f363fd896302eab9cff2dac Mon Sep 17 00:00:00 2001 From: Holger Drewes Date: Tue, 18 Jun 2024 13:04:30 +0200 Subject: [PATCH 02/15] Add experimental AccessWitnessInterface to Common, use interface for AccessWitness implementation in StateManager --- packages/common/src/interfaces.ts | 54 ++++++++++++++++++++++ packages/statemanager/src/accessWitness.ts | 21 +++------ 2 files changed, 61 insertions(+), 14 deletions(-) diff --git a/packages/common/src/interfaces.ts b/packages/common/src/interfaces.ts index 534ea123d1..d3e1ac15bc 100644 --- a/packages/common/src/interfaces.ts +++ b/packages/common/src/interfaces.ts @@ -65,6 +65,60 @@ export type AccessListBytesItem = [Uint8Array, Uint8Array[]] export type AccessListBytes = AccessListBytesItem[] export type AccessList = AccessListItem[] +/** + * Verkle related + * + * Experimental (do not implement) + */ +export type AccessEventFlags = { + stemRead: boolean + stemWrite: boolean + chunkRead: boolean + chunkWrite: boolean + chunkFill: boolean +} + +/** + * Verkle related + * + * Experimental (do not implement) + */ +export interface AccessWitnessInterface { + touchAndChargeProofOfAbsence(address: Address): bigint + touchAndChargeMessageCall(address: Address): bigint + touchAndChargeValueTransfer(caller: Address, target: Address): bigint + touchAndChargeContractCreateInit(address: Address): bigint + touchAndChargeContractCreateCompleted(address: Address): bigint + touchTxOriginAndComputeGas(origin: Address): bigint + touchTxTargetAndComputeGas(target: Address, { sendsValue }: { sendsValue?: boolean }): bigint + touchCodeChunksRangeOnReadAndChargeGas(contact: Address, startPc: number, endPc: number): bigint + touchCodeChunksRangeOnWriteAndChargeGas(contact: Address, startPc: number, endPc: number): bigint + touchAddressOnWriteAndComputeGas( + address: Address, + treeIndex: number | bigint, + subIndex: number | Uint8Array + ): bigint + touchAddressOnReadAndComputeGas( + address: Address, + treeIndex: number | bigint, + subIndex: number | Uint8Array + ): bigint + touchAddressAndChargeGas( + address: Address, + treeIndex: number | bigint, + subIndex: number | Uint8Array, + { isWrite }: { isWrite?: boolean } + ): bigint + touchAddress( + address: Address, + treeIndex: number | bigint, + subIndex: number | Uint8Array, + { isWrite }: { isWrite?: boolean } + ): AccessEventFlags + shallowCopy(): AccessWitnessInterface + merge(accessWitness: AccessWitnessInterface): void +} + /* * Generic StateManager interface corresponding with the @ethereumjs/statemanager package * diff --git a/packages/statemanager/src/accessWitness.ts b/packages/statemanager/src/accessWitness.ts index 916a922277..87913d9595 100644 --- a/packages/statemanager/src/accessWitness.ts +++ b/packages/statemanager/src/accessWitness.ts @@ -15,6 +15,7 @@ import { } from '@ethereumjs/verkle' import debugDefault from 'debug' +import type { AccessEventFlags, AccessWitnessInterface } from '@ethereumjs/common' import type { Address, PrefixedHexString } from '@ethereumjs/util' import type { VerkleCrypto } from '@ethereumjs/verkle' @@ -36,14 +37,6 @@ type StemAccessEvent = { write?: boolean } // in upcoming iterations type ChunkAccessEvent = StemAccessEvent & { fill?: boolean } -type AccessEventFlags = { - stemRead: boolean - stemWrite: boolean - chunkRead: boolean - chunkWrite: boolean - chunkFill: boolean -} - // Since stem is pedersen hashed, it is useful to maintain the reverse relationship type StemMeta = { address: Address; treeIndex: number | bigint } type RawAccessedState = { @@ -72,7 +65,7 @@ export type AccessedStateWithAddress = AccessedState & { chunkKey: PrefixedHexString } -export class AccessWitness { +export class AccessWitness implements AccessWitnessInterface { stems: Map chunks: Map verkleCrypto: VerkleCrypto @@ -225,20 +218,20 @@ export class AccessWitness { { isWrite } ) - if (stemRead) { + if (stemRead === true) { gas += WitnessBranchReadCost } - if (stemWrite) { + if (stemWrite === true) { gas += WitnessBranchWriteCost } - if (chunkRead) { + if (chunkRead === true) { gas += WitnessChunkReadCost } - if (chunkWrite) { + if (chunkWrite === true) { gas += WitnessChunkWriteCost } - if (chunkFill) { + if (chunkFill === true) { gas += WitnessChunkFillCost } From 1b528c65dc46b98fdb230a560fe0394bd037e31f Mon Sep 17 00:00:00 2001 From: Holger Drewes Date: Tue, 18 Jun 2024 13:08:26 +0200 Subject: [PATCH 03/15] Use AccessWitnessInterface in EVM --- packages/evm/src/interpreter.ts | 5 ++--- packages/evm/src/message.ts | 6 +++--- packages/evm/src/types.ts | 5 ++--- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/packages/evm/src/interpreter.ts b/packages/evm/src/interpreter.ts index c4fcd418d2..bba5c9ce90 100644 --- a/packages/evm/src/interpreter.ts +++ b/packages/evm/src/interpreter.ts @@ -23,8 +23,7 @@ import type { EVM } from './evm.js' import type { Journal } from './journal.js' import type { AsyncOpHandler, Opcode, OpcodeMapEntry } from './opcodes/index.js' import type { Block, Blockchain, EVMProfilerOpts, EVMResult, Log } from './types.js' -import type { Common, EVMStateManagerInterface } from '@ethereumjs/common' -import type { AccessWitness } from '@ethereumjs/statemanager' +import type { AccessWitnessInterface, Common, EVMStateManagerInterface } from '@ethereumjs/common' import type { Address, PrefixedHexString } from '@ethereumjs/util' const { debug: createDebugLogger } = debugDefault @@ -68,7 +67,7 @@ export interface Env { containerCode?: Uint8Array /** Full container code for EOF1 contracts */ blobVersionedHashes: Uint8Array[] /** Versioned hashes for blob transactions */ createdAddresses?: Set - accessWitness?: AccessWitness + accessWitness?: AccessWitnessInterface chargeCodeAccesses?: boolean } diff --git a/packages/evm/src/message.ts b/packages/evm/src/message.ts index 0b7c60a482..85cefdf583 100644 --- a/packages/evm/src/message.ts +++ b/packages/evm/src/message.ts @@ -1,7 +1,7 @@ import { Address, BIGINT_0 } from '@ethereumjs/util' import type { PrecompileFunc } from './precompiles/index.js' -import type { AccessWitness } from '@ethereumjs/statemanager' +import type { AccessWitnessInterface } from '@ethereumjs/common' import type { PrefixedHexString } from '@ethereumjs/util' const defaults = { @@ -39,7 +39,7 @@ interface MessageOpts { authcallOrigin?: Address gasRefund?: bigint blobVersionedHashes?: Uint8Array[] - accessWitness?: AccessWitness + accessWitness?: AccessWitnessInterface } export class Message { @@ -75,7 +75,7 @@ export class Message { * List of versioned hashes if message is a blob transaction in the outer VM */ blobVersionedHashes?: Uint8Array[] - accessWitness?: AccessWitness + accessWitness?: AccessWitnessInterface constructor(opts: MessageOpts) { this.to = opts.to diff --git a/packages/evm/src/types.ts b/packages/evm/src/types.ts index 0621bab859..37ce910079 100644 --- a/packages/evm/src/types.ts +++ b/packages/evm/src/types.ts @@ -7,8 +7,7 @@ import type { AsyncDynamicGasHandler, SyncDynamicGasHandler } from './opcodes/ga import type { OpHandler } from './opcodes/index.js' import type { CustomPrecompile } from './precompiles/index.js' import type { PrecompileFunc } from './precompiles/types.js' -import type { Common, EVMStateManagerInterface } from '@ethereumjs/common' -import type { AccessWitness } from '@ethereumjs/statemanager' +import type { AccessWitnessInterface, Common, EVMStateManagerInterface } from '@ethereumjs/common' import type { Account, Address, AsyncEventEmitter, PrefixedHexString } from '@ethereumjs/util' export type DeleteOpcode = { @@ -124,7 +123,7 @@ export interface EVMRunCallOpts extends EVMRunOpts { */ message?: Message - accessWitness?: AccessWitness + accessWitness?: AccessWitnessInterface } interface NewContractEvent { From f7e22d2bd17b1e0a3e3691607476c1ce939fc06b Mon Sep 17 00:00:00 2001 From: Holger Drewes Date: Tue, 18 Jun 2024 14:08:18 +0200 Subject: [PATCH 04/15] Add verkle module to Util, replace EVM function calls, remove @ethereumjs/verkle dependency --- packages/evm/package.json | 1 - packages/evm/src/opcodes/functions.ts | 2 +- packages/evm/src/opcodes/gas.ts | 10 ++-- packages/util/src/index.ts | 1 + packages/util/src/verkle.ts | 83 +++++++++++++++++++++++++++ 5 files changed, 89 insertions(+), 8 deletions(-) create mode 100644 packages/util/src/verkle.ts diff --git a/packages/evm/package.json b/packages/evm/package.json index b5a3d071a7..fba80237d7 100644 --- a/packages/evm/package.json +++ b/packages/evm/package.json @@ -58,7 +58,6 @@ "@ethereumjs/statemanager": "^2.3.0", "@ethereumjs/tx": "^5.3.0", "@ethereumjs/util": "^9.0.3", - "@ethereumjs/verkle": "^0.0.2", "@types/debug": "^4.1.9", "debug": "^4.3.3", "ethereum-cryptography": "^2.1.3", diff --git a/packages/evm/src/opcodes/functions.ts b/packages/evm/src/opcodes/functions.ts index d6bdfc423d..7807bc82c7 100644 --- a/packages/evm/src/opcodes/functions.ts +++ b/packages/evm/src/opcodes/functions.ts @@ -26,12 +26,12 @@ import { bytesToHex, concatBytes, ecrecover, + getTreeIndexesForStorageSlot, hexToBytes, publicToAddress, setLengthLeft, setLengthRight, } from '@ethereumjs/util' -import { getTreeIndexesForStorageSlot } from '@ethereumjs/verkle' import { keccak256 } from 'ethereum-cryptography/keccak.js' import { ERROR } from '../exceptions.js' diff --git a/packages/evm/src/opcodes/gas.ts b/packages/evm/src/opcodes/gas.ts index 0ed6688aea..010f996a92 100644 --- a/packages/evm/src/opcodes/gas.ts +++ b/packages/evm/src/opcodes/gas.ts @@ -2,21 +2,19 @@ import { Hardfork } from '@ethereumjs/common' import { Account, Address, + BALANCE_LEAF_KEY, BIGINT_0, BIGINT_1, BIGINT_3, BIGINT_31, BIGINT_32, - bigIntToBytes, - setLengthLeft, -} from '@ethereumjs/util' -import { - BALANCE_LEAF_KEY, CODE_HASH_LEAF_KEY, CODE_SIZE_LEAF_KEY, VERSION_LEAF_KEY, + bigIntToBytes, getTreeIndexesForStorageSlot, -} from '@ethereumjs/verkle' + setLengthLeft, +} from '@ethereumjs/util' import { ERROR } from '../exceptions.js' diff --git a/packages/util/src/index.ts b/packages/util/src/index.ts index 3b99e04a01..bc3e1462cf 100644 --- a/packages/util/src/index.ts +++ b/packages/util/src/index.ts @@ -65,3 +65,4 @@ export * from './lock.js' export * from './mapDB.js' export * from './provider.js' export * from './requests.js' +export * from './verkle.js' diff --git a/packages/util/src/verkle.ts b/packages/util/src/verkle.ts new file mode 100644 index 0000000000..75694a4167 --- /dev/null +++ b/packages/util/src/verkle.ts @@ -0,0 +1,83 @@ +import { concatBytes, intToBytes } from './bytes.js' + +/** + * Verkle related constants and helper functions + * + * Experimental (do not use in production!) + */ + +// TODO: this comes with a deprecation of the respective constants and methods within the +// @ethereumjs/verkle package. Due to ease of parallel work this has not yet been executed upon, +// so this still needs a small follow-up clean up PR. +// +// Along with the PR likely more/additional helper functionality should be moved over +// (basically everything generic not depending on Verkle cryptography) +// +// Holger Drewes, 2024-06-18 + +export enum LeafType { + Version = 0, + Balance = 1, + Nonce = 2, + CodeHash = 3, + CodeSize = 4, +} + +export const VERSION_LEAF_KEY = intToBytes(LeafType.Version) +export const BALANCE_LEAF_KEY = intToBytes(LeafType.Balance) +export const NONCE_LEAF_KEY = intToBytes(LeafType.Nonce) +export const CODE_HASH_LEAF_KEY = intToBytes(LeafType.CodeHash) +export const CODE_SIZE_LEAF_KEY = intToBytes(LeafType.CodeSize) + +export const HEADER_STORAGE_OFFSET = 64 +export const CODE_OFFSET = 128 +export const VERKLE_NODE_WIDTH = 256 +export const MAIN_STORAGE_OFFSET = BigInt(256) ** BigInt(31) + +/** + * @dev Returns the tree key for a given verkle tree stem, and sub index. + * @dev Assumes that the verkle node width = 256 + * @param stem The 31-bytes verkle tree stem as a Uint8Array. + * @param subIndex The sub index of the tree to generate the key for as a Uint8Array. + * @return The tree key as a Uint8Array. + */ + +export const getKey = (stem: Uint8Array, leaf: LeafType | Uint8Array) => { + switch (leaf) { + case LeafType.Version: + return concatBytes(stem, VERSION_LEAF_KEY) + case LeafType.Balance: + return concatBytes(stem, BALANCE_LEAF_KEY) + case LeafType.Nonce: + return concatBytes(stem, NONCE_LEAF_KEY) + case LeafType.CodeHash: + return concatBytes(stem, CODE_HASH_LEAF_KEY) + case LeafType.CodeSize: + return concatBytes(stem, CODE_SIZE_LEAF_KEY) + default: + return concatBytes(stem, leaf) + } +} + +export function getTreeIndexesForStorageSlot(storageKey: bigint): { + treeIndex: bigint + subIndex: number +} { + let position: bigint + if (storageKey < CODE_OFFSET - HEADER_STORAGE_OFFSET) { + position = BigInt(HEADER_STORAGE_OFFSET) + storageKey + } else { + position = MAIN_STORAGE_OFFSET + storageKey + } + + const treeIndex = position / BigInt(VERKLE_NODE_WIDTH) + const subIndex = Number(position % BigInt(VERKLE_NODE_WIDTH)) + + return { treeIndex, subIndex } +} + +export function getTreeIndicesForCodeChunk(chunkId: number) { + const treeIndex = Math.floor((CODE_OFFSET + chunkId) / VERKLE_NODE_WIDTH) + const subIndex = (CODE_OFFSET + chunkId) % VERKLE_NODE_WIDTH + return { treeIndex, subIndex } +} From 32ab354485abd9e88f1d478f4a6118452a2effe3 Mon Sep 17 00:00:00 2001 From: Holger Drewes Date: Tue, 18 Jun 2024 14:08:39 +0200 Subject: [PATCH 05/15] Rebuild package-lock.json --- package-lock.json | 1 - 1 file changed, 1 deletion(-) diff --git a/package-lock.json b/package-lock.json index 69fdc9ffd3..b1e26a5021 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13641,7 +13641,6 @@ "@ethereumjs/statemanager": "^2.3.0", "@ethereumjs/tx": "^5.3.0", "@ethereumjs/util": "^9.0.3", - "@ethereumjs/verkle": "^0.0.2", "@types/debug": "^4.1.9", "debug": "^4.3.3", "ethereum-cryptography": "^2.1.3", From b05093c662c6699315c07d30e91cda758b941822 Mon Sep 17 00:00:00 2001 From: Holger Drewes Date: Wed, 19 Jun 2024 10:40:13 +0200 Subject: [PATCH 06/15] Move VerkleCrypto type from verkle-cryptography-wasm to Util --- packages/statemanager/src/accessWitness.ts | 3 +-- .../statemanager/src/statelessVerkleStateManager.ts | 3 +-- packages/util/src/verkle.ts | 13 +++++++++++++ packages/verkle/src/types.ts | 3 --- packages/verkle/src/util/crypto.ts | 2 +- packages/verkle/src/util/keys.ts | 3 +-- 6 files changed, 17 insertions(+), 10 deletions(-) diff --git a/packages/statemanager/src/accessWitness.ts b/packages/statemanager/src/accessWitness.ts index 87913d9595..5596143851 100644 --- a/packages/statemanager/src/accessWitness.ts +++ b/packages/statemanager/src/accessWitness.ts @@ -16,8 +16,7 @@ import { import debugDefault from 'debug' import type { AccessEventFlags, AccessWitnessInterface } from '@ethereumjs/common' -import type { Address, PrefixedHexString } from '@ethereumjs/util' -import type { VerkleCrypto } from '@ethereumjs/verkle' +import type { Address, PrefixedHexString, VerkleCrypto } from '@ethereumjs/util' const { debug: createDebugLogger } = debugDefault const debug = createDebugLogger('statemanager:verkle:aw') diff --git a/packages/statemanager/src/statelessVerkleStateManager.ts b/packages/statemanager/src/statelessVerkleStateManager.ts index 2b8d88b12f..7eb11c249c 100644 --- a/packages/statemanager/src/statelessVerkleStateManager.ts +++ b/packages/statemanager/src/statelessVerkleStateManager.ts @@ -40,8 +40,7 @@ import type { StorageDump, StorageRange, } from '@ethereumjs/common' -import type { Address, PrefixedHexString } from '@ethereumjs/util' -import type { VerkleCrypto } from '@ethereumjs/verkle' +import type { Address, PrefixedHexString, VerkleCrypto } from '@ethereumjs/util' const { debug: createDebugLogger } = debugDefault diff --git a/packages/util/src/verkle.ts b/packages/util/src/verkle.ts index 75694a4167..de8e55d311 100644 --- a/packages/util/src/verkle.ts +++ b/packages/util/src/verkle.ts @@ -15,6 +15,19 @@ import { concatBytes, intToBytes } from './bytes.js' // // Holger Drewes, 2024-06-18 +export interface VerkleCrypto { + getTreeKey: (address: Uint8Array, treeIndex: Uint8Array, subIndex: number) => Uint8Array + getTreeKeyHash: (address: Uint8Array, treeIndexLE: Uint8Array) => Uint8Array + updateCommitment: ( + commitment: Uint8Array, + commitmentIndex: number, + oldScalarValue: Uint8Array, + newScalarValue: Uint8Array + ) => Uint8Array // Commitment + zeroCommitment: Uint8Array + verifyExecutionWitnessPreState: (prestateRoot: string, execution_witness_json: string) => boolean +} + export enum LeafType { Version = 0, Balance = 1, diff --git a/packages/verkle/src/types.ts b/packages/verkle/src/types.ts index 81614ae5a0..1019532db5 100644 --- a/packages/verkle/src/types.ts +++ b/packages/verkle/src/types.ts @@ -3,7 +3,6 @@ import { intToBytes, utf8ToBytes } from '@ethereumjs/util' import type { VerkleNode } from './node/index.js' import type { WalkController } from './util/walkController.js' import type { DB } from '@ethereumjs/util' -import type { VerkleCrypto as VerkleFFI } from 'verkle-cryptography-wasm' // Field representation of a commitment export interface Fr {} @@ -122,8 +121,6 @@ export type FoundNodeFunction = ( export const ROOT_DB_KEY = utf8ToBytes('__root__') -export type VerkleCrypto = VerkleFFI - export enum LeafType { Version = 0, Balance = 1, diff --git a/packages/verkle/src/util/crypto.ts b/packages/verkle/src/util/crypto.ts index 5ba3310159..04cb0041e9 100644 --- a/packages/verkle/src/util/crypto.ts +++ b/packages/verkle/src/util/crypto.ts @@ -8,7 +8,7 @@ import { } from '@ethereumjs/util' import type { VerkleExecutionWitness } from '@ethereumjs/block' -import type { VerkleCrypto } from 'verkle-cryptography-wasm' +import type { VerkleCrypto } from '@ethereumjs/util' /** * @dev Returns the 31-bytes verkle tree stem for a given address and tree index. diff --git a/packages/verkle/src/util/keys.ts b/packages/verkle/src/util/keys.ts index 5f2a3adb7f..da3d81e3a5 100644 --- a/packages/verkle/src/util/keys.ts +++ b/packages/verkle/src/util/keys.ts @@ -15,8 +15,7 @@ import { import { getStem } from './crypto.js' -import type { VerkleCrypto } from '../types.js' -import type { Address } from '@ethereumjs/util' +import type { Address, VerkleCrypto } from '@ethereumjs/util' /** * @dev Returns the tree key for a given verkle tree stem, and sub index. From e9adc6afbfa100aabd4057cabe63607ad94983bb Mon Sep 17 00:00:00 2001 From: Holger Drewes Date: Wed, 19 Jun 2024 10:45:46 +0200 Subject: [PATCH 07/15] Make verkleCrypto passing in mandatory in StatelessVerkleStateManager, remove async create constructor, move verkle-cryptography-wasm to dev dependenciew --- packages/statemanager/package.json | 6 +++--- .../src/statelessVerkleStateManager.ts | 16 ++-------------- .../test/statelessVerkleStateManager.spec.ts | 13 ++++++------- 3 files changed, 11 insertions(+), 24 deletions(-) diff --git a/packages/statemanager/package.json b/packages/statemanager/package.json index 9849f958e6..8d0bf94ce8 100644 --- a/packages/statemanager/package.json +++ b/packages/statemanager/package.json @@ -57,13 +57,13 @@ "debug": "^4.3.3", "ethereum-cryptography": "^2.1.3", "js-sdsl": "^4.1.4", - "lru-cache": "10.1.0", - "verkle-cryptography-wasm": "^0.4.2" + "lru-cache": "10.1.0" }, "devDependencies": { "@ethereumjs/block": "^5.2.0", "@ethereumjs/genesis": "^0.2.2", "@types/debug": "^4.1.9", - "rustbn-wasm": "^0.4.0" + "rustbn-wasm": "^0.4.0", + "verkle-cryptography-wasm": "^0.4.2" } } diff --git a/packages/statemanager/src/statelessVerkleStateManager.ts b/packages/statemanager/src/statelessVerkleStateManager.ts index 7eb11c249c..2ea75fab4c 100644 --- a/packages/statemanager/src/statelessVerkleStateManager.ts +++ b/packages/statemanager/src/statelessVerkleStateManager.ts @@ -23,7 +23,6 @@ import { } from '@ethereumjs/verkle' import debugDefault from 'debug' import { keccak256 } from 'ethereum-cryptography/keccak.js' -import { loadVerkleCrypto } from 'verkle-cryptography-wasm' import { AccessWitness, AccessedStateType, decodeValue } from './accessWitness.js' import { AccountCache, CacheType, CodeCache, StorageCache } from './cache/index.js' @@ -109,7 +108,7 @@ export interface StatelessVerkleStateManagerOpts { storageCacheOpts?: CacheOptions codeCacheOpts?: CacheOptions accesses?: AccessWitness - verkleCrypto?: VerkleCrypto + verkleCrypto: VerkleCrypto initialStateRoot?: Uint8Array } @@ -174,21 +173,10 @@ export class StatelessVerkleStateManager implements EVMStateManagerInterface { private keccakFunction: Function - /** - * Async static constructor for StatelessVerkleStateManager - * @param opts `StatelessVerkleStateManagerOpts` - * @returns a StatelessVerkleStateManager with initialized Verkle Crypto - */ - static create = async (opts: StatelessVerkleStateManagerOpts = {}) => { - if (opts.verkleCrypto === undefined) { - opts.verkleCrypto = await loadVerkleCrypto() - } - return new StatelessVerkleStateManager(opts) - } /** * Instantiate the StateManager interface. */ - constructor(opts: StatelessVerkleStateManagerOpts = {}) { + constructor(opts: StatelessVerkleStateManagerOpts) { this.originalStorageCache = new OriginalStorageCache(this.getContractStorage.bind(this)) this._accountCacheSettings = { diff --git a/packages/statemanager/test/statelessVerkleStateManager.spec.ts b/packages/statemanager/test/statelessVerkleStateManager.spec.ts index 9642d15a7f..54eb341147 100644 --- a/packages/statemanager/test/statelessVerkleStateManager.spec.ts +++ b/packages/statemanager/test/statelessVerkleStateManager.spec.ts @@ -19,8 +19,7 @@ import * as testnetVerkleKaustinen from './testdata/testnetVerkleKaustinen.json' import * as verkleBlockJSON from './testdata/verkleKaustinen6Block72.json' import type { BlockData } from '@ethereumjs/block' -import type { PrefixedHexString } from '@ethereumjs/util' -import type { VerkleCrypto } from '@ethereumjs/verkle' +import type { PrefixedHexString, VerkleCrypto } from '@ethereumjs/util' describe('StatelessVerkleStateManager: Kaustinen Verkle Block', () => { let verkleCrypto: VerkleCrypto @@ -39,14 +38,14 @@ describe('StatelessVerkleStateManager: Kaustinen Verkle Block', () => { }) it('initPreState()', async () => { - const stateManager = await StatelessVerkleStateManager.create({ verkleCrypto }) + const stateManager = new StatelessVerkleStateManager({ verkleCrypto }) stateManager.initVerkleExecutionWitness(block.header.number, block.executionWitness) assert.ok(Object.keys(stateManager['_state']).length !== 0, 'should initialize with state') }) it('getAccount()', async () => { - const stateManager = await StatelessVerkleStateManager.create({ common, verkleCrypto }) + const stateManager = new StatelessVerkleStateManager({ common, verkleCrypto }) stateManager.initVerkleExecutionWitness(block.header.number, block.executionWitness) const account = await stateManager.getAccount( @@ -64,7 +63,7 @@ describe('StatelessVerkleStateManager: Kaustinen Verkle Block', () => { }) it('put/delete/modify account', async () => { - const stateManager = await StatelessVerkleStateManager.create({ common, verkleCrypto }) + const stateManager = new StatelessVerkleStateManager({ common, verkleCrypto }) stateManager.initVerkleExecutionWitness(block.header.number, block.executionWitness) const address = new Address(randomBytes(20)) @@ -110,7 +109,7 @@ describe('StatelessVerkleStateManager: Kaustinen Verkle Block', () => { }) it('getKey function', async () => { - const stateManager = await StatelessVerkleStateManager.create({ common, verkleCrypto }) + const stateManager = new StatelessVerkleStateManager({ common, verkleCrypto }) stateManager.initVerkleExecutionWitness(block.header.number, block.executionWitness) const address = Address.fromString('0x6177843db3138ae69679a54b95cf345ed759450d') @@ -168,7 +167,7 @@ describe('StatelessVerkleStateManager: Kaustinen Verkle Block', () => { // TODO contract storage functions not yet completely implemented test.skip('get/put/clear contract storage', async () => { - const stateManager = await StatelessVerkleStateManager.create({ common, verkleCrypto }) + const stateManager = new StatelessVerkleStateManager({ common, verkleCrypto }) stateManager.initVerkleExecutionWitness(block.header.number, block.executionWitness) const contractAddress = Address.fromString('0x4242424242424242424242424242424242424242') From fc774efdcc37a18c858089ef4b678a9bb952661b Mon Sep 17 00:00:00 2001 From: Holger Drewes Date: Wed, 19 Jun 2024 10:57:14 +0200 Subject: [PATCH 08/15] Replace additional StatelessVerkleStateManager create() constructor instantiations, add verkle-cryptography-wasm to Client package.json --- packages/client/package.json | 1 + packages/client/src/execution/vmexecution.ts | 5 ++++- packages/vm/test/api/EIPs/eip-6800-verkle.spec.ts | 4 +++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/client/package.json b/packages/client/package.json index ae413f3dee..ff3c86ec9c 100644 --- a/packages/client/package.json +++ b/packages/client/package.json @@ -87,6 +87,7 @@ "level": "^8.0.0", "memory-level": "^1.0.0", "prom-client": "^15.1.0", + "verkle-cryptography-wasm": "^0.4.2", "winston": "^3.3.3", "winston-daily-rotate-file": "^4.5.5", "yargs": "^17.7.1" diff --git a/packages/client/src/execution/vmexecution.ts b/packages/client/src/execution/vmexecution.ts index 2aad9d5ebf..83ee15bab7 100644 --- a/packages/client/src/execution/vmexecution.ts +++ b/packages/client/src/execution/vmexecution.ts @@ -23,6 +23,7 @@ import { } from '@ethereumjs/util' import { VM } from '@ethereumjs/vm' import { writeFileSync } from 'fs' +import { loadVerkleCrypto } from 'verkle-cryptography-wasm' import { Event } from '../types.js' import { debugCodeReplayBlock } from '../util/debug.js' @@ -190,8 +191,10 @@ export class VMExecution extends Execution { return } this.config.logger.info(`Setting up verkleVM`) - const stateManager = await StatelessVerkleStateManager.create({ + const verkleCrypto = await loadVerkleCrypto() + const stateManager = new StatelessVerkleStateManager({ initialStateRoot: this.config.initialVerkleStateRoot, + verkleCrypto, }) this.verkleVM = await VM.create({ common: this.config.execCommon, diff --git a/packages/vm/test/api/EIPs/eip-6800-verkle.spec.ts b/packages/vm/test/api/EIPs/eip-6800-verkle.spec.ts index d416392d3d..1f7d5657cc 100644 --- a/packages/vm/test/api/EIPs/eip-6800-verkle.spec.ts +++ b/packages/vm/test/api/EIPs/eip-6800-verkle.spec.ts @@ -4,6 +4,7 @@ import { EVM } from '@ethereumjs/evm' import { StatelessVerkleStateManager } from '@ethereumjs/statemanager' import { TransactionFactory } from '@ethereumjs/tx' import { hexToBytes } from '@ethereumjs/util' +import { loadVerkleCrypto } from 'verkle-cryptography-wasm' import { describe, it } from 'vitest' import * as verkleBlockJSON from '../../../../statemanager/test/testdata/verkleKaustinen6Block72.json' @@ -31,7 +32,8 @@ const block = Block.fromBlockData({ ...verkleBlockJSON, transactions: decodedTxs describe('EIP 6800 tests', () => { it('successfully run transactions statelessly using the block witness', async () => { - const verkleStateManager = await StatelessVerkleStateManager.create({ common }) + const verkleCrypto = await loadVerkleCrypto() + const verkleStateManager = new StatelessVerkleStateManager({ common, verkleCrypto }) const evm = await EVM.create({ common, stateManager: verkleStateManager }) const vm = await VM.create({ common, From 27a810dbddadf11823e9e382b363aadb0c1a1243 Mon Sep 17 00:00:00 2001 From: Holger Drewes Date: Wed, 19 Jun 2024 10:57:25 +0200 Subject: [PATCH 09/15] Rebuild package-lock.json --- package-lock.json | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index b1e26a5021..e1a7bc0404 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13473,6 +13473,7 @@ "level": "^8.0.0", "memory-level": "^1.0.0", "prom-client": "^15.1.0", + "verkle-cryptography-wasm": "^0.4.2", "winston": "^3.3.3", "winston-daily-rotate-file": "^4.5.5", "yargs": "^17.7.1" @@ -13709,14 +13710,14 @@ "debug": "^4.3.3", "ethereum-cryptography": "^2.1.3", "js-sdsl": "^4.1.4", - "lru-cache": "10.1.0", - "verkle-cryptography-wasm": "^0.4.2" + "lru-cache": "10.1.0" }, "devDependencies": { "@ethereumjs/block": "^5.2.0", "@ethereumjs/genesis": "^0.2.2", "@types/debug": "^4.1.9", - "rustbn-wasm": "^0.4.0" + "rustbn-wasm": "^0.4.0", + "verkle-cryptography-wasm": "^0.4.2" } }, "packages/trie": { From 95e66610f37f06becf9706d40f78c9c72c2ab5be Mon Sep 17 00:00:00 2001 From: Holger Drewes Date: Wed, 19 Jun 2024 11:58:47 +0200 Subject: [PATCH 10/15] Move verkle helper functionality to Util verkle module, fully remove @ethereumjs/verkle usages --- packages/block/src/types.ts | 39 ----- packages/statemanager/src/accessWitness.ts | 8 +- .../src/statelessVerkleStateManager.ts | 14 +- .../test/statelessVerkleStateManager.spec.ts | 4 +- packages/util/src/verkle.ts | 136 +++++++++++++++++- 5 files changed, 149 insertions(+), 52 deletions(-) diff --git a/packages/block/src/types.ts b/packages/block/src/types.ts index 332911d0af..78c8520fa2 100644 --- a/packages/block/src/types.ts +++ b/packages/block/src/types.ts @@ -78,45 +78,6 @@ export interface BlockOptions { executionWitness?: VerkleExecutionWitness } -export interface VerkleProof { - commitmentsByPath: PrefixedHexString[] - d: PrefixedHexString - depthExtensionPresent: PrefixedHexString - ipaProof: { - cl: PrefixedHexString[] - cr: PrefixedHexString[] - finalEvaluation: PrefixedHexString - } - otherStems: PrefixedHexString[] -} - -export interface VerkleStateDiff { - stem: PrefixedHexString - suffixDiffs: { - currentValue: PrefixedHexString | null - newValue: PrefixedHexString | null - suffix: number | string - }[] -} - -/** - * Experimental, object format could eventual change. - * An object that provides the state and proof necessary for verkle stateless execution - * */ -export interface VerkleExecutionWitness { - /** - * An array of state diffs. - * Each item corresponding to state accesses or state modifications of the block. - * In the current design, it also contains the resulting state of the block execution (post-state). - */ - stateDiff: VerkleStateDiff[] - /** - * The verkle proof for the block. - * Proves that the provided stateDiff belongs to the canonical verkle tree. - */ - verkleProof: VerkleProof -} - /** * A block header's data. */ diff --git a/packages/statemanager/src/accessWitness.ts b/packages/statemanager/src/accessWitness.ts index 5596143851..4398b3c61b 100644 --- a/packages/statemanager/src/accessWitness.ts +++ b/packages/statemanager/src/accessWitness.ts @@ -1,6 +1,6 @@ -import { BIGINT_0, bytesToBigInt, bytesToHex, hexToBytes, intToBytes } from '@ethereumjs/util' import { BALANCE_LEAF_KEY, + BIGINT_0, CODE_HASH_LEAF_KEY, CODE_OFFSET, CODE_SIZE_LEAF_KEY, @@ -9,10 +9,14 @@ import { NONCE_LEAF_KEY, VERKLE_NODE_WIDTH, VERSION_LEAF_KEY, + bytesToBigInt, + bytesToHex, getKey, getStem, getTreeIndicesForCodeChunk, -} from '@ethereumjs/verkle' + hexToBytes, + intToBytes, +} from '@ethereumjs/util' import debugDefault from 'debug' import type { AccessEventFlags, AccessWitnessInterface } from '@ethereumjs/common' diff --git a/packages/statemanager/src/statelessVerkleStateManager.ts b/packages/statemanager/src/statelessVerkleStateManager.ts index 2ea75fab4c..a8fb9d5013 100644 --- a/packages/statemanager/src/statelessVerkleStateManager.ts +++ b/packages/statemanager/src/statelessVerkleStateManager.ts @@ -2,25 +2,23 @@ import { Account, KECCAK256_NULL, KECCAK256_NULL_S, + LeafType, bigIntToBytes, bytesToBigInt, bytesToHex, bytesToInt32, + getKey, + getStem, + getTreeKeyForCodeChunk, + getTreeKeyForStorageSlot, hexToBytes, padToEven, setLengthLeft, setLengthRight, short, toBytes, -} from '@ethereumjs/util' -import { - LeafType, - getKey, - getStem, - getTreeKeyForCodeChunk, - getTreeKeyForStorageSlot, verifyProof, -} from '@ethereumjs/verkle' +} from '@ethereumjs/util' import debugDefault from 'debug' import { keccak256 } from 'ethereum-cryptography/keccak.js' diff --git a/packages/statemanager/test/statelessVerkleStateManager.spec.ts b/packages/statemanager/test/statelessVerkleStateManager.spec.ts index 54eb341147..7475e47459 100644 --- a/packages/statemanager/test/statelessVerkleStateManager.spec.ts +++ b/packages/statemanager/test/statelessVerkleStateManager.spec.ts @@ -4,12 +4,14 @@ import { TransactionFactory } from '@ethereumjs/tx' import { Account, Address, + LeafType, bytesToBigInt, bytesToHex, + getKey, + getStem, hexToBytes, randomBytes, } from '@ethereumjs/util' -import { LeafType, getKey, getStem } from '@ethereumjs/verkle' import { loadVerkleCrypto } from 'verkle-cryptography-wasm' import { assert, beforeAll, describe, it, test } from 'vitest' diff --git a/packages/util/src/verkle.ts b/packages/util/src/verkle.ts index de8e55d311..86dc132762 100644 --- a/packages/util/src/verkle.ts +++ b/packages/util/src/verkle.ts @@ -1,4 +1,16 @@ -import { concatBytes, intToBytes } from './bytes.js' +import { + bigIntToBytes, + bytesToHex, + concatBytes, + int32ToBytes, + intToBytes, + setLengthLeft, + setLengthRight, + toBytes, +} from './bytes.js' + +import type { Address } from './address.js' +import type { PrefixedHexString } from './types.js' /** * Verkle related constants and helper functions @@ -6,15 +18,20 @@ import { concatBytes, intToBytes } from './bytes.js' * Experimental (do not use in production!) */ -// TODO: this comes with a deprecation of the respective constants and methods within the +// TODO 1: this comes with a deprecation of the respective constants and methods within the // @ethereumjs/verkle package. Due to ease of parallel work this has not yet been executed upon, // so this still needs a small follow-up clean up PR. // // Along with the PR likely more/additional helper functionality should be moved over // (basically everything generic not depending on Verkle cryptography) // +// TODO 2: Basically all these constants and methods need a Verkle or (VERKLE) prefix since +// atm names are too generic to be grasped in a non-Verkle-limited context (e.g. `getKey()`) +// // Holger Drewes, 2024-06-18 +/* Verkle Crypto */ + export interface VerkleCrypto { getTreeKey: (address: Uint8Array, treeIndex: Uint8Array, subIndex: number) => Uint8Array getTreeKeyHash: (address: Uint8Array, treeIndexLE: Uint8Array) => Uint8Array @@ -28,6 +45,92 @@ export interface VerkleCrypto { verifyExecutionWitnessPreState: (prestateRoot: string, execution_witness_json: string) => boolean } +/** + * @dev Returns the 31-bytes verkle tree stem for a given address and tree index. + * @dev Assumes that the verkle node width = 256 + * @param ffi The verkle ffi object from verkle-crypotography-wasm. + * @param address The address to generate the tree key for. + * @param treeIndex The index of the tree to generate the key for. Defaults to 0. + * @return The 31-bytes verkle tree stem as a Uint8Array. + */ +export function getStem( + ffi: VerkleCrypto, + address: Address, + treeIndex: number | bigint = 0 +): Uint8Array { + const address32 = setLengthLeft(address.toBytes(), 32) + + let treeIndexBytes: Uint8Array + if (typeof treeIndex === 'number') { + treeIndexBytes = setLengthRight(int32ToBytes(Number(treeIndex), true), 32) + } else { + treeIndexBytes = setLengthRight(bigIntToBytes(BigInt(treeIndex), true).slice(0, 32), 32) + } + + const treeStem = ffi.getTreeKey(address32, treeIndexBytes, 0).slice(0, 31) + + return treeStem +} + +/** + * Verifies that the executionWitness is valid for the given prestateRoot. + * @param ffi The verkle ffi object from verkle-crypotography-wasm. + * @param prestateRoot The prestateRoot matching the executionWitness. + * @param executionWitness The verkle execution witness. + * @returns {boolean} Whether or not the executionWitness belongs to the prestateRoot. + */ +export function verifyProof( + ffi: VerkleCrypto, + prestateRoot: Uint8Array, + executionWitness: VerkleExecutionWitness +): boolean { + return ffi.verifyExecutionWitnessPreState( + bytesToHex(prestateRoot), + JSON.stringify(executionWitness) + ) +} + +/* Verkle Structure */ + +export interface VerkleProof { + commitmentsByPath: PrefixedHexString[] + d: PrefixedHexString + depthExtensionPresent: PrefixedHexString + ipaProof: { + cl: PrefixedHexString[] + cr: PrefixedHexString[] + finalEvaluation: PrefixedHexString + } + otherStems: PrefixedHexString[] +} + +export interface VerkleStateDiff { + stem: PrefixedHexString + suffixDiffs: { + currentValue: PrefixedHexString | null + newValue: PrefixedHexString | null + suffix: number | string + }[] +} + +/** + * Experimental, object format could eventual change. + * An object that provides the state and proof necessary for verkle stateless execution + * */ +export interface VerkleExecutionWitness { + /** + * An array of state diffs. + * Each item corresponding to state accesses or state modifications of the block. + * In the current design, it also contains the resulting state of the block execution (post-state). + */ + stateDiff: VerkleStateDiff[] + /** + * The verkle proof for the block. + * Proves that the provided stateDiff belongs to the canonical verkle tree. + */ + verkleProof: VerkleProof +} + export enum LeafType { Version = 0, Balance = 1, @@ -94,3 +197,32 @@ export function getTreeIndicesForCodeChunk(chunkId: number) { const subIndex = (CODE_OFFSET + chunkId) % VERKLE_NODE_WIDTH return { treeIndex, subIndex } } + +export const getTreeKeyForCodeChunk = async ( + address: Address, + chunkId: number, + verkleCrypto: VerkleCrypto +) => { + const { treeIndex, subIndex } = getTreeIndicesForCodeChunk(chunkId) + return concatBytes(getStem(verkleCrypto, address, treeIndex), toBytes(subIndex)) +} + +export const chunkifyCode = (code: Uint8Array) => { + // Pad code to multiple of 31 bytes + if (code.length % 31 !== 0) { + const paddingLength = 31 - (code.length % 31) + code = setLengthRight(code, code.length + paddingLength) + } + + throw new Error('Not implemented') +} + +export const getTreeKeyForStorageSlot = async ( + address: Address, + storageKey: bigint, + verkleCrypto: VerkleCrypto +) => { + const { treeIndex, subIndex } = getTreeIndexesForStorageSlot(storageKey) + + return concatBytes(getStem(verkleCrypto, address, treeIndex), toBytes(subIndex)) +} From d3a749e7462e3d2c94967393360f570f79518afd Mon Sep 17 00:00:00 2001 From: Holger Drewes Date: Wed, 19 Jun 2024 12:07:57 +0200 Subject: [PATCH 11/15] Update VerkleExecutionWitness, VerkleProof type imports moved to Util --- packages/block/src/block.ts | 2 +- packages/block/src/from-beacon-payload.ts | 4 ++-- packages/block/src/types.ts | 1 + packages/block/test/from-beacon-payload.spec.ts | 3 ++- packages/statemanager/package.json | 1 - packages/statemanager/src/statelessVerkleStateManager.ts | 9 +++++++-- 6 files changed, 13 insertions(+), 7 deletions(-) diff --git a/packages/block/src/block.ts b/packages/block/src/block.ts index 3b914193a3..2670b096cd 100644 --- a/packages/block/src/block.ts +++ b/packages/block/src/block.ts @@ -38,7 +38,6 @@ import type { JsonBlock, JsonRpcBlock, RequestsBytes, - VerkleExecutionWitness, WithdrawalsBytes, } from './types.js' import type { Common } from '@ethereumjs/common' @@ -53,6 +52,7 @@ import type { EthersProvider, PrefixedHexString, RequestBytes, + VerkleExecutionWitness, WithdrawalBytes, } from '@ethereumjs/util' diff --git a/packages/block/src/from-beacon-payload.ts b/packages/block/src/from-beacon-payload.ts index 5de5da9f44..263272cbc5 100644 --- a/packages/block/src/from-beacon-payload.ts +++ b/packages/block/src/from-beacon-payload.ts @@ -1,7 +1,7 @@ import { bigIntToHex } from '@ethereumjs/util' -import type { ExecutionPayload, VerkleExecutionWitness } from './types.js' -import type { PrefixedHexString } from '@ethereumjs/util' +import type { ExecutionPayload } from './types.js' +import type { PrefixedHexString, VerkleExecutionWitness } from '@ethereumjs/util' type BeaconWithdrawal = { index: PrefixedHexString diff --git a/packages/block/src/types.ts b/packages/block/src/types.ts index 78c8520fa2..8c08048dc4 100644 --- a/packages/block/src/types.ts +++ b/packages/block/src/types.ts @@ -11,6 +11,7 @@ import type { JsonRpcWithdrawal, PrefixedHexString, RequestBytes, + VerkleExecutionWitness, WithdrawalBytes, WithdrawalData, WithdrawalRequestV1, diff --git a/packages/block/test/from-beacon-payload.spec.ts b/packages/block/test/from-beacon-payload.spec.ts index d8e0a5fc05..0faf8f31d0 100644 --- a/packages/block/test/from-beacon-payload.spec.ts +++ b/packages/block/test/from-beacon-payload.spec.ts @@ -10,7 +10,8 @@ import * as payload87335 from './testdata/payload-slot-87335.json' import * as payload87475 from './testdata/payload-slot-87475.json' import * as testnetVerkleKaustinen from './testdata/testnetVerkleKaustinen.json' -import type { BeaconPayloadJson, VerkleExecutionWitness } from '../src/index.js' +import type { BeaconPayloadJson } from '../src/index.js' +import type { VerkleExecutionWitness } from '@ethereumjs/util' describe('[fromExecutionPayloadJson]: 4844 devnet 5', () => { let common: Common diff --git a/packages/statemanager/package.json b/packages/statemanager/package.json index 8d0bf94ce8..ae5fb4dc74 100644 --- a/packages/statemanager/package.json +++ b/packages/statemanager/package.json @@ -53,7 +53,6 @@ "@ethereumjs/rlp": "^5.0.2", "@ethereumjs/trie": "^6.2.0", "@ethereumjs/util": "^9.0.3", - "@ethereumjs/verkle": "^0.0.2", "debug": "^4.3.3", "ethereum-cryptography": "^2.1.3", "js-sdsl": "^4.1.4", diff --git a/packages/statemanager/src/statelessVerkleStateManager.ts b/packages/statemanager/src/statelessVerkleStateManager.ts index a8fb9d5013..10e534156d 100644 --- a/packages/statemanager/src/statelessVerkleStateManager.ts +++ b/packages/statemanager/src/statelessVerkleStateManager.ts @@ -28,7 +28,6 @@ import { OriginalStorageCache } from './cache/originalStorageCache.js' import type { AccessedStateWithAddress } from './accessWitness.js' import type { DefaultStateManager } from './stateManager.js' -import type { VerkleExecutionWitness, VerkleProof } from '@ethereumjs/block' import type { AccountFields, Common, @@ -37,7 +36,13 @@ import type { StorageDump, StorageRange, } from '@ethereumjs/common' -import type { Address, PrefixedHexString, VerkleCrypto } from '@ethereumjs/util' +import type { + Address, + PrefixedHexString, + VerkleCrypto, + VerkleExecutionWitness, + VerkleProof, +} from '@ethereumjs/util' const { debug: createDebugLogger } = debugDefault From 1583f1f310efe44e69d1e6ab12a62e3782829f23 Mon Sep 17 00:00:00 2001 From: Holger Drewes Date: Wed, 19 Jun 2024 12:09:48 +0200 Subject: [PATCH 12/15] Remove @ethereumjs/verkle dependency from VM --- packages/vm/package.json | 1 - packages/vm/src/runBlock.ts | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/vm/package.json b/packages/vm/package.json index e39e57389f..0caeb614af 100644 --- a/packages/vm/package.json +++ b/packages/vm/package.json @@ -72,7 +72,6 @@ "@ethereumjs/trie": "^6.2.0", "@ethereumjs/tx": "^5.3.0", "@ethereumjs/util": "^9.0.3", - "@ethereumjs/verkle": "^0.0.2", "debug": "^4.3.3", "ethereum-cryptography": "^2.1.3", "mcl-wasm": "^1.5.0" diff --git a/packages/vm/src/runBlock.ts b/packages/vm/src/runBlock.ts index 2a9f190d2d..b7873603e9 100644 --- a/packages/vm/src/runBlock.ts +++ b/packages/vm/src/runBlock.ts @@ -17,13 +17,13 @@ import { bytesToHex, concatBytes, equalsBytes, + getTreeIndexesForStorageSlot, hexToBytes, intToBytes, setLengthLeft, short, unprefixedHexToBytes, } from '@ethereumjs/util' -import { getTreeIndexesForStorageSlot } from '@ethereumjs/verkle' import debugDefault from 'debug' import { Bloom } from './bloom/index.js' From 9b9f6185e849cedeb5afe3237a9a2108939460a2 Mon Sep 17 00:00:00 2001 From: Holger Drewes Date: Wed, 19 Jun 2024 12:11:40 +0200 Subject: [PATCH 13/15] Rebuild package-lock.json --- package-lock.json | 2 -- 1 file changed, 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index e1a7bc0404..51705c8e98 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13706,7 +13706,6 @@ "@ethereumjs/rlp": "^5.0.2", "@ethereumjs/trie": "^6.2.0", "@ethereumjs/util": "^9.0.3", - "@ethereumjs/verkle": "^0.0.2", "debug": "^4.3.3", "ethereum-cryptography": "^2.1.3", "js-sdsl": "^4.1.4", @@ -13814,7 +13813,6 @@ "@ethereumjs/trie": "^6.2.0", "@ethereumjs/tx": "^5.3.0", "@ethereumjs/util": "^9.0.3", - "@ethereumjs/verkle": "^0.0.2", "debug": "^4.3.3", "ethereum-cryptography": "^2.1.3", "mcl-wasm": "^1.5.0" From 69754699afb356b977bd697896c4688d0fb0d17a Mon Sep 17 00:00:00 2001 From: Holger Drewes Date: Wed, 19 Jun 2024 12:20:34 +0200 Subject: [PATCH 14/15] Additional import fix --- packages/client/test/rpc/engine/kaustinen6.spec.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/client/test/rpc/engine/kaustinen6.spec.ts b/packages/client/test/rpc/engine/kaustinen6.spec.ts index ce9041dc9b..99f58a5380 100644 --- a/packages/client/test/rpc/engine/kaustinen6.spec.ts +++ b/packages/client/test/rpc/engine/kaustinen6.spec.ts @@ -9,8 +9,9 @@ import genesisJSON from '../../testdata/geth-genesis/kaustinen6.json' import { getRpcClient, setupChain } from '../helpers.js' import type { Chain } from '../../../src/blockchain/index.js' -import type { BeaconPayloadJson, VerkleExecutionWitness } from '@ethereumjs/block' +import type { BeaconPayloadJson } from '@ethereumjs/block' import type { Common } from '@ethereumjs/common' +import type { VerkleExecutionWitness } from '@ethereumjs/util' import type { HttpClient } from 'jayson/promise' const genesisVerkleStateRoot = '0x1fbf85345a3cbba9a6d44f991b721e55620a22397c2a93ee8d5011136ac300ee' const genesisVerkleBlockHash = '0x3fe165c03e7a77d1e3759362ebeeb16fd964cb411ce11fbe35c7032fab5b9a8a' From e63ecf0eafc48624dcaa1145a27886b39d53243b Mon Sep 17 00:00:00 2001 From: Holger Drewes Date: Wed, 19 Jun 2024 12:28:50 +0200 Subject: [PATCH 15/15] Yet another fix --- packages/verkle/src/util/crypto.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/verkle/src/util/crypto.ts b/packages/verkle/src/util/crypto.ts index 04cb0041e9..c4d93d2780 100644 --- a/packages/verkle/src/util/crypto.ts +++ b/packages/verkle/src/util/crypto.ts @@ -7,8 +7,7 @@ import { setLengthRight, } from '@ethereumjs/util' -import type { VerkleExecutionWitness } from '@ethereumjs/block' -import type { VerkleCrypto } from '@ethereumjs/util' +import type { VerkleCrypto, VerkleExecutionWitness } from '@ethereumjs/util' /** * @dev Returns the 31-bytes verkle tree stem for a given address and tree index.