Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix secret params #453

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 18 additions & 12 deletions symbolic-base/src/ZkFold/Base/Protocol/Plonk.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module ZkFold.Base.Protocol.Plonk (

import Data.Binary (Binary)
import Data.Functor.Classes (Show1)
import Data.Functor.Rep (Rep)
import Data.Functor.Rep (Rep, Representable)
import Data.Kind (Type)
import Data.Word (Word8)
import Prelude hiding (Num (..), div, drop, length, replicate,
Expand All @@ -16,19 +16,21 @@ import qualified Prelude as P hiding
import Test.QuickCheck (Arbitrary (..))

import ZkFold.Base.Algebra.Basic.Class (AdditiveGroup)
import ZkFold.Base.Algebra.Basic.Number
import ZkFold.Base.Algebra.EllipticCurve.Class
import ZkFold.Base.Protocol.NonInteractiveProof
import ZkFold.Base.Algebra.Basic.Number (KnownNat, Natural)
import ZkFold.Base.Algebra.EllipticCurve.Class (CompressedPoint, EllipticCurve (..), Pairing)
import ZkFold.Base.Protocol.NonInteractiveProof.Internal (CoreFunction, FromTranscript,
NonInteractiveProof (..), ToTranscript)
import ZkFold.Base.Protocol.Plonk.Prover (plonkProve)
import ZkFold.Base.Protocol.Plonk.Verifier (plonkVerify)
import ZkFold.Base.Protocol.Plonkup.Input
import ZkFold.Base.Protocol.Plonkup.Internal
import ZkFold.Base.Protocol.Plonkup.Proof
import ZkFold.Base.Protocol.Plonkup.Prover
import ZkFold.Base.Protocol.Plonkup.Verifier
import ZkFold.Base.Protocol.Plonkup.Witness
import ZkFold.Symbolic.Compiler (desugarRanges)
import ZkFold.Symbolic.Compiler.ArithmeticCircuit.Internal
import ZkFold.Base.Protocol.Plonkup.Input (PlonkupInput)
import ZkFold.Base.Protocol.Plonkup.Internal (Plonkup (..))
import ZkFold.Base.Protocol.Plonkup.Proof (PlonkupProof)
import ZkFold.Base.Protocol.Plonkup.Prover.Secret (PlonkupProverSecret)
import ZkFold.Base.Protocol.Plonkup.Prover.Setup (PlonkupProverSetup)
import ZkFold.Base.Protocol.Plonkup.Verifier.Setup (PlonkupVerifierSetup)
import ZkFold.Base.Protocol.Plonkup.Witness (PlonkupWitnessInput)
import ZkFold.Symbolic.Compiler.ArithmeticCircuit (desugarRanges)
import ZkFold.Symbolic.Compiler.ArithmeticCircuit.Internal (Arithmetic, ArithmeticCircuit (..))
import qualified ZkFold.Symbolic.Data.Ord as Sym

{-| Based on the paper https://eprint.iacr.org/2019/953.pdf -}
Expand Down Expand Up @@ -72,6 +74,9 @@ instance forall p i n l c1 c2 (ts :: Type) core .
, Proof (Plonkup p i n l c1 c2 ts) ~ PlonkupProof c1
, KnownNat n
, Foldable l
, Representable p
, Representable i
, Representable l
, Sym.Ord (BooleanOf c1) (BaseField c1)
, AdditiveGroup (BaseField c1)
, Pairing c1 c2
Expand All @@ -81,6 +86,7 @@ instance forall p i n l c1 c2 (ts :: Type) core .
, ToTranscript ts (CompressedPoint c1)
, FromTranscript ts (ScalarField c1)
, CoreFunction c1 core
, Binary (ScalarField c2)
) => NonInteractiveProof (Plonk p i n l c1 c2 ts) core where
type Transcript (Plonk p i n l c1 c2 ts) = ts
type SetupProve (Plonk p i n l c1 c2 ts) = PlonkupProverSetup p i n l c1 c2
Expand Down
40 changes: 26 additions & 14 deletions symbolic-base/src/ZkFold/Base/Protocol/Plonk/Prover.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ module ZkFold.Base.Protocol.Plonk.Prover
( plonkProve
) where

import Data.Binary (Binary, Word8)
import Data.Bool (bool)
import Data.Functor.Rep (Representable)
import qualified Data.Vector as V
import Data.Word (Word8)
import GHC.IsList (IsList (..))
import Prelude hiding (Num (..), Ord, drop, length, pi, sum, take,
(!!), (/), (^))
Expand All @@ -16,20 +17,21 @@ import ZkFold.Base.Algebra.Basic.Number (KnownNat,
import ZkFold.Base.Algebra.EllipticCurve.Class (CompressedPoint, EllipticCurve (..), compress)
import ZkFold.Base.Algebra.Polynomials.Univariate hiding (qr)
import ZkFold.Base.Data.Vector ((!!))
import ZkFold.Base.Protocol.NonInteractiveProof
import ZkFold.Base.Protocol.Plonkup (with4n6)
import ZkFold.Base.Protocol.Plonkup.Input
import ZkFold.Base.Protocol.Plonkup.Internal (PlonkupPolyExtended, PlonkupPolyExtendedLength)
import ZkFold.Base.Protocol.Plonkup.Proof
import ZkFold.Base.Protocol.Plonkup.Prover.Polynomials
import ZkFold.Base.Protocol.Plonkup.Prover.Secret
import ZkFold.Base.Protocol.Plonkup.Prover.Setup
import ZkFold.Base.Protocol.NonInteractiveProof.Internal (CoreFunction (..), FromTranscript, ToTranscript,
challenge, transcript)
import ZkFold.Base.Protocol.Plonkup.Input (PlonkupInput (..))
import ZkFold.Base.Protocol.Plonkup.Internal (PlonkupPolyExtended, PlonkupPolyExtendedLength,
with4n6)
import ZkFold.Base.Protocol.Plonkup.Proof (PlonkupProof (..))
import ZkFold.Base.Protocol.Plonkup.Prover.Polynomials (PlonkupCircuitPolynomials (..))
import ZkFold.Base.Protocol.Plonkup.Prover.Secret (PlonkupProverSecret (..))
import ZkFold.Base.Protocol.Plonkup.Prover.Setup (PlonkupProverSetup (..))
import ZkFold.Base.Protocol.Plonkup.Relation (PlonkupRelation (..))
import ZkFold.Base.Protocol.Plonkup.Testing (PlonkupProverTestInfo (..))
import ZkFold.Base.Protocol.Plonkup.Utils (sortByList)
import ZkFold.Base.Protocol.Plonkup.Witness
import ZkFold.Symbolic.Compiler.ArithmeticCircuit.Internal
import ZkFold.Symbolic.Data.Ord
import ZkFold.Base.Protocol.Plonkup.Witness (PlonkupWitnessInput (..))
import ZkFold.Symbolic.Compiler.ArithmeticCircuit.Internal (Arithmetic, indexW)
import ZkFold.Symbolic.Data.Ord (Ord)

plonkProve :: forall p i n l c1 c2 ts core .
( KnownNat n
Expand All @@ -42,6 +44,10 @@ plonkProve :: forall p i n l c1 c2 ts core .
, ToTranscript ts (CompressedPoint c1)
, FromTranscript ts (ScalarField c1)
, CoreFunction c1 core
, Representable p
, Representable i
, Functor l
, Binary (ScalarField c1)
) => PlonkupProverSetup p i n l c1 c2 -> (PlonkupWitnessInput p i c1, PlonkupProverSecret c1) -> (PlonkupInput l c1, PlonkupProof c1, PlonkupProverTestInfo n c1)
plonkProve PlonkupProverSetup {..}
(PlonkupWitnessInput wExtra wInput, PlonkupProverSecret ps)
Expand All @@ -56,8 +62,14 @@ plonkProve PlonkupProverSetup {..}
n = value @n
zhX = with4n6 @n $ polyVecZero @_ @n @(PlonkupPolyExtendedLength n)

(w1, w2, w3) = witness relation wExtra wInput
wPub = pubInput relation wExtra wInput
w1' e i = toPolyVec $ fromList $ fmap (indexW (plonkupAC relation) e i) (plonkupA relation)
w2' e i = toPolyVec $ fromList $ fmap (indexW (plonkupAC relation) e i) (plonkupB relation)
w3' e i = toPolyVec $ fromList $ fmap (indexW (plonkupAC relation) e i) (plonkupC relation)
witness e i = (w1' e i, w2' e i, w3' e i)
pubInput e i = fmap (indexW (plonkupAC relation) e i) (xPub relation)

(w1, w2, w3) = witness wExtra wInput
wPub = pubInput wExtra wInput

w1X = with4n6 @n $ polyVecInLagrangeBasis omega w1 :: PlonkupPolyExtended n c1
w2X = with4n6 @n $ polyVecInLagrangeBasis omega w2 :: PlonkupPolyExtended n c1
Expand Down
38 changes: 20 additions & 18 deletions symbolic-base/src/ZkFold/Base/Protocol/Plonkup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,28 @@ module ZkFold.Base.Protocol.Plonkup (
Plonkup (..)
) where

import Data.Binary (Binary)
import Data.Functor.Rep (Rep, Representable)
import Data.Word (Word8)
import Prelude hiding (Num (..), div, drop, length, replicate,
sum, take, (!!), (/), (^))
import qualified Prelude as P hiding (length)
import Data.Binary (Binary)
import Data.Functor.Rep (Rep, Representable)
import Data.Word (Word8)
import Prelude hiding (Num (..), div, drop, length, replicate, sum,
take, (!!), (/), (^))
import qualified Prelude as P hiding (length)

import ZkFold.Base.Algebra.Basic.Class
import ZkFold.Base.Algebra.Basic.Number
import ZkFold.Base.Algebra.EllipticCurve.Class (CompressedPoint, EllipticCurve (..), Pairing (..))
import ZkFold.Base.Protocol.NonInteractiveProof
import ZkFold.Base.Protocol.Plonkup.Input
import ZkFold.Base.Algebra.Basic.Class (AdditiveGroup)
import ZkFold.Base.Algebra.Basic.Number (KnownNat)
import ZkFold.Base.Algebra.EllipticCurve.Class (CompressedPoint, EllipticCurve (..), Pairing (..))
import ZkFold.Base.Protocol.NonInteractiveProof.Internal (CoreFunction, FromTranscript,
NonInteractiveProof (..), ToTranscript)
import ZkFold.Base.Protocol.Plonkup.Input (PlonkupInput)
import ZkFold.Base.Protocol.Plonkup.Internal
import ZkFold.Base.Protocol.Plonkup.Proof
import ZkFold.Base.Protocol.Plonkup.Prover
import ZkFold.Base.Protocol.Plonkup.Setup
import ZkFold.Base.Protocol.Plonkup.Verifier
import ZkFold.Base.Protocol.Plonkup.Witness
import ZkFold.Symbolic.Compiler.ArithmeticCircuit.Internal
import qualified ZkFold.Symbolic.Data.Ord as Sym
import ZkFold.Base.Protocol.Plonkup.Proof (PlonkupProof)
import ZkFold.Base.Protocol.Plonkup.Prover (PlonkupProverSecret, PlonkupProverSetup (..),
plonkupProve)
import ZkFold.Base.Protocol.Plonkup.Setup (PlonkupSetup (..), plonkupSetup)
import ZkFold.Base.Protocol.Plonkup.Verifier (PlonkupVerifierSetup (..), plonkupVerify)
import ZkFold.Base.Protocol.Plonkup.Witness (PlonkupWitnessInput)
import ZkFold.Symbolic.Class (Arithmetic)
import qualified ZkFold.Symbolic.Data.Ord as Sym

{-| Based on the paper https://eprint.iacr.org/2022/086.pdf -}

Expand Down
29 changes: 21 additions & 8 deletions symbolic-base/src/ZkFold/Base/Protocol/Plonkup/Prover.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ module ZkFold.Base.Protocol.Plonkup.Prover
, plonkupProve
) where

import Data.Binary (Binary)
import Data.Bool (bool)
import Data.Functor.Rep (Representable)
import qualified Data.Vector as V
import Data.Word (Word8)
import GHC.IsList (IsList (..))
Expand All @@ -19,19 +21,20 @@ import ZkFold.Base.Algebra.Basic.Number (KnownNat,
import ZkFold.Base.Algebra.EllipticCurve.Class (CompressedPoint, EllipticCurve (..), compress)
import ZkFold.Base.Algebra.Polynomials.Univariate hiding (qr)
import ZkFold.Base.Data.Vector ((!!))
import ZkFold.Base.Protocol.NonInteractiveProof
import ZkFold.Base.Protocol.Plonkup.Input
import ZkFold.Base.Protocol.NonInteractiveProof.Internal (CoreFunction (..), FromTranscript, ToTranscript,
challenge, transcript)
import ZkFold.Base.Protocol.Plonkup.Input (PlonkupInput (..))
import ZkFold.Base.Protocol.Plonkup.Internal (PlonkupPolyExtended, PlonkupPolyExtendedLength)
import ZkFold.Base.Protocol.Plonkup.Proof
import ZkFold.Base.Protocol.Plonkup.Proof (PlonkupProof (..))
import ZkFold.Base.Protocol.Plonkup.Prover.Polynomials
import ZkFold.Base.Protocol.Plonkup.Prover.Secret
import ZkFold.Base.Protocol.Plonkup.Prover.Setup
import ZkFold.Base.Protocol.Plonkup.Relation (PlonkupRelation (..))
import ZkFold.Base.Protocol.Plonkup.Testing (PlonkupProverTestInfo (..))
import ZkFold.Base.Protocol.Plonkup.Utils (sortByList)
import ZkFold.Base.Protocol.Plonkup.Witness
import ZkFold.Symbolic.Compiler.ArithmeticCircuit.Internal
import ZkFold.Symbolic.Data.Ord
import ZkFold.Base.Protocol.Plonkup.Witness (PlonkupWitnessInput (..))
import ZkFold.Symbolic.Compiler.ArithmeticCircuit.Internal (Arithmetic, indexW)
import ZkFold.Symbolic.Data.Ord (Ord)

plonkupProve :: forall p i n l c1 c2 ts core .
( KnownNat n
Expand All @@ -45,6 +48,10 @@ plonkupProve :: forall p i n l c1 c2 ts core .
, ToTranscript ts (CompressedPoint c1)
, FromTranscript ts (ScalarField c1)
, CoreFunction c1 core
, Representable p
, Representable i
, Functor l
, Binary (ScalarField c1)
) => PlonkupProverSetup p i n l c1 c2 -> (PlonkupWitnessInput p i c1, PlonkupProverSecret c1) -> (PlonkupInput l c1, PlonkupProof c1, PlonkupProverTestInfo n c1)
plonkupProve PlonkupProverSetup {..}
(PlonkupWitnessInput wExtra wInput, PlonkupProverSecret ps)
Expand All @@ -59,8 +66,14 @@ plonkupProve PlonkupProverSetup {..}
n = value @n
zhX = polyVecZero @_ @n @(PlonkupPolyExtendedLength n)

(w1, w2, w3) = witness relation wExtra wInput
wPub = pubInput relation wExtra wInput
w1' e i = toPolyVec $ fromList $ fmap (indexW (plonkupAC relation) e i) (plonkupA relation)
w2' e i = toPolyVec $ fromList $ fmap (indexW (plonkupAC relation) e i) (plonkupB relation)
w3' e i = toPolyVec $ fromList $ fmap (indexW (plonkupAC relation) e i) (plonkupC relation)
witness e i = (w1' e i, w2' e i, w3' e i)
pubInput e i = fmap (indexW (plonkupAC relation) e i) (xPub relation)

(w1, w2, w3) = witness wExtra wInput
wPub = pubInput wExtra wInput

w1X = polyVecInLagrangeBasis omega w1 :: PlonkupPolyExtended n c1
w2X = polyVecInLagrangeBasis omega w2 :: PlonkupPolyExtended n c1
Expand Down
Loading