symbolic-base-0.1.0.0: ZkFold Symbolic compiler and zero-knowledge proof protocols
Safe HaskellSafe-Inferred
LanguageHaskell2010

ZkFold.Symbolic.Compiler.ArithmeticCircuit.Internal

Synopsis

Documentation

data ArithmeticCircuit a p i o Source #

Arithmetic circuit in the form of a system of polynomial constraints.

Constructors

ArithmeticCircuit 

Fields

Instances

Instances details
(Ord (Rep i), Ord a) => HApplicative (ArithmeticCircuit a p i :: (Type -> Type) -> Type) Source # 
Instance details

Defined in ZkFold.Symbolic.Compiler.ArithmeticCircuit.Internal

Methods

hpure :: (forall (a0 :: k). f a0) -> ArithmeticCircuit a p i f Source #

hunit :: ArithmeticCircuit a p i U1 Source #

hap :: forall (f :: k -> Type) (g :: k -> Type). ArithmeticCircuit a p i (Transform f g) -> ArithmeticCircuit a p i f -> ArithmeticCircuit a p i g Source #

hliftA2 :: (forall (a0 :: k). f a0 -> g a0 -> h a0) -> ArithmeticCircuit a p i f -> ArithmeticCircuit a p i g -> ArithmeticCircuit a p i h Source #

hpair :: forall (f :: k -> Type) (g :: k -> Type). ArithmeticCircuit a p i f -> ArithmeticCircuit a p i g -> ArithmeticCircuit a p i (f :*: g) Source #

HFunctor (ArithmeticCircuit a p i :: (Type -> Type) -> Type) Source # 
Instance details

Defined in ZkFold.Symbolic.Compiler.ArithmeticCircuit.Internal

Methods

hmap :: (forall (a0 :: k). f a0 -> g a0) -> ArithmeticCircuit a p i f -> ArithmeticCircuit a p i g Source #

(Ord (Rep i), Ord a) => Package (ArithmeticCircuit a p i :: (Type -> Type) -> Type) Source # 
Instance details

Defined in ZkFold.Symbolic.Compiler.ArithmeticCircuit.Internal

Methods

unpack :: forall f (g :: k1 -> Type). Functor f => ArithmeticCircuit a p i (f :.: g) -> f (ArithmeticCircuit a p i g) Source #

unpackWith :: Functor f => (forall (a0 :: k1). h a0 -> f (g a0)) -> ArithmeticCircuit a p i h -> f (ArithmeticCircuit a p i g) Source #

pack :: forall f (g :: k1 -> Type). (Foldable f, Functor f) => f (ArithmeticCircuit a p i g) -> ArithmeticCircuit a p i (f :.: g) Source #

packWith :: (Foldable f, Functor f) => (forall (a0 :: k1). f (g a0) -> h a0) -> f (ArithmeticCircuit a p i g) -> ArithmeticCircuit a p i h Source #

(Arithmetic a, Binary a, Binary (Rep p), Binary (Rep i), Ord (Rep i), NFData (Rep i)) => Symbolic (ArithmeticCircuit a p i) Source # 
Instance details

Defined in ZkFold.Symbolic.Compiler.ArithmeticCircuit.Internal

Associated Types

type BaseField (ArithmeticCircuit a p i) Source #

type WitnessField (ArithmeticCircuit a p i) Source #

Methods

witnessF :: Functor f => ArithmeticCircuit a p i f -> f (WitnessField (ArithmeticCircuit a p i)) Source #

fromCircuitF :: forall (f :: Type -> Type) (g :: Type -> Type). ArithmeticCircuit a p i f -> CircuitFun '[f] g (ArithmeticCircuit a p i) -> ArithmeticCircuit a p i g Source #

sanityF :: BaseField (ArithmeticCircuit a p i) ~ a0 => ArithmeticCircuit a p i f -> (f a0 -> g a0) -> (ArithmeticCircuit a p i f -> ArithmeticCircuit a p i g) -> ArithmeticCircuit a p i g Source #

