Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use mlocked KES #1284

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,82 @@ package ouroboros-network
if(os(windows))
constraints:
bitvec -simd

-- For the time being, we need to override some dependency bounds
allow-newer: plutus-core:cardano-crypto-class
, cardano-slotting

source-repository-package
type: git
location: https://github.com/input-output-hk/cardano-base
tag: 890eec1bbb17068ee7df84c468e1c6bc39643d3a
--sha256: 0944wg2nqazmhlmsynwgdwxxj6ay0hb9qig9l128isb2cjia0hlp
subdir:
-- cardano-binary
cardano-crypto-class
cardano-crypto-tests
cardano-crypto-praos
cardano-mempool
-- cardano-slotting

source-repository-package
type: git
location: https://github.com/IntersectMBO/formal-ledger-specifications.git
-- !WARNING!:
-- MAKE SURE THIS POINTS TO A COMMIT IN `MAlonzo-code` BEFORE MERGE!
subdir: generated
tag: 544ab20985e3374a1d672354e25d8ca0ca89e7e4
--sha256: sha256-bhh09OZkHazXCPjsiU/50Hrmfg52i+6UORTZ6/bAx6c=
-- NOTE: If you would like to update the above, look for the `MAlonzo-code`
-- branch in the `formal-ledger-specifications` repo and copy the SHA of
-- the commit you need. The `MAlonzo-code` branch functions like an alternative
-- `master / main` branch for the generated code, see the details here:
-- https://github.com/IntersectMBO/formal-ledger-specifications/pull/530
-- If you are working on something in `formal-ledger-specifications`
-- and would like to see how they reflect here, just open a PR / draft PR
-- in `formal-ledger-specifications` for your branch and that will
-- automatically create a branch for the generated code that you can try here
-- by editing the above SRP.
-- Once your changes are merged in `formal-ledger-specifications`, the branch
-- for the generated code will be merged into `MAlonzo-code` automatically.
-- Before merging a PR in `cardano-ledger`, make sure that the above SRP
-- 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-ledger
tag: ebba3fb4554a04ddaa4734f9083afebd64c81099
--sha256: 0944wg2nqazmhlmsynwgdwxxj6ay0hb9qig9l128isb2cjia0hlp
subdir:
eras/allegra/impl
eras/alonzo/impl
eras/alonzo/test-suite
eras/babbage/impl
eras/babbage/test-suite
eras/byron/chain/executable-spec
eras/byron/crypto
eras/byron/crypto/test
eras/byron/ledger/executable-spec
eras/byron/ledger/impl
eras/byron/ledger/impl/test
eras/conway/impl
eras/conway/test-suite
eras/mary/impl
eras/shelley/impl
eras/shelley-ma/test-suite
eras/shelley/test-suite
libs/cardano-data
libs/cardano-ledger-api
libs/cardano-ledger-binary
libs/cardano-ledger-conformance
libs/cardano-ledger-core
libs/cardano-ledger-test
libs/cardano-protocol-tpraos
libs/constrained-generators
libs/ledger-state
libs/non-integral
libs/plutus-preprocessor
libs/set-algebra
libs/small-steps
libs/vector-map
17 changes: 9 additions & 8 deletions ouroboros-consensus-cardano/ouroboros-consensus-cardano.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,15 @@ library
cardano-crypto-class,
cardano-crypto-wrapper,
cardano-ledger-allegra ^>=1.6,
cardano-ledger-alonzo ^>=1.10.2,
cardano-ledger-alonzo ^>=1.11.0,
cardano-ledger-api ^>=1.9.3,
cardano-ledger-babbage ^>=1.9,
cardano-ledger-binary ^>=1.3.4,
cardano-ledger-babbage ^>=1.10,
cardano-ledger-binary ^>=1.4.0,
cardano-ledger-byron ^>=1.0.1,
cardano-ledger-conway ^>=1.16,
cardano-ledger-core ^>=1.14,
cardano-ledger-conway ^>=1.17,
cardano-ledger-core ^>=1.15,
cardano-ledger-mary ^>=1.7,
cardano-ledger-shelley ^>=1.13.1,
cardano-ledger-shelley ^>=1.14.0,
cardano-prelude,
cardano-protocol-tpraos ^>=1.2,
cardano-slotting,
Expand Down Expand Up @@ -304,7 +304,7 @@ library unstable-shelley-testlib
cardano-ledger-alonzo,
cardano-ledger-alonzo-test,
cardano-ledger-babbage-test,
cardano-ledger-conway-test >=1.2.1,
cardano-ledger-conway-test >=1.3.0,
cardano-ledger-core:{cardano-ledger-core, testlib},
cardano-ledger-mary,
cardano-ledger-shelley:{cardano-ledger-shelley, testlib},
Expand Down Expand Up @@ -390,7 +390,7 @@ library unstable-cardano-testlib
cardano-ledger-api,
cardano-ledger-byron,
cardano-ledger-conway:testlib,
cardano-ledger-conway-test ^>=1.2.1,
cardano-ledger-conway-test ^>=1.3.0,
cardano-ledger-core:{cardano-ledger-core, testlib},
cardano-ledger-shelley,
cardano-protocol-tpraos,
Expand Down Expand Up @@ -545,6 +545,7 @@ library unstable-cardano-tools
filepath,
fs-api ^>=0.3,
githash,
io-classes ^>=1.5,
microlens,
mtl,
network,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import Cardano.Crypto (ProtocolMagicId, SignTag (..), Signature (..),
SigningKey (..), VerificationKey (..), deterministicKeyGen,
signRaw, toVerification, verifySignatureRaw)
import Cardano.Crypto.DSIGN.Class
import Cardano.Crypto.Seed (SeedBytesExhausted (..), getBytesFromSeed)
import Cardano.Crypto.Seed (getBytesFromSeedEither)
import qualified Cardano.Crypto.Signing as Crypto
import qualified Cardano.Crypto.Wallet as CC
import Cardano.Ledger.Binary
Expand Down Expand Up @@ -90,9 +90,9 @@ instance DSIGNAlgorithm ByronDSIGN where
genKeyDSIGN seed =
SignKeyByronDSIGN . snd $ deterministicKeyGen seedBytes
where
seedBytes = case getBytesFromSeed 32 seed of
Just (x,_) -> x
Nothing -> throw $ SeedBytesExhausted (-1) -- TODO We can't get the seed size!
seedBytes = case getBytesFromSeedEither 32 seed of
Right (x,_) -> x
Left err -> throw err

