Skip to content

fix(blocksync): prevent maxPeerHeight poisoning by peers with inflated base - #40

Merged
fridrik01 merged 2 commits into
bera-v1.xfrom
fix-blocksync-maxpeerheight-poisoning
Apr 21, 2026
Merged

fridrik01 merged 2 commits into
bera-v1.xfrom
fix-blocksync-maxpeerheight-poisoning

Conversation

@fridrik01

@fridrik01 fridrik01 commented Apr 21, 2026 •

Copy link
Copy Markdown
Collaborator

Each peer advertises a (base, height) range in StatusResponse declaring the contiguous blocks it can serve. base is the oldest block it still has (moves up if the peer prunes), height is the newest. A malicious peer can advertise something like base=100_000_000, height=100_000_100 to poison maxPeerHeight with 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:

  • updateMaxPeerHeight now excludes peers whose base > pool.height from the maxPeerHeight computation.

Tests:

  • TestBlockPoolIgnoresPeersWithInflatedBase: verifies a peer with base > pool.height does not raise maxPeerHeight.
  • TestBlockPoolTimeout: forced uniform base=start so all peers contribute to maxPeerHeight. The staggered bases from makePeers combined with the new gating would otherwise starve the request pipeline since this test never advances pool.height.

@fridrik01 fridrik01 self-assigned this Apr 21, 2026
@fridrik01
fridrik01 requested a review from calbera April 21, 2026 15:09
@fridrik01
fridrik01 force-pushed the fix-blocksync-maxpeerheight-poisoning branch from 09a1be3 to 08ce249 Compare April 21, 2026 15:49
@fridrik01
fridrik01 marked this pull request as ready for review April 21, 2026 15:56
@fridrik01
fridrik01 merged commit c234299 into bera-v1.x Apr 21, 2026
16 of 17 checks passed
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).
@unknownfeature

unknownfeature commented Apr 29, 2026 •

Copy link
Copy Markdown

@fridrik01

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 pool.height is less than base height of the first peer who joins the network. Which can be if it's state is pruned.

In this case it seems like the blocksync might exit prematurely. Since exit conditions are:

  1. Num of peers > 0
  2. pool.height > 0 (which seems to be always >=1 since 1 is genesis height)
  3. pool.maxPeerHeight == 0 which will be true is base > pool.height

Please, let me know if I'm missing something.

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.

4 participants