Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
332 changes: 294 additions & 38 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion packages/binarytree/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
"@ethereumjs/util": "^10.0.0-rc.1",
"@noble/hashes": "^1.7.2",
"debug": "^4.4.0",
"ethereum-cryptography": "^3.1.0",
"lru-cache": "11.0.2"
},
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion packages/block/examples/clrequests.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Common, Hardfork, Mainnet } from '@ethereumjs/common'
import { CLRequestType, bytesToHex, createCLRequest, hexToBytes } from '@ethereumjs/util'
import { sha256 } from 'ethereum-cryptography/sha256.js'
import { sha256 } from '@noble/hashes/sha2'

import { createBlock, genRequestsRoot } from '../src'

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 @@
"@ethereumjs/mpt": "^10.0.0-rc.1",
"@ethereumjs/tx": "^10.0.0-rc.1",
"@ethereumjs/util": "^10.0.0-rc.1",
"ethereum-cryptography": "^3.1.0"
"@noble/hashes": "1.8.0",
"@noble/curves": "1.9.0"
},
"devDependencies": {
"@ethereumjs/testdata": "1.0.0",
Expand Down
6 changes: 3 additions & 3 deletions packages/block/src/block/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import {
bytesToHex,
equalsBytes,
} from '@ethereumjs/util'
import { keccak256 } from 'ethereum-cryptography/keccak.js'
import { sha256 } from 'ethereum-cryptography/sha256.js'
import { sha256 } from '@noble/hashes/sha2'
import { keccak_256 } from '@noble/hashes/sha3'

import type { Common } from '@ethereumjs/common'
import type { FeeMarket1559Tx, LegacyTx, TypedTransaction } from '@ethereumjs/tx'
Expand Down Expand Up @@ -90,7 +90,7 @@ export class Block {
) {
this.header = header ?? new BlockHeader({}, opts)
this.common = this.header.common
this.keccakFunction = this.common.customCrypto.keccak256 ?? keccak256
this.keccakFunction = this.common.customCrypto.keccak256 ?? keccak_256
this.sha256Function = this.common.customCrypto.sha256 ?? sha256

this.transactions = transactions
Expand Down
2 changes: 1 addition & 1 deletion packages/block/src/consensus/clique.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
equalsBytes,
setLengthLeft,
} from '@ethereumjs/util'
import { secp256k1 } from 'ethereum-cryptography/secp256k1.js'
import { secp256k1 } from '@noble/curves/secp256k1'

import type { CliqueConfig } from '@ethereumjs/common'
import type { BlockHeader } from '../index.ts'
Expand Down
4 changes: 2 additions & 2 deletions packages/block/src/header/header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
hexToBytes,
toType,
} from '@ethereumjs/util'
import { keccak256 } from 'ethereum-cryptography/keccak.js'
import { keccak_256 } from '@noble/hashes/sha3'

import {
CLIQUE_EXTRA_SEAL,
Expand Down Expand Up @@ -102,7 +102,7 @@ export class BlockHeader {
}
this.common.updateParams(opts.params ?? paramsBlock)

this.keccakFunction = this.common.customCrypto.keccak256 ?? keccak256
this.keccakFunction = this.common.customCrypto.keccak256 ?? keccak_256

const skipValidateConsensusFormat = opts.skipConsensusFormatValidation ?? false

Expand Down
2 changes: 1 addition & 1 deletion packages/block/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ export function genRequestsRoot(
}

// def compute_requests_hash(list):
// return keccak256(rlp.encode([rlp.encode(req) for req in list]))
// return keccak_256(rlp.encode([rlp.encode(req) for req in list]))

let flatRequests = new Uint8Array()
for (const req of requests) {
Expand Down
2 changes: 1 addition & 1 deletion packages/block/test/clrequests.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Common, Hardfork, Mainnet } from '@ethereumjs/common'
import { CLRequestType, createCLRequest, equalsBytes, hexToBytes } from '@ethereumjs/util'
import { sha256 } from 'ethereum-cryptography/sha256.js'
import { sha256 } from '@noble/hashes/sha2'
import { assert, describe, it } from 'vitest'

import { createBlock, genRequestsRoot } from '../src/index.ts'
Expand Down
4 changes: 2 additions & 2 deletions packages/blockchain/test/blockValidation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Common, ConsensusAlgorithm, Hardfork, Mainnet } from '@ethereumjs/commo
import { Ethash } from '@ethereumjs/ethash'
import { RLP } from '@ethereumjs/rlp'
import { bytesToHex } from '@ethereumjs/util'
import { keccak256 } from 'ethereum-cryptography/keccak.js'
import { keccak_256 } from '@noble/hashes/sha3'
import { assert, describe, expect, it } from 'vitest'

