Skip to content

Commit 5d88406

Browse files
committed
FFD implementation
1 parent 355911b commit 5d88406

File tree

4 files changed

+29
-41
lines changed

4 files changed

+29
-41
lines changed

formal-spec/Leios/FFD.agda

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ record FFDAbstract : Type₁ where
2121
field State : Type
2222
initFFDState : State
2323
_-⟦_/_⟧⇀_ : State Input Output State Type
24-
FFD-total : {ffds i o} ∃[ ffds' ] ffds -⟦ i / o ⟧⇀ ffds'
24+
FFD-Send-total : {ffds h b} ∃[ ffds' ] ffds -⟦ Send h b / SendRes ⟧⇀ ffds'
2525

2626
open Input public
2727
open Output public

formal-spec/Leios/Foreign/Export.agda

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@ instance
144144
Computational-FFD .computeProof s (Send (ibHeader h) (just (ibBody b))) = success ((SendRes , record s {outIBs = record {header = h; body = b} ∷ outIBs s}) , SendIB)
145145
Computational-FFD .computeProof s (Send (ebHeader h) nothing) = success ((SendRes , record s {outEBs = h ∷ outEBs s}) , SendEB)
146146
Computational-FFD .computeProof s (Send (vHeader h) nothing) = success ((SendRes , record s {outVTs = h ∷ outVTs s}) , SendVS)
147-
Computational-FFD .computeProof (record {inIBs = record { header = h; body = b} ∷ i; inEBs = e; inVTs = v}) Fetch = success ((FetchRes (inj₁ (ibHeader h) ∷ inj₂ (ibBody b) ∷ []) , record {inIBs = i; inEBs = e; inVTs = v}) , FetchIB)
148-
Computational-FFD .computeProof (record {inIBs = []; inEBs = e; inVTs = v}) Fetch = success ((FetchRes [] , record {inIBs = []; inEBs = e; inVTs = v}) , EmptyIB)
147+
Computational-FFD .computeProof s Fetch = success ((FetchRes (flushIns s) , record s {inIBs = []; inEBs = []; inVTs = []}) , Fetch)
148+
149149
Computational-FFD .computeProof _ _ = failure "FFD error"
150150
Computational-FFD .completeness _ _ _ _ _ = error "Computational-FFD completeness"
151151

formal-spec/Leios/Short/Deterministic.agda

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ IB-Role⇒ND (No-IB-Role x x₁) = Roles (No-IB-Role x x₁)
115115
opaque
116116
IB-Role-total : LeiosState.needsUpkeep s IB-Role ∃[ s' ] s -⟦IB-Role⟧⇀ s'
117117
IB-Role-total {s = s} h = let open LeiosState s in case Dec-canProduceIB of λ where
118-
(inj₁ (π , pf)) -, IB-Role h pf (proj₂ FFD.FFD-total)
118+
(inj₁ (π , pf)) -, IB-Role h pf (proj₂ FFD.FFD-Send-total)
119119
(inj₂ pf) -, No-IB-Role h pf
120120

121121
IB-Role-Upkeep : s -⟦IB-Role⟧⇀ s' LeiosState.needsUpkeep s IB-Role × ¬ LeiosState.needsUpkeep s' IB-Role
@@ -147,7 +147,7 @@ EB-Role⇒ND (No-EB-Role x x₁) = Roles (No-EB-Role x x₁)
147147
opaque
148148
EB-Role-total : LeiosState.needsUpkeep s EB-Role ∃[ s' ] s -⟦EB-Role⟧⇀ s'
149149
EB-Role-total {s = s} h = let open LeiosState s in case Dec-canProduceEB of λ where
150-
(inj₁ (π , pf)) -, EB-Role h pf (proj₂ FFD.FFD-total)
150+
(inj₁ (π , pf)) -, EB-Role h pf (proj₂ FFD.FFD-Send-total)
151151
(inj₂ pf) -, No-EB-Role h pf
152152

153153
EB-Role-Upkeep : s -⟦EB-Role⟧⇀ s' LeiosState.needsUpkeep s EB-Role × ¬ LeiosState.needsUpkeep s' EB-Role
@@ -179,7 +179,7 @@ V-Role⇒ND (No-V-Role x x₁) = Roles (No-V-Role x x₁)
179179
opaque
180180
V-Role-total : LeiosState.needsUpkeep s V-Role ∃[ s' ] s -⟦V-Role⟧⇀ s'
181181
V-Role-total {s = s} h = let open LeiosState s in case Dec-canProduceV of λ where
182-
(yes p) -, V-Role h p (proj₂ FFD.FFD-total)
182+
(yes p) -, V-Role h p (proj₂ FFD.FFD-Send-total)
183183
(no ¬p) -, No-V-Role h ¬p
184184

185185
V-Role-Upkeep : s -⟦V-Role⟧⇀ s' LeiosState.needsUpkeep s V-Role × ¬ LeiosState.needsUpkeep s' V-Role

formal-spec/Leios/Trace.agda

Lines changed: 23 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -117,53 +117,41 @@ open GenFFD.Header
117117
open GenFFD.Body
118118
open FFDState
119119

120-
data SimpleFFD : FFDState FFDAbstract.Input ffdAbstract FFDAbstract.Output ffdAbstract FFDState Type where
121-
SendIB : {s h b o} SimpleFFD s (FFDAbstract.Send (ibHeader h) (just (ibBody b))) o (record s { outIBs = record {header = h; body = b} ∷ outIBs s})
122-
SendEB : {s eb o} SimpleFFD s (FFDAbstract.Send (ebHeader eb) nothing) o (record s { outEBs = eb ∷ outEBs s})
123-
SendVS : {s vs o} SimpleFFD s (FFDAbstract.Send (vHeader vs) nothing) o (record s { outVTs = vs ∷ outVTs s})
124-
125-
BadSendIB : {s h o} SimpleFFD s (FFDAbstract.Send (ibHeader h) nothing) o s
126-
BadSendEB : {s h b o} SimpleFFD s (FFDAbstract.Send (ebHeader h) (just b)) o s
127-
BadSendVS : {s h b o} SimpleFFD s (FFDAbstract.Send (vHeader h) (just b)) o s
128-
129-
FetchIB : {s ib o} SimpleFFD record s {inIBs = ib ∷ inIBs s} FFDAbstract.Fetch o s
130-
EmptyIB : {s o} SimpleFFD record s {inIBs = []} FFDAbstract.Fetch o s
131-
132-
{-
133-
FetchEB : ∀ {s eb o} → SimpleFFD record s {inEBs = eb ∷ inEBs s} FFDAbstract.Fetch o s
134-
EmptyEB : ∀ {s o} → SimpleFFD record s {inEBs = []} FFDAbstract.Fetch o s
135-
136-
FetchVT : ∀ {s x o} → SimpleFFD record s {inVTs = x ∷ inVTs s} FFDAbstract.Fetch o s
137-
EmptyVT : ∀ {s o} → SimpleFFD record s {inVTs = []} FFDAbstract.Fetch o s
138-
-}
120+
flushIns : FFDState List (GenFFD.Header ⊎ GenFFD.Body)
121+
flushIns record { inIBs = ibs ; inEBs = ebs ; inVTs = vts } =
122+
flushIBs ibs ++ L.map (inj₁ ∘ ebHeader) ebs ++ L.map (inj₁ ∘ vHeader) vts
123+
where
124+
flushIBs : List InputBlock List (GenFFD.Header ⊎ GenFFD.Body)
125+
flushIBs [] = []
126+
flushIBs (record {header = h; body = b} ∷ ibs) = inj₁ (ibHeader h) ∷ inj₂ (ibBody b) ∷ flushIBs ibs
139127

140-
simple-total : {ffds i o} ∃[ ffds' ] (SimpleFFD ffds i o ffds')
141-
simple-total {ffd} {FFDAbstract.Send (ibHeader h) (just (ibBody b))} {o} = record ffd { outIBs = record {header = h; body = b} ∷ outIBs ffd} , SendIB
142-
simple-total {ffd} {FFDAbstract.Send (ebHeader eb) nothing} {o} = record ffd { outEBs = eb ∷ outEBs ffd} , SendEB
143-
simple-total {ffd} {FFDAbstract.Send (vHeader vs) nothing} {o} = record ffd { outVTs = vs ∷ outVTs ffd} , SendVS
128+
data SimpleFFD : FFDState FFDAbstract.Input ffdAbstract FFDAbstract.Output ffdAbstract FFDState Type where
129+
SendIB : {s h b} SimpleFFD s (FFDAbstract.Send (ibHeader h) (just (ibBody b))) FFDAbstract.SendRes (record s { outIBs = record {header = h; body = b} ∷ outIBs s})
130+
SendEB : {s eb} SimpleFFD s (FFDAbstract.Send (ebHeader eb) nothing) FFDAbstract.SendRes (record s { outEBs = eb ∷ outEBs s})
131+
SendVS : {s vs} SimpleFFD s (FFDAbstract.Send (vHeader vs) nothing) FFDAbstract.SendRes (record s { outVTs = vs ∷ outVTs s})
144132

145-
simple-total {ffd} {FFDAbstract.Send (ibHeader h) nothing} {o} = ffd , BadSendIB
146-
simple-total {ffd} {FFDAbstract.Send (ebHeader eb) (just b)} {o} = ffd , BadSendEB
147-
simple-total {ffd} {FFDAbstract.Send (vHeader vs) (just b)} {o} = ffd , BadSendVS
133+
BadSendIB : {s h} SimpleFFD s (FFDAbstract.Send (ibHeader h) nothing) FFDAbstract.SendRes s
134+
BadSendEB : {s h b} SimpleFFD s (FFDAbstract.Send (ebHeader h) (just b)) FFDAbstract.SendRes s
135+
BadSendVS : {s h b} SimpleFFD s (FFDAbstract.Send (vHeader h) (just b)) FFDAbstract.SendRes s
148136

149-
simple-total {record {inIBs = record {header = h; body = b} ∷ i; inEBs = e; inVTs = v}} {FFDAbstract.Fetch} {o} = record {inIBs = i; inEBs = e; inVTs = v} , FetchIB
150-
simple-total {record {inIBs = []; inEBs = e; inVTs = v}} {FFDAbstract.Fetch} {o} = record {inIBs = []; inEBs = e; inVTs = v} , EmptyIB
137+
Fetch : {s} SimpleFFD s FFDAbstract.Fetch (FFDAbstract.FetchRes (flushIns s)) (record s { inIBs = [] ; inEBs = [] ; inVTs = [] })
151138

152-
{-
153-
simple-total {record {inIBs = i; inEBs = eb ∷ e; inVTs = v}} {FFDAbstract.Fetch} {o} = record {inIBs = i; inEBs = e; inVTs = v} , FetchEB
154-
simple-total {record {inIBs = i; inEBs = []; inVTs = v}} {FFDAbstract.Fetch} {o} = record {inIBs = i; inEBs = []; inVTs = v} , EmptyEB
139+
simple-total : {s h b} ∃[ s' ] (SimpleFFD s (FFDAbstract.Send h b) FFDAbstract.SendRes s')
140+
simple-total {s} {ibHeader h} {just (ibBody b)} = record s { outIBs = record {header = h; body = b} ∷ outIBs s} , SendIB
141+
simple-total {s} {ebHeader eb} {nothing} = record s { outEBs = eb ∷ outEBs s} , SendEB
142+
simple-total {s} {vHeader vs} {nothing} = record s { outVTs = vs ∷ outVTs s} , SendVS
155143

156-
simple-total {record {inIBs = i; inEBs = e; inVTs = x ∷ v}} {FFDAbstract.Fetch} {o} = record {inIBs = i; inEBs = e; inVTs = v} , FetchVT
157-
simple-total {record {inIBs = i; inEBs = e; inVTs = []}} {FFDAbstract.Fetch} {o} = record {inIBs = ; inEBs = e; inVTs = []} , EmptyVT
158-
-}
144+
simple-total {s} {ibHeader h} {nothing} = s , BadSendIB
145+
simple-total {s} {ebHeader eb} {just _} = s , BadSendEB
146+
simple-total {s} {vHeader vs} {just _} = s , BadSendVS
159147

160148
d-FFDFunctionality : FFDAbstract.Functionality ffdAbstract
161149
d-FFDFunctionality =
162150
record
163151
{ State = FFDState
164152
; initFFDState = record { inIBs = []; inEBs = []; inVTs = []; outIBs = []; outEBs = []; outVTs = [] }
165153
; _-⟦_/_⟧⇀_ = SimpleFFD
166-
; FFD-total = simple-total
154+
; FFD-Send-total = simple-total
167155
}
168156

169157
open import Leios.Voting public

0 commit comments

Comments
 (0)