|
1 | 1 | # KZG-WASM |
2 | 2 |
|
| 3 | +| WASM wrapper library for KZG/EIP-4844/PeerDAS functionality. | |
| 4 | +| ------------------------------------------------------------ | |
| 5 | + |
| 6 | +## Table of Contents |
| 7 | + |
| 8 | +- [Introduction](#introduction) |
| 9 | +- [Usage](#usage) |
| 10 | +- [API Reference](#api-reference) |
| 11 | +- [Performance Comparison](#performance-comparison) |
| 12 | +- [Development](#development) |
| 13 | +- [License](#license) |
| 14 | + |
| 15 | +## Introduction |
| 16 | + |
3 | 17 | This module implements a JS wrapper around a WASM compilation of the [`c-kzg-4844`](https://github.com/ethereum/c-kzg-4844) C library built for use with EIP-4844. Starting with v1.0.0, the library also support cell-based operations in the context of EIP-7594 (PeerDAS). |
4 | 18 |
|
5 | 19 | This library is produced by building the original C code to WASM using the [`empscripten`](https://empscripten.org) toolchain in [this fork](https://github.com/ETHCF/c-kzg-4844) of `c-kzg-4844`. |
6 | 20 |
|
| 21 | +If you are looking for a pure JS implementation of KZG/EIP-4844/PeerDAS functionality, check out the [`micro-eth-signer`](https://github.com/paulmillr/micro-eth-signer) library. For a comparison on how these libraries roughly compare in terms of performance, see the [Performance Comparison](#performance-comparison) section. |
| 22 | + |
7 | 23 | ## Usage |
8 | 24 |
|
9 | 25 | This module exposes a single export, an async function called `loadKZG` which loads and compiles the WASM object, loads a trusted setup (defaults to the official setup from the KZG ceremony) and returns an object that exposes the API defined in the `KZG` type interface in `@ethereumjs/util` |
@@ -127,6 +143,21 @@ type KZGProofWithCells = { |
127 | 143 | } |
128 | 144 | ``` |
129 | 145 |
|
| 146 | +## Performance Comparison |
| 147 | +
|
| 148 | +The following numbers can give you some idea of the performance of the library. Note that these are rather "napkin numbers" and no benchmarks (30 runs each using Chrome), but they should nevertheless give you an idea if this wrapper library is a good fit for your use case. |
| 149 | +
|
| 150 | +```shell |
| 151 | +WASM KZG: 27.866666666666667 ms per commitment |
| 152 | +JS KZG: 4.466666666666667 ms per commitment |
| 153 | +WASM KZG: 276.06666666666666 ms per proof |
| 154 | +JS KZG: 644.7666666666667 ms per proof |
| 155 | +WASM KZG: 12.233333333333333 ms per verify proof |
| 156 | +JS KZG: 28.333333333333332 ms per verify proof |
| 157 | +``` |
| 158 | +
|
| 159 | +Generally note that initialization of this library is pretty slow due to the large KZG setup, so it is likely only worth to use in long-running production contexts. |
| 160 | +
|
130 | 161 | ## Development |
131 | 162 |
|
132 | 163 | ### Build Process |
|
0 commit comments