diff --git a/README.md b/README.md index fe2db55..c0761aa 100644 --- a/README.md +++ b/README.md @@ -48,10 +48,10 @@ Write your circuits under `circuits` folder; the circuit code itself should be t ```js multiplier3: { - file: 'multiplier', - template: 'Multiplier', - publicInputs: [], - templateInputs: [3], + template: 'Multiplier', // template to instantiate the main component + file: 'multiplier', // file to include for the template + publicInputs: [], // array of public inputs + templateInputs: [3], // template parameters, order is important } ``` @@ -69,7 +69,7 @@ There are some environment variables that the CLI can make use of, they are writ ## Testing -To run tests: +To run Mocha tests do the following: ```bash # run all tests diff --git a/circuits/main/sudoku9.circom b/circuits/main/sudoku9.circom index 8ea72f1..b2136ed 100644 --- a/circuits/main/sudoku9.circom +++ b/circuits/main/sudoku9.circom @@ -1,6 +1,6 @@ +// auto-generated by instantiate.js pragma circom 2.0.0; include "../../circuits/sudoku.circom"; -// Circuit for 3^2 x 3^2 sudoku component main {public[puzzle]} = Sudoku(3); diff --git a/scripts/functions/clean.sh b/scripts/functions/clean.sh index 8562aee..ade44df 100755 --- a/scripts/functions/clean.sh +++ b/scripts/functions/clean.sh @@ -3,8 +3,10 @@ clean() { echo -e "\n${CLIENV_COLOR_TITLE}=== Cleaning artifacts ===${CLIENV_COLOR_RESET}" local CIRCUIT=$1 local CIRCUIT_DIR=./build/$CIRCUIT + local TARGET=./circuits/main/$CIRCUIT.circom rm -rf $CIRCUIT_DIR + rm -f $TARGET - echo -e "${CLIENV_COLOR_LOG}Deleted $CIRCUIT_DIR${CLIENV_COLOR_RESET}" + echo -e "${CLIENV_COLOR_LOG}Deleted $CIRCUIT_DIR and $TARGET${CLIENV_COLOR_RESET}" } diff --git a/tests/multiplier.test.ts b/tests/multiplier.test.ts index 2a50584..ea22b02 100644 --- a/tests/multiplier.test.ts +++ b/tests/multiplier.test.ts @@ -1,4 +1,4 @@ -import {compileCircuit} from '../utils'; +import {createWasmTester} from '../utils/wasmTester'; import {ProofTester} from '../utils/proofTester'; import type {CircuitSignals, FullProof} from '../types/circuit'; import type {WasmTester} from '../types/wasmTester'; @@ -14,15 +14,12 @@ describe(CIRCUIT_NAME, () => { let circuit: WasmTester; before(async () => { - circuit = await compileCircuit('./circuits/main/' + CIRCUIT_NAME + '.circom'); - await circuit.loadConstraints(); - console.log('#constraints:', circuit.constraints!.length); + circuit = await createWasmTester('./circuits/main/' + CIRCUIT_NAME + '.circom', true); }); it('should compute correctly', async () => { // compute witness const witness = await circuit.calculateWitness(INPUT, true); - console.log(witness); // witness should have valid constraints await circuit.checkConstraints(witness); diff --git a/tests/sudoku.test.ts b/tests/sudoku.test.ts index 915fdde..90ad69e 100644 --- a/tests/sudoku.test.ts +++ b/tests/sudoku.test.ts @@ -1,4 +1,4 @@ -import {compileCircuit} from '../utils'; +import {createWasmTester} from '../utils/wasmTester'; import type {CircuitSignals, FullProof} from '../types/circuit'; import type {WasmTester} from '../types/wasmTester'; import {assert, expect} from 'chai'; @@ -13,14 +13,12 @@ describe(CIRCUIT_NAME, () => { let circuit: WasmTester; before(async () => { - circuit = await compileCircuit('./circuits/main/' + CIRCUIT_NAME + '.circom'); - await circuit.loadConstraints(); - console.log('#constraints:', circuit.constraints!.length); + circuit = await createWasmTester('./circuits/main/' + CIRCUIT_NAME + '.circom', true); }); it('should compute correctly', async () => { // compute witness - const witness = await circuit.calculateWitness(inputfoo, true); + const witness = await circuit.calculateWitness(INPUT, true); // witness should have valid constraints await circuit.checkConstraints(witness); diff --git a/types/wasmTester.ts b/types/wasmTester.ts index 64bf0aa..f0c66cd 100644 --- a/types/wasmTester.ts +++ b/types/wasmTester.ts @@ -13,6 +13,7 @@ export type WasmTester = { /** * Cleanup directory, should probably be called upon test completion + * @deprecated this is buggy right now */ release(): Promise; diff --git a/utils/index.ts b/utils/index.ts deleted file mode 100644 index 5e0e1a1..0000000 --- a/utils/index.ts +++ /dev/null @@ -1,13 +0,0 @@ -import type {WasmTester} from '../types/wasmTester'; -const wasm_tester = require('circom_tester').wasm; - -/** - * Compiles and reutrns a circuit via `circom_tester`'s `wasm_tester`. - * @param circuit name of circuit - * @returns a `wasm_tester` object - */ -export async function compileCircuit(path: string): Promise { - return await wasm_tester(path, { - include: 'node_modules', // will link circomlib circuits - }); -} diff --git a/utils/wasmTester.ts b/utils/wasmTester.ts new file mode 100644 index 0000000..af82f4b --- /dev/null +++ b/utils/wasmTester.ts @@ -0,0 +1,21 @@ +import type {WasmTester} from '../types/wasmTester'; +const wasm_tester = require('circom_tester').wasm; + +/** + * Compiles and reutrns a circuit via `circom_tester`'s `wasm_tester`. + * @param circuit name of circuit + * @param showNumConstraints print number of constraints, defualts to `false` + * @returns a `wasm_tester` object + */ +export async function createWasmTester(path: string, showNumConstraints: boolean = false): Promise { + const circuit = await wasm_tester(path, { + include: 'node_modules', // will link circomlib circuits + }); + + if (showNumConstraints) { + await circuit.loadConstraints(); + console.log(' number of constraints:', circuit.constraints!.length); + } + + return circuit; +}