Library SetcodeConcrete.executioneoanonce
VM nonce preservation for senders that have not migrated
From Stdlib Require Import List String ZArith.
Require Import RocqOfOCaml.RocqOfOCaml MonadVM.Execution.
Require Import QedkConcrete.reservecheck QedkConcrete.hostframe QedkConcrete.vmhostframe.
Require Import SetcodeConcrete.executionemptyaccount SetcodeConcrete.executiondelegatedaccount
SetcodeConcrete.emptyaccount SetcodeConcrete.accountframe SetcodeConcrete.transactioncode
SetcodeConcrete.codeevolution.
Set Default Goal Selector "!".
Module E := Execution.Make.
Module A := Chain.Ethereum.Account.
Module W := State.WorldState.
Module S := State.TransactionState.
Section Execution.
Context {F : E.FArgs}.
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).
Theorem transaction_call_eoa_code_nonce query tx msg initial :
query ≠ Reserve_balance.precompile_address →
stringmaps.WellFormed (W.t.accounts (S.t.world_state initial)) →
(0 ≤ Evmc.Message.t.gas msg < 2^63)%Z →
A.is_smart_contract (State.op_pointcaretlparenrparen (S.t.world_state initial) (W.account None query)) = false →
(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)) →
let post := snd (E.Host.call_from_eoa tx msg initial) in
¬ In query (S.t.accounts_created_in_current_transaction post) →
let beforeAccount := State.op_pointcaretlparenrparen (S.t.world_state initial) (W.account None query) in
let afterAccount := State.op_pointcaretlparenrparen (S.t.world_state post) (W.account None query) in
stringmaps.WellFormed (W.t.accounts (S.t.world_state post)) ∧
(regularCode (A.t.code afterAccount) ∨
(A.t.code afterAccount = A.t.code beforeAccount ∧ A.t.nonce afterAccount = A.t.nonce beforeAccount)).
Proof.
intros Hnative Hmap Hgas Hnoncontract Htarget post Hnot beforeAccount afterAccount.
destruct (Delegation.is_valid_delegation (A.t.code beforeAccount)) eqn:Hdelegated.
- pose proof (@transaction_call_preserves_delegated_account F query
(A.t.code beforeAccount) (A.t.nonce beforeAccount) Hnative Hdelegated
cold warm access write reserve Hcold Hwarm Hrevision tx msg Hgas initial
(conj Hmap (or_intror (or_intror (conj eq_refl eq_refl))))) as Hafter.
destruct Hafter as [Hwf [Hin|HP]]; [contradiction|split; assumption].
- assert (Hempty : A.t.code beforeAccount = Byte_string.Bytes.empty).
{ change (andb (Byte_string.Bytes.op_ltgt (A.t.code beforeAccount) Byte_string.Bytes.empty)
(negb (Delegation.is_valid_delegation (A.t.code beforeAccount))) = false) in Hnoncontract.
rewrite Hdelegated in Hnoncontract.
cbn [negb] in Hnoncontract. rewrite Bool.andb_true_r in Hnoncontract.
change (negb (Byte_string.Bytes.op_eq (A.t.code beforeAccount) Byte_string.Bytes.empty) = false) in Hnoncontract.
apply Bool.negb_false_iff in Hnoncontract.
change (Z.eqb (OCamlString.compare (A.t.code beforeAccount) Byte_string.Bytes.empty) 0 = true) in Hnoncontract.
apply Z.eqb_eq in Hnoncontract. apply address_compare_eq. exact Hnoncontract. }
pose proof (@transaction_call_preserves_empty_account F query (A.t.nonce beforeAccount)
Hnative cold warm access write reserve Hcold Hwarm Hrevision tx msg Hgas Htarget initial
(conj Hmap (or_intror (conj Hempty eq_refl)))) as Hafter.
destruct Hafter as [Hwf [Hin|[Hcode Hnonce]]]; [contradiction|].
split; [exact Hwf|right; split; [exact (eq_trans Hcode (eq_sym Hempty))|exact Hnonce]].
Qed.
End Execution.
Print Assumptions transaction_call_eoa_code_nonce.
Require Import RocqOfOCaml.RocqOfOCaml MonadVM.Execution.
Require Import QedkConcrete.reservecheck QedkConcrete.hostframe QedkConcrete.vmhostframe.
Require Import SetcodeConcrete.executionemptyaccount SetcodeConcrete.executiondelegatedaccount
SetcodeConcrete.emptyaccount SetcodeConcrete.accountframe SetcodeConcrete.transactioncode
SetcodeConcrete.codeevolution.
Set Default Goal Selector "!".
Module E := Execution.Make.
Module A := Chain.Ethereum.Account.
Module W := State.WorldState.
Module S := State.TransactionState.
Section Execution.
Context {F : E.FArgs}.
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).
Theorem transaction_call_eoa_code_nonce query tx msg initial :
query ≠ Reserve_balance.precompile_address →
stringmaps.WellFormed (W.t.accounts (S.t.world_state initial)) →
(0 ≤ Evmc.Message.t.gas msg < 2^63)%Z →
A.is_smart_contract (State.op_pointcaretlparenrparen (S.t.world_state initial) (W.account None query)) = false →
(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)) →
let post := snd (E.Host.call_from_eoa tx msg initial) in
¬ In query (S.t.accounts_created_in_current_transaction post) →
let beforeAccount := State.op_pointcaretlparenrparen (S.t.world_state initial) (W.account None query) in
let afterAccount := State.op_pointcaretlparenrparen (S.t.world_state post) (W.account None query) in
stringmaps.WellFormed (W.t.accounts (S.t.world_state post)) ∧
(regularCode (A.t.code afterAccount) ∨
(A.t.code afterAccount = A.t.code beforeAccount ∧ A.t.nonce afterAccount = A.t.nonce beforeAccount)).
Proof.
intros Hnative Hmap Hgas Hnoncontract Htarget post Hnot beforeAccount afterAccount.
destruct (Delegation.is_valid_delegation (A.t.code beforeAccount)) eqn:Hdelegated.
- pose proof (@transaction_call_preserves_delegated_account F query
(A.t.code beforeAccount) (A.t.nonce beforeAccount) Hnative Hdelegated
cold warm access write reserve Hcold Hwarm Hrevision tx msg Hgas initial
(conj Hmap (or_intror (or_intror (conj eq_refl eq_refl))))) as Hafter.
destruct Hafter as [Hwf [Hin|HP]]; [contradiction|split; assumption].
- assert (Hempty : A.t.code beforeAccount = Byte_string.Bytes.empty).
{ change (andb (Byte_string.Bytes.op_ltgt (A.t.code beforeAccount) Byte_string.Bytes.empty)
(negb (Delegation.is_valid_delegation (A.t.code beforeAccount))) = false) in Hnoncontract.
rewrite Hdelegated in Hnoncontract.
cbn [negb] in Hnoncontract. rewrite Bool.andb_true_r in Hnoncontract.
change (negb (Byte_string.Bytes.op_eq (A.t.code beforeAccount) Byte_string.Bytes.empty) = false) in Hnoncontract.
apply Bool.negb_false_iff in Hnoncontract.
change (Z.eqb (OCamlString.compare (A.t.code beforeAccount) Byte_string.Bytes.empty) 0 = true) in Hnoncontract.
apply Z.eqb_eq in Hnoncontract. apply address_compare_eq. exact Hnoncontract. }
pose proof (@transaction_call_preserves_empty_account F query (A.t.nonce beforeAccount)
Hnative cold warm access write reserve Hcold Hwarm Hrevision tx msg Hgas Htarget initial
(conj Hmap (or_intror (conj Hempty eq_refl)))) as Hafter.
destruct Hafter as [Hwf [Hin|[Hcode Hnonce]]]; [contradiction|].
split; [exact Hwf|right; split; [exact (eq_trans Hcode (eq_sym Hempty))|exact Hnonce]].
Qed.
End Execution.
Print Assumptions transaction_call_eoa_code_nonce.