Skip to content

fix(internal/consensus/reactor.go): reject oversized proposals - #5309

Closed
arsushi wants to merge 4 commits into
cometbft:mainfrom
arsushi:main
Closed

arsushi wants to merge 4 commits into
cometbft:mainfrom
arsushi:main

Conversation

@arsushi

@arsushi arsushi commented Aug 25, 2025

Copy link
Copy Markdown
Contributor

PR checklist

  • Tests written/updated
  • Changelog entry added in .changelog (we use unclog to manage our changelog)
  • Updated relevant documentation (docs/ or spec/) and code comments

@arsushi
arsushi requested review from a team as code owners August 25, 2025 14:20
@arsushi arsushi changed the title Reject oversized proposals fix(internal/consensus/reactor.go): reject oversized proposals Aug 25, 2025
@aljo242 aljo242 added backport-to-v0.38.x Tell Mergify to backport the PR to v0.38.x backport-to-v1.x labels Aug 25, 2025
@aljo242 aljo242 self-assigned this Aug 25, 2025
}
switch msg := msg.(type) {
case *ProposalMessage:
maxBytes := conR.conS.state.ConsensusParams.Block.MaxBytes

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way we can test this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added test case in 6639886

@almkx almkx left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain the -1/+1 logic in a comment?

Comment thread internal/consensus/reactor.go Resolved
@arsushi

arsushi commented Aug 26, 2025 •

Copy link
Copy Markdown
Contributor Author

Can you explain the -1/+1 logic in a comment?

It is based on the validation in

// Validate the proposed block size, derived from its PartSetHeader
maxBytes := cs.state.ConsensusParams.Block.MaxBytes
if maxBytes == -1 {
maxBytes = int64(types.MaxBlockSizeBytes)
}
if int64(proposal.BlockID.PartSetHeader.Total) > (maxBytes-1)/int64(types.BlockPartSizeBytes)+1 {
return ErrProposalTooManyParts
}

@aljo242

aljo242 commented Aug 26, 2025

Copy link
Copy Markdown
Collaborator

@arsushi looks like we have some CI failing!

@aljo242

aljo242 commented Aug 26, 2025

Copy link
Copy Markdown
Collaborator

@arsushi can we also get a changelog entry for this?

}
proposal.Signature = p.Signature

go sendProposalAndParts(height, round, cs, targetPeer, proposal, block, block.Hash(), blockParts)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this test case is actually testing anything. This looks to me that it creates the oversized proposal, and then sends the proposal and parts to the peer (where it will be rejected), but it doesnt actually asset that the peer rejected it, it returns before anything is asserted about the peer state.

@mattac21 mattac21 closed this Sep 16, 2025
aljo242 added a commit that referenced this pull request Sep 17, 2025
---
Updates the consensus reactor to validate that a received proposal will
not contain more parts than the amount of chunks that it would take to
build a block whos size is equal to `ConsensusParams.Block.MaxBytes`.

Original PR is here #5309, but
reopened since the contributor stopped replying.

#### PR checklist

