Skip to content
Open
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
51 changes: 14 additions & 37 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ index-state:
-- Bump this if you need newer packages from Hackage
, hackage.haskell.org 2025-05-15T07:59:00Z
-- Bump this if you need newer packages from CHaP
, cardano-haskell-packages 2025-05-15T08:36:14Z
, cardano-haskell-packages 2026-04-11T06:29:42Z

packages:
ouroboros-consensus
Expand Down Expand Up @@ -66,59 +66,36 @@ if impl (ghc >= 9.12)
-- https://github.com/kapralVV/Unique/issues/11
, Unique:hashable

-- Points to ouroboros-network/nfrisby/leios-202511-demo
-- NOTE: leios-prototype requires newer cardano-crypto-class, but some
-- dependencies (plutus) are not patched for leios
allow-newer:
, cardano-crypto-class

-- Points to ouroboros-network/ch1bo/leios-voting
source-repository-package
type: git
location: https://github.com/IntersectMBO/ouroboros-network.git
tag: fb5f16f48af84950db0c2ecefd8cbda532c77d1a
--sha256: sha256-0LWD1zwOzhdcPJtBuw7pRDVcBd9CKJOFjm9o4BvsIMM=
tag: 9d8fb9338cf603e10eca0be885504dfd917a17ff
--sha256: sha256-AREjItjvcleZTZaGlG4MEZnN3PIWOU9GrCbBkaoe6rY=
subdir:
cardano-ping
monoidal-synchronisation
quickcheck-monoids
network-mux
ouroboros-network
ouroboros-network-api
ouroboros-network-framework
ouroboros-network-mock
ouroboros-network-protocols
ouroboros-network-testing
ntp-client
cardano-client

-- Points to cardano-ledger/leios-prototype
-- Points to cardano-ledger/ch1bo/leios-voting
source-repository-package
type: git
location: https://github.com/IntersectMBO/cardano-ledger.git
tag: 6b831537f4dd3863da18c9a2a82b81d946a12052
--sha256: sha256-YI5tb+kcY4uDOCiK42AD+j1JvfVWc8IgO6Acr7HBEnc=
tag: 4c8b81a375f263a5d3bcb579c5acf7a130368c4a
--sha256: sha256-3/QY6GkTWE5q++gpzOPoNjwoYq96lQvOTduWXVY9mxU=
subdir:
eras/allegra/impl
eras/alonzo/impl
eras/alonzo/test-suite
eras/babbage/impl
eras/babbage/test-suite
eras/byron/ledger/impl
eras/conway/impl
eras/conway/test-suite
eras/mary/impl
eras/shelley/impl
eras/shelley/test-suite
eras/shelley-ma/test-suite
libs/cardano-ledger-api
libs/cardano-ledger-core
libs/cardano-ledger-binary
libs/cardano-ledger-core
libs/cardano-protocol-tpraos
libs/non-integral
libs/small-steps
libs/cardano-data
libs/set-algebra
libs/vector-map
eras/byron/chain/executable-spec
eras/byron/ledger/executable-spec
eras/byron/ledger/impl
eras/byron/ledger/impl/test
eras/byron/crypto
eras/byron/crypto/test
libs/cardano-ledger-test
libs/ledger-state
libs/constrained-generators
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions nix/haskell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ let
testFlags = lib.mkForce [ "--no-create" ];
extraSrcFiles = [ "golden/${n}/**/*" ];
}) [ "byron" "shelley" "cardano" ]);
packages.ouroboros-consensus.components.tests.consensus-test = {
testFlags = lib.mkForce [ "--no-create" ];
extraSrcFiles = [ "golden/**/*" ];
};
}
];
flake.variants = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ library
bytestring >=0.10 && <0.13,
cardano-binary,
cardano-crypto,
cardano-crypto-class ^>=2.2,
cardano-crypto-class ^>=2.4,
cardano-crypto-wrapper,
cardano-ledger-allegra ^>=1.7,
cardano-ledger-alonzo ^>=1.13,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ data ByronDSIGN

