@ethereumjs/verkle

中文文档
10.0.0发布于 2025/04/29MITTypeScriptESM + CJS近 30 天下载 1.5万

Implementation of verkle trees as used in Ethereum.

原始使用文档
文档目录15 节
  1. Table of Contents
  2. Installation
  3. Getting Started
  4. Initialization
  5. Getting and Putting Values
  6. Proofs
  7. Verkle Proofs
  8. Browser
  9. API
  10. Docs
  11. Hybrid CJS/ESM Builds
  12. Debugging
  13. References
  14. EthereumJS
  15. License

@ethereumjs/verkle v10 (EXPERIMENTAL)

NPM Package GitHub Issues Actions Status Code Coverage Discord

Implementation of Verkle Trees as specified in EIP-6800

Verkle trees are a cryptographic data structure proposed for use in Ethereum to optimize storage and transaction verification. They combine features of Merkle Patricia Tries and Vector Commitment Trees to offer efficient data verification with smaller proof sizes. The goal is to improve scalability and efficiency in Ethereum's network operations.

Note: This library is in an experimental stage and should not be used in production!

Table of Contents

Installation

To obtain the latest version, simply require the project using npm:

npm install @ethereumjs/verkle

Getting Started

Initialization

To initialize a verkle tree, we provide an async constructor createVerkleTree which returns a VerkleTree instance that is properly initialized with the required VerkleCrypto package that implements the necessary cryptographic primitives used by Verkle trees.

// ./examples/simple.ts#L7-L7

const tree = await createVerkleTree()

Note, the current VerkleCrypto library we use internally is verkle-cryptography-wasm which is a WASM compilation of the rust-verkle library with some Javascript specific wrappers and helper methods.

If you prefer to instantiate the verkle tree class directly, you can do so by passing in an already instantiated VerkleCrypto object and then initializing the root node manually.

// ./examples/diyVerkle.ts

import { MapDB, bytesToHex } from '@ethereumjs/util'
import { VerkleTree } from '@ethereumjs/verkle'
import * as verkle from 'micro-eth-signer/verkle'

const main = async () => {
  const tree = new VerkleTree({
    cacheSize: 0,
    db: new MapDB<Uint8Array, Uint8Array>(),
    useRootPersistence: false,
    verkleCrypto: verkle,
  })
  await tree.createRootNode()
  console.log(bytesToHex(tree.root())) // 0x0000000000000000000000000000000000000000000000000000000000000000
}

void main()

Getting and Putting Values

Values are stored using a combination of a stem obtained through the getVerkleStem function exposed by @ethereumjs/util. In the context of Ethereum, to retrieve the data associated with an account at a particular address, we would first compute the verkle stem of that address (getVerkleStem(verkleCrypto, address)), and then get the particular pieces of data we're interested in by suffixing the stem with the suffixes corresponding to that data.

Following the design goal of verkle trees of allowing efficient reads and writes of multiple values that are "close" to each other, the get and put methods take a stem as a first argument and then an array of "suffixes" (the 32nd byte) of the key used to access a value.

Getting values

When retrieving values given a stem 0xc5e561a64a0f52c2d038d827293b3deab99a886d41cc0667c938946dcad853 and suffixes [0, 1], the get method would access the values stored at 0x781f1e4238f9de8b4d0ede9932f5a4d08f15dae70000 and 0x781f1e4238f9de8b4d0ede9932f5a4d08f15dae70001.

Putting values

When storing values given a stem 0xc5e561a64a0f52c2d038d827293b3deab99a886d41cc0667c938946dcad853, suffixes [0, 1], and values ['test', 'test2'], the put method would store the values at 0xc5e561a64a0f52c2d038d827293b3deab99a886d41cc0667c938946dcad85300 and 0xc5e561a64a0f52c2d038d827293b3deab99a886d41cc0667c938946dcad85301.

See below for a complete example.

// ./examples/simple.ts

import { bytesToUtf8, createAddressFromString, getVerkleStem, utf8ToBytes } from '@ethereumjs/util'
import { createVerkleTree } from '@ethereumjs/verkle'

