fix: pos exit proof non power of 2 merkle#908
Merged
Conversation
Polygon's matic-js MerkleTree (and the pos-contracts / pos-portal test helpers it mirrors) builds a complete fixed-depth binary tree by padding the leaf layer with zero hashes to the next power of 2. The on-chain verifier (pos-contracts/contracts/common/lib/Merkle.sol checkMembership) requires that exact shape — it asserts index < 2^proofHeight and walks a fixed-depth tree. merkleProof was instead duplicating the last node per layer when an odd count was reached. That coincidentally matches matic-js when the leaf count is already a power of 2 (mainnet's 128-block checkpoints), so the bug never surfaced in production. On a fast-cadence devnet validators sometimes submit checkpoint ranges that aren't powers of 2 (e.g. 40 blocks), and the resulting tree root differs from L1's stored headerRoot — startExitWithBurntTokens then reverts with WITHDRAW_BLOCK_NOT_A_PART_OF_SUBMITTED_HEADER. Pad once at the leaf layer to the next power of 2 with zero hashes, then build cleanly. Adds cmd_test.go with an independent reproduction of the on-chain verifier and a regression case at 40 leaves.
|
jhkimqd
approved these changes
Apr 29, 2026
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.



Related to 0xPolygon/kurtosis-pos#545