diff --git a/packages/client/src/execution/vmexecution.ts b/packages/client/src/execution/vmexecution.ts index c8a342a891..fff888fcaf 100644 --- a/packages/client/src/execution/vmexecution.ts +++ b/packages/client/src/execution/vmexecution.ts @@ -152,6 +152,7 @@ export class VMExecution extends Execution { type: CacheType.LRU, size: this.config.codeCache, }, + common: this.config.chainCommon, }) this.merkleVM = await VM.create({ common: this.config.execCommon, diff --git a/packages/devp2p/src/dpt/dpt.ts b/packages/devp2p/src/dpt/dpt.ts index 701d94458b..60c6f61f1e 100644 --- a/packages/devp2p/src/dpt/dpt.ts +++ b/packages/devp2p/src/dpt/dpt.ts @@ -68,6 +68,7 @@ export class DPT { timeout: options.timeout, endpoint: options.endpoint, createSocket: options.createSocket, + common: options.common, }) this._server.events.once('listening', () => this.events.emit('listening')) this._server.events.once('close', () => this.events.emit('close')) diff --git a/packages/vm/src/bloom/index.ts b/packages/vm/src/bloom/index.ts index 13e247161b..f333c2f14b 100644 --- a/packages/vm/src/bloom/index.ts +++ b/packages/vm/src/bloom/index.ts @@ -1,15 +1,23 @@ import { zeros } from '@ethereumjs/util' import { keccak256 } from 'ethereum-cryptography/keccak.js' +import type { Common } from '@ethereumjs/common' + const BYTE_SIZE = 256 export class Bloom { bitvector: Uint8Array + keccakFunction: (msg: Uint8Array) => Uint8Array /** * Represents a Bloom filter. */ - constructor(bitvector?: Uint8Array) { + constructor(bitvector?: Uint8Array, common?: Common) { + if (common?.customCrypto.keccak256 !== undefined) { + this.keccakFunction = common.customCrypto.keccak256 + } else { + this.keccakFunction = keccak256 + } if (!bitvector) { this.bitvector = zeros(BYTE_SIZE) } else { @@ -23,7 +31,7 @@ export class Bloom { * @param e - The element to add */ add(e: Uint8Array) { - e = keccak256(e) + e = this.keccakFunction(e) const mask = 2047 // binary 11111111111 for (let i = 0; i < 3; i++) { @@ -40,7 +48,7 @@ export class Bloom { * @param e - The element to check */ check(e: Uint8Array): boolean { - e = keccak256(e) + e = this.keccakFunction(e) const mask = 2047 // binary 11111111111 let match = true diff --git a/packages/vm/src/buildBlock.ts b/packages/vm/src/buildBlock.ts index 231c9f1eec..54e8fbfaf5 100644 --- a/packages/vm/src/buildBlock.ts +++ b/packages/vm/src/buildBlock.ts @@ -139,7 +139,7 @@ export class BlockBuilder { * Calculates and returns the logs bloom for the block. */ public logsBloom() { - const bloom = new Bloom() + const bloom = new Bloom(undefined, this.vm.common) for (const txResult of this.transactionResults) { // Combine blooms via bitwise OR bloom.or(txResult.bloom) diff --git a/packages/vm/src/runBlock.ts b/packages/vm/src/runBlock.ts index 7c5b15359f..fcf4a45e4c 100644 --- a/packages/vm/src/runBlock.ts +++ b/packages/vm/src/runBlock.ts @@ -421,7 +421,7 @@ async function applyTransactions(this: VM, block: Block, opts: RunBlockOpts) { console.time(processTxsLabel) } - const bloom = new Bloom() + const bloom = new Bloom(undefined, this.common) // the total amount of gas used processing these transactions let gasUsed = BIGINT_0 diff --git a/packages/vm/src/runTx.ts b/packages/vm/src/runTx.ts index 9496939e32..4c2999eb7f 100644 --- a/packages/vm/src/runTx.ts +++ b/packages/vm/src/runTx.ts @@ -493,7 +493,7 @@ async function _runTx(this: VM, opts: RunTxOpts): Promise { * Parse results */ // Generate the bloom for the tx - results.bloom = txLogsBloom(results.execResult.logs) + results.bloom = txLogsBloom(results.execResult.logs, this.common) if (this.DEBUG) { debug(`Generated tx bloom with logs=${results.execResult.logs?.length}`) } @@ -657,8 +657,8 @@ async function _runTx(this: VM, opts: RunTxOpts): Promise { * @method txLogsBloom * @private */ -function txLogsBloom(logs?: any[]): Bloom { - const bloom = new Bloom() +function txLogsBloom(logs?: any[], common?: Common): Bloom { + const bloom = new Bloom(undefined, common) if (logs) { for (let i = 0; i < logs.length; i++) { const log = logs[i]