-
Notifications
You must be signed in to change notification settings - Fork 744
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to verify tries in Solidity? #1096
Comments
Hey there. After setting up your trie, you would use Trie.createProof, and then pass the proof along with the root ( For some examples on how this is done within merkle-patricia-tree, check out test/proof.spec.ts |
Thanks @ryanio. I need to reconstruct the leaf in Solidity to verify that the other arguments passed to the contract function (like
|
I found the openzeppelin PR that introduces the Following this example with their JS describe("verifyProof", function() {
it("should return true for a valid Merkle proof", async function() {
const elements = ["a", "b", "c", "d"];
const merkleTree = new MerkleTree(elements);
const root = merkleTree.getHexRoot();
const proof = merkleTree.getHexProof(elements[0]);
const leaf = bufferToHex(sha3(elements[0]));
const result = await merkleProof.verifyProof(proof, root, leaf);
assert.isOk(result, "verifyProof did not return true for a valid proof");
}); (link) So your |
@ryanio is this something where we could extract some useful example from for our proof section in the Trie library README? 🤔 |
The OP was asking how to verify a merkle tree in solidity and I pointed to OpenZeppelin's From OpenZeppelin/openzeppelin-contracts#260:
I am not sure if we do this same sorting in |
Long period of inactivity and very special topic, somewhat solved with some hints as well, will close. |
I'm looking to generate a Merkle tree in JS and verify proofs on-chain in Solidity. There are Solidity libraries like OpenZeppelin's MerkleProof.sol that let me do so, but I can't find a reliable Merkle library in JS. merkle-patricia-trees seems to be the most reliable, but I can't find any examples on how I would verify tries in Solidity.
With a Merkle tree, each of my objects would look something like this:
...which I would ideally hash with something like
web3.utils.soliditySha3(address, token, amount)
, and pass an array of those leaves to the tree.Am I correct in thinking that in a trie, the key would be
Buffer.from(address)
and the value would beBuffer.from('${token}${amount}')
? And then how would I verify that in Solidity? Would really appreciate a hand or any resources that I may have overlooked. Thanks.The text was updated successfully, but these errors were encountered: