diff --git a/cabal.project b/cabal.project index bf1afab04af..9ea632babcb 100644 --- a/cabal.project +++ b/cabal.project @@ -42,11 +42,23 @@ source-repository-package -- points to a commit in `MAlonzo-code` if you were fiddling with the SRP -- as part of your PR. +source-repository-package + type: git + location: https://github.com/input-output-hk/cardano-base + tag: 5d87496a4748726d8c3fe122871c072a70e14c60 + --sha256: sha256-oW+msm9TfnUFpFzKdPN7oqjeJXbaqhrpsSk94peyH28= + subdir: + -- cardano-binary + cardano-crypto-class + cardano-crypto-tests + cardano-crypto-praos + cardano-mempool + index-state: -- Bump this if you need newer packages from Hackage - , hackage.haskell.org 2024-08-05T20:07:24Z + , hackage.haskell.org 2024-10-30T00:00:00Z -- Bump this if you need newer packages from CHaP - , cardano-haskell-packages 2024-09-20T19:39:13Z + , cardano-haskell-packages 2024-10-30T11:23:17Z packages: eras/allegra/impl @@ -88,7 +100,7 @@ packages: libs/cardano-ledger-conformance libs/cardano-ledger-test libs/plutus-preprocessor - libs/ledger-state + -- libs/ledger-state libs/constrained-generators libs/cardano-ledger-repl-environment @@ -110,6 +122,14 @@ package cardano-ledger-mary package cardano-ledger-conway flags: +asserts +allow-newer: + -- Plutus-core has an upper bound on cardano-crypto-class that would prevent + -- us from depending on the updated KES API; however, these changes to + -- cardano-crypto-class are inconsequential for plutus-core, so until the + -- dependency from plutus-core to cardano-crypto-class is updated, we will + -- have to add this exemption. + plutus-core:cardano-crypto-class + -- Always write GHC env files, because they are needed for repl and by the doctests. write-ghc-environment-files: always diff --git a/eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/Examples/Consensus.hs b/eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/Examples/Consensus.hs index 059a5608ca6..4b1989a4739 100644 --- a/eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/Examples/Consensus.hs +++ b/eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/Examples/Consensus.hs @@ -14,6 +14,7 @@ module Test.Cardano.Ledger.Shelley.Examples.Consensus where import Cardano.Crypto.DSIGN as DSIGN import Cardano.Crypto.Hash as Hash +import Cardano.Crypto.KES as KES import Cardano.Crypto.Seed as Seed import qualified Cardano.Crypto.VRF as VRF import Cardano.Ledger.AuxiliaryData @@ -181,7 +182,7 @@ exampleShelleyLedgerBlock tx = Block blockHeader blockBody KeyPair vKeyCold _ = aikCold keys blockHeader :: BHeader (EraCrypto era) - blockHeader = BHeader blockHeaderBody (signedKES () 0 blockHeaderBody hotKey) + blockHeader = BHeader blockHeaderBody (unsoundPureSignedKES () 0 blockHeaderBody hotKey) blockHeaderBody :: BHBody (EraCrypto era) blockHeaderBody = diff --git a/eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/Utils.hs b/eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/Utils.hs index a6d3a551bed..2188ff52e34 100644 --- a/eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/Utils.hs +++ b/eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/Utils.hs @@ -48,9 +48,9 @@ import Cardano.Crypto.Hash ( hashToBytes, ) import Cardano.Crypto.KES ( - KESAlgorithm (..), - deriveVerKeyKES, - genKeyKES, + UnsoundPureKESAlgorithm (..), + unsoundPureDeriveVerKeyKES, + unsoundPureGenKeyKES, ) import Cardano.Crypto.Seed (Seed, mkSeedFromBytes) import Cardano.Crypto.VRF ( @@ -210,10 +210,11 @@ mkCertifiedVRF a sk = -- | For testing purposes, generate a deterministic KES key pair given a seed. mkKESKeyPair :: Crypto c => RawSeed -> KESKeyPair c mkKESKeyPair seed = - let sk = genKeyKES $ mkSeedFromWords seed + let sk = unsoundPureGenKeyKES (mkSeedFromWords seed) + vk = unsoundPureDeriveVerKeyKES sk in KESKeyPair { kesSignKey = sk - , kesVerKey = deriveVerKeyKES sk + , kesVerKey = vk } runShelleyBase :: ShelleyBase a -> a diff --git a/eras/shelley/test-suite/test/Test/Cardano/Ledger/Shelley/Examples/PoolLifetime.hs b/eras/shelley/test-suite/test/Test/Cardano/Ledger/Shelley/Examples/PoolLifetime.hs index 2cd8ff27a4e..83d7d40384d 100644 --- a/eras/shelley/test-suite/test/Test/Cardano/Ledger/Shelley/Examples/PoolLifetime.hs +++ b/eras/shelley/test-suite/test/Test/Cardano/Ledger/Shelley/Examples/PoolLifetime.hs @@ -42,7 +42,7 @@ import Cardano.Ledger.Coin ( ) import Cardano.Ledger.Compactible import Cardano.Ledger.Credential (Credential, Ptr (..)) -import qualified Cardano.Ledger.Crypto as Cr +import Cardano.Ledger.Crypto import qualified Cardano.Ledger.EpochBoundary as EB import Cardano.Ledger.Keys (KeyRole (..), asWitness, coerceKeyRole) import Cardano.Ledger.PoolDistr ( @@ -154,7 +154,7 @@ mkStake :: EB.Stake c mkStake = EB.Stake . GHC.Exts.fromList . map (fmap toCompactCoinError) -initUTxO :: Cr.Crypto c => UTxO (ShelleyEra c) +initUTxO :: Crypto c => UTxO (ShelleyEra c) initUTxO = genesisCoins genesisId @@ -162,7 +162,7 @@ initUTxO = , ShelleyTxOut Cast.bobAddr (Val.inject bobInitCoin) ] -initStPoolLifetime :: forall c. Cr.Crypto c => ChainState (ShelleyEra c) +initStPoolLifetime :: forall c. Crypto c => ChainState (ShelleyEra c) initStPoolLifetime = initSt initUTxO -- @@ -185,7 +185,7 @@ dariaMIR = Coin 99 feeTx1 :: Coin feeTx1 = Coin 3 -txbodyEx1 :: Cr.Crypto c => ShelleyTxBody (ShelleyEra c) +txbodyEx1 :: Crypto c => ShelleyTxBody (ShelleyEra c) txbodyEx1 = ShelleyTxBody (Set.fromList [TxIn genesisId minBound]) @@ -292,7 +292,7 @@ aliceCoinEx2Ptr = aliceCoinEx1 <-> (aliceCoinEx2Base <+> feeTx2) -- | The transaction delegates Alice's and Bob's stake to Alice's pool. -- Additionally, we split Alice's ADA between a base address and a pointer address. -txbodyEx2 :: forall c. Cr.Crypto c => ShelleyTxBody (ShelleyEra c) +txbodyEx2 :: forall c. Crypto c => ShelleyTxBody (ShelleyEra c) txbodyEx2 = ShelleyTxBody { stbInputs = Set.fromList [TxIn (txIdTxBody (txbodyEx1 @c)) minBound] @@ -420,7 +420,7 @@ blockEx3 = 0 (mkOCert (coreNodeKeysBySchedule @(ShelleyEra c) ppEx 110) 0 (KESPeriod 0)) -snapEx3 :: Cr.Crypto c => EB.SnapShot c +snapEx3 :: Crypto c => EB.SnapShot c snapEx3 = EB.SnapShot { EB.ssStake = @@ -463,7 +463,7 @@ feeTx4 = Coin 5 aliceCoinEx4Base :: Coin aliceCoinEx4Base = aliceCoinEx2Base <-> feeTx4 -txbodyEx4 :: forall c. Cr.Crypto c => ShelleyTxBody (ShelleyEra c) +txbodyEx4 :: forall c. Crypto c => ShelleyTxBody (ShelleyEra c) txbodyEx4 = ShelleyTxBody { stbInputs = Set.fromList [TxIn (txIdTxBody txbodyEx2) minBound] @@ -563,7 +563,7 @@ blockEx5 = 10 (mkOCert (coreNodeKeysBySchedule @(ShelleyEra c) ppEx 220) 1 (KESPeriod 10)) -snapEx5 :: forall c. Cr.Crypto c => EB.SnapShot c +snapEx5 :: forall c. Crypto c => EB.SnapShot c snapEx5 = EB.SnapShot { EB.ssStake = @@ -580,7 +580,7 @@ snapEx5 = , EB.ssPoolParams = [(aikColdKeyHash Cast.alicePoolKeys, Cast.alicePoolParams)] } -pdEx5 :: forall c. Cr.Crypto c => PoolDistr c +pdEx5 :: forall c. Crypto c => PoolDistr c pdEx5 = PoolDistr ( Map.singleton @@ -752,7 +752,7 @@ alicePerfEx8 = likelihood blocks t (epochSize $ EpochNo 3) relativeStake = fromRational (stake % tot) f = activeSlotCoeff testGlobals -nonMyopicEx8 :: forall c. Cr.Crypto c => NonMyopic c +nonMyopicEx8 :: forall c. Crypto c => NonMyopic c nonMyopicEx8 = NonMyopic (Map.singleton (aikColdKeyHash Cast.alicePoolKeys) alicePerfEx8) @@ -762,7 +762,7 @@ pulserEx8 :: forall c. ExMock c => PulsingRewUpdate c pulserEx8 = makeCompletedPulser (BlocksMade $ Map.singleton (aikColdKeyHash Cast.alicePoolKeys) 1) expectedStEx7 -rewardUpdateEx8 :: forall c. Cr.Crypto c => RewardUpdate c +rewardUpdateEx8 :: forall c. Crypto c => RewardUpdate c rewardUpdateEx8 = RewardUpdate { deltaT = deltaT8 @@ -822,7 +822,7 @@ blockEx9 = 20 (mkOCert (coreNodeKeysBySchedule @(ShelleyEra c) ppEx 410) 2 (KESPeriod 20)) -snapEx9 :: forall c. Cr.Crypto c => EB.SnapShot c +snapEx9 :: forall c. Crypto c => EB.SnapShot c snapEx9 = snapEx5 { EB.ssStake = @@ -863,7 +863,7 @@ bobAda10 = <+> Coin 7 <-> feeTx10 -txbodyEx10 :: Cr.Crypto c => ShelleyTxBody (ShelleyEra c) +txbodyEx10 :: Crypto c => ShelleyTxBody (ShelleyEra c) txbodyEx10 = ShelleyTxBody (Set.fromList [mkTxInPartial genesisId 1]) @@ -929,7 +929,7 @@ aliceCoinEx11Ptr = aliceCoinEx4Base <-> feeTx11 aliceRetireEpoch :: EpochNo aliceRetireEpoch = EpochNo 5 -txbodyEx11 :: forall c. Cr.Crypto c => ShelleyTxBody (ShelleyEra c) +txbodyEx11 :: forall c. Crypto c => ShelleyTxBody (ShelleyEra c) txbodyEx11 = ShelleyTxBody (Set.fromList [TxIn (txIdTxBody txbodyEx4) minBound]) @@ -973,7 +973,7 @@ blockEx11 = reserves12 :: Coin reserves12 = addDeltaCoin reserves7 deltaR8 -alicePerfEx11 :: forall c. Cr.Crypto c => Likelihood +alicePerfEx11 :: forall c. Crypto c => Likelihood alicePerfEx11 = applyDecay decayFactor alicePerfEx8 <> epoch4Likelihood where epoch4Likelihood = likelihood blocks t (epochSize $ EpochNo 4) @@ -985,7 +985,7 @@ alicePerfEx11 = applyDecay decayFactor alicePerfEx8 <> epoch4Likelihood Coin supply = maxLLSupply <-> reserves12 f = activeSlotCoeff testGlobals -nonMyopicEx11 :: forall c. Cr.Crypto c => NonMyopic c +nonMyopicEx11 :: forall c. Crypto c => NonMyopic c nonMyopicEx11 = NonMyopic (Map.singleton (aikColdKeyHash Cast.alicePoolKeys) (alicePerfEx11 @c)) @@ -994,7 +994,7 @@ nonMyopicEx11 = pulserEx11 :: forall c. ExMock c => PulsingRewUpdate c pulserEx11 = makeCompletedPulser (BlocksMade mempty) expectedStEx10 -rewardUpdateEx11 :: forall c. Cr.Crypto c => RewardUpdate c +rewardUpdateEx11 :: forall c. Crypto c => RewardUpdate c rewardUpdateEx11 = RewardUpdate { deltaT = DeltaCoin 0 @@ -1044,7 +1044,7 @@ blockEx12 = 25 (mkOCert (coreNodeKeysBySchedule @(ShelleyEra c) ppEx 510) 3 (KESPeriod 25)) -snapEx12 :: forall c. Cr.Crypto c => EB.SnapShot c +snapEx12 :: forall c. Crypto c => EB.SnapShot c snapEx12 = snapEx9 { EB.ssStake = diff --git a/eras/shelley/test-suite/test/Test/Cardano/Ledger/Shelley/Serialisation/Golden/Encoding.hs b/eras/shelley/test-suite/test/Test/Cardano/Ledger/Shelley/Serialisation/Golden/Encoding.hs index 28ad8d2e784..6a9d88ea0ca 100644 --- a/eras/shelley/test-suite/test/Test/Cardano/Ledger/Shelley/Serialisation/Golden/Encoding.hs +++ b/eras/shelley/test-suite/test/Test/Cardano/Ledger/Shelley/Serialisation/Golden/Encoding.hs @@ -16,7 +16,7 @@ module Test.Cardano.Ledger.Shelley.Serialisation.Golden.Encoding (tests) where import qualified Cardano.Crypto.Hash as Monomorphic -import Cardano.Crypto.KES (SignedKES) +import Cardano.Crypto.KES (SignedKES, unsoundPureSignedKES) import Cardano.Crypto.VRF (CertifiedVRF) import Cardano.Ledger.Address (Addr (..), RewardAccount (..)) import Cardano.Ledger.BaseTypes ( @@ -76,7 +76,6 @@ import Cardano.Ledger.Keys ( hashKey, hashVerKeyVRF, signedDSIGN, - signedKES, ) import Cardano.Ledger.PoolParams ( PoolMetadata (..), @@ -382,7 +381,7 @@ testBHBSigTokens :: testBHBSigTokens = e where s = - signedKES @(KES (EraCrypto era)) + unsoundPureSignedKES @(KES (EraCrypto era)) () 0 (testBHB @era) @@ -990,7 +989,7 @@ tests = ) , -- checkEncodingCBOR "block_header" let sig :: (SignedKES (KES C_Crypto) (BHBody C_Crypto)) - sig = signedKES () 0 (testBHB @C) (kesSignKey $ testKESKeys @C_Crypto) + sig = unsoundPureSignedKES () 0 (testBHB @C) (kesSignKey $ testKESKeys @C_Crypto) in checkEncodingCBORAnnotated shelleyProtVer "block_header" @@ -1001,7 +1000,7 @@ tests = ) , -- checkEncodingCBOR "empty_block" let sig :: (SignedKES (KES C_Crypto) (BHBody C_Crypto)) - sig = signedKES () 0 (testBHB @C) (kesSignKey $ testKESKeys @C_Crypto) + sig = unsoundPureSignedKES () 0 (testBHB @C) (kesSignKey $ testKESKeys @C_Crypto) bh = BHeader (testBHB @C) sig txns = ShelleyTxSeq StrictSeq.Empty in checkEncodingCBORAnnotated @@ -1014,7 +1013,7 @@ tests = ) , -- checkEncodingCBOR "rich_block" let sig :: SignedKES (KES C_Crypto) (BHBody C_Crypto) - sig = signedKES () 0 (testBHB @C) (kesSignKey $ testKESKeys @C_Crypto) + sig = unsoundPureSignedKES () 0 (testBHB @C) (kesSignKey $ testKESKeys @C_Crypto) bh = BHeader (testBHB @C) sig tout = StrictSeq.singleton $ ShelleyTxOut @C testAddrE (Coin 2) txb :: Word64 -> ShelleyTxBody C diff --git a/flake.lock b/flake.lock index 4aa6499ca94..4facc2bdcbd 100644 --- a/flake.lock +++ b/flake.lock @@ -3,11 +3,11 @@ "CHaP": { "flake": false, "locked": { - "lastModified": 1726886523, - "narHash": "sha256-AEcPggMhxKSPlQPxciYiuJ9RRSqvszaZQQq5JEGICwc=", + "lastModified": 1730295876, + "narHash": "sha256-ijnHTQ6eKIQ9FpEqDKt6c7vuFYN8aOBDhonp67utx2s=", "owner": "intersectmbo", "repo": "cardano-haskell-packages", - "rev": "110f4bd9adf3809fa00af7807fb7f3edbf3d6538", + "rev": "25591f43ab943d5a070db5e8a2b9ff3a499d4d92", "type": "github" }, "original": { @@ -242,11 +242,11 @@ "hackage": { "flake": false, "locked": { - "lastModified": 1725409900, - "narHash": "sha256-XfSA7YyjHUfuNsCw4cE6p0kQcmrJgQq3nW36Cw/PAv0=", + "lastModified": 1730334523, + "narHash": "sha256-m3YpA8tDs3EA3UZZy8U9hDT4NJuKuwi67qnGAwMBdMw=", "owner": "input-output-hk", "repo": "hackage.nix", - "rev": "d86e544dec33ce5fb0ad3981be91074d397b700d", + "rev": "49a85d9969134eac18146e75d99e67dc454cfa34", "type": "github" }, "original": { @@ -295,11 +295,11 @@ "stackage": "stackage" }, "locked": { - "lastModified": 1725411053, - "narHash": "sha256-cW999pULNLOZHlV9sqBFIrWTkSxuVAVR6xJR7GndHdQ=", + "lastModified": 1730249446, + "narHash": "sha256-Eg5EoTFmrCWFKP32cCPXabeGJAc/opliIG2v1vqoTf4=", "owner": "input-output-hk", "repo": "haskell.nix", - "rev": "63783ecc949e99b2396ca821275cee26385adaba", + "rev": "2e69e4b902fdbb2d69991b1af2689bb83f98d43c", "type": "github" }, "original": { @@ -464,16 +464,16 @@ "hls-2.9": { "flake": false, "locked": { - "lastModified": 1718469202, - "narHash": "sha256-THXSz+iwB1yQQsr/PY151+2GvtoJnTIB2pIQ4OzfjD4=", + "lastModified": 1720003792, + "narHash": "sha256-qnDx8Pk0UxtoPr7BimEsAZh9g2WuTuMB/kGqnmdryKs=", "owner": "haskell", "repo": "haskell-language-server", - "rev": "40891bccb235ebacce020b598b083eab9dda80f1", + "rev": "0c1817cb2babef0765e4e72dd297c013e8e3d12b", "type": "github" }, "original": { "owner": "haskell", - "ref": "2.9.0.0", + "ref": "2.9.0.1", "repo": "haskell-language-server", "type": "github" } @@ -722,11 +722,11 @@ }, "nixpkgs-2405": { "locked": { - "lastModified": 1720122915, - "narHash": "sha256-Nby8WWxj0elBu1xuRaUcRjPi/rU3xVbkAt2kj4QwX2U=", + "lastModified": 1726447378, + "narHash": "sha256-2yV8nmYE1p9lfmLHhOCbYwQC/W8WYfGQABoGzJOb1JQ=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "835cf2d3f37989c5db6585a28de967a667a75fb1", + "rev": "086b448a5d54fd117f4dc2dee55c9f0ff461bdc1", "type": "github" }, "original": { @@ -770,11 +770,11 @@ }, "nixpkgs-unstable": { "locked": { - "lastModified": 1720181791, - "narHash": "sha256-i4vJL12/AdyuQuviMMd1Hk2tsGt02hDNhA0Zj1m16N8=", + "lastModified": 1726583932, + "narHash": "sha256-zACxiQx8knB3F8+Ze+1BpiYrI+CbhxyWpcSID9kVhkQ=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "4284c2b73c8bce4b46a6adf23e16d9e2ec8da4bb", + "rev": "658e7223191d2598641d50ee4e898126768fe847", "type": "github" }, "original": { @@ -906,11 +906,11 @@ "stackage": { "flake": false, "locked": { - "lastModified": 1725408838, - "narHash": "sha256-tHw95xcMElCqI6xOLmdTAEvQ0/4IS7WBZc+RF7HT/uk=", + "lastModified": 1730247073, + "narHash": "sha256-v4nQD0aQBb3QeKR87MswqEZV4ptEsOccAiMgursAKIY=", "owner": "input-output-hk", "repo": "stackage.nix", - "rev": "2ab3b5a823933ef199a289fbf39bbf0da0023100", + "rev": "3b68ec575a37eb76a937de8dc9d54435fed62e68", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index 62ad6a97e9e..dcc4f692cf1 100644 --- a/flake.nix +++ b/flake.nix @@ -132,10 +132,8 @@ # uncomment if necessary when profiling packages.byron-spec-chain.configureFlags = ["--ghc-option=-Werror"]; packages.byron-spec-ledger.configureFlags = ["--ghc-option=-Werror"]; - packages.delegation.configureFlags = ["--ghc-option=-Werror"]; packages.non-integral.configureFlags = ["--ghc-option=-Werror"]; packages.cardano-ledger-shelley.configureFlags = ["--ghc-option=-Werror"]; - packages.cardano-ledger-shelley-ma.configureFlags = ["--ghc-option=-Werror"]; packages.cardano-ledger-shelley-ma-test.configureFlags = ["--ghc-option=-Werror"]; packages.small-steps.configureFlags = ["--ghc-option=-Werror"]; packages.cardano-ledger-byron = { diff --git a/libs/cardano-ledger-binary/.ghcid b/libs/cardano-ledger-binary/.ghcid index 996f651d355..aa68a71ebf7 100644 --- a/libs/cardano-ledger-binary/.ghcid +++ b/libs/cardano-ledger-binary/.ghcid @@ -1 +1 @@ ---command="cabal repl --repl-options='-isrc -fwarn-unused-binds -fwarn-unused-imports -fno-code -fobject-code -g2 -fno-break-on-exception -fno-break-on-error -ferror-spans -j -Wno-unused-packages'" --clear --no-height-limit --reverse-errors --reload=../../ --outputfile=/tmp/cardano-ledger-binary-ghcid.txt \ No newline at end of file +--command="cabal repl --repl-options='-isrc -fwarn-unused-binds -fwarn-unused-imports -fno-code -fobject-code -g2 -fno-break-on-exception -fno-break-on-error -ferror-spans -j -Wno-unused-packages'" --clear --no-height-limit --reverse-errors --reload=../../ --outputfile=/tmp/cardano-ledger-binary-ghcid.txt diff --git a/libs/cardano-ledger-binary/src/Cardano/Ledger/Binary/Crypto.hs b/libs/cardano-ledger-binary/src/Cardano/Ledger/Binary/Crypto.hs index 831e4f39465..ca849eef8b0 100644 --- a/libs/cardano-ledger-binary/src/Cardano/Ledger/Binary/Crypto.hs +++ b/libs/cardano-ledger-binary/src/Cardano/Ledger/Binary/Crypto.hs @@ -14,8 +14,6 @@ module Cardano.Ledger.Binary.Crypto ( -- * KES encodeVerKeyKES, decodeVerKeyKES, - encodeSignKeyKES, - decodeSignKeyKES, encodeSigKES, decodeSigKES, encodeSignedKES, @@ -85,14 +83,6 @@ decodeVerKeyKES :: C.KESAlgorithm v => Decoder s (C.VerKeyKES v) decodeVerKeyKES = fromPlainDecoder C.decodeVerKeyKES {-# INLINE decodeVerKeyKES #-} -encodeSignKeyKES :: C.KESAlgorithm v => C.SignKeyKES v -> Encoding -encodeSignKeyKES = fromPlainEncoding . C.encodeSignKeyKES -{-# INLINE encodeSignKeyKES #-} - -decodeSignKeyKES :: C.KESAlgorithm v => Decoder s (C.SignKeyKES v) -decodeSignKeyKES = fromPlainDecoder C.decodeSignKeyKES -{-# INLINE decodeSignKeyKES #-} - encodeSigKES :: C.KESAlgorithm v => C.SigKES v -> Encoding encodeSigKES = fromPlainEncoding . C.encodeSigKES {-# INLINE encodeSigKES #-} diff --git a/libs/cardano-ledger-binary/src/Cardano/Ledger/Binary/Decoding/DecCBOR.hs b/libs/cardano-ledger-binary/src/Cardano/Ledger/Binary/Decoding/DecCBOR.hs index 9b41743131c..e8730d8b5b3 100644 --- a/libs/cardano-ledger-binary/src/Cardano/Ledger/Binary/Decoding/DecCBOR.hs +++ b/libs/cardano-ledger-binary/src/Cardano/Ledger/Binary/Decoding/DecCBOR.hs @@ -23,20 +23,13 @@ where import qualified Cardano.Binary as Plain (Decoder, FromCBOR (..)) import Cardano.Crypto.DSIGN.Class ( DSIGNAlgorithm, - SeedSizeDSIGN, SigDSIGN, SignKeyDSIGN, SignedDSIGN, VerKeyDSIGN, ) import Cardano.Crypto.Hash.Class (Hash, HashAlgorithm) -import Cardano.Crypto.KES.Class (KESAlgorithm, OptimizedKESAlgorithm, SigKES, SignKeyKES, VerKeyKES) -import Cardano.Crypto.KES.CompactSingle (CompactSingleKES) -import Cardano.Crypto.KES.CompactSum (CompactSumKES) -import Cardano.Crypto.KES.Mock (MockKES) -import Cardano.Crypto.KES.Simple (SimpleKES) -import Cardano.Crypto.KES.Single (SingleKES) -import Cardano.Crypto.KES.Sum (SumKES) +import Cardano.Crypto.KES.Class (KESAlgorithm, SigKES, VerKeyKES) import Cardano.Crypto.VRF.Class ( CertVRF, CertifiedVRF (..), @@ -92,7 +85,6 @@ import qualified Data.Vector.Storable as VS import qualified Data.Vector.Unboxed as VU import Data.Void (Void) import Data.Word (Word16, Word32, Word64, Word8) -import GHC.TypeNats (KnownNat, type (*)) import Numeric.Natural (Natural) import qualified PlutusLedgerApi.V1 as PV1 import qualified PlutusLedgerApi.V2 as PV2 @@ -487,93 +479,11 @@ instance (HashAlgorithm h, Typeable a) => DecCBOR (Hash h a) -- KES -------------------------------------------------------------------------------- -instance - (DSIGNAlgorithm d, KnownNat t, KnownNat (SeedSizeDSIGN d * t)) => - DecCBOR (VerKeyKES (SimpleKES d t)) - where - decCBOR = decodeVerKeyKES - {-# INLINE decCBOR #-} - -instance - (DSIGNAlgorithm d, KnownNat t, KnownNat (SeedSizeDSIGN d * t)) => - DecCBOR (SignKeyKES (SimpleKES d t)) - where - decCBOR = decodeSignKeyKES - {-# INLINE decCBOR #-} - -instance - (DSIGNAlgorithm d, KnownNat t, KnownNat (SeedSizeDSIGN d * t)) => - DecCBOR (SigKES (SimpleKES d t)) - where - decCBOR = decodeSigKES - {-# INLINE decCBOR #-} - -instance (KESAlgorithm d, HashAlgorithm h) => DecCBOR (VerKeyKES (SumKES h d)) where - decCBOR = decodeVerKeyKES - {-# INLINE decCBOR #-} - -instance (KESAlgorithm d, HashAlgorithm h) => DecCBOR (SignKeyKES (SumKES h d)) where - decCBOR = decodeSignKeyKES - {-# INLINE decCBOR #-} - -instance (KESAlgorithm d, HashAlgorithm h) => DecCBOR (SigKES (SumKES h d)) where - decCBOR = decodeSigKES - {-# INLINE decCBOR #-} - -instance DSIGNAlgorithm d => DecCBOR (VerKeyKES (CompactSingleKES d)) where - decCBOR = decodeVerKeyKES - {-# INLINE decCBOR #-} - -instance DSIGNAlgorithm d => DecCBOR (SignKeyKES (CompactSingleKES d)) where - decCBOR = decodeSignKeyKES - {-# INLINE decCBOR #-} - -instance DSIGNAlgorithm d => DecCBOR (SigKES (CompactSingleKES d)) where - decCBOR = decodeSigKES - {-# INLINE decCBOR #-} - -instance - (OptimizedKESAlgorithm d, HashAlgorithm h) => - DecCBOR (VerKeyKES (CompactSumKES h d)) - where +instance KESAlgorithm k => DecCBOR (VerKeyKES k) where decCBOR = decodeVerKeyKES {-# INLINE decCBOR #-} -instance - (OptimizedKESAlgorithm d, HashAlgorithm h) => - DecCBOR (SignKeyKES (CompactSumKES h d)) - where - decCBOR = decodeSignKeyKES - {-# INLINE decCBOR #-} - -instance - (OptimizedKESAlgorithm d, HashAlgorithm h) => - DecCBOR (SigKES (CompactSumKES h d)) - where - decCBOR = decodeSigKES - {-# INLINE decCBOR #-} - -instance DSIGNAlgorithm d => DecCBOR (VerKeyKES (SingleKES d)) where - decCBOR = decodeVerKeyKES - {-# INLINE decCBOR #-} - -instance DSIGNAlgorithm d => DecCBOR (SignKeyKES (SingleKES d)) where - decCBOR = decodeSignKeyKES - {-# INLINE decCBOR #-} - -instance DSIGNAlgorithm d => DecCBOR (SigKES (SingleKES d)) where - decCBOR = decodeSigKES - {-# INLINE decCBOR #-} - -instance KnownNat t => DecCBOR (VerKeyKES (MockKES t)) where - decCBOR = decodeVerKeyKES - {-# INLINE decCBOR #-} - -instance KnownNat t => DecCBOR (SignKeyKES (MockKES t)) where - decCBOR = decodeSignKeyKES - {-# INLINE decCBOR #-} - -instance KnownNat t => DecCBOR (SigKES (MockKES t)) where +instance KESAlgorithm k => DecCBOR (SigKES k) where decCBOR = decodeSigKES {-# INLINE decCBOR #-} diff --git a/libs/cardano-ledger-binary/src/Cardano/Ledger/Binary/Encoding/EncCBOR.hs b/libs/cardano-ledger-binary/src/Cardano/Ledger/Binary/Encoding/EncCBOR.hs index 99586f051d5..24984e3c47a 100644 --- a/libs/cardano-ledger-binary/src/Cardano/Ledger/Binary/Encoding/EncCBOR.hs +++ b/libs/cardano-ledger-binary/src/Cardano/Ledger/Binary/Encoding/EncCBOR.hs @@ -13,6 +13,7 @@ {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE StandaloneDeriving #-} {-# LANGUAGE TypeApplications #-} +{-# LANGUAGE TypeFamilies #-} {-# LANGUAGE TypeOperators #-} {-# LANGUAGE UndecidableInstances #-} {-# LANGUAGE NoStarIsType #-} @@ -57,7 +58,6 @@ where import Cardano.Crypto.DSIGN.Class ( DSIGNAlgorithm, - SeedSizeDSIGN, SigDSIGN, SignKeyDSIGN, SignedDSIGN, @@ -74,7 +74,6 @@ import Cardano.Crypto.Hash.Class ( ) import Cardano.Crypto.KES.Class ( KESAlgorithm, - OptimizedKESAlgorithm, SigKES, SignKeyKES, VerKeyKES, @@ -82,12 +81,6 @@ import Cardano.Crypto.KES.Class ( sizeSignKeyKES, sizeVerKeyKES, ) -import Cardano.Crypto.KES.CompactSingle (CompactSingleKES) -import Cardano.Crypto.KES.CompactSum (CompactSumKES) -import Cardano.Crypto.KES.Mock (MockKES) -import Cardano.Crypto.KES.Simple (SimpleKES) -import Cardano.Crypto.KES.Single (SingleKES) -import Cardano.Crypto.KES.Sum (SumKES) import Cardano.Crypto.VRF.Class ( CertVRF, CertifiedVRF (..), @@ -159,7 +152,6 @@ import Data.Word (Word16, Word32, Word64, Word8) import Foreign.Storable (sizeOf) import Formatting (bprint, build, shown, stext) import qualified Formatting.Buildable as B (Buildable (..)) -import GHC.TypeNats (KnownNat, type (*)) import Numeric.Natural (Natural) import qualified PlutusLedgerApi.V1 as PV1 import qualified PlutusLedgerApi.V2 as PV2 @@ -941,102 +933,11 @@ encodedSigKESSizeExpr _proxy = -- payload + fromIntegral (sizeSigKES (Proxy :: Proxy v)) -instance - (DSIGNAlgorithm d, KnownNat t, KnownNat (SeedSizeDSIGN d * t)) => - EncCBOR (VerKeyKES (SimpleKES d t)) - where - encCBOR = encodeVerKeyKES - encodedSizeExpr _size = encodedVerKeyKESSizeExpr - -instance - (DSIGNAlgorithm d, KnownNat t, KnownNat (SeedSizeDSIGN d * t)) => - EncCBOR (SignKeyKES (SimpleKES d t)) - where - encCBOR = encodeSignKeyKES - encodedSizeExpr _size = encodedSignKeyKESSizeExpr - -instance - (DSIGNAlgorithm d, KnownNat t, KnownNat (SeedSizeDSIGN d * t)) => - EncCBOR (SigKES (SimpleKES d t)) - where - encCBOR = encodeSigKES - encodedSizeExpr _size = encodedSigKESSizeExpr - -instance - (KESAlgorithm d, HashAlgorithm h) => - EncCBOR (VerKeyKES (SumKES h d)) - where - encCBOR = encodeVerKeyKES - encodedSizeExpr _size = encodedVerKeyKESSizeExpr - -instance - (KESAlgorithm d, HashAlgorithm h) => - EncCBOR (SignKeyKES (SumKES h d)) - where - encCBOR = encodeSignKeyKES - encodedSizeExpr _size = encodedSignKeyKESSizeExpr - -instance - (KESAlgorithm d, HashAlgorithm h) => - EncCBOR (SigKES (SumKES h d)) - where - encCBOR = encodeSigKES - encodedSizeExpr _size = encodedSigKESSizeExpr - -instance DSIGNAlgorithm d => EncCBOR (VerKeyKES (CompactSingleKES d)) where - encCBOR = encodeVerKeyKES - encodedSizeExpr _size = encodedVerKeyKESSizeExpr - -instance DSIGNAlgorithm d => EncCBOR (SignKeyKES (CompactSingleKES d)) where - encCBOR = encodeSignKeyKES - encodedSizeExpr _size = encodedSignKeyKESSizeExpr - -instance DSIGNAlgorithm d => EncCBOR (SigKES (CompactSingleKES d)) where - encCBOR = encodeSigKES - encodedSizeExpr _size = encodedSigKESSizeExpr - -instance - (OptimizedKESAlgorithm d, HashAlgorithm h) => - EncCBOR (VerKeyKES (CompactSumKES h d)) - where +instance KESAlgorithm k => EncCBOR (VerKeyKES k) where encCBOR = encodeVerKeyKES encodedSizeExpr _size = encodedVerKeyKESSizeExpr -instance - (OptimizedKESAlgorithm d, HashAlgorithm h) => - EncCBOR (SignKeyKES (CompactSumKES h d)) - where - encCBOR = encodeSignKeyKES - encodedSizeExpr _size = encodedSignKeyKESSizeExpr - -instance - (OptimizedKESAlgorithm d, HashAlgorithm h) => - EncCBOR (SigKES (CompactSumKES h d)) - where - encCBOR = encodeSigKES - encodedSizeExpr _size = encodedSigKESSizeExpr - -instance DSIGNAlgorithm d => EncCBOR (VerKeyKES (SingleKES d)) where - encCBOR = encodeVerKeyKES - encodedSizeExpr _size = encodedVerKeyKESSizeExpr - -instance DSIGNAlgorithm d => EncCBOR (SignKeyKES (SingleKES d)) where - encCBOR = encodeSignKeyKES - encodedSizeExpr _size = encodedSignKeyKESSizeExpr - -instance DSIGNAlgorithm d => EncCBOR (SigKES (SingleKES d)) where - encCBOR = encodeSigKES - encodedSizeExpr _size = encodedSigKESSizeExpr - -instance KnownNat t => EncCBOR (VerKeyKES (MockKES t)) where - encCBOR = encodeVerKeyKES - encodedSizeExpr _size = encodedVerKeyKESSizeExpr - -instance KnownNat t => EncCBOR (SignKeyKES (MockKES t)) where - encCBOR = encodeSignKeyKES - encodedSizeExpr _size = encodedSignKeyKESSizeExpr - -instance KnownNat t => EncCBOR (SigKES (MockKES t)) where +instance KESAlgorithm k => EncCBOR (SigKES k) where encCBOR = encodeSigKES encodedSizeExpr _size = encodedSigKESSizeExpr diff --git a/libs/cardano-ledger-binary/test/Test/Cardano/Ledger/Binary/RoundTripSpec.hs b/libs/cardano-ledger-binary/test/Test/Cardano/Ledger/Binary/RoundTripSpec.hs index a89d82689ba..e5812de1c92 100644 --- a/libs/cardano-ledger-binary/test/Test/Cardano/Ledger/Binary/RoundTripSpec.hs +++ b/libs/cardano-ledger-binary/test/Test/Cardano/Ledger/Binary/RoundTripSpec.hs @@ -17,7 +17,7 @@ import Cardano.Crypto.Hash.Keccak256 (Keccak256) import Cardano.Crypto.Hash.SHA256 (SHA256) import Cardano.Crypto.Hash.SHA3_256 (SHA3_256) import Cardano.Crypto.Hash.Short (ShortHash) -import Cardano.Crypto.KES.Class (SigKES, SignKeyKES, VerKeyKES) +import Cardano.Crypto.KES.Class (SigKES, VerKeyKES) import Cardano.Crypto.KES.CompactSingle (CompactSingleKES) import Cardano.Crypto.KES.CompactSum ( CompactSum0KES, @@ -173,73 +173,44 @@ spec = do roundTripSpec @(CertVRF MockVRF) cborTrip describe "KES" $ do describe "CompactSingle" $ do - roundTripSpec @(SignKeyKES (CompactSingleKES Ed25519DSIGN)) cborTrip roundTripSpec @(VerKeyKES (CompactSingleKES Ed25519DSIGN)) cborTrip roundTripSpec @(SigKES (CompactSingleKES Ed25519DSIGN)) cborTrip describe "CompactSum" $ do - roundTripSpec @(SignKeyKES (CompactSum0KES Ed25519DSIGN)) cborTrip roundTripSpec @(VerKeyKES (CompactSum0KES Ed25519DSIGN)) cborTrip roundTripSpec @(SigKES (CompactSum0KES Ed25519DSIGN)) cborTrip - roundTripSpec @(SignKeyKES (CompactSum1KES Ed25519DSIGN Blake2b_256)) cborTrip roundTripSpec @(VerKeyKES (CompactSum1KES Ed25519DSIGN Blake2b_256)) cborTrip roundTripSpec @(SigKES (CompactSum1KES Ed25519DSIGN Blake2b_256)) cborTrip - roundTripSpec @(SignKeyKES (CompactSum2KES Ed25519DSIGN Blake2b_256)) cborTrip roundTripSpec @(VerKeyKES (CompactSum2KES Ed25519DSIGN Blake2b_256)) cborTrip roundTripSpec @(SigKES (CompactSum2KES Ed25519DSIGN Blake2b_256)) cborTrip - roundTripSpec @(SignKeyKES (CompactSum3KES Ed25519DSIGN Blake2b_256)) cborTrip roundTripSpec @(VerKeyKES (CompactSum3KES Ed25519DSIGN Blake2b_256)) cborTrip roundTripSpec @(SigKES (CompactSum3KES Ed25519DSIGN Blake2b_256)) cborTrip - roundTripSpec @(SignKeyKES (CompactSum4KES Ed25519DSIGN Blake2b_256)) cborTrip roundTripSpec @(VerKeyKES (CompactSum4KES Ed25519DSIGN Blake2b_256)) cborTrip roundTripSpec @(SigKES (CompactSum4KES Ed25519DSIGN Blake2b_256)) cborTrip - roundTripSpec @(SignKeyKES (CompactSum5KES Ed25519DSIGN Blake2b_256)) cborTrip roundTripSpec @(VerKeyKES (CompactSum5KES Ed25519DSIGN Blake2b_256)) cborTrip roundTripSpec @(SigKES (CompactSum5KES Ed25519DSIGN Blake2b_256)) cborTrip - roundTripSpec @(SignKeyKES (CompactSum6KES Ed25519DSIGN Blake2b_256)) cborTrip roundTripSpec @(VerKeyKES (CompactSum6KES Ed25519DSIGN Blake2b_256)) cborTrip roundTripSpec @(SigKES (CompactSum6KES Ed25519DSIGN Blake2b_256)) cborTrip - roundTripSpec @(SignKeyKES (CompactSum7KES Ed25519DSIGN Blake2b_256)) cborTrip roundTripSpec @(VerKeyKES (CompactSum7KES Ed25519DSIGN Blake2b_256)) cborTrip roundTripSpec @(SigKES (CompactSum7KES Ed25519DSIGN Blake2b_256)) cborTrip describe "Sum" $ do - roundTripSpec @(SignKeyKES (Sum0KES Ed25519DSIGN)) cborTrip roundTripSpec @(VerKeyKES (Sum0KES Ed25519DSIGN)) cborTrip roundTripSpec @(SigKES (Sum0KES Ed25519DSIGN)) cborTrip - roundTripSpec @(SignKeyKES (Sum1KES Ed25519DSIGN Blake2b_256)) cborTrip roundTripSpec @(VerKeyKES (Sum1KES Ed25519DSIGN Blake2b_256)) cborTrip roundTripSpec @(SigKES (Sum1KES Ed25519DSIGN Blake2b_256)) cborTrip - roundTripSpec @(SignKeyKES (Sum2KES Ed25519DSIGN Blake2b_256)) cborTrip roundTripSpec @(VerKeyKES (Sum2KES Ed25519DSIGN Blake2b_256)) cborTrip roundTripSpec @(SigKES (Sum2KES Ed25519DSIGN Blake2b_256)) cborTrip - roundTripSpec @(SignKeyKES (Sum3KES Ed25519DSIGN Blake2b_256)) cborTrip roundTripSpec @(VerKeyKES (Sum3KES Ed25519DSIGN Blake2b_256)) cborTrip roundTripSpec @(SigKES (Sum3KES Ed25519DSIGN Blake2b_256)) cborTrip - roundTripSpec @(SignKeyKES (Sum4KES Ed25519DSIGN Blake2b_256)) cborTrip roundTripSpec @(VerKeyKES (Sum4KES Ed25519DSIGN Blake2b_256)) cborTrip roundTripSpec @(SigKES (Sum4KES Ed25519DSIGN Blake2b_256)) cborTrip - roundTripSpec @(SignKeyKES (Sum5KES Ed25519DSIGN Blake2b_256)) cborTrip roundTripSpec @(VerKeyKES (Sum5KES Ed25519DSIGN Blake2b_256)) cborTrip roundTripSpec @(SigKES (Sum5KES Ed25519DSIGN Blake2b_256)) cborTrip - roundTripSpec @(SignKeyKES (Sum6KES Ed25519DSIGN Blake2b_256)) cborTrip roundTripSpec @(VerKeyKES (Sum6KES Ed25519DSIGN Blake2b_256)) cborTrip roundTripSpec @(SigKES (Sum6KES Ed25519DSIGN Blake2b_256)) cborTrip - roundTripSpec @(SignKeyKES (Sum7KES Ed25519DSIGN Blake2b_256)) cborTrip roundTripSpec @(VerKeyKES (Sum7KES Ed25519DSIGN Blake2b_256)) cborTrip roundTripSpec @(SigKES (Sum7KES Ed25519DSIGN Blake2b_256)) cborTrip -- below we also test some tuple roundtripping as well as KES describe "Simple" $ do - roundTripSpec - @( SignKeyKES (SimpleKES Ed25519DSIGN 1) - , SignKeyKES (SimpleKES Ed25519DSIGN 2) - , SignKeyKES (SimpleKES Ed25519DSIGN 3) - , SignKeyKES (SimpleKES Ed25519DSIGN 4) - , SignKeyKES (SimpleKES Ed25519DSIGN 5) - , SignKeyKES (SimpleKES Ed25519DSIGN 6) - ) - cborTrip - roundTripSpec - @(SignKeyKES (SimpleKES Ed25519DSIGN 7)) - cborTrip roundTripSpec @( VerKeyKES (SimpleKES Ed25519DSIGN 1) , VerKeyKES (SimpleKES Ed25519DSIGN 2) @@ -264,19 +235,18 @@ spec = do ) cborTrip describe "Mock" $ do - roundTripSpec @(SignKeyKES (MockKES 7)) cborTrip roundTripSpec @(VerKeyKES (MockKES 7)) cborTrip roundTripSpec @(SigKES (MockKES 7)) cborTrip - describe "Hash" $ do - roundTripSpec - @( Hash Blake2b_224 () - , Hash Blake2b_256 () - , Hash SHA256 () - , Hash SHA3_256 () - , Hash Keccak256 () - , Hash ShortHash () - ) - cborTrip + describe "Hash" $ do + roundTripSpec + @( Hash Blake2b_224 () + , Hash Blake2b_256 () + , Hash SHA256 () + , Hash SHA3_256 () + , Hash Keccak256 () + , Hash ShortHash () + ) + cborTrip describe "EmbedTrip" $ do forM_ [shelleyProtVer .. maxBound] $ \v -> describe (show v) $ do diff --git a/libs/cardano-ledger-binary/testlib/Test/Cardano/Ledger/Binary/Arbitrary.hs b/libs/cardano-ledger-binary/testlib/Test/Cardano/Ledger/Binary/Arbitrary.hs index 40530bd4cf1..7f13de380ec 100644 --- a/libs/cardano-ledger-binary/testlib/Test/Cardano/Ledger/Binary/Arbitrary.hs +++ b/libs/cardano-ledger-binary/testlib/Test/Cardano/Ledger/Binary/Arbitrary.hs @@ -19,6 +19,7 @@ module Test.Cardano.Ledger.Binary.Arbitrary ( where import Cardano.Crypto.DSIGN.Class hiding (Signable) +import qualified Cardano.Crypto.KES.Class as KES import Cardano.Crypto.Util import Cardano.Crypto.VRF.Class import Cardano.Ledger.Binary.Version @@ -30,7 +31,9 @@ import Codec.CBOR.ByteArray.Sliced (SlicedByteArray (..)) import Codec.CBOR.Term import qualified Data.ByteString as BS (ByteString, pack, unpack) import qualified Data.ByteString.Lazy as BSL (ByteString, fromChunks, fromStrict, toChunks) +import GHC.TypeLits (natVal) import Numeric.Half +import Test.Crypto.Util (arbitrarySeedOfSize) #if MIN_VERSION_bytestring(0,11,1) import qualified Data.ByteString.Short as SBS #else @@ -237,3 +240,22 @@ genByteArray n = do sbs <- genShortByteString n case sbs of SBS.SBS ba -> pure (Prim.ByteArray ba) + +instance KES.KESAlgorithm v => Arbitrary (KES.VerKeyKES v) where + arbitrary = do + bs <- genByteString (fromInteger (natVal (Proxy @(KES.SizeVerKeyKES v)))) + case KES.rawDeserialiseVerKeyKES bs of + Nothing -> error "Impossible: the size of VerKeyKES is specified statically" + Just vk -> pure vk + +instance KES.KESAlgorithm v => Arbitrary (KES.SigKES v) where + arbitrary = do + bs <- genByteString (fromInteger (natVal (Proxy @(KES.SizeSigKES v)))) + case KES.rawDeserialiseSigKES bs of + Nothing -> error "Impossible: the size of SigKES is specified statically" + Just vk -> pure vk + +instance KES.UnsoundPureKESAlgorithm v => Arbitrary (KES.UnsoundPureSignKeyKES v) where + arbitrary = KES.unsoundPureGenKeyKES <$> arbitrarySeedOfSize seedSize + where + seedSize = KES.seedSizeKES (Proxy :: Proxy v) diff --git a/libs/cardano-ledger-core/src/Cardano/Ledger/Crypto.hs b/libs/cardano-ledger-core/src/Cardano/Ledger/Crypto.hs index 53887b9f6ea..d29f04189ce 100644 --- a/libs/cardano-ledger-core/src/Cardano/Ledger/Crypto.hs +++ b/libs/cardano-ledger-core/src/Cardano/Ledger/Crypto.hs @@ -17,7 +17,7 @@ class ( HashAlgorithm (HASH c) , HashAlgorithm (ADDRHASH c) , DSIGNAlgorithm (DSIGN c) - , KESAlgorithm (KES c) + , UnsoundPureKESAlgorithm (KES c) , VRFAlgorithm (VRF c) , ContextDSIGN (DSIGN c) ~ () , ContextKES (KES c) ~ () diff --git a/libs/cardano-ledger-core/src/Cardano/Ledger/Orphans.hs b/libs/cardano-ledger-core/src/Cardano/Ledger/Orphans.hs index a0189a246a9..44c1ad5ac77 100644 --- a/libs/cardano-ledger-core/src/Cardano/Ledger/Orphans.hs +++ b/libs/cardano-ledger-core/src/Cardano/Ledger/Orphans.hs @@ -83,6 +83,3 @@ instance HS.HashAlgorithm h => Default (Hash h b) where UnsafeHash $ Short.pack $ replicate (fromIntegral (Hash.sizeHash (Proxy :: Proxy h))) 0 - -instance Default Bool where - def = False diff --git a/libs/cardano-protocol-tpraos/testlib/Test/Cardano/Protocol/Crypto/KES.hs b/libs/cardano-protocol-tpraos/testlib/Test/Cardano/Protocol/Crypto/KES.hs index 91073f34c90..4e1f360b352 100644 --- a/libs/cardano-protocol-tpraos/testlib/Test/Cardano/Protocol/Crypto/KES.hs +++ b/libs/cardano-protocol-tpraos/testlib/Test/Cardano/Protocol/Crypto/KES.hs @@ -9,15 +9,14 @@ module Test.Cardano.Protocol.Crypto.KES ( import qualified Cardano.Crypto.KES.Class as KES import Cardano.Ledger.Crypto -import Cardano.Ledger.Keys ( - SignKeyKES, - VerKeyKES, - ) +import Cardano.Ledger.Keys (VerKeyKES) data KESKeyPair c = KESKeyPair - { kesSignKey :: !(SignKeyKES c) + { kesSignKey :: !(KES.UnsoundPureSignKeyKES (KES c)) , kesVerKey :: !(VerKeyKES c) } -deriving instance - (Show (KES.SignKeyKES (KES c)), Show (KES.VerKeyKES (KES c))) => Show (KESKeyPair c) +instance Show (KES.VerKeyKES (KES c)) => Show (KESKeyPair c) where + show (KESKeyPair _ vk) = + -- showing `SignKeyKES` is impossible for security reasons. + "KESKeyPair " <> show vk diff --git a/libs/cardano-protocol-tpraos/testlib/Test/Cardano/Protocol/Crypto/VRF/Fake.hs b/libs/cardano-protocol-tpraos/testlib/Test/Cardano/Protocol/Crypto/VRF/Fake.hs index 51dd7e7bbb2..eab693351d4 100644 --- a/libs/cardano-protocol-tpraos/testlib/Test/Cardano/Protocol/Crypto/VRF/Fake.hs +++ b/libs/cardano-protocol-tpraos/testlib/Test/Cardano/Protocol/Crypto/VRF/Fake.hs @@ -117,8 +117,8 @@ instance VRFAlgorithm FakeVRF where -- This implementation of 'verifyVRF' checks the real proof, which is contained -- in the certificate, but ignores the produced value, and insteads returns -- the output which is stored in the 'CertFakeVRF'. - verifyVRF () (VerKeyFakeVRF n) a (CertFakeVRF _ proof o) - | proof == recomputedProof = Just o + verifyVRF () (VerKeyFakeVRF n) a (CertFakeVRF _ proof _) + | proof == recomputedProof = Just (OutputVRF recomputedProofBytes) | otherwise = Nothing where (OutputVRF recomputedProofBytes, _) = evalFakeVRF a (SignKeyFakeVRF n) diff --git a/libs/cardano-protocol-tpraos/testlib/Test/Cardano/Protocol/TPraos/Arbitrary.hs b/libs/cardano-protocol-tpraos/testlib/Test/Cardano/Protocol/TPraos/Arbitrary.hs index d32c740cdc3..4276b984bdb 100644 --- a/libs/cardano-protocol-tpraos/testlib/Test/Cardano/Protocol/TPraos/Arbitrary.hs +++ b/libs/cardano-protocol-tpraos/testlib/Test/Cardano/Protocol/TPraos/Arbitrary.hs @@ -25,7 +25,6 @@ import Cardano.Ledger.BaseTypes (BlockNo (..), Nonce, Seed, SlotNo (..)) import Cardano.Ledger.Block (Block (Block)) import Cardano.Ledger.Core import Cardano.Ledger.Crypto (Crypto (KES, VRF), DSIGN) -import Cardano.Ledger.Keys (signedKES) import Cardano.Protocol.TPraos.API (PraosCrypto) import Cardano.Protocol.TPraos.BHeader ( BHBody (BHBody), @@ -69,7 +68,7 @@ instance arbitrary = do bhBody <- arbitrary hotKey <- arbitrary - let sig = signedKES () 1 bhBody hotKey + let sig = KES.unsoundPureSignedKES () 1 bhBody hotKey pure $ BHeader bhBody sig genBHeader :: diff --git a/libs/cardano-protocol-tpraos/testlib/Test/Cardano/Protocol/TPraos/Create.hs b/libs/cardano-protocol-tpraos/testlib/Test/Cardano/Protocol/TPraos/Create.hs index e6c7b9ae3e7..2e84cf7e907 100644 --- a/libs/cardano-protocol-tpraos/testlib/Test/Cardano/Protocol/TPraos/Create.hs +++ b/libs/cardano-protocol-tpraos/testlib/Test/Cardano/Protocol/TPraos/Create.hs @@ -44,7 +44,6 @@ import Cardano.Ledger.Keys ( KeyHash, KeyRole (..), signedDSIGN, - signedKES, ) import Cardano.Protocol.TPraos.BHeader ( BHBody (..), @@ -199,24 +198,24 @@ mkBHeader pKeys kesPeriod keyRegKesPeriod bhBody = , "kpDiff: " ++ show kpDiff ] Just hKey -> hKey - sig = signedKES () kpDiff bhBody hotKey + sig = KES.unsoundPureSignedKES () kpDiff bhBody hotKey in BHeader bhBody sig -- | Try to evolve KES key until specific KES period is reached, given the -- current KES period. evolveKESUntil :: - (KES.KESAlgorithm v, KES.ContextKES v ~ ()) => - KES.SignKeyKES v -> + (KES.UnsoundPureKESAlgorithm v, KES.ContextKES v ~ ()) => + KES.UnsoundPureSignKeyKES v -> -- | Current KES period KESPeriod -> -- | Target KES period KESPeriod -> - Maybe (KES.SignKeyKES v) + Maybe (KES.UnsoundPureSignKeyKES v) evolveKESUntil sk1 (KESPeriod current) (KESPeriod target) = go sk1 current target where go !_ c t | t < c = Nothing go !sk c t | c == t = Just sk - go !sk c t = case KES.updateKES () sk c of + go !sk c t = case KES.unsoundPureUpdateKES () sk c of Nothing -> Nothing Just sk' -> go sk' (c + 1) t