From 4eb39188f86968375fe60d7b7ca4536cf13e95d1 Mon Sep 17 00:00:00 2001 From: 0xturboblitz Date: Wed, 22 May 2024 01:22:52 +0900 Subject: [PATCH] fix IMT depth passed to circuit and contract --- common/src/utils/generateInputs.ts | 6 +++--- common/src/utils/utils.ts | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/common/src/utils/generateInputs.ts b/common/src/utils/generateInputs.ts index 2e21b4348..5896a0d93 100644 --- a/common/src/utils/generateInputs.ts +++ b/common/src/utils/generateInputs.ts @@ -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, diff --git a/common/src/utils/utils.ts b/common/src/utils/utils.ts index b32aa1d6c..4e760f1da 100644 --- a/common/src/utils/utils.ts +++ b/common/src/utils/utils.ts @@ -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 } }