Skip to content

Commit

Permalink
Move Crypto class and StandardCrypto to protocol-tpraos
Browse files Browse the repository at this point in the history
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
  • Loading branch information
lehins committed Dec 19, 2024
1 parent 07fb1c6 commit 1ff2f3e
Show file tree
Hide file tree
Showing 45 changed files with 163 additions and 210 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
module Test.Cardano.Ledger.EraBuffet (
StandardCrypto,
ShelleyEra,
MaryEra,
AllegraEra,
Expand All @@ -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)
1 change: 0 additions & 1 deletion eras/shelley/impl/cardano-ledger-shelley.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ library testlib
ImpSpec,
base,
bytestring,
cardano-crypto-class,
cardano-data,
cardano-ledger-binary:{cardano-ledger-binary, testlib},
cardano-ledger-byron,
Expand Down
8 changes: 0 additions & 8 deletions eras/shelley/impl/src/Cardano/Ledger/Shelley/API/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 (..),
Expand Down
18 changes: 10 additions & 8 deletions eras/shelley/impl/src/Cardano/Ledger/Shelley/Genesis.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 (..))
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
21 changes: 0 additions & 21 deletions eras/shelley/impl/testlib/Test/Cardano/Ledger/Shelley/Arbitrary.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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 ()
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion eras/shelley/test-suite/bench/BenchValidation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -39,6 +38,7 @@ import Cardano.Ledger.Shelley.LedgerState (
StashedAVVMAddresses,
nesBcur,
)
import Cardano.Protocol.Crypto
import Cardano.Protocol.TPraos.API (
ChainDepState (..),
ChainTransitionError,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ import Cardano.Ledger.Keys (
VRFVerKeyHash,
asWitness,
hashKey,
hashVerKeyVRF,
)
import Cardano.Ledger.PoolParams (
PoolParams (..),
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ 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)

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 (..),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 (..),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 (..),
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 (..))
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import Cardano.Ledger.Keys (
VRFVerKeyHash,
asWitness,
hashKey,
hashVerKeyVRF,
)
import Cardano.Ledger.SafeHash (hashAnnotated)
import Cardano.Ledger.Shelley (ShelleyEra)
Expand All @@ -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)
Expand Down
Loading

0 comments on commit 1ff2f3e

Please sign in to comment.