Skip to content

Tolerate individual malformed ENRs in discv5#10941

Open
MysticRyuujin wants to merge 2 commits into
Consensys:masterfrom
MysticRyuujin:discv5-tolerate-malformed-enrs
Open

Tolerate individual malformed ENRs in discv5#10941
MysticRyuujin wants to merge 2 commits into
Consensys:masterfrom
MysticRyuujin:discv5-tolerate-malformed-enrs

Conversation

@MysticRyuujin

@MysticRyuujin MysticRyuujin commented Jul 6, 2026

Copy link
Copy Markdown

Changes

Two related robustness fixes so that a single malformed ENR cannot disrupt discv5 beyond that one record:

  • NodeRecordConverter.convertToDiscoveryPeer: address resolution (getTcpAddress / getQuicAddress) can throw on a record with an out-of-range port. Because the conversion is consumed via flatMap (streamKnownPeers / convertToDiscoveryPeers), one throwing record aborted the entire peer-conversion batch. It now catches the failure per record and skips only that record.
  • DiscV5Service constructor: bootnodes were decoded with .map(NodeRecordFactory.DEFAULT::fromEnr), so one un-decodable --p2p-discovery-bootnodes entry threw and prevented node startup. Bootnodes are now parsed individually, skipping a bad entry.

Found during a cross-client discv5 audit.

Testing

Unit tests added to NodeRecordConverterTest (out-of-range port → skipped) and DiscV5ServiceTest (malformed bootnode → startup does not fail); both fail before the change and pass after. spotlessApply + :networking:p2p:test run clean.


Note

Low Risk
Localized defensive error handling in discovery; no auth, data, or protocol semantics changes beyond ignoring invalid ENRs.

Overview
Hardens discv5 so one bad ENR cannot take down startup or an entire peer batch.

Bootnodes: --p2p-discovery-bootnodes entries are decoded via a new parseBootnode helper that catches decode failures, logs a warning, and drops only that entry; valid bootnodes still load.

Peer conversion: NodeRecordConverter.convertToDiscoveryPeer wraps TCP/QUIC address resolution in a try/catch so records with unusable addresses (e.g. out-of-range ports) return empty instead of aborting streamKnownPeers / convertToDiscoveryPeers flatMap batches.

Unit tests cover malformed bootnode startup and out-of-range TCP port skipping.

Reviewed by Cursor Bugbot for commit 6c19079. Bugbot is set up for automated code reviews on this repo. Configure here.

An out-of-range port in a peer ENR made getTcpAddress throw, and because
convertToDiscoveryPeer is consumed via flatMap the exception aborted the
whole peer-conversion batch. Catch it per record and skip only that record.
One un-decodable --p2p-discovery-bootnodes entry threw from the DiscV5Service
constructor, preventing node startup. Parse each bootnode independently and
skip the bad one.
@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@MysticRyuujin

Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

github-actions Bot added a commit that referenced this pull request Jul 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant