Skip to content
This repository has been archived by the owner on Jun 4, 2024. It is now read-only.

Commit

Permalink
Merge pull request #3 from l-adic/update-snarkl
Browse files Browse the repository at this point in the history
update snarkl to lates
  • Loading branch information
martyall authored Jan 27, 2024
2 parents da590c5 + 49f92ea commit 00735ab
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 34 deletions.
2 changes: 1 addition & 1 deletion cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ source-repository-package
source-repository-package
type: git
location: https://github.com/l-adic/snarkl.git
tag: 5d539a7827f570ee6e9dbf9a30e898acccd6c0cb
tag: c2561b898d93fd444ca57aaf8b2ad8b203f19489
--sha256: jHy2OKlvSgBAkvtadvDVB0t3Hr2wTgXTFKW5T2t/yi0=

source-repository-package
Expand Down
4 changes: 2 additions & 2 deletions examples/Examples.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import qualified Snarkl.Toplevel as Snarkl

-- | Little helper to get our expressions into a form that Hedgehog can compare.
comparable :: (Typeable ty, GaloisField k) => Snarkl.Comp ty k -> String
comparable = show . Snarkl.compileCompToR1CS Snarkl.Simplify
comparable = show . Snarkl.compileCompToR1CS [Snarkl.Simplify]

interpretable :: (Typeable ty, GaloisField k) => Snarkl.Comp ty k -> [k] -> k
interpretable = Snarkl.comp_interp
interpretable comp is = Snarkl.comp_interp comp is mempty

prop_simple_bool :: Hedgehog.Property
prop_simple_bool =
Expand Down
10 changes: 5 additions & 5 deletions examples/Examples/Arithmetic.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ module Examples.Arithmetic (simpleBool, simpleArith) where
import qualified Categorifier.Categorify as Categorify
import Categorifier.Vec.Client ()
import Snarkl.Field (F_BN128)
import Snarkl.Language (Ty (..), pair, (>>=))
import qualified Snarkl.Language.SyntaxMonad as Snarkl
import Snarkl.Language.Prelude (Ty (..), pair, (>>=))
import qualified Snarkl.Language.Prelude as Snarkl
import Stalk (Stalk (runStalk))
import Prelude (Bool (..), fromInteger, (*), (+), (-), (==))

Expand All @@ -33,7 +33,7 @@ simpleArith =
compiledProg :: Stalk F_BN128 F_BN128 F_BN128
compiledProg = Categorify.expression prog
in do
z <- Snarkl.fresh_input
z <- Snarkl.fresh_public_input
runStalk compiledProg z

{-
Expand All @@ -57,7 +57,7 @@ simpleBool =
compiledProg :: Stalk F_BN128 (F_BN128, F_BN128) F_BN128
compiledProg = Categorify.expression prog
in do
x <- Snarkl.fresh_input
y <- Snarkl.fresh_input
x <- Snarkl.fresh_public_input
y <- Snarkl.fresh_public_input
p <- pair x y
runStalk compiledProg p
8 changes: 4 additions & 4 deletions examples/Examples/Lens.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import qualified Categorifier.Categorify as Categorify
import Categorifier.Client
import Control.Lens
import Snarkl.Field (F_BN128)
import Snarkl.Language (Ty (TField), pair, (>>=))
import qualified Snarkl.Language.SyntaxMonad as Snarkl
import Snarkl.Language.Prelude (Ty (TField), pair, (>>=))
import qualified Snarkl.Language.Prelude as Snarkl
import Stalk
import Prelude (fromInteger)

Expand Down Expand Up @@ -43,8 +43,8 @@ simpleLens =
compiledProg :: Stalk F_BN128 (F_BN128, F_BN128) F_BN128
compiledProg = Categorify.expression prog
in do
x <- Snarkl.fresh_input
y <- Snarkl.fresh_input
x <- Snarkl.fresh_public_input
y <- Snarkl.fresh_public_input
p <- pair x y
runStalk compiledProg p

Expand Down
2 changes: 1 addition & 1 deletion examples/Examples/Snarkl.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module Examples.Snarkl
where

import Snarkl.Field (F_BN128)
import Snarkl.Language (Comp, TExp, Ty (..), arr, forall, fromField, get, return, set, (+), (>>), (>>=))
import Snarkl.Language.Prelude (Comp, TExp, Ty (..), arr, forall, fromField, get, return, set, (+), (>>), (>>=))
import Prelude (fromInteger, ($))

arr_ex :: TExp 'TField F_BN128 -> Comp 'TField F_BN128
Expand Down
16 changes: 8 additions & 8 deletions examples/Examples/SnarklUnitTests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ module Examples.SnarklUnitTests where
import qualified Categorifier.Categorify as Categorify
import Categorifier.Vec.Client ()
import Snarkl.Field (F_BN128)
import Snarkl.Language (Ty (TField), pair, (>>=))
import qualified Snarkl.Language.SyntaxMonad as Snarkl
import Snarkl.Language.Prelude (Ty (TField), pair, (>>=))
import qualified Snarkl.Language.Prelude as Snarkl
import Stalk
import Prelude (Bool (..), fromInteger, (&&), (*), (+), (-))

Expand All @@ -30,9 +30,9 @@ prog1 =
compiledProg :: Stalk F_BN128 (Bool, (F_BN128, Bool)) F_BN128
compiledProg = Categorify.expression prog
in do
x <- Snarkl.fresh_input
y <- Snarkl.fresh_input
z <- Snarkl.fresh_input
x <- Snarkl.fresh_public_input
y <- Snarkl.fresh_public_input
z <- Snarkl.fresh_public_input
yz <- pair y z
p <- pair x yz
runStalk compiledProg p
Expand Down Expand Up @@ -68,8 +68,8 @@ bool_prog9 =
compiledProg :: Stalk F_BN128 (Bool, Bool) Bool
compiledProg = Categorify.expression prog
in do
x <- Snarkl.fresh_input
y <- Snarkl.fresh_input
x <- Snarkl.fresh_public_input
y <- Snarkl.fresh_public_input
p <- pair x y
runStalk compiledProg p

Expand All @@ -87,4 +87,4 @@ bool_prog9 =
-- = do { e1 <- fresh_input
-- ; e2 <- fresh_input
-- ; return (e1 && e2)
-- }
-- }
12 changes: 6 additions & 6 deletions examples/Examples/Stalk.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import Data.Either (fromLeft)
import Data.Field.Galois (GaloisField)
import Data.Vec.Lazy (Vec (..))
import Snarkl.Field (F_BN128)
import qualified Snarkl.Language as Snarkl
import qualified Snarkl.Language.Prelude as Snarkl
import Stalk
import "snarkl" Snarkl.Language (fromField, (>>=))
import "snarkl" Snarkl.Language.Prelude (Comp, fromField, (>>=))
import Prelude (Bool (..), Either (..), fromInteger, sum, ($), (*), (+), (.))

