Skip to content

Commit 253344f

Browse files
authored
Merge pull request #593 from semaphore-protocol/chore/snarkjs
Replace `@zk-kit/groth16` with new `snarkjs` package Former-commit-id: 33a7dd7
2 parents 3079d0a + 5b9065b commit 253344f

File tree

9 files changed

+24
-22
lines changed

9 files changed

+24
-22
lines changed

packages/proof/package.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,12 @@
5151
"@semaphore-protocol/identity": "4.0.0-alpha"
5252
},
5353
"dependencies": {
54-
"@ethersproject/bignumber": "^5.7.0",
55-
"@ethersproject/bytes": "^5.7.0",
56-
"@ethersproject/keccak256": "^5.7.0",
57-
"@zk-kit/groth16": "0.5.0",
58-
"download": "^8.0.0",
59-
"tmp": "^0.2.1"
54+
"@ethersproject/bignumber": "5.7.0",
55+
"@ethersproject/bytes": "5.7.0",
56+
"@ethersproject/keccak256": "5.7.0",
57+
"@types/snarkjs": "0.7.8",
58+
"download": "8.0.0",
59+
"snarkjs": "0.7.3",
60+
"tmp": "0.2.1"
6061
}
6162
}

packages/proof/src/generate-proof.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import { BigNumber } from "@ethersproject/bignumber"
22
import { BytesLike, Hexable } from "@ethersproject/bytes"
33
import { Group } from "@semaphore-protocol/group"
44
import type { Identity } from "@semaphore-protocol/identity"
5-
import { NumericString, prove } from "@zk-kit/groth16"
5+
import { NumericString, groth16 } from "snarkjs"
66
import getSnarkArtifacts from "./get-snark-artifacts.node"
77
import hash from "./hash"
8-
import packPoints from "./pack-proof"
8+
import packPoints from "./pack-points"
99
import { SemaphoreProof, SnarkArtifacts } from "./types"
1010

1111
/**
@@ -57,7 +57,7 @@ export default async function generateProof(
5757
}
5858
}
5959

60-
const { proof, publicSignals } = await prove(
60+
const { proof, publicSignals } = await groth16.fullProve(
6161
{
6262
secret: identity.secretScalar,
6363
merkleProofLength,

packages/proof/src/hash.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { BigNumber } from "@ethersproject/bignumber"
22
import { BytesLike, Hexable, zeroPad } from "@ethersproject/bytes"
33
import { keccak256 } from "@ethersproject/keccak256"
4-
import { NumericString } from "@zk-kit/groth16"
4+
import { NumericString } from "snarkjs"
55

66
/**
77
* Creates a keccak256 hash of a message compatible with the SNARK scalar modulus.

packages/proof/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import generateProof from "./generate-proof"
22
import getSnarkArtifacts from "./get-snark-artifacts.node"
3-
import packPoints from "./pack-proof"
4-
import unpackPoints from "./unpack-proof"
3+
import packPoints from "./pack-points"
4+
import unpackPoints from "./unpack-points"
55
import verifyProof from "./verify-proof"
66

77
export * from "./types"

packages/proof/src/pack-proof.ts renamed to packages/proof/src/pack-points.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Groth16Proof } from "@zk-kit/groth16"
1+
import { Groth16Proof } from "snarkjs"
22
import { PackedPoints } from "./types"
33

44
/**

packages/proof/src/types/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { NumericString } from "@zk-kit/groth16"
1+
import type { NumericString } from "snarkjs"
22

33
export type BigNumberish = string | number | bigint
44

packages/proof/src/unpack-proof.ts renamed to packages/proof/src/unpack-points.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Groth16Proof } from "@zk-kit/groth16"
1+
import { Groth16Proof } from "snarkjs"
22
import { PackedPoints } from "./types"
33

44
/**

packages/proof/src/verify-proof.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { verify } from "@zk-kit/groth16"
1+
import { groth16 } from "snarkjs"
22
import hash from "./hash"
33
import { SemaphoreProof } from "./types"
4-
import unpackPoints from "./unpack-proof"
4+
import unpackPoints from "./unpack-points"
55
import verificationKeys from "./verification-keys.json"
66

77
/**
@@ -29,8 +29,9 @@ export default async function verifyProof({
2929
IC: verificationKeys.IC[merkleTreeDepth - 1]
3030
}
3131

32-
return verify(verificationKey, {
33-
publicSignals: [merkleTreeRoot, nullifier, hash(message), hash(scope)],
34-
proof: unpackPoints(points)
35-
})
32+
return groth16.verify(
33+
verificationKey,
34+
[merkleTreeRoot, nullifier, hash(message), hash(scope)],
35+
unpackPoints(points)
36+
)
3637
}

yarn.lock.REMOVED.git-id

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
efdb7972e73571da5467fda80978d7cbf6d475b1
1+
77c20f3da77a76f425420068852c75fa9f77eacc

0 commit comments

Comments
 (0)