Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CIP-0140? | Ouroboros Peras - Faster Settlement #872

Open
wants to merge 62 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
4f0ce8d
Transfer Peras draft to this repository.
bwbush Aug 2, 2024
5907487
Update CIP-0PRS/CIP-0PRS.lagda.md
bwbush Aug 5, 2024
3a0464e
Update CIP-0PRS/CIP-0PRS.lagda.md
bwbush Aug 5, 2024
88ccf9f
Refactoring of the Peras Agda spec so it is executable.
bwbush Aug 5, 2024
30697cc
Implemented weighted voting.
bwbush Aug 6, 2024
602fe9d
Completed narrative and refactoring of Agda specification.
bwbush Aug 6, 2024
e6ff96c
Tweaked formal specification.
bwbush Aug 6, 2024
a6cc892
Reworked section specifying votes and certificates.
bwbush Aug 6, 2024
a8a69a2
Drafted the abstract.
bwbush Aug 6, 2024
8d09c8f
Added versioning section.
bwbush Aug 6, 2024
55add67
Renamed peras file.
bwbush Aug 6, 2024
1657146
Drafted section motiving Peras.
bwbush Aug 6, 2024
13a5ba7
Fixed metadata YAML for Peras
bwbush Aug 6, 2024
2835f03
Revised settlement terminology.
bwbush Aug 7, 2024
6e8194d
Added blockchain diagram.
bwbush Aug 7, 2024
b8c11a4
Drafted section on node integration.
bwbush Aug 7, 2024
4d05fa0
Added references.
bwbush Aug 7, 2024
df7fdbb
Added citations and reference.
bwbush Aug 7, 2024
fe736df
Drafted the rationale and use-cases sections for Peras.
bwbush Aug 7, 2024
fe5e785
Drafted section on attacks and mitigations.
bwbush Aug 7, 2024
5f30e46
Added table of Kraken settlement times.
bwbush Aug 7, 2024
bf986a2
Drafted section on resource requirements.
bwbush Aug 7, 2024
3467021
Drafted sections on feasible set of protocol parameters.
bwbush Aug 7, 2024
d4dad2e
Drafted path to active section for peras.
bwbush Aug 7, 2024
cf0e474
Moved IOG Agda Prelude to separate repository.
bwbush Aug 8, 2024
de7831a
Added instructions for typechecking the specification.
bwbush Aug 9, 2024
95e3af6
Removed flake lock file for peras.
bwbush Aug 9, 2024
d3b9949
Updated URL for IOG Agda Prelude.
bwbush Aug 9, 2024
360d79a
Added internal hyperlinks.
bwbush Aug 12, 2024
ff8a101
Added paragraph on reproducible builds to versioning section.
bwbush Aug 12, 2024
97d3c22
Renamed `PartyId` to `Party`.
bwbush Aug 12, 2024
44dfd54
Zoomed in on figure where adversarial chain receives boost.
bwbush Aug 12, 2024
e3b5f6f
Reviewed exchange-settlement table.
bwbush Aug 13, 2024
bd6f1bb
Added appendix for statement of proofs.
bwbush Aug 13, 2024
b858d95
Added settlement plots
bwbush Aug 13, 2024
ed3e6d0
Renamed `diagrams/` to `images/`.
bwbush Aug 13, 2024
5942b8f
Redrew figures and proofread.
bwbush Aug 14, 2024
b19792b
Replaced figure with higher-resolution version.
bwbush Aug 15, 2024
fddc24b
Redrew two figures with more realistic total-stake assumptions.
bwbush Aug 26, 2024
3f8f9dd
Added block-progression diagram and explanatory text.
bwbush Aug 28, 2024
1396458
Fixed line break.
bwbush Aug 28, 2024
6ed2bf6
Updated ValidChain definition
yveshauser Sep 10, 2024
8f6e543
Hash, rather than an optional block
yveshauser Sep 10, 2024
0b65501
Dropped adversarial behavior
yveshauser Sep 10, 2024
4921f67
Less imports
yveshauser Sep 10, 2024
7ef0cb8
Only add valid votes and chains to the block-tree
yveshauser Sep 11, 2024
d5081e2
Minor cleanups
yveshauser Sep 12, 2024
01d2e09
Dropped NextSlotNewRound
yveshauser Sep 13, 2024
70c191c
Workarounds for rendering of LaTeX equations in GH MathJax
bwbush Sep 17, 2024
ada84a6
Delay per party and message
yveshauser Sep 20, 2024
7442636
Fix extends
yveshauser Sep 26, 2024
dfb9698
Checked weight for votes
yveshauser Sep 26, 2024
1ad58b4
Removed indirection
yveshauser Oct 3, 2024
065153b
Removed explicit commit hash in reference to peras-design.
bwbush Oct 4, 2024
1c11a2a
Merge pull request #2 from cardano-scaling/peras-formal-spec-update
bwbush Oct 4, 2024
4f8092e
Added figure showing probability of rolling back a boosted block.
bwbush Oct 4, 2024
fbfe38e
Added link to Faster Settlement CPS.
bwbush Oct 4, 2024
c261b78
Tone down "promises" about ALBA certificates
abailly Oct 7, 2024
497f21c
Resolved outstanding review comments.
bwbush Nov 13, 2024
d053321
Made table of contents collapsable
bwbush Nov 13, 2024
8568324
Added missing caption
bwbush Nov 13, 2024
b59c80e
Merge pull request #4 from cardano-scaling/bwbush/peras
bwbush Nov 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CIP-0PRS/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.agdai
1,655 changes: 1,655 additions & 0 deletions CIP-0PRS/README.lagda.md