- [ ] Tests written/updated
- [ ] Changelog entry added in `.changelog` (we use
[unclog](https://github.com/informalsystems/unclog) to manage our
changelog)
- [ ] Updated relevant documentation (`docs/` or `spec/`) and code
comments

---------

Co-authored-by: arsushi <[email protected]>
Co-authored-by: Abdul Malek <[email protected]>
Co-authored-by: Matt Acciai <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: Tyler <[email protected]>
Co-authored-by: maradini77 <[email protected]>
mergify Bot added a commit that referenced this pull request Sep 17, 2025
---
Updates the consensus reactor to validate that a received proposal will
not contain more parts than the amount of chunks that it would take to
build a block whos size is equal to `ConsensusParams.Block.MaxBytes`.

Original PR is here #5309, but
reopened since the contributor stopped replying.

#### PR checklist

- [ ] Tests written/updated
- [ ] Changelog entry added in `.changelog` (we use
[unclog](https://github.com/informalsystems/unclog) to manage our
changelog)
- [ ] Updated relevant documentation (`docs/` or `spec/`) and code
comments

---------

Co-authored-by: arsushi <[email protected]>
Co-authored-by: Abdul Malek <[email protected]>
Co-authored-by: Matt Acciai <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: Tyler <[email protected]>
Co-authored-by: maradini77 <[email protected]>
(cherry picked from commit 9ff47d0)
aljo242 added a commit that referenced this pull request Sep 18, 2025
…5407)

---
Updates the consensus reactor to validate that a received proposal will
not contain more parts than the amount of chunks that it would take to
build a block whos size is equal to `ConsensusParams.Block.MaxBytes`.

Original PR is here #5309, but
reopened since the contributor stopped replying.

#### PR checklist

- [ ] Tests written/updated
- [ ] Changelog entry added in `.changelog` (we use
[unclog](https://github.com/informalsystems/unclog) to manage our
changelog)
- [ ] Updated relevant documentation (`docs/` or `spec/`) and code
comments
<hr>This is an automatic backport of pull request #5324 done by
[Mergify](https://mergify.com).

Co-authored-by: Alex | Interchain Labs <[email protected]>
Co-authored-by: arsushi <[email protected]>
Co-authored-by: Abdul Malek <[email protected]>
Co-authored-by: Matt Acciai <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: Tyler <[email protected]>
Co-authored-by: maradini77 <[email protected]>
tqin7 pushed a commit to dydxprotocol/cometbft that referenced this pull request Oct 14, 2025
…#5324) (cometbft#5407)

---
Updates the consensus reactor to validate that a received proposal will
not contain more parts than the amount of chunks that it would take to
build a block whos size is equal to `ConsensusParams.Block.MaxBytes`.

Original PR is here cometbft#5309, but
reopened since the contributor stopped replying.

#### PR checklist

- [ ] Tests written/updated
- [ ] Changelog entry added in `.changelog` (we use
[unclog](https://github.com/informalsystems/unclog) to manage our
changelog)
- [ ] Updated relevant documentation (`docs/` or `spec/`) and code
comments
<hr>This is an automatic backport of pull request cometbft#5324 done by
[Mergify](https://mergify.com).

Co-authored-by: Alex | Interchain Labs <[email protected]>
Co-authored-by: arsushi <[email protected]>
Co-authored-by: Abdul Malek <[email protected]>
Co-authored-by: Matt Acciai <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: Tyler <[email protected]>
Co-authored-by: maradini77 <[email protected]>
tqin7 pushed a commit to dydxprotocol/cometbft that referenced this pull request Oct 14, 2025
…#5324) (cometbft#5407)

---
Updates the consensus reactor to validate that a received proposal will
not contain more parts than the amount of chunks that it would take to
build a block whos size is equal to `ConsensusParams.Block.MaxBytes`.

Original PR is here cometbft#5309, but
reopened since the contributor stopped replying.

- [ ] Tests written/updated
- [ ] Changelog entry added in `.changelog` (we use
[unclog](https://github.com/informalsystems/unclog) to manage our
changelog)
- [ ] Updated relevant documentation (`docs/` or `spec/`) and code
comments
<hr>This is an automatic backport of pull request cometbft#5324 done by
[Mergify](https://mergify.com).

Co-authored-by: Alex | Interchain Labs <[email protected]>
Co-authored-by: arsushi <[email protected]>
Co-authored-by: Abdul Malek <[email protected]>
Co-authored-by: Matt Acciai <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: Tyler <[email protected]>
Co-authored-by: maradini77 <[email protected]>
tqin7 pushed a commit to dydxprotocol/cometbft that referenced this pull request Oct 14, 2025
…#5324) (cometbft#5407)

---
Updates the consensus reactor to validate that a received proposal will
not contain more parts than the amount of chunks that it would take to
build a block whos size is equal to `ConsensusParams.Block.MaxBytes`.

Original PR is here cometbft#5309, but
reopened since the contributor stopped replying.

- [ ] Tests written/updated
- [ ] Changelog entry added in `.changelog` (we use
[unclog](https://github.com/informalsystems/unclog) to manage our
changelog)
- [ ] Updated relevant documentation (`docs/` or `spec/`) and code
comments
<hr>This is an automatic backport of pull request cometbft#5324 done by
[Mergify](https://mergify.com).

Co-authored-by: Alex | Interchain Labs <[email protected]>
Co-authored-by: arsushi <[email protected]>
Co-authored-by: Abdul Malek <[email protected]>
Co-authored-by: Matt Acciai <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: Tyler <[email protected]>
Co-authored-by: maradini77 <[email protected]>
tqin7 added a commit to dydxprotocol/cometbft that referenced this pull request Oct 14, 2025
* fix(bits): prevent BitArray.UnmarshalJSON from crashing on 0 bits in the JSON (backport cometbft#2774) (cometbft#2778)

This change fixes a bug in which BitArray.UnmarshalJSON hadn't accounted
for the fact that invoking NewBitArray(<=0) returns nil and hence when
dereferenced would crash with a runtime nil pointer dereference. This
bug was found by my security analysis and fuzzing too.

Author: @odeke-em

Fixes cometbft#2658

---

- [x] Tests written/updated
- [x] Changelog entry added in `.changelog` (we use
[unclog](https://github.com/informalsystems/unclog) to manage our
changelog)
- [ ] ~~Updated relevant documentation (`docs/` or `spec/`) and code
comments~~
- [x] Title follows the [Conventional
Commits](https://www.conventionalcommits.org/en/v1.0.0/) spec
<hr>This is an automatic backport of pull request cometbft#2774 done by
[Mergify](https://mergify.com).

---------

Co-authored-by: Anton Kaliaev <[email protected]>

* fix(consensus/reactor): reject oversized proposals (backport cometbft#5324) (cometbft#5407)

---
Updates the consensus reactor to validate that a received proposal will
not contain more parts than the amount of chunks that it would take to
build a block whos size is equal to `ConsensusParams.Block.MaxBytes`.

Original PR is here cometbft#5309, but
reopened since the contributor stopped replying.

- [ ] Tests written/updated
- [ ] Changelog entry added in `.changelog` (we use
[unclog](https://github.com/informalsystems/unclog) to manage our
changelog)
- [ ] Updated relevant documentation (`docs/` or `spec/`) and code
comments
<hr>This is an automatic backport of pull request cometbft#5324 done by
[Mergify](https://mergify.com).

Co-authored-by: Alex | Interchain Labs <[email protected]>
Co-authored-by: arsushi <[email protected]>
Co-authored-by: Abdul Malek <[email protected]>
Co-authored-by: Matt Acciai <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: Tyler <[email protected]>
Co-authored-by: maradini77 <[email protected]>

* Merge commit from fork

* add VaidateBasic to BitArray to ensure Bits and len(Elems) are valid

* call ValidateBasic on BitArrays when receiving as a msg from exteranl nodes

* enfore SetIndex is not setting out of bounds

* add guard to getNumTrueIndices

getNumTrueIndices will index out of bounds if Bits and Elems have a
mismatch where len(elems) != (bits+63)/64, this guard makes it simply
return 0 if this mismatch is present

* changelog

* fix missing import for v0.38.x

* update changelog for release of v0.38.19

* remove duplicate bug fixes from unreleased

* fix changelog date

* fix lint

* fix expected error string in test

* add necessary test constants

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: Anton Kaliaev <[email protected]>
Co-authored-by: Alex | Interchain Labs <[email protected]>
Co-authored-by: arsushi <[email protected]>
Co-authored-by: Abdul Malek <[email protected]>
Co-authored-by: Matt Acciai <[email protected]>
Co-authored-by: Tyler <[email protected]>
Co-authored-by: maradini77 <[email protected]>
Co-authored-by: Matt Acciai <[email protected]>
beer-1 pushed a commit to initia-labs/cometbft that referenced this pull request Oct 15, 2025
…#5324) (cometbft#5407)

---
Updates the consensus reactor to validate that a received proposal will
not contain more parts than the amount of chunks that it would take to
build a block whos size is equal to `ConsensusParams.Block.MaxBytes`.

Original PR is here cometbft#5309, but
reopened since the contributor stopped replying.

#### PR checklist

- [ ] Tests written/updated
- [ ] Changelog entry added in `.changelog` (we use
[unclog](https://github.com/informalsystems/unclog) to manage our
changelog)
- [ ] Updated relevant documentation (`docs/` or `spec/`) and code
comments
<hr>This is an automatic backport of pull request cometbft#5324 done by
[Mergify](https://mergify.com).

Co-authored-by: Alex | Interchain Labs <[email protected]>
Co-authored-by: arsushi <[email protected]>
Co-authored-by: Abdul Malek <[email protected]>
Co-authored-by: Matt Acciai <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: Tyler <[email protected]>
Co-authored-by: maradini77 <[email protected]>
swift1337 pushed a commit that referenced this pull request Oct 16, 2025
---
Updates the consensus reactor to validate that a received proposal will
not contain more parts than the amount of chunks that it would take to
build a block whos size is equal to `ConsensusParams.Block.MaxBytes`.

Original PR is here #5309, but
reopened since the contributor stopped replying.

#### PR checklist

- [ ] Tests written/updated
- [ ] Changelog entry added in `.changelog` (we use
[unclog](https://github.com/informalsystems/unclog) to manage our
changelog)
- [ ] Updated relevant documentation (`docs/` or `spec/`) and code
comments

---------

Co-authored-by: arsushi <[email protected]>
Co-authored-by: Abdul Malek <[email protected]>
Co-authored-by: Matt Acciai <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: Tyler <[email protected]>
Co-authored-by: maradini77 <[email protected]>
peternose pushed a commit to oasisprotocol/cometbft that referenced this pull request Jun 17, 2026
---
Updates the consensus reactor to validate that a received proposal will
not contain more parts than the amount of chunks that it would take to
build a block whos size is equal to `ConsensusParams.Block.MaxBytes`.

Original PR is here cometbft#5309, but
reopened since the contributor stopped replying.

- [ ] Tests written/updated
- [ ] Changelog entry added in `.changelog` (we use
[unclog](https://github.com/informalsystems/unclog) to manage our
changelog)
- [ ] Updated relevant documentation (`docs/` or `spec/`) and code
comments

---------

Co-authored-by: arsushi <[email protected]>
Co-authored-by: Abdul Malek <[email protected]>
Co-authored-by: Matt Acciai <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: Tyler <[email protected]>
Co-authored-by: maradini77 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-to-v0.38.x Tell Mergify to backport the PR to v0.38.x

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants