diff --git a/src/Gate/Computation.hs b/src/Gate/Computation.hs index a5cd381..89f27aa 100644 --- a/src/Gate/Computation.hs +++ b/src/Gate/Computation.hs @@ -124,6 +124,18 @@ straightLineOperCount (MkStraightLine{..}) = final where coms = map exprOperCount $ commits final = mconcat defs <> mconcat coms +-- | Maximum degree of a gate's constraints +constraintDegree :: StraightLine -> Int +constraintDegree (MkStraightLine{..}) = maxdeg where + ndefs = length localdefs + table = array (0,ndefs-1) [ (i, exprDegree lkp rhs) | MkLocalDef i _ rhs <- localdefs ] + lkp var = case var of + LocalVar i _ -> table!i + ProofVar v -> case v of { PIV {} -> 0 ; _ -> 1 } + maxdeg = case commits of + [] -> 0 + _ -> maximum (map (exprDegree lkp) commits) + -------------------------------------------------------------------------------- type Scope a = IntMap a diff --git a/src/Gate/Vars.hs b/src/Gate/Vars.hs index 593f05e..c4070df 100644 --- a/src/Gate/Vars.hs +++ b/src/Gate/Vars.hs @@ -18,7 +18,7 @@ data PlonkyVar = SelV Int -- ^ selector variable | ConstV Int -- ^ constant variable | WireV Int -- ^ wire variable - | PIV Int -- ^ public input hash variable + | PIV Int -- ^ public input hash variable (technically these are constants, not variables) deriving (Eq,Ord,Show) instance Pretty PlonkyVar where diff --git a/src/Test/Witness.hs b/src/Test/Witness.hs index 19d806f..d5e50a8 100644 --- a/src/Test/Witness.hs +++ b/src/Test/Witness.hs @@ -70,6 +70,11 @@ test_fibonacci = do let pubio_prg = gateProgram (PublicInputGate ) let const_prg = gateProgram (ConstantGate 2) + putStrLn $ "maximum degree of constraints in ArithmeticGate = " ++ show (constraintDegree arith_prg) + putStrLn $ "maximum degree of constraints in PosiedonGate = " ++ show (constraintDegree posei_prg) + putStrLn $ "maximum degree of constraints in PublicInputGate = " ++ show (constraintDegree pubio_prg) + putStrLn $ "maximum degree of constraints in ConstGate = " ++ show (constraintDegree const_prg) + let arith_evals = runStraightLine (fmap fromBase arith_row) arith_prg let posei_evals = runStraightLine (fmap fromBase posei_row) posei_prg let const_evals = runStraightLine (fmap fromBase const_row) const_prg @@ -92,5 +97,5 @@ test_fibonacci = do -------------------------------------------------------------------------------- -main :: IO +main :: IO () main = test_fibonacci