Library QedkConcrete.uncreatednoncehost
From Stdlib Require Import List String ZArith.
Require Import RocqOfOCaml.RocqOfOCaml.
Require Import QedkConcrete.uncreatednonce QedkConcrete.uncreatednoncecreate
QedkConcrete.persistentnoncehost QedkConcrete.creationassembly QedkConcrete.nondebitframe
QedkConcrete.hostnonce QedkConcrete.nativenonce QedkConcrete.vmhostframe QedkConcrete.vmcallframe
QedkConcrete.persistentcode QedkConcrete.hostframe QedkConcrete.hostcode
QedkConcrete.hostsupply QedkConcrete.hostbalance QedkConcrete.contexthostinstance
QedkConcrete.assemblychecked QedkConcrete.creationhost.
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.
Section Host.
Context {F : Host.Instantiate.FArgs}.
Local Abbreviation U64 := (Opaque.legacy_witness 0%Z).
Local Abbreviation UF := (Opaque.legacy_witness 0%Z).
Local Abbreviation protected := (@uncreatedNonce).
Local Abbreviation HostF := (@Evmc.Instantiate.HostF S.t (@recursiveArgs F)).
Context (vm : Evmc.Vm.SIG (_fargs := Evmc.Vm.Build_FArgs (@Evmc.Instantiate.T S.t (@recursiveArgs F)))).
Local Abbreviation native := (@Reserve_balance.precompile_address).
Lemma native_preserves_uncreated_nonce query nonce msg addr action :
query ≠ native →
F.(Host.Instantiate.ChainParams).(Chain.Monad.PARAMS.revision) = Support.Variants.Revision.Eleven →
nativeDispatch vm msg addr = Some action →
preservesCallback (protected query nonce) action.
Proof.
intros Hdifferent Hrevision Hselected. apply uncreated_nonce_callback.
- exact (@native_preserves_creation F vm msg addr action Hrevision Hselected).
- exact (@native_preserves_other_nonce F vm query nonce msg addr action Hdifferent Hrevision Hselected).
Qed.
Lemma concrete_primitives_preserve_uncreated_nonce query nonce :
PrimitiveHostFrame (HostF vm) (protected query nonce).
Proof.
pose proof (@concrete_primitives_preserve_nonce F vm query nonce) as Hnonce.
assert (Hcreation : ∀ initial, PrimitiveHostFrame (HostF vm)
(@creationInvariant initial)) by (apply concrete_primitives_preserve_creation).
constructor; intros; apply uncreated_nonce_callback.
all: try solve [destruct Hnonce; eauto].
all: intros s Hwf.
all: assert (Hstart : @creationInvariant s s) by
(split; [exact Hwf|apply creation_frame_refl]).
all: destruct (Hcreation s); unfold preservesCallback in ×.
all: match goal with |- _ ∧ creationFrame _ ?after ⇒
change (@creationInvariant s after) end.
all: eauto.
Qed.
Lemma concrete_primitives_preserve_still_uncreated_nonce query nonce :
PrimitiveHostFrame (HostF vm) (fun s ⇒ protected query nonce s ∧
¬ List.In query (S.t.accounts_created_in_current_transaction s)).
Proof.
pose proof (concrete_primitives_preserve_uncreated_nonce query nonce) as Hnonce.
assert (Hset : ∀ initial, PrimitiveHostFrame (HostF vm) (fun s ⇒
S.t.accounts_created_in_current_transaction s = S.t.accounts_created_in_current_transaction initial))
by (apply concrete_primitives_preserve_creation_set).
constructor; intros; intros s [Hinitial Hnot]; split.
all: first [solve [destruct Hnonce; unfold preservesCallback in *; eauto] |
solve [destruct (Hset s); unfold preservesCallback in *;
match goal with |- ¬ List.In _ ?created ⇒
assert (Heq : created = S.t.accounts_created_in_current_transaction s) by eauto;
rewrite Heq; exact Hnot end]].
Qed.
Local Abbreviation processCall := (@H.process_call (H.Build_FArgs F.(Host.Instantiate.ChainParams) vm) ).
Local Abbreviation callImpl := (@H.call_impl (H.Build_FArgs F.(Host.Instantiate.ChainParams) vm) ).
Local Abbreviation hostCall := (@H.call (H.Build_FArgs F.(Host.Instantiate.ChainParams) vm) ).
Lemma process_call_preserves_uncreated_nonce from_tx query nonce msg :
(∀ addr action, nativeDispatch vm msg addr = Some action →
preservesCallback (protected query nonce) action) →
(Evmc.Message.t.recipient msg = query → Evmc.Message.t.code_address msg = query) →
(∀ code s, protected query nonce s →
(Evmc.Message.t.recipient msg = query →
code = Byte_string.Bytes.empty ∨ List.In query (S.t.accounts_created_in_current_transaction s)) →
protected query nonce (snd (vm.(Evmc.Vm.SIG.execute) msg code s))) →
preservesCallback (protected query nonce) (processCall from_tx msg).
Proof.
intros Hnative HcodeAddress Hvm s Hinitial.
assert (Htransfer : protected query nonce (snd
((if @H.should_transfer (H.Build_FArgs F.(Host.Instantiate.ChainParams) vm) msg
then @H.transfer_ether (H.Build_FArgs F.(Host.Instantiate.ChainParams) vm)
(Evmc.Message.t.sender msg) (Evmc.Message.t.recipient msg) (Evmc.Message.t.value msg)
else fun st ⇒ (true, st)) s))).
{ destruct (H.should_transfer msg); [apply transfer_preserves_uncreated_nonce|]; exact Hinitial. }
unfold H.process_call, H.M.
cbn -[H.should_transfer H.transfer_ether W.account Precompiles.Make.try_precompile].
match goal with |- context [Monad.Identity.Impl.op_gtgteq ?run _] ⇒
assert (Hmiddle : protected query nonce (snd run)) by exact Htransfer;
destruct run as [ok middle] eqn:Hrun end.
cbn beta iota zeta delta [snd] in Hmiddle.
destruct ok; [|exact Hmiddle].
destruct from_tx as [tx|].
all: cbn -[W.account Precompiles.Make.try_precompile Delegation.get_delegated_address].
all: try match goal with |- context [@Delegation.get_delegated_address ?bytes] ⇒
destruct (@Delegation.get_delegated_address bytes) as [delegated|] eqn:Hdelegation end.
all: cbn -[W.account Precompiles.Make.try_precompile].
all: match goal with |- context [match ?selection with Some _ ⇒ _ | None ⇒ _ end] ⇒
destruct selection as [action|] eqn:Hselected end.
all: try (eapply Hnative; eassumption).
all: apply Hvm; [exact Hmiddle|].
all: intro Hrecipient;
destruct (List.in_dec String.string_dec query
(S.t.accounts_created_in_current_transaction middle)) as [Hin|Hnot];
[right; exact Hin|left].
all: pose proof (proj2 (uncreated_nonce_not_created query nonce middle Hmiddle Hnot)) as Hempty;
first [rewrite (HcodeAddress Hrecipient); exact Hempty|idtac].
exfalso. match type of Hdelegation with
| @Delegation.get_delegated_address ?bytes = Some _ ⇒
assert (Hbytes : bytes = Byte_string.Bytes.empty) by
(rewrite (HcodeAddress Hrecipient); exact Hempty);
pose proof (eq_trans
(eq_sym (f_equal (@Delegation.get_delegated_address) Hbytes))
Hdelegation) as Hfalse;
discriminate Hfalse
end.
Qed.
Require Import RocqOfOCaml.RocqOfOCaml.
Require Import QedkConcrete.uncreatednonce QedkConcrete.uncreatednoncecreate
QedkConcrete.persistentnoncehost QedkConcrete.creationassembly QedkConcrete.nondebitframe
QedkConcrete.hostnonce QedkConcrete.nativenonce QedkConcrete.vmhostframe QedkConcrete.vmcallframe
QedkConcrete.persistentcode QedkConcrete.hostframe QedkConcrete.hostcode
QedkConcrete.hostsupply QedkConcrete.hostbalance QedkConcrete.contexthostinstance
QedkConcrete.assemblychecked QedkConcrete.creationhost.
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.
Section Host.
Context {F : Host.Instantiate.FArgs}.
Local Abbreviation U64 := (Opaque.legacy_witness 0%Z).
Local Abbreviation UF := (Opaque.legacy_witness 0%Z).
Local Abbreviation protected := (@uncreatedNonce).
Local Abbreviation HostF := (@Evmc.Instantiate.HostF S.t (@recursiveArgs F)).
Context (vm : Evmc.Vm.SIG (_fargs := Evmc.Vm.Build_FArgs (@Evmc.Instantiate.T S.t (@recursiveArgs F)))).
Local Abbreviation native := (@Reserve_balance.precompile_address).
Lemma native_preserves_uncreated_nonce query nonce msg addr action :
query ≠ native →
F.(Host.Instantiate.ChainParams).(Chain.Monad.PARAMS.revision) = Support.Variants.Revision.Eleven →
nativeDispatch vm msg addr = Some action →
preservesCallback (protected query nonce) action.
Proof.
intros Hdifferent Hrevision Hselected. apply uncreated_nonce_callback.
- exact (@native_preserves_creation F vm msg addr action Hrevision Hselected).
- exact (@native_preserves_other_nonce F vm query nonce msg addr action Hdifferent Hrevision Hselected).
Qed.
Lemma concrete_primitives_preserve_uncreated_nonce query nonce :
PrimitiveHostFrame (HostF vm) (protected query nonce).
Proof.
pose proof (@concrete_primitives_preserve_nonce F vm query nonce) as Hnonce.
assert (Hcreation : ∀ initial, PrimitiveHostFrame (HostF vm)
(@creationInvariant initial)) by (apply concrete_primitives_preserve_creation).
constructor; intros; apply uncreated_nonce_callback.
all: try solve [destruct Hnonce; eauto].
all: intros s Hwf.
all: assert (Hstart : @creationInvariant s s) by
(split; [exact Hwf|apply creation_frame_refl]).
all: destruct (Hcreation s); unfold preservesCallback in ×.
all: match goal with |- _ ∧ creationFrame _ ?after ⇒
change (@creationInvariant s after) end.
all: eauto.
Qed.
Lemma concrete_primitives_preserve_still_uncreated_nonce query nonce :
PrimitiveHostFrame (HostF vm) (fun s ⇒ protected query nonce s ∧
¬ List.In query (S.t.accounts_created_in_current_transaction s)).
Proof.
pose proof (concrete_primitives_preserve_uncreated_nonce query nonce) as Hnonce.
assert (Hset : ∀ initial, PrimitiveHostFrame (HostF vm) (fun s ⇒
S.t.accounts_created_in_current_transaction s = S.t.accounts_created_in_current_transaction initial))
by (apply concrete_primitives_preserve_creation_set).
constructor; intros; intros s [Hinitial Hnot]; split.
all: first [solve [destruct Hnonce; unfold preservesCallback in *; eauto] |
solve [destruct (Hset s); unfold preservesCallback in *;
match goal with |- ¬ List.In _ ?created ⇒
assert (Heq : created = S.t.accounts_created_in_current_transaction s) by eauto;
rewrite Heq; exact Hnot end]].
Qed.
Local Abbreviation processCall := (@H.process_call (H.Build_FArgs F.(Host.Instantiate.ChainParams) vm) ).
Local Abbreviation callImpl := (@H.call_impl (H.Build_FArgs F.(Host.Instantiate.ChainParams) vm) ).
Local Abbreviation hostCall := (@H.call (H.Build_FArgs F.(Host.Instantiate.ChainParams) vm) ).
Lemma process_call_preserves_uncreated_nonce from_tx query nonce msg :
(∀ addr action, nativeDispatch vm msg addr = Some action →
preservesCallback (protected query nonce) action) →
(Evmc.Message.t.recipient msg = query → Evmc.Message.t.code_address msg = query) →
(∀ code s, protected query nonce s →
(Evmc.Message.t.recipient msg = query →
code = Byte_string.Bytes.empty ∨ List.In query (S.t.accounts_created_in_current_transaction s)) →
protected query nonce (snd (vm.(Evmc.Vm.SIG.execute) msg code s))) →
preservesCallback (protected query nonce) (processCall from_tx msg).
Proof.
intros Hnative HcodeAddress Hvm s Hinitial.
assert (Htransfer : protected query nonce (snd
((if @H.should_transfer (H.Build_FArgs F.(Host.Instantiate.ChainParams) vm) msg
then @H.transfer_ether (H.Build_FArgs F.(Host.Instantiate.ChainParams) vm)
(Evmc.Message.t.sender msg) (Evmc.Message.t.recipient msg) (Evmc.Message.t.value msg)
else fun st ⇒ (true, st)) s))).
{ destruct (H.should_transfer msg); [apply transfer_preserves_uncreated_nonce|]; exact Hinitial. }
unfold H.process_call, H.M.
cbn -[H.should_transfer H.transfer_ether W.account Precompiles.Make.try_precompile].
match goal with |- context [Monad.Identity.Impl.op_gtgteq ?run _] ⇒
assert (Hmiddle : protected query nonce (snd run)) by exact Htransfer;
destruct run as [ok middle] eqn:Hrun end.
cbn beta iota zeta delta [snd] in Hmiddle.
destruct ok; [|exact Hmiddle].
destruct from_tx as [tx|].
all: cbn -[W.account Precompiles.Make.try_precompile Delegation.get_delegated_address].
all: try match goal with |- context [@Delegation.get_delegated_address ?bytes] ⇒
destruct (@Delegation.get_delegated_address bytes) as [delegated|] eqn:Hdelegation end.
all: cbn -[W.account Precompiles.Make.try_precompile].
all: match goal with |- context [match ?selection with Some _ ⇒ _ | None ⇒ _ end] ⇒
destruct selection as [action|] eqn:Hselected end.
all: try (eapply Hnative; eassumption).
all: apply Hvm; [exact Hmiddle|].
all: intro Hrecipient;
destruct (List.in_dec String.string_dec query
(S.t.accounts_created_in_current_transaction middle)) as [Hin|Hnot];
[right; exact Hin|left].
all: pose proof (proj2 (uncreated_nonce_not_created query nonce middle Hmiddle Hnot)) as Hempty;
first [rewrite (HcodeAddress Hrecipient); exact Hempty|idtac].
exfalso. match type of Hdelegation with
| @Delegation.get_delegated_address ?bytes = Some _ ⇒
assert (Hbytes : bytes = Byte_string.Bytes.empty) by
(rewrite (HcodeAddress Hrecipient); exact Hempty);
pose proof (eq_trans
(eq_sym (f_equal (@Delegation.get_delegated_address) Hbytes))
Hdelegation) as Hfalse;
discriminate Hfalse
end.
Qed.
On failure the Host restores the call-entry state. On success it keeps
the state protected by the recursive VM/native-call induction steps.
The top-level reserve check is read-only and can only cause rollback.
Lemma call_impl_preserves_uncreated_nonce from_tx query nonce msg :
(∀ nested addr action, nativeDispatch vm nested addr = Some action →
preservesCallback (protected query nonce) action) →
(∀ nested code, 0 ≤ Evmc.Message.t.gas nested < 2^63 →
@preservesCreation _ (vm.(Evmc.Vm.SIG.execute) nested code)) →
(∀ nested code, 0 ≤ Evmc.Message.t.gas nested < 2^63 →
∀ s, protected query nonce s →
(Evmc.Message.t.recipient nested = query →
code = Byte_string.Bytes.empty ∨ List.In query (S.t.accounts_created_in_current_transaction s)) →
protected query nonce (snd (vm.(Evmc.Vm.SIG.execute) nested code s))) →
0 ≤ Evmc.Message.t.gas msg < 2^63 →
(Evmc.Message.t.kind msg = Evmc.Message.CallKind.Create ∨
Evmc.Message.t.kind msg = Evmc.Message.CallKind.Create2 ∨
(Evmc.Message.t.recipient msg = query → Evmc.Message.t.code_address msg = query)) →
preservesCallback (protected query nonce)
(callImpl (match from_tx with Some tx ⇒ H.Eoa_tx tx | None ⇒ H.Evm_call end) msg).
Proof.
intros Hnative Hcreation Hvm Hgas Htarget s Hinitial.
pose proof (process_create_preserves_uncreated_nonce (F := H.Build_FArgs F.(Host.Instantiate.ChainParams) vm)
query nonce msg) as Hcreate.
specialize (Hcreate Hcreation Hvm Hgas).
assert (Hcall :
(Evmc.Message.t.recipient msg = query → Evmc.Message.t.code_address msg = query) →
preservesCallback (protected query nonce) (processCall from_tx msg)).
{ intro Hcode. exact (process_call_preserves_uncreated_nonce from_tx query nonce msg
(Hnative msg) Hcode (fun code initial ⇒ Hvm msg code Hgas initial)). }
unfold H.call_impl.
Local Opaque H.process_call H.process_syscall H.process_create
Addr.of_contract_creation Reserve_balance.dipped_into_reserve.
destruct (Evmc.Message.t.kind msg) eqn:Hkind; destruct from_tx as [tx|]; cbn.
all: match goal with
| |- context [Monad.Identity.Impl.op_gtgteq ?run _] ⇒
assert (Hcore : protected query nonce (snd run)) by
(lazymatch run with ?f ?initial ⇒
assert (Hentry : protected query nonce initial) by
(destruct Hinitial as [Hwf Haccount]; split; assumption);
first [exact (Hcreate initial Hentry)|
destruct Htarget as [Hbad|[Hbad|Htarget]]; try discriminate;
exact (Hcall Htarget initial Hentry)] end);
destruct run as [result intermediate] eqn:Hrun
end.
all: destruct result as [status gasleft refund output address].
all: destruct status;
cbn; unfold Monad.Make_Monad.when_; cbn;
try exact Hcore; try exact Hinitial.
all: try (destruct Hinitial as [Hwf Haccount]; split; assumption).
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; first [exact Hinitial|exact Hcore|
destruct Hinitial as [Hwf Haccount]; split; assumption].
Qed.
Lemma call_preserves_uncreated_nonce self query nonce msg :
(∀ nested addr action, nativeDispatch vm nested addr = Some action →
preservesCallback (protected query nonce) action) →
(∀ nested code, 0 ≤ Evmc.Message.t.gas nested < 2^63 →
@preservesCreation _ (vm.(Evmc.Vm.SIG.execute) nested code)) →
(∀ nested code, 0 ≤ Evmc.Message.t.gas nested < 2^63 →
∀ s, protected query nonce s →
(Evmc.Message.t.recipient nested = query →
code = Byte_string.Bytes.empty ∨ List.In query (S.t.accounts_created_in_current_transaction s)) →
protected query nonce (snd (vm.(Evmc.Vm.SIG.execute) nested code s))) →
0 ≤ Evmc.Message.t.gas msg < 2^63 →
self ≠ query → childCallFrom self msg →
(Evmc.Message.t.kind msg = Evmc.Message.CallKind.Create ∨
Evmc.Message.t.kind msg = Evmc.Message.CallKind.Create2 ∨
(Evmc.Message.t.recipient msg = query → Evmc.Message.t.code_address msg = query)) →
preservesCallback (protected query nonce) (hostCall msg).
Proof.
intros Hnative Hcreation Hvm Hgas Hdifferent Horigin Htarget s Hinitial.
pose proof (call_impl_preserves_uncreated_nonce None query nonce msg
Hnative Hcreation Hvm Hgas Htarget) as Himpl.
unfold H.call.
destruct (Evmc.Message.t.kind msg) eqn:Hkind.
all: cbn -[H.call_impl H.try_increment_nonce].
all: try (apply Himpl; exact Hinitial).
all: assert (Hsender : Evmc.Message.t.sender msg ≠ query) by
(unfold childCallFrom in Horigin; rewrite Hkind in Horigin; rewrite Horigin; exact Hdifferent).
all: pose proof (increment_preserves_other_uncreated_nonce
(F := H.Build_FArgs F.(Host.Instantiate.ChainParams) vm) query nonce
(Evmc.Message.t.sender msg) Hsender s Hinitial) as Hincrement.
all: match goal with |- context [Monad.Identity.Impl.op_gtgteq ?run _] ⇒
destruct run as [ok middle] end.
all: cbn [snd] in Hincrement; destruct ok;
cbn -[H.call_impl]; [apply Himpl; exact Hincrement|exact Hincrement].
Qed.
End Host.
(∀ nested addr action, nativeDispatch vm nested addr = Some action →
preservesCallback (protected query nonce) action) →
(∀ nested code, 0 ≤ Evmc.Message.t.gas nested < 2^63 →
@preservesCreation _ (vm.(Evmc.Vm.SIG.execute) nested code)) →
(∀ nested code, 0 ≤ Evmc.Message.t.gas nested < 2^63 →
∀ s, protected query nonce s →
(Evmc.Message.t.recipient nested = query →
code = Byte_string.Bytes.empty ∨ List.In query (S.t.accounts_created_in_current_transaction s)) →
protected query nonce (snd (vm.(Evmc.Vm.SIG.execute) nested code s))) →
0 ≤ Evmc.Message.t.gas msg < 2^63 →
(Evmc.Message.t.kind msg = Evmc.Message.CallKind.Create ∨
Evmc.Message.t.kind msg = Evmc.Message.CallKind.Create2 ∨
(Evmc.Message.t.recipient msg = query → Evmc.Message.t.code_address msg = query)) →
preservesCallback (protected query nonce)
(callImpl (match from_tx with Some tx ⇒ H.Eoa_tx tx | None ⇒ H.Evm_call end) msg).
Proof.
intros Hnative Hcreation Hvm Hgas Htarget s Hinitial.
pose proof (process_create_preserves_uncreated_nonce (F := H.Build_FArgs F.(Host.Instantiate.ChainParams) vm)
query nonce msg) as Hcreate.
specialize (Hcreate Hcreation Hvm Hgas).
assert (Hcall :
(Evmc.Message.t.recipient msg = query → Evmc.Message.t.code_address msg = query) →
preservesCallback (protected query nonce) (processCall from_tx msg)).
{ intro Hcode. exact (process_call_preserves_uncreated_nonce from_tx query nonce msg
(Hnative msg) Hcode (fun code initial ⇒ Hvm msg code Hgas initial)). }
unfold H.call_impl.
Local Opaque H.process_call H.process_syscall H.process_create
Addr.of_contract_creation Reserve_balance.dipped_into_reserve.
destruct (Evmc.Message.t.kind msg) eqn:Hkind; destruct from_tx as [tx|]; cbn.
all: match goal with
| |- context [Monad.Identity.Impl.op_gtgteq ?run _] ⇒
assert (Hcore : protected query nonce (snd run)) by
(lazymatch run with ?f ?initial ⇒
assert (Hentry : protected query nonce initial) by
(destruct Hinitial as [Hwf Haccount]; split; assumption);
first [exact (Hcreate initial Hentry)|
destruct Htarget as [Hbad|[Hbad|Htarget]]; try discriminate;
exact (Hcall Htarget initial Hentry)] end);
destruct run as [result intermediate] eqn:Hrun
end.
all: destruct result as [status gasleft refund output address].
all: destruct status;
cbn; unfold Monad.Make_Monad.when_; cbn;
try exact Hcore; try exact Hinitial.
all: try (destruct Hinitial as [Hwf Haccount]; split; assumption).
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; first [exact Hinitial|exact Hcore|
destruct Hinitial as [Hwf Haccount]; split; assumption].
Qed.
Lemma call_preserves_uncreated_nonce self query nonce msg :
(∀ nested addr action, nativeDispatch vm nested addr = Some action →
preservesCallback (protected query nonce) action) →
(∀ nested code, 0 ≤ Evmc.Message.t.gas nested < 2^63 →
@preservesCreation _ (vm.(Evmc.Vm.SIG.execute) nested code)) →
(∀ nested code, 0 ≤ Evmc.Message.t.gas nested < 2^63 →
∀ s, protected query nonce s →
(Evmc.Message.t.recipient nested = query →
code = Byte_string.Bytes.empty ∨ List.In query (S.t.accounts_created_in_current_transaction s)) →
protected query nonce (snd (vm.(Evmc.Vm.SIG.execute) nested code s))) →
0 ≤ Evmc.Message.t.gas msg < 2^63 →
self ≠ query → childCallFrom self msg →
(Evmc.Message.t.kind msg = Evmc.Message.CallKind.Create ∨
Evmc.Message.t.kind msg = Evmc.Message.CallKind.Create2 ∨
(Evmc.Message.t.recipient msg = query → Evmc.Message.t.code_address msg = query)) →
preservesCallback (protected query nonce) (hostCall msg).
Proof.
intros Hnative Hcreation Hvm Hgas Hdifferent Horigin Htarget s Hinitial.
pose proof (call_impl_preserves_uncreated_nonce None query nonce msg
Hnative Hcreation Hvm Hgas Htarget) as Himpl.
unfold H.call.
destruct (Evmc.Message.t.kind msg) eqn:Hkind.
all: cbn -[H.call_impl H.try_increment_nonce].
all: try (apply Himpl; exact Hinitial).
all: assert (Hsender : Evmc.Message.t.sender msg ≠ query) by
(unfold childCallFrom in Horigin; rewrite Hkind in Horigin; rewrite Horigin; exact Hdifferent).
all: pose proof (increment_preserves_other_uncreated_nonce
(F := H.Build_FArgs F.(Host.Instantiate.ChainParams) vm) query nonce
(Evmc.Message.t.sender msg) Hsender s Hinitial) as Hincrement.
all: match goal with |- context [Monad.Identity.Impl.op_gtgteq ?run _] ⇒
destruct run as [ok middle] end.
all: cbn [snd] in Hincrement; destruct ok;
cbn -[H.call_impl]; [apply Himpl; exact Hincrement|exact Hincrement].
Qed.
End Host.