Large diffs are not rendered by default.

45 changes: 45 additions & 0 deletions CIP-0PRS/iog-prelude/Prelude/Allable.agda
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
module Prelude.Allable where

open import Prelude.Init
open import Prelude.LiteralSequences
open import Prelude.DecEq

record Allable (F : Type ℓ → Type ℓ) : Type (lsuc ℓ) where
field All : ∀ {A} → (A → Type) → F A → Type ℓ

∀∈-syntax = All
∀∈-syntax′ = All
¬∀∈-syntax = λ {A} P → ¬_ ∘ All {A} P
¬∀∈-syntax′ = ¬∀∈-syntax
infix 2 ∀∈-syntax ∀∈-syntax′ ¬∀∈-syntax ¬∀∈-syntax′
syntax ∀∈-syntax P xs = ∀[∈ xs ] P
syntax ∀∈-syntax′ (λ x → P) xs = ∀[ x ∈ xs ] P
syntax ¬∀∈-syntax P xs = ¬∀[∈ xs ] P
syntax ¬∀∈-syntax′ (λ x → P) xs = ¬∀[ x ∈ xs ] P

open Allable ⦃...⦄ public

instance
Allable-List : Allable {ℓ} List
Allable-List .All = L.All.All

Allable-Vec : ∀ {n} → Allable {ℓ} (flip Vec n)
Allable-Vec .All P = V.All.All P

Allable-Maybe : Allable {ℓ} Maybe
Allable-Maybe .All = M.All.All

private
open import Prelude.Decidable

_ : ∀[ x ∈ List ℕ ∋ [ 1 ⨾ 2 ⨾ 3 ] ] (x > 0)
_ = auto

_ : ∀[ x ∈ just 42 ] (x > 0)
_ = auto

_ : ∀[ x ∈ nothing ] (x > 0)
_ = auto

_ : ¬∀[ x ∈ just 0 ] (x > 0)
_ = auto
41 changes: 41 additions & 0 deletions CIP-0PRS/iog-prelude/Prelude/Anyable.agda
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
module Prelude.Anyable where

open import Prelude.Init
open import Prelude.LiteralSequences

record Anyable (F : Type ℓ → Type ℓ) : Type (lsuc ℓ) where
field Any : ∀ {A} → (A → Type) → F A → Type ℓ

∃∈-syntax = Any
∃∈-syntax′ = Any
∄∈-syntax = λ {A} P → ¬_ ∘ Any {A} P
∄∈-syntax′ = ∄∈-syntax
infix 2 ∃∈-syntax ∃∈-syntax′ ∄∈-syntax ∄∈-syntax′
syntax ∃∈-syntax P xs = ∃[∈ xs ] P
syntax ∃∈-syntax′ (λ x → P) xs = ∃[ x ∈ xs ] P
syntax ∄∈-syntax P xs = ∄[∈ xs ] P
syntax ∄∈-syntax′ (λ x → P) xs = ∄[ x ∈ xs ] P

open Anyable ⦃...⦄ public

instance
Anyable-List : Anyable {ℓ} List
Anyable-List .Any = L.Any.Any

