Skip to content

Commit afb30e8

Browse files
committed
Use mlocked KES
1 parent 92a8330 commit afb30e8

File tree

48 files changed

+629
-301
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+629
-301
lines changed

Diff for: cabal.project

+79
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,82 @@ package ouroboros-network
4444
if(os(windows))
4545
constraints:
4646
bitvec -simd
47+
48+
-- For the time being, we need to override some dependency bounds
49+
allow-newer: plutus-core:cardano-crypto-class
50+
, cardano-slotting
51+
52+
source-repository-package
53+
type: git
54+
location: https://github.com/input-output-hk/cardano-base
55+
tag: 890eec1bbb17068ee7df84c468e1c6bc39643d3a
56+
--sha256: 0944wg2nqazmhlmsynwgdwxxj6ay0hb9qig9l128isb2cjia0hlp
57+
subdir:
58+
-- cardano-binary
59+
cardano-crypto-class
60+
cardano-crypto-tests
61+
cardano-crypto-praos
62+
cardano-mempool
63+
-- cardano-slotting
64+
65+
source-repository-package
66+
type: git
67+
location: https://github.com/IntersectMBO/formal-ledger-specifications.git
68+
-- !WARNING!:
69+
-- MAKE SURE THIS POINTS TO A COMMIT IN `MAlonzo-code` BEFORE MERGE!
70+
subdir: generated
71+
tag: 544ab20985e3374a1d672354e25d8ca0ca89e7e4
72+
--sha256: sha256-bhh09OZkHazXCPjsiU/50Hrmfg52i+6UORTZ6/bAx6c=
73+
-- NOTE: If you would like to update the above, look for the `MAlonzo-code`
74+
-- branch in the `formal-ledger-specifications` repo and copy the SHA of
75+
-- the commit you need. The `MAlonzo-code` branch functions like an alternative
76+
-- `master / main` branch for the generated code, see the details here:
77+
-- https://github.com/IntersectMBO/formal-ledger-specifications/pull/530
78+
-- If you are working on something in `formal-ledger-specifications`
79+
-- and would like to see how they reflect here, just open a PR / draft PR
80+
-- in `formal-ledger-specifications` for your branch and that will
81+
-- automatically create a branch for the generated code that you can try here
82+
-- by editing the above SRP.
83+
-- Once your changes are merged in `formal-ledger-specifications`, the branch
84+
-- for the generated code will be merged into `MAlonzo-code` automatically.
85+
-- Before merging a PR in `cardano-ledger`, make sure that the above SRP
86+
-- points to a commit in `MAlonzo-code` if you were fiddling with the SRP
87+
-- as part of your PR.
88+
89+
source-repository-package
90+
type: git
91+
location: https://github.com/input-output-hk/cardano-ledger
92+
tag: ebba3fb4554a04ddaa4734f9083afebd64c81099
93+
--sha256: 0944wg2nqazmhlmsynwgdwxxj6ay0hb9qig9l128isb2cjia0hlp
94+
subdir:
95+
eras/allegra/impl
96+
eras/alonzo/impl
97+
eras/alonzo/test-suite
98+
eras/babbage/impl
99+
eras/babbage/test-suite
100+
eras/byron/chain/executable-spec
101+
eras/byron/crypto
102+
eras/byron/crypto/test
103+
eras/byron/ledger/executable-spec
104+
eras/byron/ledger/impl
105+
eras/byron/ledger/impl/test
106+
eras/conway/impl
107+
eras/conway/test-suite
108+
eras/mary/impl
109+
eras/shelley/impl
110+
eras/shelley-ma/test-suite
111+
eras/shelley/test-suite
112+
libs/cardano-data
113+
libs/cardano-ledger-api
114+
libs/cardano-ledger-binary
115+
libs/cardano-ledger-conformance
116+
libs/cardano-ledger-core
117+
libs/cardano-ledger-test
118+
libs/cardano-protocol-tpraos
119+
libs/constrained-generators
120+
libs/ledger-state
121+
libs/non-integral
122+
libs/plutus-preprocessor
123+
libs/set-algebra
124+
libs/small-steps
125+
libs/vector-map

Diff for: ouroboros-consensus-cardano/ouroboros-consensus-cardano.cabal

