@@ -5643,7 +5643,18 @@ Module CheriMemoryImplWithProofs
56435643 apply H0.
56445644 Qed .
56455645
5646- Fact mem_state_with_funptrmap_bytemap_capmeta_preserves:
5646+ (* TODO: We can get away with just proving [0<l] but this is more precise formulation *)
5647+ Fact Capability_GS_encode_length
5648+ (isexact : bool)
5649+ (c : Capability_GS.t)
5650+ (l: list ascii)
5651+ (t: bool):
5652+ Capability_GS.encode isexact c = Some (l, t) -> Datatypes.length l = sizeof_pointer MorelloImpl.get.
5653+ Proof .
5654+ Admitted .
5655+
5656+ (** Storing some bytes into memory and ghosting the tags for corresponding region preserves invariant *)
5657+ Fact mem_state_with_bytes_preserves:
56475658 forall s : mem_state_r,
56485659 ZMapProofs.map_forall (fun a : allocation => is_dead a = false) (allocations s) ->
56495660 (forall (alloc_id1 alloc_id2 : ZMap.M.key) (a1 a2 : allocation),
@@ -5679,9 +5690,6 @@ Module CheriMemoryImplWithProofs
56795690 Proof .
56805691 intros s Bdead Bnooverlap Bfit Balign Bnextallocid Blastaddr MIcap bs capmeta0 szn SP BL start RSZ H1.
56815692
5682- (* The following part should be same for most types.
5683- We just write some stuff to memory and ghost some tags *)
5684-
56855693 unfold mem_state_with_funptrmap_bytemap_capmeta.
56865694 repeat split;cbn;auto.
56875695 +
@@ -5951,15 +5959,33 @@ Module CheriMemoryImplWithProofs
59515959 lia.
59525960 Qed .
59535961
5962+ (** Storing a capability bytes into memory and and addit it to capmeta preserves invariant *)
5963+ Fact mem_state_with_cap_preserves:
5964+ forall s : mem_state_r,
5965+ ZMapProofs.map_forall (fun a : allocation => is_dead a = false) (allocations s) ->
5966+ (forall (alloc_id1 alloc_id2 : ZMap.M.key) (a1 a2 : allocation),
5967+ alloc_id1 <> alloc_id2 -> ZMap.M.MapsTo alloc_id1 a1 (allocations s) -> ZMap.M.MapsTo alloc_id2 a2 (allocations s) -> allocations_do_no_overlap a1 a2) ->
5968+ ZMapProofs.map_forall (fun a : allocation => AddressValue.to_Z (base a) + Z.of_nat (size a) <= AddressValue.ADDR_LIMIT) (allocations s) ->
5969+ AMapProofs.map_forall_keys addr_ptr_aligned (capmeta s) ->
5970+ ZMapProofs.map_forall_keys (fun alloc_id : ZMap.M.key => alloc_id < next_alloc_id s) (allocations s) ->
5971+ ZMapProofs.map_forall (fun a : allocation => AddressValue.to_Z (base a) >= AddressValue.to_Z (last_address s)) (allocations s) ->
5972+ (forall (addr : AMap.M.key) (g : CapGhostState),
5973+ AMap.M.MapsTo addr (true, g) (capmeta s) ->
5974+ tag_unspecified g = false ->
5975+ forall bs : list (option ascii),
5976+ fetch_bytes (bytemap s) addr (sizeof_pointer MorelloImpl.get) = bs ->
5977+ exists c : Capability_GS.t,
5978+ decode_cap bs true c /\ (exists (a : allocation) (alloc_id : ZMap.M.key), ZMap.M.MapsTo alloc_id a (allocations s) /\ cap_bounds_within_alloc c a)) ->
5979+ forall (c : Capability_GS.t) (cb : list ascii) (b:bool),
59545980
5955- (* TODO: We can get away with just proving [0<l] but this is more precise formulation *)
5956- Fact Capability_GS_encode_length
5957- (isexact : bool)
5958- (c : Capability_GS.t)
5959- (l: list ascii)
5960- (t: bool):
5961- Capability_GS.encode isexact c = Some (l, t) -> Datatypes.length l = sizeof_pointer MorelloImpl.get.
5981+ Capability_GS.encode true c = Some (cb, b) ->
5982+ forall start : AddressValue.t,
5983+ AddressValue.to_Z start + Z.of_nat (Datatypes.length cb) <= AddressValue.ADDR_LIMIT ->
5984+ forall bs : list (option ascii),
5985+ bs = map Some cb ->
5986+ mem_invariant (mem_state_with_funptrmap_bytemap_capmeta (funptrmap s) (AMap.map_add_list_at (bytemap s) bs start) (update_capmeta c start (capmeta s)) s).
59625987 Proof .
5988+ intros s Bdead Bnooverlap Bfit Balign Bnextallocid Blastaddr MIcap c cb ct start RSZ bs Heqbs.
59635989 Admitted .
59645990
59655991 Lemma repr_preserves
@@ -5999,7 +6025,7 @@ Module CheriMemoryImplWithProofs
59996025 intros start RSZ H1.
60006026 bool_to_prop_hyp.
60016027
6002- eapply mem_state_with_funptrmap_bytemap_capmeta_preserves ;eauto.
6028+ eapply mem_state_with_bytes_preserves ;eauto.
60036029 -
60046030 (* MVinteger *)
60056031 break_match_hyp.
@@ -6015,26 +6041,24 @@ Module CheriMemoryImplWithProofs
60156041 intros start RSZ IHfuel.
60166042 bool_to_prop_hyp.
60176043
6018- eapply mem_state_with_funptrmap_bytemap_capmeta_preserves ;eauto.
6044+ eapply mem_state_with_bytes_preserves ;eauto.
60196045 rewrite map_length.
60206046 auto.
60216047 +
60226048 (* IC *)
60236049 repeat break_match_hyp; state_inv_steps.
60246050 *
6025- apply Capability_GS_encode_length in R2.
6026- pose proof pointer_sizeof_pos as SP.
6027- remember (sizeof_pointer MorelloImpl.get) as szn.
6028- clear Heqszn.
6029- generalize dependent (Capability_GS.cap_get_value c).
6051+ generalize dependent (Capability_GS.cap_get_value c); clear c.
60306052 intros start RSZ IHfuel.
60316053 bool_to_prop_hyp.
60326054 remember (map Some l) as bs.
6033- (* TODO: deal with [update_capmeta] in the goal *)
6034- admit.
6055+ eapply mem_state_with_cap_preserves;eauto.
60356056 *
6036- (* TODO: Same as above *)
6037- admit.
6057+ generalize dependent (Capability_GS.cap_get_value c); clear c.
6058+ intros start RSZ IHfuel.
6059+ bool_to_prop_hyp.
6060+ remember (map Some l) as bs.
6061+ eapply mem_state_with_cap_preserves;eauto.
60386062 -
60396063 (* MVfloating *)
60406064 state_inv_steps.
@@ -6047,13 +6071,43 @@ Module CheriMemoryImplWithProofs
60476071 intros start RSZ IHfuel.
60486072 bool_to_prop_hyp.
60496073
6050- eapply mem_state_with_funptrmap_bytemap_capmeta_preserves ;eauto.
6074+ eapply mem_state_with_bytes_preserves ;eauto.
60516075 rewrite map_length.
60526076 auto.
60536077 -
60546078 (* MVpointer *)
6055- (* TODO: This should be similar to [IC] branch above *)
6056- admit.
6079+ clear fuel IHfuel.
6080+ break_match_hyp.
6081+ +
6082+ (* PVfunction *)
6083+ break_match_hyp.
6084+ *
6085+ break_match_hyp.
6086+ break_let.
6087+ state_inv_step_quick.
6088+ state_inv_step_quick.
6089+ break_let.
6090+ state_inv_step_quick.
6091+ apply ret_inr in R5.
6092+ inversion R5; clear R5.
6093+ bool_to_prop_hyp.
6094+ eapply mem_state_with_cap_preserves;eauto.
6095+ *
6096+ state_inv_step_quick.
6097+ break_let.
6098+ state_inv_step_quick.
6099+ state_inv_step_quick.
6100+ apply ret_inr in R5.
6101+ inversion R5; clear R5.
6102+ bool_to_prop_hyp.
6103+ eapply mem_state_with_cap_preserves;eauto.
6104+ +
6105+ state_inv_steps.
6106+ generalize dependent (Capability_GS.cap_get_value c); clear c.
6107+ intros start RSZ.
6108+ bool_to_prop_hyp.
6109+ remember (map Some l) as bs.
6110+ eapply mem_state_with_cap_preserves;eauto.
60576111 -
60586112 (* MVarray *)
60596113 (* TODO: prove using IHfuel *)
0 commit comments