Anyable-Vec : ∀ {n} → Anyable {ℓ} (flip Vec n)
Anyable-Vec .Any P = V.Any.Any P

Anyable-Maybe : Anyable {ℓ} Maybe
Anyable-Maybe .Any = M.Any.Any

private
open import Prelude.Decidable

_ : ∃[ x ∈ List ℕ ∋ [ 1 ⨾ 2 ⨾ 3 ] ] (x > 0)
_ = auto

_ : ∃[ x ∈ just 42 ] (x > 0)
_ = auto

_ : ∄[ x ∈ nothing ] (x > 0)
_ = auto
59 changes: 59 additions & 0 deletions CIP-0PRS/iog-prelude/Prelude/AssocList.agda
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
-- Finite maps as association lists
module Prelude.AssocList where

open import Prelude.Init
open import Prelude.DecEq
open import Prelude.Decidable
open import Prelude.Irrelevance
open import Prelude.Default

AssocList : Type → Type → Type
AssocList K V = List (K × V)

mapValues : ∀ {K V V′} → (V → V′) → AssocList K V → AssocList K V′
mapValues f = map (map₂ f)

module _ {K V : Type} where
_∈ᵐ_ _∉ᵐ_ : K → AssocList K V → Type
k ∈ᵐ m = AnyFirst ((k ≡_) ∘ proj₁) m
k ∉ᵐ m = ·¬ (k ∈ᵐ m)

∈ᵐ-irrelevant : ∀ {k m} → Irrelevant (k ∈ᵐ m)
∈ᵐ-irrelevant = AnyFirst-irrelevant λ where refl refl → refl

_∪_ : Op₂ (AssocList K V)
_∪_ = _++_

module _ ⦃ _ : DecEq K ⦄ where

_∈ᵐ?_ = ¿ _∈ᵐ_ ¿²
_∉ᵐ?_ = ¿ _∉ᵐ_ ¿²

_‼_ : ∀ {k : K} (m : AssocList K V) → k ∈ᵐ m → V
m ‼ p = L.First.satisfied p .proj₁ .proj₂

_⁉_ : AssocList K V → K → Maybe V
m ⁉ k with k ∈ᵐ? m
... | yes p = just (m ‼ p)
... | no _ = nothing

module _ {k : K} {m : AssocList K V} where
_∷~_ : k ∈ᵐ m → (V → V) → AssocList K V
p ∷~ f = m [ L.First.index p ]∷= (k , f (m ‼ p))

_∷=_ : k ∈ᵐ m → V → AssocList K V
p ∷= v = p ∷~ const v

module _ ⦃ _ : Default V ⦄ where
modify : K → (V → V) → Op₁ (AssocList K V)
modify k f m = case k ∈ᵐ? m of λ where
(no _) → (k , f def) ∷ m
(yes p) → p ∷= f (m ‼ p)

set : K → V → Op₁ (AssocList K V)
set k v = modify k (const v)

_‼d_ : AssocList K V → K → V
m ‼d k with m ⁉ k
... | nothing = def
... | just v = v
21 changes: 21 additions & 0 deletions CIP-0PRS/iog-prelude/Prelude/Bitmasks.agda
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module Prelude.Bitmasks where

open import Prelude.Init
open import Prelude.Lists
open import Prelude.Default

private variable A : Type

Bitmask : List A → Type
Bitmask xs = Vec Bool (length xs)

select : (xs : List A) → Bitmask xs → List A
select [] [] = []
select (x ∷ xs) (b ∷ bs) = (if b then (x ∷_) else id) (select xs bs)

switchOn switchOff : ∀ {xs : List A} → Index xs → Op₁ (Bitmask xs)
switchOn i bs = bs V.[ i ]≔ true
switchOff i bs = bs V.[ i ]≔ false

-- set default bits to 0
instance Default-Bool = Default-Bool-✖
22 changes: 22 additions & 0 deletions CIP-0PRS/iog-prelude/Prelude/Closures.agda
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
open import Prelude.Init

module Prelude.Closures {A : Type ℓ} (_—→_ : Rel A ℓ) where

private variable x y z : A

-- left-biased
infix 3 _∎
infixr 2 _—→⟨_⟩_ _—↠⟨_⟩_
infix 1 begin_; pattern begin_ x = x
infix -1 _—↠_

