Skip to content

Commit b37a8d9

Browse files
g11techjochem-brouweram1r021spencer-tbacolytec3
authored
pectra devnet4: implement pectra devnet4 spec (#3706)
* vm: update the system contract addresses for prague devnet4 * change the requests root from trie root to flat root and update examples and spcs * convert requests to flat type across util,block and vm * bundle execution requests separately from execution payload * t8ntool: update to devnet-4 interface support * update devnet-4 to EIP PRs 8924, 8394 * t8ntool hotfix to fix state tests * refactor cl requests to the new simplified version * remove requests from the block and modify associated code paths * remove storing and retriving of requests from blockchain * modify the deposit, withdrawal and consolidation requests accumulation for buildblock and runblock and corresponding requestsroot calcs * modfiy the 7002 eip spec along with the new contract and debug and fix the test including fixing a logs bloom bug in the generate fields block generation * modify code to correctly patch generated requests on getpayload/build/pending block * fix the newpayload engine codeflow to validate the cl requests * remove the requests from eth rpc and blockfetcher p2p * modify debug and fix 6110 deposit spec test * update the vm 7685 spec and add todos for later consideration * fix t8ntool rq output * vm: fix 6110 requests * update request to just store bytes and expose getters for data and type and fix the 6110 and 7685 spec * repo: rename requestsRoot -> requestsHash * vm: fix import (fix docker build) * client: correctly return request data (not including type) * fix the ingress, generation and propagation of execution requests/requestsroot data from the engine api and debug and fix the newpayloadv4 spec * Update 6110 example * Use sha256 constant for default * Fix asserts * Add sha256 empty string constant * Update block REAME examples * Reuse already computed hash * Fix buildBlock tests * Fix vm api tests * Fix client tests * Fix tests * packages: add requests hash to genesis block (#3771) * packages: add requests hash to genesis block. * Update packages/util/src/constants.ts Co-authored-by: Jochem Brouwer <[email protected]> * Update packages/util/src/constants.ts Co-authored-by: Jochem Brouwer <[email protected]> * packages: integrate suggestions. * Update packages/util/src/constants.ts --------- Co-authored-by: Jochem Brouwer <[email protected]> * util: correctly report empty rq hash * blockchain/util: remove sha256_empty_rh from exported util constants * Remove requests from being passed in as blockData * Remove old tests that do not conform to new devnet4 specs * Remove old test that does not conform to new devnet4 specs * make linter happy * block: make tsc happy * block: remove obsolete examples * util: make tsc happy * vm: make linter and tsc happy * blockchain: make linter happy * vm: fix example * make cspell happy * client/util/vm: simplify CLRequest --------- Co-authored-by: Jochem Brouwer <[email protected]> Co-authored-by: Amir <[email protected]> Co-authored-by: spencer <[email protected]> Co-authored-by: acolytec3 <[email protected]>
1 parent 987a855 commit b37a8d9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+567
-1347
lines changed

config/cspell-ts.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
}
1313
],
1414
"words": [
15+
"EEST",
1516
"paulmillr",
1617
"t8ntool",
1718
"!Json",

packages/block/CHANGELOG.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {
2626
type CLRequest,
2727
type CLRequestType,
2828
} from '@ethereumjs/util'
29+
import { keccak256 } from 'ethereum-cryptography/keccak.js'
2930

3031
const main = async () => {
3132
const common = new Common({
@@ -42,7 +43,7 @@ const main = async () => {
4243
}
4344
const request = DepositRequest.fromRequestData(depositRequestData) as CLRequest<CLRequestType>
4445
const requests = [request]
45-
const requestsRoot = await Block.genRequestsTrieRoot(requests)
46+
const requestsRoot = await Block.genRequestsRoot(requests, keccak256)
4647

4748
const block = Block.fromBlockData(
4849
{
@@ -77,6 +78,7 @@ import {
7778
type CLRequest,
7879
type CLRequestType,
7980
} from '@ethereumjs/util'
81+
import { keccak256 } from 'ethereum-cryptography/keccak.js'
8082

8183
const main = async () => {
8284
const common = new Common({
@@ -93,7 +95,7 @@ const main = async () => {
9395
withdrawalRequestData,
9496
) as CLRequest<CLRequestType>
9597
const requests = [request]
96-
const requestsRoot = await Block.genRequestsTrieRoot(requests)
98+
const requestsRoot = await Block.genRequestsRoot(requests, keccak256)
9799

98100
const block = Block.fromBlockData(
99101
{
@@ -130,6 +132,7 @@ import {
130132
type CLRequest,
131133
type CLRequestType,
132134
} from '@ethereumjs/util'
135+
import { keccak256 } from 'ethereum-cryptography/keccak.js'
133136

134137
const main = async () => {
135138
const common = new Common({
@@ -146,7 +149,7 @@ const main = async () => {
146149
consolidationRequestData,
147150
) as CLRequest<CLRequestType>
148151
const requests = [request]
149-
const requestsRoot = await Block.genRequestsTrieRoot(requests)
152+
const requestsRoot = await Block.genRequestsRoot(requests, keccak256)
150153

151154
const block = Block.fromBlockData(
152155
{

packages/block/README.md

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -245,15 +245,16 @@ Starting with v5.3.0 this library supports requests to the consensus layer which
245245
```ts
246246
// ./examples/6110Requests.ts
247247

248-
import { createBlock, genRequestsTrieRoot } from '@ethereumjs/block'
248+
import { createBlock, genRequestsRoot } from '@ethereumjs/block'
249249
import { Common, Hardfork, Mainnet } from '@ethereumjs/common'
250250
import {
251251
type CLRequest,
252-
type CLRequestType,
253-
bytesToBigInt,
254-
createDepositRequest,
252+
CLRequestType,
253+
bytesToHex,
254+
createCLRequest,
255255
randomBytes,
256256
} from '@ethereumjs/util'
257+
import { sha256 } from 'ethereum-cryptography/sha256.js'
257258

258259
const main = async () => {
259260
const common = new Common({
@@ -264,26 +265,29 @@ const main = async () => {
264265
const depositRequestData = {
265266
pubkey: randomBytes(48),
266267
withdrawalCredentials: randomBytes(32),
267-
amount: bytesToBigInt(randomBytes(8)),
268+
amount: randomBytes(8),
268269
signature: randomBytes(96),
269-
index: bytesToBigInt(randomBytes(8)),
270+
index: randomBytes(8),
270271
}
271-
const request = createDepositRequest(depositRequestData) as CLRequest<CLRequestType>
272+
// flatten request bytes as per EIP-7685
273+
const depositRequestBytes = new Uint8Array(
274+
Object.values(depositRequestData)
275+
.map((arr) => Array.from(arr)) // Convert Uint8Arrays to regular arrays
276+
.reduce((acc, curr) => acc.concat(curr), []), // Concatenate arrays
277+
)
278+
const request = createCLRequest(
279+
new Uint8Array([CLRequestType.Deposit, ...depositRequestBytes]),
280+
) as CLRequest<CLRequestType.Deposit>
272281
const requests = [request]
273-
const requestsRoot = await genRequestsTrieRoot(requests)
282+
const requestsRoot = genRequestsRoot(requests, sha256)
274283

275284
const block = createBlock(
276285
{
277-
requests,
278-
header: { requestsRoot },
286+
header: { requestsHash: requestsRoot },
279287
},
280288
{ common },
281289
)
282-
console.log(
283-
`Instantiated block with ${
284-
block.requests?.length
285-
} deposit request, requestTrieValid=${await block.requestsTrieIsValid()}`,
286-
)
290+
console.log(`Instantiated block ${block}, requestsHash=${bytesToHex(block.header.requestsHash!)}`)
287291
}
288292

289293
void main()
@@ -298,7 +302,7 @@ Have a look at the EIP for some guidance on how to use and fill in the various d
298302
```ts
299303
// ./examples/7002Requests.ts
300304

301-
import { createBlock, genRequestsTrieRoot } from '@ethereumjs/block'
305+
import { createBlock, genRequestsRoot } from '@ethereumjs/block'
302306
import { Common, Hardfork, Mainnet } from '@ethereumjs/common'
303307
import {
304308
type CLRequest,
@@ -307,6 +311,7 @@ import {
307311
createWithdrawalRequest,
308312
randomBytes,
309313
} from '@ethereumjs/util'
314+
import { sha256 } from 'ethereum-cryptography/keccak.js'
310315

311316
const main = async () => {
312317
const common = new Common({
@@ -321,7 +326,7 @@ const main = async () => {
321326
}
322327
const request = createWithdrawalRequest(withdrawalRequestData) as CLRequest<CLRequestType>
323328
const requests = [request]
324-
const requestsRoot = await genRequestsTrieRoot(requests)
329+
const requestsRoot = genRequestsRoot(requests, sha256)
325330

326331
const block = createBlock(
327332
{
@@ -349,14 +354,15 @@ Have a look at the EIP for some guidance on how to use and fill in the various w
349354
```ts
350355
// ./examples/7251Requests.ts
351356

352-
import { createBlock, genRequestsTrieRoot } from '@ethereumjs/block'
357+
import { createBlock, genRequestsRoot } from '@ethereumjs/block'
353358
import { Common, Hardfork, Mainnet } from '@ethereumjs/common'
354359
import {
355360
type CLRequest,
356361
type CLRequestType,
357362
createConsolidationRequest,
358363
randomBytes,
359364
} from '@ethereumjs/util'
365+
import { sha256 } from 'ethereum-cryptography/keccak.js'
360366

361367
const main = async () => {
362368
const common = new Common({
@@ -371,7 +377,7 @@ const main = async () => {
371377
}
372378
const request = createConsolidationRequest(consolidationRequestData) as CLRequest<CLRequestType>
373379
const requests = [request]
374-
const requestsRoot = await genRequestsTrieRoot(requests)
380+
const requestsRoot = genRequestsRoot(requests, sha256)
375381

376382
const block = createBlock(
377383
{

packages/block/examples/6110Requests.ts

Lines changed: 0 additions & 42 deletions
This file was deleted.

packages/block/examples/7002Requests.ts

Lines changed: 0 additions & 40 deletions
This file was deleted.

packages/block/examples/7251Requests.ts

Lines changed: 0 additions & 39 deletions
This file was deleted.

0 commit comments

Comments
 (0)