Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
218 changes: 0 additions & 218 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions packages/portalnetwork/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@
"@types/ws": "^7.4.7",
"@vitest/coverage-v8": "^3.0.2",
"@vitest/ui": "^3.0.2",
"eslint": "^8.6.0",
"js-yaml": "^4.1.0",
"tslib": "^2.3.1",
"typedoc": "^0.28.0",
Expand Down Expand Up @@ -104,4 +103,4 @@
"optional": true
}
}
}
}
30 changes: 18 additions & 12 deletions packages/portalnetwork/src/networks/history/history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,20 @@
import { bytesToHex, bytesToInt, concatBytes, equalsBytes, hexToBytes } from '@ethereumjs/util'
import debug from 'debug'

import type {
BaseNetworkConfig,
ContentLookupResponse,
EphemeralHeaderKeyValues,
FindContentMessage,
INodeAddress,
} from '../../index.js'
import {
type BaseNetworkConfig,
BasicRadius,
BiMap,
ClientInfoAndCapabilities,
type ContentLookupResponse,
ContentMessageType,
type EphemeralHeaderKeyValues,
type FindContentMessage,
FoundContent,
HistoricalSummariesBlockProof,
HistoricalSummariesBlockProofCapella,
HistoricalSummariesBlockProofDeneb,
HistoryRadius,
type INodeAddress,
MAX_UDP_PACKET_SIZE,
MessageCodes,
PortalWireMessageType,
Expand All @@ -39,6 +38,7 @@
AccumulatorProofType,
BlockHeaderWithProof,
BlockNumberKey,
CANCUN_BLOCK,
EphemeralHeaderPayload,
HistoricalRootsBlockProof,
HistoryNetworkContentType,
Expand Down Expand Up @@ -187,7 +187,7 @@
}
const proof = headerProof.proof

