diff --git a/packages/block/src/block.ts b/packages/block/src/block.ts index eb1d243f098..398712132dc 100644 --- a/packages/block/src/block.ts +++ b/packages/block/src/block.ts @@ -389,6 +389,7 @@ export class Block { feeRecipient: coinbase, transactions, withdrawals: withdrawalsData, + requestsRoot, executionWitness, } = payload @@ -408,6 +409,7 @@ export class Block { } } + const reqRoot = requestsRoot === null ? undefined : requestsRoot const transactionsTrie = await Block.genTransactionsTrieRoot( txs, new Trie({ common: opts?.common }) @@ -424,6 +426,7 @@ export class Block { withdrawalsRoot, mixHash, coinbase, + requestsRoot: reqRoot, } // we are not setting setHardfork as common is already set to the correct hf diff --git a/packages/block/src/types.ts b/packages/block/src/types.ts index acb703a274e..f5edac5cad6 100644 --- a/packages/block/src/types.ts +++ b/packages/block/src/types.ts @@ -302,5 +302,5 @@ export type ExecutionPayload = { parentBeaconBlockRoot?: PrefixedHexString | string // QUANTITY, 64 Bits // VerkleExecutionWitness is already a hex serialized object executionWitness?: VerkleExecutionWitness | null // QUANTITY, 64 Bits, null implies not available - // TODO: Determine if we need the requestsRoot here + requestsRoot?: PrefixedHexString | string | null // DATA, 32 bytes, null implies EIP 7685 not active yet } diff --git a/packages/common/src/eips.ts b/packages/common/src/eips.ts index 978e1abc7b7..7513552f239 100644 --- a/packages/common/src/eips.ts +++ b/packages/common/src/eips.ts @@ -605,7 +605,7 @@ export const EIPs: EIPsDict = { status: Status.Draft, // TODO: Set correct minimum hardfork minimumHardfork: Hardfork.Cancun, - requiredEIPs: [], + requiredEIPs: [3675], gasPrices: {}, }, } diff --git a/packages/vm/src/runBlock.ts b/packages/vm/src/runBlock.ts index 0a143480fdd..e1f34aee66c 100644 --- a/packages/vm/src/runBlock.ts +++ b/packages/vm/src/runBlock.ts @@ -952,16 +952,6 @@ const DAOConfig = { DAORefundContract: 'bf4ed7b27f1d666546e30d74d50d173d20bca754', } -export class ValidatorWithdrawalRequest extends CLRequest implements CLRequestType { - constructor(type: number, bytes: Uint8Array) { - super(type, bytes) - } - - serialize() { - return concatBytes(Uint8Array.from([this.type]), this.bytes) - } -} - /** * This helper method generates a list of all CL requests that can be included in a pending block * @param _vm VM instance from which to derive CL requests @@ -969,11 +959,10 @@ export class ValidatorWithdrawalRequest extends CLRequest implements CLRequestTy */ export const accumulateRequests = async (vm: VM): Promise => { const requests: CLRequest[] = [] - const common = vm.common // TODO: Add in code to accumulate deposits (EIP-6110) - if (common.isActivatedEIP(7002)) { + if (vm.common.isActivatedEIP(7002)) { await _accumulateEIP7002Requests(vm, requests) } @@ -986,8 +975,17 @@ export const accumulateRequests = async (vm: VM): Promise => { return requests } +export class ValidatorWithdrawalRequest extends CLRequest implements CLRequestType { + constructor(type: number, bytes: Uint8Array) { + super(type, bytes) + } + + serialize() { + return concatBytes(Uint8Array.from([this.type]), this.bytes) + } +} + const _accumulateEIP7002Requests = async (vm: VM, requests: CLRequest[]): Promise => { - console.log('Perform system call') // TODO PERFORM LOGIC TO CHECK IF CONTRACT EXISTS // Partial withdrawals logic const addressBytes = setLengthLeft( diff --git a/packages/vm/test/api/EIPs/eip-7685.spec.ts b/packages/vm/test/api/EIPs/eip-7685.spec.ts index 066e049e056..ce097778bee 100644 --- a/packages/vm/test/api/EIPs/eip-7685.spec.ts +++ b/packages/vm/test/api/EIPs/eip-7685.spec.ts @@ -1,7 +1,7 @@ import { Block } from '@ethereumjs/block' import { Blockchain } from '@ethereumjs/blockchain' import { Chain, Common, Hardfork } from '@ethereumjs/common' -import { CLRequest, KECCAK256_RLP, concatBytes, randomBytes } from '@ethereumjs/util' +import { CLRequest, KECCAK256_RLP, concatBytes, hexToBytes, randomBytes } from '@ethereumjs/util' import { assert, describe, expect, it } from 'vitest' import { VM } from '../../../src/vm.js' @@ -9,6 +9,9 @@ import { setupVM } from '../utils.js' import type { CLRequestType } from '@ethereumjs/util' +const invalidRequestsRoot = hexToBytes( + '0xc98048d6605eb79ecc08d90b8817f44911ec474acd8d11688453d2c6ef743bc5' +) class NumberRequest extends CLRequest implements CLRequestType { constructor(type: number, bytes: Uint8Array) { super(type, bytes) @@ -37,8 +40,9 @@ describe('EIP-7685 runBlock tests', () => { }) it('should error when an invalid requestsRoot is provided', async () => { const vm = await setupVM({ common }) + const emptyBlock = Block.fromBlockData( - { header: { requestsRoot: randomBytes(32) } }, + { header: { requestsRoot: invalidRequestsRoot } }, { common } ) await expect(async () => @@ -66,7 +70,7 @@ describe('EIP-7685 runBlock tests', () => { const block = Block.fromBlockData( { requests: [request], - header: { requestsRoot: randomBytes(32) }, + header: { requestsRoot: invalidRequestsRoot }, }, { common } )