Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion eras/alonzo/impl/cardano-ledger-alonzo.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ library
cardano-crypto-class,
cardano-data ^>=1.2.1,
cardano-ledger-allegra ^>=1.9,
cardano-ledger-binary ^>=1.7,
cardano-ledger-binary ^>=1.8,
cardano-ledger-core:{cardano-ledger-core, internal} ^>=1.19,
cardano-ledger-mary ^>=1.9,
cardano-ledger-shelley ^>=1.17,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import Cardano.Ledger.Binary (
encodeFoldableEncoder,
encodeFoldableMapEncoder,
encodePreEncoded,
encodedSizeExpr,
serialize,
withSlice,
)
Expand All @@ -54,7 +53,6 @@ import Data.ByteString.Builder (Builder, shortByteString, toLazyByteString)
import qualified Data.ByteString.Lazy as BSL
import Data.Coerce (coerce)
import Data.Maybe.Strict (maybeToStrictMaybe, strictMaybeToMaybe)
import Data.Proxy (Proxy (..))
import qualified Data.Sequence as Seq
import Data.Sequence.Strict (StrictSeq)
import qualified Data.Sequence.Strict as StrictSeq
Expand Down Expand Up @@ -178,11 +176,6 @@ instance Era era => EncCBORGroup (AlonzoBlockBody era) where
encodePreEncoded $
BSL.toStrict $
bodyBytes <> witsBytes <> metadataBytes <> invalidBytes
encodedGroupSizeExpr size _proxy =
encodedSizeExpr size (Proxy :: Proxy ByteString)
+ encodedSizeExpr size (Proxy :: Proxy ByteString)
+ encodedSizeExpr size (Proxy :: Proxy ByteString)
+ encodedSizeExpr size (Proxy :: Proxy ByteString)
listLen _ = 4
listLenBound _ = 4

Expand Down
7 changes: 1 addition & 6 deletions eras/alonzo/impl/src/Cardano/Ledger/Alonzo/Rules/Bbody.hs
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,7 @@ deriving anyclass instance
(Era era, NoThunks (PredicateFailure (EraRule "LEDGERS" era))) =>
NoThunks (AlonzoBbodyPredFailure era)

instance
( Typeable era
, EncCBOR (ShelleyBbodyPredFailure era)
) =>
EncCBOR (AlonzoBbodyPredFailure era)
where
instance EncCBOR (ShelleyBbodyPredFailure era) => EncCBOR (AlonzoBbodyPredFailure era) where
encCBOR (ShelleyInAlonzoBbodyPredFailure x) = encode (Sum ShelleyInAlonzoBbodyPredFailure 0 !> To x)
encCBOR (TooManyExUnits m) = encode (Sum TooManyExUnits 1 !> To m)

Expand Down
2 changes: 0 additions & 2 deletions eras/alonzo/impl/src/Cardano/Ledger/Alonzo/Rules/Utxow.hs
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,7 @@ instance

instance
( AlonzoEraScript era
, EncCBOR (TxCert era)
, EncCBOR (PredicateFailure (EraRule "UTXO" era))
, Typeable (TxAuxData era)
) =>
EncCBOR (AlonzoUtxowPredFailure era)
where
Expand Down
7 changes: 1 addition & 6 deletions eras/alonzo/impl/src/Cardano/Ledger/Alonzo/Scripts.hs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ import qualified Data.Map.Strict as Map
import Data.Maybe (fromJust, isJust)
import Data.MemPack
import Data.Typeable
import Data.Word (Word16, Word32, Word8)
import Data.Word (Word32)
import GHC.Generics (Generic)
import GHC.Stack
import NoThunks.Class (NoThunks (..))
Expand Down Expand Up @@ -331,7 +331,6 @@ instance
instance
( forall a b. (EncCBOR a, EncCBOR b) => EncCBOR (f a b)
, Era era
, Typeable f
, EncCBOR (TxCert era)
) =>
EncCBORGroup (AlonzoPlutusPurpose f era)
Expand All @@ -343,9 +342,6 @@ instance
AlonzoMinting p -> encodeWord8 1 <> encCBOR p
AlonzoCertifying p -> encodeWord8 2 <> encCBOR p
AlonzoRewarding p -> encodeWord8 3 <> encCBOR p
encodedGroupSizeExpr size_ _proxy =
encodedSizeExpr size_ (Proxy :: Proxy Word8)
+ encodedSizeExpr size_ (Proxy :: Proxy Word16)