deriveVerKeyDSIGN (SignKeyByronDSIGN sk) = VerKeyByronDSIGN $ toVerification sk

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ byronBlockForging creds = BlockForging {
slot
tickedPBftState
, forgeBlock = \cfg -> return ....: forgeByronBlock cfg
, finalize = pure ()
}
where
canBeLeader = mkPBftCanBeLeader creds
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ module Ouroboros.Consensus.Cardano.Node (
, CardanoHardForkTriggers (.., CardanoHardForkTriggers', triggerHardForkShelley, triggerHardForkAllegra, triggerHardForkMary, triggerHardForkAlonzo, triggerHardForkBabbage, triggerHardForkConway)
, CardanoProtocolParams (..)
, MaxMajorProtVer (..)
, ProtocolParamsByron
, ProtocolParamsShelleyBased
, CheckpointsMap
, TriggerHardFork (..)
, protocolClientInfoCardano
, protocolInfoCardano
Expand Down Expand Up @@ -64,8 +67,8 @@ import qualified Cardano.Ledger.Api.Transition as L
import qualified Cardano.Ledger.BaseTypes as SL
import qualified Cardano.Ledger.Shelley.API as SL
import Cardano.Prelude (cborError)
import qualified Cardano.Protocol.TPraos.OCert as Absolute (KESPeriod (..),
ocertKESPeriod)
import qualified Cardano.Protocol.TPraos.OCert as Absolute (KESPeriod (..))
import qualified Cardano.Protocol.TPraos.OCert as SL
import Cardano.Slotting.Time (SystemStart (SystemStart))
import qualified Codec.CBOR.Decoding as CBOR
import Codec.CBOR.Encoding (Encoding)
Expand Down Expand Up @@ -100,10 +103,8 @@ import Ouroboros.Consensus.Ledger.Extended
import Ouroboros.Consensus.Node.NetworkProtocolVersion
import Ouroboros.Consensus.Node.ProtocolInfo
import Ouroboros.Consensus.Node.Run
import qualified Ouroboros.Consensus.Protocol.Ledger.HotKey as HotKey
import Ouroboros.Consensus.Protocol.Praos (Praos, PraosParams (..))
import Ouroboros.Consensus.Protocol.Praos.Common
(praosCanBeLeaderOpCert)
import Ouroboros.Consensus.Protocol.Praos.Common (PraosCanBeLeader (..), instantiatePraosCredentials)
import Ouroboros.Consensus.Protocol.TPraos (TPraos, TPraosParams (..))
import qualified Ouroboros.Consensus.Protocol.TPraos as Shelley
import Ouroboros.Consensus.Shelley.HFEras ()
Expand All @@ -112,9 +113,9 @@ import qualified Ouroboros.Consensus.Shelley.Ledger as Shelley
import Ouroboros.Consensus.Shelley.Ledger.Block (IsShelleyBlock,
ShelleyBlockLedgerEra)
import Ouroboros.Consensus.Shelley.Ledger.NetworkProtocolVersion
import qualified Ouroboros.Consensus.Protocol.Ledger.HotKey as HotKey
import Ouroboros.Consensus.Shelley.Node
import Ouroboros.Consensus.Shelley.Node.Common (ShelleyEraWithCrypto,
shelleyBlockIssuerVKey)
import Ouroboros.Consensus.Shelley.Node.Common (ShelleyEraWithCrypto, shelleyBlockIssuerVKey)
import qualified Ouroboros.Consensus.Shelley.Node.Praos as Praos
import qualified Ouroboros.Consensus.Shelley.Node.TPraos as TPraos
import Ouroboros.Consensus.Storage.Serialisation
Expand Down Expand Up @@ -609,12 +610,12 @@ protocolInfoCardano paramsCardano
, length credssShelleyBased > 1
= error "Multiple Shelley-based credentials not allowed for mainnet"
| otherwise
= assertWithMsg (validateGenesis genesisShelley)
= assertWithMsg (validateGenesis genesisShelley) $
( ProtocolInfo {
pInfoConfig = cfg
, pInfoInitLedger = initExtLedgerStateCardano
}
, blockForging
, mkBlockForgings
)
where
CardanoProtocolParams {
Expand Down Expand Up @@ -975,8 +976,8 @@ protocolInfoCardano paramsCardano
-- credentials. If there are multiple Shelley credentials, we merge the
-- Byron credentials with the first Shelley one but still have separate
-- threads for the remaining Shelley ones.
blockForging :: m [BlockForging m (CardanoBlock c)]
blockForging = do
mkBlockForgings :: m ([BlockForging m (CardanoBlock c)])
mkBlockForgings = do
shelleyBased <- traverse blockForgingShelleyBased credssShelleyBased
let blockForgings :: [NonEmptyOptNP (BlockForging m) (CardanoEras c)]
blockForgings = case (mBlockForgingByron, shelleyBased) of
Expand All @@ -1002,24 +1003,26 @@ protocolInfoCardano paramsCardano
ShelleyLeaderCredentials c
-> m (NonEmptyOptNP (BlockForging m) (CardanoEras c))
blockForgingShelleyBased credentials = do
let ShelleyLeaderCredentials
{ shelleyLeaderCredentialsInitSignKey = initSignKey
, shelleyLeaderCredentialsCanBeLeader = canBeLeader
} = credentials

hotKey <- do
let maxKESEvo :: Word64
maxKESEvo = assert (tpraosMaxKESEvo == praosMaxKESEvo) praosMaxKESEvo

startPeriod :: Absolute.KESPeriod
startPeriod = Absolute.ocertKESPeriod $ praosCanBeLeaderOpCert canBeLeader

HotKey.mkHotKey @m @c initSignKey startPeriod maxKESEvo
let canBeLeader = shelleyLeaderCredentialsCanBeLeader credentials

let slotToPeriod :: SlotNo -> Absolute.KESPeriod
slotToPeriod (SlotNo slot) = assert (tpraosSlotsPerKESPeriod == praosSlotsPerKESPeriod) $
Absolute.KESPeriod $ fromIntegral $ slot `div` praosSlotsPerKESPeriod

(ocert, sk) <- instantiatePraosCredentials (praosCanBeLeaderCredentialsSource canBeLeader)

let startPeriod :: Absolute.KESPeriod
startPeriod = SL.ocertKESPeriod ocert

let maxKESEvo :: Word64
maxKESEvo = assert (tpraosMaxKESEvo == praosMaxKESEvo) praosMaxKESEvo

hotKey :: HotKey.HotKey c m <- HotKey.mkHotKey
ocert
sk
startPeriod
maxKESEvo

let tpraos :: forall era.
ShelleyEraWithCrypto c (TPraos c) era
=> BlockForging m (ShelleyBlock (TPraos c) era)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ mkShelleyLedgerConfig genesis transCtxt epochInfo mmpv =
SL.mkShelleyGlobals
genesis
(hoistEpochInfo (left (Text.pack . show) . runExcept) epochInfo)
maxMajorPV
, shelleyLedgerTranslationContext = transCtxt
}
where
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import Cardano.Ledger.Alonzo.Scripts (ExUnits, ExUnits',
import Cardano.Ledger.Alonzo.Tx (totExUnits)
import qualified Cardano.Ledger.Api as L
import qualified Cardano.Ledger.Babbage.Rules as BabbageEra
import qualified Cardano.Ledger.BaseTypes as CB
import Cardano.Ledger.Binary (Annotator (..), DecCBOR (..),
EncCBOR (..), FromCBOR (..), FullByteString (..),
ToCBOR (..), toPlainDecoder)
Expand Down Expand Up @@ -342,7 +343,8 @@ instance MaxTxSizeUTxO (ShelleyEra c) where
SL.ApplyTxError . pure
$ ShelleyEra.UtxowFailure
$ ShelleyEra.UtxoFailure
$ ShelleyEra.MaxTxSizeUTxO x y
$ ShelleyEra.MaxTxSizeUTxO
$ CB.Mismatch x y

instance MaxTxSizeUTxO (AllegraEra c) where
maxTxSizeUTxO x y =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import Ouroboros.Consensus.Shelley.Ledger
import Ouroboros.Consensus.Shelley.Ledger.Inspect ()
import Ouroboros.Consensus.Shelley.Ledger.NetworkProtocolVersion ()
import Ouroboros.Consensus.Shelley.Node.DiffusionPipelining ()
import Ouroboros.Consensus.Shelley.Node.Common
import Ouroboros.Consensus.Shelley.Node.Serialisation ()
import Ouroboros.Consensus.Shelley.Node.TPraos
import Ouroboros.Consensus.Shelley.Protocol.Abstract (pHeaderIssuer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,7 @@ import Ouroboros.Consensus.Storage.ImmutableDB
-------------------------------------------------------------------------------}

data ShelleyLeaderCredentials c = ShelleyLeaderCredentials
{ -- | The unevolved signing KES key (at evolution 0).
--
-- Note that this is not inside 'ShelleyCanBeLeader' since it gets evolved
-- automatically, whereas 'ShelleyCanBeLeader' does not change.
shelleyLeaderCredentialsInitSignKey :: SL.SignKeyKES c,
shelleyLeaderCredentialsCanBeLeader :: PraosCanBeLeader c,
{ shelleyLeaderCredentialsCanBeLeader :: PraosCanBeLeader c,
-- | Identifier for this set of credentials.
--
-- Useful when the node is running with multiple sets of credentials.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ import qualified Ouroboros.Consensus.Ledger.SupportsMempool as Mempool
import qualified Ouroboros.Consensus.Protocol.Ledger.HotKey as HotKey
import Ouroboros.Consensus.Protocol.Praos (Praos, PraosParams (..),
praosCheckCanForge)
import Ouroboros.Consensus.Protocol.Praos.Common
(PraosCanBeLeader (praosCanBeLeaderOpCert))
import Ouroboros.Consensus.Shelley.Eras (EraCrypto)
import Ouroboros.Consensus.Shelley.Ledger (ShelleyBlock,
ShelleyCompatible, forgeShelleyBlock)
Expand All @@ -51,21 +49,13 @@ praosBlockForging ::
, IOLike m
)
=> PraosParams
-> HotKey.HotKey c m
-> ShelleyLeaderCredentials (EraCrypto era)
-> m (BlockForging m (ShelleyBlock (Praos c) era))
praosBlockForging praosParams credentials = do
hotKey <- HotKey.mkHotKey @m @c initSignKey startPeriod praosMaxKESEvo
pure $ praosSharedBlockForging hotKey slotToPeriod credentials
-> BlockForging m (ShelleyBlock (Praos c) era)
praosBlockForging praosParams hotKey credentials =
praosSharedBlockForging hotKey slotToPeriod credentials
where
PraosParams {praosMaxKESEvo, praosSlotsPerKESPeriod} = praosParams

ShelleyLeaderCredentials {
shelleyLeaderCredentialsInitSignKey = initSignKey
, shelleyLeaderCredentialsCanBeLeader = canBeLeader
} = credentials

startPeriod :: Absolute.KESPeriod
startPeriod = SL.ocertKESPeriod $ praosCanBeLeaderOpCert canBeLeader
PraosParams {praosSlotsPerKESPeriod} = praosParams

slotToPeriod :: SlotNo -> Absolute.KESPeriod
slotToPeriod (SlotNo slot) =
Expand All @@ -90,13 +80,15 @@ praosSharedBlockForging
ShelleyLeaderCredentials {
shelleyLeaderCredentialsCanBeLeader = canBeLeader
, shelleyLeaderCredentialsLabel = label
} = do
} =
BlockForging
{ forgeLabel = label <> "_" <> T.pack (L.eraName @era),
canBeLeader = canBeLeader,

updateForgeState = \_ curSlot _ ->
forgeStateUpdateInfoFromUpdateInfo
<$> HotKey.evolve hotKey (slotToPeriod curSlot),

checkCanForge = \cfg curSlot _tickedChainDepState _isLeader ->
praosCheckCanForge
(configConsensus cfg)
Expand All @@ -105,5 +97,6 @@ praosSharedBlockForging
forgeShelleyBlock
hotKey
canBeLeader
cfg
cfg,
finalize = HotKey.finalize hotKey
}
Loading