Skip to content

Commit

Permalink
testing
Browse files Browse the repository at this point in the history
  • Loading branch information
echatav committed Jan 14, 2025
1 parent f562bd9 commit aea0ffb
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 30 deletions.
10 changes: 9 additions & 1 deletion symbolic-base/src/ZkFold/Base/Algebra/EllipticCurve/Class.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ import Data.Kind (Type)
import Data.String (fromString)
import GHC.Generics
import GHC.TypeLits (Symbol)
import Prelude (Integer, type (~))
import Prelude (Integer, type (~), ($), (>>=), return)
import qualified Prelude
import Test.QuickCheck hiding (scale)

import ZkFold.Base.Algebra.Basic.Class
import ZkFold.Base.Algebra.Basic.Number
Expand Down Expand Up @@ -142,6 +143,13 @@ class HasPointInf point where pointInf :: point
{- | `Weierstrass` tags a `ProjectivePlanar` @point@, over a `Field` @field@,
with a phantom `WeierstrassCurve` @curve@. -}
newtype Weierstrass curve point = Weierstrass {pointWeierstrass :: point}
instance
( Arbitrary (ScalarFieldOf (Weierstrass curve point))
, CyclicGroup (Weierstrass curve point)
) => Arbitrary (Weierstrass curve point) where
arbitrary = do
c <- arbitrary @ScalarFieldOf (Weierstrass curve point)
return $ scale c pointGen
instance
( WeierstrassCurve curve field
, Conditional bool bool
Expand Down
24 changes: 10 additions & 14 deletions symbolic-base/src/ZkFold/Base/Protocol/KZG.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ module ZkFold.Base.Protocol.KZG where

import Control.Monad (replicateM)
import Data.ByteString (ByteString, empty)
import Data.Kind (Type)
import Data.Map.Strict (Map, fromList, insert, keys, toList, (!))
import qualified Data.Vector as V
import Data.Vector.Binary ()
Expand All @@ -35,19 +34,16 @@ instance Arbitrary field => Arbitrary (KZG field g1 g2 d) where
newtype WitnessKZG field g1 g2 d = WitnessKZG { runWitness :: Map field (V.Vector (PolyVec field d)) }
instance (Show field) => Show (WitnessKZG field g1 g2 d) where
show (WitnessKZG w) = "WitnessKZG " <> show w
-- instance
-- ( SubgroupCurve c1 Bool baseField1 scalarField point
-- , SubgroupCurve c2 Bool baseField2 scalarField point
-- , KnownNat d
-- , Arbitrary scalarField
-- , Ord scalarField
-- , g1 ~ point baseField1
-- , g2 ~ point baseField2
-- ) => Arbitrary (WitnessKZG scalarField g1 g2 d) where
-- arbitrary = do
-- n <- chooseInt (1, 3)
-- m <- chooseInt (1, 5)
-- WitnessKZG . fromList <$> replicateM n ((,) <$> arbitrary <*> (V.fromList <$> replicateM m arbitrary))
instance
( KnownNat d
, Arbitrary scalarField
, Ord scalarField
, Ring scalarField
) => Arbitrary (WitnessKZG scalarField g1 g2 d) where
arbitrary = do
n <- chooseInt (1, 3)
m <- chooseInt (1, 5)
WitnessKZG . fromList <$> replicateM n ((,) <$> arbitrary <*> (V.fromList <$> replicateM m arbitrary))

-- TODO (Issue #18): check list lengths
instance forall f g1 g2 gt d kzg core.
Expand Down
8 changes: 4 additions & 4 deletions symbolic-base/test/Tests/Arithmetization/Test4.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ import Test.Hspec (Spec, describe, it
import Test.QuickCheck (Testable (..), (==>))

import ZkFold.Base.Algebra.Basic.Class (FromConstant (..), one, zero)
import ZkFold.Base.Algebra.EllipticCurve.BLS12_381 (BLS12_381_G1)
import ZkFold.Base.Algebra.EllipticCurve.Class (EllipticCurve (..))
import ZkFold.Base.Algebra.EllipticCurve.BLS12_381 (BLS12_381_G1_Point)
import ZkFold.Base.Algebra.EllipticCurve.Class (CyclicGroup (..))
import ZkFold.Symbolic.Class
import ZkFold.Symbolic.Compiler (ArithmeticCircuit (..), compile, eval)
import ZkFold.Symbolic.Data.Bool (Bool (..))
import ZkFold.Symbolic.Data.Eq (Eq (..))
import ZkFold.Symbolic.Data.FieldElement (FieldElement)

type C = BLS12_381_G1
type F = ScalarField C
type C = BLS12_381_G1_Point
type F = ScalarFieldOf C

lockedByTxId :: forall a c . (FromConstant a (FieldElement c), Symbolic c) => a -> FieldElement c -> Bool c
lockedByTxId targetValue inputValue = inputValue == fromConstant targetValue
Expand Down
22 changes: 11 additions & 11 deletions symbolic-base/test/Tests/Binary.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import Test.Hspec.QuickCheck
import Test.QuickCheck

import ZkFold.Base.Algebra.Basic.Field (Zp)
import ZkFold.Base.Algebra.EllipticCurve.BLS12_381 (BLS12_381_G1, BLS12_381_G2, BLS12_381_Scalar)
import ZkFold.Base.Algebra.EllipticCurve.BN254 (BN254_G1, BN254_G2)
import ZkFold.Base.Algebra.EllipticCurve.BLS12_381 (BLS12_381_G1_Point, BLS12_381_G2_Point, BLS12_381_G1_CompressedPoint, BLS12_381_G2_CompressedPoint, BLS12_381_Scalar)
import ZkFold.Base.Algebra.EllipticCurve.BN254 (BN254_G1_Point, BN254_G2_Point)
import ZkFold.Base.Algebra.EllipticCurve.Class (CompressedPoint, Point)
import ZkFold.Base.Algebra.EllipticCurve.Pasta (Pallas, Vesta)
import ZkFold.Base.Algebra.EllipticCurve.Pasta (Pallas_Point, Vesta_Point)
import ZkFold.Base.Data.ByteString (LittleEndian, fromByteString, toByteString)

doesRoundtrip :: (Binary a, Eq a, Show a) => a -> Property
Expand All @@ -23,11 +23,11 @@ specBinary :: IO ()
specBinary = hspec $ describe "Binary instance" $ do
prop "roundtrips LittleEndian" $ doesRoundtrip @LittleEndian
prop "roundtrips Zp BLS12_381_Scalar" $ doesRoundtrip @(Zp BLS12_381_Scalar)
prop "roundtrips Point BN254_G1" $ doesRoundtrip @(Point BN254_G1)
prop "roundtrips Point BN254_G2" $ doesRoundtrip @(Point BN254_G2)
prop "roundtrips Point BLS12_381_G1" $ doesRoundtrip @(Point BLS12_381_G1)
prop "roundtrips CompressedPoint BLS12_381_G1" $ doesRoundtrip @(CompressedPoint BLS12_381_G1)
prop "roundtrips Point BLS12_381_G2" $ doesRoundtrip @(Point BLS12_381_G2)
prop "roundtrips CompressedPoint BLS12_381_G2" $ doesRoundtrip @(CompressedPoint BLS12_381_G2)
prop "roundtrips Point Pallas" $ doesRoundtrip @(Point Pallas)
prop "roundtrips Point Vesta" $ doesRoundtrip @(Point Vesta)
prop "roundtrips Point BN254_G1" $ doesRoundtrip @BN254_G1_Point
prop "roundtrips Point BN254_G2" $ doesRoundtrip @BN254_G2_Point
prop "roundtrips Point BLS12_381_G1" $ doesRoundtrip @BLS12_381_G1_Point
prop "roundtrips CompressedPoint BLS12_381_G1" $ doesRoundtrip @BLS12_381_G1_CompressedPoint
prop "roundtrips Point BLS12_381_G2" $ doesRoundtrip @BLS12_381_G2_Point
prop "roundtrips CompressedPoint BLS12_381_G2" $ doesRoundtrip @BLS12_381_G2_CompressedPoint
prop "roundtrips Point Pallas" $ doesRoundtrip @Pallas_Point
prop "roundtrips Point Vesta" $ doesRoundtrip @Vesta_Point

0 comments on commit aea0ffb

Please sign in to comment.