Library SetcodeConcrete.executionreserve
Reserve protection through actual SETCODE transaction execution
From Stdlib Require Import List ZArith.
Require Import RocqOfOCaml.RocqOfOCaml MonadVM.Execution.
Require Import QedkConcrete.hostrollback QedkConcrete.hostcode QedkConcrete.hostframe.
Require Import SetcodeConcrete.reserve SetcodeConcrete.contextframe SetcodeConcrete.executioncontext
SetcodeConcrete.executiondestruction.
Set Default Goal Selector "!".
Local Open Scope Z_scope.
Module E := Execution.Make.
Lemma context_preserves_recent_sender before after query :
migrationContext after = migrationContext before →
Reserve_balance.sent_in_window after query = Reserve_balance.sent_in_window before query.
Proof.
unfold migrationContext, transactionContext. intro Hcontext.
injection Hcontext as Hsnapshot Hblock Hsender Hlimit Hprice Hhistory Hcounter Hprior Hchain.
unfold Reserve_balance.sent_in_window. rewrite Hblock, Hhistory, Hprior, Hchain. reflexivity.
Qed.
Lemma context_preserves_protected before after query original :
migrationContext after = migrationContext before →
protected after query original = protected before query original.
Proof.
unfold migrationContext, transactionContext. intro Hcontext.
injection Hcontext as Hsnapshot Hblock Hsender Hlimit Hprice Hhistory Hcounter Hprior Hchain.
unfold protected. rewrite Hsnapshot, Hblock. reflexivity.
Qed.
Section Execution.
Context {F : E.FArgs}.
Local Abbreviation args := (@E.Instantiation_fargs F).
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).
Require Import RocqOfOCaml.RocqOfOCaml MonadVM.Execution.
Require Import QedkConcrete.hostrollback QedkConcrete.hostcode QedkConcrete.hostframe.
Require Import SetcodeConcrete.reserve SetcodeConcrete.contextframe SetcodeConcrete.executioncontext
SetcodeConcrete.executiondestruction.
Set Default Goal Selector "!".
Local Open Scope Z_scope.
Module E := Execution.Make.
Lemma context_preserves_recent_sender before after query :
migrationContext after = migrationContext before →
Reserve_balance.sent_in_window after query = Reserve_balance.sent_in_window before query.
Proof.
unfold migrationContext, transactionContext. intro Hcontext.
injection Hcontext as Hsnapshot Hblock Hsender Hlimit Hprice Hhistory Hcounter Hprior Hchain.
unfold Reserve_balance.sent_in_window. rewrite Hblock, Hhistory, Hprior, Hchain. reflexivity.
Qed.
Lemma context_preserves_protected before after query original :
migrationContext after = migrationContext before →
protected after query original = protected before query original.
Proof.
unfold migrationContext, transactionContext. intro Hcontext.
injection Hcontext as Hsnapshot Hblock Hsender Hlimit Hprice Hhistory Hcounter Hprior Hchain.
unfold protected. rewrite Hsnapshot, Hblock. reflexivity.
Qed.
Section Execution.
Context {F : E.FArgs}.
Local Abbreviation args := (@E.Instantiation_fargs F).
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).
initial is the state passed to the VM, after the current sender's
fee debit and authorization processing. query is a different account
that sent a transaction in the execution window. Its entry balance must
cover its protected amount. The conclusion is the same lower bound
after this call; no condition on its resulting code is required.
The only final-execution premise is the approved CREATE exclusion:
query does not occur in the created-account list. No successful VM or
reserve-check result, and no non-deletion premise, is assumed.
Theorem transaction_call_protects_recent_sender tx msg initial query original :
0 ≤ Evmc.Message.t.gas msg < 2^63 →
S.t.self_destruct initial = nil →
In (query, original) (W.t.accounts (S.t.initial_world_state initial)) →
Addr.op_eq query (S.t.tx_origin initial) = false →
Reserve_balance.sent_in_window initial query = true →
protected initial query original ≤ A.t.balance (accountAt initial query) →
let post := snd (@E.Host.call_from_eoa F tx msg initial) in
¬ In query (S.t.accounts_created_in_current_transaction post) →
protected initial query original ≤ A.t.balance (accountAt post query).
Proof.
intros Hgas Hempty Hin Hother Hrecent Hentry post HnotCreated.
pose proof (transaction_call_preserves_migration_context cold warm access write reserve
Hrevision Hcold Hwarm tx msg Hgas initial) as Hcontext.
change (migrationContext post = migrationContext initial) in Hcontext.
pose proof (uncreated_sender_not_destroyed cold warm access write reserve
Hrevision Hcold Hwarm tx msg initial query Hgas Hempty HnotCreated) as HnotDestroyed.
assert (Hdes : Addr._Set.(OCamlSet.S.mem) query (S.t.self_destruct post) = false).
{ destruct (Addr._Set.(OCamlSet.S.mem) query (S.t.self_destruct post)) eqn:Hmem; [|reflexivity].
exfalso. apply HnotDestroyed, address_set_mem_member, Hmem. }
pose proof (@transaction_world_rollback_or_reserve
(@Host.Instantiate.Host_fargs args) tx msg initial) as Hresult.
change (S.t.world_state post = S.t.world_state initial ∨
fst (Reserve_balance.dipped_into_reserve
E.Params.(Execution.Make_Params_signature.revision) post) = false) in Hresult.
destruct Hresult as [Hrollback|Hcheck].
- unfold accountAt. rewrite Hrollback. exact Hentry.
- rewrite Hrevision in Hcheck.
rewrite <- (context_preserves_protected initial post query original Hcontext).
apply (recent_nonsender_retains_reserve (cold,warm,access,write,reserve)
post query original Hcheck).
+ unfold migrationContext, transactionContext in Hcontext.
injection Hcontext as Hsnapshot Hblock Hsender Hlimit Hprice Hhistory Hcounter Hprior Hchain.
rewrite Hsnapshot. exact Hin.
+ exact Hdes.
+ unfold migrationContext, transactionContext in Hcontext.
injection Hcontext as Hsnapshot Hblock Hsender Hlimit Hprice Hhistory Hcounter Hprior Hchain.
rewrite Hsender. exact Hother.
+ rewrite (context_preserves_recent_sender initial post query Hcontext). exact Hrecent.
Qed.
End Execution.
Print Assumptions transaction_call_protects_recent_sender.
0 ≤ Evmc.Message.t.gas msg < 2^63 →
S.t.self_destruct initial = nil →
In (query, original) (W.t.accounts (S.t.initial_world_state initial)) →
Addr.op_eq query (S.t.tx_origin initial) = false →
Reserve_balance.sent_in_window initial query = true →
protected initial query original ≤ A.t.balance (accountAt initial query) →
let post := snd (@E.Host.call_from_eoa F tx msg initial) in
¬ In query (S.t.accounts_created_in_current_transaction post) →
protected initial query original ≤ A.t.balance (accountAt post query).
Proof.
intros Hgas Hempty Hin Hother Hrecent Hentry post HnotCreated.
pose proof (transaction_call_preserves_migration_context cold warm access write reserve
Hrevision Hcold Hwarm tx msg Hgas initial) as Hcontext.
change (migrationContext post = migrationContext initial) in Hcontext.
pose proof (uncreated_sender_not_destroyed cold warm access write reserve
Hrevision Hcold Hwarm tx msg initial query Hgas Hempty HnotCreated) as HnotDestroyed.
assert (Hdes : Addr._Set.(OCamlSet.S.mem) query (S.t.self_destruct post) = false).
{ destruct (Addr._Set.(OCamlSet.S.mem) query (S.t.self_destruct post)) eqn:Hmem; [|reflexivity].
exfalso. apply HnotDestroyed, address_set_mem_member, Hmem. }
pose proof (@transaction_world_rollback_or_reserve
(@Host.Instantiate.Host_fargs args) tx msg initial) as Hresult.
change (S.t.world_state post = S.t.world_state initial ∨
fst (Reserve_balance.dipped_into_reserve
E.Params.(Execution.Make_Params_signature.revision) post) = false) in Hresult.
destruct Hresult as [Hrollback|Hcheck].
- unfold accountAt. rewrite Hrollback. exact Hentry.
- rewrite Hrevision in Hcheck.
rewrite <- (context_preserves_protected initial post query original Hcontext).
apply (recent_nonsender_retains_reserve (cold,warm,access,write,reserve)
post query original Hcheck).
+ unfold migrationContext, transactionContext in Hcontext.
injection Hcontext as Hsnapshot Hblock Hsender Hlimit Hprice Hhistory Hcounter Hprior Hchain.
rewrite Hsnapshot. exact Hin.
+ exact Hdes.
+ unfold migrationContext, transactionContext in Hcontext.
injection Hcontext as Hsnapshot Hblock Hsender Hlimit Hprice Hhistory Hcounter Hprior Hchain.
rewrite Hsender. exact Hother.
+ rewrite (context_preserves_recent_sender initial post query Hcontext). exact Hrecent.
Qed.
End Execution.
Print Assumptions transaction_call_protects_recent_sender.