-
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
0 parents
commit a9dd31d
Showing
16 changed files
with
315 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
dist-newstyle/ | ||
.dockerignore | ||
.gitignore | ||
CHANGELOG.md | ||
Dockerfile | ||
LICENSE | ||
README.md |
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,23 @@ | ||
dist | ||
dist-* | ||
cabal-dev | ||
*.o | ||
*.hi | ||
*.hie | ||
*.chi | ||
*.chs.h | ||
*.dyn_o | ||
*.dyn_hi | ||
.hpc | ||
.hsenv | ||
.cabal-sandbox/ | ||
cabal.sandbox.config | ||
*.prof | ||
*.aux | ||
*.hp | ||
*.eventlog | ||
.stack-work/ | ||
cabal.project.local | ||
cabal.project.local~ | ||
.HTF/ | ||
.ghc.environment.* |
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,5 @@ | ||
# Revision history for zkfold-prover-api | ||
|
||
## 0.1.0.0 -- YYYY-mm-dd | ||
|
||
* First version. Released on an unsuspecting world. |
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,21 @@ | ||
FROM haskell:9.6.3 as build | ||
|
||
WORKDIR /app | ||
|
||
COPY zkfold-prover-api.cabal cabal.project /app/ | ||
|
||
RUN cabal update | ||
|
||
COPY . /app | ||
|
||
RUN cabal build --enable-executable-static --libexecdir=/usr/local/bin | ||
|
||
FROM debian:bullseye-slim | ||
|
||
RUN apt-get update && apt-get install -y libgmp10 && rm -rf /var/lib/apt/lists/* | ||
|
||
WORKDIR /app | ||
|
||
COPY --from=build /usr/local/bin/zkfold-prover-api /app/zkfold-prover-api | ||
|
||
EXPOSE 8080 |
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,20 @@ | ||
Copyright (c) 2024 Vardominator | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
"Software"), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included | ||
in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | ||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
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,23 @@ | ||
APP_NAME=zkfold-prover-api | ||
DOCKER_IMAGE=$(APP_NAME):latest | ||
PORT ?= 8080 | ||
|
||
all: build | ||
|
||
build: | ||
cabal update | ||
cabal build | ||
|
||
run: build | ||
PORT=$(PORT) cabal run | ||
|
||
docker-build: | ||
docker build -t $(DOCKER_IMAGE) . | ||
|
||
docker-run: docker-build | ||
docker run -e PORT=$(PORT) -p $(PORT):$(PORT) $(DOCKER_IMAGE) | ||
|
||
clean: | ||
cabal clean | ||
|
||
.PHONY: all build run docker-build docker-run clean |
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,29 @@ | ||
# zkFold Prover API | ||
REST API server for zkFold proof creation and verification. Leverages the [zkFold Base](https://github.com/zkFold/zkfold-base/tree/main) building blocks. | ||
|
||
In collaboration with [Maestro](https://github.com/maestro-org)! | ||
|
||
<img src="media/cover.png" alt="Cover Image" width="400"> | ||
|
||
# Build | ||
## Source | ||
The package compiles with GHC 9.6.3 and Cabal 3.10.2.1. | ||
``` | ||
make build | ||
``` | ||
## Docker | ||
``` | ||
make docker-build | ||
``` | ||
# Run | ||
## Host | ||
``` | ||
make run | ||
``` | ||
## Docker | ||
``` | ||
make docker-run | ||
``` | ||
|
||
# Tests | ||
On the way! |
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,13 @@ | ||
module Main where | ||
|
||
import Network.Wai.Handler.Warp (run) | ||
import System.Environment (lookupEnv) | ||
import Text.Read (readMaybe) | ||
import Server (app) | ||
|
||
main :: IO () | ||
main = do | ||
portEnv <- lookupEnv "PORT" | ||
let port = maybe 8080 id (portEnv >>= readMaybe) | ||
putStrLn $ "Running server on port " ++ show port | ||
run port app |
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,7 @@ | ||
packages: . | ||
|
||
source-repository-package | ||
type: git | ||
location: https://github.com/zkFold/zkfold-base | ||
tag: main | ||
subdir: . |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 DataKinds #-} | ||
{-# LANGUAGE TypeOperators #-} | ||
|
||
module API.Prove where | ||
|
||
import Servant | ||
import Data.ByteString (ByteString) | ||
import ZkFold.Base.Protocol.NonInteractiveProof (ProveAPIResult) | ||
|
||
type ProveAPI = "prove" :> ReqBody '[OctetStream] ByteString :> ReqBody '[OctetStream] ByteString :> Post '[JSON] ProveAPIResult |
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,18 @@ | ||
{-# LANGUAGE ScopedTypeVariables #-} | ||
{-# LANGUAGE TypeApplications #-} | ||
|
||
module Handlers.ProveHandler where | ||
|
||
import Servant | ||
import Data.ByteString (ByteString) | ||
import ZkFold.Base.Protocol.NonInteractiveProof (proveAPI, ProveAPIResult(..)) | ||
import ZkFold.Base.Data.ByteString (fromByteString) | ||
import Data.Maybe (fromJust) | ||
import Types.ZkProof (ZkProof) | ||
import Types.Instances () | ||
|
||
proveHandler :: ByteString -> ByteString -> Handler ProveAPIResult | ||
proveHandler bsS bsW = do | ||
let setup = fromJust (fromByteString bsS) | ||
witness = fromJust (fromByteString bsW) | ||
return $ proveAPI @ZkProof setup witness |
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,17 @@ | ||
{-# LANGUAGE DataKinds #-} | ||
{-# LANGUAGE TypeOperators #-} | ||
|
||
module Server (app) where | ||
|
||
import Servant | ||
import API.Prove (ProveAPI) | ||
import Handlers.ProveHandler (proveHandler) | ||
import Types.Instances () -- Import the instances | ||
|
||
type API = ProveAPI | ||
|
||
server :: Server API | ||
server = proveHandler | ||
|
||
app :: Application | ||
app = serve (Proxy :: Proxy API) server |
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,47 @@ | ||
{-# LANGUAGE DeriveGeneric #-} | ||
{-# LANGUAGE DeriveAnyClass #-} | ||
|
||
module Types.Instances where | ||
|
||
import GHC.Generics (Generic) | ||
import Data.Aeson (ToJSON, FromJSON, toJSON, parseJSON, withObject, (.:), (.=), object) | ||
import qualified Data.Aeson as Aeson | ||
import qualified Data.ByteString.Base64 as B64 | ||
import qualified Data.ByteString.Char8 as BS | ||
import qualified Data.Text as T | ||
import qualified Data.Aeson.Key as Key | ||
import ZkFold.Base.Protocol.NonInteractiveProof (ProveAPIResult(..)) | ||
|
||
-- Define ToJSON and FromJSON instances for ByteString | ||
instance ToJSON BS.ByteString where | ||
toJSON = Aeson.String . T.pack . BS.unpack . B64.encode | ||
|
||
instance FromJSON BS.ByteString where | ||
parseJSON = Aeson.withText "ByteString" $ \t -> | ||
case B64.decode (BS.pack (T.unpack t)) of | ||
Left err -> fail err | ||
Right bs -> return bs | ||
|
||
-- Define ToJSON and FromJSON instances for ProveAPIResult | ||
instance ToJSON ProveAPIResult where | ||
toJSON (ProveAPISuccess bs) = | ||
object [Key.fromString "status" .= ("success" :: String), Key.fromString "data" .= bs] | ||
toJSON ProveAPIErrorSetup = | ||
object [Key.fromString "status" .= ("error" :: String), Key.fromString "message" .= ("Setup error" :: String)] | ||
toJSON ProveAPIErrorWitness = | ||
object [Key.fromString "status" .= ("error" :: String), Key.fromString "message" .= ("Witness error" :: String)] | ||
|
||
instance FromJSON ProveAPIResult where | ||
parseJSON = withObject "ProveAPIResult" $ \v -> do | ||
status <- v .: Key.fromString "status" | ||
case (status :: String) of | ||
"success" -> do | ||
dataStr <- v .: Key.fromString "data" | ||
return $ ProveAPISuccess dataStr | ||
"error" -> do | ||
message <- v .: Key.fromString "message" | ||
case (message :: String) of | ||
"Setup error" -> return ProveAPIErrorSetup | ||
"Witness error" -> return ProveAPIErrorWitness | ||
_ -> fail "Unknown error message" | ||
_ -> fail "Unknown status" |
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,26 @@ | ||
{-# LANGUAGE DeriveGeneric #-} | ||
{-# LANGUAGE DeriveAnyClass #-} | ||
{-# LANGUAGE TypeFamilies #-} | ||
|
||
module Types.ZkProof where | ||
|
||
import GHC.Generics (Generic) | ||
import Control.DeepSeq (NFData) | ||
import ZkFold.Base.Protocol.NonInteractiveProof | ||
import Data.ByteString (ByteString) | ||
import qualified Data.ByteString as BS (empty) | ||
|
||
-- Define your proof type | ||
data ZkProof = ZkProof | ||
deriving (Show, Eq, Generic, NFData) | ||
|
||
instance NonInteractiveProof ZkProof where | ||
type Transcript ZkProof = ByteString | ||
type Setup ZkProof = ByteString | ||
type Witness ZkProof = ByteString | ||
type Input ZkProof = ByteString | ||
type Proof ZkProof = ByteString | ||
|
||
setup _ = BS.empty | ||
prove _ _ = (BS.empty, BS.empty) | ||
verify _ _ _ = True |
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,49 @@ | ||
cabal-version: 3.0 | ||
name: zkfold-prover-api | ||
version: 0.1.0.0 | ||
synopsis: ZkFold's prover backend API for constructing ZK proofs | ||
homepage: https://zkfold.io/ | ||
license: MIT | ||
license-file: LICENSE | ||
author: Vardominator | ||
maintainer: [email protected] | ||
build-type: Simple | ||
extra-doc-files: CHANGELOG.md | ||
|
||
common warnings | ||
ghc-options: -Wall | ||
|
||
library | ||
hs-source-dirs: src | ||
exposed-modules: Server | ||
, API.Prove | ||
, Handlers.ProveHandler | ||
, Types.ZkProof | ||
, Types.Instances | ||
build-depends: base ^>=4.18.1.0 && <5 | ||
, servant | ||
, servant-server | ||
, aeson | ||
, bytestring | ||
, text | ||
, deepseq | ||
, generic-deriving | ||
, QuickCheck | ||
, cryptohash-sha256 | ||
, base64-bytestring | ||
, warp | ||
, zkfold-base | ||
default-language: Haskell2010 | ||
|
||
executable zkfold-prover-api | ||
import: warnings | ||
main-is: Main.hs | ||
hs-source-dirs: app | ||
build-depends: base ^>=4.18.1.0 && <5 | ||
, zkfold-prover-api | ||
, aeson | ||
, bytestring | ||
, base64-bytestring | ||
, text | ||
, warp | ||
default-language: Haskell2010 |