Skip to content

Scaffold an initial cardano-crypto-leios package#670

Merged
ch1bo merged 28 commits into
masterfrom
ch1bo/cardano-crypto-leios
Jun 29, 2026
Merged

Scaffold an initial cardano-crypto-leios package#670
ch1bo merged 28 commits into
masterfrom
ch1bo/cardano-crypto-leios

Conversation

@ch1bo

@ch1bo ch1bo commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Adds a new package for leios cryptographic types and operations. This was done in course of IntersectMBO/ouroboros-consensus#2068, I'm currently integrating this with the cardano-ledger master and expect a follow-up PR there.

The digital signature scheme is BLS12-381 and fixed in the module. Contrary to the CIP-164, the certificate does not contain a slot or EbHash anymore. This makes definition in cardano-base a lot easier and in the current block structure design, the "message" against which the certificate is signed would be available from the (block) context in which the certificate is used.

Most importantly, this module contains encoders/decoders for the LeiosCert type including roundtrip and golden tests. This should be enough for the cardano-ledger to use this type confidently in Dijkstra era blocks.

There are also property tests about aggregating and verifying certificates. The Committee is part of this package, but how it is selected is deliberately kept out of scope.

image

@ch1bo ch1bo changed the title WIP: Scaffold an initial cardano-crypto-leios package Scaffold an initial cardano-crypto-leios package Jun 11, 2026
@ch1bo ch1bo force-pushed the ch1bo/cardano-crypto-leios branch from d85df0c to aa227fa Compare June 16, 2026 14:56
@ch1bo ch1bo requested review from lehins and perturbing June 16, 2026 18:10
@ch1bo ch1bo marked this pull request as ready for review June 16, 2026 18:10
@ch1bo ch1bo force-pushed the ch1bo/cardano-crypto-leios branch from bf92c7d to 780e347 Compare June 17, 2026 07:22
@ch1bo ch1bo force-pushed the ch1bo/cardano-crypto-leios branch 5 times, most recently from 745de18 to 38a3b98 Compare June 18, 2026 19:24

@lehins lehins left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consistency is one of the most important parts in software development. It is important to use consistent dependencies as the rest of the project, in this case cardano-base repo being that project.

Comment thread cardano-crypto-leios/cardano-crypto-leios.cabal Outdated
Comment thread cardano-crypto-leios/cardano-crypto-leios.cabal Outdated
Comment thread cardano-crypto-leios/cardano-crypto-leios.cabal Outdated
Comment thread cardano-crypto-leios/src/Cardano/Crypto/Leios.hs Outdated
Comment thread cardano-crypto-leios/src/Cardano/Crypto/Leios.hs Outdated
Comment thread cardano-crypto-leios/src/Cardano/Crypto/Leios.hs
Comment thread cardano-crypto-leios/src/Cardano/Crypto/Leios.hs Outdated
Comment thread cardano-crypto-leios/src/Cardano/Crypto/Leios.hs Outdated
Comment thread cardano-crypto-leios/src/Cardano/Crypto/Leios.hs
Comment thread cardano-crypto-leios/src/Cardano/Crypto/Leios.hs Outdated
@ch1bo ch1bo requested a review from lehins June 21, 2026 18:07
@ch1bo ch1bo linked an issue Jun 25, 2026 that may be closed by this pull request
7 tasks

@lehins lehins left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More feedback, none of which is terribly critical and we can fix it up later if needed.

Comment thread cardano-crypto-leios/src/Cardano/Crypto/Leios.hs Outdated
Comment thread cardano-crypto-leios/src/Cardano/Crypto/Leios.hs Outdated
Comment thread cardano-crypto-leios/src/Cardano/Crypto/Leios.hs Outdated
Comment thread cardano-crypto-leios/src/Cardano/Crypto/Leios.hs
Comment thread cardano-crypto-leios/src/Cardano/Crypto/Leios.hs Outdated
Comment thread cardano-crypto-leios/src/Cardano/Crypto/Leios.hs Outdated
Comment thread cardano-crypto-leios/src/Cardano/Crypto/Leios.hs Outdated
Comment thread cardano-crypto-leios/src/Cardano/Crypto/Leios.hs Outdated
Comment thread cardano-crypto-leios/src/Cardano/Crypto/Leios.hs
Comment thread cardano-crypto-leios/src/Cardano/Crypto/Leios.hs
@ch1bo ch1bo force-pushed the ch1bo/cardano-crypto-leios branch 2 times, most recently from 9bfac4c to 8989c05 Compare June 26, 2026 20:55
@ch1bo ch1bo force-pushed the ch1bo/cardano-crypto-leios branch 2 times, most recently from 28947bd to 986f69f Compare June 26, 2026 21:17
ch1bo added 21 commits June 29, 2026 08:17
The golden test compares 'cardano-crypto-leios/test/golden/LeiosCert'
byte-for-byte against the hex-dump output of 'encodeWithIndex'. Without
this attribute, the default Windows 'core.autocrlf=true' translates LF
to CRLF on checkout and the comparison fails, even though the file is
committed with LF endings.
These were needed/useful in the cardano-ledger-dijkstra integration
This avoids redundant import warnings on newer GHC versions
- Replace indexed-hex golden file with raw binary; drop the .gitattributes
  LF pin and the base16-bytestring dep.
