Repository navigation
fix(blocksync): prevent maxPeerHeight poisoning by peers with inflated base - #40
Merged
Merged
Conversation
fridrik01
force-pushed
the
fix-blocksync-maxpeerheight-poisoning
branch
from
April 21, 2026 15:49
09a1be3 to
08ce249
Compare
fridrik01
marked this pull request as ready for review
April 21, 2026 15:56
calbera
approved these changes
Apr 21, 2026
reecepbcups
approved these changes
Apr 21, 2026
This was referenced Apr 22, 2026
mergify Bot
added a commit
to cometbft/cometbft
that referenced
this pull request
Apr 22, 2026
Cherry-picks [berachain#40](berachain#40) (@fridrik01) into upstream blocksync/. Fixes a deadlock where a malicious peer can poison maxPeerHeight with an inflated base/height that no peer can serve, stalling IsCaughtUp forever. Taken from commit 1 of the PR rather than the final state, which keeps the base > height ban and PopRequest recompute that commit 2 stripped back out.<hr>This is an automatic backport of pull request #5803 done by [Mergify](https://mergify.com). Co-authored-by: Vlad J <[email protected]>
vladjdk
added a commit
to cometbft/cometbft
that referenced
this pull request
Apr 22, 2026
Cherry-picks [berachain#40](berachain#40) (@fridrik01) into upstream blocksync/. Fixes a deadlock where a malicious peer can poison maxPeerHeight with an inflated base/height that no peer can serve, stalling IsCaughtUp forever. Taken from commit 1 of the PR rather than the final state, which keeps the base > height ban and PopRequest recompute that commit 2 stripped back out.<hr>This is an automatic backport of pull request #5803 done by [Mergify](https://mergify.com).
|
Hey! We are having a discussion here cometbft#5801. Where your change is also being discussed as a proposed solution. I looked at it, and I see an issue that might occur if initial In this case it seems like the blocksync might exit prematurely. Since exit conditions are:
Please, let me know if I'm missing something. |
This was referenced Aug 7, 2026
Closed
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.
Each peer advertises a
(base, height)range inStatusResponsedeclaring the contiguous blocks it can serve.baseis the oldest block it still has (moves up if the peer prunes),heightis the newest. A malicious peer can advertise something likebase=100_000_000, height=100_000_100to poisonmaxPeerHeightwith a value no peer can serve, which can deadlock blocksync. The attack window opens on any validator restart, not just on genesis sync.This is a minimal fix while we wait for the upstream patch.
Changes:
updateMaxPeerHeightnow excludes peers whosebase > pool.heightfrom themaxPeerHeightcomputation.Tests:
TestBlockPoolIgnoresPeersWithInflatedBase: verifies a peer withbase > pool.heightdoes not raisemaxPeerHeight.TestBlockPoolTimeout: forced uniformbase=startso all peers contribute tomaxPeerHeight. The staggered bases frommakePeerscombined with the new gating would otherwise starve the request pipeline since this test never advancespool.height.