1
- {-# OPTIONS --safe #-}
1
+ {-# OPTIONS --allow-unsolved-metas #-}
2
2
3
3
open import Leios.Prelude
4
4
open import Leios.Abstract
5
5
open import Leios.SpecStructure
6
6
open import Axiom.Set.Properties th
7
7
8
8
open import Data.Nat.Show as N
9
- open import Data.Integer
9
+ open import Data.Integer hiding (_≟_)
10
10
open import Data.String as S using (intersperse)
11
11
open import Function.Related.TypeIsomorphisms
12
12
open import Relation.Binary.Structures
13
13
14
- import Data.Sum
14
+ open import Tactic.Defaults
15
+ open import Tactic.Derive.DecEq
15
16
16
17
open Equivalence
17
18
@@ -21,7 +22,7 @@ open Equivalence
21
22
-- As parameters the module expects
22
23
-- * numberOfParties: the total number of participants
23
24
-- * SUT-id: the number of the SUT (system under test)
24
- module Leios.Foreign. Defaults (numberOfParties : ℕ) (SUT-id : Fin numberOfParties) where
25
+ module Leios.Defaults (numberOfParties : ℕ) (SUT-id : Fin numberOfParties) where
25
26
26
27
instance
27
28
htx : Hashable (List ℕ) String
@@ -90,6 +91,7 @@ d-BaseFunctionality =
90
91
record
91
92
{ State = ⊤
92
93
; _-⟦_/_⟧⇀_ = λ _ _ _ _ → ⊤
94
+ ; Dec-_-⟦_/_⟧⇀_ = ⁇ (yes tt)
93
95
; SUBMIT-total = tt , tt
94
96
}
95
97
@@ -104,7 +106,7 @@ instance
104
106
; lotteryPf = λ _ → tt
105
107
}
106
108
107
- hhs : ∀ {b} → Hashable (IBHeaderOSig b) String
109
+ hhs : Hashable PreIBHeader String
108
110
hhs = record { hash = IBHeaderOSig.bodyHash }
109
111
110
112
hpe : Hashable PreEndorserBlock String
@@ -119,6 +121,8 @@ record FFDState : Type where
119
121
outEBs : List EndorserBlock
120
122
outVTs : List (List Vote)
121
123
124
+ unquoteDecl DecEq-FFDState = derive-DecEq ((quote FFDState , DecEq-FFDState) ∷ [])
125
+
122
126
open GenFFD.Header
123
127
open GenFFD.Body
124
128
open FFDState
@@ -142,22 +146,54 @@ data SimpleFFD : FFDState → FFDAbstract.Input ffdAbstract → FFDAbstract.Outp
142
146
143
147
Fetch : ∀ {s} → SimpleFFD s FFDAbstract.Fetch (FFDAbstract.FetchRes (flushIns s)) (record s { inIBs = [] ; inEBs = [] ; inVTs = [] })
144
148
145
- simple-total : ∀ {s h b} → ∃[ s' ] (SimpleFFD s (FFDAbstract.Send h b) FFDAbstract.SendRes s')
146
- simple-total {s} {ibHeader h} {just (ibBody b)} = record s { outIBs = record {header = h; body = b} ∷ outIBs s} , SendIB
147
- simple-total {s} {ebHeader eb} {nothing} = record s { outEBs = eb ∷ outEBs s} , SendEB
148
- simple-total {s} {vHeader vs} {nothing} = record s { outVTs = vs ∷ outVTs s} , SendVS
149
+ send-total : ∀ {s h b} → ∃[ s' ] (SimpleFFD s (FFDAbstract.Send h b) FFDAbstract.SendRes s')
150
+ send-total {s} {ibHeader h} {just (ibBody b)} = record s { outIBs = record {header = h; body = b} ∷ outIBs s} , SendIB
151
+ send-total {s} {ebHeader eb} {nothing} = record s { outEBs = eb ∷ outEBs s} , SendEB
152
+ send-total {s} {vHeader vs} {nothing} = record s { outVTs = vs ∷ outVTs s} , SendVS
153
+
154
+ send-total {s} {ibHeader h} {nothing} = s , BadSendIB
155
+ send-total {s} {ebHeader eb} {just _} = s , BadSendEB
156
+ send-total {s} {vHeader vs} {just _} = s , BadSendVS
157
+
158
+ fetch-total : ∀ {s} → ∃[ x ] (∃[ s' ] (SimpleFFD s FFDAbstract.Fetch (FFDAbstract.FetchRes x) s'))
159
+ fetch-total {s} = flushIns s , (record s { inIBs = [] ; inEBs = [] ; inVTs = [] } , Fetch)
160
+
161
+ send-complete : ∀ {s h b s'} → SimpleFFD s (FFDAbstract.Send h b) FFDAbstract.SendRes s' → s' ≡ proj₁ (send-total {s} {h} {b})
162
+ send-complete SendIB = refl
163
+ send-complete SendEB = refl
164
+ send-complete SendVS = refl
165
+ send-complete BadSendIB = refl
166
+ send-complete BadSendEB = refl
167
+ send-complete BadSendVS = refl
149
168
150
- simple-total {s} {ibHeader h} {nothing} = s , BadSendIB
151
- simple-total {s} {ebHeader eb} {just _} = s , BadSendEB
152
- simple-total {s} {vHeader vs} {just _} = s , BadSendVS
169
+ fetch-complete₁ : ∀ {s r s'} → SimpleFFD s FFDAbstract.Fetch (FFDAbstract.FetchRes r) s' → s' ≡ proj₁ (proj₂ (fetch-total {s}))
170
+ fetch-complete₁ Fetch = refl
171
+
172
+ fetch-complete₂ : ∀ {s r s'} → SimpleFFD s FFDAbstract.Fetch (FFDAbstract.FetchRes r) s' → r ≡ proj₁ (fetch-total {s})
173
+ fetch-complete₂ Fetch = refl
174
+
175
+ instance
176
+ Dec-SimpleFFD : ∀ {s i o s'} → SimpleFFD s i o s' ⁇
177
+ Dec-SimpleFFD {s} {FFDAbstract.Send h b} {FFDAbstract.SendRes} {s'} with s' ≟ proj₁ (send-total {s} {h} {b})
178
+ ... | yes p rewrite p = ⁇ yes (proj₂ send-total)
179
+ ... | no ¬p = ⁇ no λ x → ⊥-elim (¬p (send-complete x))
180
+ Dec-SimpleFFD {_} {FFDAbstract.Send _ _} {FFDAbstract.FetchRes _} {_} = ⁇ no λ ()
181
+ Dec-SimpleFFD {s} {FFDAbstract.Fetch} {FFDAbstract.FetchRes r} {s'}
182
+ with s' ≟ proj₁ (proj₂ (fetch-total {s}))
183
+ | r ≟ proj₁ (fetch-total {s})
184
+ ... | yes p | yes q rewrite p rewrite q = ⁇ yes (proj₂ (proj₂ (fetch-total {s})))
185
+ ... | yes p | no ¬q = ⁇ no λ x → ⊥-elim (¬q (fetch-complete₂ x))
186
+ ... | no ¬p | _ = ⁇ no λ x → ⊥-elim (¬p (fetch-complete₁ x))
187
+ Dec-SimpleFFD {_} {FFDAbstract.Fetch} {FFDAbstract.SendRes} {_} = ⁇ no λ ()
153
188
154
189
d-FFDFunctionality : FFDAbstract.Functionality ffdAbstract
155
190
d-FFDFunctionality =
156
191
record
157
192
{ State = FFDState
158
193
; initFFDState = record { inIBs = []; inEBs = []; inVTs = []; outIBs = []; outEBs = []; outVTs = [] }
159
194
; _-⟦_/_⟧⇀_ = SimpleFFD
160
- ; FFD-Send-total = simple-total
195
+ ; Dec-_-⟦_/_⟧⇀_ = Dec-SimpleFFD
196
+ ; FFD-Send-total = send-total
161
197
}
162
198
163
199
open import Leios.Voting public
@@ -181,6 +217,8 @@ d-VotingAbstract-2 =
181
217
st : SpecStructure 1
182
218
st = record
183
219
{ a = d-Abstract
220
+ ; Hashable-PreIBHeader = hhs
221
+ ; Hashable-PreEndorserBlock = hpe
184
222
; id = SUT-id
185
223
; FFD' = d-FFDFunctionality
186
224
; vrf' = d-VRF
@@ -201,6 +239,8 @@ st = record
201
239
st-2 : SpecStructure 2
202
240
st-2 = record
203
241
{ a = d-Abstract
242
+ ; Hashable-PreIBHeader = hhs
243
+ ; Hashable-PreEndorserBlock = hpe
204
244
; id = SUT-id
205
245
; FFD' = d-FFDFunctionality
206
246
; vrf' = d-VRF
@@ -249,4 +289,31 @@ maximalFin (ℕ.suc n) {a} with toℕ a N.<? n
249
289
open FunTot (completeFin numberOfParties) (maximalFin numberOfParties)
250
290
251
291
sd : TotalMap (Fin numberOfParties) ℕ
252
- sd = Fun⇒TotalMap toℕ
292
+ sd = Fun⇒TotalMap (const 100000000 )
293
+
294
+ open import Class.Computational
295
+ open import Class.Computational22
296
+
297
+ open Computational22
298
+ open BaseAbstract
299
+ open FFDAbstract
300
+
301
+ open GenFFD.Header using (ibHeader; ebHeader; vHeader)
302
+ open GenFFD.Body using (ibBody)
303
+ open FFDState
304
+
305
+ instance
306
+ Computational-B : Computational22 (BaseAbstract.Functionality._-⟦_/_⟧⇀_ d-BaseFunctionality) String
307
+ Computational-B .computeProof s (INIT x) = success ((STAKE sd , tt) , tt)
308
+ Computational-B .computeProof s (SUBMIT x) = success ((EMPTY , tt) , tt)
309
+ Computational-B .computeProof s FTCH-LDG = success (((BASE-LDG []) , tt) , tt)
310
+ Computational-B .completeness _ _ _ _ _ = {!!} -- TODO: Completeness proof
311
+
312
+ Computational-FFD : Computational22 (FFDAbstract.Functionality._-⟦_/_⟧⇀_ d-FFDFunctionality) String
313
+ Computational-FFD .computeProof s (Send (ibHeader h) (just (ibBody b))) = success ((SendRes , record s {outIBs = record {header = h; body = b} ∷ outIBs s}) , SendIB)
314
+ Computational-FFD .computeProof s (Send (ebHeader h) nothing) = success ((SendRes , record s {outEBs = h ∷ outEBs s}) , SendEB)
315
+ Computational-FFD .computeProof s (Send (vHeader h) nothing) = success ((SendRes , record s {outVTs = h ∷ outVTs s}) , SendVS)
316
+ Computational-FFD .computeProof s Fetch = success ((FetchRes (flushIns s) , record s {inIBs = []; inEBs = []; inVTs = []}) , Fetch)
317
+
318
+ Computational-FFD .computeProof _ _ = failure "FFD error"
319
+ Computational-FFD .completeness _ _ _ _ _ = {!!} -- TODO:Completeness proof
0 commit comments