@@ -75,8 +75,14 @@ record Endorsement : Type where
7575
7676postulate
7777 Nullable : Type → Type
78+ unwrap : ∀ {a} → Nullable a → Maybe a
7879
7980{-# COMPILE GHC Nullable = type Nullable #-}
81+ {-# FOREIGN GHC
82+ unwrap' :: () -> Nullable a -> Maybe a
83+ unwrap' _ (Nullable x) = x
84+ #-}
85+ {-# COMPILE GHC unwrap = unwrap' #-}
8086
8187data Event : Type where
8288 Slot : String → SlotNo → Event
@@ -98,13 +104,20 @@ record TraceEvent : Type where
98104
99105{-# COMPILE GHC TraceEvent = data TraceEvent (TraceEvent) #-}
100106
101- module _ (numberOfParties : ℕ) (sutId : ℕ) (stakeDistr : List (Pair String ℕ)) (sl : ℕ) where
107+ module _
108+ (numberOfParties : ℕ)
109+ (sutId : ℕ)
110+ (stakeDistr : List (Pair String ℕ))
111+ (stageLength : ℕ)
112+ (ledgerQuality : ℕ)
113+ (lateIBInclusion : Bool) -- TODO: Pass config and topology instead
114+ where
102115
103116 from-id : ℕ → Fin numberOfParties
104117 from-id n =
105118 case n <? numberOfParties of λ where
106119 (yes p) → #_ n {numberOfParties} {fromWitness p}
107- (no _) → error "Conversion to Fin not possible!"
120+ (no _) → error $ "Conversion to Fin not possible! " ◇ show n ◇ " / " ◇ show numberOfParties
108121
109122 nodePrefix : String
110123 nodePrefix = "node-"
@@ -113,20 +126,26 @@ module _ (numberOfParties : ℕ) (sutId : ℕ) (stakeDistr : List (Pair String
113126 SUT-id = from-id sutId
114127
115128 instance
116- sl -NonZero : NonZero sl
117- sl -NonZero with sl ≟ 0
129+ stageLength -NonZero : NonZero stageLength
130+ stageLength -NonZero with stageLength ≟ 0
118131 ... | yes _ = error "Stage length is 0"
119132 ... | no ¬p = ≢-nonZero ¬p
120133
134+ numberOfParties-NonZero : NonZero numberOfParties
135+ numberOfParties-NonZero with numberOfParties ≟ 0
136+ ... | yes _ = error "Number of parties is 0"
137+ ... | no ¬p = ≢-nonZero ¬p
138+
139+
121140 nodeId : String → Fin numberOfParties
122141 nodeId s with S.readMaybe 10 (S.fromList (drop (S.length nodePrefix) $ S.toList s))
123142 ... | nothing = error ("Unknown node: " ◇ s)
124143 ... | just n = from-id n
125144
126145 open FunTot (completeFin numberOfParties) (maximalFin numberOfParties)
127146
128- sd : TotalMap (Fin numberOfParties) ℕ
129- sd =
147+ stakeDistribution : TotalMap (Fin numberOfParties) ℕ
148+ stakeDistribution =
130149 let (r , l) = fromListᵐ (L.map (λ (x , y) → (nodeId x , y)) stakeDistr)
131150 in case (¿ total r ¿) of λ where
132151 (yes p) → record { rel = r ; left-unique-rel = l ; total-rel = p }
@@ -177,11 +196,16 @@ module _ (numberOfParties : ℕ) (sutId : ℕ) (stakeDistr : List (Pair String
177196 params : Params
178197 params =
179198 record
180- { numberOfParties = numberOfParties
181- ; sutId = SUT-id
182- ; stakeDistribution = sd
183- ; stageLength = sl
184- ; winning-slots = fromList (L.catMaybes $ L.map winningSlot l)
199+ { networkParams =
200+ record
201+ { numberOfParties = numberOfParties
202+ ; ledgerQuality = ledgerQuality
203+ ; stakeDistribution = stakeDistribution
204+ ; stageLength = stageLength
205+ ; lateIBInclusion = lateIBInclusion
206+ }
207+ ; sutId = SUT-id
208+ ; winning-slots = fromList ∘ L.catMaybes $ L.map winningSlot l
185209 }
186210
187211 open import Leios.Short.Trace.Verifier params renaming (verifyTrace to checkTrace)
@@ -190,13 +214,14 @@ module _ (numberOfParties : ℕ) (sutId : ℕ) (stakeDistr : List (Pair String
190214 IB-Blk : InputBlock → Blk
191215 EB-Blk : EndorserBlock → Blk
192216 VT-Blk : List Vote → Blk
217+ RB-Blk : EndorserBlock → Blk
193218
194219 record State : Type where
195220 field refs : AssocList String Blk
196221
197222 instance
198- hhx : Hashable InputBlock (List ℕ)
199- hhx .hash record { header = h } = hash h
223+ Hashable-InputBlock : Hashable InputBlock (List ℕ)
224+ Hashable-InputBlock .hash record { header = h } = hash h
200225
201226 _ = Show-List
202227 _ = Show-×
@@ -210,17 +235,12 @@ module _ (numberOfParties : ℕ) (sutId : ℕ) (stakeDistr : List (Pair String
210235 unquoteDecl Show-EndorserBlockOSig = derive-Show [ (quote EndorserBlockOSig , Show-EndorserBlockOSig) ]
211236 unquoteDecl Show-Blk = derive-Show [ (quote Blk , Show-Blk) ]
212237
213- del : String
214- del = ", "
215-
216- nl : String
217- nl = "\n"
218-
219238 blockRefToNat : AssocList String Blk → String → IBRef
220239 blockRefToNat refs r with refs ⁉ r
221240 ... | just (IB-Blk ib) = hash ib
222241 ... | just (EB-Blk eb) = error $ "IB expected, got EB instead, " ◇ show eb
223242 ... | just (VT-Blk vt) = error $ "IB expected, got VT instead"
243+ ... | just (RB-Blk eb) = error $ "IB expected, got RB instead"
224244 ... | nothing = error $ "IB expected, got nothing (" ◇ r ◇ " / " ◇ show refs ◇ ")"
225245
226246 open State
@@ -292,7 +312,7 @@ module _ (numberOfParties : ℕ) (sutId : ℕ) (stakeDistr : List (Pair String
292312 where
293313 actions : List (Action × LeiosInput ⊎ FFDUpdate)
294314 actions with p ≟ SUT
295- ... | yes _ = (inj₁ (EB-Role-Action (primWord64ToNat s) [] , SLOT)) ∷ []
315+ ... | yes _ = (inj₁ (EB-Role-Action (primWord64ToNat s) [] [] , SLOT)) ∷ []
296316 ... | no _ = []
297317 traceEvent→action l record { message = VTBundleGenerated p i s _ _ vts } =
298318 let vt = map (const tt) (elems vts)
@@ -302,7 +322,13 @@ module _ (numberOfParties : ℕ) (sutId : ℕ) (stakeDistr : List (Pair String
302322 actions with p ≟ SUT
303323 ... | yes _ = (inj₁ (VT-Role-Action (primWord64ToNat s) , SLOT)) ∷ []
304324 ... | no _ = []
305- traceEvent→action l record { message = RBGenerated _ _ _ _ _ _ _ _ } = l , []
325+ traceEvent→action l record { message = RBGenerated p i s _ eb _ _ _ }
326+ with (unwrap eb)
327+ ... | nothing = l , []
328+ ... | just b
329+ with refs l ⁉ BlockRef.id (Endorsement.eb b)
330+ ... | nothing = l , []
331+ ... | just e = record l { refs = (i , e) ∷ refs l } , []
306332
307333 mapAccuml : {A B S : Set } → (S → A → S × B) → S → List A → S × List B
308334 mapAccuml f s [] = s , []
@@ -325,17 +351,17 @@ module _ (numberOfParties : ℕ) (sutId : ℕ) (stakeDistr : List (Pair String
325351 Show-FFDBuffers .show _ = "ffd buffers"
326352
327353 Show-Action : Show Action
328- Show-Action .show (IB-Role-Action x) = "IB-Role-Action " ◇ show x
329- Show-Action .show (EB-Role-Action x _) = "EB-Role-Action " ◇ show x
330- Show-Action .show (VT-Role-Action x) = "VT-Role-Action " ◇ show x
331- Show-Action .show (No-IB-Role-Action x) = "No-IB-Role-Action " ◇ show x
332- Show-Action .show (No-EB-Role-Action x) = "No-EB-Role-Action " ◇ show x
333- Show-Action .show (No-VT-Role-Action x) = "No-VT-Role-Action " ◇ show x
334- Show-Action .show (Ftch-Action x) = "Ftch-Action " ◇ show x
335- Show-Action .show (Slot-Action x) = "Slot-Action " ◇ show x
336- Show-Action .show (Base₁-Action x) = "Base₁-Action " ◇ show x
337- Show-Action .show (Base₂a-Action x _) = "Base₂a-Action " ◇ show x
338- Show-Action .show (Base₂b-Action x) = "Base₂b-Action " ◇ show x
354+ Show-Action .show (IB-Role-Action x) = "IB-Role-Action " ◇ show x
355+ Show-Action .show (EB-Role-Action x _ _) = "EB-Role-Action " ◇ show x
356+ Show-Action .show (VT-Role-Action x) = "VT-Role-Action " ◇ show x
357+ Show-Action .show (No-IB-Role-Action x) = "No-IB-Role-Action " ◇ show x
358+ Show-Action .show (No-EB-Role-Action x) = "No-EB-Role-Action " ◇ show x
359+ Show-Action .show (No-VT-Role-Action x) = "No-VT-Role-Action " ◇ show x
360+ Show-Action .show (Ftch-Action x) = "Ftch-Action " ◇ show x
361+ Show-Action .show (Slot-Action x) = "Slot-Action " ◇ show x
362+ Show-Action .show (Base₁-Action x) = "Base₁-Action " ◇ show x
363+ Show-Action .show (Base₂a-Action x _) = "Base₂a-Action " ◇ show x
364+ Show-Action .show (Base₂b-Action x) = "Base₂b-Action " ◇ show x
339365
340366 instance
341367 Show-NonZero : ∀ {n : ℕ} → Show (NonZero n)
@@ -351,22 +377,26 @@ module _ (numberOfParties : ℕ) (sutId : ℕ) (stakeDistr : List (Pair String
351377 Show-⊎ .show (inj₁ x) = show x
352378 Show-⊎ .show (inj₂ y) = show y
353379
354- unquoteDecl Show-FFDUpdate = derive-Show [ (quote FFDUpdate , Show-FFDUpdate) ]
355- unquoteDecl Show-Params = derive-Show [ (quote Params , Show-Params) ]
356- unquoteDecl Show-Upkeep = derive-Show [ (quote SlotUpkeep , Show-Upkeep) ]
357- unquoteDecl Show-Upkeep-Stage = derive-Show [ (quote StageUpkeep , Show-Upkeep-Stage) ]
358- unquoteDecl Show-LeiosState = derive-Show [ (quote LeiosState , Show-LeiosState) ]
359- unquoteDecl Show-LeiosInput = derive-Show [ (quote LeiosInput , Show-LeiosInput) ]
380+ unquoteDecl Show-FFDUpdate = derive-Show [ (quote FFDUpdate , Show-FFDUpdate) ]
381+ unquoteDecl Show-NetworkParams = derive-Show [ (quote NetworkParams , Show-NetworkParams) ]
382+ unquoteDecl Show-Params = derive-Show [ (quote Params , Show-Params) ]
383+ unquoteDecl Show-Upkeep = derive-Show [ (quote SlotUpkeep , Show-Upkeep) ]
384+ unquoteDecl Show-Upkeep-Stage = derive-Show [ (quote StageUpkeep , Show-Upkeep-Stage) ]
385+ unquoteDecl Show-LeiosState = derive-Show [ (quote LeiosState , Show-LeiosState) ]
386+ unquoteDecl Show-LeiosInput = derive-Show [ (quote LeiosInput , Show-LeiosInput) ]
360387
361388 s₀ : LeiosState
362- s₀ = initLeiosState tt sd tt ((SUT-id , tt) ∷ [])
389+ s₀ = initLeiosState tt stakeDistribution tt ((SUT-id , tt) ∷ [])
363390
364391 format-Err-verifyAction : ∀ {α i s} → Err-verifyAction α i s → Pair String String
365392 format-Err-verifyAction {α} {i} {s} (E-Err e) =
366393 "Invalid Action: Slot " ◇ show α ,
367394 "Parameters: " ◇ show params ◇ nl ◇
368395 "Input: " ◇ show i ◇ nl ◇
369396 "LeiosState: " ◇ show s
397+ where
398+ nl : String
399+ nl = "\n"
370400
371401 format-Err-verifyUpdate : ∀ {μ s} → Err-verifyUpdate μ s → Pair String String
372402 format-Err-verifyUpdate {μ} (E-Err _) = "Invalid Update" , show μ
0 commit comments