Skip to content

Commit

Permalink
Fix loadKZG references
Browse files Browse the repository at this point in the history
  • Loading branch information
acolytec3 committed Sep 20, 2024
1 parent 9e6d5b0 commit 4e81a11
Show file tree
Hide file tree
Showing 19 changed files with 71 additions and 81 deletions.
8 changes: 1 addition & 7 deletions package-lock.json

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

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
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
7 changes: 3 additions & 4 deletions packages/client/test/miner/pendingBlock.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import {
randomBytes,
} from '@ethereumjs/util'
import { createVM } from '@ethereumjs/vm'
import { loadKZG } from 'kzg-wasm'
import { trustedSetup as fast } from '@paulmillr/trusted-setups/fast.js'
import { KZG as microEthKZG } from 'micro-eth-signer/kzg'
import { assert, describe, it, vi } from 'vitest'

import { hardfork4844Data } from '../../../block/test/testdata/4844-hardfork.js'
Expand All @@ -28,6 +29,7 @@ import { mockBlockchain } from '../rpc/mockBlockchain.js'
import type { Blockchain } from '@ethereumjs/blockchain'
import type { TypedTransaction } from '@ethereumjs/tx'
import type { VM } from '@ethereumjs/vm'
const kzg = new microEthKZG(fast)