(Arithmetic a, Binary a, Binary (Rep p), Binary (Rep i), Ord (Rep i), NFData (Rep i)) => SymbolicFold (ArithmeticCircuit a p i) Source # 
Instance details

Defined in ZkFold.Symbolic.Compiler.ArithmeticCircuit.Internal

Methods

sfoldl :: forall (f :: Type -> Type) p0 g (h :: Type -> Type) wc. (Binary (Rep f), NFData (Rep f), Ord (Rep f), forall a0. Binary a0 => Binary (f a0), Representable f, NFData1 f, Traversable f, Binary (Rep p0), Representable p0, Binary (Rep g), NFData (Rep g), Ord (Rep g), Representable g, forall a1. Binary a1 => Binary (h a1), WitnessField (ArithmeticCircuit a p i) ~ wc) => (forall (s :: (Type -> Type) -> Type) ws. (Symbolic s, BaseField s ~ BaseField (ArithmeticCircuit a p i), WitnessField s ~ ws) => s f -> p0 ws -> s g -> (s f, p0 ws)) -> ArithmeticCircuit a p i f -> p0 wc -> ArithmeticCircuit a p i h -> Infinite (g wc) -> ArithmeticCircuit a p i Par1 -> (ArithmeticCircuit a p i f, p0 wc) Source #

(Arithmetic a, Arbitrary a, Binary a, Binary (Rep p), Arbitrary (Rep i), Binary (Rep i), Ord (Rep i), NFData (Rep i), Representable i, Foldable i) => Arbitrary (ArithmeticCircuit a p i Par1) Source # 
Instance details

Defined in ZkFold.Symbolic.Compiler.ArithmeticCircuit.Instance

(Arithmetic a, Arbitrary a, Binary a, Binary (Rep p), Arbitrary (Rep i), Binary (Rep i), Ord (Rep i), NFData (Rep i), Representable i, Foldable i, KnownNat l) => Arbitrary (ArithmeticCircuit a p i (Vector l)) Source # 
Instance details

Defined in ZkFold.Symbolic.Compiler.ArithmeticCircuit.Instance

(FromJSON a, FromJSON (o (Var a i)), ToJSONKey (Var a i), FromJSONKey a, Ord a, Ord (Rep i), FromJSON (Rep i)) => FromJSON (ArithmeticCircuit a p i o) Source # 
Instance details

Defined in ZkFold.Symbolic.Compiler.ArithmeticCircuit.Instance

(ToJSON a, ToJSON (o (Var a i)), ToJSONKey a, FromJSONKey (Var a i), ToJSON (Rep i)) => ToJSON (ArithmeticCircuit a p i o) Source # 
Instance details

Defined in ZkFold.Symbolic.Compiler.ArithmeticCircuit.Instance

(Ord a, Ord (Rep i), o ~ (U1 :: Type -> Type)) => Monoid (ArithmeticCircuit a p i o) Source # 
Instance details

Defined in ZkFold.Symbolic.Compiler.ArithmeticCircuit.Internal

Methods

mempty :: ArithmeticCircuit a p i o #

mappend :: ArithmeticCircuit a p i o -> ArithmeticCircuit a p i o -> ArithmeticCircuit a p i o #

mconcat :: [ArithmeticCircuit a p i o] -> ArithmeticCircuit a p i o #

(Ord a, Ord (Rep i), o ~ (U1 :: Type -> Type)) => Semigroup (ArithmeticCircuit a p i o) Source # 
Instance details

Defined in ZkFold.Symbolic.Compiler.ArithmeticCircuit.Internal

Methods

(<>) :: ArithmeticCircuit a p i o -> ArithmeticCircuit a p i o -> ArithmeticCircuit a p i o #

sconcat :: NonEmpty (ArithmeticCircuit a p i o) -> ArithmeticCircuit a p i o #

stimes :: Integral b => b -> ArithmeticCircuit a p i o -> ArithmeticCircuit a p i o #

