{-# LANGUAGE UndecidableInstances #-}

module ZkFold.Base.Protocol.Plonkup.Witness where

import           Control.Applicative                     ((<*>))
import           Data.Functor                            ((<$>))
import           Data.Functor.Classes                    (Show1)
import           Data.List                               ((++))
import           Test.QuickCheck                         (Arbitrary (..), Arbitrary1, arbitrary1)
import           Text.Show                               (Show, show)

import           ZkFold.Base.Algebra.EllipticCurve.Class (EllipticCurve (..))

data PlonkupWitnessInput p i c = PlonkupWitnessInput
  { forall {k} (p :: Type -> Type) (i :: Type -> Type) (c :: k).
PlonkupWitnessInput p i c -> p (ScalarField c)
payloadInput :: p (ScalarField c)
  , forall {k} (p :: Type -> Type) (i :: Type -> Type) (c :: k).
PlonkupWitnessInput p i c -> i (ScalarField c)
witnessInput :: i (ScalarField c)
  }

instance (Show1 p, Show1 i, Show (ScalarField c))
  => Show (PlonkupWitnessInput p i c) where
    show :: PlonkupWitnessInput p i c -> String
show (PlonkupWitnessInput p (ScalarField c)
p i (ScalarField c)
v) = String
"Plonkup Witness Input: " String -> ShowS
forall a. [a] -> [a] -> [a]
++ p (ScalarField c) -> String
forall a. Show a => a -> String
show p (ScalarField c)
p String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
", " String -> ShowS
forall a. [a] -> [a] -> [a]
++ i (ScalarField c) -> String
forall a. Show a => a -> String
show i (ScalarField c)
v

instance (Arbitrary1 p, Arbitrary1 i, Arbitrary (ScalarField c))
  => Arbitrary (PlonkupWitnessInput p i c) where
    arbitrary :: Gen (PlonkupWitnessInput p i c)
arbitrary = p (ScalarField c) -> i (ScalarField c) -> PlonkupWitnessInput p i c
forall {k} (p :: Type -> Type) (i :: Type -> Type) (c :: k).
p (ScalarField c) -> i (ScalarField c) -> PlonkupWitnessInput p i c
PlonkupWitnessInput (p (ScalarField c)
 -> i (ScalarField c) -> PlonkupWitnessInput p i c)
-> Gen (p (ScalarField c))
-> Gen (i (ScalarField c) -> PlonkupWitnessInput p i c)
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen (p (ScalarField c))
forall (f :: Type -> Type) a.
(Arbitrary1 f, Arbitrary a) =>
Gen (f a)
arbitrary1 Gen (i (ScalarField c) -> PlonkupWitnessInput p i c)
-> Gen (i (ScalarField c)) -> Gen (PlonkupWitnessInput p i c)
forall a b. Gen (a -> b) -> Gen a -> Gen b
forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> Gen (i (ScalarField c))
forall (f :: Type -> Type) a.
(Arbitrary1 f, Arbitrary a) =>
Gen (f a)
arbitrary1