diff --git a/ouroboros-consensus-cardano/changelog.d/20241128_174448_neilmayhew_release_srp.md b/ouroboros-consensus-cardano/changelog.d/20241128_174448_neilmayhew_release_srp.md new file mode 100644 index 0000000000..460c2a2c40 --- /dev/null +++ b/ouroboros-consensus-cardano/changelog.d/20241128_174448_neilmayhew_release_srp.md @@ -0,0 +1,3 @@ +### Breaking + +- Change the type of the `mkKeyHashVrf` function to use the new `VRFVerKeyHash` ledger type. diff --git a/ouroboros-consensus-cardano/src/shelley/Ouroboros/Consensus/Shelley/Ledger/Query/Types.hs b/ouroboros-consensus-cardano/src/shelley/Ouroboros/Consensus/Shelley/Ledger/Query/Types.hs index e1c754e519..c996af7dc2 100644 --- a/ouroboros-consensus-cardano/src/shelley/Ouroboros/Consensus/Shelley/Ledger/Query/Types.hs +++ b/ouroboros-consensus-cardano/src/shelley/Ouroboros/Consensus/Shelley/Ledger/Query/Types.hs @@ -20,8 +20,8 @@ import Cardano.Ledger.Binary (DecCBOR (..), EncCBOR (..), decodeRecordNamed, encodeListLen) import Cardano.Ledger.Crypto (Crypto) import Cardano.Ledger.Keys (Hash) +import qualified Cardano.Ledger.Keys as SL import qualified Cardano.Ledger.PoolDistr as SL -import qualified Cardano.Ledger.Shelley.API as SL import Data.Map.Strict (Map) import qualified Data.Map.Strict as Map import GHC.Generics (Generic) @@ -39,7 +39,7 @@ data IndividualPoolStake c = IndividualPoolStake { fromLedgerIndividualPoolStake :: SL.IndividualPoolStake c -> IndividualPoolStake c fromLedgerIndividualPoolStake ips = IndividualPoolStake { individualPoolStake = SL.individualPoolStake ips - , individualPoolStakeVrf = SL.individualPoolStakeVrf ips + , individualPoolStakeVrf = SL.fromVRFVerKeyHash $ SL.individualPoolStakeVrf ips } instance Crypto c => EncCBOR (IndividualPoolStake c) where diff --git a/ouroboros-consensus-cardano/src/shelley/Ouroboros/Consensus/Shelley/Node/TPraos.hs b/ouroboros-consensus-cardano/src/shelley/Ouroboros/Consensus/Shelley/Node/TPraos.hs index 44d13dee75..82e5698885 100644 --- a/ouroboros-consensus-cardano/src/shelley/Ouroboros/Consensus/Shelley/Node/TPraos.hs +++ b/ouroboros-consensus-cardano/src/shelley/Ouroboros/Consensus/Shelley/Node/TPraos.hs @@ -148,7 +148,7 @@ shelleySharedBlockForging hotKey slotToPeriod credentials = forgingVRFHash :: SL.Hash c (SL.VerKeyVRF c) forgingVRFHash = - SL.hashVerKeyVRF + VRF.hashVerKeyVRF . VRF.deriveVerKeyVRF . praosCanBeLeaderSignKeyVRF $ canBeLeader diff --git a/ouroboros-consensus-cardano/src/unstable-cardano-tools/Cardano/Api/KeysPraos.hs b/ouroboros-consensus-cardano/src/unstable-cardano-tools/Cardano/Api/KeysPraos.hs index 5dd33d6dff..153f0a3cd5 100644 --- a/ouroboros-consensus-cardano/src/unstable-cardano-tools/Cardano/Api/KeysPraos.hs +++ b/ouroboros-consensus-cardano/src/unstable-cardano-tools/Cardano/Api/KeysPraos.hs @@ -178,7 +178,7 @@ instance Key VrfKey where verificationKeyHash :: VerificationKey VrfKey -> Hash VrfKey verificationKeyHash (VrfVerificationKey vkey) = - VrfKeyHash (Shelley.hashVerKeyVRF vkey) + VrfKeyHash (Crypto.hashVerKeyVRF vkey) instance SerialiseAsRawBytes (VerificationKey VrfKey) where serialiseToRawBytes (VrfVerificationKey vk) = diff --git a/ouroboros-consensus-cardano/src/unstable-cardano-tools/Cardano/Tools/Headers.hs b/ouroboros-consensus-cardano/src/unstable-cardano-tools/Cardano/Tools/Headers.hs index f98b8b60c5..3376c36563 100644 --- a/ouroboros-consensus-cardano/src/unstable-cardano-tools/Cardano/Tools/Headers.hs +++ b/ouroboros-consensus-cardano/src/unstable-cardano-tools/Cardano/Tools/Headers.hs @@ -12,12 +12,11 @@ module Cardano.Tools.Headers ( ) where import Cardano.Crypto.DSIGN (deriveVerKeyDSIGN) -import Cardano.Crypto.VRF - (VRFAlgorithm (deriveVerKeyVRF, hashVerKeyVRF)) +import Cardano.Crypto.VRF (VRFAlgorithm (deriveVerKeyVRF)) import Cardano.Ledger.Api (ConwayEra, StandardCrypto) import Cardano.Ledger.Coin (Coin (..)) import Cardano.Ledger.Compactible (toCompact) -import Cardano.Ledger.Keys (VKey (..), hashKey) +import Cardano.Ledger.Keys (VKey (..), hashKey, hashVerKeyVRF) import Cardano.Ledger.PoolDistr (IndividualPoolStake (..)) import Cardano.Prelude (ExitCode (..), exitWith, forM_, hPutStrLn, stderr) diff --git a/ouroboros-consensus-cardano/src/unstable-shelley-testlib/Test/ThreadNet/Infra/Shelley.hs b/ouroboros-consensus-cardano/src/unstable-shelley-testlib/Test/ThreadNet/Infra/Shelley.hs index 2ca053c7a8..b67594b964 100644 --- a/ouroboros-consensus-cardano/src/unstable-shelley-testlib/Test/ThreadNet/Infra/Shelley.hs +++ b/ouroboros-consensus-cardano/src/unstable-shelley-testlib/Test/ThreadNet/Infra/Shelley.hs @@ -36,18 +36,18 @@ module Test.ThreadNet.Infra.Shelley ( ) where import Cardano.Crypto.DSIGN (DSIGNAlgorithm (..), seedSizeDSIGN) -import Cardano.Crypto.Hash (Hash, HashAlgorithm) +import Cardano.Crypto.Hash (HashAlgorithm) import Cardano.Crypto.KES (KESAlgorithm (..)) import Cardano.Crypto.Seed (mkSeedFromBytes) import qualified Cardano.Crypto.Seed as Cardano.Crypto -import Cardano.Crypto.VRF (SignKeyVRF, VRFAlgorithm, VerKeyVRF, - deriveVerKeyVRF, genKeyVRF, seedSizeVRF) +import Cardano.Crypto.VRF (SignKeyVRF, deriveVerKeyVRF, genKeyVRF, + seedSizeVRF) import qualified Cardano.Ledger.Allegra.Scripts as SL import Cardano.Ledger.Alonzo (AlonzoEra) import Cardano.Ledger.BaseTypes (boundRational) import Cardano.Ledger.Crypto (Crypto, DSIGN, HASH, KES, VRF) import Cardano.Ledger.Hashes (EraIndependentTxBody) -import qualified Cardano.Ledger.Keys +import qualified Cardano.Ledger.Keys as LK import qualified Cardano.Ledger.Mary.Core as SL import Cardano.Ledger.SafeHash (HashAnnotated (..), SafeHash, hashAnnotated) @@ -182,7 +182,7 @@ genCoreNode startKESPeriod = do vrfKey <- genKeyVRF <$> genSeed (seedSizeVRF (Proxy @(VRF c))) kesKey <- genKeyKES <$> genSeed (seedSizeKES (Proxy @(KES c))) let kesPub = deriveVerKeyKES kesKey - sigma = Cardano.Ledger.Keys.signedDSIGN + sigma = LK.signedDSIGN @c delKey (SL.OCertSignable kesPub certificateIssueNumber startKESPeriod) @@ -522,9 +522,9 @@ mkVerKey = SL.VKey . deriveVerKeyDSIGN mkKeyPair :: Crypto c => SL.SignKeyDSIGN c -> TL.KeyPair r c mkKeyPair sk = TL.KeyPair { vKey = mkVerKey sk, sKey = sk } -mkKeyHashVrf :: (HashAlgorithm h, VRFAlgorithm vrf) - => SignKeyVRF vrf - -> Hash h (VerKeyVRF vrf) +mkKeyHashVrf :: Crypto c + => SignKeyVRF (VRF c) + -> LK.VRFVerKeyHash (r :: LK.KeyRoleVRF) c mkKeyHashVrf = SL.hashVerKeyVRF . deriveVerKeyVRF networkId :: SL.Network diff --git a/ouroboros-consensus-protocol/changelog.d/20241218_141944_neilmayhew_integrate_ledger.md b/ouroboros-consensus-protocol/changelog.d/20241218_141944_neilmayhew_integrate_ledger.md new file mode 100644 index 0000000000..bdaf678e9f --- /dev/null +++ b/ouroboros-consensus-protocol/changelog.d/20241218_141944_neilmayhew_integrate_ledger.md @@ -0,0 +1,3 @@ +### Patch + +* Use the `VRFVerKeyHash` type from `cardano-ledger-core-1.16` diff --git a/ouroboros-consensus-protocol/src/ouroboros-consensus-protocol/Ouroboros/Consensus/Protocol/Praos.hs b/ouroboros-consensus-protocol/src/ouroboros-consensus-protocol/Ouroboros/Consensus/Protocol/Praos.hs index 3ddbcf200b..ce8bcdb08e 100644 --- a/ouroboros-consensus-protocol/src/ouroboros-consensus-protocol/Ouroboros/Consensus/Protocol/Praos.hs +++ b/ouroboros-consensus-protocol/src/ouroboros-consensus-protocol/Ouroboros/Consensus/Protocol/Praos.hs @@ -37,7 +37,6 @@ module Ouroboros.Consensus.Protocol.Praos ( import Cardano.Binary (FromCBOR (..), ToCBOR (..), enforceSize) import qualified Cardano.Crypto.DSIGN as DSIGN import qualified Cardano.Crypto.KES as KES -import Cardano.Crypto.VRF (hashVerKeyVRF) import qualified Cardano.Crypto.VRF as VRF import Cardano.Ledger.BaseTypes (ActiveSlotCoeff, Nonce, (⭒)) import qualified Cardano.Ledger.BaseTypes as SL @@ -548,8 +547,10 @@ doValidateVRFSignature eta0 pd f b = do case Map.lookup hk pd of Nothing -> throwError $ VRFKeyUnknown hk Just (IndividualPoolStake sigma _totalPoolStake vrfHK) -> do - vrfHK == hashVerKeyVRF vrfK - ?! VRFKeyWrongVRFKey hk vrfHK (hashVerKeyVRF vrfK) + let vrfHKStake = SL.fromVRFVerKeyHash vrfHK + vrfHKBlock = VRF.hashVerKeyVRF vrfK + vrfHKStake == vrfHKBlock + ?! VRFKeyWrongVRFKey hk vrfHKStake vrfHKBlock VRF.verifyCertified () vrfK diff --git a/ouroboros-consensus-protocol/src/ouroboros-consensus-protocol/Ouroboros/Consensus/Protocol/TPraos.hs b/ouroboros-consensus-protocol/src/ouroboros-consensus-protocol/Ouroboros/Consensus/Protocol/TPraos.hs index 37a9475a8b..43529217bc 100644 --- a/ouroboros-consensus-protocol/src/ouroboros-consensus-protocol/Ouroboros/Consensus/Protocol/TPraos.hs +++ b/ouroboros-consensus-protocol/src/ouroboros-consensus-protocol/Ouroboros/Consensus/Protocol/TPraos.hs @@ -324,7 +324,7 @@ instance SL.PraosCrypto c => ConsensusProtocol (TPraos c) where -- the overlay schedule, so we could set it to whatever we -- want. We evaluate it as normal for simplicity's sake. , tpraosIsLeaderProof = coerce y - , tpraosIsLeaderGenVRFHash = Just genDlgVRFHash + , tpraosIsLeaderGenVRFHash = Just $ SL.fromVRFVerKeyHash genDlgVRFHash } | otherwise -> Nothing