Skip to content

Commit

Permalink
Move all kzg stuff to util
Browse files Browse the repository at this point in the history
  • Loading branch information
acolytec3 authored and g11tech committed Mar 30, 2023
1 parent 1c4bb05 commit 8693a6a
Show file tree
Hide file tree
Showing 20 changed files with 92 additions and 65 deletions.
10 changes: 8 additions & 2 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/test/eip4844block.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Chain, Common, Hardfork } from '@ethereumjs/common'
import { BlobEIP4844Transaction, initKZG } from '@ethereumjs/tx'
import { BlobEIP4844Transaction } from '@ethereumjs/tx'
import {
blobsToCommitments,
commitmentsToVersionedHashes,
getBlobs,
} from '@ethereumjs/tx/dist/utils/blobHelpers'
initKZG,
} from '@ethereumjs/util'
import * as kzg from 'c-kzg'
import { randomBytes } from 'crypto'
import * as tape from 'tape'
Expand Down
3 changes: 1 addition & 2 deletions packages/client/bin/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import { Block } from '@ethereumjs/block'
import { Blockchain, parseGethGenesisState } from '@ethereumjs/blockchain'
import { Chain, Common, ConsensusAlgorithm, Hardfork } from '@ethereumjs/common'
import { RLP } from '@ethereumjs/rlp'
import { initKZG } from '@ethereumjs/tx'
import { Address, arrToBufArr, short, toBuffer } from '@ethereumjs/util'
import { Address, arrToBufArr, initKZG, short, toBuffer } from '@ethereumjs/util'
import * as kzg from 'c-kzg'
import { randomBytes } from 'crypto'
import { existsSync, writeFileSync } from 'fs'
Expand Down
7 changes: 4 additions & 3 deletions packages/client/devnets/4844-interop/tools/txGenerator.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
// Adapted from - https://github.com/Inphi/eip4844-interop/blob/master/blob_tx_generator/blob.js
import { Common, Hardfork } from '@ethereumjs/common'
import { BlobEIP4844Transaction, initKZG } from '@ethereumjs/tx'
import { BlobEIP4844Transaction } from '@ethereumjs/tx'
import {
Address,
initKZG,
blobsToCommitments,
commitmentsToVersionedHashes,
getBlobs,
} from '@ethereumjs/tx/dist/utils/blobHelpers'
import { Address } from '@ethereumjs/util'
} from '@ethereumjs/util'
import * as kzg from 'c-kzg'
import { randomBytes } from 'crypto'
import { Client } from 'jayson/promise'
Expand Down
9 changes: 6 additions & 3 deletions packages/client/test/miner/pendingBlock.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { Block, BlockHeader } from '@ethereumjs/block'
import { Common, Chain as CommonChain, Hardfork } from '@ethereumjs/common'
import { BlobEIP4844Transaction, Transaction, initKZG } from '@ethereumjs/tx'
import { BlobEIP4844Transaction, Transaction } from '@ethereumjs/tx'
import {
Account,
Address,
blobsToCommitments,
bufferToHex,
commitmentsToVersionedHashes,
getBlobs,
} from '@ethereumjs/tx/dist/utils/blobHelpers'
import { Account, Address, bufferToHex } from '@ethereumjs/util'
initKZG,
} from '@ethereumjs/util'
import { VM } from '@ethereumjs/vm'
import { VmState } from '@ethereumjs/vm/dist/eei/vmState'
import * as kzg from 'c-kzg'
Expand Down
4 changes: 2 additions & 2 deletions packages/client/test/rpc/engine/getBlobsBundleV1.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Hardfork } from '@ethereumjs/common'
import { DefaultStateManager } from '@ethereumjs/statemanager'
import { TransactionFactory, initKZG } from '@ethereumjs/tx'
import { Address } from '@ethereumjs/util'
import { TransactionFactory } from '@ethereumjs/tx'
import { Address, initKZG } from '@ethereumjs/util'
import * as kzg from 'c-kzg'
import * as tape from 'tape'

