Skip to content

Commit

Permalink
vm: update tests to v13 (cancun tests) (#3162)
Browse files Browse the repository at this point in the history
* vm: update tests to v13 (cancun tests)

* fix ci file

* vm/tx: update test runner + 4844 spec

* block/tx: fix tests

* client: fix tests

* client: fix final test

* vm: better error msg
jochem-brouwer authored Nov 17, 2023
1 parent 8209e39 commit e2803ab
Showing 15 changed files with 73 additions and 44 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/vm-pr.yml
Original file line number Diff line number Diff line change
@@ -119,6 +119,8 @@ jobs:
'--fork=ArrowGlacierToMergeAtDiffC0000',
'--fork=Shanghai --dir=GeneralStateTests/stTimeConsuming',
'--fork=Shanghai --excludeDir=stTimeConsuming',
'--fork=Cancun --dir=GeneralStateTests/stTimeConsuming',
'--fork=Cancun --excludeDir=stTimeConsuming',
]
fail-fast: false
steps:
@@ -157,6 +159,7 @@ jobs:
'--fork=London --verify-test-amount-alltests',
'--fork=Paris --verify-test-amount-alltests',
'--fork=Shanghai --verify-test-amount-alltests',
'--fork=Cancun --verify-test-amount-alltests',
'--fork=ByzantiumToConstantinopleFixAt5 --verify-test-amount-alltests',
'--fork=EIP158ToByzantiumAt5 --verify-test-amount-alltests',
'--fork=FrontierToHomesteadAt5 --verify-test-amount-alltests',
6 changes: 3 additions & 3 deletions packages/block/test/testdata/payload-slot-87335.json
Original file line number Diff line number Diff line change
@@ -11,11 +11,11 @@
"timestamp": "1683551220",
"extra_data": "0x4e65746865726d696e64",
"base_fee_per_gas": "7",
"block_hash": "0xdb9615aeeae255df092f27d42478eccbf7921c3fd537d5f1ce5ac5120ee4b7a4",
"block_hash": "0xc49a052fba00d1171381b811adde068179fd130ef76227388a54cfcf516f7126",
"transactions": [
"0x03f89d850120b996ed3685012a1a646085012a1a64608303345094ffb38a7a99e3e2335be83fc74b7faa19d55312418308a80280c085012a1a6460e1a00153a6a1e053cf4c5a09e84088ed8ad7cb53d76c8168f1b82f7cfebfcd06da1a01a007785223eec68459d72265f10bdb30ec3415252a63100605a03142fa211ebbe9a07dbbf9e081fa7b9a01202e4d9ee0e0e513f80efbbab6c784635429905389ce86",
"0x03f889850120b996ed81f0847735940084b2d05e158307a1208001855f495f4955c084b2d05e15e1a001d343d3cd62abd9c5754cbe5128c25ea90786a8ae75fb79c8cf95f4dcdd08ec80a014103732b5a9789bbf5ea859ed904155398abbef343f8fd63007efb70795d382a07272e847382789a092eadf08e2b9002e727376f8466fff0e4d4639fd60a528f2",
"0x03f889850120b996ed81f1843b9aca00847735940e8307a1208001855f495f4955c0847735940ee1a001d552e24560ec2f168be1d4a6385df61c70afe4288f00a3ad172da1a6f2b4f280a0b6690786e5fe79df67dcb60e8a9e8555142c3c96ffd5097c838717f0a7f64129a0112f01ed0cd3b86495f01736fbbc1b793f71565223aa26f093471a4d8605d198",
"0x03f89d850120b996ed81f0847735940084b2d05e158307a12094000000000000000000000000000000000000000001855f495f4955c084b2d05e15e1a001d343d3cd62abd9c5754cbe5128c25ea90786a8ae75fb79c8cf95f4dcdd08ec80a014103732b5a9789bbf5ea859ed904155398abbef343f8fd63007efb70795d382a07272e847382789a092eadf08e2b9002e727376f8466fff0e4d4639fd60a528f2",
"0x03f89d850120b996ed81f0847735940084b2d05e158307a12094000000000000000000000000000000000000000001855f495f4955c084b2d05e15e1a001d343d3cd62abd9c5754cbe5128c25ea90786a8ae75fb79c8cf95f4dcdd08ec80a014103732b5a9789bbf5ea859ed904155398abbef343f8fd63007efb70795d382a07272e847382789a092eadf08e2b9002e727376f8466fff0e4d4639fd60a528f2",
"0x03f897850120b996ed80840bebc200843b9aca078303345094c8d369b164361a8961286cfbab3bc10f962185a88080c08411e1a300e1a0011df88a2971c8a7ac494a7ba37ec1acaa1fc1edeeb38c839b5d1693d47b69b080a032f122f06e5802224db4c8a58fd22c75173a713f63f89936f811c144b9e40129a043a2a872cbfa5727007adf6a48febe5f190d2e4cd5ed6122823fb6ff47ecda32"
],
"withdrawals": [],
7 changes: 5 additions & 2 deletions packages/client/test/net/protocol/ethprotocol.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Block } from '@ethereumjs/block'
import { Common, Hardfork } from '@ethereumjs/common'
import { FeeMarketEIP1559Transaction, TransactionFactory, TransactionType } from '@ethereumjs/tx'
import { bigIntToBytes, bytesToBigInt, hexToBytes, randomBytes } from '@ethereumjs/util'
import { Address, bigIntToBytes, bytesToBigInt, hexToBytes, randomBytes } from '@ethereumjs/util'
import { assert, describe, it } from 'vitest'

