forked from sdiehl/arithmetic-circuits
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Example.hs
38 lines (32 loc) · 895 Bytes
/
Example.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import Circuit.Arithmetic
import Circuit.Expr
import Circuit.Lang
import qualified Data.Map as Map
import Data.Pairing.BN254 (Fr, getRootOfUnity)
import Fresh (evalFresh, fresh)
import Protolude
import QAP
program :: ArithCircuit Fr
program =
execCircuitBuilder
( do
i0 <- fmap deref input
i1 <- fmap deref input
i2 <- fmap deref input
let r0 = mul i0 i1
r1 = mul r0 (add i0 i2)
ret r1
)
roots :: [[Fr]]
roots = evalFresh (generateRoots (fmap (fromIntegral . (+ 1)) fresh) program)
qap :: QAP Fr
qap = arithCircuitToQAPFFT getRootOfUnity roots program
inputs :: Map.Map Int Fr
inputs = Map.fromList [(0, 7), (1, 5), (2, 4)]
assignment :: QapSet Fr
assignment = generateAssignment program inputs
main :: IO ()
main =
if verifyAssignment qap assignment
then putText "Valid assignment"
else putText "Invalid assignment"