Skip to content

Commit

Permalink
refactor: add @zk-kit/artifacts (#788)
Browse files Browse the repository at this point in the history
* refactor: add `@zk-kit/artifacts`

* chore: update `jest.config.ts`

* test: increase timeouts

* chore: bump `@zk-kit/utils`

* fix: bump `@zk-kit/artifacts`
  • Loading branch information
sripwoud committed May 20, 2024
1 parent f3f3688 commit 7b3621a
Show file tree
Hide file tree
Showing 6 changed files with 713 additions and 812 deletions.
2 changes: 1 addition & 1 deletion packages/group/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@
},
"dependencies": {
"@zk-kit/imt": "2.0.0-beta.4",
"@zk-kit/utils": "1.0.0-beta.4"
"@zk-kit/utils": "1.0.0-beta.5"
}
}
2 changes: 1 addition & 1 deletion packages/identity/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"dependencies": {
"@zk-kit/baby-jubjub": "1.0.0",
"@zk-kit/eddsa-poseidon": "1.0.0",
"@zk-kit/utils": "1.0.0-beta.4",
"@zk-kit/utils": "1.0.0-beta.5",
"poseidon-lite": "0.2.0"
}
}
3 changes: 2 additions & 1 deletion packages/proof/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@
},
"dependencies": {
"@semaphore-protocol/utils": "4.0.0-beta.10",
"@zk-kit/utils": "1.0.0-beta.4",
"@zk-kit/artifacts": "^1.3.2",
"@zk-kit/utils": "1.0.0-beta.5",
"ethers": "6.10.0",
"snarkjs": "0.7.4"
}
Expand Down
4 changes: 2 additions & 2 deletions packages/proof/src/generate-proof.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { Identity } from "@semaphore-protocol/identity"
import { MAX_DEPTH, MIN_DEPTH } from "@semaphore-protocol/utils/constants"
import { requireDefined, requireNumber, requireObject, requireTypes } from "@zk-kit/utils/error-handlers"
import { packGroth16Proof } from "@zk-kit/utils/proof-packing"
import { maybeGetSemaphoreSnarkArtifacts, type SnarkArtifacts } from "@zk-kit/utils"
import { maybeGetSnarkArtifacts, Project, type SnarkArtifacts } from "@zk-kit/artifacts"
import type { BigNumberish } from "ethers"
import { type NumericString, groth16 } from "snarkjs"
import hash from "./hash"
Expand Down Expand Up @@ -83,7 +83,7 @@ export default async function generateProof(
}

// If the Snark artifacts are not defined they will be automatically downloaded.
snarkArtifacts ??= await maybeGetSemaphoreSnarkArtifacts(merkleTreeDepth)
snarkArtifacts ??= await maybeGetSnarkArtifacts(Project.SEMAPHORE, { parameters: [merkleTreeDepth] })
const { wasm, zkey } = snarkArtifacts

// The index must be converted to a list of indices, 1 for each tree level.
Expand Down
8 changes: 4 additions & 4 deletions packages/proof/tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe("Proof", () => {

expect(typeof proof).toBe("object")
expect(BigInt(proof.merkleTreeRoot)).toBe(group.root)
}, 70000)
}, 80000)

it("Should generate a Semaphore proof passing a Merkle proof instead of a group", async () => {
const group = new Group([1n, 2n, identity.commitment])
Expand All @@ -55,7 +55,7 @@ describe("Proof", () => {

expect(typeof proof).toBe("object")
expect(BigInt(proof.merkleTreeRoot)).toBe(group.root)
}, 70000)
}, 80000)

it("Should generate a Semaphore proof without passing the tree depth", async () => {
const group = new Group([1n, 2n, identity.commitment])
Expand All @@ -64,7 +64,7 @@ describe("Proof", () => {

expect(typeof proof).toBe("object")
expect(BigInt(proof.merkleTreeRoot)).toBe(group.root)
}, 70000)
}, 80000)

it("Should throw an error because snarkArtifacts is not an object", async () => {
const group = new Group([1n, 2n, identity.commitment])
Expand Down Expand Up @@ -102,6 +102,6 @@ describe("Proof", () => {
const response = await verifyProof(proof)

expect(response).toBe(true)
})
}, 80_000)
})
})
Loading

0 comments on commit 7b3621a

Please sign in to comment.