-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds basic benchmarking for GPC PCD prove and verify operations (useful for getting a sense of how long they take vs. ZKEdDSAEventTicketPCD or Semaphore signature).
- Loading branch information
Showing
4 changed files
with
149 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
import { GPCProofConfig, serializeGPCProofConfig } from "@pcd/gpc"; | ||
import { GPCPCD, GPCPCDArgs, GPCPCDPackage } from "@pcd/gpc-pcd"; | ||
import { ArgumentTypeName } from "@pcd/pcd-types"; | ||
import { POD, PODEntries } from "@pcd/pod"; | ||
import { PODPCD, PODPCDPackage } from "@pcd/pod-pcd"; | ||
import { SemaphoreIdentityPCDPackage } from "@pcd/semaphore-identity-pcd"; | ||
import { BABY_JUB_NEGATIVE_ONE } from "@pcd/util"; | ||
import { Identity } from "@semaphore-protocol/identity"; | ||
import path from "path"; | ||
import { v4 as uuid } from "uuid"; | ||
import { TimerCase } from "../types"; | ||
|
||
export const GPC_TEST_ARTIFACTS_PATH = path.join( | ||
__dirname, | ||
"../../../../lib/gpcircuits/artifacts/test" | ||
); | ||
|
||
async function setupProveArgs(): Promise<GPCPCDArgs> { | ||
// Key borrowed from https://github.com/iden3/circomlibjs/blob/4f094c5be05c1f0210924a3ab204d8fd8da69f49/test/eddsa.js#L103 | ||
const privateKey = | ||
"0001020304050607080900010203040506070809000102030405060708090001"; | ||
|
||
const ownerIdentity = new Identity( | ||
'["329061722381819402313027227353491409557029289040211387019699013780657641967", "99353161014976810914716773124042455250852206298527174581112949561812190422"]' | ||
); | ||
|
||
// 11 entries, max depth 5 | ||
// Defined out of order, but will be sorted by POD construction. | ||
const sampleEntries = { | ||
E: { type: "cryptographic", value: 123n }, | ||
F: { type: "cryptographic", value: BABY_JUB_NEGATIVE_ONE }, | ||
C: { type: "string", value: "hello" }, | ||
D: { type: "string", value: "foobar" }, | ||
A: { type: "int", value: 123n }, | ||
B: { type: "int", value: 321n }, | ||
G: { type: "int", value: 7n }, | ||
H: { type: "int", value: 8n }, | ||
I: { type: "int", value: 9n }, | ||
J: { type: "int", value: 10n }, | ||
owner: { type: "cryptographic", value: ownerIdentity.commitment } | ||
} satisfies PODEntries; | ||
|
||
const proofConfig: GPCProofConfig = { | ||
pods: { | ||
pod0: { | ||
entries: { | ||
A: { isRevealed: true }, | ||
E: { isRevealed: false, equalsEntry: "pod0.A" }, | ||
owner: { isRevealed: false, isOwnerID: true } | ||
} | ||
} | ||
} | ||
}; | ||
|
||
const pod = POD.sign(sampleEntries, privateKey); | ||
const podPCD = new PODPCD(uuid(), pod); | ||
|
||
const identityPCD = await SemaphoreIdentityPCDPackage.prove({ | ||
identity: ownerIdentity | ||
}); | ||
|
||
return { | ||
proofConfig: { | ||
argumentType: ArgumentTypeName.String, | ||
value: serializeGPCProofConfig(proofConfig) | ||
}, | ||
pod: { | ||
value: await PODPCDPackage.serialize(podPCD), | ||
argumentType: ArgumentTypeName.PCD | ||
}, | ||
identity: { | ||
value: await SemaphoreIdentityPCDPackage.serialize(identityPCD), | ||
argumentType: ArgumentTypeName.PCD | ||
}, | ||
externalNullifier: { | ||
value: "some external nullifier", | ||
argumentType: ArgumentTypeName.String | ||
}, | ||
watermark: { | ||
value: "some watermark", | ||
argumentType: ArgumentTypeName.String | ||
}, | ||
id: { | ||
argumentType: ArgumentTypeName.String, | ||
value: uuid() | ||
} | ||
} satisfies GPCPCDArgs; | ||
} | ||
|
||
export class GPCPCDProveCase extends TimerCase { | ||
proveArgs?: GPCPCDArgs; | ||
|
||
constructor() { | ||
super("gpc-pcd.prove"); | ||
} | ||
|
||
async init(): Promise<void> { | ||
await GPCPCDPackage.init?.({ zkArtifactPath: GPC_TEST_ARTIFACTS_PATH }); | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-empty-function | ||
async setup(_: number): Promise<void> { | ||
this.proveArgs = await setupProveArgs(); | ||
} | ||
|
||
async op(_: number): Promise<void> { | ||
if (!this.proveArgs) { | ||
throw new Error("Missing proveArgs. Skipped setup?"); | ||
} | ||
await GPCPCDPackage.prove(this.proveArgs); | ||
} | ||
} | ||
|
||
export class GPCPCDVerifyCase extends TimerCase { | ||
pcd?: GPCPCD; | ||
|
||
constructor() { | ||
super("gpc-pcd.verify"); | ||
} | ||
|
||
async init(): Promise<void> { | ||
await GPCPCDPackage.init?.({ zkArtifactPath: GPC_TEST_ARTIFACTS_PATH }); | ||
} | ||
|
||
async setup(_: number): Promise<void> { | ||
this.pcd = await GPCPCDPackage.prove(await setupProveArgs()); | ||
} | ||
|
||
async op(_: number): Promise<void> { | ||
if (!this.pcd) { | ||
throw new Error("Missing PCD. Skipped setup?"); | ||
} | ||
await GPCPCDPackage.verify(this.pcd); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters