Repository navigation
fix(pipeline): reject non-canonical header bytes instead of logging - #26
Open
cafebedouin wants to merge 2 commits into
Open
cafebedouin wants to merge 2 commits into
cafebedouin wants to merge 2 commits into
Conversation
…section ids bind_and_store_sections required only that a body hash to its delivered id and that its header_id be a header the node holds; it never consulted the header's roots. A body bound to its own label was therefore stored for any known header, one row per distinct digest, under ids sync never queries — fork-bound rows at height 0 that pruning cannot reach, and for best-chain headers an unconditional height-index insert that let a poison body take the honest body's index row. Load the header (best chain or stored fork) and require (type_id, delivered_id) ∈ section_ids(header): the JVM's bsCorrespondsToHeader membership test. Test: body_under_its_own_id_for_a_known_header_is_dropped_unless_declared. Contracts: facts/receive-path.md sections row, facts/sync.md request gate.
The header's id is recomputed from its parsed fields but the bytes stored and served are the raw wire bytes. A header with trailing bytes parsed to the same id, the round-trip mismatch was tracing::error! only, and the raw bytes were kept, served to peers by the local-serve hook, and served by the API — a label not recomputed from the bytes it labels, the one sink facts/receive-path.md's invariant did not yet cover. The mismatch now rejects the header with a PENALTY warn before PoW, and a header that cannot be re-serialized is rejected too. Test: non_canonical_header_bytes_are_rejected (block 2666's canonical bytes plus four trailing bytes: same id, not received, not buffered; canonical control accepted). Contract: facts/receive-path.md header row.
This was referenced Sep 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Branch:
ergo-logic/header-roundtrip-reject, stacked on #25 (declared section ids) (its commit isincluded; merge that one first and this PR shows only its own commit — the two touch the same test
module and the same contract table). Files:
src/pipeline.rs,facts/receive-path.md.Why
Headers are the one receive sink where the label (the id) is recomputed from the parsed fields while
the bytes stored and served are the raw wire bytes. A header with trailing bytes parses to the same
id (
same_id=truein the round-trip witness), the mismatch atprocess_headersistracing::error!only, and
data.to_vec()is whatput_headerkeeps and what the p2p serve hook and the API hand out.facts/receive-path.md's invariant is met for sections (section_id_from_body::finishrejectstrailing bytes) and not for headers.
What
The round-trip mismatch now rejects the header with a
PENALTYwarn (or a debug line for localingest), before PoW, and a header that cannot be re-serialized is rejected too.
Tests
New:
non_canonical_header_bytes_are_rejected(block 2666's canonical bytes plus four trailingbytes: same id, not reported received, not buffered; the canonical bytes are accepted as the
control). Run:
cargo test -p ergo-node-ruston the stacked branch: 83 passed (the two new tests included), 0 failed, 3 ignored (pre-existing ignores).Does this penalize JVM peers?
No. The JVM never emits non-canonical header bytes: a header's
bytesare its own re-serialization(ergo v6.0.5,
ergo-core/src/main/scala/org/ergoplatform/core/BytesSerializable.scala:12), its id is the hash of those bytes(
ergo-core/src/main/scala/org/ergoplatform/modifiers/history/header/Header.scala:62), the deserializer does not check for leftover input(
avldb/src/main/scala/org/ergoplatform/serialization/ErgoSerializer.scala:27-30), the received-modifier check compares thedeclared id with that re-serialized hash (
src/main/scala/org/ergoplatform/network/ErgoNodeViewSynchronizer.scala:819), and thehistory store writes the re-serialization (
src/main/scala/org/ergoplatform/nodeView/history/storage/HistoryStorage.scala:135). So theJVM silently canonicalizes and never penalizes; every header it sends is canonical, and every header
this PR rejects would have been canonicalized by a JVM node. Rejecting is stricter than the reference.
The alternative that matches the JVM exactly is to keep the header and store
reserializedinsteadof
data(one line at the store push) — your call; the invariant infacts/receive-path.mdis meteither way, and the test here checks rejection.
Note for the maintainer
If a future header version legitimately carries
unparsed_bytes, the round trip must preserve themor this check will reject those headers.
Header::scorex_serializealready writesunparsed_bytesback out, but no test in the tree exercises a header with non-empty
unparsed_bytes(every fixtureuses
Box::new([]), andchain/src/cache.rsnotes it is empty in every version accepted today), sothe preservation is by construction, not yet by test. A fixture with non-empty
unparsed_bytesinheader_scorex_bytes_roundtripwould close that.Changelog entry
Not in the patch (your repo instructions reserve
CHANGELOG.mdfor the main session, and four PRsinserting an Unreleased block at the same spot conflict with each other). Text, if useful:
🤖 Generated with Claude Code