Commit 8962fbb6 authored by Jakob Botsch Nielsen's avatar Jakob Botsch Nielsen

Rename ChainStep -> ActionEvaluation and ChainEvent -> ChainStep

parent 5b89d7a3
Pipeline #12673 passed with stage
in 6 minutes and 26 seconds
This diff is collapsed.
......@@ -15,7 +15,7 @@ Local Open Scope Z.
Definition circulation (chain : Chain) :=
sumZ (account_balance chain) (elements Address).
(* We then prove that over any single step, the circulation is preserved.
(* We then prove that over any single action, the circulation is preserved.
The idea behind this proof is that addrs contain from and to so
we can move them to the beginning of the sum and it easily follows that
the sum of their balances is the same as before. For the rest of the
......@@ -32,13 +32,13 @@ Proof.
intuition.
Qed.
Lemma step_from_to_same
Lemma eval_action_from_to_same
{pre : Environment}
{act : Action}
{post : Environment}
{new_acts : list Action}
(step : ChainStep pre act post new_acts) :
step_from step = step_to step ->
(eval : ActionEvaluation pre act post new_acts) :
eval_from eval = eval_to eval ->
circulation post = circulation pre.
Proof.
intros from_eq_to.
......@@ -46,46 +46,46 @@ Proof.
induction (elements Address) as [| x xs IH].
- reflexivity.
- cbn in *.
rewrite IH, (account_balance_post step), from_eq_to.
rewrite IH, (account_balance_post eval), from_eq_to.
lia.
Qed.
Hint Resolve step_from_to_same : core.
Hint Resolve eval_action_from_to_same : core.
Lemma step_circulation_unchanged
Lemma eval_action_circulation_unchanged
{pre : Environment}
{act : Action}
{post : Environment}
{new_acts : list Action} :
ChainStep pre act post new_acts ->
ActionEvaluation pre act post new_acts ->
circulation post = circulation pre.
Proof.
intros step.
destruct (address_eqb_spec (step_from step) (step_to step))
intros eval.
destruct (address_eqb_spec (eval_from eval) (eval_to eval))
as [from_eq_to | from_neq_to]; eauto.
destruct (address_reorganize from_neq_to) as [suf perm].
apply Permutation_sym in perm.
unfold circulation.
rewrite 2!(sumZ_permutation perm).
cbn.
rewrite (account_balance_post_to step from_neq_to).
rewrite (account_balance_post_from step from_neq_to).
rewrite (account_balance_post_to eval from_neq_to).
rewrite (account_balance_post_from eval from_neq_to).
enough (sumZ (account_balance pre) suf = sumZ (account_balance post) suf) by lia.
pose proof (Permutation_NoDup perm) as perm_set.
assert (from_not_in_suf: ~In (step_from step) suf).
{ apply (in_NoDup_app _ [step_from step; step_to step] _); intuition. }
assert (to_not_in_suf: ~In (step_to step) suf).
{ apply (in_NoDup_app _ [step_from step; step_to step] _); intuition. }
assert (from_not_in_suf: ~In (eval_from eval) suf).
{ apply (in_NoDup_app _ [eval_from eval; eval_to eval] _); intuition. }
assert (to_not_in_suf: ~In (eval_to eval) suf).
{ apply (in_NoDup_app _ [eval_from eval; eval_to eval] _); intuition. }
clear perm perm_set.
pose proof (account_balance_post_irrelevant step) as balance_irrel.
pose proof (account_balance_post_irrelevant eval) as balance_irrel.
induction suf as [| x xs IH]; auto.
cbn in *.
rewrite IH, balance_irrel; auto.
Qed.
Hint Resolve step_circulation_unchanged : core.
Hint Resolve eval_action_circulation_unchanged : core.
Instance circulation_proper :
Proper (ChainEquiv ==> eq) circulation.
......@@ -129,23 +129,23 @@ Proof.
lia.
Qed.
Lemma event_circulation {prev next} (evt : ChainEvent prev next) :
Lemma step_circulation {prev next} (step : ChainStep prev next) :
circulation next =
match evt with
| evt_block _ _ _ _ =>
match step with
| step_block _ _ _ _ =>
circulation prev + compute_block_reward (block_height (block_header next))
| _ => circulation prev
end%Z.
Proof.
destruct evt;
destruct step;
repeat
match goal with
| [H: EnvironmentEquiv _ _ |- _] => rewrite H in *; clear H
end.
- (* New block *)
now rewrite circulation_add_new_block.
- (* New step *)
erewrite step_circulation_unchanged; eauto.
- (* New action *)
erewrite eval_action_circulation_unchanged; eauto.
- (* Permute queue *)
intuition.
Qed.
......@@ -161,7 +161,7 @@ Proof.
induction trace as [| from mid to xs IH x]; rewrite eq in *; clear eq.
- unfold circulation.
induction (elements Address); auto.
- rewrite (event_circulation x).
- rewrite (step_circulation x).
destruct x.
+ rewrite_environment_equiv.
cbn.
......@@ -170,7 +170,7 @@ Proof.
| [H: IsValidNextBlock _ _ |- _] =>
rewrite (proj1 H), IH, sumZ_seq_S; auto
end.
+ erewrite block_header_post_step; eauto.
+ erewrite block_header_post_action; eauto.
+ intuition.
Qed.
End Circulation.
......@@ -773,8 +773,8 @@ Proof.
assert (address_is_contract contract = true) as addr_format by eauto.
remember empty_state eqn:eq.
(* Contract cannot have been deployed in empty trace so we solve that immediately. *)
induction trace as [|? ? ? evts IH evt]; subst; try solve_by_inversion.
destruct_chain_event.
induction trace as [|? ? ? steps IH step]; subst; try solve_by_inversion.
destruct_chain_step.
- (* New block added, does not change any of the values *)
(* so basically just use IH directly. *)
rewrite queue_prev in *.
......@@ -787,7 +787,7 @@ Proof.
cbn [trace_txs].
rewrite queue_prev, queue_new in *.
remember (chain_state_env prev).
destruct_chain_step; subst pre; cbn [step_tx].
destruct_action_eval; subst pre; cbn [eval_tx].
+ (* Transfer step: cannot be to contract, but can come from contract. *)
rewrite_environment_equiv.
specialize_hypotheses.
......@@ -820,7 +820,7 @@ Proof.
simpl_hyp_invariant.
simpl_goal_invariant.
(* Outgoing transactions is 0 *)
fold (outgoing_txs evts contract).
fold (outgoing_txs steps contract).
rewrite undeployed_contract_no_out_txs; auto.
cbn. lia.
+ (* Call. *)
......@@ -842,15 +842,15 @@ Proof.
match goal with
| [H1: wc_receive _ _ _ _ _ = Some _,
H2: contract_state _ _ = Some _ |- _] =>
generalize (wc_receive_state_well_behaved _ _ _ _ _ _ _ _ _ evts H2 H1)
generalize (wc_receive_state_well_behaved _ _ _ _ _ _ _ _ _ steps H2 H1)
end.
simpl_goal_invariant.
rewrite num_outgoing_acts_call.
intros.
cbn -[set_contract_state].
fold (incoming_txs evts contract) in *.
fold (outgoing_txs evts contract) in *.
fold (incoming_txs steps contract) in *.
fold (outgoing_txs steps contract) in *.
rewrite address_eq_refl.
destruct (address_eqb_spec from contract);
simpl_hyp_invariant;
......
......@@ -223,7 +223,7 @@ Section ExecuteActions.
| None => act_transfer to amount
| Some msg => act_call to amount msg
end) ->
ChainStep lc_before act lc_after new_acts.
ActionEvaluation lc_before act lc_after new_acts.
Proof.
intros sent act_eq.
unfold send_or_call in sent.
......@@ -240,7 +240,7 @@ Section ExecuteActions.
| [p: OakValue * list ActionBody |- _] => destruct p as [new_state resp_acts]
end.
Hint Resolve gtb_le : core.
apply (step_call from to amount wc msg prev_state new_state resp_acts);
apply (eval_call from to amount wc msg prev_state new_state resp_acts);
try solve [cbn in *; auto; congruence].
+ rewrite <- receive.
apply wc_receive_proper; auto.
......@@ -252,7 +252,7 @@ Section ExecuteActions.
destruct (address_is_contract to) eqn:addr_format; simpl in *; try congruence.
destruct msg; simpl in *; try congruence.
assert (new_acts = []) by congruence; subst new_acts.
apply (step_transfer from to amount); auto.
apply (eval_transfer from to amount); auto.
inversion sent; subst; now apply transfer_balance_equiv.
Defined.
......@@ -273,7 +273,7 @@ Section ExecuteActions.
Lemma deploy_contract_step from amount wc setup act lc_before new_acts lc_after :
deploy_contract from amount wc setup lc_before = Some (new_acts, lc_after) ->
act = build_act from (act_deploy amount wc setup) ->
ChainStep lc_before act lc_after new_acts.
ActionEvaluation lc_before act lc_after new_acts.
Proof.
intros dep act_eq.
unfold deploy_contract in dep.
......@@ -287,7 +287,7 @@ Section ExecuteActions.
cbn in dep.
assert (new_acts = []) by congruence; subst new_acts.
Hint Resolve get_new_contract_addr_is_contract_addr : core.
apply (step_deploy from contract_addr amount wc setup state); eauto.
apply (eval_deploy from contract_addr amount wc setup state); eauto.
- rewrite <- recv.
apply wc_init_proper; auto.
now symmetry; apply transfer_balance_equiv.
......@@ -301,7 +301,7 @@ Section ExecuteActions.
(lc_before : LocalChain)
(lc_after : LocalChain) :
execute_action act lc_before = Some (new_acts, lc_after) ->
ChainStep lc_before act lc_after new_acts.
ActionEvaluation lc_before act lc_after new_acts.
Proof.
intros exec.
unfold execute_action in exec.
......@@ -322,14 +322,14 @@ Section ExecuteActions.
destruct (execute_action x lc) as [[new_acts lc_after]|] eqn:exec_once;
cbn in *; try congruence.
set (step := execute_action_step _ _ _ _ exec_once).
Hint Constructors ChainEvent : core.
Hint Constructors ChainStep : core.
Hint Constructors ChainedList : core.
Hint Unfold ChainTrace : core.
refine (IH _ _ _ _ exec).
destruct df.
+ (* depth-first case *)
eauto.
+ (* breadth-first case. Insert permute event. *)
+ (* breadth-first case. Insert permute step. *)
assert (Permutation (new_acts ++ xs) (xs ++ new_acts)) by perm_simplify.
cut (ChainTrace
empty_state
......@@ -468,7 +468,7 @@ Proof.
refine (execute_actions_trace _ _ _ _ _ _ exec).
refine (snoc prev_lcb_trace _).
Hint Resolve validate_header_valid validate_actions_valid : core.
eapply evt_block; eauto.
eapply step_block; eauto.
apply add_new_block_equiv.
reflexivity.
Defined.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment