Skip to content

Commit ff14efe

Browse files
committed
revert own_merkle_tree and finish proof of put on empty node
1 parent dc24c01 commit ff14efe

File tree

1 file changed

+35
-51
lines changed

1 file changed

+35
-51
lines changed

src/program_proof/pav/merkle2.v

+35-51
Original file line numberDiff line numberDiff line change
@@ -209,45 +209,31 @@ Definition is_merkle_proof (label: list w8)
209209
tree_sibs_proof t label 0 proof ∗
210210
⌜tree_path t label 0 found⌝.
211211

212-
Definition own_merkle_tree' (recur : loc -d> tree -d> dfrac -d> iProp Σ) :
213-
loc -d> tree -d> dfrac -d> iProp Σ :=
214-
(λ ptr t d,
212+
Fixpoint own_merkle_tree ptr t d : iProp Σ :=
215213
∃ hash,
216214
"#Htree_hash" ∷ is_tree_hash t hash ∗
217-
(("%Heq_ptr" ∷ ⌜ ptr = null ⌝ ∗
218-
"->" ∷ ⌜ t = Empty ⌝ ) ∨
219-
( ∃ sl_hash (ptr_child0 ptr_child1 : loc) sl_label sl_val,
220-
"%Heq_ptr" ∷ ⌜ ptr ≠ null ⌝ ∗
215+
match t with
216+
| Empty => ⌜ ptr = null ⌝
217+
| Leaf label val =>
218+
∃ sl_hash sl_label sl_val,
219+
"Hsl_hash" ∷ own_slice_small sl_hash byteT d hash ∗
221220
"Hptr_hash" ∷ ptr ↦[node :: "hash"]{d} (slice_val sl_hash) ∗
221+
"Hptr_child0" ∷ ptr ↦[node :: "child0"]{d} #null ∗
222+
"Hptr_child1" ∷ ptr ↦[node :: "child1"]{d} #null ∗
223+
"Hsl_label" ∷ own_slice_small sl_label byteT DfracDiscarded label ∗
224+
"Hptr_label" ∷ ptr ↦[node :: "label"]{d} (slice_val sl_label) ∗
225+
"Hsl_val" ∷ own_slice_small sl_val byteT DfracDiscarded val ∗
226+
"Hptr_val" ∷ ptr ↦[node :: "val"]{d} (slice_val sl_val)
227+
| Inner child0 child1 =>
228+
∃ sl_hash ptr_child0 ptr_child1,
222229
"Hsl_hash" ∷ own_slice_small sl_hash byteT d hash ∗
230+
"Hptr_hash" ∷ ptr ↦[node :: "hash"]{d} (slice_val sl_hash) ∗
231+
"Hown_child0" ∷ own_merkle_tree ptr_child0 child0 d ∗
223232
"Hptr_child0" ∷ ptr ↦[node :: "child0"]{d} #ptr_child0 ∗
224-
"Hptr_child1" ∷ ptr ↦[node :: "child1"]{d} #ptr_child1 ∗
225-
"Hptr_label" ∷ ptr ↦[node :: "label"]{d} (slice_val sl_label) ∗
226-
"Hptr_val" ∷ ptr ↦[node :: "val"]{d} (slice_val sl_val) ∗
227-
((∃ label val,
228-
"%Heq_ptr_child0" ∷ ⌜ ptr_child0 = null ⌝ ∗
229-
"%Heq_ptr_child1" ∷ ⌜ ptr_child1 = null ⌝ ∗
230-
"->" ∷ ⌜ t = Leaf label val ⌝ ∗
231-
"Hsl_label" ∷ own_slice_small sl_label byteT DfracDiscarded label ∗
232-
"Hsl_val" ∷ own_slice_small sl_val byteT DfracDiscarded val ) ∨
233-
( ∃ child0 child1,
234-
"%Heq_ptr_children" ∷ ⌜ ptr_child0 ≠ null ∨ ptr_child1 ≠ null ⌝ ∗
235-
"->" ∷ ⌜ t = Inner child0 child1 ⌝ ∗
236-
"Hown_child0" ∷ ▷ recur ptr_child0 child0 d ∗
237-
"Hown_child1" ∷ ▷ recur ptr_child1 child1 d)))))%I.
238-
239-
Local Instance own_merkle_tree'_contractive : Contractive own_merkle_tree'.
240-
Proof.
241-
repeat intros ?.
242-
solve_proper_prepare.
243-
repeat (f_contractive || f_equiv); apply H.
244-
Qed.
245-
246-
Definition own_merkle_tree := fixpoint own_merkle_tree'.
247-
248-
Definition own_merkle_tree_unfold ptr t d :
249-
own_merkle_tree ptr t d ⊣⊢ (own_merkle_tree' own_merkle_tree) ptr t d.
250-
Proof. apply (fixpoint_unfold own_merkle_tree'). Qed.
233+
"Hown_child1" ∷ own_merkle_tree ptr_child1 child1 d ∗
234+
"Hptr_child1" ∷ ptr ↦[node :: "child1"]{d} #ptr_child1
235+
| Cut _ => False
236+
end.
251237

252238
Definition own_merkle_map_aux (ptr : loc) (t : tree)
253239
(m : gmap (list w8) (list w8)) depth d : iProp Σ :=
@@ -267,9 +253,7 @@ Lemma own_merkle_map_to_is_merkle_map ptr m d:
267253
is_merkle_map m h.
268254
Proof.
269255
iIntros "H". iDestruct "H" as (t) "[% H]".
270-
rewrite own_merkle_tree_unfold. iNamed "H".
271-
iDestruct "H" as "[H|H]"; iNamed "H"; [iFrame "#%"|].
272-
iDestruct "H" as "[H|H]"; iNamed "H"; iFrame "#%".
256+
destruct t; iNamed "H"; iFrame "#%".
273257
Qed.
274258

275259
Lemma is_merkle_proof_to_is_merkle_found label found proof h:
@@ -395,6 +379,15 @@ Global Instance own_context_as_fractional ptr q :
395379
AsFractional (own_context ptr (DfracOwn q)) (λ q, own_context ptr (DfracOwn q)) q.
396380
Proof. split; [auto|apply _]. Qed.
397381

382+
Lemma own_empty_tree t d :
383+
own_merkle_tree null t d -∗
384+
⌜ t = Empty ⌝.
385+
Proof.
386+
iIntros "H". destruct t; [done|..];
387+
iNamed "H"; [..|done]; iNamed "H"; iExFalso;
388+
by iDestruct (struct_field_pointsto_not_null with "Hptr_hash") as %?.
389+
Qed.
390+
398391
Lemma empty_tree_reln m depth :
399392
tree_map_reln Empty m depth →
400393
m = ∅.
@@ -425,9 +418,8 @@ Proof.
425418
iLöb as "IH" forall (n0 ptr_n tr elems depth).
426419
wp_rec. wp_load. wp_if_destruct.
427420
{ (* empty node. *)
428-
iDestruct "Hown_merkle" as "[%Htr_reln H]".
429-
rewrite own_merkle_tree_unfold. iNamed "H".
430-
iDestruct "H" as "[H|H]"; iNamed "H"; [|done].
421+
iDestruct "Hown_merkle" as "[%Htr_reln Hown_merkle]".
422+
iDestruct (own_empty_tree with "Hown_merkle") as %->.
431423
opose proof (empty_tree_reln _ _ Htr_reln) as ->.
432424

433425
wp_apply wp_allocStruct; [val_ty|]. iIntros (?) "Hptr_leaf".
@@ -438,17 +430,9 @@ Proof.
438430
iDestruct (own_slice_to_small with "Hsl_hash") as "Hsl_hash".
439431
wp_storeField.
440432
wp_pures. iApply ("HΦ" $! _ (Leaf label val)).
441-
iFrame "Hown_ctx ∗". iIntros "!>". iSplit.
442-
- iPureIntro. intros label'. destruct (decide (label = label')).
443-
+ subst. by simpl_map.
444-
+ simpl_map. naive_solver.
445-
- rewrite own_merkle_tree_unfold. iFrame "#%".
446-
iRight.
447-
(* annoying argument that ptr not null bc it points to stuff.
448-
was the reverse argument with prev own_tree.
449-
bc ptr null, can't have a non-Empty tree,
450-
null ptr would point to stuff. *)
451-
admit.
433+
iFrame "Hown_ctx ∗#%". iIntros "!%".
434+
intros label'.
435+
destruct (decide (label = label')); subst; simpl_map; naive_solver. }
452436
Admitted.
453437

454438
Lemma wp_verifySiblings sl_label sl_last_hash sl_sibs sl_dig

0 commit comments

Comments
 (0)