feat: set binary tree for semaphore protocol

Former-commit-id: 4470df6ff258e21411bfcc74d3388a0398f3f46a [formerly 378f35fd4813b389ae7c6b90b248c5154e704868] [formerly f79a8fe36217321f8b02b7b6786bb5413a9b1a50 [formerly 7213b343ffb281c8e81d447a179009bdb04b3c54]] [formerly 695155b5c1e4758f36af45097f2cf521c3f1c854 [formerly 2b70d23f1ffd70ff28ba9ac214c113534c92e77e] [formerly 1b46c2fd8ba488de78eaa68abdf125021ad3e6d1 [formerly f5411edad3]]]
Former-commit-id: d968886745f403b5415d0738310e56b9e0cf38c9 [formerly 02f33b46e896683807cebe621a429c8b244a7a0d] [formerly 7d3098a31babe73e1206219582b759e79beb4989 [formerly bf80a5fe52804b657594a35b34b0eb3d17fe5cee]]
Former-commit-id: 6084776c23b2e0f82d3d49613bed6334674339f3 [formerly 2b0a41a2d5792ec35d7248ada6a0e175025f9584]
Former-commit-id: b052d15edbcbe7d2dc5dec46ac2153ff73ae3af3
This commit is contained in:
cedoor
2022-02-14 18:17:14 +01:00
parent 4e84772463
commit 5b514c080e
6 changed files with 24 additions and 17 deletions

View File

@@ -66,7 +66,7 @@ import { generateMerkleProof } from "@zk-kit/protocols"
const depth = 20
const zeroValue = BigInt(0)
const arity = 5
const arity = 2
const identity = new ZkIdentity()
const identityCommitment = identity.genIdentityCommitment()
const identityCommitments = [BigInt(1), identityCommitment, BigInt(2)]

View File

@@ -24,12 +24,12 @@ export default class Semaphore extends ZkProtocol {
shouldHash = true
): SemaphoreWitness {
return {
identity_nullifier: identityNullifier,
identity_trapdoor: identityTrapdoor,
identity_path_index: merkleProof.pathIndices,
path_elements: merkleProof.siblings,
external_nullifier: externalNullifier,
signal_hash: shouldHash ? genSignalHash(signal) : signal
identityNullifier,
identityTrapdoor,
treePathIndices: merkleProof.pathIndices,
treeSiblings: merkleProof.siblings,
externalNullifier,
signalHash: shouldHash ? genSignalHash(signal) : signal
}
}

View File

@@ -16,10 +16,10 @@ export type FullProof = {
export type SolidityProof = StrBigInt[]
export type SemaphoreWitness = {
identity_nullifier: StrBigInt
identity_trapdoor: StrBigInt
path_elements: StrBigInt[]
identity_path_index: number[]
external_nullifier: StrBigInt
signal_hash: StrBigInt
identityNullifier: StrBigInt
identityTrapdoor: StrBigInt
treeSiblings: StrBigInt[]
treePathIndices: number[]
externalNullifier: StrBigInt
signalHash: StrBigInt
}

View File

@@ -72,5 +72,12 @@ export function generateMerkleProof(
throw new Error("The leaf does not exists")
}
return tree.createProof(leafIndex)
const merkleProof = tree.createProof(leafIndex)
if (arity === 2) {
// It makes it compatible with the parameter in the contracts.
merkleProof.siblings = merkleProof.siblings.map((s) => s[0])
}
return merkleProof
}

View File

@@ -26,7 +26,7 @@ describe("Semaphore", () => {
const leaves = [BigInt(3), BigInt(2), identityCommitment, BigInt(4)]
const signal = "0x111"
const merkleProof = generateMerkleProof(20, BigInt(0), 5, leaves, identityCommitment)
const merkleProof = generateMerkleProof(20, BigInt(0), 2, leaves, identityCommitment)
const witness = Semaphore.genWitness(
identity.getTrapdoor(),
@@ -47,7 +47,7 @@ describe("Semaphore", () => {
const leaves = [BigInt(3), BigInt(2), identityCommitment, BigInt(4)]
const signal = "0x111"
const merkleProof = generateMerkleProof(20, BigInt(0), 5, leaves, identityCommitment)
const merkleProof = generateMerkleProof(20, BigInt(0), 2, leaves, identityCommitment)
const witness = Semaphore.genWitness(
identity.getTrapdoor(),

View File

@@ -1 +1 @@
2daec67f953ad6155f56d4c0c16ac1b67eb97a94
83a3802ca5e94bb251704b767deab0b7202c3ecd