-- * Basic
Expand All @@ -44,9 +44,9 @@ arr_ex x =
p1 :: Snarkl.Comp 'Snarkl.TField F_BN128
p1 = runStalk (Categorify.expression arr_ex) (fromField @F_BN128 1)

p2 :: Snarkl.State (Snarkl.Env F_BN128) (Snarkl.TExp 'Snarkl.TField F_BN128)
p2 :: Snarkl.Comp 'Snarkl.TField F_BN128
p2 =
Snarkl.fresh_input
Snarkl.fresh_public_input
>>= runStalk (Categorify.expression $ \(x :: F_BN128) -> x + x)

comp1 :: Either Bool F_BN128
Expand All @@ -56,8 +56,8 @@ comp2 :: Either Bool F_BN128
comp2 = Right 0

-- | __TODO__: Needs @`ConCat.Category.ClosedCat` `Stalk`@
test1 :: Snarkl.State (Snarkl.Env F_BN128) (Snarkl.TExp 'Snarkl.TBool F_BN128)
test1 :: Comp 'Snarkl.TBool F_BN128
test1 =
Snarkl.fresh_input
Snarkl.fresh_public_input
>>= runStalk
(Categorify.expression $ fromLeft False . bool comp2 comp1)
14 changes: 7 additions & 7 deletions src/Stalk.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import Categorifier.Category
)
import qualified Categorifier.Category as Categorifier
import Categorifier.Vec.Client ()
import qualified ConCat.Category as ConCat
import qualified ConCat.Additive
import qualified ConCat.Category as ConCat
import Data.Bool (bool)
import qualified Data.Constraint as Constraint
import Data.Field.Galois (GaloisField)
Expand All @@ -37,11 +37,11 @@ import Data.Type.Nat (Nat (..))
import qualified Data.Type.Nat as Nat
import Data.Typeable (Typeable)
import Data.Vec.Lazy (Vec (..))
import GHC.Natural (Natural)
import Snarkl.Field (F_BN128)
import Snarkl.Language (return, (>>), (>>=))
import qualified Snarkl.Language as Snarkl
import Snarkl.Language.Prelude (return, (>>), (>>=))
import qualified Snarkl.Language.Prelude as Snarkl
import Prelude (Bool, Either, error, fromInteger, ($), (+), (.))
import GHC.Natural (Natural)

-- | Mapping from Haskell types to Snarkl types.
data Stalk k a b = Stalk
Expand Down Expand Up @@ -205,8 +205,8 @@ instance (ConCat.Additive.Additive k, Nat.SNatI n, GaloisField k, SnarklTy k ~ '
(\n' e -> Snarkl.get (a, n') >>= (return . (Snarkl.+ e)))
(Snarkl.fromField 0)

instance GaloisField k => ConCat.Additive.Additive k where
zero = 0
instance (GaloisField k) => ConCat.Additive.Additive k where
zero = 0
(^+^) = (+)

instance
Expand Down Expand Up @@ -247,7 +247,7 @@ cat ::
(Typeable (SnarklTy b)) =>
Snarkl.TExp (SnarklTy (a -> b)) k ->
Stalk k a b
cat f = Stalk $ \x -> return $ Snarkl.TEApp f x
cat f = Stalk $ \x -> Snarkl.apply f x

lowerCat ::
(Typeable (SnarklTy a)) =>
Expand Down
2 changes: 2 additions & 0 deletions stalk.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ test-suite examples
, snarkl
, stalk
, vec
, wl-pprint-text


default-language: Haskell2010
ghc-options:
Expand Down

0 comments on commit 00735ab

Please sign in to comment.