-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add test circuits, some minor fixes, array tests
- Loading branch information
Showing
35 changed files
with
377 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
node_modules | ||
circuits/test | ||
circuits/main | ||
# circuits/test # keep the test files | ||
# circuits/main # keep the main files | ||
build | ||
.yarn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// auto-generated by circomkit | ||
pragma circom 2.0.0; | ||
|
||
include "../../arrays/index.circom"; | ||
|
||
component main = ArrayRead(10); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// auto-generated by circomkit | ||
pragma circom 2.0.0; | ||
|
||
include "../../arrays/index.circom"; | ||
|
||
component main = Sum(10); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// auto-generated by circomkit | ||
pragma circom 2.0.0; | ||
|
||
include "../../arrays/distinct.circom"; | ||
|
||
component main = AssertDistinct(3); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// auto-generated by circomkit | ||
pragma circom 2.0.0; | ||
|
||
include "../../arrays/distinct.circom"; | ||
|
||
component main = IsDistinct(3); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// auto-generated by circomkit | ||
pragma circom 2.0.0; | ||
|
||
include "../../basics/fibonacci.circom"; | ||
|
||
component main = Fibonacci(14); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// auto-generated by circomkit | ||
pragma circom 2.0.0; | ||
|
||
include "../../basics/magic.circom"; | ||
|
||
component main {public[sum]} = MagicSquare(3); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// auto-generated by circomkit | ||
pragma circom 2.0.0; | ||
|
||
include "../../basics/magic.circom"; | ||
|
||
component main {public[sum]} = MagicSquare(4); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// auto-generated by circomkit | ||
pragma circom 2.0.0; | ||
|
||
include "../../basics/multiplier.circom"; | ||
|
||
component main = Multiplier(3); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// auto-generated by circomkit | ||
pragma circom 2.0.0; | ||
|
||
include "../../basics/sudoku.circom"; | ||
|
||
component main {public[puzzle]} = Sudoku(2); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// auto-generated by circomkit | ||
pragma circom 2.0.0; | ||
|
||
include "../../basics/sudoku.circom"; | ||
|
||
component main {public[puzzle]} = Sudoku(3); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// auto-generated by circomkit | ||
pragma circom 2.0.0; | ||
|
||
include "../../bits/gates.circom"; | ||
|
||
component main = AND(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// auto-generated by circomkit | ||
pragma circom 2.0.0; | ||
|
||
include "../../bits/index.circom"; | ||
|
||
component main = Bits2Num(5); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// auto-generated by circomkit | ||
pragma circom 2.0.0; | ||
|
||
include "../../bits/gates.circom"; | ||
|
||
component main = NOT(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// auto-generated by circomkit | ||
pragma circom 2.0.0; | ||
|
||
include "../../bits/index.circom"; | ||
|
||
component main = Num2Bits(5); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// auto-generated by circomkit | ||
pragma circom 2.0.0; | ||
|
||
include "../../bits/gates.circom"; | ||
|
||
component main = OR(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// auto-generated by circomkit | ||
pragma circom 2.0.0; | ||
|
||
include "../../bits/gates.circom"; | ||
|
||
component main = XOR(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// auto-generated by circomkit | ||
pragma circom 2.0.0; | ||
|
||
include "../../comparators/compconstant.circom"; | ||
|
||
component main = CompConstant(6896); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// auto-generated by circomkit | ||
pragma circom 2.0.0; | ||
|
||
include "../../comparators/index.circom"; | ||
|
||
component main = IfElse(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// auto-generated by circomkit | ||
pragma circom 2.0.0; | ||
|
||
include "../../comparators/range.circom"; | ||
|
||
component main = AssertInRange(1, 9); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// auto-generated by circomkit | ||
pragma circom 2.0.0; | ||
|
||
include "../../comparators/index.circom"; | ||
|
||
component main = Switch(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// auto-generated by circomkit | ||
pragma circom 2.0.0; | ||
|
||
include "../../control-flow/index.circom"; | ||
|
||
component main = IfElse(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// auto-generated by circomkit | ||
pragma circom 2.0.0; | ||
|
||
include "../../control-flow/index.circom"; | ||
|
||
component main = Switch(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 }); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.