From 49504f51565f200efece44036b2a03d7a146ca75 Mon Sep 17 00:00:00 2001 From: Alexey Kuleshevich Date: Mon, 16 Dec 2024 17:47:17 -0700 Subject: [PATCH] Move `Crypto` class and `StandardCrypto` to protocol-tpraos Since #4788 `Crypto` and `StandardCrypto` only define `KES` and `VRF`, which are primitives unused by ledger. For this reason they are now being moved to `cardano-protocol-tpraos` package --- .../test/Test/Cardano/Ledger/Alonzo/Golden.hs | 2 +- .../Ledger/Alonzo/Serialisation/Tripping.hs | 2 +- .../Ledger/Babbage/Serialisation/Tripping.hs | 2 +- .../src/Test/Cardano/Ledger/EraBuffet.hs | 2 - .../shelley/impl/cardano-ledger-shelley.cabal | 1 - .../src/Cardano/Ledger/Shelley/API/Types.hs | 8 -- .../src/Cardano/Ledger/Shelley/Genesis.hs | 18 ++-- .../Test/Cardano/Ledger/Shelley/Arbitrary.hs | 21 ----- eras/shelley/test-suite/CHANGELOG.md | 1 + .../test-suite/bench/BenchValidation.hs | 2 +- .../Cardano/Ledger/Shelley/Bench/Rewards.hs | 3 +- .../Ledger/Shelley/BenchmarkFunctions.hs | 2 +- .../Ledger/Shelley/ConcreteCryptoTypes.hs | 4 +- .../Cardano/Ledger/Shelley/Examples/Cast.hs | 2 +- .../Ledger/Shelley/Examples/Consensus.hs | 1 + .../Ledger/Shelley/Examples/Federation.hs | 2 +- .../Cardano/Ledger/Shelley/Generator/Block.hs | 2 +- .../Ledger/Shelley/Generator/Presets.hs | 2 +- .../Ledger/Shelley/Generator/TxCert.hs | 7 +- .../Test/Cardano/Ledger/Shelley/Rewards.hs | 3 +- .../src/Test/Cardano/Ledger/Shelley/Utils.hs | 3 +- .../Shelley/Examples/GenesisDelegation.hs | 2 +- .../test/Test/Cardano/Ledger/Shelley/Fees.hs | 3 +- .../Shelley/Serialisation/Golden/Encoding.hs | 5 +- .../Shelley/Serialisation/Golden/Genesis.hs | 4 +- .../Shelley/Serialisation/Tripping/CBOR.hs | 2 +- .../Test/Cardano/Ledger/Shelley/UnitTests.hs | 16 +--- .../src/Cardano/Ledger/Api/Era.hs | 5 -- .../cardano-ledger-core.cabal | 1 - .../src/Cardano/Ledger/Crypto.hs | 31 ------- .../src/Cardano/Ledger/Keys/Internal.hs | 58 +------------ .../Cardano/Ledger/Examples/AlonzoBBODY.hs | 2 +- libs/cardano-protocol-tpraos/CHANGELOG.md | 3 + .../cardano-protocol-tpraos.cabal | 2 + .../src/Cardano/Protocol/Crypto.hs | 83 +++++++++++++++++++ .../src/Cardano/Protocol/TPraos/API.hs | 4 +- .../src/Cardano/Protocol/TPraos/BHeader.hs | 10 +-- .../src/Cardano/Protocol/TPraos/OCert.hs | 3 +- .../Cardano/Protocol/TPraos/Rules/OCert.hs | 3 +- .../Cardano/Protocol/TPraos/Rules/Overlay.hs | 4 +- .../Cardano/Protocol/TPraos/Rules/Prtcl.hs | 10 +-- .../src/Cardano/Protocol/TPraos/Rules/Updn.hs | 2 +- .../Test/Cardano/Protocol/Binary/CddlSpec.hs | 2 +- .../Test/Cardano/Protocol/Crypto/KES.hs | 3 +- .../Test/Cardano/Protocol/Crypto/VRF.hs | 6 +- .../Test/Cardano/Protocol/TPraos/Arbitrary.hs | 21 ++++- .../Test/Cardano/Protocol/TPraos/Create.hs | 2 +- 47 files changed, 167 insertions(+), 210 deletions(-) create mode 100644 libs/cardano-protocol-tpraos/src/Cardano/Protocol/Crypto.hs diff --git a/eras/alonzo/test-suite/test/Test/Cardano/Ledger/Alonzo/Golden.hs b/eras/alonzo/test-suite/test/Test/Cardano/Ledger/Alonzo/Golden.hs index 71739fc8a2a..c8cd10a5c57 100644 --- a/eras/alonzo/test-suite/test/Test/Cardano/Ledger/Alonzo/Golden.hs +++ b/eras/alonzo/test-suite/test/Test/Cardano/Ledger/Alonzo/Golden.hs @@ -38,6 +38,7 @@ import Cardano.Ledger.Plutus.ExUnits ( Prices (..), ) import Cardano.Ledger.Plutus.Language (Language (..)) +import Cardano.Protocol.Crypto (StandardCrypto) import Cardano.Protocol.TPraos.BHeader (BHeader) import Data.Aeson (eitherDecodeFileStrict) import qualified Data.Aeson as Aeson @@ -55,7 +56,6 @@ import Lens.Micro import Paths_cardano_ledger_alonzo_test import qualified PlutusLedgerApi.V1 as PV1 (Data (..)) import Test.Cardano.Ledger.Alonzo.Examples.Consensus (ledgerExamplesAlonzo) -import Test.Cardano.Ledger.EraBuffet (StandardCrypto) import Test.Cardano.Ledger.Mary.Golden ( largestName, minUTxO, diff --git a/eras/alonzo/test-suite/test/Test/Cardano/Ledger/Alonzo/Serialisation/Tripping.hs b/eras/alonzo/test-suite/test/Test/Cardano/Ledger/Alonzo/Serialisation/Tripping.hs index 0bb91673d57..39217091b96 100644 --- a/eras/alonzo/test-suite/test/Test/Cardano/Ledger/Alonzo/Serialisation/Tripping.hs +++ b/eras/alonzo/test-suite/test/Test/Cardano/Ledger/Alonzo/Serialisation/Tripping.hs @@ -18,9 +18,9 @@ import Cardano.Ledger.Alonzo.Rules ( import Cardano.Ledger.Alonzo.Scripts (eqAlonzoScriptRaw) import Cardano.Ledger.Block (Block) import Cardano.Ledger.Core -import Cardano.Ledger.Crypto (StandardCrypto) import Cardano.Ledger.MemoBytes (zipMemoRawType) import Cardano.Ledger.Plutus.Data (BinaryData, Data (..)) +import Cardano.Protocol.Crypto (StandardCrypto) import Cardano.Protocol.TPraos.BHeader (BHeader) import Test.Cardano.Ledger.Alonzo.Arbitrary () import Test.Cardano.Ledger.Alonzo.Serialisation.Generators () diff --git a/eras/babbage/test-suite/test/Test/Cardano/Ledger/Babbage/Serialisation/Tripping.hs b/eras/babbage/test-suite/test/Test/Cardano/Ledger/Babbage/Serialisation/Tripping.hs index 9b3d8d79f2c..39bed6e58a2 100644 --- a/eras/babbage/test-suite/test/Test/Cardano/Ledger/Babbage/Serialisation/Tripping.hs +++ b/eras/babbage/test-suite/test/Test/Cardano/Ledger/Babbage/Serialisation/Tripping.hs @@ -10,7 +10,7 @@ import Cardano.Ledger.Babbage (BabbageEra) import Cardano.Ledger.Babbage.Rules (BabbageUtxoPredFailure) import Cardano.Ledger.Block (Block) import Cardano.Ledger.Core -import Cardano.Ledger.Crypto (StandardCrypto) +import Cardano.Protocol.Crypto (StandardCrypto) import Cardano.Protocol.TPraos.BHeader (BHeader) import Test.Cardano.Ledger.Babbage.Arbitrary () import Test.Cardano.Ledger.Babbage.Serialisation.Generators () diff --git a/eras/shelley-ma/test-suite/src/Test/Cardano/Ledger/EraBuffet.hs b/eras/shelley-ma/test-suite/src/Test/Cardano/Ledger/EraBuffet.hs index a8d1a54053a..ccc9d501eeb 100644 --- a/eras/shelley-ma/test-suite/src/Test/Cardano/Ledger/EraBuffet.hs +++ b/eras/shelley-ma/test-suite/src/Test/Cardano/Ledger/EraBuffet.hs @@ -1,5 +1,4 @@ module Test.Cardano.Ledger.EraBuffet ( - StandardCrypto, ShelleyEra, MaryEra, AllegraEra, @@ -13,6 +12,5 @@ where import Cardano.Ledger.Allegra (AllegraEra) import Cardano.Ledger.Core (Era, Script, TxAuxData, TxBody, Value) -import Cardano.Ledger.Crypto (StandardCrypto) import Cardano.Ledger.Mary (MaryEra) import Cardano.Ledger.Shelley (ShelleyEra) diff --git a/eras/shelley/impl/cardano-ledger-shelley.cabal b/eras/shelley/impl/cardano-ledger-shelley.cabal index 0f7b8854297..4f987c9a963 100644 --- a/eras/shelley/impl/cardano-ledger-shelley.cabal +++ b/eras/shelley/impl/cardano-ledger-shelley.cabal @@ -161,7 +161,6 @@ library testlib ImpSpec, base, bytestring, - cardano-crypto-class, cardano-data, cardano-ledger-binary:{cardano-ledger-binary, testlib}, cardano-ledger-byron, diff --git a/eras/shelley/impl/src/Cardano/Ledger/Shelley/API/Types.hs b/eras/shelley/impl/src/Cardano/Ledger/Shelley/API/Types.hs index 94714a84c21..1f0f15bbc14 100644 --- a/eras/shelley/impl/src/Cardano/Ledger/Shelley/API/Types.hs +++ b/eras/shelley/impl/src/Cardano/Ledger/Shelley/API/Types.hs @@ -40,25 +40,17 @@ import Cardano.Ledger.EpochBoundary as X ( Stake (..), ) import Cardano.Ledger.Keys as X ( - CertifiedVRF, GenDelegPair (..), GenDelegs (..), Hash, - KESignable, KeyHash (..), KeyRole (..), SignKeyDSIGN, - SignKeyKES, - SignKeyVRF, SignedDSIGN, - SignedKES, VKey (..), - VerKeyKES, - VerKeyVRF, WitVKey (..), coerceKeyRole, hashKey, - hashVerKeyVRF, ) import Cardano.Ledger.Keys.Bootstrap as X ( BootstrapWitness (..), diff --git a/eras/shelley/impl/src/Cardano/Ledger/Shelley/Genesis.hs b/eras/shelley/impl/src/Cardano/Ledger/Shelley/Genesis.hs index 7ddcd84c6f3..f01d84a5c3e 100644 --- a/eras/shelley/impl/src/Cardano/Ledger/Shelley/Genesis.hs +++ b/eras/shelley/impl/src/Cardano/Ledger/Shelley/Genesis.hs @@ -41,8 +41,10 @@ module Cardano.Ledger.Shelley.Genesis ( ) where -import qualified Cardano.Crypto.Hash.Class as Crypto -import Cardano.Crypto.KES.Class (totalPeriodsKES) +import Cardano.Crypto.DSIGN (Ed25519DSIGN) +import Cardano.Crypto.Hash (Blake2b_256) +import qualified Cardano.Crypto.Hash.Class as H +import Cardano.Crypto.KES (Sum6KES, totalPeriodsKES) import Cardano.Ledger.Address (Addr, serialiseAddr) import Cardano.Ledger.BaseTypes ( ActiveSlotCoeff, @@ -74,7 +76,7 @@ import Cardano.Ledger.Binary ( ) import Cardano.Ledger.Coin (Coin) import Cardano.Ledger.Core -import Cardano.Ledger.Crypto (HASH, KES, StandardCrypto) +import Cardano.Ledger.Crypto (HASH) import Cardano.Ledger.Genesis (EraGenesis (..)) import Cardano.Ledger.Keys import Cardano.Ledger.PoolParams (PoolParams (..)) @@ -559,11 +561,11 @@ initialFundsPseudoTxIn addr = pseudoTxId = TxId . unsafeMakeSafeHash - . ( Crypto.castHash :: - Crypto.Hash HASH Addr -> - Crypto.Hash HASH EraIndependentTxBody + . ( H.castHash :: + H.Hash HASH Addr -> + H.Hash HASH EraIndependentTxBody ) - . Crypto.hashWith serialiseAddr + . H.hashWith serialiseAddr {------------------------------------------------------------------------------- Genesis validation @@ -644,7 +646,7 @@ validateGenesis activeSlotsCoeff minLength else Nothing - kesPeriods = totalPeriodsKES (Proxy @(KES StandardCrypto)) + kesPeriods = totalPeriodsKES (Proxy @(Sum6KES Ed25519DSIGN Blake2b_256)) checkKesEvolutions = if sgMaxKESEvolutions <= fromIntegral kesPeriods then Nothing diff --git a/eras/shelley/impl/testlib/Test/Cardano/Ledger/Shelley/Arbitrary.hs b/eras/shelley/impl/testlib/Test/Cardano/Ledger/Shelley/Arbitrary.hs index 27eda00a93c..dc941d08a41 100644 --- a/eras/shelley/impl/testlib/Test/Cardano/Ledger/Shelley/Arbitrary.hs +++ b/eras/shelley/impl/testlib/Test/Cardano/Ledger/Shelley/Arbitrary.hs @@ -24,15 +24,12 @@ module Test.Cardano.Ledger.Shelley.Arbitrary ( RawSeed (..), ASC (..), StakeProportion (..), - VRFNatVal (..), sizedNativeScriptGens, ) where import qualified Cardano.Chain.UTxO as Byron -import qualified Cardano.Crypto.VRF as VRF import Cardano.Ledger.BaseTypes import Cardano.Ledger.Binary (EncCBOR) -import Cardano.Ledger.Crypto import Cardano.Ledger.Shelley (ShelleyEra) import Cardano.Ledger.Shelley.API ( ApplyTxError (ApplyTxError), @@ -86,13 +83,11 @@ import Control.Monad.Identity (Identity) import qualified Data.ByteString.Char8 as BS (length, pack) import qualified Data.ListMap as LM import qualified Data.Map.Strict as Map (fromList) -import Data.Proxy (Proxy (Proxy)) import Data.Sequence.Strict (fromList) import qualified Data.Text as T (pack) import qualified Data.Text.Encoding as T (encodeUtf8) import Data.Word (Word64) import Generic.Random (genericArbitraryU) -import Numeric.Natural (Natural) import Test.Cardano.Chain.UTxO.Gen (genCompactTxOut) import Test.Cardano.Ledger.Common import Test.Cardano.Ledger.Core.Arbitrary () @@ -467,22 +462,6 @@ instance (Era era, Arbitrary (PParamsUpdate era)) => Arbitrary (Update era) wher arbitrary = genericArbitraryU shrink = genericShrink -newtype VRFNatVal = VRFNatVal Natural - deriving (Show) - -instance Arbitrary VRFNatVal where - arbitrary = - VRFNatVal . fromIntegral - <$> choose @Integer - ( 0 - , 2 - ^ ( 8 - * VRF.sizeOutputVRF - (Proxy @(VRF StandardCrypto)) - ) - ) - shrink (VRFNatVal v) = VRFNatVal <$> shrinkIntegral v - instance Arbitrary Byron.CompactTxOut where arbitrary = hedgehog genCompactTxOut diff --git a/eras/shelley/test-suite/CHANGELOG.md b/eras/shelley/test-suite/CHANGELOG.md index 6c393526a6e..ada169f9536 100644 --- a/eras/shelley/test-suite/CHANGELOG.md +++ b/eras/shelley/test-suite/CHANGELOG.md @@ -2,6 +2,7 @@ ## 1.6.0.0 +* Move `VRFNatVal` into `cardano-protocol-tpraos:testlib` * Account for removal of crypto parametrization * Remove crypto parametrization from `PoolSetUpArgs`, `PoolInfo`, `RewardUpdateOld` * Add `MockCrypto` diff --git a/eras/shelley/test-suite/bench/BenchValidation.hs b/eras/shelley/test-suite/bench/BenchValidation.hs index 0fb8ebe05f2..ca94466a0a1 100644 --- a/eras/shelley/test-suite/bench/BenchValidation.hs +++ b/eras/shelley/test-suite/bench/BenchValidation.hs @@ -29,7 +29,6 @@ module BenchValidation ( import Cardano.Ledger.BaseTypes (Globals (..), unBlocksMade) import Cardano.Ledger.Block (Block (..)) -import Cardano.Ledger.Crypto import qualified Cardano.Ledger.Shelley.API as API import Cardano.Ledger.Shelley.Bench.Gen (genBlock, genChainState) import Cardano.Ledger.Shelley.BlockChain (slotToNonce) @@ -39,6 +38,7 @@ import Cardano.Ledger.Shelley.LedgerState ( StashedAVVMAddresses, nesBcur, ) +import Cardano.Protocol.Crypto import Cardano.Protocol.TPraos.API ( ChainDepState (..), ChainTransitionError, diff --git a/eras/shelley/test-suite/bench/Cardano/Ledger/Shelley/Bench/Rewards.hs b/eras/shelley/test-suite/bench/Cardano/Ledger/Shelley/Bench/Rewards.hs index 77e4fd0be07..849f22eb2ba 100644 --- a/eras/shelley/test-suite/bench/Cardano/Ledger/Shelley/Bench/Rewards.hs +++ b/eras/shelley/test-suite/bench/Cardano/Ledger/Shelley/Bench/Rewards.hs @@ -22,13 +22,14 @@ import Cardano.Ledger.BaseTypes ( ) import Cardano.Ledger.Coin (Coin (..)) import Cardano.Ledger.Credential (Credential (..), StakeReference (..)) -import Cardano.Ledger.Keys (KeyHash, KeyRole (Staking), hashVerKeyVRF) +import Cardano.Ledger.Keys (KeyHash, KeyRole (Staking)) import Cardano.Ledger.PoolParams (PoolParams (..)) import Cardano.Ledger.Shelley (ShelleyEra) import Cardano.Ledger.Shelley.Genesis (ShelleyGenesisStaking (..)) import qualified Cardano.Ledger.Shelley.LedgerState as LS import Cardano.Ledger.Shelley.TxOut (ShelleyTxOut (..)) import Cardano.Ledger.UTxO (UTxO (..)) +import Cardano.Protocol.Crypto (hashVerKeyVRF) import Cardano.Slotting.EpochInfo import Cardano.Slotting.Slot (EpochNo) import Control.Monad.Reader (runReader, runReaderT) diff --git a/eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/BenchmarkFunctions.hs b/eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/BenchmarkFunctions.hs index fcd66102d6f..335efd5ebc5 100644 --- a/eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/BenchmarkFunctions.hs +++ b/eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/BenchmarkFunctions.hs @@ -43,7 +43,6 @@ import Cardano.Ledger.Keys ( VRFVerKeyHash, asWitness, hashKey, - hashVerKeyVRF, ) import Cardano.Ledger.PoolParams ( PoolParams (..), @@ -72,6 +71,7 @@ import Cardano.Ledger.Shelley.TxOut (ShelleyTxOut (..)) import Cardano.Ledger.Shelley.TxWits (addrWits) import Cardano.Ledger.Slot (EpochNo (..), SlotNo (..)) import Cardano.Ledger.TxIn (TxIn (..), mkTxInPartial) +import Cardano.Protocol.Crypto (hashVerKeyVRF) import Control.State.Transition.Extended (TRC (..), applySTS) import Data.Default (def) import qualified Data.Map.Strict as Map diff --git a/eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/ConcreteCryptoTypes.hs b/eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/ConcreteCryptoTypes.hs index e6f3212c1dc..61951d4eed9 100644 --- a/eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/ConcreteCryptoTypes.hs +++ b/eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/ConcreteCryptoTypes.hs @@ -12,8 +12,8 @@ module Test.Cardano.Ledger.Shelley.ConcreteCryptoTypes ( where import Cardano.Crypto.KES (MockKES) -import Cardano.Ledger.Crypto import Cardano.Ledger.Shelley (ShelleyEra) +import Cardano.Protocol.Crypto import Cardano.Protocol.TPraos.API (PraosCrypto) import Test.Cardano.Protocol.Crypto.VRF.Fake (FakeVRF) @@ -21,7 +21,7 @@ type C = ShelleyEra data MockCrypto -instance Cardano.Ledger.Crypto.Crypto MockCrypto where +instance Crypto MockCrypto where type KES MockCrypto = MockKES 10 type VRF MockCrypto = FakeVRF diff --git a/eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/Examples/Cast.hs b/eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/Examples/Cast.hs index ee84f7b79a9..a0d758713f2 100644 --- a/eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/Examples/Cast.hs +++ b/eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/Examples/Cast.hs @@ -56,13 +56,13 @@ import Cardano.Ledger.Keys ( KeyRoleVRF (StakePoolVRF), VRFVerKeyHash, hashKey, - hashVerKeyVRF, ) import Cardano.Ledger.PoolParams ( PoolMetadata (..), PoolParams (..), ) import Cardano.Ledger.Slot (SlotNo (..)) +import Cardano.Protocol.Crypto (hashVerKeyVRF) import Cardano.Protocol.TPraos.OCert (KESPeriod (..)) import qualified Data.ByteString.Char8 as BS (pack) import qualified Data.List.NonEmpty as NE 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 a2c37bc123a..ff493c56d9a 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 @@ -31,6 +31,7 @@ import Cardano.Ledger.Shelley.LedgerState import Cardano.Ledger.Shelley.Rules import Cardano.Ledger.Shelley.Translation (emptyFromByronTranslationContext) import Cardano.Ledger.Shelley.TxWits +import Cardano.Protocol.Crypto import Cardano.Protocol.TPraos.API import Cardano.Protocol.TPraos.BHeader import Cardano.Protocol.TPraos.OCert diff --git a/eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/Examples/Federation.hs b/eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/Examples/Federation.hs index 23d67315f12..711db9f2f30 100644 --- a/eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/Examples/Federation.hs +++ b/eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/Examples/Federation.hs @@ -30,9 +30,9 @@ import Cardano.Ledger.Keys ( VKey (..), coerceKeyRole, hashKey, - hashVerKeyVRF, ) import Cardano.Ledger.Slot (SlotNo (..)) +import Cardano.Protocol.Crypto (hashVerKeyVRF) import Cardano.Protocol.TPraos.OCert (KESPeriod (..)) import Cardano.Protocol.TPraos.Rules.Overlay ( OBftSlot (..), diff --git a/eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/Generator/Block.hs b/eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/Generator/Block.hs index 71d555cb3c8..64492414464 100644 --- a/eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/Generator/Block.hs +++ b/eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/Generator/Block.hs @@ -18,11 +18,11 @@ where import qualified Cardano.Crypto.VRF as VRF import Cardano.Ledger.BHeaderView (bhviewBSize, bhviewHSize) import Cardano.Ledger.BaseTypes (UnitInterval) -import Cardano.Ledger.Crypto (VRF) import Cardano.Ledger.Shelley.API import Cardano.Ledger.Shelley.Core import Cardano.Ledger.Shelley.LedgerState (curPParamsEpochStateL) import Cardano.Ledger.Slot (SlotNo (..)) +import Cardano.Protocol.Crypto (VRF) import Cardano.Protocol.TPraos.API import Cardano.Protocol.TPraos.BHeader ( BHeader (..), diff --git a/eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/Generator/Presets.hs b/eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/Generator/Presets.hs index c546ed77b77..92efdfb20dd 100644 --- a/eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/Generator/Presets.hs +++ b/eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/Generator/Presets.hs @@ -27,8 +27,8 @@ import Cardano.Ledger.Keys ( KeyRole (..), coerceKeyRole, hashKey, - hashVerKeyVRF, ) +import Cardano.Protocol.Crypto (hashVerKeyVRF) import Cardano.Protocol.TPraos.OCert (KESPeriod (..)) import Data.List.NonEmpty (NonEmpty ((:|))) import Data.Map.Strict (Map) diff --git a/eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/Generator/TxCert.hs b/eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/Generator/TxCert.hs index 4f51eb11590..b26fcc57634 100644 --- a/eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/Generator/TxCert.hs +++ b/eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/Generator/TxCert.hs @@ -18,11 +18,7 @@ where import Cardano.Ledger.Address (RewardAccount (..)) import Cardano.Ledger.Coin (DeltaCoin (..), toDeltaCoin) -import Cardano.Ledger.Keys ( - coerceKeyRole, - hashKey, - hashVerKeyVRF, - ) +import Cardano.Ledger.Keys (coerceKeyRole, hashKey) import Cardano.Ledger.Shelley.API ( AccountState (..), CertState (..), @@ -44,6 +40,7 @@ import qualified Cardano.Ledger.Shelley.HardForks as HardForks import Cardano.Ledger.Shelley.LedgerState (availableAfterMIR, rewards) import Cardano.Ledger.Slot (EpochNo (EpochNo), SlotNo) import qualified Cardano.Ledger.UMap as UM +import Cardano.Protocol.Crypto (hashVerKeyVRF) import Control.Monad (replicateM) import Control.SetAlgebra (dom, domain, eval, (∈)) import Data.Foldable (fold) diff --git a/eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/Rewards.hs b/eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/Rewards.hs index e7ddc1d975b..58d7f562ffb 100644 --- a/eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/Rewards.hs +++ b/eras/shelley/test-suite/src/Test/Cardano/Ledger/Shelley/Rewards.hs @@ -49,7 +49,6 @@ import Cardano.Ledger.Binary (encCBOR, hashWithEncoder, natVersion, shelleyProtV import Cardano.Ledger.Coin (Coin (..), DeltaCoin (..), rationalToCoinViaFloor, toDeltaCoin) import Cardano.Ledger.Compactible import Cardano.Ledger.Credential (Credential (..)) -import Cardano.Ledger.Crypto (VRF) import Cardano.Ledger.EpochBoundary ( Stake (..), maxPool, @@ -62,7 +61,6 @@ import Cardano.Ledger.Keys ( KeyRole (..), VKey (..), hashKey, - hashVerKeyVRF, ) import Cardano.Ledger.Shelley.API (NonMyopic, SnapShot (..), SnapShots (..)) import Cardano.Ledger.Shelley.API.Types (PoolParams (..)) @@ -111,6 +109,7 @@ import Cardano.Ledger.Shelley.TxBody (RewardAccount (..)) import Cardano.Ledger.Slot (epochInfoSize) import qualified Cardano.Ledger.UMap as UM import Cardano.Ledger.Val (Val (..), invert, (<+>), (<->)) +import Cardano.Protocol.Crypto (VRF, hashVerKeyVRF) import Cardano.Slotting.Slot (EpochSize (..)) import Control.Monad (replicateM) import Control.Monad.Trans.Reader (asks, runReader) 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 39629352563..1e26d3cb53c 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 @@ -73,10 +73,11 @@ import Cardano.Ledger.BaseTypes ( import Cardano.Ledger.Binary (EncCBOR (..), hashWithEncoder, shelleyProtVer) import Cardano.Ledger.Block (Block, bheader) import Cardano.Ledger.Coin (Coin (..)) -import Cardano.Ledger.Crypto (Crypto, DSIGN) +import Cardano.Ledger.Crypto (DSIGN) import Cardano.Ledger.Shelley.API (ApplyBlock, KeyRole (..), VKey (..)) import Cardano.Ledger.Shelley.Core import Cardano.Ledger.Slot (EpochNo, EpochSize (..), SlotNo) +import Cardano.Protocol.Crypto (Crypto) import Cardano.Protocol.TPraos.API (GetLedgerView) import Cardano.Protocol.TPraos.BHeader (BHBody (..), BHeader, bhbody) import Cardano.Slotting.EpochInfo ( diff --git a/eras/shelley/test-suite/test/Test/Cardano/Ledger/Shelley/Examples/GenesisDelegation.hs b/eras/shelley/test-suite/test/Test/Cardano/Ledger/Shelley/Examples/GenesisDelegation.hs index 44faba26e37..bad86e63eb8 100644 --- a/eras/shelley/test-suite/test/Test/Cardano/Ledger/Shelley/Examples/GenesisDelegation.hs +++ b/eras/shelley/test-suite/test/Test/Cardano/Ledger/Shelley/Examples/GenesisDelegation.hs @@ -26,7 +26,6 @@ import Cardano.Ledger.Keys ( VRFVerKeyHash, asWitness, hashKey, - hashVerKeyVRF, ) import Cardano.Ledger.SafeHash (hashAnnotated) import Cardano.Ledger.Shelley (ShelleyEra) @@ -41,6 +40,7 @@ import Cardano.Ledger.TxIn (TxIn (..)) import Cardano.Ledger.UTxO (UTxO (..)) import Cardano.Ledger.Val ((<->)) import qualified Cardano.Ledger.Val as Val +import Cardano.Protocol.Crypto (hashVerKeyVRF) import Cardano.Protocol.TPraos.BHeader (BHeader, bhHash) import Cardano.Protocol.TPraos.OCert (KESPeriod (..)) import Data.Default (Default) diff --git a/eras/shelley/test-suite/test/Test/Cardano/Ledger/Shelley/Fees.hs b/eras/shelley/test-suite/test/Test/Cardano/Ledger/Shelley/Fees.hs index 68014cad348..a692b6f8ef9 100644 --- a/eras/shelley/test-suite/test/Test/Cardano/Ledger/Shelley/Fees.hs +++ b/eras/shelley/test-suite/test/Test/Cardano/Ledger/Shelley/Fees.hs @@ -24,7 +24,6 @@ import Cardano.Ledger.BaseTypes ( import Cardano.Ledger.Binary.Plain as Plain (serialize) import Cardano.Ledger.Coin (Coin (..)) import Cardano.Ledger.Core -import Cardano.Ledger.Crypto (StandardCrypto) import Cardano.Ledger.Keys (KeyHash, KeyRole (..), asWitness, hashKey) import Cardano.Ledger.PoolParams (PoolMetadata (..), StakePoolRelay (..)) import Cardano.Ledger.SafeHash (hashAnnotated) @@ -37,7 +36,6 @@ import Cardano.Ledger.Shelley.API ( ShelleyTxBody (..), ShelleyTxOut (..), TxIn (..), - hashVerKeyVRF, ) import Cardano.Ledger.Shelley.Scripts ( ShelleyEraScript, @@ -61,6 +59,7 @@ import Cardano.Ledger.Slot (EpochNo (..), SlotNo (..)) import Cardano.Ledger.Tools (estimateMinFeeTx) import Cardano.Ledger.TxIn (mkTxInPartial) import qualified Cardano.Ledger.Val as Val +import Cardano.Protocol.Crypto (StandardCrypto, hashVerKeyVRF) import qualified Data.ByteString.Base16.Lazy as Base16 import qualified Data.ByteString.Char8 as BS (pack) import qualified Data.ByteString.Lazy as BSL 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 37b01ee0a39..0639b585947 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 @@ -55,13 +55,13 @@ import Cardano.Ledger.Binary ( ) import Cardano.Ledger.Binary.Crypto ( encodeSignedDSIGN, + encodeSignedKES, encodeVerKeyDSIGN, ) import qualified Cardano.Ledger.Binary.Plain as Plain import Cardano.Ledger.Block (Block (..)) import Cardano.Ledger.Coin (Coin (..), DeltaCoin (..)) import Cardano.Ledger.Credential (Credential (..), StakeReference (..)) -import Cardano.Ledger.Crypto import Cardano.Ledger.Keys ( Hash, KeyHash (..), @@ -72,9 +72,7 @@ import Cardano.Ledger.Keys ( VRFVerKeyHash, WitVKey (..), asWitness, - encodeSignedKES, hashKey, - hashVerKeyVRF, signedDSIGN, ) import Cardano.Ledger.PoolParams ( @@ -101,6 +99,7 @@ import Cardano.Ledger.Shelley.TxOut (ShelleyTxOut (..)) import Cardano.Ledger.Shelley.TxWits (ShelleyTxWits, addrWits) import Cardano.Ledger.Slot (BlockNo (..), EpochNo (..), SlotNo (..)) import Cardano.Ledger.TxIn (TxId, TxIn (..)) +import Cardano.Protocol.Crypto hiding (CertifiedVRF, SignedKES) import Cardano.Protocol.TPraos.BHeader ( BHBody (..), BHeader (..), diff --git a/eras/shelley/test-suite/test/Test/Cardano/Ledger/Shelley/Serialisation/Golden/Genesis.hs b/eras/shelley/test-suite/test/Test/Cardano/Ledger/Shelley/Serialisation/Golden/Genesis.hs index 34de2c52e4f..5fa4f2fd32d 100644 --- a/eras/shelley/test-suite/test/Test/Cardano/Ledger/Shelley/Serialisation/Golden/Genesis.hs +++ b/eras/shelley/test-suite/test/Test/Cardano/Ledger/Shelley/Serialisation/Golden/Genesis.hs @@ -18,11 +18,11 @@ import Cardano.Ledger.BaseTypes (textToDns, textToUrl) import Cardano.Ledger.Binary (Tokens (..)) import qualified Cardano.Ledger.Binary.Plain as Plain import Cardano.Ledger.Core (emptyPParams, ppDL, ppMaxBBSizeL, ppMaxBHSizeL) -import Cardano.Ledger.Crypto (StandardCrypto) -import Cardano.Ledger.Keys (KeyRoleVRF (..), VRFVerKeyHash (..), hashKey, hashVerKeyVRF) +import Cardano.Ledger.Keys (KeyRoleVRF (..), VRFVerKeyHash (..), hashKey) import Cardano.Ledger.Shelley (ShelleyEra) import qualified Cardano.Ledger.Shelley.API as L import Cardano.Ledger.Shelley.Genesis +import Cardano.Protocol.Crypto (StandardCrypto, hashVerKeyVRF) import Cardano.Slotting.Slot (EpochSize (..)) import Control.Monad import Data.Aeson hiding (Encoding) diff --git a/eras/shelley/test-suite/test/Test/Cardano/Ledger/Shelley/Serialisation/Tripping/CBOR.hs b/eras/shelley/test-suite/test/Test/Cardano/Ledger/Shelley/Serialisation/Tripping/CBOR.hs index eec0f8b95b3..b7ef5734fde 100644 --- a/eras/shelley/test-suite/test/Test/Cardano/Ledger/Shelley/Serialisation/Tripping/CBOR.hs +++ b/eras/shelley/test-suite/test/Test/Cardano/Ledger/Shelley/Serialisation/Tripping/CBOR.hs @@ -13,10 +13,10 @@ module Test.Cardano.Ledger.Shelley.Serialisation.Tripping.CBOR ( where import Cardano.Ledger.Core -import Cardano.Ledger.Crypto (StandardCrypto) import Cardano.Ledger.Shelley (ShelleyEra) import Cardano.Ledger.Shelley.API as Ledger import qualified Cardano.Ledger.Shelley.Rules as STS +import Cardano.Protocol.Crypto (StandardCrypto) import qualified Cardano.Protocol.TPraos.BHeader as TP import qualified Cardano.Protocol.TPraos.Rules.Prtcl as STS (PrtclState) import Test.Cardano.Ledger.Binary.RoundTrip diff --git a/eras/shelley/test-suite/test/Test/Cardano/Ledger/Shelley/UnitTests.hs b/eras/shelley/test-suite/test/Test/Cardano/Ledger/Shelley/UnitTests.hs index ea29779da00..c979517b176 100644 --- a/eras/shelley/test-suite/test/Test/Cardano/Ledger/Shelley/UnitTests.hs +++ b/eras/shelley/test-suite/test/Test/Cardano/Ledger/Shelley/UnitTests.hs @@ -17,17 +17,8 @@ import qualified Cardano.Crypto.VRF as VRF import Cardano.Ledger.Address (Addr (..), raCredential, pattern RewardAccount) import Cardano.Ledger.BaseTypes hiding ((==>)) import Cardano.Ledger.Coin -import Cardano.Ledger.Credential ( - Credential (..), - StakeReference (..), - ) -import Cardano.Ledger.Crypto (StandardCrypto, VRF) -import Cardano.Ledger.Keys ( - KeyRole (..), - asWitness, - hashKey, - hashVerKeyVRF, - ) +import Cardano.Ledger.Credential (Credential (..), StakeReference (..)) +import Cardano.Ledger.Keys (KeyRole (..), asWitness, hashKey) import Cardano.Ledger.PoolParams ( PoolMetadata (..), PoolParams (..), @@ -78,6 +69,7 @@ import Cardano.Ledger.Shelley.TxWits ( import Cardano.Ledger.TxIn (TxIn (..)) import qualified Cardano.Ledger.UMap as UM import Cardano.Ledger.Val ((<+>), (<->)) +import Cardano.Protocol.Crypto (StandardCrypto, VRF, hashVerKeyVRF) import Cardano.Protocol.TPraos.BHeader (checkLeaderValue) import Control.DeepSeq (rnf) import Control.State.Transition.Extended (PredicateFailure, TRC (..)) @@ -105,7 +97,6 @@ import Test.Cardano.Ledger.Core.KeyPair ( import Test.Cardano.Ledger.Shelley.Arbitrary ( ASC (ASC), StakeProportion (StakeProportion), - VRFNatVal (VRFNatVal), ) import Test.Cardano.Ledger.Shelley.ConcreteCryptoTypes (C, MockCrypto) import Test.Cardano.Ledger.Shelley.Fees (sizeTests) @@ -113,6 +104,7 @@ import Test.Cardano.Ledger.Shelley.Generator.Core (VRFKeyPair (..), genesisCoins import Test.Cardano.Ledger.Shelley.Generator.EraGen (genesisId) import Test.Cardano.Ledger.Shelley.Generator.ShelleyEraGen () import Test.Cardano.Ledger.Shelley.Utils +import Test.Cardano.Protocol.TPraos.Arbitrary (VRFNatVal (VRFNatVal)) import Test.Control.State.Transition.Trace (checkTrace, (.-), (.->>)) import qualified Test.QuickCheck.Gen as QC import qualified Test.QuickCheck.Random as QC diff --git a/libs/cardano-ledger-api/src/Cardano/Ledger/Api/Era.hs b/libs/cardano-ledger-api/src/Cardano/Ledger/Api/Era.hs index 991876aa62d..4b3d256d400 100644 --- a/libs/cardano-ledger-api/src/Cardano/Ledger/Api/Era.hs +++ b/libs/cardano-ledger-api/src/Cardano/Ledger/Api/Era.hs @@ -37,10 +37,6 @@ module Cardano.Ledger.Api.Era ( -- ** Latest Known LatestKnownEra, - -- * Crypto - StandardCrypto, - Crypto (..), - -- * Protocol version -- ** Value level @@ -77,7 +73,6 @@ import Cardano.Ledger.Core ( eraProtVerHigh, eraProtVerLow, ) -import Cardano.Ledger.Crypto (Crypto (..), StandardCrypto) import Cardano.Ledger.Mary (Mary, MaryEra) import Cardano.Ledger.Shelley (Shelley, ShelleyEra) diff --git a/libs/cardano-ledger-core/cardano-ledger-core.cabal b/libs/cardano-ledger-core/cardano-ledger-core.cabal index 21d92f9d01f..b6c6e3951e7 100644 --- a/libs/cardano-ledger-core/cardano-ledger-core.cabal +++ b/libs/cardano-ledger-core/cardano-ledger-core.cabal @@ -98,7 +98,6 @@ library bytestring, cardano-crypto, cardano-crypto-class ^>=2.2, - cardano-crypto-praos, cardano-crypto-wrapper, cardano-data ^>=1.2, cardano-ledger-binary ^>=1.6, diff --git a/libs/cardano-ledger-core/src/Cardano/Ledger/Crypto.hs b/libs/cardano-ledger-core/src/Cardano/Ledger/Crypto.hs index a8a8f1468a8..28252c1144e 100644 --- a/libs/cardano-ledger-core/src/Cardano/Ledger/Crypto.hs +++ b/libs/cardano-ledger-core/src/Cardano/Ledger/Crypto.hs @@ -1,38 +1,7 @@ -{-# LANGUAGE FlexibleContexts #-} -{-# LANGUAGE TypeFamilies #-} -{-# LANGUAGE TypeOperators #-} - --- | Package all the crypto constraints into one place. module Cardano.Ledger.Crypto where import Cardano.Crypto.DSIGN import Cardano.Crypto.Hash -import Cardano.Crypto.KES -import Cardano.Crypto.VRF -import Cardano.Crypto.VRF.Praos -import Data.Kind (Type) -import Data.Typeable (Typeable) - -class - ( UnsoundPureKESAlgorithm (KES c) - , VRFAlgorithm (VRF c) - , ContextKES (KES c) ~ () - , ContextVRF (VRF c) ~ () - , Typeable c - ) => - Crypto c - where - type KES c :: Type - type VRF c :: Type - --- ================================ - --- | The same crypto used on the net -data StandardCrypto - -instance Crypto StandardCrypto where - type KES StandardCrypto = Sum6KES Ed25519DSIGN Blake2b_256 - type VRF StandardCrypto = PraosVRF type HASH = Blake2b_256 type ADDRHASH = Blake2b_224 diff --git a/libs/cardano-ledger-core/src/Cardano/Ledger/Keys/Internal.hs b/libs/cardano-ledger-core/src/Cardano/Ledger/Keys/Internal.hs index ea26e9d28ce..b2e81b81467 100644 --- a/libs/cardano-ledger-core/src/Cardano/Ledger/Keys/Internal.hs +++ b/libs/cardano-ledger-core/src/Cardano/Ledger/Keys/Internal.hs @@ -34,7 +34,6 @@ module Cardano.Ledger.Keys.Internal ( -- * VRF Key Hashes KeyRoleVRF (..), VRFVerKeyHash (..), - hashVerKeyVRF, toVRFVerKeyHash, fromVRFVerKeyHash, @@ -42,44 +41,20 @@ module Cardano.Ledger.Keys.Internal ( GenDelegPair (..), GenDelegs (..), - -- * KES - KESignable, - - -- * VRF - VRFSignable, - -- * Re-exports from cardano-crypto-class decodeSignedDSIGN, encodeSignedDSIGN, Hash.hashWithSerialiser, - decodeSignedKES, - decodeVerKeyKES, - encodeSignedKES, - encodeVerKeyKES, - KES.signedKES, - KES.updateKES, - KES.verifyKES, - KES.verifySignedKES, - decodeVerKeyVRF, - encodeVerKeyVRF, - VRF.verifyVRF, - - -- * Re-parametrised types over `crypto` - CertifiedVRF, + + -- * Concrete crypto algorithms Hash, SignedDSIGN, SignKeyDSIGN, - SignedKES, - SignKeyKES, - SignKeyVRF, - VerKeyKES, - VerKeyVRF, ) where import qualified Cardano.Crypto.DSIGN as DSIGN import qualified Cardano.Crypto.Hash as Hash -import qualified Cardano.Crypto.KES as KES import qualified Cardano.Crypto.VRF as VRF import Cardano.Ledger.Binary ( DecCBOR (..), @@ -90,7 +65,7 @@ import Cardano.Ledger.Binary ( encodeListLen, ) import Cardano.Ledger.Binary.Crypto -import Cardano.Ledger.Crypto (ADDRHASH, Crypto, DSIGN, HASH, KES, VRF) +import Cardano.Ledger.Crypto (ADDRHASH, DSIGN, HASH) import Cardano.Ledger.Orphans () import Control.DeepSeq (NFData) import Data.Aeson (FromJSON (..), FromJSONKey, ToJSON (..), ToJSONKey, (.:), (.=)) @@ -234,18 +209,6 @@ instance HasKeyRole KeyHash hashKey :: VKey kd -> KeyHash kd hashKey (VKey vk) = KeyHash $ DSIGN.hashVerKeyDSIGN vk --------------------------------------------------------------------------------- --- KES --------------------------------------------------------------------------------- - -type KESignable c = KES.Signable (KES c) - --------------------------------------------------------------------------------- --- VRF --------------------------------------------------------------------------------- - -type VRFSignable c = VRF.Signable (VRF c) - -------------------------------------------------------------------------------- -- Genesis delegation -- @@ -309,18 +272,6 @@ type SignedDSIGN = DSIGN.SignedDSIGN DSIGN type SignKeyDSIGN = DSIGN.SignKeyDSIGN DSIGN -type SignedKES c = KES.SignedKES (KES c) - -type SignKeyKES c = KES.SignKeyKES (KES c) - -type VerKeyKES c = KES.VerKeyKES (KES c) - -type CertifiedVRF c = VRF.CertifiedVRF (VRF c) - -type SignKeyVRF c = VRF.SignKeyVRF (VRF c) - -type VerKeyVRF c = VRF.VerKeyVRF (VRF c) - data KeyRoleVRF = StakePoolVRF | GenDelegVRF @@ -345,9 +296,6 @@ newtype VRFVerKeyHash (r :: KeyRoleVRF) = VRFVerKeyHash , Default ) -hashVerKeyVRF :: Crypto c => VerKeyVRF c -> VRFVerKeyHash (r :: KeyRoleVRF) -hashVerKeyVRF = VRFVerKeyHash . Hash.castHash . VRF.hashVerKeyVRF - toVRFVerKeyHash :: Hash.Hash HASH (VRF.VerKeyVRF v) -> VRFVerKeyHash (r :: KeyRoleVRF) toVRFVerKeyHash = VRFVerKeyHash . Hash.castHash diff --git a/libs/cardano-ledger-test/src/Test/Cardano/Ledger/Examples/AlonzoBBODY.hs b/libs/cardano-ledger-test/src/Test/Cardano/Ledger/Examples/AlonzoBBODY.hs index 1c975e69fc7..2f85cbdcb69 100644 --- a/libs/cardano-ledger-test/src/Test/Cardano/Ledger/Examples/AlonzoBBODY.hs +++ b/libs/cardano-ledger-test/src/Test/Cardano/Ledger/Examples/AlonzoBBODY.hs @@ -44,7 +44,6 @@ import Cardano.Ledger.Keys ( KeyRole (..), coerceKeyRole, hashKey, - hashVerKeyVRF, ) import Cardano.Ledger.Mary.Value (MaryValue (..), MultiAsset (..)) import Cardano.Ledger.Plutus.Data (Data (..), hashData) @@ -75,6 +74,7 @@ import Cardano.Ledger.TxIn (TxIn (..)) import Cardano.Ledger.UMap (UView (RewDepUView)) import qualified Cardano.Ledger.UMap as UM import Cardano.Ledger.Val (inject, (<->)) +import Cardano.Protocol.Crypto (hashVerKeyVRF) import Cardano.Slotting.Slot (SlotNo (..)) import Control.State.Transition.Extended (STS (..)) import qualified Data.ByteString as BS (replicate) diff --git a/libs/cardano-protocol-tpraos/CHANGELOG.md b/libs/cardano-protocol-tpraos/CHANGELOG.md index f0103983c81..d33ee5116e1 100644 --- a/libs/cardano-protocol-tpraos/CHANGELOG.md +++ b/libs/cardano-protocol-tpraos/CHANGELOG.md @@ -2,6 +2,8 @@ ## 1.4.0.0 +* Move `Crypto` and `StandardCrypto` definitions from `cardano-ledger-core` into new + `Cardano.Protocol.Crypto` module. * Remove crypto parametrization from types: * `LedgerView`, `ChainDepState` * `HashHeader` `PrevHash`, `LastAppliedBlock` @@ -11,6 +13,7 @@ ### `testlib` +* Move `VRFNatVal` from `cardano-ledger-shelley-test` in here. * Change type of `kesSignKey` in `KESKeyPair` and result of `evolveKESUntil` from `SignKeyKES` to `UnsoundPureSignKeyKES` ## 1.3.0.0 diff --git a/libs/cardano-protocol-tpraos/cardano-protocol-tpraos.cabal b/libs/cardano-protocol-tpraos/cardano-protocol-tpraos.cabal index 2464420f6bb..a6514135e14 100644 --- a/libs/cardano-protocol-tpraos/cardano-protocol-tpraos.cabal +++ b/libs/cardano-protocol-tpraos/cardano-protocol-tpraos.cabal @@ -14,6 +14,7 @@ source-repository head library exposed-modules: + Cardano.Protocol.Crypto Cardano.Protocol.TPraos.API Cardano.Protocol.TPraos.BHeader Cardano.Protocol.TPraos.OCert @@ -38,6 +39,7 @@ library base >=4.14 && <5, bytestring, cardano-crypto-class ^>=2.2, + cardano-crypto-praos ^>=2.2, cardano-ledger-allegra >=1.1, cardano-ledger-alonzo >=1.2, cardano-ledger-babbage >=1.1, diff --git a/libs/cardano-protocol-tpraos/src/Cardano/Protocol/Crypto.hs b/libs/cardano-protocol-tpraos/src/Cardano/Protocol/Crypto.hs new file mode 100644 index 00000000000..80cc023853f --- /dev/null +++ b/libs/cardano-protocol-tpraos/src/Cardano/Protocol/Crypto.hs @@ -0,0 +1,83 @@ +{-# LANGUAGE AllowAmbiguousTypes #-} +{-# LANGUAGE ConstraintKinds #-} +{-# LANGUAGE DataKinds #-} +{-# LANGUAGE FlexibleContexts #-} +{-# LANGUAGE TypeFamilies #-} +{-# LANGUAGE TypeOperators #-} + +-- | Package all the crypto constraints into one place. +module Cardano.Protocol.Crypto where + +-- -- * KES +-- KESignable, + +-- -- * VRF +-- VRFSignable, +-- CertifiedVRF, +-- SignedKES, +-- SignKeyKES, +-- SignKeyVRF, +-- VerKeyKES, +-- VerKeyVRF, +-- KES.signedKES, +-- KES.updateKES, +-- KES.verifyKES, +-- KES.verifySignedKES, +-- VRF.verifyVRF, + +import Cardano.Crypto.DSIGN +import Cardano.Crypto.Hash as Hash +import qualified Cardano.Crypto.KES as KES +import qualified Cardano.Crypto.VRF as VRF +import qualified Cardano.Crypto.VRF.Praos as VRF +import Cardano.Ledger.Keys (KeyRoleVRF (..), VRFVerKeyHash (..)) +import Data.Kind (Type) +import Data.Typeable (Typeable) + +class + ( KES.UnsoundPureKESAlgorithm (KES c) + , VRF.VRFAlgorithm (VRF c) + , KES.ContextKES (KES c) ~ () + , VRF.ContextVRF (VRF c) ~ () + , Typeable c + ) => + Crypto c + where + type KES c :: Type + type VRF c :: Type + +-- ================================ + +-- | The same crypto used on the net +data StandardCrypto + +instance Crypto StandardCrypto where + type KES StandardCrypto = KES.Sum6KES Ed25519DSIGN Blake2b_256 + type VRF StandardCrypto = VRF.PraosVRF + +hashVerKeyVRF :: Crypto c => VerKeyVRF c -> VRFVerKeyHash (r :: KeyRoleVRF) +hashVerKeyVRF = VRFVerKeyHash . Hash.castHash . VRF.hashVerKeyVRF + +-------------------------------------------------------------------------------- +-- KES +-------------------------------------------------------------------------------- + +type KESignable c = KES.Signable (KES c) + +-------------------------------------------------------------------------------- +-- VRF +-------------------------------------------------------------------------------- + +type VRFSignable c = VRF.Signable (VRF c) + +type SignedKES c = KES.SignedKES (KES c) + +type SignKeyKES c = KES.SignKeyKES (KES c) + +type VerKeyKES c = KES.VerKeyKES (KES c) + +type CertifiedVRF c = VRF.CertifiedVRF (VRF c) + +type SignKeyVRF c = VRF.SignKeyVRF (VRF c) + +type VerKeyVRF c = VRF.VerKeyVRF (VRF c) diff --git a/libs/cardano-protocol-tpraos/src/Cardano/Protocol/TPraos/API.hs b/libs/cardano-protocol-tpraos/src/Cardano/Protocol/TPraos/API.hs index 226a104a8d2..e6cd7f40607 100644 --- a/libs/cardano-protocol-tpraos/src/Cardano/Protocol/TPraos/API.hs +++ b/libs/cardano-protocol-tpraos/src/Cardano/Protocol/TPraos/API.hs @@ -59,14 +59,11 @@ import Cardano.Ledger.Binary.Plain (FromCBOR (..), ToCBOR (..), decodeRecordName import Cardano.Ledger.Chain (ChainChecksPParams, pparamsToChainChecksPParams) import Cardano.Ledger.Conway (ConwayEra) import Cardano.Ledger.Core -import Cardano.Ledger.Crypto (Crypto, StandardCrypto) import Cardano.Ledger.Keys ( GenDelegPair (..), GenDelegs (..), - KESignable, KeyHash, KeyRole (..), - VRFSignable, coerceKeyRole, ) import Cardano.Ledger.Mary (MaryEra) @@ -83,6 +80,7 @@ import Cardano.Ledger.Shelley.LedgerState ( ) import Cardano.Ledger.Shelley.Translation (FromByronTranslationContext (..)) import Cardano.Ledger.Slot (SlotNo) +import Cardano.Protocol.Crypto import Cardano.Protocol.TPraos.BHeader ( BHBody, BHeader, diff --git a/libs/cardano-protocol-tpraos/src/Cardano/Protocol/TPraos/BHeader.hs b/libs/cardano-protocol-tpraos/src/Cardano/Protocol/TPraos/BHeader.hs index dc84550bcd8..5ef9996ade5 100644 --- a/libs/cardano-protocol-tpraos/src/Cardano/Protocol/TPraos/BHeader.hs +++ b/libs/cardano-protocol-tpraos/src/Cardano/Protocol/TPraos/BHeader.hs @@ -76,28 +76,22 @@ import Cardano.Ledger.Binary ( szCases, withWordSize, ) +import Cardano.Ledger.Binary.Crypto import qualified Cardano.Ledger.Binary.Plain as Plain -import Cardano.Ledger.Crypto (Crypto) import Cardano.Ledger.Hashes ( EraIndependentBlockBody, EraIndependentBlockHeader, ) import Cardano.Ledger.Keys ( - CertifiedVRF, Hash, KeyHash, KeyRole (..), - SignedKES, VKey, - VerKeyVRF, - decodeSignedKES, - decodeVerKeyVRF, - encodeSignedKES, - encodeVerKeyVRF, hashKey, ) import Cardano.Ledger.NonIntegral (CompareResult (..), taylorExpCmp) import Cardano.Ledger.Slot (BlockNo (..), SlotNo (..)) +import Cardano.Protocol.Crypto import Cardano.Protocol.TPraos.OCert (OCert (..)) import Cardano.Slotting.Slot (WithOrigin (..)) import Control.DeepSeq (NFData) diff --git a/libs/cardano-protocol-tpraos/src/Cardano/Protocol/TPraos/OCert.hs b/libs/cardano-protocol-tpraos/src/Cardano/Protocol/TPraos/OCert.hs index 12ac8aa4033..b4243241a74 100644 --- a/libs/cardano-protocol-tpraos/src/Cardano/Protocol/TPraos/OCert.hs +++ b/libs/cardano-protocol-tpraos/src/Cardano/Protocol/TPraos/OCert.hs @@ -39,14 +39,13 @@ import Cardano.Ledger.Binary ( runByteBuilder, ) import qualified Cardano.Ledger.Binary.Plain as Plain -import Cardano.Ledger.Crypto (Crypto, KES) import Cardano.Ledger.Keys ( KeyHash, KeyRole (..), SignedDSIGN, - VerKeyKES, coerceKeyRole, ) +import Cardano.Protocol.Crypto (Crypto, KES, VerKeyKES) import Control.Monad.Trans.Reader (asks) import qualified Data.ByteString.Builder as BS import qualified Data.ByteString.Builder.Extra as BS diff --git a/libs/cardano-protocol-tpraos/src/Cardano/Protocol/TPraos/Rules/OCert.hs b/libs/cardano-protocol-tpraos/src/Cardano/Protocol/TPraos/Rules/OCert.hs index 85b753e20a6..f36e6c04f14 100644 --- a/libs/cardano-protocol-tpraos/src/Cardano/Protocol/TPraos/Rules/OCert.hs +++ b/libs/cardano-protocol-tpraos/src/Cardano/Protocol/TPraos/Rules/OCert.hs @@ -13,9 +13,10 @@ module Cardano.Protocol.TPraos.Rules.OCert ( ) where +import Cardano.Crypto.KES (verifySignedKES) import Cardano.Ledger.BaseTypes -import Cardano.Ledger.Crypto import Cardano.Ledger.Keys +import Cardano.Protocol.Crypto import Cardano.Protocol.TPraos.BHeader import Cardano.Protocol.TPraos.OCert import Control.Monad.Trans.Reader (asks) diff --git a/libs/cardano-protocol-tpraos/src/Cardano/Protocol/TPraos/Rules/Overlay.hs b/libs/cardano-protocol-tpraos/src/Cardano/Protocol/TPraos/Rules/Overlay.hs index 0a1ac67e494..7f1948f13ba 100644 --- a/libs/cardano-protocol-tpraos/src/Cardano/Protocol/TPraos/Rules/Overlay.hs +++ b/libs/cardano-protocol-tpraos/src/Cardano/Protocol/TPraos/Rules/Overlay.hs @@ -43,24 +43,22 @@ import Cardano.Ledger.Binary ( encodeNull, peekTokenType, ) -import Cardano.Ledger.Crypto import Cardano.Ledger.Keys ( GenDelegPair (..), GenDelegs (..), - KESignable, KeyHash (..), KeyRole (..), KeyRoleVRF (..), VRFVerKeyHash (..), coerceKeyRole, hashKey, - hashVerKeyVRF, ) import Cardano.Ledger.PoolDistr ( IndividualPoolStake (..), PoolDistr (..), ) import Cardano.Ledger.Slot (epochInfoEpoch, epochInfoFirst, (-*)) +import Cardano.Protocol.Crypto import Cardano.Protocol.TPraos.BHeader ( BHBody (..), BHeader (BHeader), diff --git a/libs/cardano-protocol-tpraos/src/Cardano/Protocol/TPraos/Rules/Prtcl.hs b/libs/cardano-protocol-tpraos/src/Cardano/Protocol/TPraos/Rules/Prtcl.hs index 4ce5ddb8eee..793bf827310 100644 --- a/libs/cardano-protocol-tpraos/src/Cardano/Protocol/TPraos/Rules/Prtcl.hs +++ b/libs/cardano-protocol-tpraos/src/Cardano/Protocol/TPraos/Rules/Prtcl.hs @@ -36,16 +36,10 @@ import Cardano.Ledger.Binary.Plain ( decodeRecordNamed, encodeListLen, ) -import Cardano.Ledger.Crypto (Crypto, VRF) -import Cardano.Ledger.Keys ( - GenDelegs (..), - KESignable, - KeyHash, - KeyRole (..), - VRFSignable, - ) +import Cardano.Ledger.Keys (GenDelegs (..), KeyHash, KeyRole (..)) import Cardano.Ledger.PoolDistr (PoolDistr) import Cardano.Ledger.Slot (BlockNo, SlotNo) +import Cardano.Protocol.Crypto import Cardano.Protocol.TPraos.BHeader ( BHBody (..), BHeader (..), diff --git a/libs/cardano-protocol-tpraos/src/Cardano/Protocol/TPraos/Rules/Updn.hs b/libs/cardano-protocol-tpraos/src/Cardano/Protocol/TPraos/Rules/Updn.hs index f63c45294af..f5f6c5fc459 100644 --- a/libs/cardano-protocol-tpraos/src/Cardano/Protocol/TPraos/Rules/Updn.hs +++ b/libs/cardano-protocol-tpraos/src/Cardano/Protocol/TPraos/Rules/Updn.hs @@ -13,8 +13,8 @@ module Cardano.Protocol.TPraos.Rules.Updn ( where import Cardano.Ledger.BaseTypes -import Cardano.Ledger.Crypto import Cardano.Ledger.Slot +import Cardano.Protocol.Crypto import Control.Monad.Trans.Reader (asks) import Control.State.Transition import GHC.Generics (Generic) diff --git a/libs/cardano-protocol-tpraos/test/Test/Cardano/Protocol/Binary/CddlSpec.hs b/libs/cardano-protocol-tpraos/test/Test/Cardano/Protocol/Binary/CddlSpec.hs index b92c7257edf..21fc43c0477 100644 --- a/libs/cardano-protocol-tpraos/test/Test/Cardano/Protocol/Binary/CddlSpec.hs +++ b/libs/cardano-protocol-tpraos/test/Test/Cardano/Protocol/Binary/CddlSpec.hs @@ -7,8 +7,8 @@ module Test.Cardano.Protocol.Binary.CddlSpec (spec) where import Cardano.Ledger.Binary.Group (CBORGroup) import Cardano.Ledger.Core -import Cardano.Ledger.Crypto import Cardano.Ledger.Shelley +import Cardano.Protocol.Crypto import Cardano.Protocol.TPraos.BHeader (BHBody, BHeader) import Cardano.Protocol.TPraos.OCert (OCert) import qualified Data.ByteString.Lazy as BSL 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 4e1f360b352..56f11a54513 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 @@ -8,8 +8,7 @@ module Test.Cardano.Protocol.Crypto.KES ( ) where import qualified Cardano.Crypto.KES.Class as KES -import Cardano.Ledger.Crypto -import Cardano.Ledger.Keys (VerKeyKES) +import Cardano.Protocol.Crypto data KESKeyPair c = KESKeyPair { kesSignKey :: !(KES.UnsoundPureSignKeyKES (KES c)) diff --git a/libs/cardano-protocol-tpraos/testlib/Test/Cardano/Protocol/Crypto/VRF.hs b/libs/cardano-protocol-tpraos/testlib/Test/Cardano/Protocol/Crypto/VRF.hs index 0b40dd8a0e6..8b8fdc3ece3 100644 --- a/libs/cardano-protocol-tpraos/testlib/Test/Cardano/Protocol/Crypto/VRF.hs +++ b/libs/cardano-protocol-tpraos/testlib/Test/Cardano/Protocol/Crypto/VRF.hs @@ -8,11 +8,7 @@ module Test.Cardano.Protocol.Crypto.VRF ( ) where import qualified Cardano.Crypto.VRF.Class as VRF -import Cardano.Ledger.Crypto -import Cardano.Ledger.Keys ( - SignKeyVRF, - VerKeyVRF, - ) +import Cardano.Protocol.Crypto data VRFKeyPair c = VRFKeyPair { vrfSignKey :: !(SignKeyVRF c) 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 2b77e3c4004..c321172b39b 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 @@ -15,6 +15,7 @@ module Test.Cardano.Protocol.TPraos.Arbitrary ( genBHeader, genBlock, genCoherentBlock, + VRFNatVal (..), ) where import qualified Cardano.Crypto.KES as KES @@ -23,7 +24,7 @@ import qualified Cardano.Crypto.VRF as VRF 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)) +import Cardano.Protocol.Crypto (Crypto (KES, VRF), StandardCrypto) import Cardano.Protocol.TPraos.API (PraosCrypto) import Cardano.Protocol.TPraos.BHeader ( BHBody (BHBody), @@ -35,13 +36,31 @@ import Cardano.Protocol.TPraos.OCert (KESPeriod (KESPeriod), OCert (..)) import Cardano.Protocol.TPraos.Rules.Overlay (OBftSlot) import Cardano.Protocol.TPraos.Rules.Prtcl (PrtclState) import Cardano.Protocol.TPraos.Rules.Tickn (TicknState) +import Data.Proxy (Proxy (Proxy)) import Generic.Random (genericArbitraryU) +import Numeric.Natural (Natural) import Test.Cardano.Ledger.Binary.Arbitrary () import Test.Cardano.Ledger.Common import Test.Cardano.Ledger.Core.Arbitrary () import Test.Cardano.Ledger.Shelley.Arbitrary () import Test.Cardano.Protocol.TPraos.Create (AllIssuerKeys, mkBHBody, mkBHeader, mkBlock, mkOCert) +newtype VRFNatVal = VRFNatVal Natural + deriving (Show) + +instance Arbitrary VRFNatVal where + arbitrary = + VRFNatVal . fromIntegral + <$> choose @Integer + ( 0 + , 2 + ^ ( 8 + * VRF.sizeOutputVRF + (Proxy @(VRF StandardCrypto)) + ) + ) + shrink (VRFNatVal v) = VRFNatVal <$> shrinkIntegral v + instance Arbitrary HashHeader where arbitrary = HashHeader <$> arbitrary 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 fbbc623b0af..b0d42c2b82e 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 @@ -36,7 +36,6 @@ import Cardano.Ledger.BaseTypes ( ) import Cardano.Ledger.Block import Cardano.Ledger.Core -import Cardano.Ledger.Crypto import Cardano.Ledger.Keys ( HasKeyRole (coerceKeyRole), Hash, @@ -44,6 +43,7 @@ import Cardano.Ledger.Keys ( KeyRole (..), signedDSIGN, ) +import Cardano.Protocol.Crypto import Cardano.Protocol.TPraos.BHeader ( BHBody (..), BHeader (..),