Skip to content

Commit

Permalink
Merge branch 'master' into eip-7002-new [no ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
jochem-brouwer committed May 1, 2024
2 parents 20b80a1 + 55a8e66 commit a22191b
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 18 deletions.
3 changes: 3 additions & 0 deletions packages/block/src/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ export class Block {
feeRecipient: coinbase,
transactions,
withdrawals: withdrawalsData,
requestsRoot,
executionWitness,
} = payload

Expand All @@ -408,6 +409,7 @@ export class Block {
}
}

const reqRoot = requestsRoot === null ? undefined : requestsRoot
const transactionsTrie = await Block.genTransactionsTrieRoot(
txs,
new Trie({ common: opts?.common })
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/block/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion packages/common/src/eips.ts
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ export const EIPs: EIPsDict = {
status: Status.Draft,
// TODO: Set correct minimum hardfork
minimumHardfork: Hardfork.Cancun,
requiredEIPs: [],
requiredEIPs: [3675],
gasPrices: {},
},
}
24 changes: 11 additions & 13 deletions packages/vm/src/runBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -952,28 +952,17 @@ 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
* @returns an list of CL requests in ascending order by type
*/
export const accumulateRequests = async (vm: VM): Promise<CLRequest[]> => {
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)
}

Expand All @@ -986,8 +975,17 @@ export const accumulateRequests = async (vm: VM): Promise<CLRequest[]> => {
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<void> => {
console.log('Perform system call')
// TODO PERFORM LOGIC TO CHECK IF CONTRACT EXISTS
// Partial withdrawals logic
const addressBytes = setLengthLeft(
Expand Down
10 changes: 7 additions & 3 deletions packages/vm/test/api/EIPs/eip-7685.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
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'
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)
Expand Down Expand Up @@ -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 () =>
Expand Down Expand Up @@ -66,7 +70,7 @@ describe('EIP-7685 runBlock tests', () => {
const block = Block.fromBlockData(
{
requests: [request],
header: { requestsRoot: randomBytes(32) },
header: { requestsRoot: invalidRequestsRoot },
},
{ common }
)
Expand Down

0 comments on commit a22191b

Please sign in to comment.