MerkleTree计算根节点不相等 #238
-
|
Beta Was this translation helpful? Give feedback.
Answered by
coldstar1993
Nov 29, 2024
Replies: 2 comments
-
先 const tree = new MerkleTree(4);
// ith leaf => Filed(i)
for (let i = 0; i < 4; i++) {
tree.setLeaf(BigInt(i), Field(i));
}
const expectRoot = tree.getRoot();
const witness = new (MerkleWitness(4))(tree.getWitness(0n));
const calculatedRoot = witness.calculateRoot(Field(0));
console.log('root:', calculatedRoot.toBigInt(), expectRoot.toBigInt()); |
Beta Was this translation helpful? Give feedback.
0 replies
-
用法错了。正确的如下: tree.setLeaf(1n,Poseidon.hash([Field(1)])); |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
missop
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
用法错了。正确的如下:
const tree = new MerkleTree(64);
const root = tree.getRoot();
const witness = new MerkleTreeWitness(tree.getWitness(1n));
tree.setLeaf(1n,Poseidon.hash([Field(1)]));
const root1 = tree.getRoot();
console.log("witness.calculateRoot(Poseidon.hash([Field(1)]))",witness.calculateRoot(Poseidon.hash([Field(1)])), root1 );