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
8 changes: 4 additions & 4 deletions packages/client/src/execution/vmexecution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
equalsBytes,
hexToBytes,
} from '@ethereumjs/util'
import { VM, runBlock, runTx } from '@ethereumjs/vm'
import { createVM, runBlock, runTx } from '@ethereumjs/vm'
import { writeFileSync } from 'fs'
import * as mcl from 'mcl-wasm'
import { initRustBN } from 'rustbn-wasm'
Expand All @@ -41,7 +41,7 @@ import { ReceiptsManager } from './receipt.js'
import type { ExecutionOptions } from './execution.js'
import type { Block } from '@ethereumjs/block'
import type { PrefixedHexString } from '@ethereumjs/util'
import type { RunBlockOpts, TxReceipt } from '@ethereumjs/vm'
import type { RunBlockOpts, TxReceipt, VM } from '@ethereumjs/vm'

export enum ExecStatus {
VALID = 'VALID',
Expand Down Expand Up @@ -183,7 +183,7 @@ export class VMExecution extends Execution {

await mcl.init(mcl.BLS12_381)
const rustBN = await initRustBN()
this.merkleVM = await VM.create({
this.merkleVM = await createVM({
common: this.config.execCommon,
blockchain: this.chain.blockchain,
stateManager,
Expand All @@ -208,7 +208,7 @@ export class VMExecution extends Execution {
})
await mcl.init(mcl.BLS12_381)
const rustBN = await initRustBN()
this.verkleVM = await VM.create({
this.verkleVM = await createVM({
common: this.config.execCommon,
blockchain: this.chain.blockchain,
stateManager,
Expand Down
4 changes: 2 additions & 2 deletions packages/client/src/util/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export async function debugCodeReplayBlock(execution: VMExecution, block: Block)
import { Level } from 'level';
import { Common } from '@ethereumjs/common'
import { Block } from '@ethereumjs/block'
import { VM, runBlock } from './src'
import { VM, runBlock, createVM } from './src'
import { Trie } from '@ethereumjs/trie'
import { DefaultStateManager } from './src/state'
import { Blockchain } from '@ethereumjs/blockchain'
Expand All @@ -55,7 +55,7 @@ const main = async () => {
validateBlocks: true,
validateConsensus: false,
})
const vm = await VM.create({ stateManager, blockchain, common })
const vm = await createVM({ stateManager, blockchain, common })

await runBlock({ block })
}
Expand Down
4 changes: 2 additions & 2 deletions packages/client/test/execution/vmexecution.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createBlockFromExecutionPayload } from '@ethereumjs/block'
import { createBlockchain, createBlockchainFromBlocksData } from '@ethereumjs/blockchain'
import { Common, Goerli, Hardfork, Mainnet, createCustomCommon } from '@ethereumjs/common'
import { bytesToHex } from '@ethereumjs/util'
import { VM } from '@ethereumjs/vm'
import { createVM } from '@ethereumjs/vm'
import { assert, describe, it } from 'vitest'

import { Chain } from '../../src/blockchain/index.js'
Expand Down Expand Up @@ -88,7 +88,7 @@ const shanghaiPayload = {

describe('[VMExecution]', () => {
it('Initialization', async () => {
const vm = await VM.create()
const vm = await createVM()
const config = new Config({ vm, accountCache: 10000, storageCache: 1000 })
const chain = await Chain.create({ config })
const exec = new VMExecution({ config, chain })
Expand Down
19 changes: 10 additions & 9 deletions packages/client/test/miner/pendingBlock.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
hexToBytes,
randomBytes,
} from '@ethereumjs/util'
import { VM } from '@ethereumjs/vm'
import { createVM } from '@ethereumjs/vm'
import { loadKZG } from 'kzg-wasm'
import { assert, describe, it, vi } from 'vitest'

Expand All @@ -28,6 +28,7 @@ import { mockBlockchain } from '../rpc/mockBlockchain.js'

import type { Blockchain } from '@ethereumjs/blockchain'
import type { TypedTransaction } from '@ethereumjs/tx'
import type { VM } from '@ethereumjs/vm'

const A = {
address: new Address(hexToBytes('0x0b90087d864e82a284dca15923f3776de6bb016f')),
Expand Down Expand Up @@ -127,7 +128,7 @@ describe('[PendingBlock]', async () => {
it('should start and build', async () => {
const { txPool } = setup()
const blockchain = await createBlockchain({ common })
const vm = await VM.create({ common, blockchain })
const vm = await createVM({ common, blockchain })
await setBalance(vm, A.address, BigInt(5000000000000000))
await setBalance(vm, B.address, BigInt(5000000000000000))
await txPool.add(txA01)
Expand Down Expand Up @@ -155,7 +156,7 @@ describe('[PendingBlock]', async () => {
it('should include txs with mismatching hardforks that can still be executed', async () => {
const { txPool } = setup()
const blockchain = await createBlockchain({ common })
const vm = await VM.create({ common, blockchain })
const vm = await createVM({ common, blockchain })
await setBalance(vm, A.address, BigInt(5000000000000000))
await setBalance(vm, B.address, BigInt(5000000000000000))

Expand Down Expand Up @@ -204,7 +205,7 @@ describe('[PendingBlock]', async () => {
await txPool.add(txA01)
const pendingBlock = new PendingBlock({ config, txPool, skipHardForkValidation: true })
const blockchain = await createBlockchain({ common })
const vm = await VM.create({ common, blockchain })
const vm = await createVM({ common, blockchain })
await setBalance(vm, A.address, BigInt(5000000000000000))
const parentBlock = await (vm.blockchain as Blockchain).getCanonicalHeadBlock!()
const payloadId = await pendingBlock.start(vm, parentBlock)
Expand All @@ -225,7 +226,7 @@ describe('[PendingBlock]', async () => {
common['_chainParams'].genesis.gasLimit = 50000

const blockchain = await createBlockchain({ common })
const vm = await VM.create({ common, blockchain })
const vm = await createVM({ common, blockchain })
await setBalance(vm, A.address, BigInt(5000000000000000))

// create alternate transactions with custom gas limits to
Expand Down Expand Up @@ -277,7 +278,7 @@ describe('[PendingBlock]', async () => {
it('should skip adding txs when tx too big to fit', async () => {
const { txPool } = setup()
const blockchain = await createBlockchain({ common })
const vm = await VM.create({ common, blockchain })
const vm = await createVM({ common, blockchain })
await setBalance(vm, A.address, BigInt(5000000000000000))
await txPool.add(txA01)
await txPool.add(txA02)
Expand Down Expand Up @@ -319,7 +320,7 @@ describe('[PendingBlock]', async () => {
await txPool.add(txA01)
const pendingBlock = new PendingBlock({ config, txPool, skipHardForkValidation: true })
const blockchain = await createBlockchain({ common })
const vm = await VM.create({ common, blockchain })
const vm = await createVM({ common, blockchain })
const parentBlock = await (vm.blockchain as Blockchain).getCanonicalHeadBlock!()
const payloadId = await pendingBlock.start(vm, parentBlock)
assert.equal(pendingBlock.pendingPayloads.size, 1, 'should set the pending payload')
Expand Down Expand Up @@ -399,7 +400,7 @@ describe('[PendingBlock]', async () => {

const pendingBlock = new PendingBlock({ config, txPool })
const blockchain = await createBlockchain({ common })
const vm = await VM.create({ common, blockchain })
const vm = await createVM({ common, blockchain })
await setBalance(vm, A.address, BigInt(500000000000000000))
const parentBlock = await (vm.blockchain as Blockchain).getCanonicalHeadBlock!()
// stub the vm's common set hf to do nothing but stay in cancun
Expand Down Expand Up @@ -459,7 +460,7 @@ describe('[PendingBlock]', async () => {

const pendingBlock = new PendingBlock({ config, txPool })
const blockchain = await createBlockchain({ common })
const vm = await VM.create({ common, blockchain })
const vm = await createVM({ common, blockchain })
await setBalance(vm, A.address, BigInt(500000000000000000))
const parentBlock = await (vm.blockchain as Blockchain).getCanonicalHeadBlock!()
// stub the vm's common set hf to do nothing but stay in cancun
Expand Down
8 changes: 4 additions & 4 deletions packages/statemanager/test/rpcStateManager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
setLengthLeft,
utf8ToBytes,
} from '@ethereumjs/util'
import { VM, runBlock, runTx } from '@ethereumjs/vm'
import { createVM, runBlock, runTx } from '@ethereumjs/vm'
import { assert, describe, expect, it, vi } from 'vitest'

import { RPCBlockChain, RPCStateManager } from '../src/rpcStateManager.js'
Expand Down Expand Up @@ -231,7 +231,7 @@ describe('runTx custom transaction test', () => {
const common = new Common({ chain: Mainnet, hardfork: Hardfork.London })

const state = new RPCStateManager({ provider, blockTag: 1n })
const vm = await VM.create({ common, stateManager: <any>state }) // TODO fix the type DefaultStateManager back to StateManagerInterface in VM
const vm = await createVM({ common, stateManager: <any>state }) // TODO fix the type DefaultStateManager back to StateManagerInterface in VM

const vitalikDotEth = createAddressFromString('0xd8da6bf26964af9d7eed9e03e53415d37aa96045')
const privateKey = hexToBytes(
Expand Down Expand Up @@ -264,7 +264,7 @@ describe('runTx test: replay mainnet transactions', () => {
// Set the state manager to look at the state of the chain before the block has been executed
blockTag: blockTag - 1n,
})
const vm = await VM.create({ common, stateManager: state })
const vm = await createVM({ common, stateManager: state })
const res = await runTx(vm, { tx })
assert.equal(
res.totalGasSpent,
Expand All @@ -289,7 +289,7 @@ describe('runBlock test', () => {
// blocks, also for post merge network, ttd should also be passed
common.setHardforkBy({ blockNumber: blockTag - 1n })

const vm = await VM.create({ common, stateManager: state })
const vm = await createVM({ common, stateManager: state })
const block = createBlockFromRPC(blockData.default as JsonRpcBlock, [], { common })
try {
const res = await runBlock(vm, {
Expand Down
4 changes: 2 additions & 2 deletions packages/vm/benchmarks/mainnetBlocks.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Block, createBlockFromRPC } from '@ethereumjs/block'
import { Common, Hardfork, Mainnet } from '@ethereumjs/common'
import { runBlock as runBlockVM, VM } from '@ethereumjs/vm'
import { createVM, runBlock as runBlockVM, VM } from '@ethereumjs/vm'
import Benchmark from 'benchmark'
import { readFileSync } from 'fs'
import { getBlockchain, getPreState, verifyResult } from './util.js'
Expand Down Expand Up @@ -42,7 +42,7 @@ export async function mainnetBlocks(suite?: Benchmark.Suite, numSamples?: number

const stateManager = await getPreState(preState, common)
const blockchain = getBlockchain(blockhashes) as any
const vm = await VM.create({ stateManager, common, blockchain })
const vm = await createVM({ stateManager, common, blockchain })

if (suite) {
suite.add(`Block ${blockNumber}`, async () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/vm/examples/buildBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { createBlock } from '@ethereumjs/block'
import { Common, Mainnet } from '@ethereumjs/common'
import { createLegacyTx } from '@ethereumjs/tx'
import { Account, bytesToHex, createAddressFromPrivateKey, hexToBytes } from '@ethereumjs/util'
import { VM, buildBlock } from '@ethereumjs/vm'
import { buildBlock, createVM } from '@ethereumjs/vm'

const main = async () => {
const common = new Common({ chain: Mainnet })
const vm = await VM.create({ common })
const vm = await createVM({ common })

const parentBlock = createBlock(
{ header: { number: 1n } },
Expand Down
5 changes: 3 additions & 2 deletions packages/vm/examples/run-blockchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ import {
setLengthLeft,
toBytes,
} from '@ethereumjs/util'
import { VM, runBlock } from '@ethereumjs/vm'
import { createVM, runBlock } from '@ethereumjs/vm'

import testData from './helpers/blockchain-mock-data.json'

import type { Block } from '@ethereumjs/block'
import type { Blockchain, ConsensusDict } from '@ethereumjs/blockchain'
import type { VM } from '@ethereumjs/vm'

async function main() {
const common = new Common({ chain: Mainnet, hardfork: testData.network.toLowerCase() })
Expand All @@ -42,7 +43,7 @@ async function main() {
genesisBlock,
})

const vm = await VM.create({ blockchain, common })
const vm = await createVM({ blockchain, common })

await setupPreConditions(vm, testData)

Expand Down
5 changes: 3 additions & 2 deletions packages/vm/examples/run-solidity-contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createBlock } from '@ethereumjs/block'
import { Common, Hardfork, Mainnet } from '@ethereumjs/common'
import { createLegacyTx } from '@ethereumjs/tx'
import { bytesToHex, createAddressFromPrivateKey, hexToBytes } from '@ethereumjs/util'
import { VM, runTx } from '@ethereumjs/vm'
import { createVM, runTx } from '@ethereumjs/vm'
import { defaultAbiCoder as AbiCoder, Interface } from '@ethersproject/abi' // cspell:disable-line
import { readFileSync } from 'fs'
import path from 'path'
Expand All @@ -13,6 +13,7 @@ import { getAccountNonce, insertAccount } from './helpers/account-utils.js'
import { buildTransaction, encodeDeployment, encodeFunction } from './helpers/tx-builder.js'

import type { Address } from '@ethereumjs/util'
import type { VM } from '@ethereumjs/vm'

const INITIAL_GREETING = 'Hello, World!'
const SECOND_GREETING = 'Hola, Mundo!' // cspell:disable-line
Expand Down Expand Up @@ -168,7 +169,7 @@ async function getGreeting(vm: VM, contractAddress: Address, caller: Address) {
async function main() {
const accountPk = hexToBytes('0xe331b6d69882b4cb4ea581d88e0b604039a3de5967688d3dcffdd2270c0fd109')

const vm = await VM.create({ common })
const vm = await createVM({ common })
const accountAddress = createAddressFromPrivateKey(accountPk)

console.log('Account: ', accountAddress.toString())
Expand Down
5 changes: 2 additions & 3 deletions packages/vm/examples/runGoerliBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ import { createBlockFromRPC } from '@ethereumjs/block'
import { Common, Goerli } from '@ethereumjs/common'
import { bytesToHex } from '@ethereumjs/util'

import { runBlock } from '../src/index.js'
import { VM } from '../src/vm.js'
import { createVM, runBlock } from '../src/index.js'

import goerliBlock2 from './testData/goerliBlock2.json'

const main = async () => {
const common = new Common({ chain: Goerli, hardfork: 'london' })
const vm = await VM.create({ common, setHardfork: true })
const vm = await createVM({ common, setHardfork: true })

const block = createBlockFromRPC(goerliBlock2, undefined, { common })
const result = await runBlock(vm, { block, generate: true, skipHeaderValidation: true }) // we skip header validation since we are running a block without the full Ethereum history available
Expand Down
4 changes: 2 additions & 2 deletions packages/vm/examples/runTx.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Common, Hardfork, Mainnet } from '@ethereumjs/common'
import { createLegacyTx } from '@ethereumjs/tx'
import { createZeroAddress } from '@ethereumjs/util'
import { VM, runTx } from '@ethereumjs/vm'
import { createVM, runTx } from '@ethereumjs/vm'

const main = async () => {
const common = new Common({ chain: Mainnet, hardfork: Hardfork.Shanghai })
const vm = await VM.create({ common })
const vm = await createVM({ common })

const tx = createLegacyTx({
gasLimit: BigInt(21000),
Expand Down
4 changes: 2 additions & 2 deletions packages/vm/examples/vmWith4844.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Common, Hardfork, Mainnet } from '@ethereumjs/common'

import { VM } from '../src/vm.js'
import { createVM } from '../src/index.js'

const main = async () => {
const common = new Common({ chain: Mainnet, hardfork: Hardfork.Shanghai, eips: [4844] })
const vm = await VM.create({ common })
const vm = await createVM({ common })
console.log(`4844 is active in the VM - ${vm.common.isActivatedEIP(4844)}`)
}

Expand Down
4 changes: 2 additions & 2 deletions packages/vm/examples/vmWithEIPs.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Common, Mainnet } from '@ethereumjs/common'
import { VM } from '@ethereumjs/vm'
import { createVM } from '@ethereumjs/vm'

const main = async () => {
const common = new Common({ chain: Mainnet, eips: [7702] })
const vm = await VM.create({ common })
const vm = await createVM({ common })
console.log(`EIP 7702 is active in the VM - ${vm.common.isActivatedEIP(7702)}`)
}
void main()
4 changes: 2 additions & 2 deletions packages/vm/examples/vmWithGenesisState.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Chain } from '@ethereumjs/common'
import { getGenesis } from '@ethereumjs/genesis'
import { createAddressFromString } from '@ethereumjs/util'
import { VM } from '@ethereumjs/vm'
import { createVM } from '@ethereumjs/vm'

const main = async () => {
const genesisState = getGenesis(Chain.Mainnet)

const vm = await VM.create()
const vm = await createVM()
await vm.stateManager.generateCanonicalGenesis!(genesisState)
const account = await vm.stateManager.getAccount(
createAddressFromString('0x000d836201318ec6899a67540690382780743280'),
Expand Down
Loading