cardano-crypto-leios-0.2.0.0: Crypto primitives for Leios
Safe HaskellSafe-Inferred
LanguageHaskell2010

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

Cryptographic primitives

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 

Instances

Instances details
Generic LeiosVoterId Source # 
Instance details

Defined in Cardano.Crypto.Leios

Associated Types

type Rep LeiosVoterId ∷ Type → Type #

Show LeiosVoterId Source # 
Instance details

Defined in Cardano.Crypto.Leios

NFData LeiosVoterId Source # 
Instance details

Defined in Cardano.Crypto.Leios

Methods

rnf ∷ LeiosVoterId → () #

Eq LeiosVoterId Source # 
Instance details

Defined in Cardano.Crypto.Leios

Ord LeiosVoterId Source # 
Instance details

Defined in Cardano.Crypto.Leios

NoThunks LeiosVoterId Source # 
Instance details

Defined in Cardano.Crypto.Leios

type Rep LeiosVoterId Source # 
Instance details

Defined in Cardano.Crypto.Leios

type Rep LeiosVoterId = D1 ('MetaData "LeiosVoterId" "Cardano.Crypto.Leios" "cardano-crypto-leios-0.2.0.0-inplace" 'True) (C1 ('MetaCons "LeiosVoterId" 'PrefixI 'True) (S1 ('MetaSel ('Just "leiosVoterIndex") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Word16)))

data LeiosVoter Source #

A single seat in a LeiosCommittee: a voter's normalised weight paired with its BLS verification key.

Instances

Instances details
Generic LeiosVoter Source # 
Instance details

Defined in Cardano.Crypto.Leios

Associated Types

type Rep LeiosVoter ∷ Type → Type #

Show LeiosVoter Source # 
Instance details

Defined in Cardano.Crypto.Leios

NFData LeiosVoter Source # 
Instance details

Defined in Cardano.Crypto.Leios

Methods

rnf ∷ LeiosVoter → () #

Eq LeiosVoter Source # 
Instance details

Defined in Cardano.Crypto.Leios

Methods

(==) ∷ LeiosVoter → LeiosVoter → Bool #

(/=) ∷ LeiosVoter → LeiosVoter → Bool #

NoThunks LeiosVoter Source # 
Instance details

Defined in Cardano.Crypto.Leios

type Rep LeiosVoter Source # 
Instance details

Defined in Cardano.Crypto.Leios

type Rep LeiosVoter = D1 ('MetaData "LeiosVoter" "Cardano.Crypto.Leios" "cardano-crypto-leios-0.2.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.

Instances

Instances details
Generic LeiosCommittee Source # 
Instance details

Defined in Cardano.Crypto.Leios

Associated Types

type Rep LeiosCommittee ∷ Type → Type #

Show LeiosCommittee Source # 
Instance details

Defined in Cardano.Crypto.Leios

NFData LeiosCommittee Source # 
Instance details

Defined in Cardano.Crypto.Leios

Methods

rnf ∷ LeiosCommittee → () #

Eq LeiosCommittee Source # 
Instance details

Defined in Cardano.Crypto.Leios

NoThunks LeiosCommittee Source # 
Instance details

Defined in Cardano.Crypto.Leios

type Rep LeiosCommittee Source # 
Instance details

Defined in Cardano.Crypto.Leios

type Rep LeiosCommittee = D1 ('MetaData "LeiosCommittee" "Cardano.Crypto.Leios" "cardano-crypto-leios-0.2.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

data LeiosCert Source #

A Leios certificate over an endorser block, as specified in CIP-164

Instances

Instances details
Generic LeiosCert Source # 
Instance details

Defined in Cardano.Crypto.Leios

Associated Types

type Rep LeiosCert ∷ Type → Type #

Methods

from ∷ LeiosCert → Rep LeiosCert x #

to ∷ Rep LeiosCert x → LeiosCert #

Show LeiosCert Source # 
Instance details

Defined in Cardano.Crypto.Leios

Methods

showsPrec ∷ Int → LeiosCert → ShowS #

show ∷ LeiosCert → String #

showList ∷ [LeiosCert] → ShowS #

NFData LeiosCert Source # 
Instance details

Defined in Cardano.Crypto.Leios

Methods

rnf ∷ LeiosCert → () #

Eq LeiosCert Source # 
Instance details

Defined in Cardano.Crypto.Leios

Methods

(==) ∷ LeiosCert → LeiosCert → Bool #

(/=) ∷ LeiosCert → LeiosCert → Bool #

NoThunks LeiosCert Source # 
Instance details

Defined in Cardano.Crypto.Leios

type Rep LeiosCert Source # 
Instance details

Defined in Cardano.Crypto.Leios

type Rep LeiosCert = D1 ('MetaData "LeiosCert" "Cardano.Crypto.Leios" "cardano-crypto-leios-0.2.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

Instances details
Generic AggregationError Source # 
Instance details

Defined in Cardano.Crypto.Leios

Associated Types

type Rep AggregationError ∷ Type → Type #

Show AggregationError Source # 
Instance details

Defined in Cardano.Crypto.Leios

NFData AggregationError Source # 
Instance details

Defined in Cardano.Crypto.Leios

Methods

rnf ∷ AggregationError → () #

Eq AggregationError Source # 
Instance details

Defined in Cardano.Crypto.Leios

type Rep AggregationError Source # 
Instance details

Defined in Cardano.Crypto.Leios

type Rep AggregationError = D1 ('MetaData "AggregationError" "Cardano.Crypto.Leios" "cardano-crypto-leios-0.2.0.0-inplace" 'False) (C1 ('MetaCons "VoterIdsOutOfBounds" 'PrefixI 'False) (S1 ('MetaSel ('Nothing ∷ Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (NonEmpty LeiosVoterId))) :+: C1 ('MetaCons "BLSAggregationFailed" 'PrefixI 'False) (S1 ('MetaSel ('Nothing ∷ Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text)))

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 LeiosVoterId against 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

leiosCertSigners bitfield is longer than ⌈leiosCommitteeSize/8⌉ bytes.

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

Instances details
Generic VerificationError Source # 
Instance details

Defined in Cardano.Crypto.Leios

Associated Types

type Rep VerificationError ∷ Type → Type #

Show VerificationError Source # 
Instance details

Defined in Cardano.Crypto.Leios

NFData VerificationError Source # 
Instance details

Defined in Cardano.Crypto.Leios

Methods

rnf ∷ VerificationError → () #

Eq VerificationError Source # 
Instance details

Defined in Cardano.Crypto.Leios

type Rep VerificationError Source # 
Instance details

Defined in Cardano.Crypto.Leios

type Rep VerificationError = D1 ('MetaData "VerificationError" "Cardano.Crypto.Leios" "cardano-crypto-leios-0.2.0.0-inplace" 'False) (C1 ('MetaCons "MalformedSigners" 'PrefixI 'False) (U1 ∷ Type → Type) :+: (C1 ('MetaCons "InvalidSignature" 'PrefixI 'False) (U1 ∷ Type → Type) :+: C1 ('MetaCons "InsufficientWeight" 'PrefixI 'False) (S1 ('MetaSel ('Nothing ∷ Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Weight))))

verifyLeiosCert Source #

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

  1. Decodes the leiosCertSigners bitfield to the list of contributing voter indices, rejecting too small or big bitfield with MalformedSigners.
  1. Sums those voters' weights from the committee; short-circuits with InsufficientWeight if the sum is below the threshold.
  2. Aggregates the contributing verification keys and verifies the certificate's leiosCertSignature against the aggregate key over msg.

Bitfield wire-format helpers

newtype BitField Source #

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.

Constructors

BitField 

Instances

Instances details
Generic BitField Source # 
Instance details

Defined in Cardano.Crypto.Leios

Associated Types

type Rep BitField ∷ Type → Type #

Methods

from ∷ BitField → Rep BitField x #

to ∷ Rep BitField x → BitField #

Show BitField Source # 
Instance details

Defined in Cardano.Crypto.Leios

Methods

showsPrec ∷ Int → BitField → ShowS #

show ∷ BitField → String #

showList ∷ [BitField] → ShowS #

NFData BitField Source # 
Instance details

Defined in Cardano.Crypto.Leios

Methods

rnf ∷ BitField → () #

Eq BitField Source # 
Instance details

Defined in Cardano.Crypto.Leios

Methods

(==) ∷ BitField → BitField → Bool #

(/=) ∷ BitField → BitField → Bool #

NoThunks BitField Source # 
Instance details

Defined in Cardano.Crypto.Leios

type Rep BitField Source # 
Instance details

Defined in Cardano.Crypto.Leios

type Rep BitField = D1 ('MetaData "BitField" "Cardano.Crypto.Leios" "cardano-crypto-leios-0.2.0.0-inplace" 'True) (C1 ('MetaCons "BitField" 'PrefixI 'True) (S1 ('MetaSel ('Just "bitFieldBytes") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ByteArray)))