Safe Haskell | None |
---|---|
Language | Haskell2010 |
Definitions of quadratic arithmetic programs, along with their assignment verification functions and the translations from single multiplication- or equality-gates into QAPs and arithmetic circuits into QAPs.
Synopsis
- data QapSet f = QapSet {
- qapSetConstant :: f
- qapSetInput :: Map Int f
- qapSetIntermediate :: Map Int f
- qapSetOutput :: Map Int f
- data QAP f = QAP {
- qapInputsLeft :: QapSet (VPoly f)
- qapInputsRight :: QapSet (VPoly f)
- qapOutputs :: QapSet (VPoly f)
- qapTarget :: VPoly f
- updateAtWire :: Wire -> a -> QapSet a -> QapSet a
- lookupAtWire :: Wire -> QapSet a -> Maybe a
- cnstInpQapSet :: g -> Map Int g -> QapSet g
- sumQapSet :: Monoid g => QapSet g -> g
- sumQapSetCnstInp :: Monoid g => QapSet g -> g
- sumQapSetMidOut :: Monoid g => QapSet g -> g
- foldQapSet :: (a -> a -> a) -> QapSet a -> a
- combineWithDefaults :: (a -> b -> c) -> a -> b -> QapSet a -> QapSet b -> QapSet c
- combineInputsWithDefaults :: (a -> b -> c) -> a -> b -> QapSet a -> QapSet b -> QapSet c
- combineNonInputsWithDefaults :: (a -> b -> c) -> a -> b -> c -> QapSet a -> QapSet b -> QapSet c
- verifyAssignment :: (Eq f, Field f, Num f) => QAP f -> QapSet f -> Bool
- verificationWitness :: forall f. (Eq f, Field f, Num f) => QAP f -> QapSet f -> Maybe (VPoly f)
- verificationWitnessZk :: (Eq f, Field f, Num f) => f -> f -> f -> QAP f -> QapSet f -> Maybe (VPoly f)
- gateToQAP :: GaloisField k => (Int -> k) -> [k] -> Gate Wire k -> QAP k
- gateToGenQAP :: GaloisField k => [k] -> Gate Wire k -> [GenQAP ((,) k) k]
- qapSetToMap :: QapSet g -> Map Int g
- initialQapSet :: Num f => Map Int f -> QapSet f
- generateAssignmentGate :: (Bits f, Fractional f) => Gate Wire f -> Map Int f -> QapSet f
- generateAssignment :: forall f. (Bits f, Fractional f) => ArithCircuit f -> Map Int f -> QapSet f
- addMissingZeroes :: forall f. (Ord f, Num f) => [f] -> GenQAP (Map f) f -> GenQAP (Map f) f
- arithCircuitToGenQAP :: GaloisField k => [[k]] -> ArithCircuit k -> GenQAP (Map k) k
- arithCircuitToQAP :: GaloisField k => [[k]] -> ArithCircuit k -> QAP k
- arithCircuitToQAPFFT :: GaloisField k => (Int -> k) -> [[k]] -> ArithCircuit k -> QAP k
- createPolynomials :: forall k. GaloisField k => GenQAP (Map k) k -> QAP k
- createPolynomialsFFT :: GaloisField k => (Int -> k) -> GenQAP (Map k) k -> QAP k
Documentation
The sets of polynomials/constants as they occur in QAPs, grouped into their constant, input, output and intermediate parts.
QapSet | |
|
Instances
Quadratic arithmetic program
QAP | |
|
Instances
Eq f => Eq (QAP f) Source # | |
Show f => Show (QAP f) Source # | |
Generic (QAP f) Source # | |
(Generic f, ToJSON f) => ToJSON (QAP f) Source # | |
(FromJSON f, Generic f, Eq f, Num f) => FromJSON (QAP f) Source # | |
NFData f => NFData (QAP f) Source # | |
(Eq f, Num f, Pretty f, Show f) => Pretty (QAP f) Source # | |
type Rep (QAP f) Source # | |
Defined in QAP type Rep (QAP f) = D1 (MetaData "QAP" "QAP" "arithmetic-circuits-0.2.0-6zOfGRHnhI9W2wAnMDkNU" False) (C1 (MetaCons "QAP" PrefixI True) ((S1 (MetaSel (Just "qapInputsLeft") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (QapSet (VPoly f))) :*: S1 (MetaSel (Just "qapInputsRight") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (QapSet (VPoly f)))) :*: (S1 (MetaSel (Just "qapOutputs") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (QapSet (VPoly f))) :*: S1 (MetaSel (Just "qapTarget") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (VPoly f))))) |
updateAtWire :: Wire -> a -> QapSet a -> QapSet a Source #
Update the value at the given wire label in the
QapSet
. (Partial function at the moment.)
lookupAtWire :: Wire -> QapSet a -> Maybe a Source #
Lookup the value at the given wire label in the
QapSet
.
sumQapSetCnstInp :: Monoid g => QapSet g -> g Source #
Sum only over constant and input values
sumQapSetMidOut :: Monoid g => QapSet g -> g Source #
Sum only over intermediate and output values
:: (a -> a -> a) |
|
-> QapSet a | QapSet to fold over |
-> a |
Fold over a QapSet with an operation that is assumed to be commutative.
:: (Eq f, Field f, Num f) | |
=> QAP f | circuit whose evaluation we want to verify |
-> QapSet f | vector containing the inputs, outputs and intermediate values (outputs of all the mul-gates) |
-> Bool |
Verify whether an assignment of variables is consistent with the given QAP
:: (Eq f, Field f, Num f) | |
=> QAP f | circuit whose evaluation we want to verify |
-> QapSet f | vector containing the inputs, outputs and intermediate values (outputs of all the mul-gates) |
-> Maybe (VPoly f) |
Produce the polynomial witnessing the validity of given
assignment against the given QAP. Will return Nothing
if the
assignment is not valid.
In Pinocchio's terminology: this produces the h(x) such that p(x) = h(x) * t(x) where t(x) is the target polynomial and p(x) is the left input polynomials times the right input polynomials minus the output polynomials.
:: GaloisField k | |
=> (Int -> k) | |
-> [k] | arbitrarily chosen roots |
-> Gate Wire k | circuit to encode as a QAP |
-> QAP k |
Convert a single multiplication- or equality-gate into a QAP
:: GaloisField k | |
=> [k] | arbitrarily chosen roots |
-> Gate Wire k | circuit to encode as a QAP |
-> [GenQAP ((,) k) k] |
Convert a single multiplication gate (with affine circuits for inputs) into a GenQAP
generateAssignmentGate Source #
Generate a valid assignment for a single gate.
:: (Bits f, Fractional f) | |
=> ArithCircuit f | program |
-> Map Int f | inputs |
-> QapSet f |
addMissingZeroes :: forall f. (Ord f, Num f) => [f] -> GenQAP (Map f) f -> GenQAP (Map f) f Source #
Add zeroes for those roots that are missing, to prevent the values in the GenQAP to be too sparse. (We can be sparse in wire values, but not in values at roots, otherwise the interpolation step is incorrect.)
:: GaloisField k | |
=> [[k]] | arbitrarily chosen roots, one for each gate |
-> ArithCircuit k | circuit to encode as a QAP |
-> GenQAP (Map k) k |
Convert an arithmetic circuit into a GenQAP: perform every step of the QAP translation except the final interpolation step.
:: GaloisField k | |
=> [[k]] | arbitrarily chosen roots, one for each gate |
-> ArithCircuit k | circuit to encode as a QAP |
-> QAP k |
Convert an arithmetic circuit into a QAP
:: GaloisField k | |
=> (Int -> k) | function that gives us the primitive 2^k-th root of unity |
-> [[k]] | arbitrarily chosen roots, one for each gate |
-> ArithCircuit k | circuit to encode as a QAP |
-> QAP k |
Convert an arithmetic circuit into a QAP
createPolynomials :: forall k. GaloisField k => GenQAP (Map k) k -> QAP k Source #
For the left inputright inputoutput polynomials: turn list of coordinates into a polynomial that interpolates the coordinates. For the target polynomial: define it as the product of all monics t_g(x) := x - r_g where r_g is the root corresponding to the gate g.
Naive construction of polynomials using Lagrange interpolation This has terrible complexity at the moment. Use the FFT-based approach if possible.
:: GaloisField k | |
=> (Int -> k) | function that gives us the primitive 2^k-th root of unity |
-> GenQAP (Map k) k | GenQAP containing the coordinates we want to interpolate |
-> QAP k |
Create polynomials using FFT-based polynomial operations instead of naive.