instance
( forall a b. (DecCBOR a, DecCBOR b) => DecCBOR (f a b)
Expand All @@ -368,7 +364,6 @@ deriving via
instance
( forall a b. (EncCBOR a, EncCBOR b) => EncCBOR (f a b)
, Era era
, Typeable f
, EncCBOR (TxCert era)
) =>
EncCBOR (AlonzoPlutusPurpose f era)
Expand Down
3 changes: 1 addition & 2 deletions eras/alonzo/impl/src/Cardano/Ledger/Alonzo/TxWits.hs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ import qualified Data.MapExtras as Map (fromElems)
import Data.Maybe (mapMaybe)
import Data.Set (Set)
import qualified Data.Set as Set
import Data.Typeable (Typeable)
import GHC.Generics (Generic)
import Lens.Micro
import NoThunks.Class (NoThunks)
Expand Down Expand Up @@ -312,7 +311,7 @@ newtype TxDatsRaw era = TxDatsRaw {unTxDatsRaw :: Map DataHash (Data era)}

deriving instance Show (TxDatsRaw era)

instance (Typeable era, EncCBOR (Data era)) => EncCBOR (TxDatsRaw era) where
instance EncCBOR (Data era) => EncCBOR (TxDatsRaw era) where
encCBOR = encodeWithSetTag . Map.elems . unTxDatsRaw

pattern TxDats' :: Map DataHash (Data era) -> TxDats era
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import Cardano.Ledger.TxIn (TxIn)
import Cardano.Ledger.Val (Val)
import Codec.CBOR.Term (Term (..))
import Data.Maybe (catMaybes)
import Data.Typeable (Typeable)
import Test.Cardano.Ledger.Alonzo.Arbitrary ()
import Test.Cardano.Ledger.Binary.Twiddle
import Test.Cardano.Ledger.Common
Expand Down Expand Up @@ -50,7 +49,7 @@ instance Twiddle MultiAsset where
instance Twiddle ScriptIntegrityHash where
twiddle v = twiddle v . toTerm v

instance Typeable t => Twiddle (KeyHash t) where
instance Twiddle (KeyHash t) where
twiddle v = twiddle v . toTerm v

instance Twiddle Network where
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ instance DecCBOR VersionedTxInfo where

instance
( Era era
, EncCBOR (PParams era)
, EncCBOR (UTxO era)
, EncCBOR (Core.Tx era)
) =>
Expand Down
3 changes: 0 additions & 3 deletions eras/babbage/impl/src/Cardano/Ledger/Babbage/Rules/Utxo.hs
Original file line number Diff line number Diff line change
Expand Up @@ -498,10 +498,7 @@ instance
, EncCBOR (TxOut era)
, EncCBOR (Value era)
, EncCBOR (PredicateFailure (EraRule "UTXOS" era))
, EncCBOR (PredicateFailure (EraRule "UTXO" era))
, EncCBOR (Script era)
, EncCBOR TxIn
, Typeable (TxAuxData era)
) =>
EncCBOR (BabbageUtxoPredFailure era)
where
Expand Down
5 changes: 0 additions & 5 deletions eras/babbage/impl/src/Cardano/Ledger/Babbage/Rules/Utxow.hs
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,7 @@ deriving instance

instance
( AlonzoEraScript era
, EncCBOR (TxOut era)
, EncCBOR (TxCert era)
, EncCBOR (Value era)
, EncCBOR (PredicateFailure (EraRule "UTXOS" era))
, EncCBOR (PredicateFailure (EraRule "UTXO" era))
, Typeable (TxAuxData era)
) =>
EncCBOR (BabbageUtxowPredFailure era)
where
Expand Down
1 change: 1 addition & 0 deletions eras/byron/crypto/cardano-crypto-wrapper.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ library testlib
build-depends:
base,
bytestring,
cardano-binary:testlib,
cardano-crypto,
cardano-crypto-wrapper,
cardano-ledger-binary:{cardano-ledger-binary, testlib},
Expand Down
6 changes: 3 additions & 3 deletions eras/byron/crypto/src/Cardano/Crypto/Hashing.hs
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,13 @@ instance ToJSONKey (AbstractHash algo a) where
instance (Typeable algo, Typeable a, HashAlgorithm algo) => ToCBOR (AbstractHash algo a) where
toCBOR = toByronCBOR

instance (Typeable algo, Typeable a, HashAlgorithm algo) => EncCBOR (AbstractHash algo a) where
encCBOR (AbstractHash h) = encCBOR h

