https://github.com/cwgoes/tm-proposer-idris
Formalization of Tendermint proposer election properties
https://github.com/cwgoes/tm-proposer-idris
blockchain dlt formal-verification idris tendermint
Last synced: 3 months ago
JSON representation
Formalization of Tendermint proposer election properties
- Host: GitHub
- URL: https://github.com/cwgoes/tm-proposer-idris
- Owner: cwgoes
- License: gpl-3.0
- Created: 2018-12-15T14:19:38.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-01-13T17:59:02.000Z (over 6 years ago)
- Last Synced: 2025-01-01T22:19:09.818Z (5 months ago)
- Topics: blockchain, dlt, formal-verification, idris, tendermint
- Language: Idris
- Size: 55.7 KB
- Stars: 15
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
### Summary
Formal verification of fairness of the [Tendermint](https://github.com/tendermint/tendermint) proposer election algorithm in the proof assistant [Idris](https://idris-lang.org).
In particular, the Idris source in this repository proves that maximally strict bounds on stake-proportionality of proposer election hold over an epoch of any length with no power changes by inhabiting the following type:
```idris
fairlyProportional :
(idA : ProposerId) -> (idB : ProposerId) ->
(wA : ProposerWeight) -> (wB : ProposerWeight) ->
(pA : ProposerPriority) -> (pB: ProposerPriority) ->
(n : Nat) ->
(wA >= 0 = True) -> (wB >= 0 = True) ->
(abs(pA - pB) <= (wA + wB) = True) ->
((count idA (snd (incrementElectMany n ((idA, wA, pA), (idB, wB, pB)))))
>= ((n * (wA / (wA + wB))) - 1) = True,
(count idA (snd (incrementElectMany n ((idA, wA, pA), (idB, wB, pB)))))
<= ((n * (wA / (wA + wB))) + 1) = True)
```where `incrementElectMany` repeats the proposer-election function and returns the list of elected proposers.
In English, this proof could be read as "a validator, in a sequence of proposer elections where no other power
changes take place, proposes no fewer blocks than the total blocks in the epoch multiplied by its fraction of stake
less one, and proposes no more blocks than the total blocks in the epoch multiplied by its fraction of stake plus one".As epochs can be as short as one block (for which one proposer must be chosen), this is the strictest possible fairness criterion.
The requisite initial bound on the difference in proposer priority is the reason for [this pull request](https://github.com/tendermint/tendermint/pull/3049).
### Caveats
- You must trust that the type theory used by Idris ([paper](https://pdfs.semanticscholar.org/1407/220ca09070233dca256433430d29e5321dc2.pdf)) is sound.
- At present, this proof only covers the two-validator case - a reduction from the n-validator case is planned.
- This fairness criterion only holds over epochs with no validator power (weight) changes.
- The Idris standard library does not implement proofs of standard field laws for arithmetic operations over integers, so these are [assumed to hold](src/Types.idr).
In practice standard library proofs wouldn't be helpful anyways since the actual implementation is in Golang, not Idris.
- This constitutes a proof of algorithmic correctness, which is not the same thing as implementational correctness - the Golang
code could have incorrect optimizations, integer overflow/underflow, etc.### Usage
To check that the verified properties hold, run:
```bash
make check
```To open up a REPL and play around with proof components, run:
```bash
make
```Or to read the logic yourself, open [Main.idr](src/Main.idr).