Skip to content

Commit

Permalink
vm: fix block prestate root
Browse files Browse the repository at this point in the history
  • Loading branch information
jochem-brouwer committed Mar 17, 2024
1 parent 53d3743 commit 66a1918
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions packages/vm/test/tester/runners/BlockchainTestsRunner.ts
Expand Up @@ -6,6 +6,7 @@ import { DefaultStateManager } from '@ethereumjs/statemanager'
import { Trie } from '@ethereumjs/trie'
import { TransactionFactory } from '@ethereumjs/tx'
import {
Address,
MapDB,
bytesToBigInt,
bytesToHex,
Expand All @@ -16,12 +17,17 @@ import {
} from '@ethereumjs/util'

import { VM } from '../../../dist/cjs'
import { accumulateParentBeaconBlockRoot } from '../../../src/runBlock'
import { setupPreConditions, verifyPostConditions } from '../../util'

import type { EthashConsensus } from '@ethereumjs/blockchain'
import type { Common } from '@ethereumjs/common'
import type * as tape from 'tape'

const parentBeaconBlockRootAddress = Address.fromString(
'0x000F3df6D732807Ef1319fB7B8bB8522d0Beac02'
)

function formatBlockHeader(data: any) {
const formatted: any = {}
for (const [key, value] of Object.entries(data) as [string, string][]) {
Expand Down Expand Up @@ -97,6 +103,15 @@ export async function runBlockchainTest(options: any, testData: any, t: tape.Tes
// set up pre-state
await setupPreConditions(vm.stateManager, testData)

if (vm.common.isActivatedEIP(4788)) {
if ((await vm.stateManager.getContractCode(parentBeaconBlockRootAddress)).length > 0) {
// Fix pre state root, have to add timestamp + block root for the genesis block in the
const root = hexToBytes(testData.genesisBlockHeader.parentBeaconBlockRoot)
const timestamp = bytesToBigInt(hexToBytes(testData.genesisBlockHeader.timestamp))
await accumulateParentBeaconBlockRoot.bind(<any>vm)(root, timestamp)
}
}

t.deepEquals(
await vm.stateManager.getStateRoot(),
genesisBlock.header.stateRoot,
Expand Down

0 comments on commit 66a1918

Please sign in to comment.