encodedSizeExpr _ _ =
let realSz = hashDigestSize (panic "unused, I hope!" :: algo)
in fromInteger (toInteger (withWordSize realSz + realSz))

instance (Typeable algo, Typeable a, HashAlgorithm algo) => EncCBOR (AbstractHash algo a) where
encCBOR (AbstractHash h) = encCBOR h

instance (Typeable algo, Typeable a, HashAlgorithm algo) => FromCBOR (AbstractHash algo a) where
fromCBOR = fromByronCBOR

Expand Down
6 changes: 3 additions & 3 deletions eras/byron/crypto/src/Cardano/Crypto/Orphans.hs
Original file line number Diff line number Diff line change
Expand Up @@ -64,33 +64,34 @@ instance ToJSON Ed25519.Signature where

instance ToCBOR Ed25519.PublicKey where
toCBOR = toByronCBOR
encodedSizeExpr _ _ = bsSize 32

instance FromCBOR Ed25519.PublicKey where
fromCBOR = fromByronCBOR

instance ToCBOR Ed25519.SecretKey where
toCBOR = toByronCBOR
encodedSizeExpr _ _ = bsSize 64

instance FromCBOR Ed25519.SecretKey where
fromCBOR = fromByronCBOR

instance ToCBOR Ed25519.Signature where
toCBOR = toByronCBOR
encodedSizeExpr _ _ = bsSize 64

instance FromCBOR Ed25519.Signature where
fromCBOR = fromByronCBOR

instance EncCBOR Ed25519.PublicKey where
encCBOR = encodeBytes . toByteString
encodedSizeExpr _ _ = bsSize 32

instance DecCBOR Ed25519.PublicKey where
decCBOR = do
res <- Ed25519.publicKey . fromByteStringToBytes <$> decCBOR
toCborError $ fromCryptoFailable "decCBOR Ed25519.PublicKey" res

instance EncCBOR Ed25519.SecretKey where
encodedSizeExpr _ _ = bsSize 64
encCBOR sk =
encodeBytes
$ BS.append (toByteString sk) (toByteString $ Ed25519.toPublic sk)
Expand All @@ -105,7 +106,6 @@ instance DecCBOR Ed25519.SecretKey where
toCborError $ fromCryptoFailable "decCBOR Ed25519.SecretKey" res

instance EncCBOR Ed25519.Signature where
encodedSizeExpr _ _ = bsSize 64
encCBOR = encodeBytes . toByteString

instance DecCBOR Ed25519.Signature where
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ import Cardano.Ledger.Binary (
FromCBOR (..),
ToCBOR (..),
byronProtVer,
fromByronCBOR,
serialize',
toByronCBOR,
)
import Cardano.Prelude
import qualified Crypto.PubKey.Ed25519 as Ed25519
Expand All @@ -41,13 +39,7 @@ import qualified Formatting.Buildable as B (Buildable (..))
type RedeemSignature :: Type -> Type
newtype RedeemSignature a
= RedeemSignature Ed25519.Signature
deriving (Eq, Show, Generic, NFData, DecCBOR, EncCBOR)

instance EncCBOR a => ToCBOR (RedeemSignature a) where
toCBOR = toByronCBOR

instance DecCBOR a => FromCBOR (RedeemSignature a) where
fromCBOR = fromByronCBOR
deriving (Eq, Show, Generic, NFData, DecCBOR, EncCBOR, ToCBOR, FromCBOR)

-- Note that there is deliberately no Ord instance. The crypto libraries
-- encourage using key /hashes/ not keys for things like sets, map etc.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ import Cardano.Ledger.Binary (
EncCBOR,
FromCBOR (..),
ToCBOR (..),
fromByronCBOR,
toByronCBOR,
)
import Cardano.Prelude
import qualified Crypto.PubKey.Ed25519 as Ed25519
Expand All @@ -31,14 +29,12 @@ import NoThunks.Class (InspectHeap (..), NoThunks (..))
type RedeemSigningKey :: Type
newtype RedeemSigningKey
= RedeemSigningKey Ed25519.SecretKey
deriving (Eq, Show, Generic, NFData, DecCBOR, EncCBOR)
deriving (Eq, Show, Generic, NFData, ToCBOR, FromCBOR)
deriving (NoThunks) via InspectHeap RedeemSigningKey

instance ToCBOR RedeemSigningKey where
toCBOR = toByronCBOR
instance EncCBOR RedeemSigningKey

