Skip to content

Indefinite length decoding support for Bytes #5513

@lehins

Description

@lehins

It turns out that in all places where we decode ByteString, ShortByteString or ByteArray we do not support indefinite length decoding, which is not in accordance to the CDDL specification that we provide.

We need to change these instances to start accepting indefinite length encoding starting with protocol version 12:

instance DecCBOR BSL.ByteString where
decCBOR = BSL.fromStrict <$> decCBOR
{-# INLINE decCBOR #-}
instance DecCBOR ShortByteString where
decCBOR = do
BA (Prim.ByteArray ba) <- decodeByteArray
return $ SBS ba
{-# INLINE decCBOR #-}
instance DecCBOR ByteArray where
decCBOR = decodeByteArray
{-# INLINE decCBOR #-}
instance DecCBOR Prim.ByteArray where
decCBOR = unBA <$> decodeByteArray
{-# INLINE decCBOR #-}
instance DecCBOR SlicedByteArray where
decCBOR = fromByteArray . unBA <$> decodeByteArray
{-# INLINE decCBOR #-}

We also need to make sure that none of the types that ByteString, ShortByteString or ByteArray rely on default implementation in decCBOR, which uses FromCBOR instance that will not have this fixed.

Metadata

Metadata

Assignees

Labels

DijkstraEraLedger era that will follow after ConwayserializationAnything that affects serialization of ledger types

Type

No type

Projects

Status

Todo

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions