Hello! I’m the Lead Developer working on integrating GoldHunt Game (thegame.gold) 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):
-
https://goerli.etherscan.io/tx/0x8b19cb0f540d5f6fba1ff19c5c64bb99ba15ee0cc33f1f24859fd26db18b9872
-
https://goerli.etherscan.io/tx/0x605f6c4ed73547d956c5635aae23e5b1c54f560e2f7e6e57bfed14827c0dcd6c
-
https://goerli.etherscan.io/tx/0x8906d30b22d7c49366a8641ed5613654c5ab280f897a16bdc97d3c38ea019260
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 -----")
console.log(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 https://goerli.etherscan.io/address/0xC0Af0b1a10F2417D62EE044BC99dB1b40b4DC82e - 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) - https://goerli.etherscan.io/address/0xbdCDF80D26DDA1ae2F9C0003995d160F4893F20A
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!