instance FromCBOR RedeemSigningKey where
fromCBOR = fromByronCBOR
instance DecCBOR RedeemSigningKey

-- Note that there is deliberately no Ord instance. The crypto libraries
-- encourage using key /hashes/ not keys for things like sets, map etc.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,13 @@ decCBORXSignature = toCborError . CC.xsignature =<< decCBOR

instance Typeable a => ToCBOR (Signature a) where
toCBOR = toByronCBOR
encodedSizeExpr _ _ = 66

instance Typeable a => FromCBOR (Signature a) where
fromCBOR = fromByronCBOR

instance Typeable a => EncCBOR (Signature a) where
encCBOR (Signature a) = encCBORXSignature a
encodedSizeExpr _ _ = 66

instance Typeable a => DecCBOR (Signature a) where
decCBOR = fmap Signature decCBORXSignature
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@ instance MonadError SchemaError m => TJC.FromJSON m VerificationKey where

instance ToCBOR VerificationKey where
toCBOR = toByronCBOR
encodedSizeExpr _ _ = 66

instance FromCBOR VerificationKey where
fromCBOR = fromByronCBOR

instance EncCBOR VerificationKey where
encCBOR (VerificationKey a) = encCBORXPub a
encodedSizeExpr _ _ = 66

instance DecCBOR VerificationKey where
decCBOR = fmap VerificationKey decCBORXPub
Expand Down
6 changes: 3 additions & 3 deletions eras/byron/crypto/testlib/Test/Cardano/Crypto/CBOR.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ import Cardano.Crypto (
sign,
)
import Cardano.Crypto.Wallet (xprv, xpub)
import Cardano.Ledger.Binary (Dropper, EncCBOR, dropBytes, dropList, enforceSize)
import Cardano.Ledger.Binary (Dropper, ToCBOR, dropBytes, dropList, enforceSize)
import Cardano.Prelude
import Crypto.Hash (Blake2b_224, Blake2b_256, Blake2b_384, Blake2b_512, SHA1)
import qualified Data.ByteArray as ByteArray
import qualified Data.ByteString as BS
import Hedgehog (Gen, Property)
import qualified Hedgehog as H
import Test.Cardano.Binary.Helpers (SizeTestConfig (..), scfg, sizeTest)
import Test.Cardano.Crypto.Gen
import Test.Cardano.Ledger.Binary.Vintage.Helpers (SizeTestConfig (..), scfg, sizeTest)
import Test.Cardano.Ledger.Binary.Vintage.Helpers.GoldenRoundTrip (
deprecatedGoldenDecode,
goldenTestCBOR,
Expand Down Expand Up @@ -266,7 +266,7 @@ constantByteString =

sizeEstimates :: H.Group
sizeEstimates =
let testPrecise :: forall a. (Show a, EncCBOR a) => Gen a -> Property
let testPrecise :: forall a. (Show a, ToCBOR a) => Gen a -> Property
testPrecise g = sizeTest $ scfg {gen = g, precise = True}
in H.Group
"Encoded size bounds for crypto types."
Expand Down
5 changes: 3 additions & 2 deletions eras/byron/ledger/impl/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Revision history for `cardano-ledger-byron`

## 1.2.0.1
## 1.3.0.0

*
* Add `ToCBOR` and `FromCBOR` instances for `KeyHash` and `GenesisHash`
* Rename `encodedSizeTestEncCBOR` to `encodedSizeTestToCBOR`

## 1.2.0.0

Expand Down
6 changes: 4 additions & 2 deletions eras/byron/ledger/impl/cardano-ledger-byron.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 3.0
name: cardano-ledger-byron
version: 1.2.0.0
version: 1.3.0.0
license: Apache-2.0
maintainer: [email protected]
author: IOHK
Expand Down Expand Up @@ -240,9 +240,10 @@ library
binary,
bytestring,
canonical-json,
cardano-binary,
cardano-crypto,
cardano-crypto-wrapper >=1.6,
cardano-ledger-binary >=1.5,
cardano-ledger-binary >=1.8,
cardano-prelude,
cborg,
containers,
Expand Down Expand Up @@ -345,6 +346,7 @@ library testlib
byron-spec-chain,
byron-spec-ledger,
bytestring,
cardano-binary:{cardano-binary, testlib} >=1.7.2,
cardano-crypto,
cardano-crypto-wrapper:{cardano-crypto-wrapper, testlib},
cardano-ledger-binary:{cardano-ledger-binary, testlib},
Expand Down
Loading