import { EthashConsensus, createBlockchain } from '../src/index.ts'
Expand Down Expand Up @@ -304,7 +304,7 @@ describe('[Blockchain]: Block validation tests', () => {
common: new Common({ chain: Mainnet, hardfork: Hardfork.Berlin }),
})

forkBlockHeaderData.uncleHash = bytesToHex(keccak256(RLP.encode([uncleHeader.raw()])))
forkBlockHeaderData.uncleHash = bytesToHex(keccak_256(RLP.encode([uncleHeader.raw()])))

const forkBlock_ValidCommon = createBlock(
{
Expand Down
4 changes: 2 additions & 2 deletions packages/blockchain/test/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
toBytes,
utf8ToBytes,
} from '@ethereumjs/util'
import { keccak256 } from 'ethereum-cryptography/keccak.js'
import { keccak_256 } from '@noble/hashes/sha3'

import { createBlockchain } from '../src/index.ts'

Expand Down Expand Up @@ -200,7 +200,7 @@ function generateBlock(
const number = parentBlock.header.number + BigInt(1)
const timestamp = parentBlock.header.timestamp + BigInt(1)

const uncleHash = keccak256(RLP.encode(uncles.map((uh) => uh.raw())))
const uncleHash = keccak_256(RLP.encode(uncles.map((uh) => uh.raw())))

const londonHfBlock = common.hardforkBlock(Hardfork.London)
const baseFeePerGas =
Expand Down
8 changes: 4 additions & 4 deletions packages/client/bin/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ import {
randomBytes,
setLengthLeft,
} from '@ethereumjs/util'
import { secp256k1 } from '@noble/curves/secp256k1'
import { sha256 } from '@noble/hashes/sha2'
import { keccak_256 } from '@noble/hashes/sha3'
import { trustedSetup } from '@paulmillr/trusted-setups/fast.js'
import {
keccak256 as keccak256WASM,
Expand All @@ -37,9 +40,6 @@ import {
waitReady as waitReadyPolkadotSha256,
sha256 as wasmSha256,
} from '@polkadot/wasm-crypto'
import { keccak256 } from 'ethereum-cryptography/keccak.js'
import { secp256k1 } from 'ethereum-cryptography/secp256k1.js'
import { sha256 } from 'ethereum-cryptography/sha256.js'
import { KZG as microEthKZG } from 'micro-eth-signer/kzg'
import * as verkle from 'micro-eth-signer/verkle'
import * as promClient from 'prom-client'
Expand Down Expand Up @@ -662,7 +662,7 @@ export async function getCryptoFunctions(useJsCrypto: boolean): Promise<CustomCr
return secp256k1Recover(hash, sig, recId)
}
} else {
cryptoFunctions.keccak256 = keccak256
cryptoFunctions.keccak256 = keccak_256
cryptoFunctions.ecrecover = ecrecover
cryptoFunctions.sha256 = sha256
cryptoFunctions.ecsign = secp256k1.sign
Expand Down
3 changes: 2 additions & 1 deletion packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@
"@ethereumjs/vm": "10.0.0-rc.1",
"@js-sdsl/ordered-map": "^4.4.2",
"@multiformats/multiaddr": "^12.4.0",
"@noble/curves": "1.9.0",
"@noble/hashes": "1.8.0",
"@paulmillr/trusted-setups": "^0.1.2",
"@polkadot/wasm-crypto": "^7.4.1",
"@scure/base": "^1.2.4",
Expand All @@ -76,7 +78,6 @@
"connect": "^3.7.0",
"cors": "^2.8.5",
"debug": "^4.4.0",
"ethereum-cryptography": "^3.1.0",
"eventemitter3": "^5.0.1",
"jayson": "^4.1.3",
"level": "^9.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/execution/preimage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { DBKey, MetaDBManager } from '../util/metaDBManager.ts'

/**
* The `PreImagesManager` saves the preimages of hashed keys. This is necessary for the Verkle transition.
* A "PreImage" of a hash is whatever the input is to the hashed function. So, if one calls `keccak256(X)` with
* A "PreImage" of a hash is whatever the input is to the hashed function. So, if one calls `keccak_256(X)` with
* output `Y` then `X` is the preimage of `Y`. It thus serves to recover the input to the trapdoor hash function,
* which would otherwise not be feasible.
*/
Expand Down
4 changes: 2 additions & 2 deletions packages/client/src/miner/pendingBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
toType,
} from '@ethereumjs/util'
import { BuildStatus, buildBlock } from '@ethereumjs/vm'
import { keccak256 } from 'ethereum-cryptography/keccak.js'
import { keccak_256 } from '@noble/hashes/sha3'

import type { Block, HeaderData } from '@ethereumjs/block'
import type { TypedTransaction } from '@ethereumjs/tx'
Expand Down Expand Up @@ -142,7 +142,7 @@ export class PendingBlock {
withdrawalsBuf = concatBytes(...withdrawalsBufTemp)
}

const keccakFunction = this.config.chainCommon.customCrypto.keccak256 ?? keccak256
const keccakFunction = this.config.chainCommon.customCrypto.keccak256 ?? keccak_256

const payloadIdBytes = keccakFunction(
concatBytes(
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/rpc/modules/engine/util/newPayload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
bytesToHex,
hexToBytes,
} from '@ethereumjs/util'
import { sha256 } from 'ethereum-cryptography/sha256.js'
import { sha256 } from '@noble/hashes/sha2'

import { short } from '../../../../util/index.ts'
import { Status } from '../types.ts'
Expand Down
4 changes: 2 additions & 2 deletions packages/client/src/rpc/modules/web3.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { bytesToHex, hexToBytes } from '@ethereumjs/util'
import { keccak256 } from 'ethereum-cryptography/keccak.js'
import { keccak_256 } from '@noble/hashes/sha3'

import { getClientVersion } from '../../util/index.ts'
import { callWithStackTrace } from '../helpers.ts'
Expand Down Expand Up @@ -45,7 +45,7 @@ export class Web3 {
* @param params The data to convert into a SHA3 hash
*/
sha3(params: PrefixedHexString[]): PrefixedHexString {
const hexEncodedDigest = bytesToHex(keccak256(hexToBytes(params[0])))
const hexEncodedDigest = bytesToHex(keccak_256(hexToBytes(params[0])))
return hexEncodedDigest
}
}
4 changes: 2 additions & 2 deletions packages/client/src/sync/fetcher/bytecodefetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {
concatBytes,
equalsBytes,
} from '@ethereumjs/util'
import { keccak_256 } from '@noble/hashes/sha3'
import debug from 'debug'
import { keccak256 } from 'ethereum-cryptography/keccak.js'

import { Fetcher } from './fetcher.ts'
import { getInitFetcherDoneFlags } from './types.ts'
Expand Down Expand Up @@ -59,7 +59,7 @@ export class ByteCodeFetcher extends Fetcher<JobTask, Uint8Array[], Uint8Array>
this.fetcherDoneFlags.byteCodeFetcher.count = BigInt(this.hashes.length)
this.codeDB = this.stateManager['_getCodeDB']()

this.keccakFunction = this.config.chainCommon.customCrypto.keccak256 ?? keccak256
this.keccakFunction = this.config.chainCommon.customCrypto.keccak256 ?? keccak_256

this.debug = debug('client:fetcher:bytecode')
if (this.hashes.length > 0) {
Expand Down
4 changes: 2 additions & 2 deletions packages/client/src/sync/fetcher/trienodefetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import {
unprefixedHexToBytes,
} from '@ethereumjs/util'
import { OrderedMap } from '@js-sdsl/ordered-map'
import { keccak_256 } from '@noble/hashes/sha3'
import debug from 'debug'
import { keccak256 } from 'ethereum-cryptography/keccak.js'

import { Fetcher } from './fetcher.ts'
import { getInitFetcherDoneFlags } from './types.ts'
Expand Down Expand Up @@ -115,7 +115,7 @@ export class TrieNodeFetcher extends Fetcher<JobTask, Uint8Array[], Uint8Array>
this.nodeCount = 0
this.debug = debug('client:fetcher:trienode')

this.keccakFunction = this.config.chainCommon.customCrypto.keccak256 ?? keccak256
this.keccakFunction = this.config.chainCommon.customCrypto.keccak256 ?? keccak_256

// will always start with root node as first set of node requests
this.pathToNodeRequestData.setElement('', {
Expand Down
8 changes: 6 additions & 2 deletions packages/client/test/cli/utils.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as fs from 'fs'
import { keccak_256 } from '@noble/hashes/sha3'
import { keccak256 as keccak256WASM } from '@polkadot/wasm-crypto'
import { keccak256 } from 'ethereum-cryptography/keccak.js'
import { assert, describe, it } from 'vitest'

import { generateClientConfig } from '../../bin/utils.ts'
Expand Down Expand Up @@ -52,7 +52,11 @@ describe('generateClientConfig', () => {
useJsCrypto: true,
}
const { common } = await generateClientConfig(opts)
assert.deepEqual(common.customCrypto.keccak256, keccak256, 'JS keccak256 should be initialized')
assert.deepEqual(
common.customCrypto.keccak256,
keccak_256,
'JS keccak256 should be initialized',
)
})

it('should set bootnodes correctly from a file', async () => {
Expand Down
6 changes: 3 additions & 3 deletions packages/client/test/miner/miner.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { goerliChainConfig } from '@ethereumjs/testdata'
import { createFeeMarket1559Tx, createLegacyTx } from '@ethereumjs/tx'
import { Address, equalsBytes, hexToBytes } from '@ethereumjs/util'
import { AbstractLevel } from 'abstract-level'
// import { keccak256 } from 'ethereum-cryptography/keccak.js'
// import { keccak_256 } from '@noble/hashes/sha3'
import { assert, describe, it, vi } from 'vitest'

// import { Chain } from '../../src/blockchain/index.ts'
Expand Down Expand Up @@ -569,15 +569,15 @@ describe.skip('assembleBlocks() -> should stop assembling when a new block is re
await setBalance(vm, A.address, BigInt('200000000000001'))

// add many txs to slow assembling
let privateKey = keccak256(new Uint8Array(0))
let privateKey = keccak_256(new Uint8Array(0))
for (let i = 0; i < 1000; i++) {
// In order not to pollute TxPool with too many txs from the same address
// (or txs which are already known), keep generating a new address for each tx
const address = createAddressFromPrivateKey(privateKey)
await setBalance(vm, address, BigInt('200000000000001'))
const tx = createTx({ address, privateKey })
await txPool.add(tx)
privateKey = keccak256(privateKey)
privateKey = keccak_256(privateKey)
}

chain.putBlocks = () => {
Expand Down
12 changes: 6 additions & 6 deletions packages/client/test/net/protocol/snapprotocol.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
hexToBytes,
setLengthLeft,
} from '@ethereumjs/util'
import { keccak256 } from 'ethereum-cryptography/keccak.js'
import { keccak_256 } from '@noble/hashes/sha3'
import { assert, describe, it } from 'vitest'

import { Chain } from '../../../src/blockchain/index.ts'
Expand Down Expand Up @@ -201,7 +201,7 @@ describe('[SnapProtocol]', () => {
assert.fail(`AccountRange proof verification failed with message=${(e as Error).message}`)
}
assert.isTrue(
equalsBytes(keccak256(proof[0]), stateRoot),
equalsBytes(keccak_256(proof[0]), stateRoot),
'Proof should link to the requested stateRoot',
)
})
Expand All @@ -216,7 +216,7 @@ describe('[SnapProtocol]', () => {
const limit = hexToBytes('0x0000000000000000000000000f00000000000000000000000000000000000010')
const bytes = BigInt(5000000)
const accounts = [
keccak256(hexToBytes('0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')),
keccak_256(hexToBytes('0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')),
hexToBytes('0x0000000000000000000000000f00000000000000000000000000000000000010'),
]

Expand Down Expand Up @@ -344,7 +344,7 @@ describe('[SnapProtocol]', () => {
assert.fail(`StorageRange proof verification failed with message=${(e as Error).message}`)
}
assert.isTrue(
equalsBytes(keccak256(proof[0]), lastAccountStorageRoot),
equalsBytes(keccak_256(proof[0]), lastAccountStorageRoot),
'Proof should link to the accounts storageRoot',
)
})
Expand All @@ -355,7 +355,7 @@ describe('[SnapProtocol]', () => {
const p = new SnapProtocol({ config, chain })
const reqId = BigInt(1)
const hashes = [
keccak256(hexToBytes('0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')),
keccak_256(hexToBytes('0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')),
hexToBytes('0x0000000000000000000000000f00000000000000000000000000000000000010'),
]
const bytes = BigInt(5000000)
Expand Down Expand Up @@ -431,7 +431,7 @@ describe('[SnapProtocol]', () => {
)
const code = codes[0]
assert.isTrue(
equalsBytes(keccak256(code), codeHash),
equalsBytes(keccak_256(code), codeHash),
'Code should match the requested codeHash',
)
})
Expand Down
Loading