fix IMT depth passed to circuit and contract

This commit is contained in:
0xturboblitz
2024-05-22 01:22:52 +09:00
parent 93eaf83f87
commit 4eb39188f8
2 changed files with 5 additions and 4 deletions

View File

@@ -128,11 +128,11 @@ export function generateCircuitInputsDisclose(
mrz_bytes[2]
]);
console.log('commitment', commitment);
console.log('commitment', commitment.toString());
const index = findIndexInTree(merkletree, commitment);
const { merkleProofSiblings, merkleProofIndices } = generateMerkleProof(merkletree, index, PUBKEY_TREE_DEPTH)
const { merkleProofSiblings, merkleProofIndices, depthForThisOne } = generateMerkleProof(merkletree, index, PUBKEY_TREE_DEPTH)
return {
secret: [secret],
@@ -140,7 +140,7 @@ export function generateCircuitInputsDisclose(
pubkey_leaf: [pubkey_leaf.toString()],
mrz: formattedMrz.map(byte => String(byte)),
merkle_root: [merkletree.root.toString()],
merkletree_size: [BigInt(merkletree.depth).toString()],
merkletree_size: [BigInt(depthForThisOne).toString()],
path: merkleProofIndices.map(index => BigInt(index).toString()),
siblings: merkleProofSiblings.map(index => BigInt(index).toString()),
bitmap: bitmap,

View File

@@ -246,6 +246,7 @@ export function packBytes(unpacked) {
export function generateMerkleProof(imt: LeanIMT, _index: number, maxDepth: number) {
const { siblings: merkleProofSiblings, index } = imt.generateProof(_index)
const depthForThisOne = merkleProofSiblings.length
// The index must be converted to a list of indices, 1 for each tree level.
// The circuit tree depth is 20, so the number of siblings must be 20, even if
// the tree depth is actually 3. The missing siblings can be set to 0, as they
@@ -258,5 +259,5 @@ export function generateMerkleProof(imt: LeanIMT, _index: number, maxDepth: numb
merkleProofSiblings[i] = BigInt(0)
}
}
return { merkleProofSiblings, merkleProofIndices }
return { merkleProofSiblings, merkleProofIndices, depthForThisOne }
}