Skip to content

Commit

Permalink
tx: Update the kzg valiation and replace trusted setup with latest
Browse files Browse the repository at this point in the history
  • Loading branch information
g11tech committed Jun 6, 2023
1 parent 752b270 commit 32aaac3
Show file tree
Hide file tree
Showing 17 changed files with 4,187 additions and 8,208 deletions.
2 changes: 1 addition & 1 deletion packages/block/test/eip4844block.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const isBrowser = new Function('try {return this===window;}catch(e){ return fals

if (isBrowser() === false) {
try {
initKZG(kzg, __dirname + '/../../client/src/trustedSetups/devnet4.txt')
initKZG(kzg, __dirname + '/../../client/src/trustedSetups/devnet6.txt')
// eslint-disable-next-line
} catch {}
}
Expand Down
6 changes: 5 additions & 1 deletion packages/client/bin/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ const args: ClientOpts = yargs(hideBin(process.argv))
describe: 'Import a geth genesis file for running a custom network',
coerce: (arg: string) => (arg ? path.resolve(arg) : undefined),
})
.option('trustedSetup', {
describe: 'A custom trusted setup txt file for initializing the kzg library',
coerce: (arg: string) => (arg ? path.resolve(arg) : undefined),
})
.option('mergeForkIdPostMerge', {
describe:
'Place mergeForkIdTransition hardfork before (false) or after (true) Merge hardfork in the custom gethGenesis',
Expand Down Expand Up @@ -658,7 +662,7 @@ async function run() {

// TODO sharding: Just initialize kzg library now, in future it can be optimized to be
// loaded and initialized on the sharding hardfork activation
initKZG(kzg, __dirname + '/../src/trustedSetups/devnet4.txt')
initKZG(kzg, args.trustedSetup ?? __dirname + '/../src/trustedSetups/devnet6.txt')
// Give network id precedence over network name
const chain = args.networkId ?? args.network ?? Chain.Mainnet

Expand Down
2 changes: 1 addition & 1 deletion packages/client/devnets/4844-interop/tools/txGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const input = process.argv[3] // text to generate blob from
const genesisJson = require(process.argv[4]) // Genesis parameters
const pkey = hexStringToBytes(process.argv[5]) // private key of tx sender as unprefixed hex string

initKZG(kzg, __dirname + '/../../../src/trustedSetups/devnet4.txt')
initKZG(kzg, __dirname + '/../../../src/trustedSetups/devnet6.txt')

const sender = Address.fromPrivateKey(pkey)
const common = Common.fromGethGenesis(genesisJson, {
Expand Down
8,193 changes: 0 additions & 8,193 deletions packages/client/src/trustedSetups/devnet4.txt

This file was deleted.

4,163 changes: 4,163 additions & 0 deletions packages/client/src/trustedSetups/devnet6.txt

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions packages/client/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export interface ClientOpts {
customChain?: string
customGenesisState?: string
gethGenesis?: string
trustedSetup?: string
mergeForkIdPostMerge?: boolean
transports?: string[]
bootnodes?: string | string[]
Expand Down
2 changes: 1 addition & 1 deletion packages/client/test/miner/pendingBlock.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ tape('[PendingBlock]', async (t) => {

t.test('construct blob bundles', async (st) => {
try {
initKZG(kzg, __dirname + '/../../src/trustedSetups/devnet4.txt')
initKZG(kzg, __dirname + '/../../src/trustedSetups/devnet6.txt')
// eslint-disable-next-line
} catch {}
const gethGenesis = require('../../../block/test/testdata/4844-hardfork.json')
Expand Down
2 changes: 1 addition & 1 deletion packages/client/test/rpc/engine/getPayloadV3.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const validPayloadAttributes = {
const validPayload = [validForkChoiceState, { ...validPayloadAttributes, withdrawals: [] }]

try {
initKZG(kzg, __dirname + '/../../../src/trustedSetups/devnet4.txt')
initKZG(kzg, __dirname + '/../../../src/trustedSetups/devnet6.txt')
// eslint-disable-next-line
} catch {}
const method = 'engine_getPayloadV3'
Expand Down
2 changes: 1 addition & 1 deletion packages/client/test/rpc/eth/getTransactionReceipt.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ tape(`${method}: get dataGasUsed/dataGasPrice in blob tx receipt`, async (t) =>
} else {
try {
// Verified KZG is loaded correctly -- NOOP if throws
initKZG(kzg, __dirname + '/../../../src/trustedSetups/devnet4.txt')
initKZG(kzg, __dirname + '/../../../src/trustedSetups/devnet6.txt')
//eslint-disable-next-line
} catch {}
const gethGenesis = require('../../../../block/test/testdata/4844-hardfork.json')
Expand Down
2 changes: 1 addition & 1 deletion packages/client/test/rpc/eth/sendRawTransaction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ tape('blob EIP 4844 transaction', async (t) => {
const consensusFormatValidation = BlockHeader.prototype._consensusFormatValidation
BlockHeader.prototype._consensusFormatValidation = (): any => {}
try {
initKZG(kzg, __dirname + '/../../../src/trustedSetups/devnet4.txt')
initKZG(kzg, __dirname + '/../../../src/trustedSetups/devnet6.txt')
// eslint-disable-next-line
} catch {}
const gethGenesis = require('../../../../block/test/testdata/4844-hardfork.json')
Expand Down
2 changes: 1 addition & 1 deletion packages/client/test/sim/simutils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import type { Client } from 'jayson/promise'

export const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms))
// Initialize the kzg object with the kzg library
initKZG(kzg, __dirname + '/../../src/trustedSetups/devnet4.txt')
initKZG(kzg, __dirname + '/../../src/trustedSetups/devnet6.txt')

export async function waitForELOnline(client: Client): Promise<string> {
for (let i = 0; i < 15; i++) {
Expand Down
2 changes: 1 addition & 1 deletion packages/evm/test/precompiles/14-pointevaluation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ tape('Precompiles: point evaluation', async (t) => {
t.end()
} else {
try {
initKZG(kzg, __dirname + '/../../../client/src/trustedSetups/devnet4.txt')
initKZG(kzg, __dirname + '/../../../client/src/trustedSetups/devnet6.txt')
// eslint-disable-next-line
} catch {}

Expand Down
8 changes: 6 additions & 2 deletions packages/tx/src/eip4844Transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,13 @@ const validateBlobTransactionNetworkWrapper = (
throw new Error('Invalid transaction with empty blobs')
}

let isValid
try {
kzg.verifyBlobKzgProofBatch(blobs, commitments, kzgProofs)
} catch (e) {
isValid = kzg.verifyBlobKzgProofBatch(blobs, commitments, kzgProofs)
} catch (error) {
throw new Error(`KZG verification of blobs fail with error=${error}`)
}
if (!isValid) {
throw new Error('KZG proof cannot be verified from blobs/commitments')
}

Expand Down
2 changes: 1 addition & 1 deletion packages/tx/test/eip4844.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const isBrowser = new Function('try {return this===window;}catch(e){ return fals
const pk = randomBytes(32)
if (isBrowser() === false) {
try {
initKZG(kzg, __dirname + '/../../client/src/trustedSetups/devnet4.txt')
initKZG(kzg, __dirname + '/../../client/src/trustedSetups/devnet6.txt')
// eslint-disable-next-line
} catch {}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/vm/test/api/EIPs/eip-4844-blobs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const pk = hexToBytes('20'.repeat(32))
const sender = bytesToPrefixedHexString(privateToAddress(pk))
if (isBrowser() === false) {
try {
initKZG(kzg, __dirname + '/../../../../client/src/trustedSetups/devnet4.txt')
initKZG(kzg, __dirname + '/../../../../client/src/trustedSetups/devnet6.txt')
// eslint-disable-next-line
} catch {}

Expand Down
2 changes: 1 addition & 1 deletion packages/vm/test/api/runTx.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,7 @@ tape('EIP 4844 transaction tests', async (t) => {
t.end()
} else {
try {
initKZG(kzg, __dirname + '/../../../client/src/trustedSetups/devnet4.txt')
initKZG(kzg, __dirname + '/../../../client/src/trustedSetups/devnet6.txt')
// eslint-disable-next-line
} catch {}

Expand Down
2 changes: 1 addition & 1 deletion packages/vm/test/tester/runners/BlockchainTestsRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import type { EthashConsensus } from '@ethereumjs/blockchain'
import type { Common } from '@ethereumjs/common'
import type * as tape from 'tape'

initKZG(kzg, __dirname + '/../../../../client/src/trustedSetups/devnet4.txt')
initKZG(kzg, __dirname + '/../../../../client/src/trustedSetups/devnet6.txt')

function formatBlockHeader(data: any) {
const formatted: any = {}
Expand Down

0 comments on commit 32aaac3

Please sign in to comment.