const A = {
address: new Address(hexToBytes('0x0b90087d864e82a284dca15923f3776de6bb016f')),
Expand Down Expand Up @@ -342,7 +344,6 @@ describe('[PendingBlock]', async () => {
})

it('construct blob bundles', async () => {
const kzg = await loadKZG()
const common = createCommonFromGethGenesis(hardfork4844Data, {
chain: 'customChain',
hardfork: Hardfork.Cancun,
Expand Down Expand Up @@ -422,8 +423,6 @@ describe('[PendingBlock]', async () => {
})

it('should exclude missingBlobTx', async () => {
const kzg = await loadKZG()

const common = createCommonFromGethGenesis(hardfork4844Data, {
chain: 'customChain',
hardfork: Hardfork.Cancun,
Expand Down
5 changes: 3 additions & 2 deletions packages/client/test/net/protocol/ethprotocol.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ import {
hexToBytes,
randomBytes,
} from '@ethereumjs/util'
import { loadKZG } from 'kzg-wasm'
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 { Chain } from '../../../src/blockchain/chain.js'
import { Config } from '../../../src/config.js'
import { EthProtocol } from '../../../src/net/protocol/index.js'
const kzg = new microEthKZG(fast)

describe('[EthProtocol]', () => {
it('should get properties', async () => {
Expand Down Expand Up @@ -209,7 +211,6 @@ describe('[EthProtocol]', () => {
})

it('verify that Transactions handler encodes/decodes correctly', async () => {
const kzg = await loadKZG()
const config = new Config({
common: new Common({
chain: Holesky,
Expand Down
6 changes: 3 additions & 3 deletions packages/client/test/rpc/debug/getRawBlock.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import { createBlock, createBlockHeader } from '@ethereumjs/block'
import { Mainnet, createCustomCommon } from '@ethereumjs/common'
import { createBlob4844Tx, createLegacyTx } from '@ethereumjs/tx'
import { bytesToHex, createZeroAddress, hexToBytes } from '@ethereumjs/util'
import { loadKZG } from 'kzg-wasm'
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 { INVALID_PARAMS } from '../../../src/rpc/error-code.js'
import { createClient, createManager, dummy, getRPCClient, startRPC } from '../helpers.js'

const kzg = await loadKZG()
const kzg = new microEthKZG(fast)

const common = createCustomCommon({ chainId: 1 }, Mainnet, { customCrypto: { kzg } })

Expand Down
6 changes: 3 additions & 3 deletions packages/client/test/rpc/debug/getRawHeader.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import { createBlock, createBlockHeader } from '@ethereumjs/block'
import { Mainnet, createCustomCommon } from '@ethereumjs/common'
import { createBlob4844Tx, createLegacyTx } from '@ethereumjs/tx'
import { bytesToHex, createZeroAddress, hexToBytes } from '@ethereumjs/util'
import { loadKZG } from 'kzg-wasm'
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 { INVALID_PARAMS } from '../../../src/rpc/error-code.js'
import { createClient, createManager, dummy, getRPCClient, startRPC } from '../helpers.js'

const kzg = await loadKZG()
const kzg = new microEthKZG(fast)

const common = createCustomCommon({ chainId: 1 }, Mainnet, { customCrypto: { kzg } })

Expand Down
8 changes: 4 additions & 4 deletions packages/client/test/rpc/debug/getRawReceipts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import {
randomBytes,
} from '@ethereumjs/util'
import { encodeReceipt } from '@ethereumjs/vm'
import { loadKZG } from 'kzg-wasm'
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 { powData } from '../../testdata/geth-genesis/pow.js'
Expand All @@ -24,6 +25,7 @@ import {

import type { PrefixedHexString } from '@ethereumjs/util'
import type { TxReceipt } from '@ethereumjs/vm'
const kzg = new microEthKZG(fast)

const method = 'eth_getTransactionReceipt'
const method2 = 'debug_getRawReceipts'
Expand Down Expand Up @@ -103,8 +105,6 @@ describe(method, () => {
} else {
const { hardfork4844Data } = await import('../../../../block/test/testdata/4844-hardfork.js')

const kzg = await loadKZG()

const common = createCommonFromGethGenesis(hardfork4844Data, {
chain: 'customChain',
hardfork: Hardfork.Cancun,
Expand All @@ -122,7 +122,7 @@ describe(method, () => {
const commitments = blobsToCommitments(kzg, blobs)
const blobVersionedHashes = commitmentsToVersionedHashes(commitments)
const proofs = blobs.map((blob, ctx) =>
kzg.computeBlobKZGProof(blob, commitments[ctx]),
kzg.computeBlobProof(blob, commitments[ctx]),
) as PrefixedHexString[]
const tx = createBlob4844Tx(
{
Expand Down
6 changes: 3 additions & 3 deletions packages/client/test/rpc/engine/getPayloadV3.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ import {
getBlobs,
hexToBytes,
} from '@ethereumjs/util'
import { loadKZG } from 'kzg-wasm'
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 { INVALID_PARAMS } from '../../../src/rpc/error-code.js'
import { eip4844Data } from '../../testdata/geth-genesis/eip4844.js'
import { baseSetup, getRPCClient, setupChain } from '../helpers.js'
const kzg = new microEthKZG(fast)

// Since the genesis is copy of withdrawals with just sharding hardfork also started
// at 0, we can re-use the same payload args
Expand Down Expand Up @@ -67,8 +69,6 @@ describe(method, () => {
return this
}

const kzg = await loadKZG()

const { service, server, common } = await setupChain(eip4844Data, 'post-merge', {
engine: true,
hardfork: Hardfork.Cancun,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { loadKZG } from 'kzg-wasm'
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 { INVALID_PARAMS } from '../../../src/rpc/error-code.js'
import { beaconData } from '../../testdata/blocks/beacon.js'
import { eip4844Data } from '../../testdata/geth-genesis/eip4844.js'
import { getRPCClient, setupChain } from '../helpers.js'
const kzg = new microEthKZG(fast)

const method = 'engine_newPayloadV3'

Expand All @@ -14,8 +16,6 @@ const [blockData] = beaconData

describe(`${method}: Cancun validations`, () => {
it('blobVersionedHashes', async () => {
const kzg = await loadKZG()

const { server } = await setupChain(eip4844Data, 'post-merge', {
engine: true,
customCrypto: { kzg },
Expand Down
9 changes: 4 additions & 5 deletions packages/client/test/rpc/eth/blobBaseFee.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import {
hexToBytes,
} from '@ethereumjs/util'
import { buildBlock } from '@ethereumjs/vm'
import { loadKZG } from 'kzg-wasm'
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 { eip4844Data } from '../../testdata/geth-genesis/eip4844.js'
Expand All @@ -20,16 +21,16 @@ import { getRPCClient, setupChain } from '../helpers.js'
import type { Chain } from '../../../src/blockchain/chain.js'
import type { VMExecution } from '../../../src/execution/vmexecution.js'
import type { PrefixedHexString } from '@ethereumjs/util'
const method = 'eth_blobBaseFee'

const method = 'eth_blobBaseFee'
const kzg = new microEthKZG(fast)
const privateKey = hexToBytes('0x45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8')
const accountAddress = createAddressFromPrivateKey(privateKey)
const produceBlockWith4844Tx = async (
execution: VMExecution,
chain: Chain,
blobsCount: number[],
) => {
const kzg = await loadKZG()
// 4844 sample blob
const sampleBlob = getBlobs('hello world')
const commitment = blobsToCommitments(kzg, sampleBlob)
Expand Down Expand Up @@ -90,7 +91,6 @@ const produceBlockWith4844Tx = async (

describe(method, () => {
it('call', async () => {
const kzg = await loadKZG()
const { server } = await setupChain(eip4844Data, 'post-merge', {
engine: true,
hardfork: Hardfork.Cancun,
Expand All @@ -105,7 +105,6 @@ describe(method, () => {
})

it('call with more realistic blockchain', async () => {
const kzg = await loadKZG()
const { server, execution, chain } = await setupChain(eip4844Data, 'post-merge', {
engine: true,
hardfork: Hardfork.Cancun,
Expand Down
6 changes: 3 additions & 3 deletions packages/client/test/rpc/eth/getBlockByNumber.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import { createBlock } from '@ethereumjs/block'
import { Mainnet, createCustomCommon } from '@ethereumjs/common'
import { createBlob4844Tx, createLegacyTx } from '@ethereumjs/tx'
import { createZeroAddress, hexToBytes } from '@ethereumjs/util'
import { loadKZG } from 'kzg-wasm'
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 { INVALID_PARAMS } from '../../../src/rpc/error-code.js'
import { createClient, createManager, dummy, getRPCClient, startRPC } from '../helpers.js'

const kzg = await loadKZG()
const kzg = new microEthKZG(fast)

const common = createCustomCommon({ chainId: 1 }, Mainnet, { customCrypto: { kzg } })

Expand Down
9 changes: 4 additions & 5 deletions packages/client/test/rpc/eth/getBlockReceipts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import {
getBlobs,
randomBytes,
} from '@ethereumjs/util'
import { loadKZG } from 'kzg-wasm'
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 { powData } from '../../testdata/geth-genesis/pow.js'
Expand All @@ -24,7 +25,7 @@ import type { PrefixedHexString } from '@ethereumjs/util'

const method = 'eth_getTransactionReceipt'
const method2 = 'eth_getBlockReceipts'

const kzg = new microEthKZG(fast)
describe(method, () => {
it('call with legacy tx', async () => {
const { chain, common, execution, server } = await setupChain(powData, 'pow')
Expand Down Expand Up @@ -107,8 +108,6 @@ describe(method, () => {
} else {
const { hardfork4844Data } = await import('../../../../block/test/testdata/4844-hardfork.js')

const kzg = await loadKZG()

const common = createCommonFromGethGenesis(hardfork4844Data, {
chain: 'customChain',
hardfork: Hardfork.Cancun,
Expand All @@ -126,7 +125,7 @@ describe(method, () => {
const commitments = blobsToCommitments(kzg, blobs)
const blobVersionedHashes = commitmentsToVersionedHashes(commitments)
const proofs = blobs.map((blob, ctx) =>
kzg.computeBlobKZGProof(blob, commitments[ctx]),
kzg.computeBlobProof(blob, commitments[ctx]),
) as PrefixedHexString[]
const tx = createBlob4844Tx(
{
Expand Down
6 changes: 3 additions & 3 deletions packages/client/test/rpc/eth/getFeeHistory.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ import {
getBlobs,
} from '@ethereumjs/util'
import { buildBlock } from '@ethereumjs/vm'
import { trustedSetup as fast } from '@paulmillr/trusted-setups/fast.js'
import { hexToBytes } from 'ethereum-cryptography/utils'
import { loadKZG } from 'kzg-wasm'
import { KZG as microEthKZG } from 'micro-eth-signer/kzg'
import { assert, describe, it } from 'vitest'

import { eip4844Data } from '../../testdata/geth-genesis/eip4844.js'
Expand All @@ -34,6 +35,7 @@ const privateKey4844 = hexToBytes(
'0x45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8',
)
const p4844Address = createAddressFromPrivateKey(privateKey4844)
const kzg = new microEthKZG(fast)

const produceFakeGasUsedBlock = async (execution: VMExecution, chain: Chain, gasUsed: bigint) => {
const { vm } = execution
Expand Down Expand Up @@ -124,7 +126,6 @@ const produceBlockWith4844Tx = async (
chain: Chain,
blobsCount: number[],
) => {
const kzg = await loadKZG()
// 4844 sample blob
const sampleBlob = getBlobs('hello world')
const commitment = blobsToCommitments(kzg, sampleBlob)
Expand Down Expand Up @@ -428,7 +429,6 @@ describe(method, () => {
it(
`${method} - Should correctly return the right blob base fees and ratios for a chain with 4844 active`,
async () => {
const kzg = await loadKZG()
const { chain, execution, server } = await setupChain(eip4844Data, 'post-merge', {
engine: true,
hardfork: Hardfork.Cancun,
Expand Down
Loading

0 comments on commit 4e81a11

Please sign in to comment.