Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add micro-eth-signer/kzg #3674

Merged
merged 33 commits into from
Sep 21, 2024
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
1667ba9
add jsKZG interface and modify tests
acolytec3 Sep 16, 2024
b4d37f4
export wrapper and add vm tester
acolytec3 Sep 16, 2024
8a2ad27
Add trusdest setup for initial verification
acolytec3 Sep 16, 2024
ffb8c12
move jsKZG to util
acolytec3 Sep 17, 2024
0243ad9
use jsKZG in the tester
acolytec3 Sep 17, 2024
e73564a
move benchmarks to util
acolytec3 Sep 17, 2024
f72b183
switch blobTx example to use jsKZG
acolytec3 Sep 17, 2024
8e2047e
update benchmarks
acolytec3 Sep 17, 2024
d1d68e8
partially migrate bytes to strings for kzg data [no ci]
acolytec3 Sep 17, 2024
3d82857
Adjust tx constructors
acolytec3 Sep 17, 2024
84dcfd7
use trusted-setups package
acolytec3 Sep 18, 2024
dbf3ae9
change kzg capitalization
acolytec3 Sep 18, 2024
7f5d40f
Merge remote-tracking branch 'origin/master' into hot-swappable-kzg
acolytec3 Sep 18, 2024
c120a9a
lots o fixes
acolytec3 Sep 18, 2024
0844315
hack to fix tester
acolytec3 Sep 18, 2024
1311aef
bye bye kzg-wasm
acolytec3 Sep 19, 2024
93eb171
Merge remote-tracking branch 'origin/master' into hot-swappable-kzg
acolytec3 Sep 19, 2024
44ab026
spell check
acolytec3 Sep 19, 2024
303de90
last fixes
acolytec3 Sep 19, 2024
0f1573a
fix vm test
acolytec3 Sep 19, 2024
fa66682
one more fix
acolytec3 Sep 19, 2024
2215eb1
Merge branch 'master' into hot-swappable-kzg
gabrocheleau Sep 19, 2024
eb6a960
Merge branch 'master' into hot-swappable-kzg
holgerd77 Sep 20, 2024
9e6d5b0
Small tx dependency fix
holgerd77 Sep 20, 2024
4e81a11
Fix loadKZG references
acolytec3 Sep 20, 2024
947df8b
Switch trusted setup to default export
acolytec3 Sep 20, 2024
94e84e2
Update trusted-setups version
acolytec3 Sep 20, 2024
3bc8e60
ignore missing types for trusted-setups
acolytec3 Sep 20, 2024
ab1c6ce
use named import
acolytec3 Sep 20, 2024
358a497
Lint fixes
acolytec3 Sep 20, 2024
25e4a40
revert bundler config change
acolytec3 Sep 20, 2024
50df7eb
update trusted-setups again
acolytec3 Sep 21, 2024
8f56221
remove ts-ignore
acolytec3 Sep 21, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/cspell-ts.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
}
],
"words": [
"paulmillr",
"t8ntool",
"!Json",
"!Rpc",
Expand Down
53 changes: 45 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions packages/block/examples/4844.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ import { createBlock } from '@ethereumjs/block'
import { Common, Hardfork, Mainnet } from '@ethereumjs/common'
import { createBlob4844Tx } from '@ethereumjs/tx'
import { createAddressFromPrivateKey } from '@ethereumjs/util'
import { trustedSetup } from '@paulmillr/trusted-setups/fast.js'
import { randomBytes } from 'crypto'
import { loadKZG } from 'kzg-wasm'
import { KZG as microEthKZG } from 'micro-eth-signer/kzg'

const main = async () => {
const kzg = await loadKZG()
const kzg = new microEthKZG(trustedSetup)

const common = new Common({
chain: Mainnet,
Expand Down
3 changes: 2 additions & 1 deletion packages/block/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@
"ethereum-cryptography": "^3.0.0"
},
"devDependencies": {
"kzg-wasm": "^0.4.0"
"@paulmillr/trusted-setups": "^0.1.1",
"micro-eth-signer": "^0.11.0"
},
"engines": {
"node": ">=18"
Expand Down
61 changes: 26 additions & 35 deletions packages/block/test/eip4844block.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import {
getBlobs,
randomBytes,
} from '@ethereumjs/util'
import { loadKZG } from 'kzg-wasm'
import { assert, beforeAll, describe, it } from 'vitest'
import { trustedSetup as fast } from '@paulmillr/trusted-setups/fast.js'
import { KZG as microEthKZG } from 'micro-eth-signer/kzg'
import { assert, describe, it } from 'vitest'

import { fakeExponential, getNumBlobs } from '../src/helpers.js'
import { createBlock, createBlockHeader } from '../src/index.js'
Expand All @@ -16,19 +17,14 @@ import { paramsBlock } from '../src/params.js'
import { hardfork4844Data } from './testdata/4844-hardfork.js'

import type { TypedTransaction } from '@ethereumjs/tx'
import type { Kzg } from '@ethereumjs/util'

describe('EIP4844 header tests', () => {
let common: Common
const kzg = new microEthKZG(fast)

beforeAll(async () => {
const kzg = await loadKZG()

common = createCommonFromGethGenesis(hardfork4844Data, {
chain: 'customChain',
hardfork: Hardfork.Cancun,
customCrypto: { kzg },
})
const common = createCommonFromGethGenesis(hardfork4844Data, {
chain: 'customChain',
hardfork: Hardfork.Cancun,
customCrypto: { kzg },
})

it('should work', () => {
Expand Down Expand Up @@ -98,18 +94,16 @@ describe('EIP4844 header tests', () => {
})

describe('blob gas tests', () => {
let common: Common
let blobGasPerBlob: bigint
beforeAll(async () => {
const kzg = await loadKZG()
common = createCommonFromGethGenesis(hardfork4844Data, {
chain: 'customChain',
hardfork: Hardfork.Cancun,
params: paramsBlock,
customCrypto: { kzg },
})
blobGasPerBlob = common.param('blobGasPerBlob')
const kzg = new microEthKZG(fast)

const common = createCommonFromGethGenesis(hardfork4844Data, {
chain: 'customChain',
hardfork: Hardfork.Cancun,
params: paramsBlock,
customCrypto: { kzg },
})
const blobGasPerBlob = common.param('blobGasPerBlob')

it('should work', () => {
const preShardingHeader = createBlockHeader(
{},
Expand Down Expand Up @@ -158,19 +152,16 @@ describe('blob gas tests', () => {
})

describe('transaction validation tests', () => {
let kzg: Kzg
let common: Common
let blobGasPerBlob: bigint
beforeAll(async () => {
kzg = await loadKZG()
common = createCommonFromGethGenesis(hardfork4844Data, {
chain: 'customChain',
hardfork: Hardfork.Cancun,
params: paramsBlock,
customCrypto: { kzg },
})
blobGasPerBlob = common.param('blobGasPerBlob')
const kzg = new microEthKZG(fast)

const common = createCommonFromGethGenesis(hardfork4844Data, {
chain: 'customChain',
hardfork: Hardfork.Cancun,
params: paramsBlock,
customCrypto: { kzg },
})
const blobGasPerBlob = common.param('blobGasPerBlob')

it('should work', () => {
const blobs = getBlobs('hello world')
const commitments = blobsToCommitments(kzg, blobs)
Expand Down
28 changes: 13 additions & 15 deletions packages/block/test/from-beacon-payload.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Hardfork, createCommonFromGethGenesis } from '@ethereumjs/common'
import { loadKZG } from 'kzg-wasm'
import { assert, beforeAll, describe, it } from 'vitest'
import { trustedSetup as fast } from '@paulmillr/trusted-setups/fast.js'
import { KZG as microEthKZG } from 'micro-eth-signer/kzg'
import { assert, describe, it } from 'vitest'

import { devnet4844Config } from '../../client/test/sim/configs/4844-devnet.js'
import { createBlockFromBeaconPayloadJSON, createBlockHeader } from '../src/index.js'
Expand All @@ -10,21 +11,18 @@ import { payloadSlot87335Data } from './testdata/payload-slot-87335.js'
import { payloadSlot87475Data } from './testdata/payload-slot-87475.js'
import { testnetVerkleKaustinenData } from './testdata/testnetVerkleKaustinen.js'

import type { Common } from '@ethereumjs/common'

const kzg = new microEthKZG(fast)
describe('[fromExecutionPayloadJSON]: 4844 devnet 5', () => {
let common: Common
beforeAll(async () => {
const kzg = await loadKZG()

const commonConfig = { ...devnet4844Config }
commonConfig.config = { ...commonConfig.config, chainId: 4844001005 }
const network = 'sharding'
common = createCommonFromGethGenesis(commonConfig, { chain: network, customCrypto: { kzg } })
// safely change chainId without modifying underlying json

common.setHardfork(Hardfork.Cancun)
const commonConfig = { ...devnet4844Config }
commonConfig.config = { ...commonConfig.config, chainId: 4844001005 }
const network = 'sharding'
const common = createCommonFromGethGenesis(commonConfig, {
chain: network,
customCrypto: { kzg },
})
// safely change chainId without modifying underlying json

common.setHardfork(Hardfork.Cancun)

it('reconstruct cancun block with blob txs', async () => {
for (const payload of [payloadSlot87335Data, payloadSlot87475Data]) {
Expand Down
8 changes: 4 additions & 4 deletions packages/client/bin/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import {
setLengthLeft,
short,
} from '@ethereumjs/util'
//@ts-ignore trusted-setups doesn't include types
import { trustedSetup as fast } from '@paulmillr/trusted-setups/fast.js'
jochem-brouwer marked this conversation as resolved.
Show resolved Hide resolved
import {
keccak256 as keccak256WASM,
secp256k1Expand,
Expand All @@ -41,8 +43,8 @@ import { ecdsaRecover, ecdsaSign } from 'ethereum-cryptography/secp256k1-compat'
import { sha256 } from 'ethereum-cryptography/sha256.js'
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'fs'
import * as http from 'http'
import { loadKZG } from 'kzg-wasm'
import { Level } from 'level'
import { KZG as microEthKZG } from 'micro-eth-signer/kzg'
import { homedir } from 'os'
import * as path from 'path'
import * as promClient from 'prom-client'
Expand Down Expand Up @@ -927,15 +929,13 @@ async function run() {
return helpRPC()
}

// TODO sharding: Just initialize kzg library now, in future it can be optimized to be
// loaded and initialized on the sharding hardfork activation
// Give chainId priority over networkId
// Give networkId precedence over network name
const chainName = args.chainId ?? args.networkId ?? args.network ?? Chain.Mainnet
const chain = getPresetChainConfig(chainName)
const cryptoFunctions: CustomCrypto = {}
const kzg = await loadKZG()

const kzg = new microEthKZG(fast)
// Initialize WASM crypto if JS crypto is not specified
if (args.useJsCrypto === false) {
await waitReadyPolkadotSha256()
Expand Down
6 changes: 3 additions & 3 deletions packages/client/devnets/4844-interop/tools/txGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import {

import { randomBytes } from '@ethereumjs/util'
import { Client } from 'jayson/promise'
import { loadKZG } from 'kzg-wasm'
import { trustedSetup as fast } from '@paulmillr/trusted-setups/fast.js'
import { KZG as microEthKZG } from 'micro-eth-signer/kzg'
const kzg = new microEthKZG(fast)

// CLI Args
const clientPort = parseInt(process.argv[2]) // EL client port number
Expand All @@ -27,8 +29,6 @@ async function getNonce(client: Client, account: string) {
}

async function run(data: any) {
const kzg = await loadKZG()

const common = createCommonFromGethGenesis(genesisJSON, {
chain: genesisJSON.ChainName ?? 'devnet',
hardfork: Hardfork.Cancun,
Expand Down
3 changes: 2 additions & 1 deletion packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@
"ethereum-cryptography": "^3.0.0",
"it-pipe": "^1.1.0",
"jayson": "^4.0.0",
"kzg-wasm": "^0.4.0",
"@paulmillr/trusted-setups": "^0.1.1",
"micro-eth-signer": "^0.11.0",
"level": "^8.0.0",
"mcl-wasm": "^1.5.0",
"memory-level": "^1.0.0",
Expand Down
Loading
Loading