From 29bc8f834fc56281bb9626567971508ea9b2ea1e Mon Sep 17 00:00:00 2001 From: Erhan Tezcan Date: Thu, 30 Mar 2023 10:53:28 +0300 Subject: [PATCH] rfks --- README.md | 4 +++ tests/multiplier.test.ts | 3 +- tests/sudoku.test.ts | 3 +- types/proofTester.ts | 0 types/wasmTester.ts | 65 --------------------------------------- utils/proofTester.ts | 4 +++ utils/wasmTester.ts | 66 +++++++++++++++++++++++++++++++++++++++- 7 files changed, 75 insertions(+), 70 deletions(-) delete mode 100644 types/proofTester.ts delete mode 100644 types/wasmTester.ts diff --git a/README.md b/README.md index c0761aa..75fa070 100644 --- a/README.md +++ b/README.md @@ -82,3 +82,7 @@ Within each test, there are two sub-tests: - **Witness Computation** will test whether witness computations are matching the expectations & the constraints hold. - **Proof Validation** will test whether proof generation & verification works correctly. This requires the **WASM file**, **prover key**, and **verification key** to be calculated beforehand. + +## Styling + +The code uses Google TypeScript Style guide. It also has some folder & file icon overrides for several Material UI icons to make things look better. diff --git a/tests/multiplier.test.ts b/tests/multiplier.test.ts index ea22b02..cfd2ca8 100644 --- a/tests/multiplier.test.ts +++ b/tests/multiplier.test.ts @@ -1,7 +1,6 @@ import {createWasmTester} from '../utils/wasmTester'; import {ProofTester} from '../utils/proofTester'; import type {CircuitSignals, FullProof} from '../types/circuit'; -import type {WasmTester} from '../types/wasmTester'; import {assert, expect} from 'chai'; // read inputs from file import input80 from '../inputs/multiplier3/80.json'; @@ -11,7 +10,7 @@ describe(CIRCUIT_NAME, () => { const INPUT: CircuitSignals = input80; describe('witness computation', () => { - let circuit: WasmTester; + let circuit: Awaited>; before(async () => { circuit = await createWasmTester('./circuits/main/' + CIRCUIT_NAME + '.circom', true); diff --git a/tests/sudoku.test.ts b/tests/sudoku.test.ts index 90ad69e..2b393c4 100644 --- a/tests/sudoku.test.ts +++ b/tests/sudoku.test.ts @@ -1,6 +1,5 @@ import {createWasmTester} from '../utils/wasmTester'; import type {CircuitSignals, FullProof} from '../types/circuit'; -import type {WasmTester} from '../types/wasmTester'; import {assert, expect} from 'chai'; // read inputs from file import inputfoo from '../inputs/sudoku9/foo.json'; @@ -10,7 +9,7 @@ describe(CIRCUIT_NAME, () => { const INPUT: CircuitSignals = inputfoo; describe('witness computation', () => { - let circuit: WasmTester; + let circuit: Awaited>; before(async () => { circuit = await createWasmTester('./circuits/main/' + CIRCUIT_NAME + '.circom', true); diff --git a/types/proofTester.ts b/types/proofTester.ts deleted file mode 100644 index e69de29..0000000 diff --git a/types/wasmTester.ts b/types/wasmTester.ts deleted file mode 100644 index f0c66cd..0000000 --- a/types/wasmTester.ts +++ /dev/null @@ -1,65 +0,0 @@ -import {WitnessType, CircuitSignals} from './circuit'; - -/** - * Custom types added with respect to `circomlibjs.wasm`. Not all functions exist here, some are omitted. - * @see https://github.com/iden3/circom_tester/blob/main/wasm/tester.js - */ -export type WasmTester = { - /** - * Assert that constraints are valid. - * @param witness witness - */ - checkConstraints: (witness: WitnessType) => Promise; - - /** - * Cleanup directory, should probably be called upon test completion - * @deprecated this is buggy right now - */ - release(): Promise; - - /** - * Assert the output of a given witness. - * @param actualOut expected output signals - * @param expectedOut computed output signals - */ - assertOut: (actualOut: CircuitSignals, expectedOut: CircuitSignals) => Promise; - - /** - * Compute witness given the input signals. - * @param input all signals, private and public. - * @param sanityCheck ? - */ - calculateWitness: (input: CircuitSignals, sanityCheck: boolean) => Promise; - - /** - * Loads the list of R1CS constraints to `this.constraints` - */ - loadConstraints(): Promise; - - /** - * List of constraints, must call `loadConstraints` before - * accessing this key - */ - constraints: any[] | undefined; - - /** - * Loads the symbols in a dictionary at `this.symbols` - * Symbols are stored under the .sym file - * Each line has 4 comma-separated values: - * 0: label index - * 1: variable index - * 2: component index - */ - loadSymbols(): Promise; - - /** - * A dictionary of symbols - */ - symbols: object; - - /** - * @deprecated this is buggy right now - * @param witness witness - */ - getDecoratedOutput(witness: WitnessType): Promise; -}; diff --git a/utils/proofTester.ts b/utils/proofTester.ts index ad0a31f..a76af58 100644 --- a/utils/proofTester.ts +++ b/utils/proofTester.ts @@ -11,6 +11,10 @@ export class ProofTester { private readonly proverKeyPath: string; private readonly verificationKey: object; + /** + * Sets the paths & loads the verification key + * @param circuit a proof tester + */ constructor(circuit: string) { // find paths (computed w.r.t circuit name) this.wasmPath = `./build/${circuit}/${circuit}_js/${circuit}.wasm`; diff --git a/utils/wasmTester.ts b/utils/wasmTester.ts index af82f4b..7f6afd1 100644 --- a/utils/wasmTester.ts +++ b/utils/wasmTester.ts @@ -1,5 +1,69 @@ -import type {WasmTester} from '../types/wasmTester'; const wasm_tester = require('circom_tester').wasm; +import {WitnessType, CircuitSignals} from '../types/circuit'; + +/** + * Custom types added with respect to `circomlibjs.wasm`. Not all functions exist here, some are omitted. + * @see https://github.com/iden3/circom_tester/blob/main/wasm/tester.js + */ +type WasmTester = { + /** + * Assert that constraints are valid. + * @param witness witness + */ + checkConstraints: (witness: WitnessType) => Promise; + + /** + * Cleanup directory, should probably be called upon test completion + * @deprecated this is buggy right now + */ + release(): Promise; + + /** + * Assert the output of a given witness. + * @param actualOut expected output signals + * @param expectedOut computed output signals + */ + assertOut: (actualOut: CircuitSignals, expectedOut: CircuitSignals) => Promise; + + /** + * Compute witness given the input signals. + * @param input all signals, private and public. + * @param sanityCheck ? + */ + calculateWitness: (input: CircuitSignals, sanityCheck: boolean) => Promise; + + /** + * Loads the list of R1CS constraints to `this.constraints` + */ + loadConstraints(): Promise; + + /** + * List of constraints, must call `loadConstraints` before + * accessing this key + */ + constraints: any[] | undefined; + + /** + * Loads the symbols in a dictionary at `this.symbols` + * Symbols are stored under the .sym file + * Each line has 4 comma-separated values: + * 0: label index + * 1: variable index + * 2: component index + */ + loadSymbols(): Promise; + + /** + * A dictionary of symbols + */ + symbols: object; + + /** + * @deprecated this is buggy right now + * @param witness witness + */ + getDecoratedOutput(witness: WitnessType): Promise; +}; /** * Compiles and reutrns a circuit via `circom_tester`'s `wasm_tester`.