if (header.number < MERGE_BLOCK) {
if (header.number <= MERGE_BLOCK) {
let deserializedProof: Uint8Array[]
try {
deserializedProof = AccumulatorProofType.deserialize(proof)
Expand Down Expand Up @@ -231,17 +231,23 @@
throw new Error(msg)
}
if (!validated) {
throw new Error('Unable to validate proof for post-merge header')

Check failure on line 234 in packages/portalnetwork/src/networks/history/history.ts

View workflow job for this annotation

GitHub Actions / test-unit-portalnetwork (22)

test/networks/history/historyNetwork.spec.ts > Header Tests > should validate and store a post merge header proof

Error: Unable to validate proof for post-merge header ❯ HistoryNetwork.validateHeader src/networks/history/history.ts:234:15 ❯ HistoryNetwork.store src/networks/history/history.ts:555:22 ❯ test/networks/history/historyNetwork.spec.ts:159:19

Check failure on line 234 in packages/portalnetwork/src/networks/history/history.ts

View workflow job for this annotation

GitHub Actions / test-unit-portalnetwork (22)

Unhandled error

Error: Unable to validate proof for post-merge header ❯ HistoryNetwork.validateHeader src/networks/history/history.ts:234:15 ❯ test/networks/history/historyNetwork.spec.ts:152:27 ❯ ../../node_modules/@vitest/runner/dist/index.js:103:11 ❯ ../../node_modules/@vitest/runner/dist/index.js:596:26 ❯ ../../node_modules/@vitest/runner/dist/index.js:879:20 ❯ runWithTimeout ../../node_modules/@vitest/runner/dist/index.js:852:10 ❯ runTest ../../node_modules/@vitest/runner/dist/index.js:1360:12 ❯ runSuite ../../node_modules/@vitest/runner/dist/index.js:1507:8 ❯ runSuite ../../node_modules/@vitest/runner/dist/index.js:1507:8 This error originated in "test/networks/history/historyNetwork.spec.ts" test file. It doesn't mean the error was thrown inside the file itself, but while it was running. The latest test that might've caused the error is "should verify a pre-merge header proof". It might mean one of the following: - The error was thrown, while Vitest was running this test. - If the error occurred after the test had been completed, this was the last documented test before it was thrown.
}
} else {
// TODO: Check proof slot to ensure header is from previous sync period and handle ephemeral headers separately

let deserializedProof: ReturnType<typeof HistoricalSummariesBlockProof.deserialize>
let deserializedProof: ReturnType<
| typeof HistoricalSummariesBlockProofCapella.deserialize
| typeof HistoricalSummariesBlockProofDeneb.deserialize
>
try {
deserializedProof = HistoricalSummariesBlockProof.deserialize(proof)
if (header.number < CANCUN_BLOCK) {
deserializedProof = HistoricalSummariesBlockProofCapella.deserialize(proof)
} else {
deserializedProof = HistoricalSummariesBlockProofDeneb.deserialize(proof)
}
} catch (err: any) {
this.logger(`invalid proof for block ${bytesToHex(header.hash())}`)
throw new Error(`invalid proof for block ${bytesToHex(header.hash())}`)

Check failure on line 250 in packages/portalnetwork/src/networks/history/history.ts

View workflow job for this annotation

GitHub Actions / test-integration-portalnetwork (22)

test/integration/postCapellaHeaderProof.spec.ts > Block Bridge Data Test > should store and retrieve block header data

Error: invalid proof for block 0x1e98ea9bdf6e44eaed730041682e7db748812d5baef84a38435c8ad5f6c5d1e2 ❯ HistoryNetwork.validateHeader src/networks/history/history.ts:250:15 ❯ HistoryNetwork.store src/networks/history/history.ts:555:22 ❯ test/integration/postCapellaHeaderProof.spec.ts:111:20
}
const beacon = this.portal.network()['0x500c']
if (beacon !== undefined && beacon.lightClient?.status === RunStatusCode.started) {
Expand Down
25 changes: 17 additions & 8 deletions packages/portalnetwork/src/networks/history/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const MAX_ENCODED_UNCLES_LENGTH = 131072 // MAX_HEADER_LENGTH * 2 ** 4
export const MAX_HEADER_PROOF_LENGTH = 1024
export const MERGE_BLOCK = 15537393n
export const SHANGHAI_BLOCK = 17034871n
export const CANCUN_BLOCK = 19426587n

export const CAPELLA_ERA = 758 // The era/period in which the Capella fork happened on CL

Expand Down Expand Up @@ -190,22 +191,30 @@ export const BlockNumberKey = new ContainerType({
/** Post-merge pre-Capella block header proof types */
export const SlotType = new UintBigintType(8)
export const BeaconBlockProofHistoricalRoots = new VectorCompositeType(Bytes32Type, 14)
export const PostMergeExecutionBlockProof = new VectorCompositeType(Bytes32Type, 11)

export const ExecutionBlockProofBellatrix = new VectorCompositeType(Bytes32Type, 11)
export const HistoricalRootsBlockProof = new ContainerType({
historicalRootsProof: BeaconBlockProofHistoricalRoots,
beaconBlockProof: BeaconBlockProofHistoricalRoots,
beaconBlockRoot: Bytes32Type,
beaconBlockProof: PostMergeExecutionBlockProof,
executionBlockProof: ExecutionBlockProofBellatrix,
slot: SlotType,
})

/** Post-Capella block header proof types */
export const PostCapellaExecutionBlockProof = new ListCompositeType(Bytes32Type, 12)
export const BeaconBlockProofHistoricalSummaries = new VectorCompositeType(Bytes32Type, 13)
export const HistoricalSummariesBlockProof = new ContainerType({
historicalSummariesProof: BeaconBlockProofHistoricalSummaries,

export const HistoricalSummariesBlockProofCapella = new ContainerType({
beaconBlockProof: BeaconBlockProofHistoricalSummaries,
beaconBlockRoot: Bytes32Type,
executionBlockProof: ExecutionBlockProofBellatrix,
slot: SlotType,
})

/** Post-Deneb block header proof types */
export const PostDenebExecutionBlockProof = new VectorCompositeType(Bytes32Type, 12)
export const HistoricalSummariesBlockProofDeneb = new ContainerType({
beaconBlockProof: BeaconBlockProofHistoricalSummaries,
beaconBlockRoot: Bytes32Type,
beaconBlockProof: PostCapellaExecutionBlockProof,
executionBlockProof: PostDenebExecutionBlockProof,
slot: SlotType,
})

Expand Down
Loading
Loading