| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
Cardano.Crypto.Leios
Description
Cryptographic data types and operations used in Leios per CIP-164. Leios
uses BLS12-381 MinSig as its signature scheme and defines a LeiosCert that
can be included into blocks. This module deliberately not includes a
LeiosVote because the vote itself is not an artifact that is on-chain.
Synopsis
- type LeiosDSIGN = BLS12381MinSigDSIGN
- type LeiosSigningKey = SignKeyDSIGN LeiosDSIGN
- type LeiosVerificationKey = VerKeyDSIGN LeiosDSIGN
- type LeiosSignature = SigDSIGN LeiosDSIGN
- leiosSignContext ∷ BLS12381SignContext
- leiosSignatureSize ∷ Word
- leiosSignatureToBytes ∷ LeiosSignature → ByteString
- type Weight = Rational
- newtype LeiosVoterId = LeiosVoterId {}
- encodeLeiosVoterId ∷ LeiosVoterId → Encoding
- decodeLeiosVoterId ∷ Decoder s LeiosVoterId
- data LeiosVoter = LeiosVoter {}
- newtype LeiosCommittee = LeiosCommittee {}
- leiosCommitteeSize ∷ LeiosCommittee → Int
- resolveLeiosVoter ∷ LeiosCommittee → LeiosVoterId → Maybe LeiosVoter
- getLeiosVoterId ∷ HasCallStack ⇒ LeiosVerificationKey → LeiosCommittee → Maybe LeiosVoterId
- data LeiosCert = LeiosCert {}
- encodeLeiosCert ∷ LeiosCert → Encoding
- decodeLeiosCert ∷ Decoder s LeiosCert
- data AggregationError
- aggregateLeiosCert ∷ LeiosCommittee → Map LeiosVoterId LeiosSignature → Either AggregationError LeiosCert
- data VerificationError
- verifyLeiosCert ∷ SignableRepresentation msg ⇒ LeiosCommittee → Weight → msg → LeiosCert → Either VerificationError Weight
- data BitField
- encodeBitField ∷ BitField → Encoding
- decodeBitField ∷ Decoder s BitField
Cryptographic primitives
type LeiosDSIGN = BLS12381MinSigDSIGN Source #
type LeiosSigningKey = SignKeyDSIGN LeiosDSIGN Source #
type LeiosSignature = SigDSIGN LeiosDSIGN Source #
leiosSignContext ∷ BLS12381SignContext Source #
The BLS12-381 MinSig proof-of-possession ciphersuite DST used by Leios,
per CIP-164. Pass this as the ContextDSIGN to signDSIGN / verifyDSIGN.
leiosSignatureSize ∷ Word Source #
Size of a Leios signature in the chosen signature scheme.
leiosSignatureToBytes ∷ LeiosSignature → ByteString Source #
Get the bytes of a Leios signature.
Voting committee
type Weight = Rational Source #
A weight assigned to a committee voter, normalised so the total over a
committee sums to 1. Threshold checks in verifyLeiosCert are against
this same scale.
newtype LeiosVoterId Source #
A committee member's seat index. The index is the voter's position in
leiosCommitteeVoters and determines its bit in the LeiosCert leiosCertSigners
bitfield (MSB-first within each byte, so voter i ↔ bit 7-(i mod 8) of
byte i `div` 8).
Constructors
| LeiosVoterId | |
Fields | |
Instances
encodeLeiosVoterId ∷ LeiosVoterId → Encoding Source #
Plain CBOR encoder for LeiosVoterId.
decodeLeiosVoterId ∷ Decoder s LeiosVoterId Source #
Plain CBOR decoder for LeiosVoterId.
data LeiosVoter Source #
A single seat in a LeiosCommittee: a voter's normalised weight paired with
its BLS verification key.
Constructors
| LeiosVoter | |
Fields | |
Instances
| Generic LeiosVoter Source # | |
Defined in Cardano.Crypto.Leios Associated Types type Rep LeiosVoter ∷ Type → Type # | |
| Show LeiosVoter Source # | |
Defined in Cardano.Crypto.Leios Methods showsPrec ∷ Int → LeiosVoter → ShowS # show ∷ LeiosVoter → String # showList ∷ [LeiosVoter] → ShowS # | |
| NFData LeiosVoter Source # | |
Defined in Cardano.Crypto.Leios Methods rnf ∷ LeiosVoter → () # | |
| Eq LeiosVoter Source # | |
Defined in Cardano.Crypto.Leios | |
| NoThunks LeiosVoter Source # | |
Defined in Cardano.Crypto.Leios | |
| type Rep LeiosVoter Source # | |
Defined in Cardano.Crypto.Leios type Rep LeiosVoter = D1 ('MetaData "LeiosVoter" "Cardano.Crypto.Leios" "cardano-crypto-leios-0.1.0.0-inplace" 'False) (C1 ('MetaCons "LeiosVoter" 'PrefixI 'True) (S1 ('MetaSel ('Just "voterWeight") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Weight) :*: S1 ('MetaSel ('Just "voterVKey") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 LeiosVerificationKey))) | |
newtype LeiosCommittee Source #
The voting committee for a Leios epoch: an ordered vector of
LeiosVoter seats.
Ixition determines the voter's LeiosVoterId and its bit in the certificate's
bitfield, so callers must keep the order stable between construction and
verification of any cert.
This package intentionally does not provide committee selection — sampling
voters from the active stake distribution lives in consensus/ledger.
However, callers are responsible for ensuring that every voter's BLS
proof-of-possession has been verified before a LeiosCommittee value is built;
verifyLeiosCert and aggregateLeiosCert both rely on this invariant to
skip per-key PoP checks (they use uncheckedAggregateVerKeysDSIGN /
aggregateSigsDSIGN under the hood). Passing in unchecked keys defeats
the security of the aggregate signature.
Constructors
| LeiosCommittee | |
Fields | |
Instances
| Generic LeiosCommittee Source # | |
Defined in Cardano.Crypto.Leios Associated Types type Rep LeiosCommittee ∷ Type → Type # | |
| Show LeiosCommittee Source # | |
Defined in Cardano.Crypto.Leios Methods showsPrec ∷ Int → LeiosCommittee → ShowS # show ∷ LeiosCommittee → String # showList ∷ [LeiosCommittee] → ShowS # | |
| NFData LeiosCommittee Source # | |
Defined in Cardano.Crypto.Leios Methods rnf ∷ LeiosCommittee → () # | |
| Eq LeiosCommittee Source # | |
Defined in Cardano.Crypto.Leios Methods (==) ∷ LeiosCommittee → LeiosCommittee → Bool # (/=) ∷ LeiosCommittee → LeiosCommittee → Bool # | |
| NoThunks LeiosCommittee Source # | |
Defined in Cardano.Crypto.Leios | |
| type Rep LeiosCommittee Source # | |
Defined in Cardano.Crypto.Leios type Rep LeiosCommittee = D1 ('MetaData "LeiosCommittee" "Cardano.Crypto.Leios" "cardano-crypto-leios-0.1.0.0-inplace" 'True) (C1 ('MetaCons "LeiosCommittee" 'PrefixI 'True) (S1 ('MetaSel ('Just "leiosCommitteeVoters") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Vector LeiosVoter)))) | |
leiosCommitteeSize ∷ LeiosCommittee → Int Source #
Number of seats in the committee.
resolveLeiosVoter ∷ LeiosCommittee → LeiosVoterId → Maybe LeiosVoter Source #
Resolve a LeiosVoterId to its LeiosVoter on the LeiosCommittee, or Nothing
if the index is past the committee bound.
getLeiosVoterId ∷ HasCallStack ⇒ LeiosVerificationKey → LeiosCommittee → Maybe LeiosVoterId Source #
Find a voter's LeiosVoterId on the LeiosCommittee by its
LeiosVerificationKey, or Nothing if the key is not on the committee.
If the committee carries duplicate verification keys, returns the smallest
index matching vk (committee selection is expected to deduplicate, but
this module does not enforce it).
Errors if the matching index does not fit in Word16. The wire format of
LeiosCert indexes voters by a 16-bit field, so a committee with more than
2^16 seats is already malformed. NOTE: this partiality could later be
avoided by introducing a smart constructor for LeiosCommittee (or for the
committee-selection step in consensus) that rejects oversized committees
up front.
Leios certificates
A Leios certificate over an endorser block, as specified in CIP-164
Constructors
| LeiosCert | |
Fields | |
Instances
| Generic LeiosCert Source # | |
| Show LeiosCert Source # | |
| NFData LeiosCert Source # | |
Defined in Cardano.Crypto.Leios | |
| Eq LeiosCert Source # | |
| NoThunks LeiosCert Source # | |
| type Rep LeiosCert Source # | |
Defined in Cardano.Crypto.Leios type Rep LeiosCert = D1 ('MetaData "LeiosCert" "Cardano.Crypto.Leios" "cardano-crypto-leios-0.1.0.0-inplace" 'False) (C1 ('MetaCons "LeiosCert" 'PrefixI 'True) (S1 ('MetaSel ('Just "leiosCertSigners") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 BitField) :*: S1 ('MetaSel ('Just "leiosCertSignature") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 LeiosSignature))) | |
Construction
data AggregationError Source #
Constructors
| VoterIdsOutOfBounds (NonEmpty LeiosVoterId) | One or more voter indices in the sigs are past the committee bound. |
| BLSAggregationFailed Text | BLS signature aggregation failed (e.g. malformed input signature). |
Instances
aggregateLeiosCert ∷ LeiosCommittee → Map LeiosVoterId LeiosSignature → Either AggregationError LeiosCert Source #
Build a LeiosCert from the sigs of committee members.
Caller obligations
All signatures must be over the same message. Individual LeiosSignature
values are not verified here, and once aggregated they cannot be told apart.
Feeding signatures cast over different messages produces a LeiosCert that
will silently fail verifyLeiosCert with no indication of which contribution
was wrong.
What this function does
- Range-checks each
LeiosVoterIdagainst the committee. - Encodes the bitfield over the committee and aggregates the input signatures.
This is the only way to construct a LeiosCert from outside the package;
the bitfield layout is an internal wire-format detail.
Verification
data VerificationError Source #
Constructors
| MalformedSigners |
|
| InvalidSignature | The aggregate-BLS verification failed (wrong message, tampered signature, or a bitfield/aggregate mismatch). |
| InsufficientWeight Weight | Sum of signers' weights is below the required threshold. |
Instances
Arguments
| ∷ SignableRepresentation msg | |
| ⇒ LeiosCommittee | |
| → Weight | Minimum signer weight required to accept the cert. |
| → msg | The message the signers signed. |
| → LeiosCert | |
| → Either VerificationError Weight | Total weight of the contributing signers on success. |
Verify a LeiosCert against a LeiosCommittee, a weight threshold, and the
message the signers were supposed to have signed.
Caller obligations
Every voter in the LeiosCommittee must have had its BLS proof-of-possession
verified beforehand (when the committee was selected). verifyLeiosCert
uses uncheckedAggregateVerKeysDSIGN and does not re-check PoPs; passing
in an unchecked committee breaks the security of the aggregate signature.
What this function does
- Decodes the
leiosCertSignersbitfield to the list of contributing voter indices, rejecting too small or big bitfield withMalformedSigners.
- Sums those voters' weights from the committee; short-circuits with
InsufficientWeightif the sum is below the threshold. - Aggregates the contributing verification keys and verifies the
certificate's
leiosCertSignatureagainst the aggregate key overmsg.
Bitfield wire-format helpers
The leiosCertSigners bitfield of a LeiosCert: a ⌈leiosCommitteeSize/8⌉-byte
MSB-first packed-bits representation of which committee voters contributed
to the aggregate signature.
A 'newtype' wrapper around ByteArray so type signatures throughout the
aggregate / verify path say what they're working on, and so the on-wire
form cannot be accidentally confused with arbitrary bytes.