-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added circom to perform range check * using fully qualified name to get contract artifact * minor update * prettier:write * adding to the test cases * Adding apps/circuits * added circuits components * updated with rangecheck * removed circuits from contracts * Added script to copy app/circuits compiled assets over to app/contracts dir inside * passing prettier:write
- Loading branch information
1 parent
dc09638
commit 52b9de8
Showing
26 changed files
with
1,194 additions
and
1,254 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
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,2 @@ | ||
artifacts | ||
src/test |
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,7 @@ | ||
{ | ||
"extension": ["ts"], | ||
"require": "ts-node/register", | ||
"spec": "./tests/*.test.ts", | ||
"timeout": 100000, | ||
"exit": true | ||
} |
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,17 @@ | ||
{ | ||
"protocol": "plonk", | ||
"optimization": 1, | ||
"prime": "bn128", | ||
"version": "2.1.6", | ||
"circuits": "./circuits.json", | ||
|
||
"dirCircuits": "./src", | ||
"dirInputs": "./src/inputs", | ||
"dirPtau": "./artifacts/ptau", | ||
"dirBuild": "./artifacts/build", | ||
|
||
"prettyCalldata": true, | ||
"inspect": true, | ||
"logLevel": "INFO", | ||
"verbose": true | ||
} |
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,7 @@ | ||
{ | ||
"submit-rangecheck-1-100": { | ||
"file": "submit-rangecheck", | ||
"template": "SubmissionRangeCheck", | ||
"params": [1, 100, 7] | ||
} | ||
} |
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,35 @@ | ||
{ | ||
"name": "circuits", | ||
"version": "0.0.1", | ||
"description": "Guessing game circuits", | ||
"license": "MIT", | ||
"files": [ | ||
"**/*.circom", | ||
"!main", | ||
"!test", | ||
"LICENSE", | ||
"README.md" | ||
], | ||
"scripts": { | ||
"compile": "./scripts/build-circuit.sh", | ||
"prove": "timeout 5s circomkit witness submit-rangecheck-1-100 in-range; timeout 5s circomkit prove submit-rangecheck-1-100 in-range", | ||
"verify": "timeout 5s circomkit verify submit-rangecheck-1-100 in-range", | ||
"clear": "circomkit clear", | ||
"test": "mocha" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"dependencies": { | ||
"circomlib": "2.0.5", | ||
"snarkjs": "^0.7.4" | ||
}, | ||
"devDependencies": { | ||
"@types/mocha": "^10.0.6", | ||
"@types/snarkjs": "^0.7.4", | ||
"@zk-kit/baby-jubjub": "1.0.1", | ||
"circomkit": "^0.2.1", | ||
"mocha": "^10.2.0", | ||
"poseidon-lite": "^0.2.0" | ||
} | ||
} |
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,24 @@ | ||
#!/bin/bash -e | ||
CIRCUIT=$1 | ||
TIMEOUT_SEC="6s" | ||
|
||
# Yellow color escape code | ||
YELLOW='\033[1;33m' | ||
# Reset Color | ||
NC='\033[0m' | ||
|
||
|
||
echo -e "${YELLOW}Compiling ${CIRCUIT}${NC}" | ||
yarn circomkit compile ${CIRCUIT} | ||
|
||
echo -e "\n${YELLOW}Setting up ${CIRCUIT}${NC}" | ||
timeout ${TIMEOUT_SEC} yarn circomkit setup ${CIRCUIT} || true | ||
timeout ${TIMEOUT_SEC} yarn circomkit contract ${CIRCUIT} || true | ||
|
||
echo -e "\n${YELLOW}Copying circuit assets from app/circuits to app/contracts ${NC}" | ||
mkdir -p ../contracts/artifacts/circuits | ||
cp artifacts/build/${CIRCUIT}/${CIRCUIT}.r1cs ../contracts/artifacts/circuits/${CIRCUIT}.r1cs | ||
cp artifacts/build/${CIRCUIT}/plonk_pkey.zkey ../contracts/artifacts/circuits/${CIRCUIT}.zkey | ||
cp artifacts/build/${CIRCUIT}/${CIRCUIT}_js/${CIRCUIT}.wasm ../contracts/artifacts/circuits/${CIRCUIT}.wasm | ||
|
||
cp artifacts/build/${CIRCUIT}/plonk_verifier.sol ../contracts/contracts/${CIRCUIT}_verifier.sol |
3 changes: 3 additions & 0 deletions
3
apps/circuits/src/inputs/submit-rangecheck-1-100/in-range.json
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,3 @@ | ||
{ | ||
"in": 1 | ||
} |
3 changes: 3 additions & 0 deletions
3
apps/circuits/src/inputs/submit-rangecheck-1-100/out-of-range.json
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,3 @@ | ||
{ | ||
"in": 101 | ||
} |
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.1.6; | ||
|
||
include "../submit-rangecheck.circom"; | ||
|
||
component main = SubmissionRangeCheck(1, 100, 7); |
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,17 @@ | ||
pragma circom 2.1.6; | ||
|
||
include "../../../node_modules/circomlib/circuits/comparators.circom"; | ||
|
||
template SubmissionRangeCheck(min, max, nBit) { | ||
signal input in; | ||
signal output out; | ||
|
||
component lessEqThan = LessEqThan(nBit); | ||
lessEqThan.in <== [in, max]; | ||
|
||
component greaterEqThan = GreaterEqThan(nBit); | ||
greaterEqThan.in <== [in, min]; | ||
|
||
out <== lessEqThan.out * greaterEqThan.out; | ||
out === 1; | ||
} |
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,11 @@ | ||
import { Circomkit } from "circomkit"; | ||
import { readFileSync } from "fs"; | ||
import path from "path"; | ||
|
||
const configFilePath = path.join(__dirname, "../circomkit.json"); | ||
const config = JSON.parse(readFileSync(configFilePath, "utf-8")); | ||
|
||
export const circomkit = new Circomkit({ | ||
...config, | ||
verbose: false, | ||
}); |
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,35 @@ | ||
import { WitnessTester } from "circomkit"; | ||
import { circomkit } from "./common"; | ||
|
||
describe("submit-rangecheck", () => { | ||
let circuit: WitnessTester< | ||
["in"] // private inputs | ||
>; | ||
|
||
const [MIN, MAX, NBITS] = [1, 100, 7]; | ||
|
||
before(async () => { | ||
circuit = await circomkit.WitnessTester("submit-rangecheck", { | ||
file: "submit-rangecheck", | ||
template: "SubmissionRangeCheck", | ||
params: [MIN, MAX, NBITS], | ||
}); | ||
}); | ||
|
||
it("Should pass when the value is within range", async () => { | ||
let INPUT = { in: MIN }; | ||
const OUT = { out: 1 }; | ||
await circuit.expectPass(INPUT, OUT); | ||
|
||
INPUT = { in: MAX }; | ||
await circuit.expectPass(INPUT, OUT); | ||
}); | ||
|
||
it("Should fail when the value is out of range", async () => { | ||
let INPUT = { in: MIN - 1 }; | ||
await circuit.expectFail(INPUT); | ||
|
||
INPUT = { in: MAX + 1 }; | ||
await circuit.expectFail(INPUT); | ||
}); | ||
}); |
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,8 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es2020", | ||
"module": "commonjs", | ||
"esModuleInterop": true | ||
}, | ||
"include": ["tests/**/*"] | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.