Skip to content

Commit 9710926

Browse files
committed
Cleanup
1 parent d2c43e6 commit 9710926

File tree

2 files changed

+44
-30
lines changed

2 files changed

+44
-30
lines changed

formal-spec/Leios/Foreign/Defaults.agda

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ open Equivalence
2020
-- that allow to build examples for traces for the different Leios variants
2121
module Leios.Foreign.Defaults where
2222

23+
numberOfParties :
24+
numberOfParties = 1
25+
26+
SUT-id : Fin numberOfParties
27+
SUT-id = zero
28+
2329
instance
2430
htx : Hashable (List ℕ) String
2531
htx = record { hash = S.intersperse "#" ∘ L.map N.show }
@@ -28,7 +34,7 @@ d-Abstract : LeiosAbstract
2834
d-Abstract =
2935
record
3036
{ Tx =
31-
; PoolID = Fin 1
37+
; PoolID = Fin numberOfParties
3238
; BodyHash =
3339
; VrfPf =
3440
; PrivKey =
@@ -178,7 +184,7 @@ d-VotingAbstract-2 =
178184
st : SpecStructure 1
179185
st = record
180186
{ a = d-Abstract
181-
; id = zero
187+
; id = SUT-id
182188
; FFD' = d-FFDFunctionality
183189
; vrf' = d-VRF
184190
; sk-IB = tt
@@ -198,7 +204,7 @@ st = record
198204
st-2 : SpecStructure 2
199205
st-2 = record
200206
{ a = d-Abstract
201-
; id = zero
207+
; id = SUT-id
202208
; FFD' = d-FFDFunctionality
203209
; vrf' = d-VRF
204210
; sk-IB = tt
@@ -217,9 +223,9 @@ st-2 = record
217223

218224
open import Leios.Short st public
219225

220-
sd : TotalMap (Fin 1) ℕ
226+
sd : TotalMap (Fin numberOfParties) ℕ
221227
sd = record
222-
{ rel = singleton (zero , 1)
228+
{ rel = singleton (SUT-id , 1) -- FIXME
223229
; left-unique-rel = λ x y
224230
let a = cong proj₂ (from ∈-singleton x)
225231
b = cong proj₂ (from ∈-singleton y)

formal-spec/Leios/Foreign/Export.agda

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
open import Data.Char.Base as C using (Char)
22
import Data.String as S
3-
open import Data.Fin using (Fin; toℕ; zero)
3+
open import Data.Fin using (Fin; toℕ; zero; #_)
44
open import Data.Integer using (+_; ∣_∣)
55

66
open import Class.Convertible
@@ -9,7 +9,8 @@ open import Tactic.Derive.Convertible
99
open import Tactic.Derive.HsType
1010

1111
open import Leios.Prelude
12-
open import Leios.Foreign.Defaults renaming (EndorserBlock to EndorserBlockAgda; IBHeader to IBHeaderAgda)
12+
open import Leios.Foreign.Defaults
13+
renaming (EndorserBlock to EndorserBlockAgda; IBHeader to IBHeaderAgda) -- LeiosState to LeiosStateAgda)
1314
open import Leios.Foreign.BaseTypes
1415
open import Leios.Foreign.HSTypes
1516
open import Leios.Foreign.Util
@@ -31,8 +32,8 @@ instance
3132
Conv-SlotUpkeep = autoConvert SlotUpkeep
3233

3334
record IBHeader : Type where
34-
field slotNumber :
35-
producerID :
35+
field slotNumber :
36+
producerID :
3637
bodyHash : String
3738

3839
{-# FOREIGN GHC
@@ -46,10 +47,12 @@ instance
4647
HsTy-IBHeader = MkHsType IBHeaderAgda IBHeader
4748
Conv-IBHeader : Convertible IBHeaderAgda IBHeader
4849
Conv-IBHeader = record
49-
{ to = λ (record { slotNumber = sl ; producerID = pid ; bodyHash = h })
50-
record { slotNumber = + sl ; producerID = + toℕ pid ; bodyHash = h}
51-
; from = λ (record { slotNumber = sl ; producerID = pid ; bodyHash = h })
52-
record { slotNumber = ∣ sl ∣ ; producerID = zero ; lotteryPf = tt ; bodyHash = h ; signature = tt }
50+
{ to = λ (record { slotNumber = s ; producerID = p ; bodyHash = h })
51+
record { slotNumber = s ; producerID = toℕ p ; bodyHash = h}
52+
; from = λ (record { slotNumber = s ; producerID = p ; bodyHash = h })
53+
case p <? numberOfParties of λ where
54+
(yes q) record { slotNumber = s ; producerID = #_ p {numberOfParties} {fromWitness q} ; lotteryPf = tt ; bodyHash = h ; signature = tt }
55+
(no _) error "Conversion to Fin not possible!"
5356
}
5457

5558
HsTy-IBBody = autoHsType IBBody
@@ -58,21 +61,12 @@ instance
5861
HsTy-InputBlock = autoHsType InputBlock
5962
Conv-InputBlock = autoConvert InputBlock
6063

61-
HsTy-Fin = MkHsType PoolID ℕ
62-
63-
Conv-Fin : HsConvertible PoolID
64-
Conv-Fin =
65-
record
66-
{ to = Data.Fin.toℕ
67-
; from = λ _ zero
68-
}
69-
7064
Conv-ℕ : HsConvertible ℕ
7165
Conv-ℕ = Convertible-Refl
7266

7367
record EndorserBlock : Type where
74-
field slotNumber :
75-
producerID :
68+
field slotNumber :
69+
producerID :
7670
ibRefs : List String
7771

7872
{-# FOREIGN GHC
@@ -89,25 +83,39 @@ instance
8983
Conv-EndorserBlock : Convertible EndorserBlockAgda EndorserBlock
9084
Conv-EndorserBlock =
9185
record
92-
{ to = λ (record { slotNumber = sl ; producerID = pid ; ibRefs = refs })
93-
record { slotNumber = + sl ; producerID = + toℕ pid ; ibRefs = refs }
94-
; from = λ (record { slotNumber = sl ; producerID = pid ; ibRefs = refs })
95-
record { slotNumber = ∣ sl ∣ ; producerID = zero ; ibRefs = refs ; ebRefs = [] ; lotteryPf = tt ; signature = tt }
86+
{ to = λ (record { slotNumber = s ; producerID = p ; ibRefs = refs })
87+
record { slotNumber = s ; producerID = toℕ p ; ibRefs = refs }
88+
; from = λ (record { slotNumber = s ; producerID = p ; ibRefs = refs })
89+
case p <? numberOfParties of λ where
90+
(yes q) record { slotNumber = s ; producerID = #_ p {numberOfParties} {fromWitness q} ; lotteryPf = tt ; signature = tt ; ibRefs = refs ; ebRefs = [] }
91+
(no _) error "Conversion to Fin not possible!"
9692
}
9793

98-
Listable-Fin : Listable (Fin 1)
94+
Listable-Fin : Listable (Fin numberOfParties)
9995
Listable-Fin =
10096
record
10197
{ listing = singleton zero
10298
; complete = λ {a} (Equivalence.to ∈-singleton) a≡zero
10399
}
104100
where
105-
a≡zero : {a : Fin 1} a ≡ zero
101+
a≡zero : {a : Fin numberOfParties} a ≡ zero
106102
a≡zero {zero} = refl
107103

108104
HsTy-FFDState = autoHsType FFDState
109105
Conv-FFDState = autoConvert FFDState
110106

107+
HsTy-Fin = MkHsType (Fin numberOfParties) ℕ
108+
109+
Conv-Fin : HsConvertible (Fin numberOfParties)
110+
Conv-Fin =
111+
record
112+
{ to = Data.Fin.toℕ
113+
; from = λ p
114+
case p <? numberOfParties of λ where
115+
(yes q) #_ p {numberOfParties} {fromWitness q}
116+
(no _) error "Conversion to Fin not possible!"
117+
}
118+
111119
HsTy-LeiosState = autoHsType LeiosState
112120
Conv-LeiosState = autoConvert LeiosState
113121

0 commit comments

Comments
 (0)