I want to need your help.
sheriff-rango opened this issue · 1 comments
A group of users is eligible for rewards in a certain token type.
I want to store the total reward in a smart contract called Distributor
and allow the user to withdraw his reward portion from this contract.
To make sure that each user can only withdraw the amount he is assigned I want to use the Merkle Tree where all the distribution information is encoded into the Merkle root.
I composed the string with users account address and his amount and built merkle tree with them using merkletreejs
.
Just like in your test script ("should return true for valid merkle proof (SO#63509)").
The progress of making merkle tree using merkletreejs
in the test file is the same as yours.
The difference is that I made leaf for verification with msg.sender
and amount
in the solidity file for security using kesscak256
and abi.encodePacked
.
in solidity file
...
string memory nodeString = MakeNodeString.composeNodeString(
msg.sender,
amount
);
bytes32 node = keccak256(abi.encodePacked(nodeString));
require(
MerkleProof.verify(merkleProof, merkleRoot, node),
"MerkleDistributor: Invalid proof."
);
...
But unfortunately, I failed the verification and I think it is because there are difference between the hash result of kessck256(abi.encodePacked(nodeString))
in solidity file and kesscak256(nodeString)
in javascript file.
I have already asked in Stackoverflow
.
How can I fix this issue?
@sheriff-rango I've added a working example in this branch https://github.com/miguelmota/merkletreejs-solidity/tree/encodePacked-example
It should answer your questions about using abi.encodePacked
and soliditySha3