instance DSIGNAlgorithm ByronDSIGN where
type SeedSizeDSIGN ByronDSIGN = 32
type SizeVerKeyDSIGN ByronDSIGN = 64
type SizeSignKeyDSIGN ByronDSIGN = 128
type SizeSigDSIGN ByronDSIGN = 64
type VerKeySizeDSIGN ByronDSIGN = 64
type SignKeySizeDSIGN ByronDSIGN = 128
type SigSizeDSIGN ByronDSIGN = 64

algorithmNameDSIGN _ = "ByronDSIGN"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import qualified Data.Map.Strict as Map
import Data.Proxy
import Data.Typeable
import GHC.Generics (Generic)
import LeiosVoting (HasLeiosVoting)
import NoThunks.Class (NoThunks (..))
import Ouroboros.Consensus.Block
import qualified Ouroboros.Consensus.Byron.EBBs as EBBs
Expand Down Expand Up @@ -99,6 +100,8 @@ data ByronBlock = ByronBlock

instance ResolveLeiosBlock ByronBlock

instance HasLeiosVoting ByronBlock

instance Condense ByronBlock where
condense = condense . byronBlockRaw

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ encodeByronGenTxId genTxId =
decodeByronGenTxId :: Decoder s (GenTxId ByronBlock)
decodeByronGenTxId = do
enforceSize "GenTxId (ByronBlock cfg)" 2
CBOR.decodeWord8 >>= \case
CBOR.decodeWord >>= \case
0 -> ByronTxId <$> fromByronCBOR
1 -> ByronDlgId <$> fromByronCBOR
2 -> ByronUpdateProposalId <$> fromByronCBOR
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ instance EncodeDiskDep (NestedCtxt Header) ByronBlock where
instance DecodeDiskDepIx (NestedCtxt Header) ByronBlock where
decodeDiskDepIx _ccfg = do
enforceSize "decodeDiskDepIx ByronBlock" 2
CBOR.decodeWord8 >>= \case
CBOR.decodeWord >>= \case
0 -> SomeSecond . NestedCtxt . CtxtByronBoundary . SizeInBytes <$> CBOR.decodeWord32
1 -> SomeSecond . NestedCtxt . CtxtByronRegular . SizeInBytes <$> CBOR.decodeWord32
t -> cborError $ DecoderErrorUnknownTag "decodeDiskDepIx ByronBlock" t
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,12 @@ module Ouroboros.Consensus.Cardano.Node

import Cardano.Binary (DecoderError (..), enforceSize)
import Cardano.Chain.Slotting (EpochSlots)
import Cardano.Crypto.KES.Class (rawSerialiseUnsoundPureSignKeyKES)
import Cardano.Crypto.DSIGN (DSIGNAlgorithm (rawDeserialiseSignKeyDSIGN))
import Cardano.Crypto.Hash.Class (hashToBytes)
import qualified Cardano.Ledger.Api.Era as L
import qualified Cardano.Ledger.Api.Transition as L
import qualified Cardano.Ledger.BaseTypes as SL
import Cardano.Ledger.Hashes (KeyHash (..), hashKey)
import qualified Cardano.Ledger.Shelley.API as SL
import Cardano.Prelude (cborError)
import qualified Cardano.Protocol.TPraos.OCert as Absolute
Expand All @@ -61,6 +63,7 @@ import qualified Codec.CBOR.Decoding as CBOR
import Codec.CBOR.Encoding (Encoding)
import qualified Codec.CBOR.Encoding as CBOR
import Control.Exception (assert)
import qualified Data.ByteString as BS
import qualified Data.ByteString.Short as Short
import Data.Functor.These (These1 (..))
import qualified Data.Map.Strict as Map
Expand Down Expand Up @@ -178,7 +181,7 @@ instance CardanoHardForkConstraints c => SerialiseHFC (CardanoEras c) where
5 -> fmap BlockAlonzo <$> decodeDisk ccfgAlonzo
6 -> fmap BlockBabbage <$> decodeDisk ccfgBabbage
7 -> fmap BlockConway <$> decodeDisk ccfgConway
t -> cborError $ DecoderErrorUnknownTag "CardanoBlock" (fromIntegral t)
t -> cborError $ DecoderErrorUnknownTag "CardanoBlock" t
where
epochSlots = Byron.getByronEpochSlots ccfgByron