data _—↠_ : Rel A ℓ where
_∎ : ∀ x → x —↠ x
_—→⟨_⟩_ : ∀ x → x —→ y → y —↠ z → x —↠ z

—↠-trans : Transitive _—↠_
—↠-trans (x ∎) xz = xz
—↠-trans (_ —→⟨ r ⟩ xy) yz = _ —→⟨ r ⟩ —↠-trans xy yz

_—↠⟨_⟩_ : ∀ x → x —↠ y → y —↠ z → x —↠ z
_—↠⟨_⟩_ _ = —↠-trans
Empty file.
33 changes: 33 additions & 0 deletions CIP-0PRS/iog-prelude/Prelude/DecEq.agda
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
module Prelude.DecEq where

open import Prelude.Init

record DecEq (A : Type) : Type where
field _≟_ : DecidableEquality A

_==_ : A → A → Bool
_==_ = ⌊_⌋ ∘₂ _≟_

≟-refl : ∀ (x : A) → (x ≟ x) ≡ yes refl
≟-refl x with refl , p ← dec-yes (x ≟ x) refl = p
open DecEq ⦃...⦄ public

private variable
n : ℕ
A : Type

instance
DecEq-⊤ : DecEq ⊤
DecEq-⊤ ._≟_ _ _ = yes refl

DecEq-ℕ : DecEq ℕ
DecEq-ℕ = record {Nat}

DecEq-Fin : DecEq (Fin n)
DecEq-Fin = record {Fi}

DecEq-List : ⦃ DecEq A ⦄ → DecEq (List A)
DecEq-List ._≟_ = L.≡-dec _≟_

DecEq-Bin : DecEq Bitstring
DecEq-Bin = record {Bin}
92 changes: 92 additions & 0 deletions CIP-0PRS/iog-prelude/Prelude/Decidable.agda
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
module Prelude.Decidable where

open import Prelude.Init

record _⁇ (P : Type ℓ) : Type ℓ where
constructor ⁇_
field dec : Dec P

auto : ⦃ True dec ⦄ → P
auto ⦃ pr ⦄ = toWitness pr

contradict : ∀ {X : Type} {pr : False dec} → P → X
contradict {pr = pr} = ⊥-elim ∘ toWitnessFalse pr

open _⁇ ⦃ ... ⦄ public

¿_¿ : ∀ (X : Type ℓ) → ⦃ X ⁇ ⦄ → Dec X
¿ _ ¿ = dec

_⁇¹ : ∀ {A : Type ℓ} → (P : Pred A ℓ′) → Type (ℓ ⊔ₗ ℓ′)
P ⁇¹ = ∀ {x} → P x ⁇

dec¹ : ∀ {A : Type ℓ} {P : Pred A ℓ′} → ⦃ P ⁇¹ ⦄ → Decidable¹ P
dec¹ _ = dec

¿_¿¹ : ∀ {A : Type ℓ} (P : Pred A ℓ′) → ⦃ P ⁇¹ ⦄ → Decidable¹ P
¿ _ ¿¹ = dec¹

_⁇² : ∀ {A B : Type ℓ} → (P : REL A B ℓ′) → Type (ℓ ⊔ₗ ℓ′)
_~_ ⁇² = ∀ {x y} → (x ~ y) ⁇

dec² : ∀ {A B : Type ℓ} {_~_ : REL A B ℓ′} → ⦃ _~_ ⁇² ⦄ → Decidable² _~_
dec² _ _ = dec

¿_¿² : ∀ {A B : Type ℓ} (_~_ : REL A B ℓ′) → ⦃ _~_ ⁇² ⦄ → Decidable² _~_
¿ _ ¿² = dec²

infix -100 auto∶_
auto∶_ : ∀ (X : Type ℓ) → ⦃ X ⁇ ⦄ → Type
auto∶_ A = True ¿ A ¿

dec-✓ : ∀ {P : Type ℓ} ⦃ _ : P ⁇ ⦄ (p : P) → ∃ λ p′ → (¿ P ¿ ≡ yes p′)
dec-✓ {P = P} p = dec-yes ¿ P ¿ p

-- ** instances

private variable A : Type ℓ; B : Type ℓ′
instance
Dec-⊥ : ⊥ ⁇
Dec-⊥ .dec = no λ()

Dec-⊤ : ⊤ ⁇
Dec-⊤ .dec = yes tt

Dec-T : T ⁇¹
Dec-T {false} .dec = no λ ()
Dec-T {true} .dec = yes tt

