This commit is contained in:
Erhan Tezcan
2023-03-30 01:03:29 +03:00
parent 1e4aa1daa0
commit 92fdeada86
8 changed files with 36 additions and 30 deletions

View File

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

View File

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

View File

@@ -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}"
}

View File

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

View File

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

View File

@@ -13,6 +13,7 @@ export type WasmTester = {
/**
* Cleanup directory, should probably be called upon test completion
* @deprecated this is buggy right now
*/
release(): Promise<void>;

View File

@@ -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<WasmTester> {
return await wasm_tester(path, {
include: 'node_modules', // will link circomlib circuits
});
}

21
utils/wasmTester.ts Normal file
View File

@@ -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<WasmTester> {
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;
}