From 60ada1dfed7b877e21453f8dd3b5b13528f2f796 Mon Sep 17 00:00:00 2001 From: erhant Date: Mon, 19 Feb 2024 01:50:42 +0300 Subject: [PATCH] add test circuits, some minor fixes, array tests --- .gitignore | 4 +- README.md | 4 +- book/src/arrays/README.md | 4 +- book/src/control-flow/README.md | 2 +- book/src/merkle-trees/README.md | 11 +-- circuits/basics/magic.circom | 12 +-- circuits/test/arrays/arr_read_10.circom | 6 ++ circuits/test/arrays/arr_sum_10.circom | 6 ++ circuits/test/arrays/distinct_3.circom | 6 ++ circuits/test/arrays/is_distinct_3.circom | 6 ++ circuits/test/basics/fibonacci_14.circom | 6 ++ circuits/test/basics/magic_3x3.circom | 6 ++ circuits/test/basics/magic_4x4.circom | 6 ++ circuits/test/basics/multiplier_3.circom | 6 ++ circuits/test/basics/sudoku_4x4.circom | 6 ++ circuits/test/basics/sudoku_9x9.circom | 6 ++ circuits/test/bits/and_gate.circom | 6 ++ circuits/test/bits/bits2num_5.circom | 6 ++ circuits/test/bits/not_gate.circom | 6 ++ circuits/test/bits/num2bits_5.circom | 6 ++ circuits/test/bits/or_gate.circom | 6 ++ circuits/test/bits/xor_gate.circom | 6 ++ circuits/test/comparators/compconstant.circom | 6 ++ circuits/test/comparators/ifelse.circom | 6 ++ circuits/test/comparators/inRange_1_9.circom | 6 ++ circuits/test/comparators/switch.circom | 6 ++ circuits/test/control-flow/ifelse.circom | 6 ++ circuits/test/control-flow/switch.circom | 6 ++ package.json | 5 +- tests/arrays/index.test.ts | 77 +++++++++++++++++- tests/basics/magic.test.ts | 34 ++++++-- tests/basics/sudoku.test.ts | 47 ++++++++++- tests/data/magic.ts | 22 ------ tests/data/sudoku.ts | 45 ----------- yarn.lock | 78 +++++++++++++++++++ 35 files changed, 377 insertions(+), 100 deletions(-) create mode 100644 circuits/test/arrays/arr_read_10.circom create mode 100644 circuits/test/arrays/arr_sum_10.circom create mode 100644 circuits/test/arrays/distinct_3.circom create mode 100644 circuits/test/arrays/is_distinct_3.circom create mode 100644 circuits/test/basics/fibonacci_14.circom create mode 100644 circuits/test/basics/magic_3x3.circom create mode 100644 circuits/test/basics/magic_4x4.circom create mode 100644 circuits/test/basics/multiplier_3.circom create mode 100644 circuits/test/basics/sudoku_4x4.circom create mode 100644 circuits/test/basics/sudoku_9x9.circom create mode 100644 circuits/test/bits/and_gate.circom create mode 100644 circuits/test/bits/bits2num_5.circom create mode 100644 circuits/test/bits/not_gate.circom create mode 100644 circuits/test/bits/num2bits_5.circom create mode 100644 circuits/test/bits/or_gate.circom create mode 100644 circuits/test/bits/xor_gate.circom create mode 100644 circuits/test/comparators/compconstant.circom create mode 100644 circuits/test/comparators/ifelse.circom create mode 100644 circuits/test/comparators/inRange_1_9.circom create mode 100644 circuits/test/comparators/switch.circom create mode 100644 circuits/test/control-flow/ifelse.circom create mode 100644 circuits/test/control-flow/switch.circom delete mode 100644 tests/data/magic.ts delete mode 100644 tests/data/sudoku.ts diff --git a/.gitignore b/.gitignore index 783d8c5..9cb55e7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ node_modules -circuits/test -circuits/main +# circuits/test # keep the test files +# circuits/main # keep the main files build .yarn diff --git a/README.md b/README.md index f06097d..2c2699a 100644 --- a/README.md +++ b/README.md @@ -54,8 +54,10 @@ The tests make use of [Circomkit](https://github.com/erhant/circomkit). ## Style -Check the formatting of test codes using: +Check the formatting with the following command: ```sh yarn format ``` + +This command checks the test code with [Prettier](https://www.npmjs.com/package/prettier), and lints the book with [Markdownlint](https://www.npmjs.com/package/markdownlint). diff --git a/book/src/arrays/README.md b/book/src/arrays/README.md index 93de063..f3a7c42 100644 --- a/book/src/arrays/README.md +++ b/book/src/arrays/README.md @@ -5,7 +5,7 @@ Circom arrays are a different kind of beast. The main reason is that in Circom, - Array sizes are fixed, e.g. you can't define an array based on the user input after compiling the circuit. - Array indexing should be known at compile time, e.g. you can't ask a user for index `i` and return `arr[i]` like you _normally_ do. -Before we get to the problematic unknown-at-compile-time stuff, let's quickly recap the known-time array operations: +Before we get to the problematic unknown-at-compile-time stuff, let's quickly recap the known-at-compile-time array operations: ```cs // an array with N elements @@ -17,7 +17,7 @@ signal arr[N][M]; // read element at index i for known i foo <== arr[i]; -// write to element at index j for known i +// write to element at index j for known j arr[j] <== bar; ``` diff --git a/book/src/control-flow/README.md b/book/src/control-flow/README.md index 86f17cf..58cd531 100644 --- a/book/src/control-flow/README.md +++ b/book/src/control-flow/README.md @@ -97,7 +97,7 @@ It is often useful to switch the places of two signals based on a condition, whi > signal input in[2]; > signal output out[2]; > -> aux <== (in[1] - in[0]) * cond; +> signal aux <== (in[1] - in[0]) * cond; > > out[0] <== aux + in[0]; > out[1] <== -aux + in[1]; diff --git a/book/src/merkle-trees/README.md b/book/src/merkle-trees/README.md index dc7f194..e9cfdf9 100644 --- a/book/src/merkle-trees/README.md +++ b/book/src/merkle-trees/README.md @@ -1,6 +1,6 @@ # Merkle Trees -If you have been in the world of crypto for a while, it is highly likely that you have heard the term [Merkle Tree](https://brilliant.org/wiki/merkle-tree/), also known as Merkle Hash Tree. A Merkle Tree is a hash-based data structure, an can serve as a cryptographic commitment scheme. +If you have been in the world of crypto for a while, it is highly likely that you have heard the term [Merkle Tree](https://brilliant.org/wiki/merkle-tree/), also known as Merkle Hash Tree. A Merkle Tree is a hash-based data structure, and can serve as a cryptographic commitment scheme. You can commit to a set of values using a merkle tree, such as: @@ -40,7 +40,7 @@ In a Merkle Tree, every node is made up of the hash of its children. In this exa - $h_3 = H(h_6, h_7)$ - and so on. -The leaf nodes are the hashes of elements of the committed set of data. The final hash $h1$ at the root of the tree is called the **Merkle Root**. +The leaf nodes are the hashes of elements of the committed set of data. The final hash $h_1$ at the root of the tree is called the **Merkle Root**. > Merkle Trees are often implemented as binary trees, but the concept works for $n$-ary trees as well, where each node has $n$ children. @@ -90,13 +90,6 @@ graph BT You see, we only needed to provide 3 hashes here, although our data had 8 elements! In fact, if you have $n$ elements you only need to provide $\log_2{n}$ elements to the verifier, this is so much more efficient than the naive method of sending all the data to the verifier. -- The root is the **commitment** to the vector. -- The **reveal** a value in the commitment (which is a leaf in the tree) prover does the following: - - Send sibling hashes of all nodes on root-to-leaf path. - - Verifier checks if the hashes are consistent with the root hash. - - The size of this proof to reveal a value is $\mathcal{O}(\log n)$ hash values. -- This is a **binding** scheme: once the root hash is sent, the committer is bound to the committed vector. Opening any leaf to two different values requires finding a hash collision, assumed to be intractable. - ## As a Commitment Scheme A Merkle Root can serve as a cryptographic **commitment** to a set of data. diff --git a/circuits/basics/magic.circom b/circuits/basics/magic.circom index d0eac12..22e8d52 100644 --- a/circuits/basics/magic.circom +++ b/circuits/basics/magic.circom @@ -7,12 +7,10 @@ pragma circom 2.1.0; // // Inputs: // - in: an N-by-N square -// -// Outputs: -// - sum: the magic sum +// - sum (public): the magic sum template MagicSquare(n) { signal input in[n][n]; - signal output sum; + signal input sum; // sum diagonals var diags[2]; @@ -20,8 +18,8 @@ template MagicSquare(n) { diags[0] += in[d][d]; // top-left -> bottom-right diags[1] += in[n-1-d][d]; // bottom-left -> top-right } - sum <== diags[0]; // assign this one - sum === diags[1]; // check others with equality + sum === diags[0]; + sum === diags[1]; // sum rows var rowsums[n]; @@ -40,6 +38,4 @@ template MagicSquare(n) { } sum === colsums[j]; } - - // TODO: complete circuit } diff --git a/circuits/test/arrays/arr_read_10.circom b/circuits/test/arrays/arr_read_10.circom new file mode 100644 index 0000000..2263678 --- /dev/null +++ b/circuits/test/arrays/arr_read_10.circom @@ -0,0 +1,6 @@ +// auto-generated by circomkit +pragma circom 2.0.0; + +include "../../arrays/index.circom"; + +component main = ArrayRead(10); diff --git a/circuits/test/arrays/arr_sum_10.circom b/circuits/test/arrays/arr_sum_10.circom new file mode 100644 index 0000000..68068ec --- /dev/null +++ b/circuits/test/arrays/arr_sum_10.circom @@ -0,0 +1,6 @@ +// auto-generated by circomkit +pragma circom 2.0.0; + +include "../../arrays/index.circom"; + +component main = Sum(10); diff --git a/circuits/test/arrays/distinct_3.circom b/circuits/test/arrays/distinct_3.circom new file mode 100644 index 0000000..53dfffa --- /dev/null +++ b/circuits/test/arrays/distinct_3.circom @@ -0,0 +1,6 @@ +// auto-generated by circomkit +pragma circom 2.0.0; + +include "../../arrays/distinct.circom"; + +component main = AssertDistinct(3); diff --git a/circuits/test/arrays/is_distinct_3.circom b/circuits/test/arrays/is_distinct_3.circom new file mode 100644 index 0000000..75e946e --- /dev/null +++ b/circuits/test/arrays/is_distinct_3.circom @@ -0,0 +1,6 @@ +// auto-generated by circomkit +pragma circom 2.0.0; + +include "../../arrays/distinct.circom"; + +component main = IsDistinct(3); diff --git a/circuits/test/basics/fibonacci_14.circom b/circuits/test/basics/fibonacci_14.circom new file mode 100644 index 0000000..3a1edbd --- /dev/null +++ b/circuits/test/basics/fibonacci_14.circom @@ -0,0 +1,6 @@ +// auto-generated by circomkit +pragma circom 2.0.0; + +include "../../basics/fibonacci.circom"; + +component main = Fibonacci(14); diff --git a/circuits/test/basics/magic_3x3.circom b/circuits/test/basics/magic_3x3.circom new file mode 100644 index 0000000..96f2e29 --- /dev/null +++ b/circuits/test/basics/magic_3x3.circom @@ -0,0 +1,6 @@ +// auto-generated by circomkit +pragma circom 2.0.0; + +include "../../basics/magic.circom"; + +component main {public[sum]} = MagicSquare(3); diff --git a/circuits/test/basics/magic_4x4.circom b/circuits/test/basics/magic_4x4.circom new file mode 100644 index 0000000..22211a7 --- /dev/null +++ b/circuits/test/basics/magic_4x4.circom @@ -0,0 +1,6 @@ +// auto-generated by circomkit +pragma circom 2.0.0; + +include "../../basics/magic.circom"; + +component main {public[sum]} = MagicSquare(4); diff --git a/circuits/test/basics/multiplier_3.circom b/circuits/test/basics/multiplier_3.circom new file mode 100644 index 0000000..6054330 --- /dev/null +++ b/circuits/test/basics/multiplier_3.circom @@ -0,0 +1,6 @@ +// auto-generated by circomkit +pragma circom 2.0.0; + +include "../../basics/multiplier.circom"; + +component main = Multiplier(3); diff --git a/circuits/test/basics/sudoku_4x4.circom b/circuits/test/basics/sudoku_4x4.circom new file mode 100644 index 0000000..7109211 --- /dev/null +++ b/circuits/test/basics/sudoku_4x4.circom @@ -0,0 +1,6 @@ +// auto-generated by circomkit +pragma circom 2.0.0; + +include "../../basics/sudoku.circom"; + +component main {public[puzzle]} = Sudoku(2); diff --git a/circuits/test/basics/sudoku_9x9.circom b/circuits/test/basics/sudoku_9x9.circom new file mode 100644 index 0000000..a3e49ac --- /dev/null +++ b/circuits/test/basics/sudoku_9x9.circom @@ -0,0 +1,6 @@ +// auto-generated by circomkit +pragma circom 2.0.0; + +include "../../basics/sudoku.circom"; + +component main {public[puzzle]} = Sudoku(3); diff --git a/circuits/test/bits/and_gate.circom b/circuits/test/bits/and_gate.circom new file mode 100644 index 0000000..768daef --- /dev/null +++ b/circuits/test/bits/and_gate.circom @@ -0,0 +1,6 @@ +// auto-generated by circomkit +pragma circom 2.0.0; + +include "../../bits/gates.circom"; + +component main = AND(); diff --git a/circuits/test/bits/bits2num_5.circom b/circuits/test/bits/bits2num_5.circom new file mode 100644 index 0000000..33132d6 --- /dev/null +++ b/circuits/test/bits/bits2num_5.circom @@ -0,0 +1,6 @@ +// auto-generated by circomkit +pragma circom 2.0.0; + +include "../../bits/index.circom"; + +component main = Bits2Num(5); diff --git a/circuits/test/bits/not_gate.circom b/circuits/test/bits/not_gate.circom new file mode 100644 index 0000000..5eb2244 --- /dev/null +++ b/circuits/test/bits/not_gate.circom @@ -0,0 +1,6 @@ +// auto-generated by circomkit +pragma circom 2.0.0; + +include "../../bits/gates.circom"; + +component main = NOT(); diff --git a/circuits/test/bits/num2bits_5.circom b/circuits/test/bits/num2bits_5.circom new file mode 100644 index 0000000..55df9da --- /dev/null +++ b/circuits/test/bits/num2bits_5.circom @@ -0,0 +1,6 @@ +// auto-generated by circomkit +pragma circom 2.0.0; + +include "../../bits/index.circom"; + +component main = Num2Bits(5); diff --git a/circuits/test/bits/or_gate.circom b/circuits/test/bits/or_gate.circom new file mode 100644 index 0000000..2728b82 --- /dev/null +++ b/circuits/test/bits/or_gate.circom @@ -0,0 +1,6 @@ +// auto-generated by circomkit +pragma circom 2.0.0; + +include "../../bits/gates.circom"; + +component main = OR(); diff --git a/circuits/test/bits/xor_gate.circom b/circuits/test/bits/xor_gate.circom new file mode 100644 index 0000000..9121280 --- /dev/null +++ b/circuits/test/bits/xor_gate.circom @@ -0,0 +1,6 @@ +// auto-generated by circomkit +pragma circom 2.0.0; + +include "../../bits/gates.circom"; + +component main = XOR(); diff --git a/circuits/test/comparators/compconstant.circom b/circuits/test/comparators/compconstant.circom new file mode 100644 index 0000000..d300cdb --- /dev/null +++ b/circuits/test/comparators/compconstant.circom @@ -0,0 +1,6 @@ +// auto-generated by circomkit +pragma circom 2.0.0; + +include "../../comparators/compconstant.circom"; + +component main = CompConstant(6896); diff --git a/circuits/test/comparators/ifelse.circom b/circuits/test/comparators/ifelse.circom new file mode 100644 index 0000000..d115d8f --- /dev/null +++ b/circuits/test/comparators/ifelse.circom @@ -0,0 +1,6 @@ +// auto-generated by circomkit +pragma circom 2.0.0; + +include "../../comparators/index.circom"; + +component main = IfElse(); diff --git a/circuits/test/comparators/inRange_1_9.circom b/circuits/test/comparators/inRange_1_9.circom new file mode 100644 index 0000000..5c4f2ac --- /dev/null +++ b/circuits/test/comparators/inRange_1_9.circom @@ -0,0 +1,6 @@ +// auto-generated by circomkit +pragma circom 2.0.0; + +include "../../comparators/range.circom"; + +component main = AssertInRange(1, 9); diff --git a/circuits/test/comparators/switch.circom b/circuits/test/comparators/switch.circom new file mode 100644 index 0000000..8fc3116 --- /dev/null +++ b/circuits/test/comparators/switch.circom @@ -0,0 +1,6 @@ +// auto-generated by circomkit +pragma circom 2.0.0; + +include "../../comparators/index.circom"; + +component main = Switch(); diff --git a/circuits/test/control-flow/ifelse.circom b/circuits/test/control-flow/ifelse.circom new file mode 100644 index 0000000..656a7ea --- /dev/null +++ b/circuits/test/control-flow/ifelse.circom @@ -0,0 +1,6 @@ +// auto-generated by circomkit +pragma circom 2.0.0; + +include "../../control-flow/index.circom"; + +component main = IfElse(); diff --git a/circuits/test/control-flow/switch.circom b/circuits/test/control-flow/switch.circom new file mode 100644 index 0000000..aa85db7 --- /dev/null +++ b/circuits/test/control-flow/switch.circom @@ -0,0 +1,6 @@ +// auto-generated by circomkit +pragma circom 2.0.0; + +include "../../control-flow/index.circom"; + +component main = Switch(); diff --git a/package.json b/package.json index af8192e..1d7b58b 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,9 @@ "license": "MIT", "scripts": { "test": "npx jest", - "format": "npx prettier --check ./tests/**/*.ts", + "format": "yarn format:ts", + "format:ts": "npx prettier --check ./tests/**/*.ts", + "format:md": "echo todo", "book": "cd book && mdbook serve --open", "book:build": "cd book && mdbook build" }, @@ -16,6 +18,7 @@ "@types/jest": "^29.5.12", "@types/node": "^20.11.16", "jest": "^29.7.0", + "markdownlint": "^0.33.0", "prettier": "^3.2.5", "ts-jest": "^29.1.2", "ts-node": "^10.9.1", diff --git a/tests/arrays/index.test.ts b/tests/arrays/index.test.ts index 4fb2066..782cc6d 100644 --- a/tests/arrays/index.test.ts +++ b/tests/arrays/index.test.ts @@ -1,6 +1,77 @@ import type { WitnessTester } from "circomkit"; -import { circomkit } from "../common"; +import { circomkit, primes } from "../common"; -describe.skip("arrays", () => { - // TODO +describe("arrays", () => { + const N = 10; + const arr = Array.from({ length: N }, (_, i) => i); + + describe("reads", () => { + let circuit: WitnessTester<["in", "index"], ["out"]>; + + beforeAll(async () => { + circuit = await circomkit.WitnessTester(`arr_read_${N}`, { + file: "arrays/index", + template: "ArrayRead", + dir: "test/arrays", + params: [N], + }); + }); + + it("should read correct index", async () => { + for (let i = 0; i < N; i += N >> 2) { + await circuit.expectPass({ in: arr, index: i }, { out: arr[i] }); + } + }); + + it("should read 0 for out-of-bounds index", async () => { + await circuit.expectPass({ in: arr, index: N }, { out: 0 }); + await circuit.expectPass({ in: arr, index: -1 }, { out: 0 }); + }); + }); + + describe("writes", () => { + let circuit: WitnessTester<["in", "index", "value"], ["out"]>; + + beforeAll(async () => { + circuit = await circomkit.WitnessTester(`arr_sum_${N}`, { + file: "arrays/index", + template: "ArrayWrite", + dir: "test/arrays", + params: [N], + }); + }); + + it("should write correctly", async () => { + for (let i = 0; i < N; i += N >> 2) { + const newArr = [...arr]; + const val = i * 10; + newArr[i] = val; + await circuit.expectPass({ in: arr, index: i, value: val }, { out: newArr }); + } + }); + + it("should return the same array for out-of-bounds index", async () => { + await circuit.expectPass({ in: arr, index: N, value: -1 }, { out: arr }); + await circuit.expectPass({ in: arr, index: -1, value: -1 }, { out: arr }); + }); + }); + + describe("sum", () => { + let circuit: WitnessTester<["in"], ["out"]>; + + beforeAll(async () => { + circuit = await circomkit.WitnessTester(`arr_sum_${N}`, { + file: "arrays/index", + template: "Sum", + dir: "test/arrays", + params: [N], + }); + }); + + it("should sum correctly", async () => { + // NOTE: may give wrong results for large N, use modulo if you have to + const sum = arr.reduce((acc, cur) => acc + cur); + await circuit.expectPass({ in: arr }, { out: sum }); + }); + }); }); diff --git a/tests/basics/magic.test.ts b/tests/basics/magic.test.ts index 7b72c22..6bb5959 100644 --- a/tests/basics/magic.test.ts +++ b/tests/basics/magic.test.ts @@ -1,6 +1,31 @@ import type { WitnessTester } from "circomkit"; import { circomkit } from "../common"; -import { MAGIC_SIZES, MAGIC_INPUTS } from "../data/magic"; + +// board sizes +const MAGIC_SIZES = [3, 4] as const; +type MAGIC_SIZES = (typeof MAGIC_SIZES)[number]; + +const MAGIC_INPUTS: { + [N in MAGIC_SIZES]: { in: number[][]; sum: number }; +} = { + 3: { + in: [ + [4, 9, 2], + [3, 5, 7], + [8, 1, 6], + ], + sum: 15, + }, + 4: { + in: [ + [4, 14, 15, 1], + [9, 7, 6, 12], + [5, 11, 10, 8], + [16, 2, 3, 13], + ], + sum: 34, + }, +}; MAGIC_SIZES.map((N) => describe(`magic (${N} by ${N})`, () => { @@ -8,7 +33,7 @@ MAGIC_SIZES.map((N) => const OUTPUT = { sum: INPUT.in[0].reduce((acc: number, cur: number) => acc + cur, 0), }; - let circuit: WitnessTester<["in"], ["sum"]>; + let circuit: WitnessTester<["in", "sum"]>; beforeAll(async () => { circuit = await circomkit.WitnessTester(`magic_${N}x${N}`, { @@ -16,13 +41,12 @@ MAGIC_SIZES.map((N) => template: "MagicSquare", dir: "test/basics", params: [N], + pubs: ["sum"], }); }); - it("should compute correctly", async () => { + it("should pass for correct magic squares", async () => { await circuit.expectPass(INPUT, OUTPUT); }); - - // TODO fail checks }), ); diff --git a/tests/basics/sudoku.test.ts b/tests/basics/sudoku.test.ts index cfa4054..816973d 100644 --- a/tests/basics/sudoku.test.ts +++ b/tests/basics/sudoku.test.ts @@ -1,6 +1,51 @@ import type { WitnessTester } from "circomkit"; import { circomkit } from "../common"; -import { BOARD_SIZES, SUDOKU_INPUTS } from "../data/sudoku"; + +const BOARD_SIZES = [4, 9] as const; +type BOARD_SIZES = (typeof BOARD_SIZES)[number]; + +const SUDOKU_INPUTS: { + [N in BOARD_SIZES]: { solution: number[][]; puzzle: number[][] }; +} = { + 9: { + solution: [ + [1, 9, 4, 8, 6, 5, 2, 3, 7], + [7, 3, 5, 4, 1, 2, 9, 6, 8], + [8, 6, 2, 3, 9, 7, 1, 4, 5], + [9, 2, 1, 7, 4, 8, 3, 5, 6], + [6, 7, 8, 5, 3, 1, 4, 2, 9], + [4, 5, 3, 9, 2, 6, 8, 7, 1], + [3, 8, 9, 6, 5, 4, 7, 1, 2], + [2, 4, 6, 1, 7, 9, 5, 8, 3], + [5, 1, 7, 2, 8, 3, 6, 9, 4], + ], + puzzle: [ + [0, 0, 0, 8, 6, 0, 2, 3, 0], + [7, 0, 5, 0, 0, 0, 9, 0, 8], + [0, 6, 0, 3, 0, 7, 0, 4, 0], + [0, 2, 0, 7, 0, 8, 0, 5, 0], + [0, 7, 8, 5, 0, 0, 0, 0, 0], + [4, 0, 0, 9, 0, 6, 0, 7, 0], + [3, 0, 9, 0, 5, 0, 7, 0, 2], + [0, 4, 0, 1, 0, 9, 0, 8, 0], + [5, 0, 7, 0, 8, 0, 0, 9, 4], + ], + }, + 4: { + solution: [ + [4, 1, 3, 2], + [3, 2, 4, 1], + [2, 4, 1, 3], + [1, 3, 2, 4], + ], + puzzle: [ + [0, 1, 0, 2], + [3, 2, 0, 0], + [0, 0, 1, 0], + [1, 0, 0, 0], + ], + }, +}; BOARD_SIZES.map((N) => describe(`sudoku (${N} by ${N})`, () => { diff --git a/tests/data/magic.ts b/tests/data/magic.ts deleted file mode 100644 index 9989620..0000000 --- a/tests/data/magic.ts +++ /dev/null @@ -1,22 +0,0 @@ -import type { CircuitSignals } from "circomkit"; - -export const MAGIC_SIZES = [3, 4] as const; -export const MAGIC_INPUTS: { - [N in (typeof MAGIC_SIZES)[number]]: CircuitSignals<["in"]>; -} = { - 3: { - in: [ - [4, 9, 2], - [3, 5, 7], - [8, 1, 6], - ], - }, - 4: { - in: [ - [4, 14, 15, 1], - [9, 7, 6, 12], - [5, 11, 10, 8], - [16, 2, 3, 13], - ], - }, -}; diff --git a/tests/data/sudoku.ts b/tests/data/sudoku.ts deleted file mode 100644 index 771409a..0000000 --- a/tests/data/sudoku.ts +++ /dev/null @@ -1,45 +0,0 @@ -import type { CircuitSignals } from "circomkit"; - -export const BOARD_SIZES = [4, 9] as const; -export const SUDOKU_INPUTS: { - [N in (typeof BOARD_SIZES)[number]]: CircuitSignals<["solution", "puzzle"]>; -} = { - 9: { - solution: [ - [1, 9, 4, 8, 6, 5, 2, 3, 7], - [7, 3, 5, 4, 1, 2, 9, 6, 8], - [8, 6, 2, 3, 9, 7, 1, 4, 5], - [9, 2, 1, 7, 4, 8, 3, 5, 6], - [6, 7, 8, 5, 3, 1, 4, 2, 9], - [4, 5, 3, 9, 2, 6, 8, 7, 1], - [3, 8, 9, 6, 5, 4, 7, 1, 2], - [2, 4, 6, 1, 7, 9, 5, 8, 3], - [5, 1, 7, 2, 8, 3, 6, 9, 4], - ], - puzzle: [ - [0, 0, 0, 8, 6, 0, 2, 3, 0], - [7, 0, 5, 0, 0, 0, 9, 0, 8], - [0, 6, 0, 3, 0, 7, 0, 4, 0], - [0, 2, 0, 7, 0, 8, 0, 5, 0], - [0, 7, 8, 5, 0, 0, 0, 0, 0], - [4, 0, 0, 9, 0, 6, 0, 7, 0], - [3, 0, 9, 0, 5, 0, 7, 0, 2], - [0, 4, 0, 1, 0, 9, 0, 8, 0], - [5, 0, 7, 0, 8, 0, 0, 9, 4], - ], - }, - 4: { - solution: [ - [4, 1, 3, 2], - [3, 2, 4, 1], - [2, 4, 1, 3], - [1, 3, 2, 4], - ], - puzzle: [ - [0, 1, 0, 2], - [3, 2, 0, 0], - [0, 0, 1, 0], - [1, 0, 0, 0], - ], - }, -}; diff --git a/yarn.lock b/yarn.lock index f8d5d02..2b6c792 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1072,6 +1072,13 @@ __metadata: languageName: node linkType: hard +"argparse@npm:^2.0.1": + version: 2.0.1 + resolution: "argparse@npm:2.0.1" + checksum: 10c0/c5640c2d89045371c7cedd6a70212a04e360fd34d6edeae32f6952c63949e3525ea77dbec0289d8213a99bbaeab5abfa860b5c12cf88a2e6cf8106e90dd27a7e + languageName: node + linkType: hard + "assertion-error@npm:^1.1.0": version: 1.1.0 resolution: "assertion-error@npm:1.1.0" @@ -1710,6 +1717,13 @@ __metadata: languageName: node linkType: hard +"entities@npm:^4.4.0": + version: 4.5.0 + resolution: "entities@npm:4.5.0" + checksum: 10c0/5b039739f7621f5d1ad996715e53d964035f75ad3b9a4d38c6b3804bb226e282ffeae2443624d8fdd9c47d8e926ae9ac009c54671243f0c3294c26af7cc85250 + languageName: node + linkType: hard + "env-paths@npm:^2.2.0": version: 2.2.1 resolution: "env-paths@npm:2.2.1" @@ -2944,6 +2958,15 @@ __metadata: languageName: node linkType: hard +"linkify-it@npm:^5.0.0": + version: 5.0.0 + resolution: "linkify-it@npm:5.0.0" + dependencies: + uc.micro: "npm:^2.0.0" + checksum: 10c0/ff4abbcdfa2003472fc3eb4b8e60905ec97718e11e33cca52059919a4c80cc0e0c2a14d23e23d8c00e5402bc5a885cdba8ca053a11483ab3cc8b3c7a52f88e2d + languageName: node + linkType: hard + "locate-path@npm:^5.0.0": version: 5.0.0 resolution: "locate-path@npm:5.0.0" @@ -3052,6 +3075,46 @@ __metadata: languageName: node linkType: hard +"markdown-it@npm:14.0.0": + version: 14.0.0 + resolution: "markdown-it@npm:14.0.0" + dependencies: + argparse: "npm:^2.0.1" + entities: "npm:^4.4.0" + linkify-it: "npm:^5.0.0" + mdurl: "npm:^2.0.0" + punycode.js: "npm:^2.3.1" + uc.micro: "npm:^2.0.0" + bin: + markdown-it: bin/markdown-it.mjs + checksum: 10c0/aabea498a1395776b5ca2b83ce7942d75608595b09215213edf224d5f09c31dfc7bb5a4c73ed2ead9a0a38da3e5e6e2c37daae71afd227c2acb6905ae5d6b498 + languageName: node + linkType: hard + +"markdownlint-micromark@npm:0.1.8": + version: 0.1.8 + resolution: "markdownlint-micromark@npm:0.1.8" + checksum: 10c0/7a399382462c24b066000ab80730cca98ccd8e884bfb04b17aff627c0fb5794b21e396d2e924b8827437ea5c7f255cef22b1335fed853abbdcdf37873d95eb3b + languageName: node + linkType: hard + +"markdownlint@npm:^0.33.0": + version: 0.33.0 + resolution: "markdownlint@npm:0.33.0" + dependencies: + markdown-it: "npm:14.0.0" + markdownlint-micromark: "npm:0.1.8" + checksum: 10c0/34660dfcb607c555ff3e69e37aca95042d33b3f34b1d91059d898b5efe56448c0af2c9b8eadc861e4a2433954865bd52df7f6fe34c3e5136a50a6cfe5737a4cc + languageName: node + linkType: hard + +"mdurl@npm:^2.0.0": + version: 2.0.0 + resolution: "mdurl@npm:2.0.0" + checksum: 10c0/633db522272f75ce4788440669137c77540d74a83e9015666a9557a152c02e245b192edc20bc90ae953bbab727503994a53b236b4d9c99bdaee594d0e7dd2ce0 + languageName: node + linkType: hard + "merge-stream@npm:^2.0.0": version: 2.0.0 resolution: "merge-stream@npm:2.0.0" @@ -3480,6 +3543,13 @@ __metadata: languageName: node linkType: hard +"punycode.js@npm:^2.3.1": + version: 2.3.1 + resolution: "punycode.js@npm:2.3.1" + checksum: 10c0/1d12c1c0e06127fa5db56bd7fdf698daf9a78104456a6b67326877afc21feaa821257b171539caedd2f0524027fa38e67b13dd094159c8d70b6d26d2bea4dfdb + languageName: node + linkType: hard + "pure-rand@npm:^6.0.0": version: 6.0.4 resolution: "pure-rand@npm:6.0.4" @@ -3601,6 +3671,7 @@ __metadata: circomkit: "npm:^0.0.22" circomlib: "npm:^2.0.5" jest: "npm:^29.7.0" + markdownlint: "npm:^0.33.0" prettier: "npm:^3.2.5" ts-jest: "npm:^29.1.2" ts-node: "npm:^10.9.1" @@ -4072,6 +4143,13 @@ __metadata: languageName: node linkType: hard +"uc.micro@npm:^2.0.0": + version: 2.0.0 + resolution: "uc.micro@npm:2.0.0" + checksum: 10c0/eb3699e35120ee5764b4f1e8ee426117ac97f5474abf312fdd356213bcbeab9ef5a205805dab56afa53f5b9472b452b6ba8de305270d1eeb6730c831f922c8a4 + languageName: node + linkType: hard + "undici-types@npm:~5.26.4": version: 5.26.5 resolution: "undici-types@npm:5.26.5"