-
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.
Merge pull request #5 from l-adic/circom-program
Circom program
- Loading branch information
Showing
23 changed files
with
137 additions
and
689 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 |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
dist-newstyle | ||
www/circuit_final.zkey | ||
www/circuit.wasm | ||
www/circuit.bin | ||
output | ||
.spago | ||
.purs-repl | ||
|
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{-# LANGUAGE TemplateHaskell #-} | ||
|
||
module Main where | ||
|
||
import Circom.CLI (defaultMain) | ||
import Protolude | ||
import ZK.Factors (Fr, factors) | ||
|
||
main :: IO () | ||
main = defaultMain "circuit" $ factors @Fr |
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 |
---|---|---|
@@ -1,27 +1,49 @@ | ||
module Main (main) where | ||
|
||
import Circuit (solve, lookupVar, assignInputs) | ||
import Circom.R1CS (witnessFromCircomWitness) | ||
import Circom.Solver (CircomProgram (..), mkCircomProgram, nativeGenWitness) | ||
import Circuit | ||
import Circuit.Language | ||
import qualified Data.Map as Map | ||
import Protolude | ||
import R1CS (Witness (..)) | ||
import Test.Hspec | ||
import Test.QuickCheck | ||
import ZK.Factors (Factors (..), Fr, factors) | ||
import ZK.Factors (Fr, factors) | ||
import Data.Binary (encode, decode) | ||
|
||
main :: IO () | ||
main = hspec $ do | ||
let circuit = factorsCircuit $ factors @Fr | ||
vars = factorsVars $ factors @Fr | ||
let BuilderState {bsVars, bsCircuit} = snd $ runCircuitBuilder (factors @Fr) | ||
program = mkCircomProgram bsVars bsCircuit | ||
vars = cpVars program | ||
describe "Factors" $ do | ||
it "should accept valid factors" $ do | ||
it "can serialize/deserialize the program" $ do | ||
let a = decode (encode program) | ||
cpCircuit a `shouldBe` cpCircuit program | ||
|
||
it "should accept valid factorizations" $ | ||
property $ | ||
\x y -> | ||
let inputs = assignInputs vars $ Map.fromList [("n", x * y), ("a", x), ("b", y)] | ||
w = solve vars circuit inputs | ||
in lookupVar vars "out" w === Just 1 | ||
it "shouldn't accept invalid factors" $ do | ||
(x /= 1 && y /= 1) ==> | ||
let inputs = Map.fromList [("n", x * y), ("a", x), ("b", y)] | ||
Witness w = | ||
witnessFromCircomWitness $ | ||
nativeGenWitness program inputs | ||
in lookupVar vars "out" w === Just 1 | ||
it "shouldn't accept trivial factorizations" $ | ||
property $ \x -> | ||
let inputs = Map.fromList [("n", x), ("a", 1), ("b", x)] | ||
Witness w = | ||
witnessFromCircomWitness $ | ||
nativeGenWitness program inputs | ||
in lookupVar vars "out" w == Just 0 | ||
it "shouldn't accept invalid factorizations" $ | ||
property $ | ||
\x y z -> | ||
(x * y /= z) ==> | ||
let inputs = assignInputs vars $ Map.fromList [("n", z), ("a", x), ("b", y)] | ||
w = solve vars circuit inputs | ||
in lookupVar vars "out" w == Just 0 | ||
let inputs = Map.fromList [("n", z), ("a", x), ("b", y)] | ||
Witness w = | ||
witnessFromCircomWitness $ | ||
nativeGenWitness program inputs | ||
in lookupVar vars "out" w == Just 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
Oops, something went wrong.