async function test() {
  const addrHex = '0x781f1e4238f9de8b4d0ede9932f5a4d08f15dae7'
  const address = createAddressFromString(addrHex)
  const tree = await createVerkleTree()
  const stem = getVerkleStem(tree['verkleCrypto'], address)
  await tree.put(stem, [0], [utf8ToBytes('test')])
  const value = await tree.get(stem, [0, 1])
  console.log(value[0] ? bytesToUtf8(value[0]) : 'not found') // 'test'
  console.log(value[1] ? bytesToUtf8(value[1]) : 'not found') // 'not found'
}

void test()

Proofs

Verkle Proofs

The EthereumJS Verkle package is still in development and verkle proof generation is not yet supported.

Browser

We provide hybrid ESM/CJS builds for all our libraries. With the v10 breaking release round from Spring 2025, all libraries are "pure-JS" by default and we have eliminated all hard-wired WASM code. Additionally we have substantially lowered the bundle sizes, reduced the number of dependencies, and cut out all usages of Node.js-specific primitives (like the Node.js event emitter).

It is easily possible to run a browser build of one of the EthereumJS libraries within a modern browser using the provided ESM build. For a setup example see ./examples/browser.html.

API

Docs

Generated TypeDoc API Documentation

Hybrid CJS/ESM Builds

The verkle package is shipped with both CommonJS and ESM builds.

If you use an ESM import in your code, import as below:

import { createVerkleTree } from '@ethereumjs/verkle'

If you use Node.js-specific require, the CJS build will be used:

const { createVerkleTree } = require('@ethereumjs/verkle')

Debugging

This library uses the debug debugging utility package.

The Verkle class features optional debug logging. Individual debug selections can be activated on the CL with DEBUG=ethjs,[Logger Selection].

The following options are available:

LoggerDescription
verkle:#a core verkle operation has occurred
verkle:#:puta verkle put operation has occurred
verkle:#:geta verkle get operation has occurred
verkle:#:dela verkle del operation has occurred
verkle:#:find_patha node is being searched for

To observe the logging in action at different levels:

Run with minimal logging:

DEBUG=ethjs,verkle npx vitest test/verkle.spec.ts

Run with put method logging:

DEBUG=ethjs,verkle:put npx vitest test/verkle.spec.ts

Run with verkle + put/get/del logging:

DEBUG=ethjs,verkle,verkle:put,verkle:get,verkle:del npx vitest test/verkle.spec.ts

Run with max logging:

DEBUG=ethjs,verkle:* npx vitest test/verkle.spec.ts

ethjs must be included in the DEBUG environment variables to enable any logs. Additional log selections can be added with a comma separated list (no spaces). Logs with extensions can be enabled with a colon :, and * can be used to include all extensions.

DEBUG=ethjs,verkle:#:put,verkle:#:find_path:* npx vitest test/interop.spec.ts

References

EthereumJS

See our organizational documentation for an introduction to EthereumJS as well as information on current standards and best practices. If you want to join for work or carry out improvements on the libraries, please review our contribution guidelines first.

License

MIT

版本与发布记录

@ethereumjs/verkle 共发布 6 个版本,首次发布于 2024/02/09;过去 12 个月发布了 0 个版本。

版本发布日期距今
10.0.0latest2025/04/291.5 年前
10.0.0-dev-rc.1rc2025/03/251.6 年前
0.2.0-alpha.1alpha2024/10/172 年前
0.1.02024/08/152 年前
0.0.22024/03/182 年前
0.0.12024/02/092 年前

关于 @ethereumjs/verkle 的常见问题

@ethereumjs/verkle 是什么?

Implementation of verkle trees as used in Ethereum.

如何安装 @ethereumjs/verkle?

在项目目录运行 npm install @ethereumjs/verkle,或使用 pnpm add / yarn add / bun add。

@ethereumjs/verkle 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@ethereumjs/verkle 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@ethereumjs/verkle 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=18。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@ethereumjs/verkle 可以商用吗?

@ethereumjs/verkle 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@ethereumjs/verkle 的下载量有多少?

根据 npm 官方下载统计,@ethereumjs/verkle 在 2026/10/14 – 2026/11/12 这 30 天内被下载 14,994 次,日均约 500 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@ethereumjs/verkle 还在维护吗?

最新版本 10.0.0 发布于 2025/04/29(1.5 年前);至今共发布 6 个版本,其中过去 12 个月发布了 0 个;首次发布于 2024/02/09。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。