Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ethereum-tests to 13.2 #3324

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/ethereum-tests
26 changes: 24 additions & 2 deletions packages/vm/src/runBlock.ts
Expand Up @@ -22,6 +22,7 @@
setLengthLeft,
short,
unprefixedHexToBytes,
zeros,
} from '@ethereumjs/util'
import debugDefault from 'debug'

Expand Down Expand Up @@ -344,9 +345,30 @@
}
}
if (this.common.isActivatedEIP(4788)) {
if (this.DEBUG) {
debug(`accumulate parentBeaconBlockRoot`)
if (
block.header.number === BIGINT_1 &&
(await this.stateManager.getContractCode(parentBeaconBlockRootAddress)).length > 0
) {
// TODO DELETE THIS LOGIC
// HotFix for ethereum/tests
const parent = await this.blockchain.getBlock(0)
const timestamp = parent.header.timestamp
const historicalRootsLength = BigInt(this.common.param('vm', 'historicalRootsLength'))
const timestampIndex = timestamp % historicalRootsLength
const timestampExtended = timestampIndex + historicalRootsLength

await this.stateManager.putContractStorage(
parentBeaconBlockRootAddress,
setLengthLeft(bigIntToBytes(timestampIndex), 32),
zeros(32)
)
await this.stateManager.putContractStorage(
parentBeaconBlockRootAddress,
setLengthLeft(bigIntToBytes(timestampExtended), 32),
zeros(32)
)

Check warning on line 369 in packages/vm/src/runBlock.ts

View check run for this annotation

Codecov / codecov/patch

packages/vm/src/runBlock.ts#L352-L369

Added lines #L352 - L369 were not covered by tests
}

await accumulateParentBeaconBlockRoot.bind(this)(
block.header.parentBeaconBlockRoot!,
block.header.timestamp
Expand Down
2 changes: 1 addition & 1 deletion packages/vm/test/tester/config.ts
Expand Up @@ -393,7 +393,7 @@ const expectedTestsFull: {
MuirGlacier: 12271,
Berlin: 13214,
London: 19449,
Paris: 19727,
Paris: 19718,
Shanghai: 19564,
ByzantiumToConstantinopleFixAt5: 0,
EIP158ToByzantiumAt5: 0,
Expand Down
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