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

Formal specification: Ledger construction #65

Merged
merged 31 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
d367dd6
Base chain
yveshauser Nov 1, 2024
813aefe
Most recently stored transactions from mempool
yveshauser Nov 1, 2024
17820dd
Use renaming
yveshauser Nov 1, 2024
2aa7bca
Use renaming
yveshauser Nov 1, 2024
85347d0
Added SUBMIT as Leios input
yveshauser Nov 1, 2024
f36f2a4
Construct ledger
yveshauser Nov 4, 2024
f01c2ca
Key registration functionality
yveshauser Nov 4, 2024
7f3f5a6
Key registration
yveshauser Nov 4, 2024
342f3f7
Minor cleanup
yveshauser Nov 4, 2024
1071822
Readability
yveshauser Nov 4, 2024
c3b4e0a
Readability
yveshauser Nov 4, 2024
ab2dcf0
Separate steps
yveshauser Nov 4, 2024
86e0565
Same as base chain
yveshauser Nov 4, 2024
caa9696
Merge branch 'yveshauser/base-chain' into yveshauser/ledger-construction
yveshauser Nov 4, 2024
01cde61
Formatting
yveshauser Nov 4, 2024
d4117d0
Formatting
yveshauser Nov 4, 2024
022e3b1
Comment
yveshauser Nov 5, 2024
74c8d78
MemPool consists only of most recent txs
yveshauser Nov 5, 2024
3f53588
Merge branch 'yveshauser/base-chain' into yveshauser/ledger-construction
yveshauser Nov 5, 2024
f149894
Notation
yveshauser Nov 5, 2024
b1a2676
Formatting
yveshauser Nov 5, 2024
9674d39
Renaming
yveshauser Nov 5, 2024
2f67eb8
Merge branch 'main' into yveshauser/ledger-construction
yveshauser Nov 5, 2024
16a59ff
Lost when merging
yveshauser Nov 5, 2024
ba49c60
Minor
yveshauser Nov 5, 2024
f500da0
Update formal-spec/Leios/SimpleSpec.agda
yveshauser Nov 6, 2024
50ee30a
Unused import
yveshauser Nov 6, 2024
594a37d
Merge branch 'main' into yveshauser/ledger-construction
yveshauser Nov 6, 2024
ac516e6
Formatting
yveshauser Nov 6, 2024
a1d8f8a
Reverting to previous notation for step relation
yveshauser Nov 11, 2024
4649730
Formal specification: Message fetching (#69)
yveshauser Nov 15, 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
2 changes: 1 addition & 1 deletion formal-spec/Leios/Abstract.agda
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ record LeiosAbstract : Type₁ where
BodyHash VrfPf PrivKey Sig Hash : Type -- these could have been byte strings, but this is safer
⦃ DecEq-Hash ⦄ : DecEq Hash
Vote : Type
vote : Hash Vote
vote : PrivKey Hash Vote
sign : PrivKey Hash Sig
⦃ Hashable-Txs ⦄ : Hashable (List Tx) Hash
L Λ μ :
Expand Down
12 changes: 11 additions & 1 deletion formal-spec/Leios/Base.agda
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

open import Leios.Prelude
open import Leios.Abstract
open import Leios.VRF

module Leios.Base (a : LeiosAbstract) (open LeiosAbstract a) where
module Leios.Base (a : LeiosAbstract) (open LeiosAbstract a) (vrf' : LeiosVRF a)
(let open LeiosVRF vrf') where

open import Leios.Blocks a using (EndorserBlock)

Expand All @@ -12,15 +14,23 @@ StakeDistr = PoolID ⇀ ℕ

record BaseAbstract : Type₁ where
field Cert : Type
VTy : Type
initSlot : VTy → ℕ
V-chkCerts : List PubKey → EndorserBlock × Cert → Type

data Input : Type₁ where
INIT : (EndorserBlock × Cert → Type) → Input
SUBMIT : EndorserBlock ⊎ List Tx → Input -- maybe we have both
FTCH-LDG : Input

data Output : Type where
STAKE : StakeDistr → Output
EMPTY : Output
BASE-LDG : List EndorserBlock → Output

record Functionality : Type₁ where
field State : Type
_⇀⟦_⟧_ : State → Input → State × Output → Type

open Input public
open Output public
60 changes: 57 additions & 3 deletions formal-spec/Leios/Blocks.agda
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,16 @@ mkIBHeader slot id π pKey txs = record { signature = sign pKey (hash h) ; IBHea
getIBRef : ⦃ Hashable IBHeader Hash ⦄ InputBlock IBRef
getIBRef = hash ∘ InputBlock.header

-- TODO
record ibHeaderValid (h : IBHeader) : Type where
record ibBodyValid (b : IBBody) : Type where

ibHeaderValid? : (h : IBHeader) Dec (ibHeaderValid h)
ibHeaderValid? _ = yes record {}

ibBodyValid? : (b : IBBody) Dec (ibBodyValid b)
ibBodyValid? _ = yes record {}

--------------------------------------------------------------------------------
-- Endorser Blocks
--------------------------------------------------------------------------------
Expand Down Expand Up @@ -113,12 +123,25 @@ getEBRef : ⦃ Hashable PreEndorserBlock Hash ⦄ → EndorserBlock → EBRef
getEBRef = hash

-- TODO
-- record ebValid (eb : EndorserBlock) : Type where
record ebValid (eb : EndorserBlock) : Type where
-- field lotteryPfValid : {!!}
-- signatureValid : {!!}
-- ibRefsValid : {!!}
-- ebRefsValid : {!!}

ebValid? : (eb : EndorserBlock) Dec (ebValid eb)
ebValid? _ = yes record {}

--------------------------------------------------------------------------------
-- Votes
--------------------------------------------------------------------------------

-- TODO
record vsValid (vs : List Vote) : Type where

vsValid? : (vs : List Vote) Dec (vsValid vs)
vsValid? _ = yes record {}

--------------------------------------------------------------------------------
-- FFD for Leios Blocks
--------------------------------------------------------------------------------
Expand All @@ -135,11 +158,42 @@ module GenFFD ⦃ _ : IsBlock (List Vote) ⦄ where
ID : Type
ID = ℕ × PoolID

match : Header Body Type
match (ibHeader h) (ibBody b) = bodyHash ≡ hash b
matchIB : IBHeader IBBody Type
matchIB h b = bodyHash ≡ hash b
where open IBHeaderOSig h; open IBBody b

matchIB? : (h : IBHeader) (b : IBBody) Dec (matchIB h b)
matchIB? h b = bodyHash ≟ hash b
where open IBHeaderOSig h; open IBBody b

match : Header Body Type
match (ibHeader h) (ibBody b) = matchIB h b
match _ _ =

headerValid : Header Type
headerValid (ibHeader h) = ibHeaderValid h
headerValid (ebHeader h) = ebValid h
headerValid (vHeader h) = vsValid h

headerValid? : (h : Header) Dec (headerValid h)
headerValid? (ibHeader h) = ibHeaderValid? h
headerValid? (ebHeader h) = ebValid? h
headerValid? (vHeader h) = vsValid? h

bodyValid : Body Type
bodyValid (ibBody b) = ibBodyValid b

bodyValid? : (b : Body) Dec (bodyValid b)
bodyValid? (ibBody b) = ibBodyValid? b

isValid : Header ⊎ Body Type
isValid (inj₁ h) = headerValid h
isValid (inj₂ b) = bodyValid b

isValid? : (x : Header ⊎ Body) Dec (isValid x)
isValid? (inj₁ h) = headerValid? h
isValid? (inj₂ b) = bodyValid? b

-- can we express uniqueness wrt pipelines as a property?
msgID : Header ID
msgID (ibHeader h) = (slotNumber h , producerID h)
Expand Down
4 changes: 4 additions & 0 deletions formal-spec/Leios/FFD.agda
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,8 @@ record FFDAbstract : Type₁ where

record Functionality : Type₁ where
field State : Type
initFFDState : State
stepRel : Input → State → State × Output → Type

open Input public
open Output public
23 changes: 23 additions & 0 deletions formal-spec/Leios/KeyRegistration.agda
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{-# OPTIONS --safe #-}

open import Leios.Prelude
open import Leios.Abstract
open import Leios.VRF

module Leios.KeyRegistration (a : LeiosAbstract) (open LeiosAbstract a)
(vrf : LeiosVRF a) (let open LeiosVRF vrf) where

record KeyRegistrationAbstract : Type₁ where

data Input : Type₁ where
INIT : PubKey → PubKey → PubKey → Input

data Output : Type where
PUBKEYS : List PubKey → Output

record Functionality : Type₁ where
field State : Type
_⇀⟦_⟧_ : State → Input → State × Output → Type

open Input public
open Output public
Loading
Loading