Generic (ArithmeticCircuit a p i o) Source # 
Instance details

Defined in ZkFold.Symbolic.Compiler.ArithmeticCircuit.Internal

Associated Types

type Rep (ArithmeticCircuit a p i o) :: Type -> Type #

Methods

from :: ArithmeticCircuit a p i o -> Rep (ArithmeticCircuit a p i o) x #

to :: Rep (ArithmeticCircuit a p i o) x -> ArithmeticCircuit a p i o #

(Show a, Show (o (Var a i)), Show (Var a i), Show (Rep i), Ord (Rep i)) => Show (ArithmeticCircuit a p i o) Source # 
Instance details

Defined in ZkFold.Symbolic.Compiler.ArithmeticCircuit.Instance

Methods

showsPrec :: Int -> ArithmeticCircuit a p i o -> ShowS #

show :: ArithmeticCircuit a p i o -> String #

showList :: [ArithmeticCircuit a p i o] -> ShowS #

(NFData a, NFData1 o, NFData (Rep i)) => NFData (ArithmeticCircuit a p i o) Source # 
Instance details

Defined in ZkFold.Symbolic.Compiler.ArithmeticCircuit.Internal

Methods

rnf :: ArithmeticCircuit a p i o -> () #

type BaseField (ArithmeticCircuit a p i) Source # 
Instance details

Defined in ZkFold.Symbolic.Compiler.ArithmeticCircuit.Internal

type BaseField (ArithmeticCircuit a p i) = a
type WitnessField (ArithmeticCircuit a p i) Source # 
Instance details

Defined in ZkFold.Symbolic.Compiler.ArithmeticCircuit.Internal

type Rep (ArithmeticCircuit a p i o) Source # 
Instance details

Defined in ZkFold.Symbolic.Compiler.ArithmeticCircuit.Internal

type Rep (ArithmeticCircuit a p i o)

data CircuitFold a v w Source #

Constructors

forall p s j.(Binary (Rep p), Representable p, Traversable s, Representable s, NFData1 s, Binary (Rep s), NFData (Rep s), Ord (Rep s), Representable j, Binary (Rep j), NFData (Rep j), Ord (Rep j)) => CircuitFold 

Fields

Instances

Instances details
Bifunctor (CircuitFold a) Source # 
Instance details

Defined in ZkFold.Symbolic.Compiler.ArithmeticCircuit.Internal

Methods

bimap :: (a0 -> b) -> (c -> d) -> CircuitFold a a0 c -> CircuitFold a b d #

first :: (a0 -> b) -> CircuitFold a a0 c -> CircuitFold a b c #

second :: (b -> c) -> CircuitFold a a0 b -> CircuitFold a a0 c #

Functor (CircuitFold a v) Source # 
Instance details

Defined in ZkFold.Symbolic.Compiler.ArithmeticCircuit.Internal

Methods

fmap :: (a0 -> b) -> CircuitFold a v a0 -> CircuitFold a v b #

(<$) :: a0 -> CircuitFold a v b -> CircuitFold a v a0 #

(NFData a, NFData v) => NFData (CircuitFold a v w) Source # 
Instance details

Defined in ZkFold.Symbolic.Compiler.ArithmeticCircuit.Internal

Methods

rnf :: CircuitFold a v w -> () #

data Var a i Source #

Constructors

LinVar a (SysVar i) a 
ConstVar a 

Instances

Instances details
FromConstant a (Var a i) Source # 
Instance details

Defined in ZkFold.Symbolic.Compiler.ArithmeticCircuit.Var

Methods

fromConstant :: a -> Var a i Source #

(FromJSON (Rep i), FromJSON a) => FromJSON (Var a i) Source # 
Instance details

Defined in ZkFold.Symbolic.Compiler.ArithmeticCircuit.Var

Methods

parseJSON :: Value -> Parser (Var a i) #

parseJSONList :: Value -> Parser [Var a i] #

(FromJSON (Rep i), FromJSON a) => FromJSONKey (Var a i) Source # 
Instance details