module _ ⦃ _ : A ⁇ ⦄ ⦃ _ : B ⁇ ⦄ where instance
Dec-→ : (A → B) ⁇
Dec-→ .dec = dec →-dec dec
where open import Relation.Nullary

Dec-× : (A × B) ⁇
Dec-× .dec = dec ×-dec dec
where open import Relation.Nullary

Dec-⊎ : (A ⊎ B) ⁇
Dec-⊎ .dec = dec ⊎-dec dec
where open import Relation.Nullary

instance
open import Prelude.DecEq
DecEq⇒Dec : ⦃ DecEq A ⦄ → _≡_ {A = A} ⁇²
DecEq⇒Dec .dec = _ ≟ _

open import Data.Nat using (_≤_; _≤?_)
Dec-≤ : _≤_ ⁇²
Dec-≤ .dec = _ ≤? _

module _ {P : Pred A ℓ} ⦃ _ : P ⁇¹ ⦄ where instance
Dec-Any : L.Any.Any P ⁇¹
Dec-Any .dec = L.Any.any? dec¹ _

Dec-All : L.All.All P ⁇¹
Dec-All .dec = L.All.all? dec¹ _

Dec-MAny : M.Any.Any P ⁇¹
Dec-MAny .dec = M.Any.dec dec¹ _

Dec-MAll : M.All.All P ⁇¹
Dec-MAll .dec = M.All.dec dec¹ _
27 changes: 27 additions & 0 deletions CIP-0PRS/iog-prelude/Prelude/Default.agda
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module Prelude.Default where

open import Prelude.Init

-- Types that have a default value.
record Default (A : Type) : Type where
field def : A
open Default ⦃...⦄ public

private variable A B : Type; n : ℕ

instance
Default-⊤ : Default ⊤
Default-⊤ .def = tt

Default-× : ⦃ Default A ⦄ → ⦃ Default B ⦄ → Default (A × B)
Default-× .def = def , def

Default-List : Default (List A)
Default-List .def = []

Default-Vec : ⦃ Default A ⦄ → Default (Vec A n)
Default-Vec .def = V.replicate _ def

Default-Bool-✖ Default-Bool-✓ : Default Bool
Default-Bool-✖ .def = false
Default-Bool-✓ .def = true
41 changes: 41 additions & 0 deletions CIP-0PRS/iog-prelude/Prelude/FromNat.agda
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
module Prelude.FromNat where

open import Prelude.Init
open import Prelude.LiteralSequences
open import Prelude.Decidable

-- ** dependent version
record Fromℕ (A : Type) (Can : ℕ → Type) : Type where
field fromℕ : (n : ℕ) → ⦃ Can n ⦄ → A
open Fromℕ ⦃...⦄ public
{-# BUILTIN FROMNAT fromℕ #-}

-- ** non-dependent version
Fromℕ′ : Type → Type
Fromℕ′ A = Fromℕ A (const ⊤)

fromℕ′ : ∀ {A} → ⦃ Fromℕ′ A ⦄ → ℕ → A
fromℕ′ n = fromℕ n

record MkFromℕ′ (A : Type) : Type where
constructor fromℕ∶_
field fromℕ : ℕ → A

mkFromℕ′ : ∀ {A} → MkFromℕ′ A → Fromℕ′ A
mkFromℕ′ r .fromℕ n = r .MkFromℕ′.fromℕ n

instance
Fromℕ-Nat = Fromℕ′ ℕ ∋ mkFromℕ′ (fromℕ∶ id)
Fromℕ-Bool = Fromℕ′ Bool ∋ mkFromℕ′ (fromℕ∶ λ where 0 → false; _ → true)
Fromℕ-Bin = Fromℕ′ Bitstring ∋ mkFromℕ′ (record {Bin})
Fromℕ-Float = Fromℕ′ Float ∋ mkFromℕ′ (record {Fl})

Fromℕ-Fin : ∀ {n} → Fromℕ (Fin n) (λ m → True (¿ suc m ≤ n ¿))
Fromℕ-Fin {n} .fromℕ m ⦃ m≤n ⦄ = (Fi.# m) {n} {m≤n}

_ = ℕ ∋ 0
_ = Bool ∋ 0
_ = Bitstring ∋ 0
_ = Float ∋ 0
_ = Fin 1 ∋ 0
_ = Fin 200 ∋ 1
Loading