mirror of
https://github.com/selfxyz/self.git
synced 2026-01-22 21:17:59 -05:00
fix IMT depth passed to circuit and contract
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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 }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user