Defined in ZkFold.Symbolic.Compiler.ArithmeticCircuit.Var

(ToJSON (Rep i), ToJSON a) => ToJSON (Var a i) Source # 
Instance details

Defined in ZkFold.Symbolic.Compiler.ArithmeticCircuit.Var

Methods

toJSON :: Var a i -> Value #

toEncoding :: Var a i -> Encoding #

toJSONList :: [Var a i] -> Value #

toEncodingList :: [Var a i] -> Encoding #

(ToJSON (Rep i), ToJSON a) => ToJSONKey (Var a i) Source # 
Instance details

Defined in ZkFold.Symbolic.Compiler.ArithmeticCircuit.Var

Generic (Var a i) Source # 
Instance details

Defined in ZkFold.Symbolic.Compiler.ArithmeticCircuit.Var

Associated Types

type Rep (Var a i) :: Type -> Type #

Methods

from :: Var a i -> Rep (Var a i) x #

to :: Rep (Var a i) x -> Var a i #

(Show (Rep i), Show a) => Show (Var a i) Source # 
Instance details

Defined in ZkFold.Symbolic.Compiler.ArithmeticCircuit.Var

Methods

showsPrec :: Int -> Var a i -> ShowS #

show :: Var a i -> String #

showList :: [Var a i] -> ShowS #

(Binary (Rep i), Binary a) => Binary (Var a i) Source # 
Instance details

Defined in ZkFold.Symbolic.Compiler.ArithmeticCircuit.Var

Methods

put :: Var a i -> Put #

get :: Get (Var a i) #

putList :: [Var a i] -> Put #

(NFData (Rep i), NFData a) => NFData (Var a i) Source # 
Instance details

Defined in ZkFold.Symbolic.Compiler.ArithmeticCircuit.Var

Methods

rnf :: Var a i -> () #

(Eq (Rep i), Eq a) => Eq (Var a i) Source # 
Instance details

Defined in ZkFold.Symbolic.Compiler.ArithmeticCircuit.Var

Methods

(==) :: Var a i -> Var a i -> Bool #

(/=) :: Var a i -> Var a i -> Bool #

(Ord (Rep i), Ord a) => Ord (Var a i) Source # 
Instance details

Defined in ZkFold.Symbolic.Compiler.ArithmeticCircuit.Var

Methods

compare :: Var a i -> Var a i -> Ordering #

(<) :: Var a i -> Var a i -> Bool #

(<=) :: Var a i -> Var a i -> Bool #

(>) :: Var a i -> Var a i -> Bool #

(>=) :: Var a i -> Var a i -> Bool #

max :: Var a i -> Var a i -> Var a i #

min :: Var a i -> Var a i -> Var a i #

type Rep (Var a i) Source # 
Instance details

Defined in ZkFold.Symbolic.Compiler.ArithmeticCircuit.Var

data SysVar i Source #

Constructors

InVar (Rep i) 
NewVar NewVar 

Instances

Instances details
FromJSON (Rep i) => FromJSON (SysVar i) Source # 
Instance details

Defined in ZkFold.Symbolic.Compiler.ArithmeticCircuit.Var

FromJSON (Rep i) => FromJSONKey (SysVar i) Source # 
Instance details

Defined in ZkFold.Symbolic.Compiler.ArithmeticCircuit.Var

ToJSON (Rep i) => ToJSON (SysVar i) Source # 
Instance details

Defined in ZkFold.Symbolic.Compiler.ArithmeticCircuit.Var

ToJSON (Rep i) => ToJSONKey (SysVar i) Source # 
Instance details

Defined in ZkFold.Symbolic.Compiler.ArithmeticCircuit.Var

Generic (SysVar i) Source # 
Instance details

Defined in ZkFold.Symbolic.Compiler.ArithmeticCircuit.Var

Associated Types

type Rep (SysVar i) :: Type -> Type #

Methods

from :: SysVar i -> Rep (SysVar i) x #

