-
Notifications
You must be signed in to change notification settings - Fork 0
/
SelfConnectEval.dfy
224 lines (212 loc) · 7.74 KB
/
SelfConnectEval.dfy
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
224
module SelfConnectEval {
import opened Circ
import opened Scuf
import opened SelfConnect
import opened MapFunction
import opened Eval
import opened Subcircuit
import opened ConservedSubcircuit
import opened SelfConnectEval2
import opened Path
ghost predicate ConnectRequirements(c: Circuit, s: Scuf, conn: InternalConnection, fi: FI)
{
&& c.Valid()
&& s.Valid(c)
&& conn.Valid()
&& ScufConnectionConsistent(c, s, conn)
&& assert conn.i_width == |s.mp.inputs| by {
reveal ScufConnectionConsistent();
}
&& FIValid(fi, conn.I2NI(s.mp.inputs), s.mp.state)
}
lemma EvaluateSelfConnect(c: Circuit, s: Scuf, conn: InternalConnection, np: NP, fi: FI)
requires ConnectRequirements(c, s, conn, fi)
requires
var (new_c, new_s) := ConnectCircuitScufImpl(c, s, conn);
&& (np in new_s.mp.outputs || np in StateINPs(new_s.mp.state))
&& FIValid(fi, new_s.mp.inputs, new_s.mp.state)
&& s.SomewhatValidRelaxInputs(new_c)
&& new_s.SomewhatValidRelaxInputs(new_c)
&& var conn_outputs := conn.GetConnectedOutputs(s.mp);
&& var conn_inputs := conn.GetConnectedInputs(s.mp);
&& !PathExistsBetweenNPSets(new_c, conn_outputs, conn_inputs)
ensures
var (new_c, new_s) := ConnectCircuitScufImpl(c, s, conn);
&& FICircuitValid(new_c, FItoKeys(fi))
&& NPValid(new_c, np)
&& (Evaluate(new_c, np, fi) == EvalOk(MFLookup(new_s, fi, np)))
{
var (new_c, new_s) := ConnectCircuitScufImpl(c, s, conn);
var connection := conn.GetConnection(s.mp);
var fi_first_pass := conn.FIFirstPass(s.mp, fi);
var fi_second_pass := conn.FISecondPass(s.mp, s.uf, fi);
assert NPValid(c, np) && NPValid(new_c, np) by {
assert np in s.mp.outputs || np in StateINPs(s.mp.state);
ScufFInputsAreValid(c, s);
ScufFOutputsAreValid(c, s);
ScufFInputsAreValid(new_c, s);
ScufFOutputsAreValid(new_c, s);
}
assert FICircuitValid(new_c, FItoKeys(fi )) by {
assert FIValid(fi, new_s.mp.inputs, new_s.mp.state);
ScufValidFiValidToFICircuitValid(new_c, new_s, FItoKeys(fi));
reveal FICircuitValid();
}
assert FICircuitValid(new_c, FItoKeys(fi_second_pass)) by {
assert FIValid(fi_second_pass, s.mp.inputs, s.mp.state);
ScufValidFiValidToFICircuitValid(new_c, s, FItoKeys(fi_second_pass));
}
assert FICircuitValid(c, FItoKeys(fi_second_pass)) by {
assert FIValid(fi_second_pass, s.mp.inputs, s.mp.state);
ScufValidFiValidToFICircuitValid(c, s, FItoKeys(fi_second_pass));
}
calc {
Evaluate(new_c, np, fi);
{
EvaluateWithActual(c, s, conn, np, fi);
}
Evaluate(new_c, np, fi_second_pass);
{
EvaluateSelfConnectOldONP(c, s, conn, np, fi_second_pass);
}
Evaluate(c, np, fi_second_pass);
{
assert s.Valid(c);
reveal Seq.ToSet();
reveal Scuf.EvaluatesCorrectly();
}
EvalOk(MFLookup(s, fi_second_pass, np));
{
SelfConnectSecondPassMFLookup(s, conn, np, fi);
}
EvalOk(MFLookup(new_s, fi, np));
}
}
function ConnectCircuitScuf(c: Circuit, s: Scuf, conn: InternalConnection): (r: (Circuit, Scuf))
requires c.Valid()
requires s.Valid(c)
requires conn.Valid()
requires ScufConnectionConsistent(c, s, conn)
ensures
var (new_c, new_s) := r;
&& new_c.Valid()
&& new_s.Valid(new_c)
&& s.ValidRelaxInputs(new_c)
&& (IsIsland(c, s.sc) ==> IsIsland(new_c, new_s.sc))
{
reveal ScufConnectionConsistent();
var (new_c, new_s) := ConnectCircuitScufImpl(c, s,conn);
assert new_s.Valid(new_c) by {
assert ScValid(new_c, s.sc) by {
assert ScValid(c, s.sc);
reveal ScValid();
assert new_c.NodeKind == c.NodeKind;
}
assert new_s.SomewhatValid(new_c) by {
}
assert new_s.SomewhatValidRelaxInputs(new_c) by {
new_s.SomewhatValidToRelaxInputs(new_c);
}
assert new_s.EvaluatesCorrectly(new_c) by {
reveal ScValid();
ScufFOutputsAreValid(new_c, new_s);
reveal Seq.ToSet();
forall fi: FI | FIValid(fi, new_s.mp.inputs, new_s.mp.state)
ensures forall np :: np in Seq.ToSet(new_s.mp.outputs) || np in StateINPs(new_s.mp.state) ==>
&& FICircuitValid(new_c, FItoKeys(fi))
&& (Evaluate(new_c, np, fi) == EvalOk(MFLookup(new_s, fi, np)))
{
assert FICircuitValid(new_c, FItoKeys(fi)) by {ScufValidFiValidToFICircuitValid(new_c, new_s, FItoKeys(fi));}
forall np | np in Seq.ToSet(new_s.mp.outputs) || np in StateINPs(new_s.mp.state)
ensures Evaluate(new_c, np, fi) == EvalOk(MFLookup(new_s, fi, np))
{
reveal ScufConnectionConsistent();
var conn_outputs := conn.GetConnectedOutputs(s.mp);
var conn_inputs := conn.GetConnectedInputs(s.mp);
ScufFInputsAreValid(c, s);
ScufFOutputsAreValid(c, s);
reveal ONPsValid();
StillNoPathExistsBetweenNPSets(c, new_c, conn_outputs, conn_inputs);
EvaluateSelfConnect(c, s, conn, np, fi);
}
}
reveal Scuf.EvaluatesCorrectly();
}
assert new_s.MapValid() by {
}
}
assert s.ValidRelaxInputs(new_c) by {
assert s.MapValid();
assert ScValid(new_c, s.sc);
assert s.SomewhatValidRelaxInputs(new_c);
reveal Scuf.EvaluatesCorrectly();
assert s.EvaluatesCorrectly(new_c) by {
reveal ScValid();
ScufFOutputsAreValid(new_c, s);
reveal Seq.ToSet();
forall fi: FI | FIValid(fi, s.mp.inputs, s.mp.state)
ensures forall np :: np in Seq.ToSet(s.mp.outputs) || np in StateINPs(s.mp.state) ==>
&& FICircuitValid(new_c, FItoKeys(fi))
&& (Evaluate(new_c, np, fi) == EvalOk(MFLookup(s, fi, np)))
{
assert FICircuitValid(new_c, FItoKeys(fi)) by {ScufValidFiValidToFICircuitValid(new_c, s, FItoKeys(fi));}
forall np | np in Seq.ToSet(s.mp.outputs) || np in StateINPs(s.mp.state)
ensures Evaluate(new_c, np, fi) == EvalOk(MFLookup(s, fi, np))
{
EvaluateSelfConnectOldONP(c, s, conn, np, fi);
}
}
}
}
ConnectCircuitScufConservesIsIsland(c, s, conn);
(new_c, new_s)
}
lemma ConnectCircuitScufConservesIsIsland(c: Circuit, s: Scuf, conn: InternalConnection)
requires c.Valid()
requires s.Valid(c)
requires conn.Valid()
requires ScufConnectionConsistent(c, s, conn)
ensures
var (new_c, new_s) := ConnectCircuitScufImpl(c, s,conn);
IsIsland(c, s.sc) ==> IsIsland(new_c, new_s.sc)
{
reveal IsIsland();
FOutputsInSc(c, s);
FInputsInSc(c, s);
reveal NPsInSc();
}
lemma ConnectCircuitScufCircuitUnconnected(ca: Circuit, cb: Circuit, s: Scuf, conn: InternalConnection)
requires ca.Valid()
requires cb.Valid()
requires s.Valid(cb)
requires conn.Valid()
requires ScufConnectionConsistent(cb, s, conn)
requires s.sc !! ca.NodeKind.Keys
requires CircuitUnconnected(ca, cb)
ensures
var (new_c, new_s) := ConnectCircuitScufImpl(cb, s,conn);
CircuitUnconnected(ca, new_c)
{
reveal CircuitUnconnected();
FOutputsInSc(cb, s);
FInputsInSc(cb, s);
reveal NPsInSc();
}
lemma ConnectCircuitScufCircuitConserved(ca: Circuit, cb: Circuit, s: Scuf, conn: InternalConnection)
requires ca.Valid()
requires cb.Valid()
requires s.Valid(cb)
requires conn.Valid()
requires ScufConnectionConsistent(cb, s, conn)
requires s.sc !! ca.NodeKind.Keys
requires CircuitConserved(ca, cb)
ensures
var (new_c, new_s) := ConnectCircuitScufImpl(cb, s,conn);
CircuitConserved(ca, new_c)
{
reveal CircuitConserved();
FOutputsInSc(cb, s);
FInputsInSc(cb, s);
reveal NPsInSc();
}
}