import { Chain } from '../../../src/blockchain/chain'
@@ -217,7 +217,10 @@ describe('[EthProtocol]', () => {
const legacyTx = TransactionFactory.fromTxData({ type: 0 })
const eip2929Tx = TransactionFactory.fromTxData({ type: 1 })
const eip1559Tx = TransactionFactory.fromTxData({ type: 2 })
const blobTx = TransactionFactory.fromTxData({ type: 3 }, { common: config.chainCommon })
const blobTx = TransactionFactory.fromTxData(
{ type: 3, to: Address.zero(), blobVersionedHashes: [hexToBytes('0x01' + '00'.repeat(31))] },
{ common: config.chainCommon }
)
const res = p.encode(p.messages.filter((message) => message.name === 'Transactions')[0], [
legacyTx,
eip2929Tx,
3 changes: 2 additions & 1 deletion packages/client/test/rpc/engine/getPayloadV3.spec.ts
Original file line number Diff line number Diff line change
@@ -113,6 +113,7 @@ describe(method, () => {
maxFeePerGas: 10000000000n,
maxPriorityFeePerGas: 100000000n,
gasLimit: 30000000n,
to: Address.zero(),
},
{ common }
).sign(pkey)
@@ -124,7 +125,7 @@ describe(method, () => {
const { executionPayload, blobsBundle } = res.body.result
assert.equal(
executionPayload.blockHash,
'0xf63169fd7c38630ead561c84612d0e9e1eade2f54d729f48460042a3cee66609',
'0xe8175305416ee94c996164162044338b4f4d93a8dc458b574ecad4ce84323fb5',
'built expected block'
)
assert.equal(executionPayload.excessBlobGas, '0x0', 'correct execess blob gas')
4 changes: 2 additions & 2 deletions packages/client/test/rpc/engine/newPayloadV3.spec.ts
Original file line number Diff line number Diff line change
@@ -63,8 +63,8 @@ describe(`${method}: call with executionPayloadV3`, () => {
withdrawals: [],
blobGasUsed: '0x0',
excessBlobGas: '0x0',
blockHash: '0x449c6da07b4fed636dca71e35c5c48bdea73c1e3cfd770638af05fcf015753f1',
stateRoot: '0x453898f64d0626f3bc2b50f57be5182d377b916186714ed51df749403c49b99d',
blockHash: '0xbb9bd9ec0b48b52556ce0180afcefc31d59dd288914b931ff32ff9813519fa7f',
stateRoot: '0xca3149fa9e37db08d1cd49c9061db1002ef1cd58db2210f2115c8c989b2bdf45',
}
let expectRes, req

Original file line number Diff line number Diff line change
@@ -59,7 +59,7 @@ describe(`${method}: Cancun validations`, () => {
await baseRequest(server, req, 200, expectRes, false)

const txString =
'0x03f87c01808405f5e1008502540be4008401c9c380808080c001e1a001317228841f747eac2b4987a0225753a4f81688b31b21192ad2d2a3f5d252c580a01146addbda4889ddeaa8e4d74baae37c55f9796ab17030c762260faa797ca33ea0555a673397ea115d81c390a560ab77d3f63e93a59270b1b8d12cd2a1fb8b9b11'
'0x03f89001808405f5e1008502540be4008401c9c3809400000000000000000000000000000000000000008080c001e1a001317228841f747eac2b4987a0225753a4f81688b31b21192ad2d2a3f5d252c580a01146addbda4889ddeaa8e4d74baae37c55f9796ab17030c762260faa797ca33ea0555a673397ea115d81c390a560ab77d3f63e93a59270b1b8d12cd2a1fb8b9b11'
const txVersionedHashesString = [
'0x01317228841f747eac2b4987a0225753a4f81688b31b21192ad2d2a3f5d252c5',
]
@@ -107,7 +107,7 @@ describe(`${method}: Cancun validations`, () => {
{
...blockData,
parentHash: '0x2559e851470f6e7bbed1db474980683e8c315bfce99b2a6ef47c057c04de7858',
blockHash: '0xeea272bb9ac158550c645a1b0666727a5fefa4a865f8d4c642a87143d2abef39',
blockHash: '0xda4fd641baf437352c42dd2a46a28993854b51850938140cddc45ecc9e88b108',
withdrawals: [],
blobGasUsed: '0x40000',
excessBlobGas: '0x0',
@@ -131,7 +131,7 @@ describe(`${method}: Cancun validations`, () => {
{
...blockData,
parentHash: '0x2559e851470f6e7bbed1db474980683e8c315bfce99b2a6ef47c057c04de7858',
blockHash: '0xeea272bb9ac158550c645a1b0666727a5fefa4a865f8d4c642a87143d2abef39',
blockHash: '0xda4fd641baf437352c42dd2a46a28993854b51850938140cddc45ecc9e88b108',
withdrawals: [],
blobGasUsed: '0x40000',
excessBlobGas: '0x0',
@@ -155,7 +155,7 @@ describe(`${method}: Cancun validations`, () => {
{
...blockData,
parentHash: '0x2559e851470f6e7bbed1db474980683e8c315bfce99b2a6ef47c057c04de7858',
blockHash: '0xeea272bb9ac158550c645a1b0666727a5fefa4a865f8d4c642a87143d2abef39',
blockHash: '0xda4fd641baf437352c42dd2a46a28993854b51850938140cddc45ecc9e88b108',
withdrawals: [],
blobGasUsed: '0x40000',
excessBlobGas: '0x0',
4 changes: 2 additions & 2 deletions packages/client/test/rpc/eth/getBlockByNumber.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Block } from '@ethereumjs/block'
import { Common } from '@ethereumjs/common'
import { BlobEIP4844Transaction, LegacyTransaction } from '@ethereumjs/tx'
import { hexToBytes, initKZG } from '@ethereumjs/util'
import { Address, hexToBytes, initKZG } from '@ethereumjs/util'
import * as kzg from 'c-kzg'
import { assert, describe, it } from 'vitest'

@@ -19,7 +19,7 @@ common.setHardfork('cancun')
const mockedTx1 = LegacyTransaction.fromTxData({}).sign(dummy.privKey)
const mockedTx2 = LegacyTransaction.fromTxData({ nonce: 1 }).sign(dummy.privKey)
const mockedBlobTx3 = BlobEIP4844Transaction.fromTxData(
{ nonce: 2, blobsData: ['0x1234'] },
{ nonce: 2, blobsData: ['0x1234'], to: Address.zero() },
{ common }
).sign(dummy.privKey)
const blockHash = hexToBytes('0xdcf93da321b27bca12087d6526d2c10540a4c8dc29db1b36610c3004e0e5d2d5')
2 changes: 1 addition & 1 deletion packages/ethereum-tests
2 changes: 1 addition & 1 deletion packages/tx/src/constants.ts
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
export const MAX_CALLDATA_SIZE = 16777216 // 2 ** 24
export const MAX_ACCESS_LIST_SIZE = 16777216 // 2 ** 24
export const MAX_VERSIONED_HASHES_LIST_SIZE = 16777216 // 2 ** 24
export const LIMIT_BLOBS_PER_TX = 16777216 // 2 ** 24
export const LIMIT_BLOBS_PER_TX = 6 // 786432 / 2^17 (`MAX_BLOB_GAS_PER_BLOCK` / `GAS_PER_BLOB`)
export const MAX_TX_WRAP_KZG_COMMITMENTS = 16777216 // 2 ** 24
export const FIELD_ELEMENTS_PER_BLOB = 4096 // This is also in the Common 4844 parameters but needed here since types can't access Common params
export const BYTES_PER_FIELD_ELEMENT = 32
9 changes: 9 additions & 0 deletions packages/tx/src/eip4844Transaction.ts
Original file line number Diff line number Diff line change
@@ -168,6 +168,15 @@ export class BlobEIP4844Transaction extends BaseTransaction<TransactionType.Blob
if (this.blobVersionedHashes.length > LIMIT_BLOBS_PER_TX) {
const msg = this._errorMsg(`tx can contain at most ${LIMIT_BLOBS_PER_TX} blobs`)
throw new Error(msg)
} else if (this.blobVersionedHashes.length === 0) {
const msg = this._errorMsg(`tx should contain at least one blob`)
throw new Error(msg)
}
if (this.to === undefined) {
const msg = this._errorMsg(
`tx should have a "to" field and cannot be used to create contracts`
)
throw new Error(msg)
}

this.blobs = txData.blobs?.map((blob) => toBytes(blob))
2 changes: 1 addition & 1 deletion packages/tx/test/eip3860.spec.ts
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@ const txTypes = [
TransactionType.Legacy,
TransactionType.AccessListEIP2930,
TransactionType.FeeMarketEIP1559,
TransactionType.BlobEIP4844,
//TransactionType.BlobEIP4844, // Explicitly commented out: BlobEIP4844 txs cannot create contracts
]
const addressZero = Address.zero()

40 changes: 20 additions & 20 deletions packages/tx/test/eip4844.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Common, Hardfork } from '@ethereumjs/common'
import {
Address,
blobsToCommitments,
blobsToProofs,
bytesToHex,
@@ -39,6 +40,7 @@ describe('EIP4844 constructor tests - valid scenarios', () => {
type: 0x03,
blobVersionedHashes: [concatBytes(new Uint8Array([1]), randomBytes(31))],
maxFeePerBlobGas: 1n,
to: Address.zero(),
}
const tx = BlobEIP4844Transaction.fromTxData(txData, { common })
assert.equal(tx.type, 3, 'successfully instantiated a blob transaction from txData')
@@ -132,6 +134,7 @@ describe('EIP4844 constructor tests - invalid scenarios', () => {
const baseTxData = {
type: 0x03,
maxFeePerBlobGas: 1n,
to: Address.zero(),
}
const shortVersionHash = {
blobVersionedHashes: [concatBytes(new Uint8Array([3]), randomBytes(3))],
@@ -307,26 +310,22 @@ describe('Network wrapper tests', () => {
'throws on blobsData and KZG proofs in txData'
)

const txWithEmptyBlob = BlobEIP4844Transaction.fromTxData(
{
blobVersionedHashes: [],
blobs: [],
kzgCommitments: [],
kzgProofs: [],
maxFeePerBlobGas: 100000000n,
gasLimit: 0xffffffn,
to: randomBytes(20),
},
{ common }
)

const serializedWithEmptyBlob = txWithEmptyBlob.serializeNetworkWrapper()
assert.throws(
() =>
BlobEIP4844Transaction.fromSerializedBlobTxNetworkWrapper(serializedWithEmptyBlob, {
common,
}),
'Invalid transaction with empty blobs',
() => {
BlobEIP4844Transaction.fromTxData(
{
blobVersionedHashes: [],
blobs: [],
kzgCommitments: [],
kzgProofs: [],
maxFeePerBlobGas: 100000000n,
gasLimit: 0xffffffn,
to: randomBytes(20),
},
{ common }
)
},
'tx should contain at least one blob',
undefined,
'throws a transaction with no blobs'
)
@@ -439,12 +438,13 @@ describe('hash() and signature verification', () => {
storageKeys: ['0x0000000000000000000000000000000000000000000000000000000000000000'],
},
],
to: Address.zero(),
},
{ common }
)
assert.equal(
bytesToHex(unsignedTx.getHashedMessageToSign()),
'0x8ce8c3544ca173c0e8dd0e86319d4ebfe649e15a730137a6659ba3a721a9ff8b',
'0x02560c5173b0d793ce019cfa515ece6a04a4b3f3d67eab67fbca78dd92d4ed76',
'produced the correct transaction hash'
)
const signedTx = unsignedTx.sign(
10 changes: 8 additions & 2 deletions packages/vm/src/runBlock.ts
Original file line number Diff line number Diff line change
@@ -221,7 +221,13 @@ export async function runBlock(this: VM, opts: RunBlockOpts): Promise<RunBlockRe
)}`
)
}
const msg = _errorMsg('invalid block stateRoot', this, block)
const msg = _errorMsg(
`invalid block stateRoot, got: ${bytesToHex(stateRoot)}, want: ${bytesToHex(
block.header.stateRoot
)}`,
this,
block
)
throw new Error(msg)
}
}
@@ -360,7 +366,7 @@ export async function accumulateParentBeaconBlockRoot(
*/

if ((await this.stateManager.getAccount(parentBeaconBlockRootAddress)) === undefined) {
await this.stateManager.putAccount(parentBeaconBlockRootAddress, new Account())
await this.evm.journal.putAccount(parentBeaconBlockRootAddress, new Account())
}

await this.stateManager.putContractStorage(
4 changes: 2 additions & 2 deletions packages/vm/test/tester/config.ts
Original file line number Diff line number Diff line change
@@ -378,7 +378,7 @@ const expectedTestsFull: {
HomesteadToDaoAt5: 32,
HomesteadToEIP150At5: 3,
BerlinToLondonAt5: 24,
Cancun: 0,
Cancun: 61633,
},
GeneralStateTests: {
Chainstart: 1045,
@@ -401,7 +401,7 @@ const expectedTestsFull: {
HomesteadToDaoAt5: 0,
HomesteadToEIP150At5: 0,
BerlinToLondonAt5: 0,
Cancun: 0,
Cancun: 19048,
},
}

13 changes: 10 additions & 3 deletions packages/vm/test/util.ts
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@ import { Chain, Common, Hardfork } from '@ethereumjs/common'
import { RLP } from '@ethereumjs/rlp'
import {
AccessListEIP2930Transaction,
BlobEIP4844Transaction,
FeeMarketEIP1559Transaction,
LegacyTransaction,
} from '@ethereumjs/tx'
@@ -110,14 +111,20 @@ export function format(a: any, toZero: boolean = false, isHex: boolean = false):
* Make a tx using JSON from tests repo
* @param {Object} txData The tx object from tests repo
* @param {TxOptions} opts Tx opts that can include an @ethereumjs/common object
* @returns {FeeMarketEIP1559Transaction | AccessListEIP2930Transaction | LegacyTransaction} Transaction to be passed to VM.runTx function
* @returns {BlobEIP4844Transaction | FeeMarketEIP1559Transaction | AccessListEIP2930Transaction | LegacyTransaction} Transaction to be passed to VM.runTx function
*/
export function makeTx(
txData: any,
opts?: TxOptions
): FeeMarketEIP1559Transaction | AccessListEIP2930Transaction | LegacyTransaction {
):
| BlobEIP4844Transaction
| FeeMarketEIP1559Transaction
| AccessListEIP2930Transaction
| LegacyTransaction {
let tx
if (txData.maxFeePerGas !== undefined) {
if (txData.blobVersionedHashes !== undefined) {
tx = BlobEIP4844Transaction.fromTxData(txData, opts)
} else if (txData.maxFeePerGas !== undefined) {
tx = FeeMarketEIP1559Transaction.fromTxData(txData, opts)
} else if (txData.accessLists !== undefined) {
tx = AccessListEIP2930Transaction.fromTxData(txData, opts)

0 comments on commit e2803ab

Please sign in to comment.