You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you put in the first two leaves concatenated on https://emn178.github.io/online-tools/keccak_256.html it would actually be f68b7c2821ff5479150c5204d6671eb40a33748a1d2e5becc7b34dc17964dad1 which matches the Solidity output of keccak256(abi.encodePacked(leaf1,leaf2))
For some additional context, I have a struct like:
Obj {
id: uint256,
...
}
This is then encoded in Solidity like keccak256(abi.encode(objs)) and is used as the leaf. The leaf encoding is correct (verified using debugger) and the entire process works fine in Solidity, except that each hash does not agree to the one produced by Solidity.
Here's the code I am using to run this:
import { keccak256 } from "keccak256";
...
tree = new MerkleTree(hashes, keccak256); // hashes is array of keccak256(abi.encode(objs))
const root = tree.getHexRoot();
console.log(tree.toString());
I presume this is because the hexstring is parsed as text, for e.g. this tree:
If you put in the first two leaves concatenated on https://emn178.github.io/online-tools/keccak_256.html it would actually be
f68b7c2821ff5479150c5204d6671eb40a33748a1d2e5becc7b34dc17964dad1
which matches the Solidity output ofkeccak256(abi.encodePacked(leaf1,leaf2))
For some additional context, I have a struct like:
This is then encoded in Solidity like
keccak256(abi.encode(objs))
and is used as the leaf. The leaf encoding is correct (verified using debugger) and the entire process works fine in Solidity, except that each hash does not agree to the one produced by Solidity.Here's the code I am using to run this:
hashes
looks like:The text was updated successfully, but these errors were encountered: