-
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.
- Loading branch information
Showing
6 changed files
with
28 additions
and
35 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
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 |
---|---|---|
@@ -1,27 +1,31 @@ | ||
module Main (main) where | ||
|
||
import Circuit (solve, lookupVar, assignInputs) | ||
import Circuit (lookupVar) | ||
import R1CS (Witness(..)) | ||
import R1CS.Circom (witnessFromCircomWitness) | ||
import Circuit.Solver.Circom (CircomProgram(..), nativeGenWitness) | ||
import qualified Data.Map as Map | ||
import Protolude | ||
import Test.Hspec | ||
import Test.QuickCheck | ||
import ZK.Factors (Factors (..), Fr, factors) | ||
import ZK.Factors (factors) | ||
|
||
main :: IO () | ||
main = hspec $ do | ||
let circuit = factorsCircuit $ factors @Fr | ||
vars = factorsVars $ factors @Fr | ||
let vars = cpVars factors | ||
describe "Factors" $ do | ||
it "should accept valid factors" $ do | ||
property $ | ||
\x y -> | ||
let inputs = assignInputs vars $ Map.fromList [("n", x * y), ("a", x), ("b", y)] | ||
w = solve vars circuit inputs | ||
let inputs = Map.fromList [("n", x * y), ("a", x), ("b", y)] | ||
Witness w = witnessFromCircomWitness $ | ||
nativeGenWitness factors inputs | ||
in lookupVar vars "out" w === Just 1 | ||
it "shouldn't accept invalid factors" $ do | ||
property $ | ||
\x y z -> | ||
(x * y /= z) ==> | ||
let inputs = assignInputs vars $ Map.fromList [("n", z), ("a", x), ("b", y)] | ||
w = solve vars circuit inputs | ||
let inputs = Map.fromList [("n", z), ("a", x), ("b", y)] | ||
Witness w = witnessFromCircomWitness $ | ||
nativeGenWitness factors inputs | ||
in lookupVar vars "out" w == Just 0 |