From 00dc20a00cc18b346730d7e3ea8c714058407c4d Mon Sep 17 00:00:00 2001 From: TurtlePU Date: Tue, 17 Dec 2024 01:48:44 +0300 Subject: [PATCH] fix ListItem --- .../src/ZkFold/Symbolic/Data/List.hs | 24 +++++++------------ symbolic-base/test/Tests/List.hs | 9 +++++-- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/symbolic-base/src/ZkFold/Symbolic/Data/List.hs b/symbolic-base/src/ZkFold/Symbolic/Data/List.hs index 66252af01..2b8e2b28f 100644 --- a/symbolic-base/src/ZkFold/Symbolic/Data/List.hs +++ b/symbolic-base/src/ZkFold/Symbolic/Data/List.hs @@ -29,30 +29,22 @@ import ZkFold.Symbolic.Data.Payloaded (Payloaded (Payloaded)) import ZkFold.Symbolic.Data.UInt (UInt) import ZkFold.Symbolic.MonadCircuit -data ListItem x a = ListItem - { tailHash :: Layout x a - , headLayout :: Layout x a - , headPayload :: Payload x a +data ListItem l p a = ListItem + { tailHash :: l a + , headLayout :: l a + , headPayload :: p a } - deriving (Generic1) + deriving (Functor, Generic1) -deriving instance - (Functor (Layout x), Functor (Payload x)) => - Functor (ListItem x) - -instance - (Representable (Layout x), Representable (Payload x)) => - Distributive (ListItem x) where +instance (Representable l, Representable p) => Distributive (ListItem l p) where distribute = distributeRep -instance - (Representable (Layout x), Representable (Payload x)) => - Representable (ListItem x) +instance (Representable l, Representable p) => Representable (ListItem l p) data List c x = List { lHash :: c (Layout x) , lSize :: c Par1 - , lWitness :: Payloaded (Infinite :.: ListItem x) c + , lWitness :: Payloaded (Infinite :.: ListItem (Layout x) (Payload x)) c } deriving (Generic) diff --git a/symbolic-base/test/Tests/List.hs b/symbolic-base/test/Tests/List.hs index 884b11bb5..25336c7b3 100644 --- a/symbolic-base/test/Tests/List.hs +++ b/symbolic-base/test/Tests/List.hs @@ -16,11 +16,11 @@ import ZkFold.Base.Algebra.Basic.Class (one) import ZkFold.Base.Algebra.Basic.Field (Zp) import ZkFold.Base.Algebra.EllipticCurve.BLS12_381 (BLS12_381_Scalar) import ZkFold.Symbolic.Class (Arithmetic, Symbolic) -import ZkFold.Symbolic.Compiler (compile, eval1) +import ZkFold.Symbolic.Compiler (acOutput, compile, eval1) import ZkFold.Symbolic.Data.Bool (Bool) import ZkFold.Symbolic.Data.Eq ((==)) import ZkFold.Symbolic.Data.FieldElement (FieldElement) -import ZkFold.Symbolic.Data.List (emptyList, head, tail, (.:)) +import ZkFold.Symbolic.Data.List (List, emptyList, head, tail, (.:)) headTest :: Symbolic c => FieldElement c -> FieldElement c -> Bool c headTest x y = head (x .: y .: emptyList) == x @@ -28,8 +28,13 @@ headTest x y = head (x .: y .: emptyList) == x tailTest :: Symbolic c => FieldElement c -> FieldElement c -> Bool c tailTest x y = head (tail (x .: y .: emptyList)) == y +headFun :: Symbolic c => List c (FieldElement c) -> FieldElement c +headFun = head + specList' :: forall a. (Arbitrary a, Arithmetic a, Binary a, Show a) => IO () specList' = hspec $ describe "List spec" $ do + let _headChecks = -- compile-time test + acOutput (compile @a headFun) prop "Head works fine" $ \x y -> eval1 (compile @a headTest) (U1 :*: U1 :*: U1) (Par1 x :*: Par1 y :*: U1) Haskell.== one