- Extract InsufficientWeight's named fields into a WeightMismatch record so
  no constructor has partial accessors; drop -Wno-partial-fields and
  DuplicateRecordFields.
- Introduce strict LeiosVoter to replace the lazy (Weight, VerKey) tuple
  in Committee; switch BLSAggregationFailed to Text; tighten verifier
  accumulator strictness.
- Don't export field selectors that can easily overlap.
Replaces the list-of-bytes construction in 'mkBitField' (and the
'BS.unpack' list comprehension in 'bitFieldMembers') with direct
mutable 'ByteArray' operations from 'Data.Primitive.ByteArray', so
the ByteArray-backed representation isn't undone by intermediate
list allocations. Wire encode/decode stay zero-copy via the existing
SBS aliasing; on-wire bytes are unchanged (golden test confirms).
'enforceSize' from cardano-binary only accepts definite-length lists,
which would reject any producer that emits the 2-element outer array
of a Leios certificate as an indefinite-length CBOR array. Switch to
'decodeListLenOrIndef' + 'matchSize' for the definite branch and a
trailing 'decodeBreakOr' for the indefinite branch.

Adds a QuickCheck property that round-trips through a hand-rolled
indefinite-length encoding to lock the new behaviour in.
Section headers move into the export list; the body's '-- *' /
'-- **' markers are removed to avoid double sections in Haddock.
Doc strings stay at the definitions. 'mkBitField' and
'bitFieldMembers' are no longer exported — they're only callable
through 'aggregateLeiosCert' / 'verifyLeiosCert', which the tests
exercise transitively. Adversarial tests still have the
'bitFieldFromBytes' / 'bitFieldToBytes' wire helpers.
'aggregateLeiosCert' was binding 'entries = Map.toAscList contributions'
just to feed two separate consumers: a range-check over keys and a
signature-aggregation over values. Each consumer can take its
Map.keys / Map.elems input directly, which lets list fusion eliminate
the intermediates per pass.

Adds source/destination type applications to every fromIntegral in the
package (src + test + testlib) so the conversion's intent is explicit
at the call site and silent type-changes during refactors are caught.
This should be a typical size (> 99% of current stake distribution)
Several small changes on error types and generators
This should avoid conflicts with existing or currently being created
types (Peras)
While this is less defensive, it avoids an overflow going unnoticed.
@ch1bo ch1bo force-pushed the ch1bo/cardano-crypto-leios branch from 986f69f to feba49c Compare June 29, 2026 06:17
@ch1bo ch1bo enabled auto-merge June 29, 2026 06:38
@ch1bo ch1bo merged commit 0fea263 into master Jun 29, 2026
27 checks passed
@ch1bo ch1bo deleted the ch1bo/cardano-crypto-leios branch June 29, 2026 06:45
@lehins lehins mentioned this pull request Jun 29, 2026
6 tasks
ch1bo added a commit to IntersectMBO/ouroboros-consensus that referenced this pull request Jul 3, 2026
Replaces mocked certificates with what was specified in CIP-164.

Depends on a new `cardano-crypto-leios` package that only holds the
`LeiosCert` IntersectMBO/cardano-base#670 and
the cardano-ledger which integrates that into the `DijkstraBlockBody`
IntersectMBO/cardano-ledger#5872

Explores code paths of certificate validation in the `applyBlock` /
block validation part of consensus.

Aggregates votes whenever added to the `LeiosVoteState` and creates a
certificate when exceeding the (hard-coded) threshold.

The forge loop gets the certificate from the `LeiosVoteState` and uses
it to decide whether we can build a `CertRB`.

TODO:
- [ ] Must not use committee of different epoch when creating block.
Either forecast (and re-aggregate the cert) or just index certificates
in the vote state by epoch and query using the current one.
- Left a FIXME in `VoteState.addVote` which will by extension affect
`queryCert`
- [x] Should clean up the many type class methods
- maybe anticipating an upcoming `applyBlock :: ... -> m (Either
(LedgerErr l) (LedgerResult l (l DiffMK))`
- [ ] Replace hacky integration with merges from `master` branches once
the `11.1` work was integrated (= Blocked by `11.1` release now.. or we
do that cleanup later)
  - [x] Use integrated `master` for `ouroboros-network`
  - [x] Use integrated `master` for `cardano-ledger`
  - [ ] Use integrated `master` for `ouroboros-consensus`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Prototype Voting

2 participants