Expand Down Expand Up @@ -813,11 +816,15 @@ protocolInfoCardano paramsCardano
(Shelley.ShelleyStorageConfig tpraosSlotsPerKESPeriod k)
(Shelley.ShelleyStorageConfig tpraosSlotsPerKESPeriod k)
, topLevelConfigCheckpoints = cardanoCheckpoints
, -- FIXME: REMOVE THIS. Accesses and re-uses KES signing key material.
, -- FIXME: REMOVE THIS. Interprets cold key hashes as signing keys
topLevelConfigVotingKey =
Just
. rawSerialiseUnsoundPureSignKeyKES
. shelleyLeaderCredentialsInitSignKey
rawDeserialiseSignKeyDSIGN
-- Pad the 28 bytes of blake2b_224 to get 32 bytes for BLS
. (<> BS.pack (replicate 4 0))
. hashToBytes
. unKeyHash
. hashKey
. shelleyBlockIssuerVKey
$ credssShelleyBased !! 0
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedRecordDot #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
Expand Down Expand Up @@ -59,6 +60,8 @@ module Ouroboros.Consensus.Shelley.Ledger.Ledger
, toTxSeq
) where

import Cardano.Crypto.DSIGN (DSIGNAlgorithm (deriveVerKeyDSIGN), rawDeserialiseSignKeyDSIGN)
import Cardano.Crypto.Hash.Class (hashToBytes)
import qualified Cardano.Ledger.BHeaderView as SL (BHeaderView)
import qualified Cardano.Ledger.BaseTypes as SL (epochInfoPure)
import Cardano.Ledger.BaseTypes.NonZero (unNonZero)
Expand All @@ -84,6 +87,7 @@ import qualified Cardano.Ledger.Block as Core
import qualified Cardano.Ledger.Block as SL
import Cardano.Ledger.Core
( Era
, KeyHash (..)
, eraDecoder
, fromTxSeq
, ppMaxBHSizeL
Expand All @@ -94,6 +98,7 @@ import qualified Cardano.Ledger.Core as Core
import qualified Cardano.Ledger.Shelley.API as SL
import qualified Cardano.Ledger.Shelley.Core as SL
import qualified Cardano.Ledger.Shelley.LedgerState as SL
import Cardano.Ledger.State (poolDistrDistrL)
import qualified Cardano.Ledger.UMap as SL
import Cardano.Slotting.EpochInfo
import Codec.CBOR.Decoding (Decoder)
Expand All @@ -110,6 +115,8 @@ import qualified Data.ByteString.Lazy as BL
import Data.Coerce (coerce)
import Data.Foldable (toList)
import Data.Functor.Identity
import qualified Data.Map as Map
import Data.Maybe (fromJust)
import Data.MemPack
import qualified Data.Sequence.Strict as StrictSeq
import qualified Data.Text as T
Expand All @@ -118,12 +125,14 @@ import Data.Word
import GHC.Generics (Generic)
import LeiosDemoDb (leiosDbQueryCompletedEbByPoint)
import LeiosDemoTypes
( EbAnnouncement (ebAnnouncementHash)
( Committee (..)
, EbAnnouncement (ebAnnouncementHash)
, LeiosPoint (MkLeiosPoint)
, TxHash
, pointEbHash
, pointSlotNo
)
import LeiosVoting (HasLeiosVoting (..))
import Lens.Micro
import Lens.Micro.Extras (view)
import NoThunks.Class (NoThunks (..))
Expand All @@ -150,6 +159,7 @@ import Ouroboros.Consensus.Protocol.Praos
, withOriginToSlotNo
)
import Ouroboros.Consensus.Protocol.TPraos (TPraos)
import Ouroboros.Consensus.Shelley.Eras (ConwayEra)
import Ouroboros.Consensus.Shelley.Ledger.Block
import Ouroboros.Consensus.Shelley.Ledger.Config
import Ouroboros.Consensus.Shelley.Ledger.Protocol ()
Expand Down Expand Up @@ -894,3 +904,32 @@ decodeShelleyLedgerState =

instance CanUpgradeLedgerTables (LedgerState (ShelleyBlock proto era)) where
upgradeTables _ _ = id

-- * Leios voting

-- NOTE: Only Conway opts in to Leios voting right now, all earlier
-- Shelley-based eras will never have a committee and thus no voting should
-- happen.
instance {-# OVERLAPPABLE #-} HasLeiosVoting (ShelleyBlock proto era)

instance {-# OVERLAPPING #-} HasLeiosVoting (ShelleyBlock (Praos c) ConwayEra) where
-- REVIEW: Should we use the LedgerView (Praos c) instead?
getLeiosCommittee ls =
Just $ MkCommittee{voters = everyoneVotes}
where
-- TODO: stake-based scheme and move to era boundary (to cache sort by stake)
everyoneVotes =
toList (Map.keysSet stakeDistribution)
& map (deriveVerKeyDSIGN . unsafeDeriveSigningKey)

-- FIXME: REMOVE THIS. Interprets cold key hashes as signing keys
unsafeDeriveSigningKey =
fromJust
. rawDeserialiseSignKeyDSIGN
-- Pad the 28 bytes of blake2b_224 to get 32 bytes for BLS
. (<> BS.pack (replicate 4 0))
. hashToBytes
. unKeyHash

stakeDistribution =
ls.shelleyLedgerState.nesPd ^. poolDistrDistrL
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import qualified Cardano.Ledger.Shelley.API as SL
import Cardano.Protocol.Crypto (Crypto)
import Data.Map.Strict (Map)
import qualified Data.Map.Strict as Map
import LeiosVoting (HasLeiosVoting)
import Ouroboros.Consensus.Block
import Ouroboros.Consensus.Config
import Ouroboros.Consensus.Ledger.SupportsMempool (TxLimits)
Expand Down Expand Up @@ -120,6 +121,7 @@ instance
, ResolveLeiosBlock (ShelleyBlock proto era)
, LedgerSupportsProtocol (ShelleyBlock proto era)
, BlockSupportsSanityCheck (ShelleyBlock proto era)
, HasLeiosVoting (ShelleyBlock proto era)
, TxLimits (ShelleyBlock proto era)
, SerialiseNodeToClientConstraints (ShelleyBlock proto era)
, Crypto (ProtoCrypto proto)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import Ouroboros.Consensus.Node.Run
import Ouroboros.Consensus.NodeId
import Ouroboros.Consensus.Protocol.PBFT
import qualified Ouroboros.Consensus.Protocol.PBFT.State as S
import LeiosVoting (HasLeiosVoting)
import Ouroboros.Consensus.Storage.ChainDB.Init (InitChainDB (..))
import Ouroboros.Consensus.Storage.LedgerDB (ResolveLeiosBlock)
import qualified Test.Cardano.Chain.Elaboration.Block as Spec.Test
Expand Down Expand Up @@ -293,3 +294,5 @@ instance RunNode DualByronBlock
-- * Leios

instance ResolveLeiosBlock DualByronBlock

instance HasLeiosVoting DualByronBlock
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,7 @@ library unstable-mock-testlib
QuickCheck,
base,
bytestring,
cardano-crypto-class ^>=2.2,
cardano-crypto-tests ^>=2.2,
cardano-crypto-class:{cardano-crypto-class, testlib} ^>=2.4,
containers,
ouroboros-consensus:{ouroboros-consensus, unstable-consensus-testlib, unstable-mock-block},
serialise,
Expand Down Expand Up @@ -283,7 +282,7 @@ test-suite consensus-test
base,
binary,
bytestring,
cardano-crypto-class ^>=2.2,
cardano-crypto-class ^>=2.4,
cardano-ledger-core,
cardano-slotting:{cardano-slotting, testlib},
cardano-strict-containers,
Expand Down
Loading
Loading