Skip to content

Commit

Permalink
Merge branch 'master' into update-4844-precompile-address
Browse files Browse the repository at this point in the history
  • Loading branch information
jochem-brouwer authored Jun 22, 2023
2 parents 9b884e0 + b2df147 commit 24707a5
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
17 changes: 13 additions & 4 deletions packages/block/src/header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,25 @@ export class BlockHeader {
*/
public static fromValuesArray(values: BlockHeaderBytes, opts: BlockOptions = {}) {
const headerData = valuesArrayToHeaderData(values)
const { number, baseFeePerGas } = headerData
const { number, baseFeePerGas, excessDataGas, dataGasUsed } = headerData
const header = BlockHeader.fromHeaderData(headerData, opts)
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
if (opts.common?.isActivatedEIP(1559) && baseFeePerGas === undefined) {
const eip1559ActivationBlock = bigIntToBytes(opts.common?.eipBlock(1559)!)
if (header._common.isActivatedEIP(1559) && baseFeePerGas === undefined) {
const eip1559ActivationBlock = bigIntToBytes(header._common.eipBlock(1559)!)
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
if (eip1559ActivationBlock && equalsBytes(eip1559ActivationBlock, number as Uint8Array)) {
throw new Error('invalid header. baseFeePerGas should be provided')
}
}
return BlockHeader.fromHeaderData(headerData, opts)
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
if (header._common.isActivatedEIP(4844)) {
if (excessDataGas === undefined) {
throw new Error('invalid header. excessDataGas should be provided')
} else if (dataGasUsed === undefined) {
throw new Error('invalid header. dataGasUsed should be provided')
}
}
return header
}
/**
* This constructor takes the values, validates them, assigns them and freezes the object.
Expand Down
7 changes: 7 additions & 0 deletions packages/blockchain/src/blockchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,13 @@ export class Blockchain implements BlockchainInterface {
throw new Error(`Invalid block: base fee not correct ${header.errorStr()}`)
}
}

if (header._common.isActivatedEIP(4844) === true) {
const expectedExcessDataGas = parentHeader.calcNextExcessDataGas()
if (header.excessDataGas !== expectedExcessDataGas) {
throw new Error(`expected data gas: ${expectedExcessDataGas}, got: ${header.excessDataGas}`)
}
}
}

/**
Expand Down
11 changes: 10 additions & 1 deletion packages/vm/test/tester/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ export function getTestDirs(network: string, testType: string) {
* @param ttd If set: total terminal difficulty to switch to merge
* @returns
*/
function setupCommonWithNetworks(network: string, ttd?: number) {
function setupCommonWithNetworks(network: string, ttd?: number, timestamp?: number) {
let networkLowercase: string // This only consists of the target hardfork, so without the EIPs
if (network.includes('+')) {
const index = network.indexOf('+')
Expand Down Expand Up @@ -323,6 +323,13 @@ function setupCommonWithNetworks(network: string, ttd?: number) {
ttd: BigInt(ttd),
})
}
if (timestamp !== undefined && hf.name !== Hardfork.Dao) {
testHardforks.push({
name: hf.name,
block: null,
timestamp,
})
}
}
}
const common = Common.custom(
Expand Down Expand Up @@ -369,6 +376,8 @@ export function getCommon(network: string): Common {
const startNetwork = network.substring(0, start) // HF before the merge
const TTD = Number('0x' + network.substring(end)) // Total difficulty to transition to PoS
return setupCommonWithNetworks(startNetwork, TTD)
} else if (networkLowercase === 'shanghaitocancunattime15k') {
return setupCommonWithNetworks('Shanghai', undefined, 15000)
} else {
// Case 3: this is not a "default fork" network, but it is a "transition" network. Test the VM if it transitions the right way
const transitionForks =
Expand Down

0 comments on commit 24707a5

Please sign in to comment.