Skip to content

Commit

Permalink
Merge pull request #110 from zkFold/vlasin-add-proveAPI
Browse files Browse the repository at this point in the history
Add proveAPI
  • Loading branch information
vlasin authored May 14, 2024
2 parents a6f76af + 7e4c20d commit bd28079
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/ZkFold/Base/Protocol/NonInteractiveProof.hs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE TypeApplications #-}

module ZkFold.Base.Protocol.NonInteractiveProof where

import Control.DeepSeq (NFData)
import Crypto.Hash.SHA256 (hash)
import Data.ByteString (ByteString, cons)
import Data.Maybe (fromJust)
import GHC.Generics (Generic)
import Numeric.Natural (Natural)
import Prelude

Expand Down Expand Up @@ -58,3 +61,23 @@ class NonInteractiveProof a where

verify :: Setup a -> Input a -> Proof a -> Bool

data ProveAPIResult = ProveAPISuccess ByteString | ProveAPIErrorSetup | ProveAPIErrorWitness
deriving (Show, Eq, Generic, NFData)

proveAPI
:: forall a
. (NonInteractiveProof a
, Binary (Setup a)
, Binary (Witness a)
, Binary (Input a)
, Binary (Proof a))
=> ByteString
-> ByteString
-> ProveAPIResult
proveAPI bsS bsW =
let mS = fromByteString bsS
mW = fromByteString bsW
in case (mS, mW) of
(Nothing, _) -> ProveAPIErrorSetup
(_, Nothing) -> ProveAPIErrorWitness
(Just s, Just w) -> ProveAPISuccess $ toByteString $ prove @a s w

0 comments on commit bd28079

Please sign in to comment.