Commit c98ee8f
authored
fix: pos exit proof non power of 2 merkle (#908)
* fix(pos exit-proof): pad merkle leaves to power of 2
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.
* chore(pos exit-proof): drop merkle test file1 parent 4847986 commit c98ee8f
1 file changed
Lines changed: 22 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
666 | 666 | | |
667 | 667 | | |
668 | 668 | | |
669 | | - | |
670 | | - | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
671 | 682 | | |
672 | | - | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
673 | 690 | | |
| 691 | + | |
674 | 692 | | |
675 | 693 | | |
676 | 694 | | |
677 | | - | |
678 | 695 | | |
679 | | - | |
680 | | - | |
681 | | - | |
682 | 696 | | |
683 | 697 | | |
684 | 698 | | |
| |||
687 | 701 | | |
688 | 702 | | |
689 | 703 | | |
690 | | - | |
| 704 | + | |
691 | 705 | | |
692 | 706 | | |
693 | 707 | | |
| |||
0 commit comments