Skip to content

Commit

Permalink
Passing common in various places
Browse files Browse the repository at this point in the history
  • Loading branch information
acolytec3 committed Jan 17, 2024
1 parent 7e174ef commit 00cd74d
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 8 deletions.
1 change: 1 addition & 0 deletions packages/client/src/execution/vmexecution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions packages/devp2p/src/dpt/dpt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand Down
14 changes: 11 additions & 3 deletions packages/vm/src/bloom/index.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -23,7 +31,7 @@ export class Bloom {
* @param e - The element to add
*/
add(e: Uint8Array) {
e = keccak256(e)
e = this.keccakFunction(e)

This comment has been minimized.

Copy link
@holgerd77

holgerd77 Jan 18, 2024

Member

Oh. Right.

This might have been an important one too!

const mask = 2047 // binary 11111111111

for (let i = 0; i < 3; i++) {
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion packages/vm/src/buildBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion packages/vm/src/runBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions packages/vm/src/runTx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ async function _runTx(this: VM, opts: RunTxOpts): Promise<RunTxResult> {
* 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}`)
}
Expand Down Expand Up @@ -657,8 +657,8 @@ async function _runTx(this: VM, opts: RunTxOpts): Promise<RunTxResult> {
* @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]
Expand Down

0 comments on commit 00cd74d

Please sign in to comment.