to :: Rep (SysVar i) x -> SysVar i #

Show (Rep i) => Show (SysVar i) Source # 
Instance details

Defined in ZkFold.Symbolic.Compiler.ArithmeticCircuit.Var

Methods

showsPrec :: Int -> SysVar i -> ShowS #

show :: SysVar i -> String #

showList :: [SysVar i] -> ShowS #

Binary (Rep i) => Binary (SysVar i) Source # 
Instance details

Defined in ZkFold.Symbolic.Compiler.ArithmeticCircuit.Var

Methods

put :: SysVar i -> Put #

get :: Get (SysVar i) #

putList :: [SysVar i] -> Put #

NFData (Rep i) => NFData (SysVar i) Source # 
Instance details

Defined in ZkFold.Symbolic.Compiler.ArithmeticCircuit.Var

Methods

rnf :: SysVar i -> () #

Eq (Rep i) => Eq (SysVar i) Source # 
Instance details

Defined in ZkFold.Symbolic.Compiler.ArithmeticCircuit.Var

Methods

(==) :: SysVar i -> SysVar i -> Bool #

(/=) :: SysVar i -> SysVar i -> Bool #

Ord (Rep i) => Ord (SysVar i) Source # 
Instance details

Defined in ZkFold.Symbolic.Compiler.ArithmeticCircuit.Var

Methods

compare :: SysVar i -> SysVar i -> Ordering #

(<) :: SysVar i -> SysVar i -> Bool #

(<=) :: SysVar i -> SysVar i -> Bool #

(>) :: SysVar i -> SysVar i -> Bool #

(>=) :: SysVar i -> SysVar i -> Bool #

max :: SysVar i -> SysVar i -> SysVar i #

min :: SysVar i -> SysVar i -> SysVar i #

type Rep (SysVar i) Source # 
Instance details

Defined in ZkFold.Symbolic.Compiler.ArithmeticCircuit.Var

type Rep (SysVar i) = D1 ('MetaData "SysVar" "ZkFold.Symbolic.Compiler.ArithmeticCircuit.Var" "symbolic-base-0.1.0.0-inplace" 'False) (C1 ('MetaCons "InVar" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Rep i))) :+: C1 ('MetaCons "NewVar" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 NewVar)))

data NewVar Source #

Instances

Instances details
FromJSON NewVar Source # 
Instance details

Defined in ZkFold.Symbolic.Compiler.ArithmeticCircuit.Var

FromJSONKey NewVar Source # 
Instance details

Defined in ZkFold.Symbolic.Compiler.ArithmeticCircuit.Var

ToJSON NewVar Source # 
Instance details

Defined in ZkFold.Symbolic.Compiler.ArithmeticCircuit.Var

ToJSONKey NewVar Source # 
Instance details

Defined in ZkFold.Symbolic.Compiler.ArithmeticCircuit.Var

Generic NewVar Source # 
Instance details

Defined in ZkFold.Symbolic.Compiler.ArithmeticCircuit.Var

Associated Types

type Rep NewVar :: Type -> Type #

Methods

from :: NewVar -> Rep NewVar x #

to :: Rep NewVar x -> NewVar #

Show NewVar Source # 
Instance details

Defined in ZkFold.Symbolic.Compiler.ArithmeticCircuit.Var

Binary NewVar Source # 
Instance details

Defined in ZkFold.Symbolic.Compiler.ArithmeticCircuit.Var

Methods

put :: NewVar -> Put #

get :: Get NewVar #

putList :: [NewVar] -> Put #

NFData NewVar Source # 
Instance details

Defined in ZkFold.Symbolic.Compiler.ArithmeticCircuit.Var

Methods

rnf :: NewVar -> () #

Eq NewVar Source # 
Instance details

Defined in ZkFold.Symbolic.Compiler.ArithmeticCircuit.Var

Methods

(==) :: NewVar -> NewVar -> Bool #

(/=) :: NewVar -> NewVar -> Bool #

Ord NewVar Source # 
Instance details

