MerkProof.Verify Always Retuns false on solidity but returns true frontend

121 Views Asked by At

I have this code for verifying a merkleproof on solidity

event beforeClaim(bytes32 root, bytes32 node,  bool proof);

    function claim(
        address account,
        uint256 amount,
        bytes32[] calldata merkleProof
    ) public {
        require(claimed[account] == false, 'user already claimed');

        bytes32 node = keccak256(abi.encodePacked(account, amount));

        emit beforeClaim(merkleRoot, node, MerkleProof.verify(merkleProof, merkleRoot, node));

And this code on the frontend

export interface User {
    address: string;
    amount: string;
}

function getElements(users: User[]) {
    const elements = users.map((x) => {
        return utils.solidityKeccak256(['address', 'uint256'], [x.address, parseFloat(x.amount)])
    }
    );
    return elements;
}

export function getProof(users: User[], userAddress: string): string[] {
    const index = users.findIndex((user) => user.address === userAddress);
    const elements = getElements(users);
    const leaf = elements[index];
    const merkleTree = new MerkleTree(elements, keccak256, { sort: true });
    const proof = merkleTree.getHexProof(leaf);
    return proof;
}

The root, node, merkleproof values match both on solidity and frontend but on the frontend the result is true and somehow the MerkleProof.verify() returns false always regardless of the values matching both on frontend and solidity (I passed the values manually but still the result from solidity is false)

0

There are 0 best solutions below