Skip to content

Commit

Permalink
pectra devnet4: implement pectra devnet4 spec (#3706)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
5 people authored Oct 31, 2024
1 parent 987a855 commit b37a8d9
Show file tree
Hide file tree
Showing 56 changed files with 567 additions and 1,347 deletions.
1 change: 1 addition & 0 deletions config/cspell-ts.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
}
],
"words": [
"EEST",
"paulmillr",
"t8ntool",
"!Json",
Expand Down
9 changes: 6 additions & 3 deletions packages/block/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
type CLRequest,
type CLRequestType,
} from '@ethereumjs/util'
import { keccak256 } from 'ethereum-cryptography/keccak.js'

const main = async () => {
const common = new Common({
Expand All @@ -42,7 +43,7 @@ const main = async () => {
}
const request = DepositRequest.fromRequestData(depositRequestData) as CLRequest<CLRequestType>
const requests = [request]
const requestsRoot = await Block.genRequestsTrieRoot(requests)
const requestsRoot = await Block.genRequestsRoot(requests, keccak256)

const block = Block.fromBlockData(
{
Expand Down Expand Up @@ -77,6 +78,7 @@ import {
type CLRequest,
type CLRequestType,
} from '@ethereumjs/util'
import { keccak256 } from 'ethereum-cryptography/keccak.js'

const main = async () => {
const common = new Common({
Expand All @@ -93,7 +95,7 @@ const main = async () => {
withdrawalRequestData,
) as CLRequest<CLRequestType>
const requests = [request]
const requestsRoot = await Block.genRequestsTrieRoot(requests)
const requestsRoot = await Block.genRequestsRoot(requests, keccak256)

const block = Block.fromBlockData(
{
Expand Down Expand Up @@ -130,6 +132,7 @@ import {
type CLRequest,
type CLRequestType,
} from '@ethereumjs/util'
import { keccak256 } from 'ethereum-cryptography/keccak.js'

const main = async () => {
const common = new Common({
Expand All @@ -146,7 +149,7 @@ const main = async () => {
consolidationRequestData,
) as CLRequest<CLRequestType>
const requests = [request]
const requestsRoot = await Block.genRequestsTrieRoot(requests)
const requestsRoot = await Block.genRequestsRoot(requests, keccak256)

const block = Block.fromBlockData(
{
Expand Down
44 changes: 25 additions & 19 deletions packages/block/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,15 +245,16 @@ Starting with v5.3.0 this library supports requests to the consensus layer which
```ts
// ./examples/6110Requests.ts

import { createBlock, genRequestsTrieRoot } from '@ethereumjs/block'
import { createBlock, genRequestsRoot } from '@ethereumjs/block'
import { Common, Hardfork, Mainnet } from '@ethereumjs/common'
import {
type CLRequest,
type CLRequestType,
bytesToBigInt,
createDepositRequest,
CLRequestType,
bytesToHex,
createCLRequest,
randomBytes,
} from '@ethereumjs/util'
import { sha256 } from 'ethereum-cryptography/sha256.js'

const main = async () => {
const common = new Common({
Expand All @@ -264,26 +265,29 @@ const main = async () => {
const depositRequestData = {
pubkey: randomBytes(48),
withdrawalCredentials: randomBytes(32),
amount: bytesToBigInt(randomBytes(8)),
amount: randomBytes(8),
signature: randomBytes(96),
index: bytesToBigInt(randomBytes(8)),
index: randomBytes(8),
}
const request = createDepositRequest(depositRequestData) as CLRequest<CLRequestType>
// flatten request bytes as per EIP-7685
const depositRequestBytes = new Uint8Array(
Object.values(depositRequestData)
.map((arr) => Array.from(arr)) // Convert Uint8Arrays to regular arrays
.reduce((acc, curr) => acc.concat(curr), []), // Concatenate arrays
)
const request = createCLRequest(
new Uint8Array([CLRequestType.Deposit, ...depositRequestBytes]),
) as CLRequest<CLRequestType.Deposit>
const requests = [request]
const requestsRoot = await genRequestsTrieRoot(requests)
const requestsRoot = genRequestsRoot(requests, sha256)

const block = createBlock(
{
requests,
header: { requestsRoot },
header: { requestsHash: requestsRoot },
},
{ common },
)
console.log(
`Instantiated block with ${
block.requests?.length
} deposit request, requestTrieValid=${await block.requestsTrieIsValid()}`,
)
console.log(`Instantiated block ${block}, requestsHash=${bytesToHex(block.header.requestsHash!)}`)
}

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

import { createBlock, genRequestsTrieRoot } from '@ethereumjs/block'
import { createBlock, genRequestsRoot } from '@ethereumjs/block'
import { Common, Hardfork, Mainnet } from '@ethereumjs/common'
import {
type CLRequest,
Expand All @@ -307,6 +311,7 @@ import {
createWithdrawalRequest,
randomBytes,
} from '@ethereumjs/util'
import { sha256 } from 'ethereum-cryptography/keccak.js'

const main = async () => {
const common = new Common({
Expand All @@ -321,7 +326,7 @@ const main = async () => {
}
const request = createWithdrawalRequest(withdrawalRequestData) as CLRequest<CLRequestType>
const requests = [request]
const requestsRoot = await genRequestsTrieRoot(requests)
const requestsRoot = genRequestsRoot(requests, sha256)

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

import { createBlock, genRequestsTrieRoot } from '@ethereumjs/block'
import { createBlock, genRequestsRoot } from '@ethereumjs/block'
import { Common, Hardfork, Mainnet } from '@ethereumjs/common'
import {
type CLRequest,
type CLRequestType,
createConsolidationRequest,
randomBytes,
} from '@ethereumjs/util'
import { sha256 } from 'ethereum-cryptography/keccak.js'

const main = async () => {
const common = new Common({
Expand All @@ -371,7 +377,7 @@ const main = async () => {
}
const request = createConsolidationRequest(consolidationRequestData) as CLRequest<CLRequestType>
const requests = [request]
const requestsRoot = await genRequestsTrieRoot(requests)
const requestsRoot = genRequestsRoot(requests, sha256)

const block = createBlock(
{
Expand Down
42 changes: 0 additions & 42 deletions packages/block/examples/6110Requests.ts

This file was deleted.

40 changes: 0 additions & 40 deletions packages/block/examples/7002Requests.ts

This file was deleted.

39 changes: 0 additions & 39 deletions packages/block/examples/7251Requests.ts

This file was deleted.

Loading

0 comments on commit b37a8d9

Please sign in to comment.