This repository has been archived by the owner on Jun 4, 2024. It is now read-only.
-
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 #8 from torsion-labs/cli
Add CLI
- Loading branch information
Showing
24 changed files
with
1,051 additions
and
423 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 |
---|---|---|
|
@@ -18,7 +18,7 @@ jobs: | |
uses: jaxxstorm/[email protected] | ||
with: | ||
repo: torsion-labs/arkworks-bridge | ||
tag: v0.2.0 | ||
tag: v1.0.0-rc1 | ||
|
||
- uses: cachix/install-nix-action@v24 | ||
with: | ||
|
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,29 +1,9 @@ | ||
module Main where | ||
|
||
import Control.Monad (unless) | ||
import qualified Data.ByteString.Lazy as LBS | ||
import Data.Field.Galois (PrimeField) | ||
import Data.Typeable (Typeable) | ||
import Snarkl.Compile (SimplParam (NoSimplify)) | ||
import Snarkl.Errors (ErrMsg (ErrMsg), failWith) | ||
import Snarkl.Field | ||
import Snarkl.Toplevel | ||
import Snarkl.CLI (defaultMain) | ||
import Snarkl.Field (F_BN128) | ||
import Snarkl.Toplevel (Comp, Ty (TField)) | ||
import qualified Test.Snarkl.Unit.Programs as Programs | ||
|
||
main :: IO () | ||
main = do | ||
executeAndWriteArtifacts "./snarkl-output" "prog2" NoSimplify (Programs.prog2 10) [1 :: F_BN128] | ||
|
||
executeAndWriteArtifacts :: (Typeable ty, PrimeField k) => FilePath -> String -> SimplParam -> Comp ty k -> [k] -> IO () | ||
executeAndWriteArtifacts fp name simpl mf inputs = do | ||
let Result {result_sat = isSatisfied, result_r1cs = r1cs, result_witness = wit} = execute simpl mf inputs | ||
unless isSatisfied $ failWith $ ErrMsg "R1CS is not satisfied" | ||
let r1csFP = mkR1CSFilePath fp name | ||
LBS.writeFile r1csFP (serializeR1CSAsJson r1cs) | ||
putStrLn $ "Wrote R1CS to file " <> r1csFP | ||
let witnessFP = mkWitnessFilePath fp name | ||
LBS.writeFile witnessFP (serializeWitnessAsJson r1cs wit) | ||
putStrLn $ "Wrote witness to file " <> witnessFP | ||
let inputsFP = mkInputsFilePath fp name | ||
LBS.writeFile inputsFP (serializeInputsAsJson r1cs inputs) | ||
putStrLn $ "Wrote inputs to file " <> inputsFP | ||
main = defaultMain "prog" (Programs.prog2 10 :: Comp 'TField F_BN128) |
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 |
---|---|---|
@@ -0,0 +1,67 @@ | ||
module Data.JSONLines | ||
( ToJSONLines (..), | ||
FromJSONLines (..), | ||
JSONLine (..), | ||
WithHeader (..), | ||
NoHeader (..), | ||
) | ||
where | ||
|
||
import qualified Data.Aeson as A | ||
import Data.ByteString.Builder (Builder, lazyByteString, toLazyByteString) | ||
import qualified Data.ByteString.Lazy as LBS | ||
import Data.Kind (Type) | ||
import Data.String.Conversions (LazyByteString) | ||
|
||
data JSONLine | ||
= JSONLine Builder | ||
| EmptyLine | ||
|
||
instance Semigroup JSONLine where | ||
EmptyLine <> a = a | ||
a <> EmptyLine = a | ||
JSONLine a <> JSONLine b = JSONLine (a <> "\n" <> b) | ||
|
||
instance Monoid JSONLine where | ||
mempty = EmptyLine | ||
|
||
data WithHeader :: Type -> Type -> Type where | ||
WithHeader :: hdr -> [item] -> WithHeader hdr item | ||
|
||
newtype NoHeader item = NoHeader [item] | ||
|
||
jsonlBuilder :: | ||
(Foldable t) => | ||
(A.ToJSON a) => | ||
t a -> | ||
JSONLine | ||
jsonlBuilder = foldMap jsonLine | ||
|
||
jsonLine :: (A.ToJSON a) => a -> JSONLine | ||
jsonLine = JSONLine . lazyByteString . A.encode | ||
|
||
toBS :: JSONLine -> LBS.ByteString | ||
toBS EmptyLine = mempty | ||
toBS (JSONLine a) = toLazyByteString a | ||
|
||
class ToJSONLines a where | ||
toJSONLines :: a -> LBS.ByteString | ||
|
||
instance (A.ToJSON item) => ToJSONLines (NoHeader item) where | ||
toJSONLines (NoHeader items) = toBS . jsonlBuilder $ items | ||
|
||
instance (A.ToJSON hdr, A.ToJSON item) => ToJSONLines (WithHeader hdr item) where | ||
toJSONLines (WithHeader hdr items) = toBS $ jsonLine hdr <> jsonlBuilder items | ||
|
||
class FromJSONLines a where | ||
fromJSONLines :: [LazyByteString] -> Either String a | ||
|
||
instance (A.FromJSON item) => FromJSONLines (NoHeader item) where | ||
fromJSONLines items = NoHeader <$> traverse A.eitherDecode items | ||
|
||
instance (A.FromJSON hdr, A.FromJSON item) => FromJSONLines (WithHeader hdr item) where | ||
fromJSONLines (h : is) = do | ||
hdr <- A.eitherDecode h | ||
items <- traverse A.eitherDecode is | ||
pure $ WithHeader hdr items | ||
fromJSONLines [] = Left "Empty file" |
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,10 +1,8 @@ | ||
module Snarkl.Backend.R1CS | ||
( module Snarkl.Backend.R1CS.R1CS, | ||
module Snarkl.Backend.R1CS.Serialize, | ||
module Snarkl.Backend.R1CS.Poly, | ||
) | ||
where | ||
|
||
import Snarkl.Backend.R1CS.Poly | ||
import Snarkl.Backend.R1CS.R1CS | ||
import Snarkl.Backend.R1CS.Serialize |
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.