Skip to content

Commit 30c9396

Browse files
authored
Sample trace (#145)
1 parent 045bb51 commit 30c9396

File tree

4 files changed

+265
-5
lines changed

4 files changed

+265
-5
lines changed

formal-spec/Leios/Base.agda

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module Leios.Base (a : LeiosAbstract) (open LeiosAbstract a) (vrf' : LeiosVRF a)
1010
open import Leios.Blocks a using (EndorserBlock)
1111

1212
StakeDistr : Type
13-
StakeDistr = PoolID ⇀
13+
StakeDistr = TotalMap PoolID
1414

1515
RankingBlock : Type
1616
RankingBlock = These EndorserBlock (List Tx)

formal-spec/Leios/Protocol.agda

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,7 @@ module _ (s : LeiosState) (eb : EndorserBlock) where
9898
allIBRefsKnown = ∀[ ref ∈ fromList ibRefs ] ref ∈ˡ map getIBRef IBs
9999

100100
stake : LeiosState
101-
stake record { SD = SD } = case lookupᵐ? SD id of λ where
102-
(just s) s
103-
nothing 0
101+
stake record { SD = SD } = TotalMap.lookup SD id
104102

105103
module _ (s : LeiosState) where
106104

formal-spec/Leios/Short.lagda.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ data SlotUpkeep : Type where
2727
Base IB-Role EB-Role V-Role : SlotUpkeep
2828
2929
allUpkeep : ℙ SlotUpkeep
30-
allUpkeep = fromList (Base ∷ IB-Role EB-Role V-Role ∷ [])
30+
allUpkeep = (((∅ ∪ ❴ IB-Role ❵) ∪ ❴ EB-Role ❵) ∪ ❴ V-Role ❵) ∪ ❴ Base ❵
3131
```
3232
```agda
3333
open import Leios.Protocol (⋯) SlotUpkeep public

formal-spec/Leios/Trace.agda

Lines changed: 262 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,262 @@
1+
{-# OPTIONS --safe #-}
2+
3+
open import Leios.Prelude
4+
open import Leios.Abstract
5+
open import Leios.SpecStructure
6+
open import Axiom.Set.Properties th
7+
8+
open import Data.Fin
9+
open import Function.Related.TypeIsomorphisms
10+
open import Relation.Binary.Structures
11+
12+
import Data.Sum
13+
14+
open Equivalence
15+
16+
-- The module contains very simple implementations for the functionalities
17+
-- that allow to build examples for traces for the different Leios variants
18+
module Leios.Trace where
19+
20+
instance
21+
htx : Hashable (List ⊤) ⊤
22+
htx = record { hash = λ _ tt }
23+
24+
d-Abstract : LeiosAbstract
25+
d-Abstract =
26+
record
27+
{ Tx =
28+
; PoolID = Fin 1
29+
; BodyHash =
30+
; VrfPf =
31+
; PrivKey =
32+
; Sig =
33+
; Hash =
34+
; Vote =
35+
; vote = λ _ _ tt
36+
; sign = λ _ _ tt
37+
; L = 5
38+
}
39+
40+
open import Leios.VRF d-Abstract
41+
42+
d-VRF : LeiosVRF
43+
d-VRF =
44+
record
45+
{ PubKey =
46+
; vrf = record { isKeyPair = λ _ _ ⊤ ; eval = λ x x₁ x₁ , x ; verify = λ _ _ _ _ ⊤ }
47+
; genIBInput = id
48+
; genEBInput = id
49+
; genVInput = id
50+
; genV1Input = id
51+
; genV2Input = id
52+
}
53+
54+
open import Leios.Blocks d-Abstract
55+
open import Leios.KeyRegistration d-Abstract d-VRF
56+
57+
d-KeyRegistration : KeyRegistrationAbstract
58+
d-KeyRegistration = _
59+
60+
d-KeyRegistrationFunctionality : KeyRegistrationAbstract.Functionality d-KeyRegistration
61+
d-KeyRegistrationFunctionality =
62+
record
63+
{ State =
64+
; _-⟦_/_⟧⇀_ = λ _ _ _ _
65+
}
66+
67+
open import Leios.Base d-Abstract d-VRF
68+
69+
d-Base : BaseAbstract
70+
d-Base =
71+
record
72+
{ Cert =
73+
; VTy =
74+
; initSlot = λ _ 0
75+
; V-chkCerts = λ _ _ true
76+
}
77+
78+
d-BaseFunctionality : BaseAbstract.Functionality d-Base
79+
d-BaseFunctionality =
80+
record
81+
{ State =
82+
; _-⟦_/_⟧⇀_ = λ _ _ _ _
83+
; SUBMIT-total = tt , tt
84+
}
85+
86+
open import Leios.FFD
87+
88+
instance
89+
isb : IsBlock (List ⊤)
90+
isb =
91+
record
92+
{ slotNumber = λ _ 0
93+
; producerID = λ _ zero
94+
; lotteryPf = λ _ tt
95+
}
96+
97+
hhs : {b} Hashable (IBHeaderOSig b) ⊤
98+
hhs = record { hash = λ _ tt }
99+
100+
hpe : Hashable PreEndorserBlock ⊤
101+
hpe = record { hash = λ x tt }
102+
103+
d-FFDFunctionality : FFDAbstract.Functionality ffdAbstract
104+
d-FFDFunctionality =
105+
record
106+
{ State =
107+
; initFFDState = tt
108+
; _-⟦_/_⟧⇀_ = λ _ _ _ _
109+
; FFD-total = tt , tt
110+
}
111+
112+
open import Leios.Voting
113+
114+
d-VotingAbstract : VotingAbstract (Fin 1 × EndorserBlock)
115+
d-VotingAbstract =
116+
record
117+
{ VotingState =
118+
; initVotingState = tt
119+
; isVoteCertified = λ _ _
120+
}
121+
122+
st : SpecStructure 1
123+
st = record
124+
{ a = d-Abstract
125+
; id = zero
126+
; FFD' = d-FFDFunctionality
127+
; vrf' = d-VRF
128+
; sk-IB = tt
129+
; sk-EB = tt
130+
; sk-V = tt
131+
; pk-IB = tt
132+
; pk-EB = tt
133+
; pk-V = tt
134+
; B' = d-Base
135+
; BF = d-BaseFunctionality
136+
; initBaseState = tt
137+
; K' = d-KeyRegistration
138+
; KF = d-KeyRegistrationFunctionality
139+
; va = d-VotingAbstract
140+
}
141+
142+
open SpecStructure st
143+
144+
open import Leios.Short st
145+
146+
open Protocol
147+
148+
sd : TotalMap (Fin 1) ℕ
149+
sd = record
150+
{ rel = singleton (zero , 1)
151+
; left-unique-rel = λ x y
152+
let a = cong proj₂ (from ∈-singleton x)
153+
b = cong proj₂ (from ∈-singleton y)
154+
in trans a (sym b)
155+
; total-rel = total-rel-helper
156+
}
157+
where
158+
total-rel-helper : {a : Fin 1} a ∈ dom (singleton (zero , 1))
159+
total-rel-helper {zero} = to dom∈ (1 , (to ∈-singleton refl))
160+
161+
s₀ : LeiosState
162+
s₀ = initLeiosState tt sd tt
163+
164+
open import Leios.Traces st _-⟦_/_⟧⇀_
165+
166+
-- i) Same slot
167+
168+
ftch-step : s₀ ⇉ s₀
169+
ftch-step = (FTCH-LDG , FTCH-LDG []) , Ftch
170+
171+
trace : s₀ ⇉⋆ s₀
172+
trace = 1 , (s₀ , (ftch-step , refl))
173+
174+
-- ii) Slot transition
175+
176+
t₁ : LeiosState
177+
t₁ = addUpkeep s₀ IB-Role
178+
179+
t₂ : LeiosState
180+
t₂ = addUpkeep t₁ EB-Role
181+
182+
t₃ : LeiosState
183+
t₃ = addUpkeep t₂ V-Role
184+
185+
t₄ : LeiosState
186+
t₄ = addUpkeep t₃ Base
187+
188+
s₁ : LeiosState
189+
s₁ = let open LeiosState t₄ in
190+
record t₄
191+
{ FFDState = tt
192+
; BaseState = tt
193+
; Ledger = []
194+
; IBs = []
195+
; IBHeaders = []
196+
; IBBodies = []
197+
; EBs = []
198+
; Vs = []
199+
; slot = suc slot
200+
; Upkeep =
201+
}
202+
203+
open TotalMap
204+
205+
stake≡1 : TotalMap.lookup (LeiosState.SD s₀) (SpecStructure.id st) ≡ 1
206+
stake≡1 = ∈-rel⇒lookup-≡ (LeiosState.SD s₀) {a = zero} {b = 1} (to ∈-singleton refl)
207+
208+
ib-step : s₀ ⇉ t₁
209+
ib-step = (SLOT , EMPTY) , Roles (IB-Role {π = tt} uk π-IB tt)
210+
where
211+
uk : IB-Role ∉ LeiosState.Upkeep s₀
212+
uk = λ x ∉-∅ x
213+
214+
π-IB : canProduceIB (LeiosState.slot s₀) tt (stake s₀) tt
215+
π-IB rewrite stake≡1 = s≤s z≤n , refl
216+
217+
lem1 : {A} {a : A} {B C : ℙ A} a ∉ B a ∉ C a ∉ B ∪ C
218+
lem1 {_} {_} {B} {C} x y = Data.Sum.[ x , y ] ∘ ∈-∪⁻ {X = B} {Y = C}
219+
220+
lem2 : {A} {a : A} {B : ℙ A} a ∉ B a ∉ ∅ ∪ B
221+
lem2 {_} {_} {B} = lem1 {B = ∅} {C = B} ∉-∅
222+
223+
lem3 : {A} {a b : A} a ≢ b a ∉ singleton b
224+
lem3 = to (¬-cong-⇔ ∈-singleton)
225+
226+
eb-step : t₁ ⇉ t₂
227+
eb-step = (SLOT , EMPTY) , Roles (EB-Role {π = tt} uk π-EB tt)
228+
where
229+
uk : EB-Role ∉ ∅ ∪ ❴ IB-Role ❵
230+
uk = lem2 (lem3 (λ ()))
231+
232+
π-EB : canProduceEB (LeiosState.slot s₀) tt (stake s₀) tt
233+
π-EB rewrite stake≡1 = s≤s z≤n , refl
234+
235+
v-step : t₂ ⇉ t₃
236+
v-step = (SLOT , EMPTY) , Roles (V-Role uk π-V tt)
237+
where
238+
uk : V-Role ∉ (∅ ∪ ❴ IB-Role ❵) ∪ ❴ EB-Role ❵
239+
uk = lem1 (lem2 (lem3 λ ())) (lem3 λ ())
240+
241+
π-V : canProduceV (LeiosState.slot s₀) tt (stake s₀)
242+
π-V rewrite stake≡1 = s≤s z≤n
243+
244+
base-step : t₃ ⇉ t₄
245+
base-step = (SLOT , EMPTY) , Base₂b uk refl tt
246+
where
247+
uk : Base ∉ ((∅ ∪ ❴ IB-Role ❵) ∪ ❴ EB-Role ❵) ∪ ❴ V-Role ❵
248+
uk = lem1 (lem1 (lem2 (lem3 λ ())) (lem3 λ ())) (lem3 λ ())
249+
250+
open IsEquivalence (≡ᵉ-isEquivalence {SlotUpkeep}) renaming (refl to ≡ᵉ-refl)
251+
252+
slot-step : t₄ ⇉ s₁
253+
slot-step = (SLOT , EMPTY) , Slot {rbs = []} {msgs = []} ≡ᵉ-refl tt tt
254+
255+
slot-transition-trace : s₀ ⇉⋆ s₁
256+
slot-transition-trace = 5
257+
, t₁ , ib-step
258+
, t₂ , eb-step
259+
, t₃ , v-step
260+
, t₄ , base-step
261+
, s₁ , slot-step
262+
, refl

0 commit comments

Comments
 (0)