Skip to content

fix(blocksync): validate blocksync response sender and signature count (backport #5860) - #5863

Merged
mattac21 merged 5 commits into
v0.38.xfrom
mergify/bp/v0.38.x/pr-5860
May 12, 2026
Merged

mattac21 merged 5 commits into
v0.38.xfrom
mergify/bp/v0.38.x/pr-5860

Conversation

@mergify

@mergify mergify Bot commented May 11, 2026

Copy link
Copy Markdown
Contributor

Adds additional validation to blocksync, ensuring before response unmarshalling that we have made a BlockRequest to the peer that is sending us a BlockResponse recently, and also that the response contains a valid amount of commit signatures (not > MaxVoteCount). To do this preunmarshal validation, we have added a MsgBytesFilter interface that Reactors can implement. Currently only BLOCKSYNC does. The FilterMsgBytes function is called for both comet P2P and libp2p implementations, inside of the onReceive function when setting up a peer for comet p2p, and inside of handleStream for libp2p, just before unmarshalling the message in both.

PR checklist

  • Tests written/updated
  • Changelog entry added in CHANGELOG.md
  • Updated relevant documentation (docs/ or spec/) and code comments

This is an automatic backport of pull request #5860 done by [Mergify](https://mergify.com).

#5860)

---

Adds additional validation to blocksync, ensuring _before response
unmarshalling_ that we have made a `BlockRequest` to the peer that is
sending us a `BlockResponse` recently, and also that the response
contains a valid amount of commit signatures (not > MaxVoteCount). To do
this preunmarshal validation, we have added a `MsgBytesFilter` interface
that `Reactors` can implement. Currently only `BLOCKSYNC` does. The
`FilterMsgBytes` function is called for both comet P2P and libp2p
implementations, inside of the `onReceive` function when setting up a
peer for comet p2p, and inside of `handleStream` for libp2p, just before
unmarshalling the message in both.

#### PR checklist

- [x] Tests written/updated
- [x] Changelog entry added in `CHANGELOG.md`
- [ ] Updated relevant documentation (`docs/` or `spec/`) and code
comments

(cherry picked from commit 4590e7a)

# Conflicts:
#	blocksync/reactor.go
#	lp2p/stream_test.go
#	lp2p/switch.go
#	lp2p/switch_test.go
@mergify mergify Bot added the conflicts label May 11, 2026
@mergify

mergify Bot commented May 11, 2026

Copy link
Copy Markdown
Contributor Author

Cherry-pick of 4590e7a has failed:

On branch mergify/bp/v0.38.x/pr-5860
Your branch is up to date with 'origin/v0.38.x'.

You are currently cherry-picking commit 4590e7ac.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Changes to be committed:
	modified:   CHANGELOG.md
	modified:   blocksync/pool.go
	modified:   blocksync/pool_test.go
	modified:   blocksync/reactor_test.go
	modified:   p2p/base_reactor.go
	modified:   p2p/peer.go
	modified:   p2p/switch_test.go
	new file:   proto/tendermint/blocksync/nosig.go
	new file:   proto/tendermint/blocksync/stub.pb.go
	new file:   proto/tendermint/blocksync/stub.proto

Unmerged paths:
  (use "git add/rm <file>..." as appropriate to mark resolution)
	both modified:   blocksync/reactor.go
	deleted by us:   lp2p/stream_test.go
	deleted by us:   lp2p/switch.go
	deleted by us:   lp2p/switch_test.go

To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally

@greptile-apps

greptile-apps Bot commented May 11, 2026

Copy link
Copy Markdown
Contributor

PR author is not in the allowed authors list.

@mattac21
mattac21 enabled auto-merge May 12, 2026 16:57
@mattac21
mattac21 merged commit 35ffa96 into v0.38.x May 12, 2026
20 checks passed
@mattac21
mattac21 deleted the mergify/bp/v0.38.x/pr-5860 branch May 12, 2026 17:15
tqin7 added a commit to dydxprotocol/cometbft that referenced this pull request Oct 28, 2026
…t (backport cometbft#5860) (cometbft#5863) (#66)

---

Adds additional validation to blocksync, ensuring _before response
unmarshalling_ that we have made a `BlockRequest` to the peer that is
sending us a `BlockResponse` recently, and also that the response
contains a valid amount of commit signatures (not > MaxVoteCount). To do
this preunmarshal validation, we have added a `MsgBytesFilter` interface
that `Reactors` can implement. Currently only `BLOCKSYNC` does. The
`FilterMsgBytes` function is called for both comet P2P and libp2p
implementations, inside of the `onReceive` function when setting up a
peer for comet p2p, and inside of `handleStream` for libp2p, just before
unmarshalling the message in both.

- [x] Tests written/updated
- [x] Changelog entry added in `CHANGELOG.md`
- [ ] Updated relevant documentation (`docs/` or `spec/`) and code
comments
<hr>This is an automatic backport of pull request cometbft#5860 done by
[Mergify](https://mergify.com).

Co-authored-by: mattac21 <[email protected]>
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