Library SetcodeConcrete.executiondestruction
The actual VM cannot delete an account it did not create
From Stdlib Require Import List ZArith.
Require Import RocqOfOCaml.RocqOfOCaml MonadVM.Execution.
Require Import QedkConcrete.hostframe QedkConcrete.hostaccountformat
QedkConcrete.vmhostframe QedkConcrete.recursiveassembly.
Require Import SetcodeConcrete.destructionframe SetcodeConcrete.vmcompleteframe
SetcodeConcrete.assembly SetcodeConcrete.vmprogress.
Set Default Goal Selector "!".
#[local] Hint Extern 100 (Basics.Unreachable _) ⇒
(apply Opaque.legacy_witness; Opaque.opaque_inhabit 64%nat) : typeclass_instances.
Local Open Scope Z_scope.
Module E := Execution.Make.
Definition destructionHost (host : Evmc.HOST (t := S.t)) :=
PrimitiveHostFrame host destructionCovered ∧
(∀ current source static gas, preservesCallback destructionCovered
(host.(Evmc.HOST.setcodefrom) current source static gas)) ∧
(∀ params, @setcodeGasProgress S.t (Vm.Make.Build_FArgs params host)) ∧
(∀ addr s, snd (host.(Evmc.HOST.get_code_size) addr s) = s) ∧
(∀ addr offset size s, snd (host.(Evmc.HOST.copy_code) addr offset size s) = s) ∧
(∀ s, snd (host.(Evmc.HOST.get_tx_context) s) = s) ∧
(∀ msg, 0 ≤ Evmc.Message.t.gas msg < 2^63 →
preservesCallback destructionCovered (host.(Evmc.HOST.call) msg)).
Definition destructionVm {T : Evmc.Vm_H_signature (t := S.t)}
(vm : Evmc.Vm.SIG (_fargs := Evmc.Vm.Build_FArgs T)) :=
∀ msg code, 0 ≤ Evmc.Message.t.gas msg < 2^63 →
preservesCallback destructionCovered (vm.(Evmc.Vm.SIG.execute) msg code).
Section Execution.
Context {F : E.FArgs}.
Local Abbreviation args := (@E.Instantiation_fargs F).
Local Abbreviation HostF := (@Evmc.Instantiate.HostF S.t (@recursiveArgs args)).
Local Abbreviation VmF := (@Evmc.Instantiate.VmF S.t (@recursiveArgs args)).
Context (cold warm access write reserve : N).
Context (Hrevision : E.Params.(Execution.Make_Params_signature.revision) =
Support.Variants.Revision.Setcode (cold, warm, access, write, reserve)).
Context (Hcold : (0 < cold)%N) (Hwarm : (0 < warm)%N).
Lemma vm_constructor_destruction host :
destructionHost host → destructionVm (VmF host).
Proof.
intros [Hprimitive [Hsetcode [Hprogress [Hsize [Hcopy [Hcontext Hcall]]]]]] msg code Hgas initial Hbefore.
cbn -[Vm.Make.execute destructionCovered].
eapply complete_execute_preserves with (property := destructionCovered).
- exact Hrevision.
- reflexivity.
- apply Hprogress.
- exact Hprimitive.
- exact Hsetcode.
- exact Hcall.
- exact Hcontext.
- exact Hsize.
- exact Hcopy.
- exact Hgas.
- exact Hbefore.
Qed.
Lemma host_constructor_destruction vm :
destructionVm vm → destructionHost (HostF vm).
Proof.
intro Hvm. split; [apply concrete_primitives_preserve_destruction|].
split; [intros; apply setcode_preserves_destruction|].
split.
- intro params. exact (@concrete_setcode_gas_progress args vm params
cold warm access write reserve Hrevision Hcold Hwarm).
- split; [intros; reflexivity|].
split; [intros; apply copy_code_read_only|].
split; [intros; reflexivity|].
intros msg Hgas. apply (@call_preserves_destruction
(H.Build_FArgs args.(Host.Instantiate.ChainParams) vm)
cold warm access write reserve Hrevision Hvm msg Hgas).
Qed.
Theorem execution_vm_preserves_destruction msg code :
0 ≤ Evmc.Message.t.gas msg < 2^63 →
preservesCallback destructionCovered (@Host.Instantiate.Vm.execute args msg code).
Proof.
intro Hgas.
assert (Hassembly : destructionHost (@Evmc.Instantiate.Host S.t (@recursiveArgs args)) ∧
destructionVm (@Evmc.Instantiate.Vm S.t (@recursiveArgs args))).
{ unfold Evmc.Instantiate.Host, Evmc.Instantiate.Vm,
Evmc.Instantiate._recursive_modules_Host_Vm.
generalize Evmc.Instantiate.recursive_module_fuel. intro fuel.
induction fuel as [|fuel IH].
- split.
+ apply host_constructor_destruction. intros nested body Hbound s Hbefore. exact Hbefore.
+ intros nested body Hbound s Hbefore. exact Hbefore.
- cbn [recursive_module_unroll fst snd]. split.
+ apply host_constructor_destruction. exact (proj2 IH).
+ apply vm_constructor_destruction. exact (proj1 IH). }
exact (proj2 Hassembly msg code Hgas).
Qed.
Local Opaque Evmc.Instantiate._recursive_modules_Host_Vm.
Theorem transaction_call_preserves_destruction tx msg :
0 ≤ Evmc.Message.t.gas msg < 2^63 →
preservesCallback destructionCovered (@E.Host.call_from_eoa F tx msg).
Proof.
intro Hgas. unfold E.Host.call_from_eoa.
cbv beta iota zeta delta [E.Instantiation Host.Instantiate.functor
Host.Instantiate.Instantiate_result.Host Host.Instantiate.Host
H.functor H.Make_result.call_from_eoa H.call_from_eoa].
eapply call_impl_preserves_destruction.
- exact Hrevision.
- intros nested body Hbound.
pose proof (execution_vm_preserves_destruction nested body Hbound) as Hvm.
cbv beta iota zeta delta [Host.Instantiate.Vm.execute Host.Instantiate.Vm] in Hvm |- ×.
exact Hvm.
- exact Hgas.
Qed.
Require Import RocqOfOCaml.RocqOfOCaml MonadVM.Execution.
Require Import QedkConcrete.hostframe QedkConcrete.hostaccountformat
QedkConcrete.vmhostframe QedkConcrete.recursiveassembly.
Require Import SetcodeConcrete.destructionframe SetcodeConcrete.vmcompleteframe
SetcodeConcrete.assembly SetcodeConcrete.vmprogress.
Set Default Goal Selector "!".
#[local] Hint Extern 100 (Basics.Unreachable _) ⇒
(apply Opaque.legacy_witness; Opaque.opaque_inhabit 64%nat) : typeclass_instances.
Local Open Scope Z_scope.
Module E := Execution.Make.
Definition destructionHost (host : Evmc.HOST (t := S.t)) :=
PrimitiveHostFrame host destructionCovered ∧
(∀ current source static gas, preservesCallback destructionCovered
(host.(Evmc.HOST.setcodefrom) current source static gas)) ∧
(∀ params, @setcodeGasProgress S.t (Vm.Make.Build_FArgs params host)) ∧
(∀ addr s, snd (host.(Evmc.HOST.get_code_size) addr s) = s) ∧
(∀ addr offset size s, snd (host.(Evmc.HOST.copy_code) addr offset size s) = s) ∧
(∀ s, snd (host.(Evmc.HOST.get_tx_context) s) = s) ∧
(∀ msg, 0 ≤ Evmc.Message.t.gas msg < 2^63 →
preservesCallback destructionCovered (host.(Evmc.HOST.call) msg)).
Definition destructionVm {T : Evmc.Vm_H_signature (t := S.t)}
(vm : Evmc.Vm.SIG (_fargs := Evmc.Vm.Build_FArgs T)) :=
∀ msg code, 0 ≤ Evmc.Message.t.gas msg < 2^63 →
preservesCallback destructionCovered (vm.(Evmc.Vm.SIG.execute) msg code).
Section Execution.
Context {F : E.FArgs}.
Local Abbreviation args := (@E.Instantiation_fargs F).
Local Abbreviation HostF := (@Evmc.Instantiate.HostF S.t (@recursiveArgs args)).
Local Abbreviation VmF := (@Evmc.Instantiate.VmF S.t (@recursiveArgs args)).
Context (cold warm access write reserve : N).
Context (Hrevision : E.Params.(Execution.Make_Params_signature.revision) =
Support.Variants.Revision.Setcode (cold, warm, access, write, reserve)).
Context (Hcold : (0 < cold)%N) (Hwarm : (0 < warm)%N).
Lemma vm_constructor_destruction host :
destructionHost host → destructionVm (VmF host).
Proof.
intros [Hprimitive [Hsetcode [Hprogress [Hsize [Hcopy [Hcontext Hcall]]]]]] msg code Hgas initial Hbefore.
cbn -[Vm.Make.execute destructionCovered].
eapply complete_execute_preserves with (property := destructionCovered).
- exact Hrevision.
- reflexivity.
- apply Hprogress.
- exact Hprimitive.
- exact Hsetcode.
- exact Hcall.
- exact Hcontext.
- exact Hsize.
- exact Hcopy.
- exact Hgas.
- exact Hbefore.
Qed.
Lemma host_constructor_destruction vm :
destructionVm vm → destructionHost (HostF vm).
Proof.
intro Hvm. split; [apply concrete_primitives_preserve_destruction|].
split; [intros; apply setcode_preserves_destruction|].
split.
- intro params. exact (@concrete_setcode_gas_progress args vm params
cold warm access write reserve Hrevision Hcold Hwarm).
- split; [intros; reflexivity|].
split; [intros; apply copy_code_read_only|].
split; [intros; reflexivity|].
intros msg Hgas. apply (@call_preserves_destruction
(H.Build_FArgs args.(Host.Instantiate.ChainParams) vm)
cold warm access write reserve Hrevision Hvm msg Hgas).
Qed.
Theorem execution_vm_preserves_destruction msg code :
0 ≤ Evmc.Message.t.gas msg < 2^63 →
preservesCallback destructionCovered (@Host.Instantiate.Vm.execute args msg code).
Proof.
intro Hgas.
assert (Hassembly : destructionHost (@Evmc.Instantiate.Host S.t (@recursiveArgs args)) ∧
destructionVm (@Evmc.Instantiate.Vm S.t (@recursiveArgs args))).
{ unfold Evmc.Instantiate.Host, Evmc.Instantiate.Vm,
Evmc.Instantiate._recursive_modules_Host_Vm.
generalize Evmc.Instantiate.recursive_module_fuel. intro fuel.
induction fuel as [|fuel IH].
- split.
+ apply host_constructor_destruction. intros nested body Hbound s Hbefore. exact Hbefore.
+ intros nested body Hbound s Hbefore. exact Hbefore.
- cbn [recursive_module_unroll fst snd]. split.
+ apply host_constructor_destruction. exact (proj2 IH).
+ apply vm_constructor_destruction. exact (proj1 IH). }
exact (proj2 Hassembly msg code Hgas).
Qed.
Local Opaque Evmc.Instantiate._recursive_modules_Host_Vm.
Theorem transaction_call_preserves_destruction tx msg :
0 ≤ Evmc.Message.t.gas msg < 2^63 →
preservesCallback destructionCovered (@E.Host.call_from_eoa F tx msg).
Proof.
intro Hgas. unfold E.Host.call_from_eoa.
cbv beta iota zeta delta [E.Instantiation Host.Instantiate.functor
Host.Instantiate.Instantiate_result.Host Host.Instantiate.Host
H.functor H.Make_result.call_from_eoa H.call_from_eoa].
eapply call_impl_preserves_destruction.
- exact Hrevision.
- intros nested body Hbound.
pose proof (execution_vm_preserves_destruction nested body Hbound) as Hvm.
cbv beta iota zeta delta [Host.Instantiate.Vm.execute Host.Instantiate.Vm] in Hvm |- ×.
exact Hvm.
- exact Hgas.
Qed.
At transaction entry the deletion list is empty. If a protected sender
is not created during this execution, it is absent from the deletion
list afterwards, even if it adopted code.
Corollary uncreated_sender_not_destroyed tx msg initial query :
0 ≤ Evmc.Message.t.gas msg < 2^63 →
S.t.self_destruct initial = nil →
let post := snd (@E.Host.call_from_eoa F tx msg initial) in
¬ In query (S.t.accounts_created_in_current_transaction post) →
¬ In query (S.t.self_destruct post).
Proof.
intros Hgas Hempty post HnotCreated Hdestroyed.
apply HnotCreated.
apply (transaction_call_preserves_destruction tx msg Hgas initial); [|exact Hdestroyed].
unfold destructionCovered. rewrite Hempty. intros a Ha. contradiction.
Qed.
End Execution.
Print Assumptions transaction_call_preserves_destruction.
Print Assumptions uncreated_sender_not_destroyed.
0 ≤ Evmc.Message.t.gas msg < 2^63 →
S.t.self_destruct initial = nil →
let post := snd (@E.Host.call_from_eoa F tx msg initial) in
¬ In query (S.t.accounts_created_in_current_transaction post) →
¬ In query (S.t.self_destruct post).
Proof.
intros Hgas Hempty post HnotCreated Hdestroyed.
apply HnotCreated.
apply (transaction_call_preserves_destruction tx msg Hgas initial); [|exact Hdestroyed].
unfold destructionCovered. rewrite Hempty. intros a Ha. contradiction.
Qed.
End Execution.
Print Assumptions transaction_call_preserves_destruction.
Print Assumptions uncreated_sender_not_destroyed.