Defined in ZkFold.Symbolic.Compiler.ArithmeticCircuit.Var

type Rep NewVar Source # 
Instance details

Defined in ZkFold.Symbolic.Compiler.ArithmeticCircuit.Var

type VarField = Zp (2 ^ (32 * 8)) Source #

Variables are SHA256 digests (32 bytes)

type Arithmetic a = (ResidueField Natural a, Eq a, Ord a, NFData a) Source #

Field of residues with decidable equality and ordering is called an `arithmetic' field.

type Constraint c i = Poly c (SysVar i) Natural Source #

The type that represents a constraint in the arithmetic circuit.

naturalCircuit :: (Arithmetic a, Representable p, Representable i, Traversable o, Binary a, Binary (Rep p), Binary (Rep i), Ord (Rep i)) => (forall x. p x -> i x -> o x) -> ArithmeticCircuit a p i o Source #

Given a natural transformation from payload p and input i to output o, returns a corresponding arithmetic circuit where outputs computing the payload are unconstrained.

idCircuit :: (Representable i, Semiring a) => ArithmeticCircuit a p i i Source #

Identity circuit which returns its input i and doesn't use the payload.

acInput :: (Representable i, Semiring a) => i (Var a i) Source #

getAllVars :: forall a p i o. (Representable i, Foldable i) => ArithmeticCircuit a p i o -> [SysVar i] Source #

crown :: ArithmeticCircuit a p i g -> f (Var a i) -> ArithmeticCircuit a p i f Source #

hlmap :: (Representable i, Representable j, Ord (Rep j), Functor o) => (forall x. j x -> i x) -> ArithmeticCircuit a p i o -> ArithmeticCircuit a p j o Source #

hpmap :: (Representable p, Representable q) => (forall x. q x -> p x) -> ArithmeticCircuit a p i o -> ArithmeticCircuit a q i o Source #

eval :: (Arithmetic a, Binary a, Representable p, Representable i, Functor o) => ArithmeticCircuit a p i o -> p a -> i a -> o a Source #

Evaluates the arithmetic circuit using the supplied input map.

eval1 :: (Arithmetic a, Binary a, Representable p, Representable i) => ArithmeticCircuit a p i Par1 -> p a -> i a -> a Source #

Evaluates the arithmetic circuit with one output using the supplied input map.

exec :: (Arithmetic a, Binary a, Functor o) => ArithmeticCircuit a U1 U1 o -> o a Source #

Evaluates the arithmetic circuit with no inputs.

exec1 :: (Arithmetic a, Binary a) => ArithmeticCircuit a U1 U1 Par1 -> a Source #

Evaluates the arithmetic circuit with no inputs and one output.

apply :: (Eq a, Field a, Ord (Rep j), Representable i, Functor o) => i a -> ArithmeticCircuit a p (i :*: j) o -> ArithmeticCircuit a p j o Source #

Applies the values of the first couple of inputs to the arithmetic circuit.

indexW :: (Arithmetic a, Binary a, Representable p, Representable i) => ArithmeticCircuit a p i o -> p a -> i a -> Var a i -> a Source #

witToVar :: forall a p i. (Finite a, Binary a, Binary (Rep p), Binary (Rep i)) => WitnessF a (WitVar p i) -> ByteString Source #

Generates new variable index given a witness for it.

It is a root hash (sha256) of a Merkle tree which is obtained from witness:

  1. Due to parametricity, the only operations inside witness are operations from WitnessField interface;
  2. Thus witness can be viewed as an AST of a WitnessField "language" where:

    • leafs are fromConstant calls and variables;
    • nodes are algebraic operations;
    • root is the witness value for new variable.
  3. To inspect this AST, we instantiate witness with a special inspector type whose WitnessField instances perform inspection.
  4. Inspector type used here, MerkleHash, treats AST as a Merkle tree and performs the calculation of hashes for it.
  5. Thus the result of running the witness with MerkleHash as a WitnessField is a root hash of a Merkle tree for a witness.