+9-8
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,15 @@ library
135135
cardano-crypto-class,
136136
cardano-crypto-wrapper,
137137
cardano-ledger-allegra ^>=1.6,
138-
cardano-ledger-alonzo ^>=1.10.2,
138+
cardano-ledger-alonzo ^>=1.11.0,
139139
cardano-ledger-api ^>=1.9.3,
140-
cardano-ledger-babbage ^>=1.9,
141-
cardano-ledger-binary ^>=1.3.4,
140+
cardano-ledger-babbage ^>=1.10,
141+
cardano-ledger-binary ^>=1.4.0,
142142
cardano-ledger-byron ^>=1.0.1,
143-
cardano-ledger-conway ^>=1.16,
144-
cardano-ledger-core ^>=1.14,
143+
cardano-ledger-conway ^>=1.17,
144+
cardano-ledger-core ^>=1.15,
145145
cardano-ledger-mary ^>=1.7,
146-
cardano-ledger-shelley ^>=1.13.1,
146+
cardano-ledger-shelley ^>=1.14.0,
147147
cardano-prelude,
148148
cardano-protocol-tpraos ^>=1.2,
149149
cardano-slotting,
@@ -304,7 +304,7 @@ library unstable-shelley-testlib
304304
cardano-ledger-alonzo,
305305
cardano-ledger-alonzo-test,
306306
cardano-ledger-babbage-test,
307-
cardano-ledger-conway-test >=1.2.1,
307+
cardano-ledger-conway-test >=1.3.0,
308308
cardano-ledger-core:{cardano-ledger-core, testlib},
309309
cardano-ledger-mary,
310310
cardano-ledger-shelley:{cardano-ledger-shelley, testlib},
@@ -390,7 +390,7 @@ library unstable-cardano-testlib
390390
cardano-ledger-api,
391391
cardano-ledger-byron,
392392
cardano-ledger-conway:testlib,
393-
cardano-ledger-conway-test ^>=1.2.1,
393+
cardano-ledger-conway-test ^>=1.3.0,
394394
cardano-ledger-core:{cardano-ledger-core, testlib},
395395
cardano-ledger-shelley,
396396
cardano-protocol-tpraos,
@@ -545,6 +545,7 @@ library unstable-cardano-tools
545545
filepath,
546546
fs-api ^>=0.3,
547547
githash,
548+
io-classes ^>=1.5,
548549
microlens,
549550
mtl,
550551
network,

Diff for: ouroboros-consensus-cardano/src/byron/Ouroboros/Consensus/Byron/Crypto/DSIGN.hs

+4-4
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import Cardano.Crypto (ProtocolMagicId, SignTag (..), Signature (..),
2626
SigningKey (..), VerificationKey (..), deterministicKeyGen,
2727
signRaw, toVerification, verifySignatureRaw)
2828
import Cardano.Crypto.DSIGN.Class
29-
import Cardano.Crypto.Seed (SeedBytesExhausted (..), getBytesFromSeed)
29+
import Cardano.Crypto.Seed (getBytesFromSeedEither)
3030
import qualified Cardano.Crypto.Signing as Crypto
3131
import qualified Cardano.Crypto.Wallet as CC
3232
import Cardano.Ledger.Binary
@@ -90,9 +90,9 @@ instance DSIGNAlgorithm ByronDSIGN where
9090
genKeyDSIGN seed =
9191
SignKeyByronDSIGN . snd $ deterministicKeyGen seedBytes
9292
where
93-
seedBytes = case getBytesFromSeed 32 seed of
94-
Just (x,_) -> x
95-
Nothing -> throw $ SeedBytesExhausted (-1) -- TODO We can't get the seed size!
93+
seedBytes = case getBytesFromSeedEither 32 seed of
94+
Right (x,_) -> x
95+
Left err -> throw err
9696

9797
deriveVerKeyDSIGN (SignKeyByronDSIGN sk) = VerKeyByronDSIGN $ toVerification sk
9898

Diff for: ouroboros-consensus-cardano/src/byron/Ouroboros/Consensus/Byron/Node.hs

+1
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ byronBlockForging creds = BlockForging {
140140
slot
141141
tickedPBftState
142142
, forgeBlock = \cfg -> return ....: forgeByronBlock cfg
143+
, finalize = pure ()
143144
}
144145
where
145146
canBeLeader = mkPBftCanBeLeader creds

Diff for: ouroboros-consensus-cardano/src/ouroboros-consensus-cardano/Ouroboros/Consensus/Cardano/Node.hs

