Skip to content

fix(capacitors): correct updateMaxPacketLength packet count (division, not modulo) - #440

Open
Jr-kenny wants to merge 1 commit into
SocketDotTech:masterfrom
Jr-kenny:fix/hashchain-updateMaxPacketLength-brick
Open

Jr-kenny wants to merge 1 commit into
SocketDotTech:masterfrom
Jr-kenny:fix/hashchain-updateMaxPacketLength-brick

Conversation

@Jr-kenny

Copy link
Copy Markdown

Fixes #439.

updateMaxPacketLength used modulo instead of division for the packet count and counted one message too many, so shrinking the max over-created packets, advanced messagePacked past the messages that exist, and permanently bricked the capacitor (every later addPackedMessage reverts on a uint64 underflow, panic 0x11, with no setter to recover).

The fix computes the true pending count (nextMessageCount - messagePacked - 1, since nextMessageCount is 1-indexed) and divides by the new max. Both changes are required.

Tests: five new regression tests against the fixed contract (0/1/4/6 pending, shrink-after-some-packed), all pass; the three reproduction tests fail against the fixed contract as expected, confirming the brick is gone; the existing 10 HashChainCapacitor.t.sol tests pass with no regression.

This does not touch the separate stale-state validation bug (#436 / PR #438).

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.

updateMaxPacketLength permanently bricks the capacitor: modulo instead of division, plus an off-by-one in the pending count

1 participant