Skip to content

Commit

Permalink
fix(verification): added missing files and fixed paths for ci/prod tests
Browse files Browse the repository at this point in the history
added missing types file and fixed tests to run both on emulator and prod.
  • Loading branch information
ctrlc03 committed Mar 2, 2023
1 parent ca5712c commit 73c3557
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 5 deletions.
58 changes: 58 additions & 0 deletions packages/actions/src/types/snarkjs.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/** Declaration file generated by dts-gen */

declare module "snarkjs" {
// eslint-disable-next-line @typescript-eslint/no-use-before-define
export = snarkjs

declare const snarkjs: {
groth16: {
exportSolidityCallData: any
fullProve: any
prove: any
verify: any
}
plonk: {
exportSolidityCallData: any
fullProve: any
prove: any
setup: any
verify: any
}
powersOfTau: {
beacon: any
challengeContribute: any
contribute: any
convert: any
exportChallenge: any
exportJson: any
importResponse: any
newAccumulator: any
preparePhase2: any
truncate: any
verify: any
}
r1cs: {
exportJson: any
info: any
print: any
}
wtns: {
calculate: any
debug: any
exportJson: any
}
zKey: {
beacon: any
bellmanContribute: any
contribute: any
exportBellman: any
exportJson: any
exportSolidityVerifier: any
exportVerificationKey: any
importBellman: any
newZKey: any
verifyFromInit: any
verifyFromR1cs: any
}
}
}
27 changes: 22 additions & 5 deletions packages/actions/test/unit/verification.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import chai, { expect } from "chai"
import chaiAsPromised from "chai-as-promised"
import { cwd } from "process"
import { verifyZKey } from "../../src"
import { envType } from "../utils"
import { TestingEnvironment } from "../../src/types/enums"

chai.use(chaiAsPromised)

Expand All @@ -11,11 +13,26 @@ chai.use(chaiAsPromised)
describe("Verification", () => {
/// @note verify that a zKey is valid
describe("verifyzKey", () => {
const zkeyPath = `${cwd()}/packages/actions/test/data/artifacts/circuit_0000.zkey`
const badzkeyPath = `${cwd()}/packages/actions/test/data/artifacts/bad_circuit_0000.zkey`
const wrongZkeyPath = `${cwd()}/packages/actions/test/data/artifacts/notcircuit_0000.zkey`
const potPath = `${cwd()}/packages/actions/test/data/artifacts/powersOfTau28_hez_final_02.ptau`
const r1csPath = `${cwd()}/packages/actions/test/data/artifacts/circuit.r1cs`
let zkeyPath: string = ""
let badzkeyPath: string = ""
let wrongZkeyPath: string = ""
let potPath: string = ""
let r1csPath: string = ""

if (envType === TestingEnvironment.DEVELOPMENT) {
zkeyPath = `${cwd()}/../actions/test/data/artifacts/circuit_0000.zkey`
badzkeyPath = `${cwd()}/../actions/test/data/artifacts/bad_circuit_0000.zkey`
wrongZkeyPath = `${cwd()}/../actions/test/data/artifacts/notcircuit_0000.zkey`
potPath = `${cwd()}/../actions/test/data/artifacts/powersOfTau28_hez_final_02.ptau`
r1csPath = `${cwd()}/../actions/test/data/artifacts/circuit.r1cs`
} else {
zkeyPath = `${cwd()}/packages/actions/test/data/artifacts/circuit_0000.zkey`
badzkeyPath = `${cwd()}/packages/actions/test/data/artifacts/bad_circuit_0000.zkey`
wrongZkeyPath = `${cwd()}/packages/actions/test/data/artifacts/notcircuit_0000.zkey`
potPath = `${cwd()}/packages/actions/test/data/artifacts/powersOfTau28_hez_final_02.ptau`
r1csPath = `${cwd()}/packages/actions/test/data/artifacts/circuit.r1cs`
}

it("should return true for a valid zkey", async () => {
expect(await verifyZKey(r1csPath, zkeyPath, potPath)).to.be.true
})
Expand Down

0 comments on commit 73c3557

Please sign in to comment.