+27-24
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ module Ouroboros.Consensus.Cardano.Node (
3636
, CardanoHardForkTriggers (.., CardanoHardForkTriggers', triggerHardForkShelley, triggerHardForkAllegra, triggerHardForkMary, triggerHardForkAlonzo, triggerHardForkBabbage, triggerHardForkConway)
3737
, CardanoProtocolParams (..)
3838
, MaxMajorProtVer (..)
39+
, ProtocolParamsByron
40+
, ProtocolParamsShelleyBased
41+
, CheckpointsMap
3942
, TriggerHardFork (..)
4043
, protocolClientInfoCardano
4144
, protocolInfoCardano
@@ -64,8 +67,8 @@ import qualified Cardano.Ledger.Api.Transition as L
6467
import qualified Cardano.Ledger.BaseTypes as SL
6568
import qualified Cardano.Ledger.Shelley.API as SL
6669
import Cardano.Prelude (cborError)
67-
import qualified Cardano.Protocol.TPraos.OCert as Absolute (KESPeriod (..),
68-
ocertKESPeriod)
70+
import qualified Cardano.Protocol.TPraos.OCert as Absolute (KESPeriod (..))
71+
import qualified Cardano.Protocol.TPraos.OCert as SL
6972
import Cardano.Slotting.Time (SystemStart (SystemStart))
7073
import qualified Codec.CBOR.Decoding as CBOR
7174
import Codec.CBOR.Encoding (Encoding)
@@ -100,10 +103,8 @@ import Ouroboros.Consensus.Ledger.Extended
100103
import Ouroboros.Consensus.Node.NetworkProtocolVersion
101104
import Ouroboros.Consensus.Node.ProtocolInfo
102105
import Ouroboros.Consensus.Node.Run
103-
import qualified Ouroboros.Consensus.Protocol.Ledger.HotKey as HotKey
104106
import Ouroboros.Consensus.Protocol.Praos (Praos, PraosParams (..))
105-
import Ouroboros.Consensus.Protocol.Praos.Common
106-
(praosCanBeLeaderOpCert)
107+
import Ouroboros.Consensus.Protocol.Praos.Common (PraosCanBeLeader (..), instantiatePraosCredentials)
107108
import Ouroboros.Consensus.Protocol.TPraos (TPraos, TPraosParams (..))
108109
import qualified Ouroboros.Consensus.Protocol.TPraos as Shelley
109110
import Ouroboros.Consensus.Shelley.HFEras ()
@@ -112,9 +113,9 @@ import qualified Ouroboros.Consensus.Shelley.Ledger as Shelley
112113
import Ouroboros.Consensus.Shelley.Ledger.Block (IsShelleyBlock,
113114
ShelleyBlockLedgerEra)
114115
import Ouroboros.Consensus.Shelley.Ledger.NetworkProtocolVersion
116+
import qualified Ouroboros.Consensus.Protocol.Ledger.HotKey as HotKey
115117
import Ouroboros.Consensus.Shelley.Node
116-
import Ouroboros.Consensus.Shelley.Node.Common (ShelleyEraWithCrypto,
117-
shelleyBlockIssuerVKey)
118+
import Ouroboros.Consensus.Shelley.Node.Common (ShelleyEraWithCrypto, shelleyBlockIssuerVKey)
118119
import qualified Ouroboros.Consensus.Shelley.Node.Praos as Praos
119120
import qualified Ouroboros.Consensus.Shelley.Node.TPraos as TPraos
120121
import Ouroboros.Consensus.Storage.Serialisation
@@ -609,12 +610,12 @@ protocolInfoCardano paramsCardano
609610
, length credssShelleyBased > 1
610611
= error "Multiple Shelley-based credentials not allowed for mainnet"
611612
| otherwise
612-
= assertWithMsg (validateGenesis genesisShelley)
613+
= assertWithMsg (validateGenesis genesisShelley) $
613614
( ProtocolInfo {
614615
pInfoConfig = cfg
615616
, pInfoInitLedger = initExtLedgerStateCardano
616617
}
617-
, blockForging
618+
, mkBlockForgings
618619
)
619620
where
620621
CardanoProtocolParams {
@@ -975,8 +976,8 @@ protocolInfoCardano paramsCardano
975976
-- credentials. If there are multiple Shelley credentials, we merge the
976977
-- Byron credentials with the first Shelley one but still have separate
977978
-- threads for the remaining Shelley ones.
978-
blockForging :: m [BlockForging m (CardanoBlock c)]
979-
blockForging = do
979+
mkBlockForgings :: m ([BlockForging m (CardanoBlock c)])
980+
mkBlockForgings = do
980981
shelleyBased <- traverse blockForgingShelleyBased credssShelleyBased
981982
let blockForgings :: [NonEmptyOptNP (BlockForging m) (CardanoEras c)]
982983
blockForgings = case (mBlockForgingByron, shelleyBased) of
@@ -1002,24 +1003,26 @@ protocolInfoCardano paramsCardano
10021003
ShelleyLeaderCredentials c
10031004
-> m (NonEmptyOptNP (BlockForging m) (CardanoEras c))
10041005
blockForgingShelleyBased credentials = do
1005-
let ShelleyLeaderCredentials
1006-
{ shelleyLeaderCredentialsInitSignKey = initSignKey
1007-
, shelleyLeaderCredentialsCanBeLeader = canBeLeader
1008-
} = credentials
1009-
1010-
hotKey <- do
1011-
let maxKESEvo :: Word64
1012-
maxKESEvo = assert (tpraosMaxKESEvo == praosMaxKESEvo) praosMaxKESEvo
1013-
1014-
startPeriod :: Absolute.KESPeriod
1015-
startPeriod = Absolute.ocertKESPeriod $ praosCanBeLeaderOpCert canBeLeader
1016-
1017-
HotKey.mkHotKey @m @c initSignKey startPeriod maxKESEvo
1006+
let canBeLeader = shelleyLeaderCredentialsCanBeLeader credentials
10181007

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

1012+
(ocert, sk) <- instantiatePraosCredentials (praosCanBeLeaderCredentialsSource canBeLeader)
1013+
1014+
let startPeriod :: Absolute.KESPeriod
1015+
startPeriod = SL.ocertKESPeriod ocert
1016+
1017+
let maxKESEvo :: Word64
1018+
maxKESEvo = assert (tpraosMaxKESEvo == praosMaxKESEvo) praosMaxKESEvo
1019+
1020+
hotKey :: HotKey.HotKey c m <- HotKey.mkHotKey
1021+
ocert
1022+
sk
1023+
startPeriod
1024+
maxKESEvo
1025+
10231026
let tpraos :: forall era.
10241027
ShelleyEraWithCrypto c (TPraos c) era
10251028
=> BlockForging m (ShelleyBlock (TPraos c) era)

Diff for: ouroboros-consensus-cardano/src/shelley/Ouroboros/Consensus/Shelley/Ledger/Ledger.hs

-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,6 @@ mkShelleyLedgerConfig genesis transCtxt epochInfo mmpv =
170170
SL.mkShelleyGlobals
171171
genesis
172172
(hoistEpochInfo (left (Text.pack . show) . runExcept) epochInfo)
173-
maxMajorPV
174173
, shelleyLedgerTranslationContext = transCtxt
175174
}
176175
where

Diff for: ouroboros-consensus-cardano/src/shelley/Ouroboros/Consensus/Shelley/Ledger/Mempool.hs

+3-1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import Cardano.Ledger.Alonzo.Scripts (ExUnits, ExUnits',
4646
import Cardano.Ledger.Alonzo.Tx (totExUnits)
4747
import qualified Cardano.Ledger.Api as L
4848
import qualified Cardano.Ledger.Babbage.Rules as BabbageEra
49+
import qualified Cardano.Ledger.BaseTypes as CB
4950
import Cardano.Ledger.Binary (Annotator (..), DecCBOR (..),
5051
EncCBOR (..), FromCBOR (..), FullByteString (..),
5152
ToCBOR (..), toPlainDecoder)
@@ -342,7 +343,8 @@ instance MaxTxSizeUTxO (ShelleyEra c) where
342343
SL.ApplyTxError . pure
343344
$ ShelleyEra.UtxowFailure
344345
$ ShelleyEra.UtxoFailure
345-
$ ShelleyEra.MaxTxSizeUTxO x y
346+
$ ShelleyEra.MaxTxSizeUTxO
347+
$ CB.Mismatch x y
346348

347349
instance MaxTxSizeUTxO (AllegraEra c) where
348350
maxTxSizeUTxO x y =

Diff for: ouroboros-consensus-cardano/src/shelley/Ouroboros/Consensus/Shelley/Node.hs

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import Ouroboros.Consensus.Shelley.Ledger
4444
import Ouroboros.Consensus.Shelley.Ledger.Inspect ()
4545
import Ouroboros.Consensus.Shelley.Ledger.NetworkProtocolVersion ()
4646
import Ouroboros.Consensus.Shelley.Node.DiffusionPipelining ()
47+
import Ouroboros.Consensus.Shelley.Node.Common
4748
import Ouroboros.Consensus.Shelley.Node.Serialisation ()
4849
import Ouroboros.Consensus.Shelley.Node.TPraos
4950
import Ouroboros.Consensus.Shelley.Protocol.Abstract (pHeaderIssuer)

Diff for: ouroboros-consensus-cardano/src/shelley/Ouroboros/Consensus/Shelley/Node/Common.hs

+1-6
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,7 @@ import Ouroboros.Consensus.Storage.ImmutableDB
4848
-------------------------------------------------------------------------------}
4949

5050
data ShelleyLeaderCredentials c = ShelleyLeaderCredentials
51-
{ -- | The unevolved signing KES key (at evolution 0).
52-
--
53-
-- Note that this is not inside 'ShelleyCanBeLeader' since it gets evolved
54-
-- automatically, whereas 'ShelleyCanBeLeader' does not change.
55-
shelleyLeaderCredentialsInitSignKey :: SL.SignKeyKES c,
56-
shelleyLeaderCredentialsCanBeLeader :: PraosCanBeLeader c,
51+
{ shelleyLeaderCredentialsCanBeLeader :: PraosCanBeLeader c,
5752
-- | Identifier for this set of credentials.
5853
--
5954
-- Useful when the node is running with multiple sets of credentials.

Diff for: ouroboros-consensus-cardano/src/shelley/Ouroboros/Consensus/Shelley/Node/Praos.hs

+10-17
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ import qualified Ouroboros.Consensus.Ledger.SupportsMempool as Mempool
2828
import qualified Ouroboros.Consensus.Protocol.Ledger.HotKey as HotKey
2929
import Ouroboros.Consensus.Protocol.Praos (Praos, PraosParams (..),
3030
praosCheckCanForge)
31-
import Ouroboros.Consensus.Protocol.Praos.Common
32-
(PraosCanBeLeader (praosCanBeLeaderOpCert))
3331
import Ouroboros.Consensus.Shelley.Eras (EraCrypto)
3432
import Ouroboros.Consensus.Shelley.Ledger (ShelleyBlock,
3533
ShelleyCompatible, forgeShelleyBlock)
@@ -51,21 +49,13 @@ praosBlockForging ::
5149
, IOLike m
5250
)
5351
=> PraosParams
52+
-> HotKey.HotKey c m
5453
-> ShelleyLeaderCredentials (EraCrypto era)
55-
-> m (BlockForging m (ShelleyBlock (Praos c) era))
56-
praosBlockForging praosParams credentials = do
57-
hotKey <- HotKey.mkHotKey @m @c initSignKey startPeriod praosMaxKESEvo
58-
pure $ praosSharedBlockForging hotKey slotToPeriod credentials
54+
-> BlockForging m (ShelleyBlock (Praos c) era)
55+
praosBlockForging praosParams hotKey credentials =
56+
praosSharedBlockForging hotKey slotToPeriod credentials
5957
where
60-
PraosParams {praosMaxKESEvo, praosSlotsPerKESPeriod} = praosParams
61-
62-
ShelleyLeaderCredentials {
63-
shelleyLeaderCredentialsInitSignKey = initSignKey
64-
, shelleyLeaderCredentialsCanBeLeader = canBeLeader
65-
} = credentials
66-
67-
startPeriod :: Absolute.KESPeriod
68-
startPeriod = SL.ocertKESPeriod $ praosCanBeLeaderOpCert canBeLeader
58+
PraosParams {praosSlotsPerKESPeriod} = praosParams
6959

7060
slotToPeriod :: SlotNo -> Absolute.KESPeriod
7161
slotToPeriod (SlotNo slot) =
@@ -90,13 +80,15 @@ praosSharedBlockForging
9080
ShelleyLeaderCredentials {
9181
shelleyLeaderCredentialsCanBeLeader = canBeLeader
9282
, shelleyLeaderCredentialsLabel = label
93-
} = do
83+
} =
9484
BlockForging
9585
{ forgeLabel = label <> "_" <> T.pack (L.eraName @era),
9686
canBeLeader = canBeLeader,
87+
9788
updateForgeState = \_ curSlot _ ->
9889
forgeStateUpdateInfoFromUpdateInfo
9990
<$> HotKey.evolve hotKey (slotToPeriod curSlot),
91+
10092
checkCanForge = \cfg curSlot _tickedChainDepState _isLeader ->
10193
praosCheckCanForge
10294
(configConsensus cfg)
@@ -105,5 +97,6 @@ praosSharedBlockForging
10597
forgeShelleyBlock
10698
hotKey
10799
canBeLeader
108-
cfg
100+
cfg,
101+
finalize = HotKey.finalize hotKey
109102
}

0 commit comments

Comments
 (0)