Expand Down
12 changes: 4 additions & 8 deletions packages/client/test/rpc/eth/sendRawTransaction.spec.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
import { BlockHeader } from '@ethereumjs/block'
import { Chain, Common, Hardfork } from '@ethereumjs/common'
import { DefaultStateManager } from '@ethereumjs/statemanager'
import {
BlobEIP4844Transaction,
FeeMarketEIP1559Transaction,
Transaction,
initKZG,
} from '@ethereumjs/tx'
import { BlobEIP4844Transaction, FeeMarketEIP1559Transaction, Transaction } from '@ethereumjs/tx'
import {
blobsToCommitments,
commitmentsToVersionedHashes,
getBlobs,
} from '@ethereumjs/tx/dist/utils/blobHelpers'
import { toBuffer } from '@ethereumjs/util'
initKZG,
toBuffer,
} from '@ethereumjs/util'
import * as kzg from 'c-kzg'
import { randomBytes } from 'crypto'
import * as tape from 'tape'
Expand Down
7 changes: 4 additions & 3 deletions packages/client/test/sim/simutils.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { Blockchain } from '@ethereumjs/blockchain'
import { BlobEIP4844Transaction, FeeMarketEIP1559Transaction, initKZG } from '@ethereumjs/tx'
import { BlobEIP4844Transaction, FeeMarketEIP1559Transaction } from '@ethereumjs/tx'
import {
Address,
blobsToCommitments,
blobsToProofs,
commitmentsToVersionedHashes,
getBlobs,
} from '@ethereumjs/tx/dist/utils/blobHelpers'
import { Address } from '@ethereumjs/util'
initKZG,
} from '@ethereumjs/util'
import * as kzg from 'c-kzg'
import { randomBytes } from 'crypto'
import * as fs from 'fs/promises'
Expand Down
7 changes: 4 additions & 3 deletions packages/client/test/sim/txGenerator.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// Adapted from - https://github.com/Inphi/eip4844-interop/blob/master/blob_tx_generator/blob.js
import { BlobEIP4844Transaction, initKZG } from '@ethereumjs/tx'
import { BlobEIP4844Transaction } from '@ethereumjs/tx'
import {
Address,
blobsToCommitments,
commitmentsToVersionedHashes,
} from '@ethereumjs/tx/test/utils/blobHelpers'
import { Address } from '@ethereumjs/util'
initKZG,
} from '@ethereumjs/util'
import * as kzg from 'c-kzg'
import { randomBytes } from 'crypto'
import { Client } from 'jayson/promise'
Expand Down
1 change: 0 additions & 1 deletion packages/evm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
},
"dependencies": {
"@ethereumjs/common": "^3.1.1",
"@ethereumjs/tx": "^4.1.1",
"@ethereumjs/util": "^8.0.5",
"@ethersproject/providers": "^5.7.1",
"debug": "^4.3.3",
Expand Down
11 changes: 9 additions & 2 deletions packages/evm/src/precompiles/14-kzg-point-evaluation.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import { computeVersionedHash, kzg } from '@ethereumjs/tx'
import { bigIntToBuffer, bufferToBigInt, bufferToHex, setLengthLeft, short } from '@ethereumjs/util'
import {
bigIntToBuffer,
bufferToBigInt,
bufferToHex,
computeVersionedHash,
kzg,
setLengthLeft,
short,
} from '@ethereumjs/util'

import { EvmErrorResult } from '../evm'
import { ERROR, EvmError } from '../exceptions'
Expand Down
9 changes: 7 additions & 2 deletions packages/evm/test/precompiles/14-pointevaluation.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { Common, Hardfork } from '@ethereumjs/common'
import { computeVersionedHash, initKZG } from '@ethereumjs/tx'
import { bigIntToBuffer, bufferToBigInt, unpadBuffer } from '@ethereumjs/util'
import {
bigIntToBuffer,
bufferToBigInt,
computeVersionedHash,
initKZG,
unpadBuffer,
} from '@ethereumjs/util'
import * as kzg from 'c-kzg'
import * as tape from 'tape'

Expand Down
20 changes: 0 additions & 20 deletions packages/tx/src/depInterfaces.ts

This file was deleted.

4 changes: 2 additions & 2 deletions packages/tx/src/eip4844Transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@ import {
bigIntToUnpaddedBuffer,
bufferToBigInt,
bufferToHex,
computeVersionedHash,
ecrecover,
kzg,
toBuffer,
} from '@ethereumjs/util'
import { keccak256 } from 'ethereum-cryptography/keccak'

import { BaseTransaction } from './baseTransaction'
import { LIMIT_BLOBS_PER_TX } from './constants'
import { kzg } from './kzg/kzg'
import {
BlobNetworkTransactionWrapper,
BlobTransactionType,
SignedBlobTransactionType,
} from './types'
import { AccessLists, blobTxToNetworkWrapperDataFormat } from './util'
import { computeVersionedHash } from './utils/blobHelpers'

import type {
AccessList,
Expand Down
2 changes: 0 additions & 2 deletions packages/tx/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
export { FeeMarketEIP1559Transaction } from './eip1559Transaction'
export { AccessListEIP2930Transaction } from './eip2930Transaction'
export { BlobEIP4844Transaction } from './eip4844Transaction'
export { initKZG, kzg } from './kzg/kzg'
export { Transaction } from './legacyTransaction'
export { TransactionFactory } from './transactionFactory'
export * from './types'
export { computeVersionedHash } from './utils/blobHelpers'
13 changes: 7 additions & 6 deletions packages/tx/test/eip4844.spec.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { Common, Hardfork } from '@ethereumjs/common'
import * as kzg from 'c-kzg'
import { randomBytes } from 'crypto'
import * as tape from 'tape'

import { BlobEIP4844Transaction, TransactionFactory, initKZG } from '../src'
import {
blobsToCommitments,
blobsToProofs,
commitmentsToVersionedHashes,
getBlobs,
} from '../src/utils/blobHelpers'
initKZG,
} from '@ethereumjs/util'
import * as kzg from 'c-kzg'
import { randomBytes } from 'crypto'
import * as tape from 'tape'

import { BlobEIP4844Transaction, TransactionFactory } from '../src'

// Hack to detect if running in browser or not
const isBrowser = new Function('try {return this===window;}catch(e){ return false;}')
Expand Down
8 changes: 8 additions & 0 deletions packages/util/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@
"@types/bn.js": "^5.1.0",
"@types/secp256k1": "^4.0.1"
},
"peerDependencies": {
"c-kzg": "^2.0.0"
},
"peerDependenciesMeta": {
"c-kzg": {
"optional": true
}
},
"engines": {
"node": ">=14"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { sha256 } from 'ethereum-cryptography/sha256'

import { kzg } from '../kzg/kzg'
import { kzg } from './kzg'

/**
* These utilities for constructing blobs are borrowed from https://github.com/Inphi/eip4844-interop.git
Expand Down
2 changes: 2 additions & 0 deletions packages/util/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export * from './encoding'
* Export ethjs-util methods
*/
export * from './asyncEventEmitter'
export * from './blobHelpers'
export {
arrayContainsArray,
fromAscii,
Expand All @@ -64,4 +65,5 @@ export {
stripHexPrefix,
toAscii,
} from './internal'
export * from './kzg'
export * from './lock'
21 changes: 20 additions & 1 deletion packages/tx/src/kzg/kzg.ts → packages/util/src/kzg.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
import type { Kzg } from '../depInterfaces'
/**
* Interface for an externally provided kzg library used when creating blob transactions
*/
export interface Kzg {
loadTrustedSetup(filePath: string): void
freeTrustedSetup(): void
blobToKzgCommitment(blob: Uint8Array): Uint8Array
computeBlobKzgProof(blob: Uint8Array): Uint8Array
verifyKzgProof(
polynomialKzg: Uint8Array,
z: Uint8Array,
y: Uint8Array,
kzgProof: Uint8Array
): boolean
verifyBlobKzgProofBatch(
blobs: Uint8Array[],
expectedKzgCommitments: Uint8Array[],
kzgProofs: Uint8Array[]
): boolean
}

function kzgNotLoaded(): never {
throw Error('kzg library not loaded')
Expand Down

0 comments on commit 8693a6a

Please sign in to comment.