Library SetcodeConcrete.contextframe
The reserve check reads the original transaction metadata
From Stdlib Require Import List ZArith.
Require Import RocqOfOCaml.RocqOfOCaml MonadVM.Host.
Require Import QedkConcrete.hostframe QedkConcrete.hostaccountformat
QedkConcrete.vmhostframe QedkConcrete.recursiveassembly
QedkConcrete.reserveprecompileproperties.
Set Default Goal Selector "!".
#[local] Hint Extern 100 (Basics.Unreachable _) ⇒
(apply Opaque.legacy_witness; Opaque.opaque_inhabit 64%nat) : typeclass_instances.
Require Import RocqOfOCaml.RocqOfOCaml MonadVM.Host.
Require Import QedkConcrete.hostframe QedkConcrete.hostaccountformat
QedkConcrete.vmhostframe QedkConcrete.recursiveassembly
QedkConcrete.reserveprecompileproperties.
Set Default Goal Selector "!".
#[local] Hint Extern 100 (Basics.Unreachable _) ⇒
(apply Opaque.legacy_witness; Opaque.opaque_inhabit 64%nat) : typeclass_instances.
These fields are fixed at transaction entry. Account state, storage,
created accounts and logs are deliberately not included.
Definition migrationContext (s : S.t) :=
(transactionContext s, S.t.prior_transactions s, S.t.tx_chain_id s).
Definition preservesMigrationContext {A : Set} (action : S.t → A × S.t) :=
∀ s, migrationContext (snd (action s)) = migrationContext s.
Lemma migration_bind {A B : Set} (action : S.t → A × S.t)
(next : A → S.t → B × S.t) :
preservesMigrationContext action →
(∀ value, preservesMigrationContext (next value)) →
preservesMigrationContext (S.M.(Monad.State.State_result.op_letdollar) action next).
Proof.
intros Haction Hnext s.
change (migrationContext (snd (let '(value, middle) := action s in next value middle)) = migrationContext s).
specialize (Haction s). destruct (action s) as [value middle].
rewrite Hnext. exact Haction.
Qed.
Lemma migration_return {A : Set} (value : A) :
preservesMigrationContext (S.M.(Monad.State.State_result._return) value).
Proof. intro s. reflexivity. Qed.
Lemma migration_read {A : Set} (lens : Lens.t S.t A) :
preservesMigrationContext (S.M.(Monad.State.State_result.op_exclamation) lens).
Proof. intro s. reflexivity. Qed.
Lemma migration_write {A : Set} (lens : Lens.t S.t A) value :
(∀ s, migrationContext (Lens.t.set lens value s) = migrationContext s) →
preservesMigrationContext (S.M.(Monad.State.State_result.op_coloneq) lens value).
Proof. exact (fun Hframe ⇒ Hframe). Qed.
Lemma migration_update {A : Set} (lens : Lens.t S.t A) f :
(∀ s value, migrationContext (Lens.t.set lens value s) = migrationContext s) →
preservesMigrationContext (S.M.(Monad.State.State_result.update_field) lens f).
Proof. intros Hframe s. apply Hframe. Qed.
Section Host.
Context {F : H.FArgs}.
Lemma transfer_preserves_migration_context sender recipient amount :
preservesMigrationContext (H.transfer_ether sender recipient amount).
Proof.
intro s. unfold H.transfer_ether. cbn -[Numeric.U256.op_gteq].
match goal with |- context [if ?test then _ else _] ⇒ destruct test end;
reflexivity.
Qed.
Lemma selfdestruct_preserves_migration_context addr beneficiary :
preservesMigrationContext (H.selfdestruct addr beneficiary).
Proof.
intro s. unfold H.selfdestruct. cbn -[H.transfer_ether].
match goal with |- context [H.transfer_ether ?from ?to ?amount ?before] ⇒
pose proof (transfer_preserves_migration_context from to amount before) as Htransfer;
destruct (H.transfer_ether from to amount before) as [ok middle] end.
destruct ok; cbn.
all: match goal with |- context [if ?test then _ else _] ⇒ destruct test end.
all: exact Htransfer.
Qed.
Lemma setcode_preserves_migration_context current source static gas :
preservesMigrationContext (H.setcodefrom current source static gas).
Proof.
intro s. unfold H.setcodefrom.
destruct H.ChainParams.(Chain.Monad.PARAMS.revision); try reflexivity.
match goal with prices : (_ × _ × _ × _ × _)%type |- _ ⇒
destruct prices as [[[[cold warm] access] write] reserve] end.
cbn beta iota zeta.
repeat match goal with |- context [if ?test then _ else _] ⇒
destruct test; cbn beta iota zeta end.
all: reflexivity.
Qed.
End Host.
Ltac solve_migration_frame :=
lazymatch goal with
| |- preservesMigrationContext (S.M.(Monad.State.State_result.op_letdollar) _ _) ⇒
apply migration_bind; [solve_migration_frame|];
let value := fresh "value" in intro value;
repeat match goal with x : _ × _ |- _ ⇒ destruct x end;
cbn beta iota zeta; solve_migration_frame
| |- preservesMigrationContext (S.M.(Monad.State.State_result._return) _) ⇒ apply migration_return
| |- preservesMigrationContext (S.M.(Monad.State.State_result.op_exclamation) _) ⇒ apply migration_read
| |- preservesMigrationContext (S.M.(Monad.State.State_result.op_coloneq) _ _) ⇒
apply migration_write; reflexivity
| |- preservesMigrationContext (S.M.(Monad.State.State_result.update_field) _ _) ⇒
apply migration_update; reflexivity
| |- preservesMigrationContext (if ?test then _ else _) ⇒ destruct test; solve_migration_frame
| |- preservesMigrationContext (match ?value with Some _ ⇒ _ | None ⇒ _ end) ⇒
destruct value; solve_migration_frame
| |- preservesMigrationContext (match ?status with Evmc.Result.StatusCode.Success ⇒ _ | _ ⇒ _ end) ⇒
destruct status; solve_migration_frame
| |- preservesMigrationContext (@H.transfer_ether _ _ _ _) ⇒ apply transfer_preserves_migration_context
| Hvm : ∀ msg code, _ → preservesMigrationContext (_ msg code)
|- preservesMigrationContext (_ ?msg ?code) ⇒ apply Hvm; assumption
end.
Section Native.
Context {F : Reserve_balance_introspection.Make.FArgs}.
Lemma reserve_precompile_preserves_migration_context msg :
preservesMigrationContext (Reserve_balance_introspection.Make.precompile msg).
Proof.
intro s. change (migrationContext (snd (@Reserve_balance_introspection.Make.precompile F msg s)) = migrationContext s).
pose proof (@precompile_preserves_context F msg s) as Hcontext.
change (transactionContext (snd (@Reserve_balance_introspection.Make.precompile F msg s)) = transactionContext s) in Hcontext.
destruct (@precompile_world_effect F msg s) as [Hsame|[value [world [Hwrite Hafter]]]].
- rewrite Hsame. reflexivity.
- rewrite Hafter in Hcontext |- ×. unfold migrationContext.
rewrite Hcontext. reflexivity.
Qed.
End Native.
Section Dispatch.
Context {F : Precompiles.Make.FArgs}.
Local Lemma singleton_value {A : Set} key (value : A) query result :
Chain.Ethereum.Address.Map.find_opt query
(Chain.Ethereum.Address.Map.of_list ((key, value) :: nil)) = Some result → result = value.
Proof.
change (OCamlMap.Make.find_opt stringmaps.stringOrder query ((key, value) :: nil) = Some result → result = value).
cbn [OCamlMap.Make.find_opt].
destruct (OCamlMap.Make.key_before stringmaps.stringOrder query key); [discriminate|].
destruct (OCamlMap.Make.key_equal stringmaps.stringOrder query key); [|discriminate].
intro Heq. inversion Heq. reflexivity.
Qed.
Lemma precompile_preserves_migration_context cold warm access write reserve msg addr action :
Precompiles.Make.Revision.(Precompiles.Make_Revision_signature.revision) =
Support.Variants.Revision.Setcode (cold, warm, access, write, reserve) →
Precompiles.Make.try_precompile msg addr = Some action →
preservesMigrationContext action.
Proof.
intros Hrevision Hselected. unfold Precompiles.Make.try_precompile in Hselected.
match type of Hselected with context [@Chain.Ethereum.Address.Map.find_opt ?T addr ?entries] ⇒
destruct (@Chain.Ethereum.Address.Map.find_opt T addr entries) as [pure|] eqn:Hethereum in Hselected end.
- destruct (Evmc.Message.t.delegated msg) in Hselected;
inversion Hselected; subst action; apply migration_return.
- unfold Precompiles.Make.monad_precompiles in Hselected. rewrite Hrevision in Hselected.
match type of Hselected with context [@Chain.Ethereum.Address.Map.find_opt ?T addr ?entries] ⇒
destruct (@Chain.Ethereum.Address.Map.find_opt T addr entries) as [native|] eqn:Hnative in Hselected end.
2: discriminate.
apply singleton_value in Hnative. subst native.
match type of Hselected with context [if ?reject then _ else _] ⇒ destruct reject in Hselected end.
+ inversion Hselected; subst action. apply migration_return.
+ inversion Hselected; subst action. apply reserve_precompile_preserves_migration_context.
Qed.
End Dispatch.
Section Calls.
Context {F : H.FArgs}.
Context (cold warm access write reserve : N).
Context (Hrevision : H.ChainParams.(Chain.Monad.PARAMS.revision) =
Support.Variants.Revision.Setcode (cold, warm, access, write, reserve)).
Context (Hvm : ∀ msg code, (0 ≤ Evmc.Message.t.gas msg < 2^63)%Z →
preservesMigrationContext (H.Vm.(Evmc.Vm.SIG.execute) msg code)).
Lemma process_create_preserves_migration_context msg :
(0 ≤ Evmc.Message.t.gas msg < 2^63)%Z →
preservesMigrationContext (H.process_create msg).
Proof.
intro Hgas. unfold H.process_create, H.M.
apply migration_bind.
- unfold H.contract_creation_address, H.M. solve_migration_frame.
- intro addr. solve_migration_frame.
Qed.
Lemma process_call_preserves_migration_context from_tx msg :
(0 ≤ Evmc.Message.t.gas msg < 2^63)%Z →
preservesMigrationContext (H.process_call from_tx msg).
Proof.
intro Hgas. unfold H.process_call, H.M. cbn zeta.
apply migration_bind.
- destruct (H.should_transfer msg); [apply transfer_preserves_migration_context|apply migration_return].
- intros ok. destruct ok; [|apply migration_return].
apply migration_bind.
+ apply migration_bind; [apply migration_read|]. intro code.
destruct from_tx; destruct (Delegation.get_delegated_address code); solve_migration_frame.
+ intros [addr code].
match goal with |- preservesMigrationContext (match ?selection with Some _ ⇒ _ | None ⇒ _ end) ⇒
destruct selection as [action|] eqn:Hselected end.
× exact (@precompile_preserves_migration_context (@H.Precompiles_fargs F)
cold warm access write reserve msg addr action Hrevision Hselected).
× apply Hvm. exact Hgas.
Qed.
Lemma call_impl_preserves_migration_context from_tx msg :
(0 ≤ Evmc.Message.t.gas msg < 2^63)%Z →
preservesMigrationContext (H.call_impl from_tx msg).
Proof.
intros Hgas s.
pose proof (process_call_preserves_migration_context from_tx msg Hgas) as Hcall.
pose proof (process_create_preserves_migration_context msg Hgas) as Hcreate.
unfold H.call_impl. destruct (Evmc.Message.t.kind msg);
cbn -[H.process_call H.process_create
Chain.Ethereum.Address.of_contract_creation Reserve_balance.dipped_into_reserve].
all: match goal with |- context [Monad.Identity.Impl.op_gtgteq ?run _] ⇒
assert (Hcore : migrationContext (snd run) = migrationContext s) by
(etransitivity; [first [apply Hcall|apply Hcreate]|reflexivity]);
destruct run as [result intermediate] eqn:Hrun end.
all: destruct result as [status gasleft refund output address].
all: destruct from_tx as [tx|]; destruct status;
cbn -[Reserve_balance.dipped_into_reserve];
unfold Monad.Make_Monad.when_; cbn -[Reserve_balance.dipped_into_reserve];
try reflexivity; try exact Hcore.
all: match goal with
| |- context [Monad.Identity.Impl.op_gtgteq (Monad.Identity.Impl.op_gtgteq ?check _) _] ⇒
assert (Hcheck : snd check = intermediate) by reflexivity;
destruct check as [dipped checked]; cbn [snd] in Hcheck; subst checked end.
all: destruct dipped; cbn; [reflexivity|exact Hcore].
Qed.
Lemma call_preserves_migration_context msg :
(0 ≤ Evmc.Message.t.gas msg < 2^63)%Z →
preservesMigrationContext (H.call msg).
Proof.
intro Hgas. unfold H.call, H.M. apply migration_bind.
- match goal with |- preservesMigrationContext (if ?test then _ else _) ⇒ destruct test end.
+ unfold H.try_increment_nonce, H.M. solve_migration_frame.
+ apply migration_return.
- intros ok. destruct ok; [apply call_impl_preserves_migration_context; exact Hgas|apply migration_return].
Qed.
End Calls.
Section Primitives.
Context {F : Host.Instantiate.FArgs}.
Local Abbreviation HostF := (@Evmc.Instantiate.HostF S.t (@recursiveArgs F)).
Lemma concrete_primitives_preserve_migration_context vm initial :
PrimitiveHostFrame (HostF vm)
(fun s ⇒ migrationContext s = migrationContext initial).
Proof.
constructor; intros.
all: cbn -[H.account_exists H.get_balance H.access_account H.get_storage
H.set_storage H.access_storage H.get_transient_storage H.set_transient_storage
H.get_code_size H.get_code_hash H.copy_code H.get_block_hash H.emit_log
H.selfdestruct migrationContext].
all: intros s Hinitial; transitivity (migrationContext s); [|exact Hinitial].
all: first [reflexivity | apply selfdestruct_preserves_migration_context |
rewrite copy_code_read_only; reflexivity |
unfold H.access_account, H.access_storage;
cbn -[W.account];
repeat match goal with |- context [if ?test then _ else _] ⇒ destruct test end;
reflexivity].
Qed.
End Primitives.
Print Assumptions call_preserves_migration_context.
(transactionContext s, S.t.prior_transactions s, S.t.tx_chain_id s).
Definition preservesMigrationContext {A : Set} (action : S.t → A × S.t) :=
∀ s, migrationContext (snd (action s)) = migrationContext s.
Lemma migration_bind {A B : Set} (action : S.t → A × S.t)
(next : A → S.t → B × S.t) :
preservesMigrationContext action →
(∀ value, preservesMigrationContext (next value)) →
preservesMigrationContext (S.M.(Monad.State.State_result.op_letdollar) action next).
Proof.
intros Haction Hnext s.
change (migrationContext (snd (let '(value, middle) := action s in next value middle)) = migrationContext s).
specialize (Haction s). destruct (action s) as [value middle].
rewrite Hnext. exact Haction.
Qed.
Lemma migration_return {A : Set} (value : A) :
preservesMigrationContext (S.M.(Monad.State.State_result._return) value).
Proof. intro s. reflexivity. Qed.
Lemma migration_read {A : Set} (lens : Lens.t S.t A) :
preservesMigrationContext (S.M.(Monad.State.State_result.op_exclamation) lens).
Proof. intro s. reflexivity. Qed.
Lemma migration_write {A : Set} (lens : Lens.t S.t A) value :
(∀ s, migrationContext (Lens.t.set lens value s) = migrationContext s) →
preservesMigrationContext (S.M.(Monad.State.State_result.op_coloneq) lens value).
Proof. exact (fun Hframe ⇒ Hframe). Qed.
Lemma migration_update {A : Set} (lens : Lens.t S.t A) f :
(∀ s value, migrationContext (Lens.t.set lens value s) = migrationContext s) →
preservesMigrationContext (S.M.(Monad.State.State_result.update_field) lens f).
Proof. intros Hframe s. apply Hframe. Qed.
Section Host.
Context {F : H.FArgs}.
Lemma transfer_preserves_migration_context sender recipient amount :
preservesMigrationContext (H.transfer_ether sender recipient amount).
Proof.
intro s. unfold H.transfer_ether. cbn -[Numeric.U256.op_gteq].
match goal with |- context [if ?test then _ else _] ⇒ destruct test end;
reflexivity.
Qed.
Lemma selfdestruct_preserves_migration_context addr beneficiary :
preservesMigrationContext (H.selfdestruct addr beneficiary).
Proof.
intro s. unfold H.selfdestruct. cbn -[H.transfer_ether].
match goal with |- context [H.transfer_ether ?from ?to ?amount ?before] ⇒
pose proof (transfer_preserves_migration_context from to amount before) as Htransfer;
destruct (H.transfer_ether from to amount before) as [ok middle] end.
destruct ok; cbn.
all: match goal with |- context [if ?test then _ else _] ⇒ destruct test end.
all: exact Htransfer.
Qed.
Lemma setcode_preserves_migration_context current source static gas :
preservesMigrationContext (H.setcodefrom current source static gas).
Proof.
intro s. unfold H.setcodefrom.
destruct H.ChainParams.(Chain.Monad.PARAMS.revision); try reflexivity.
match goal with prices : (_ × _ × _ × _ × _)%type |- _ ⇒
destruct prices as [[[[cold warm] access] write] reserve] end.
cbn beta iota zeta.
repeat match goal with |- context [if ?test then _ else _] ⇒
destruct test; cbn beta iota zeta end.
all: reflexivity.
Qed.
End Host.
Ltac solve_migration_frame :=
lazymatch goal with
| |- preservesMigrationContext (S.M.(Monad.State.State_result.op_letdollar) _ _) ⇒
apply migration_bind; [solve_migration_frame|];
let value := fresh "value" in intro value;
repeat match goal with x : _ × _ |- _ ⇒ destruct x end;
cbn beta iota zeta; solve_migration_frame
| |- preservesMigrationContext (S.M.(Monad.State.State_result._return) _) ⇒ apply migration_return
| |- preservesMigrationContext (S.M.(Monad.State.State_result.op_exclamation) _) ⇒ apply migration_read
| |- preservesMigrationContext (S.M.(Monad.State.State_result.op_coloneq) _ _) ⇒
apply migration_write; reflexivity
| |- preservesMigrationContext (S.M.(Monad.State.State_result.update_field) _ _) ⇒
apply migration_update; reflexivity
| |- preservesMigrationContext (if ?test then _ else _) ⇒ destruct test; solve_migration_frame
| |- preservesMigrationContext (match ?value with Some _ ⇒ _ | None ⇒ _ end) ⇒
destruct value; solve_migration_frame
| |- preservesMigrationContext (match ?status with Evmc.Result.StatusCode.Success ⇒ _ | _ ⇒ _ end) ⇒
destruct status; solve_migration_frame
| |- preservesMigrationContext (@H.transfer_ether _ _ _ _) ⇒ apply transfer_preserves_migration_context
| Hvm : ∀ msg code, _ → preservesMigrationContext (_ msg code)
|- preservesMigrationContext (_ ?msg ?code) ⇒ apply Hvm; assumption
end.
Section Native.
Context {F : Reserve_balance_introspection.Make.FArgs}.
Lemma reserve_precompile_preserves_migration_context msg :
preservesMigrationContext (Reserve_balance_introspection.Make.precompile msg).
Proof.
intro s. change (migrationContext (snd (@Reserve_balance_introspection.Make.precompile F msg s)) = migrationContext s).
pose proof (@precompile_preserves_context F msg s) as Hcontext.
change (transactionContext (snd (@Reserve_balance_introspection.Make.precompile F msg s)) = transactionContext s) in Hcontext.
destruct (@precompile_world_effect F msg s) as [Hsame|[value [world [Hwrite Hafter]]]].
- rewrite Hsame. reflexivity.
- rewrite Hafter in Hcontext |- ×. unfold migrationContext.
rewrite Hcontext. reflexivity.
Qed.
End Native.
Section Dispatch.
Context {F : Precompiles.Make.FArgs}.
Local Lemma singleton_value {A : Set} key (value : A) query result :
Chain.Ethereum.Address.Map.find_opt query
(Chain.Ethereum.Address.Map.of_list ((key, value) :: nil)) = Some result → result = value.
Proof.
change (OCamlMap.Make.find_opt stringmaps.stringOrder query ((key, value) :: nil) = Some result → result = value).
cbn [OCamlMap.Make.find_opt].
destruct (OCamlMap.Make.key_before stringmaps.stringOrder query key); [discriminate|].
destruct (OCamlMap.Make.key_equal stringmaps.stringOrder query key); [|discriminate].
intro Heq. inversion Heq. reflexivity.
Qed.
Lemma precompile_preserves_migration_context cold warm access write reserve msg addr action :
Precompiles.Make.Revision.(Precompiles.Make_Revision_signature.revision) =
Support.Variants.Revision.Setcode (cold, warm, access, write, reserve) →
Precompiles.Make.try_precompile msg addr = Some action →
preservesMigrationContext action.
Proof.
intros Hrevision Hselected. unfold Precompiles.Make.try_precompile in Hselected.
match type of Hselected with context [@Chain.Ethereum.Address.Map.find_opt ?T addr ?entries] ⇒
destruct (@Chain.Ethereum.Address.Map.find_opt T addr entries) as [pure|] eqn:Hethereum in Hselected end.
- destruct (Evmc.Message.t.delegated msg) in Hselected;
inversion Hselected; subst action; apply migration_return.
- unfold Precompiles.Make.monad_precompiles in Hselected. rewrite Hrevision in Hselected.
match type of Hselected with context [@Chain.Ethereum.Address.Map.find_opt ?T addr ?entries] ⇒
destruct (@Chain.Ethereum.Address.Map.find_opt T addr entries) as [native|] eqn:Hnative in Hselected end.
2: discriminate.
apply singleton_value in Hnative. subst native.
match type of Hselected with context [if ?reject then _ else _] ⇒ destruct reject in Hselected end.
+ inversion Hselected; subst action. apply migration_return.
+ inversion Hselected; subst action. apply reserve_precompile_preserves_migration_context.
Qed.
End Dispatch.
Section Calls.
Context {F : H.FArgs}.
Context (cold warm access write reserve : N).
Context (Hrevision : H.ChainParams.(Chain.Monad.PARAMS.revision) =
Support.Variants.Revision.Setcode (cold, warm, access, write, reserve)).
Context (Hvm : ∀ msg code, (0 ≤ Evmc.Message.t.gas msg < 2^63)%Z →
preservesMigrationContext (H.Vm.(Evmc.Vm.SIG.execute) msg code)).
Lemma process_create_preserves_migration_context msg :
(0 ≤ Evmc.Message.t.gas msg < 2^63)%Z →
preservesMigrationContext (H.process_create msg).
Proof.
intro Hgas. unfold H.process_create, H.M.
apply migration_bind.
- unfold H.contract_creation_address, H.M. solve_migration_frame.
- intro addr. solve_migration_frame.
Qed.
Lemma process_call_preserves_migration_context from_tx msg :
(0 ≤ Evmc.Message.t.gas msg < 2^63)%Z →
preservesMigrationContext (H.process_call from_tx msg).
Proof.
intro Hgas. unfold H.process_call, H.M. cbn zeta.
apply migration_bind.
- destruct (H.should_transfer msg); [apply transfer_preserves_migration_context|apply migration_return].
- intros ok. destruct ok; [|apply migration_return].
apply migration_bind.
+ apply migration_bind; [apply migration_read|]. intro code.
destruct from_tx; destruct (Delegation.get_delegated_address code); solve_migration_frame.
+ intros [addr code].
match goal with |- preservesMigrationContext (match ?selection with Some _ ⇒ _ | None ⇒ _ end) ⇒
destruct selection as [action|] eqn:Hselected end.
× exact (@precompile_preserves_migration_context (@H.Precompiles_fargs F)
cold warm access write reserve msg addr action Hrevision Hselected).
× apply Hvm. exact Hgas.
Qed.
Lemma call_impl_preserves_migration_context from_tx msg :
(0 ≤ Evmc.Message.t.gas msg < 2^63)%Z →
preservesMigrationContext (H.call_impl from_tx msg).
Proof.
intros Hgas s.
pose proof (process_call_preserves_migration_context from_tx msg Hgas) as Hcall.
pose proof (process_create_preserves_migration_context msg Hgas) as Hcreate.
unfold H.call_impl. destruct (Evmc.Message.t.kind msg);
cbn -[H.process_call H.process_create
Chain.Ethereum.Address.of_contract_creation Reserve_balance.dipped_into_reserve].
all: match goal with |- context [Monad.Identity.Impl.op_gtgteq ?run _] ⇒
assert (Hcore : migrationContext (snd run) = migrationContext s) by
(etransitivity; [first [apply Hcall|apply Hcreate]|reflexivity]);
destruct run as [result intermediate] eqn:Hrun end.
all: destruct result as [status gasleft refund output address].
all: destruct from_tx as [tx|]; destruct status;
cbn -[Reserve_balance.dipped_into_reserve];
unfold Monad.Make_Monad.when_; cbn -[Reserve_balance.dipped_into_reserve];
try reflexivity; try exact Hcore.
all: match goal with
| |- context [Monad.Identity.Impl.op_gtgteq (Monad.Identity.Impl.op_gtgteq ?check _) _] ⇒
assert (Hcheck : snd check = intermediate) by reflexivity;
destruct check as [dipped checked]; cbn [snd] in Hcheck; subst checked end.
all: destruct dipped; cbn; [reflexivity|exact Hcore].
Qed.
Lemma call_preserves_migration_context msg :
(0 ≤ Evmc.Message.t.gas msg < 2^63)%Z →
preservesMigrationContext (H.call msg).
Proof.
intro Hgas. unfold H.call, H.M. apply migration_bind.
- match goal with |- preservesMigrationContext (if ?test then _ else _) ⇒ destruct test end.
+ unfold H.try_increment_nonce, H.M. solve_migration_frame.
+ apply migration_return.
- intros ok. destruct ok; [apply call_impl_preserves_migration_context; exact Hgas|apply migration_return].
Qed.
End Calls.
Section Primitives.
Context {F : Host.Instantiate.FArgs}.
Local Abbreviation HostF := (@Evmc.Instantiate.HostF S.t (@recursiveArgs F)).
Lemma concrete_primitives_preserve_migration_context vm initial :
PrimitiveHostFrame (HostF vm)
(fun s ⇒ migrationContext s = migrationContext initial).
Proof.
constructor; intros.
all: cbn -[H.account_exists H.get_balance H.access_account H.get_storage
H.set_storage H.access_storage H.get_transient_storage H.set_transient_storage
H.get_code_size H.get_code_hash H.copy_code H.get_block_hash H.emit_log
H.selfdestruct migrationContext].
all: intros s Hinitial; transitivity (migrationContext s); [|exact Hinitial].
all: first [reflexivity | apply selfdestruct_preserves_migration_context |
rewrite copy_code_read_only; reflexivity |
unfold H.access_account, H.access_storage;
cbn -[W.account];
repeat match goal with |- context [if ?test then _ else _] ⇒ destruct test end;
reflexivity].
Qed.
End Primitives.
Print Assumptions call_preserves_migration_context.