Technical Support Required - FxPortal Implementation `Fail with error 'Leaf index is too big'`

Hello! I’m the Lead Developer working on integrating GoldHunt Game ( with the Polygon network. I intend to build a custom implementation of the FxPortal Root & Child Contracts (GitHub - fx-portal/contracts: FxPortal for Polygon (Previously Matic) chain. No mapping. Seamless.) to enable our community to move tokens between Ethereum <-> Polygon.

I need technical support on implementing this bridge on the Test networks (Goerli, Mumbai).

The problem: when I call function receiveMessage(bytes memory inputData) public virtual on my implementation of the Root contract, I am getting a Fail with error 'Leaf index is too big' error on the transaction.

Failed Transactions (same error):

I generate the burn proof as such:

const execute = async () => {

  const posClient = await getPOSClient();

  const proof = await posClient.exitUtil.buildPayloadForExit(

    "0x76bd13760e3dbea702450f8741b405bf528be0078570d94c405a9183a8911ef9", // Withdraw transaction hash

    "0x8c5261668696ce22758910d05bab8f186d6eb247ceac2af2e82c7dc17669b036"  // MESSAGE_SENT_EVENT_SIG: Do not change this


  console.log(" ----- BURN PROOF -----")



Where Polygon Transaction Hash (Txhash) Details | PolygonScan is the Withdraw transaction I submitted on the Mumbai network.

My implementation of the FxMintableERC20RootTunnel is deployed at - you’ll notice a number of failed transactions all throwing the same error.

My implementation of the FxMintableERC20ChildTunnel is deployed at Contract Address 0x38530B465C2937b6f3fB7559a796156D2a0A9f02 | PolygonScan - I submitted the Withdraw transanction on Mumbai to this contract (see above) over 24 hours ago.

I am attempting to send GGold (ERC20) back and forth across my tunnel, and am unable to resolve the last step to receive the funds back from the Tunnel on Goerli due to the error above.

GGold (Goerli) -

pGGold (Polygon) - Contract Address 0xC440ddBA14e585fdF395bD74B85797e41fd8317c | PolygonScan

I can see that the error is ultimately being thrown by the Merkle library defined as such:

pragma solidity ^0.8.0;

library Merkle {
    function checkMembership(
        bytes32 leaf,
        uint256 index,
        bytes32 rootHash,
        bytes memory proof
    ) internal pure returns (bool) {
        require(proof.length % 32 == 0, "Invalid proof length");
        uint256 proofHeight = proof.length / 32;
        // Proof of size n means, height of the tree is n+1.
        // In a tree of height n+1, max #leafs possible is 2 ^ n
        require(index < 2**proofHeight, "Leaf index is too big");

        bytes32 proofElement;
        bytes32 computedHash = leaf;
        for (uint256 i = 32; i <= proof.length; i += 32) {
            assembly {
                proofElement := mload(add(proof, i))

            if (index % 2 == 0) {
                computedHash = keccak256(abi.encodePacked(computedHash, proofElement));
            } else {
                computedHash = keccak256(abi.encodePacked(proofElement, computedHash));

            index = index / 2;
        return computedHash == rootHash;

but this entire section of code was defined as part of the FxBaseRootTunnel.sol file defined in the fx-portals repo which I am using an exact copy of so I’m not sure how to debug this issue.

Please advise on how to resolve this issue - I’ve already read through Fx-Portal | Polygon Technology | Documentation and this issue is not covered and I am unable to find any other sources online about how to resolve it.

Any help you can provide would be greatly appreciated, as we’re excited about being able to onboard thousands of new users to the Polygon network once we’re able to build out this infrastructure!