| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Test.Consensus.Committee.WFALS.Model
Description
Model implementing committee selection based on the Fait Accompli scheme.
This is based on the paper:
Peter Gaži, Aggelos Kiayias, and Alexander Russell. 2023. Fait Accompli Committee Selection: Improving the Size-Security Tradeoff of Stake-Based Committees. In Proceedings of the 2023 ACM SIGSAC Conference on Computer and Communications Security (CCS '23). Association for Computing Machinery, New York, NY, USA, 845–858. https://doi.org/10.1145/3576915.3623194
Synopsis
- data StakeRole
- data StakeType
- data family Stake ∷ StakeRole → StakeType → Type
- class (Num stake, Ord stake) ⇒ IsStake stake where
- stakeToRational ∷ stake → Rational
- rationalToStake ∷ Rational → stake
- coerceStake ∷ ∀ stake' stake. (IsStake stake, IsStake stake') ⇒ stake → stake'
- adjustStake ∷ ∀ stake' stake. (IsStake stake, IsStake stake') ⇒ (Rational → Rational) → stake → stake'
- type SeatIndex = Natural
- type VoterId = String
- type family NumSeats (st ∷ StakeType)
- type StakeDistr (sr ∷ StakeRole) (st ∷ StakeType) = Map VoterId (Stake sr st)
- stakeDistrToDecreasingStakes ∷ ∀ (sr ∷ StakeRole) (st ∷ StakeType). IsStake (Stake sr st) ⇒ StakeDistr sr st → [(VoterId, Stake sr st)]
- stakeDistrTotalStake ∷ ∀ (sr ∷ StakeRole) (st ∷ StakeType). IsStake (Stake sr st) ⇒ StakeDistr sr st → Stake sr st
- weightedFaitAccompliWith ∷ (NumSeats 'Residual → StakeDistr 'Ledger 'Residual → StakeDistr 'Weight 'Residual) → NumSeats 'Global → StakeDistr 'Ledger 'Global → (StakeDistr 'Weight 'Persistent, StakeDistr 'Weight 'Residual)
- weightedFaitAccompliPersistentSeats ∷ NumSeats 'Global → StakeDistr 'Ledger 'Global → (StakeDistr 'Weight 'Persistent, NumSeats 'Residual, StakeDistr 'Ledger 'Residual)
- weightedFaitAccompliThreshold ∷ NumSeats 'Global → SeatIndex → Stake 'Ledger 'Global → Stake 'Ledger 'Cumulative → Bool
- localSortition ∷ ∀ (st ∷ StakeType) rng. (IsStake (Stake 'Ledger st), IsStake (Stake 'Weight st), Integral (NumSeats st), RandomGen rng) ⇒ rng → NumSeats st → StakeDistr 'Ledger st → StakeDistr 'Weight st
- makeStakeDistrVotingGlobal ∷ StakeDistr 'Weight 'Persistent → StakeDistr 'Weight 'Residual → StakeDistr 'Weight 'Global
Auxiliary types
The role of a given stake.
NOTE: used mostly to better document type signatures in this module.
Extra type information about a given stake.
NOTE: used mostly to better document type signatures in this module.
Constructors
| Global | |
| Persistent | |
| Residual | |
| Cumulative |
data family Stake ∷ StakeRole → StakeType → Type Source #
Stake types annotated with their role and type information
Instances
class (Num stake, Ord stake) ⇒ IsStake stake where Source #
Type class with operations needed over stakes
Instances
| IsStake (Stake 'Ledger 'Cumulative) Source # | |
Defined in Test.Consensus.Committee.WFALS.Model Methods stakeToRational ∷ Stake 'Ledger 'Cumulative → Rational Source # rationalToStake ∷ Rational → Stake 'Ledger 'Cumulative Source # | |
| IsStake (Stake 'Ledger 'Global) Source # | |
Defined in Test.Consensus.Committee.WFALS.Model | |
| IsStake (Stake 'Ledger 'Persistent) Source # | |
Defined in Test.Consensus.Committee.WFALS.Model Methods stakeToRational ∷ Stake 'Ledger 'Persistent → Rational Source # rationalToStake ∷ Rational → Stake 'Ledger 'Persistent Source # | |
| IsStake (Stake 'Ledger 'Residual) Source # | |
Defined in Test.Consensus.Committee.WFALS.Model | |
| IsStake (Stake 'Weight 'Global) Source # | |
Defined in Test.Consensus.Committee.WFALS.Model | |
| IsStake (Stake 'Weight 'Persistent) Source # | |
Defined in Test.Consensus.Committee.WFALS.Model Methods stakeToRational ∷ Stake 'Weight 'Persistent → Rational Source # rationalToStake ∷ Rational → Stake 'Weight 'Persistent Source # | |
| IsStake (Stake 'Weight 'Residual) Source # | |
Defined in Test.Consensus.Committee.WFALS.Model | |
coerceStake ∷ ∀ stake' stake. (IsStake stake, IsStake stake') ⇒ stake → stake' Source #
Retag a stake with a different origin and type.
NOTE: type parameters are arranged so that one can use type applications to specify the parameters of the resulting type first.
adjustStake ∷ ∀ stake' stake. (IsStake stake, IsStake stake') ⇒ (Rational → Rational) → stake → stake' Source #
Adjust a stake via a function on rationals
type family NumSeats (st ∷ StakeType) Source #
Number of seats in the committee
Instances
| type NumSeats 'Global Source # | |
Defined in Test.Consensus.Committee.WFALS.Model | |
| type NumSeats 'Persistent Source # | |
Defined in Test.Consensus.Committee.WFALS.Model | |
| type NumSeats 'Residual Source # | |
Defined in Test.Consensus.Committee.WFALS.Model | |
Stake Distribution
type StakeDistr (sr ∷ StakeRole) (st ∷ StakeType) = Map VoterId (Stake sr st) Source #
Stake distribution mapping voters to their stakes
stakeDistrToDecreasingStakes ∷ ∀ (sr ∷ StakeRole) (st ∷ StakeType). IsStake (Stake sr st) ⇒ StakeDistr sr st → [(VoterId, Stake sr st)] Source #
View a stake distribution as a non-increasing list of stakes
stakeDistrTotalStake ∷ ∀ (sr ∷ StakeRole) (st ∷ StakeType). IsStake (Stake sr st) ⇒ StakeDistr sr st → Stake sr st Source #
Get the total stake in a stake distribution
Fait Accompli Committee Selection
weightedFaitAccompliWith Source #
Arguments
| ∷ (NumSeats 'Residual → StakeDistr 'Ledger 'Residual → StakeDistr 'Weight 'Residual) | Fallback function for non-persistent seats |
| → NumSeats 'Global | Total number of seats |
| → StakeDistr 'Ledger 'Global | Stake distribution |
| → (StakeDistr 'Weight 'Persistent, StakeDistr 'Weight 'Residual) | Selected persistent and non-persistent seats with their corresponding voting stakes |
Weighted Fait Accompli committee selection with a fallback mechanism.
This is mostly just plumbing to connect the result of
weightedFaitAccompliPersistentSeats with a given fallback scheme.
weightedFaitAccompliPersistentSeats ∷ NumSeats 'Global → StakeDistr 'Ledger 'Global → (StakeDistr 'Weight 'Persistent, NumSeats 'Residual, StakeDistr 'Ledger 'Residual) Source #
First step of the weighted Fait Accompli committee selection.
This step selects the persistent seats deterministically via the weighted Fait Accompli threshold, and returns the remaining stake distribution for the non-persistent seats selection.
weightedFaitAccompliThreshold Source #
Arguments
| ∷ NumSeats 'Global | Total number of seats |
| → SeatIndex | Voter seat index (0-based) |
| → Stake 'Ledger 'Global | Voter ledger stake |
| → Stake 'Ledger 'Cumulative | Cumulative ledger stake from the right (including the current voter stake) |
| → Bool | Whether the voter qualifies for a persistent seat |
Weighted Fait Accompli threshold for persistent seats
For more details, see (Section 4, Figure 7) of the paper: https://eprint.iacr.org/2023/1273.pdf
Arguments
| ∷ ∀ (st ∷ StakeType) rng. (IsStake (Stake 'Ledger st), IsStake (Stake 'Weight st), Integral (NumSeats st), RandomGen rng) | |
| ⇒ rng | Random number generator |
| → NumSeats st | Expected number of non-persistent seats |
| → StakeDistr 'Ledger st | Non-persistent stake distribution candidate (not necessarily normalized) |
| → StakeDistr 'Weight st | Selected non-persistent seats with their correspoinding voting stakes |
Local sortition fallback
makeStakeDistrVotingGlobal ∷ StakeDistr 'Weight 'Persistent → StakeDistr 'Weight 'Residual → StakeDistr 'Weight 'Global Source #
Combine the resulting persistent and non-persistent stake distributions into a single global one