This commit is contained in:
Erhan Tezcan
2023-03-30 10:53:28 +03:00
parent 92fdeada86
commit 29bc8f834f
7 changed files with 75 additions and 70 deletions

View File

@@ -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.

View File

@@ -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<ReturnType<typeof createWasmTester>>;
before(async () => {
circuit = await createWasmTester('./circuits/main/' + CIRCUIT_NAME + '.circom', true);

View File

@@ -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<ReturnType<typeof createWasmTester>>;
before(async () => {
circuit = await createWasmTester('./circuits/main/' + CIRCUIT_NAME + '.circom', true);

View File

View File

@@ -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<void>;
/**
* Cleanup directory, should probably be called upon test completion
* @deprecated this is buggy right now
*/
release(): Promise<void>;
/**
* Assert the output of a given witness.
* @param actualOut expected output signals
* @param expectedOut computed output signals
*/
assertOut: (actualOut: CircuitSignals, expectedOut: CircuitSignals) => Promise<void>;
/**
* Compute witness given the input signals.
* @param input all signals, private and public.
* @param sanityCheck ?
*/
calculateWitness: (input: CircuitSignals, sanityCheck: boolean) => Promise<WitnessType>;
/**
* Loads the list of R1CS constraints to `this.constraints`
*/
loadConstraints(): Promise<void>;
/**
* 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<void>;
/**
* A dictionary of symbols
*/
symbols: object;
/**
* @deprecated this is buggy right now
* @param witness witness
*/
getDecoratedOutput(witness: WitnessType): Promise<string>;
};

View File

@@ -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`;

View File

@@ -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<void>;
/**
* Cleanup directory, should probably be called upon test completion
* @deprecated this is buggy right now
*/
release(): Promise<void>;
/**
* Assert the output of a given witness.
* @param actualOut expected output signals
* @param expectedOut computed output signals
*/
assertOut: (actualOut: CircuitSignals, expectedOut: CircuitSignals) => Promise<void>;
/**
* Compute witness given the input signals.
* @param input all signals, private and public.
* @param sanityCheck ?
*/
calculateWitness: (input: CircuitSignals, sanityCheck: boolean) => Promise<WitnessType>;
/**
* Loads the list of R1CS constraints to `this.constraints`
*/
loadConstraints(): Promise<void>;
/**
* 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<void>;
/**
* A dictionary of symbols
*/
symbols: object;
/**
* @deprecated this is buggy right now
* @param witness witness
*/
getDecoratedOutput(witness: WitnessType): Promise<string>;
};
/**
* Compiles and reutrns a circuit via `circom_tester`'s `wasm_tester`.