Repository navigation
Expand file tree
/
Copy pathStruct.lean
More file actions
47 lines (42 loc) · 2.56 KB
/
Copy pathStruct.lean
File metadata and controls
47 lines (42 loc) · 2.56 KB
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
import Extracted
import CIL.Safety.SymbolicExecution
import CIL.Safety.LoopScaffold
import CIL.Safety.LoopVC
import CIL.Safety.AggregateFields
import CIL.Safety.LoopFrames
/-! A zeroed 12-byte struct local, stored field by field and read through a byref helper,
returns its input; the local's snapshot carries each store and its decoded field values. -/
open CIL.Safety
namespace ExampleProof
bind_entry entry (memory : Memory) (x : CIL.W64) (wellFormed : memory.WellFormed) :=
Extracted.method0 with [.scalar (.i64 x)] from memory allocating wellFormed
/-- The compiled struct stores and helper call return every input word.
All caller allocation metadata, bytes, initialization and permissions survive;
only fresh frame-owned storage may be allocated, written and expired. -/
theorem correctness (memory : Memory) (x : CIL.W64) (wellFormed : memory.WellFormed) :
∃ fuel result, invoke Extracted.program fuel 0 [.scalar (.i64 x)] memory =
.ok (result, [.scalar (.i64 x)]) ∧ MemoryBelow memory.nextIdentity memory result := by
obtain ⟨reference, entered, enter⟩ := entry.checked memory x wellFormed
have frame := enter.frame
have homes := (frame []).homes
have slot : [LocalSlot.bytes (.aggregate 12) reference][0]? = _ := rfl
obtain ⟨zeroed, zeroStep, zeroSnapshots, zeroFormed, zeroBelow, zeroReady, zeroForm, -⟩ :=
(frame []).snapshots.zero_aggregate homes (frame []).wellFormed slot enter.numeric0.writable
obtain ⟨payload, storePayload, payloadSnapshots, payloadFormed, payloadBelow, payloadReady,
payloadForm, payloadValues, -⟩ := zeroSnapshots.store_field homes zeroFormed slot rfl zeroReady
Extracted.layout0_valid (by decide) rfl rfl (fieldIndex := 0) rfl (.i64 x) rfl
obtain ⟨tagged, storeTag, tagSnapshots, tagFormed, tagBelow, -, tagForm, tagValues, -⟩ :=
payloadSnapshots.store_field homes payloadFormed slot rfl payloadReady
Extracted.layout0_valid (by decide) rfl payloadValues (fieldIndex := 1) rfl (.i32 3) rfl
have loaded := tagSnapshots.load_field tagFormed slot rfl Extracted.layout0_valid rfl tagValues
(fieldIndex := 0) rfl rfl
rw [exists_comm]
simp only [exists_and_right]
refine ⟨leaveFrame (entry.frame memory reference) tagged,
?_, MemoryBelow.frame_round_trip enter.setup (zeroBelow.trans (payloadBelow.trans tagBelow))⟩
cil_checked_steps [enter.setup, zeroStep, storePayload, storeTag, loaded, localAddress,
entry.frame,
access_reference_valid _ _ _ _ _ enter.numeric0.writable, zeroForm, payloadForm, tagForm,
numericOfWidth]
#print axioms correctness
end ExampleProof