-
Notifications
You must be signed in to change notification settings - Fork 0
/
uccomScript.sml
223 lines (199 loc) · 5.75 KB
/
uccomScript.sml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
(**********************************************************************)
(* Formalization of a simplified version of UC's communication model *)
(**********************************************************************)
open HolKernel;
open Parse;
open Arith;
open boolLib;
open bossLib;
open listTheory;
open rich_listTheory;
open arithmeticTheory;
open numLib;
open computeLib;
val _ = new_theory "uccom";
(* Datatype for messages sent between protocol, environment and attacker *)
val _ =
Hol_datatype
`Message =
EnvtoP of 'a
| EnvtoA of 'b
| PtoEnv of 'c
| PtoA of 'd
| AtoEnv of 'e
| AtoP of 'f
`;
(* To make sure the protocol can only send messages of type PtoA or PtoEnv, we
* create the following datatype. PROTO_WRAPPER below concerts it into type
* message *)
val _ =
Hol_datatype
`ProtoMessage =
Proto_toEnv of 'c
| Proto_toA of 'd
`;
val PROTO_WRAPPER_def =
Define
`
(PROTO_WRAPPER (Proto_toEnv m) = (PtoEnv m))
/\
(PROTO_WRAPPER (Proto_toA m) = (PtoA m))
`;
(* Dito for Adversary *)
val _ =
Hol_datatype
`AdvMessage =
Adv_toEnv of 'e
| Adv_toP of 'f
`;
val ADV_WRAPPER_def =
Define
`
(ADV_WRAPPER (Adv_toEnv m) = (AtoEnv m))
/\
(ADV_WRAPPER (Adv_toP m) = (AtoP m))
`;
(* Compute next state of the network from the perspective of the environment,
* given a message on the network addressed to the protocol or adversary.
*
* Parameters:
* p -- step function for protocol
* a -- step function for adversary
* Input:
* state_p -- current protocol state
* state_a -- current adversary state
* message to be routed
* Output:
* the adversary's and the protocols next state
* message resulting from computation *unless* input message was already adresses
* to envinronment (then ROUTE computes identity)
*)
(* ('a,'b,'c,'d,'e,'f, 'p, 'q) route_func is *)
val _ = type_abbrev ("routefunc",
``: ('p -> ('a,'b,'c,'d,'e,'f) Message -> ('p # ('c,'d) ProtoMessage)) (* p *)
->('q -> ('a,'b,'c,'d,'e,'f) Message -> ('q # ('e,'f)AdvMessage)) (* a *)
->('p#'q) # ('a,'b,'c,'d,'e,'f) Message
->('p#'q) # ('a,'b,'c,'d,'e,'f) Message ``);
val ROUTE_def =
Define
`
((ROUTE: ('a,'b,'c,'d,'e,'f, 'p, 'q) routefunc)
p a ((state_p,state_a),(EnvtoP m)) =
let (state_p_n, out) = p state_p (EnvtoP m) in
((state_p_n, state_a),(PROTO_WRAPPER out)))
/\
(ROUTE p a ((state_p,state_a),(AtoP m)) =
let (state_p_n, out) = p state_p (AtoP m) in
((state_p_n, state_a),(PROTO_WRAPPER out)))
/\
(ROUTE p a ((state_p,state_a),(EnvtoA m)) =
let (state_a_n, out) = a state_a (EnvtoA m) in
((state_p, state_a_n),(ADV_WRAPPER out)))
/\
(ROUTE p a ((state_p,state_a),(PtoA m)) =
let (state_a_n, out) = a state_a (PtoA m) in
((state_p, state_a_n),(ADV_WRAPPER out)))
/\
(ROUTE p a ((state_p,state_a),(PtoEnv m)) =
((state_p, state_a),(PtoEnv m)))
/\
(ROUTE p a ((state_p,state_a),(AtoEnv m)) =
((state_p, state_a),(AtoEnv m)))
`;
(* Execute routing algorithm up to a depth of 3 *)
val ROUTE_THREE_def =
Define
` ROUTE_THREE p a (s,m) = (ROUTE p a) (
(ROUTE p a) (
(ROUTE p a) (s,m))) `;
(* Old def, looks nicer, but difficult to deal with in proof
Define ` ROUTE_THREE p a = ((ROUTE p a) o (ROUTE p a) o (ROUTE p a)) `;
*)
val _ =
Hol_datatype
`EnvMessage =
Env_toP of 'a
| Env_toA of 'b
`;
val ENV_WRAPPER_def =
Define
`
(ENV_WRAPPER (Env_toP m) = (EnvtoP m))
/\
(ENV_WRAPPER (Env_toA m) = (EnvtoA m))
`;
val _ =
Hol_datatype
`GameOutput =
OutputfromP of 'c
| OutfromA of 'e
| RoutingError
`;
val GAME_OUT_WRAPPER_def =
Define
`
(GAME_OUT_WRAPPER (PtoEnv m) = (OutputfromP m))
/\
(GAME_OUT_WRAPPER (AtoEnv m) = (OutfromA m))
/\
(GAME_OUT_WRAPPER (_) = RoutingError)
`;
(* Given an input from the environment, compute the out from protocol and
* adversary to the environment. We compute the routing only up to a depth of
* three. If this is not enough, the environment is notified of a routing
* error.
*)
val EXEC_STEP_def =
Define
`
EXEC_STEP p a ((state_p,state_a),input) =
let
((state_p_n,state_a_n),out) =
(ROUTE_THREE : ('a,'b,'c,'d,'e,'f, 'p, 'q) routefunc)
p a ((state_p,state_a),(ENV_WRAPPER input))
in
((state_p_n,state_a_n),GAME_OUT_WRAPPER out)
`
(* Given protocol, adversary and their respective states, compute the output
* of a list of commands to the environment. *)
val EXEC_LIST_def =
Define
`(EXEC_LIST p a s [] = [] )
/\
(EXEC_LIST p a s (i :: il) =
case EXEC_STEP p a (s,i) of
(_,RoutingError)=> [RoutingError]
|(s',out ) => out ::(EXEC_LIST p a s' il)
)
`;
(* Given protocol, adversary and their respective states, compute the output
* of a list of commands to the environment. *)
val EXEC_LIST_FULL_def =
Define
`(EXEC_LIST_FULL p a s [] = [] )
/\
(EXEC_LIST_FULL p a s (i :: il) =
let (s',out) = EXEC_STEP p a (s,i) in
((s',out)::(EXEC_LIST_FULL p a s' il)))
`;
(* Sanity check
val TEST_PROTO_def =
Define
`(TEST_PROTO s (EnvtoP 1) = (s,(Proto_toA 2)))
/\
(TEST_PROTO s (AtoP 3) = (s,(Proto_toEnv 4)))
/\
(TEST_PROTO s (EnvtoP 5) = (s,(Proto_toEnv 6)))
`;
val TEST_ADV_def =
Define
`TEST_ADV s (PtoA 2) = (s,(Adv_toP 3))`;
(* EVAL ``EXEC_LIST TEST_PROTO TEST_ADV (0,0) [Env_toP 1; Env_toP 5]``; *)
*)
val DUMMY_ADV_def =
Define
` (DUMMY_ADV (_: num ) (EnvtoA m) = (0:num,(Adv_toP m)))
/\
(DUMMY_ADV (_: num) (PtoA m) = (0,(Adv_toEnv m)))
`
val _ = export_theory()