Library SetcodeConcrete.transactionconfigfinalize
Complete transaction finalization preserves native configuration
From Stdlib Require Import List String ZArith.
Require Import RocqOfOCaml.RocqOfOCaml MonadVM.Execution.
Require Import QedkConcrete.protectedstorageboundarycore QedkConcrete.protectedstorage
QedkConcrete.transactionframes QedkConcrete.hostframe.
Require Import SetcodeConcrete.transactionentry.
Set Default Goal Selector "!".
#[local] Hint Extern 100 (Basics.Unreachable _) ⇒
(apply Opaque.legacy_witness; Opaque.opaque_inhabit 64%nat) : typeclass_instances.
Module E := Execution.Make.
Module W := State.WorldState.
Module B := State.BlockState.
Module S := State.TransactionState.
Module A := Chain.Ethereum.Account.
Module T := Chain.Ethereum.Transaction.
Module Addr := Chain.Ethereum.Address.
Section Transaction.
Context {F : E.FArgs}.
Lemma bump_world_config query P s addresses :
worldProtectedStorage query P (S.t.world_state s) →
worldProtectedStorage query P (S.t.world_state (E.bump_emptying_transaction_counters addresses s)).
Proof.
unfold worldProtectedStorage, State.op_pointcaretlparenrparen, W.account, W.account_opt.
cbn -[E.bump_emptying_transaction_counters Addr.Map.find_opt].
rewrite bump_counters_accounts. exact (fun H ⇒ H).
Qed.
Theorem process_transaction_retains_finished_config block tx validation post query P :
E.validate_transaction block tx = inl validation →
E.process_transaction block tx = inl post →
worldProtectedStorage query P (S.t.world_state (transactionFinished block tx validation)) →
¬ In query (S.t.self_destruct (transactionFinished block tx validation)) →
worldProtectedStorage query P (B.t.world_state post).
Proof.
intros Hvalidation Hrun HP Hnot.
unfold E.process_transaction in Hrun. rewrite Hvalidation in Hrun.
destruct validation as [sender fee price intrinsic].
change (@Result.op_letdollar) with
(fun (A Error C : Set) (first : A + Error) (next : A → C + Error) ⇒
match first with inl value ⇒ next value | inr error ⇒ inr error end) in Hrun.
cbn beta iota zeta in Hrun, HP, Hnot.
match type of Hrun with context [Setcode_rules.advance_sender_nonce ?flag _ _] ⇒
set (migrated := flag) in × end.
match type of Hrun with context [Result.List.fold_left ?step ?initial ?auths] ⇒
set (authorized := Result.List.fold_left step initial auths) in × end.
assert (Hprefix : transactionPrefix block tx
{| E.transaction_validation.sender := sender; E.transaction_validation.total_fee := fee;
E.transaction_validation.effective_gas_price := price;
E.transaction_validation.intrinsic_gas := intrinsic |} = authorized) by reflexivity.
unfold transactionFinished, transactionVmInput in HP, Hnot.
rewrite Hprefix in HP, Hnot.
unfold migratedSender in HP, Hnot.
destruct authorized as [applied prepared].
cbn beta iota zeta delta [fst snd] in Hrun, HP, Hnot.
match type of Hrun with context [S.initialize_access_sets tx ?entry ?precompiles] ⇒
set (beforeVm := S.initialize_access_sets tx entry precompiles) in × end.
match type of Hrun with context [E.Host.call_from_eoa tx ?message beforeVm] ⇒
set (msg := message) in × end.
change (worldProtectedStorage query P (S.t.world_state
(if migrated then beforeVm else snd (E.Host.call_from_eoa tx msg beforeVm)))) in HP.
change (¬ In query (S.t.self_destruct
(if migrated then beforeVm else snd (E.Host.call_from_eoa tx msg beforeVm)))) in Hnot.
destruct (E.Host.call_from_eoa tx msg beforeVm) as [result afterVm].
destruct migrated; cbn beta iota zeta delta [fst snd] in Hrun, HP, Hnot.
all: try (destruct (Evmc.Message.CallKind.is_create (Evmc.Message.t.kind msg));
cbn beta iota zeta in Hrun).
all: match type of Hrun with Result._return ?computed = inl ?target ⇒
assert (Hpost : computed = target) by
(exact (f_equal (fun r ⇒ match r with inl value ⇒ value | inr _ ⇒ target end) Hrun));
rewrite <- Hpost; clear Hpost Hrun end.
all: cbn beta iota zeta delta [B.t.with_transactions_processed B.t.with_transaction_frames
B.t.with_gas_used B.t.world_state].
all: match goal with |- context [E.bump_emptying_transaction_counters (?who :: nil) ?entry] ⇒
set (final := E.bump_emptying_transaction_counters (who :: nil) entry) in × end.
all: assert (Hfinal : worldProtectedStorage query P (S.t.world_state final)) by
(unfold final; apply bump_world_config; exact HP).
all: apply delete_accounts_protected_storage; [apply world_protected_storage_balance; exact Hfinal|exact Hnot].
Qed.
End Transaction.
Print Assumptions process_transaction_retains_finished_config.
Require Import RocqOfOCaml.RocqOfOCaml MonadVM.Execution.
Require Import QedkConcrete.protectedstorageboundarycore QedkConcrete.protectedstorage
QedkConcrete.transactionframes QedkConcrete.hostframe.
Require Import SetcodeConcrete.transactionentry.
Set Default Goal Selector "!".
#[local] Hint Extern 100 (Basics.Unreachable _) ⇒
(apply Opaque.legacy_witness; Opaque.opaque_inhabit 64%nat) : typeclass_instances.
Module E := Execution.Make.
Module W := State.WorldState.
Module B := State.BlockState.
Module S := State.TransactionState.
Module A := Chain.Ethereum.Account.
Module T := Chain.Ethereum.Transaction.
Module Addr := Chain.Ethereum.Address.
Section Transaction.
Context {F : E.FArgs}.
Lemma bump_world_config query P s addresses :
worldProtectedStorage query P (S.t.world_state s) →
worldProtectedStorage query P (S.t.world_state (E.bump_emptying_transaction_counters addresses s)).
Proof.
unfold worldProtectedStorage, State.op_pointcaretlparenrparen, W.account, W.account_opt.
cbn -[E.bump_emptying_transaction_counters Addr.Map.find_opt].
rewrite bump_counters_accounts. exact (fun H ⇒ H).
Qed.
Theorem process_transaction_retains_finished_config block tx validation post query P :
E.validate_transaction block tx = inl validation →
E.process_transaction block tx = inl post →
worldProtectedStorage query P (S.t.world_state (transactionFinished block tx validation)) →
¬ In query (S.t.self_destruct (transactionFinished block tx validation)) →
worldProtectedStorage query P (B.t.world_state post).
Proof.
intros Hvalidation Hrun HP Hnot.
unfold E.process_transaction in Hrun. rewrite Hvalidation in Hrun.
destruct validation as [sender fee price intrinsic].
change (@Result.op_letdollar) with
(fun (A Error C : Set) (first : A + Error) (next : A → C + Error) ⇒
match first with inl value ⇒ next value | inr error ⇒ inr error end) in Hrun.
cbn beta iota zeta in Hrun, HP, Hnot.
match type of Hrun with context [Setcode_rules.advance_sender_nonce ?flag _ _] ⇒
set (migrated := flag) in × end.
match type of Hrun with context [Result.List.fold_left ?step ?initial ?auths] ⇒
set (authorized := Result.List.fold_left step initial auths) in × end.
assert (Hprefix : transactionPrefix block tx
{| E.transaction_validation.sender := sender; E.transaction_validation.total_fee := fee;
E.transaction_validation.effective_gas_price := price;
E.transaction_validation.intrinsic_gas := intrinsic |} = authorized) by reflexivity.
unfold transactionFinished, transactionVmInput in HP, Hnot.
rewrite Hprefix in HP, Hnot.
unfold migratedSender in HP, Hnot.
destruct authorized as [applied prepared].
cbn beta iota zeta delta [fst snd] in Hrun, HP, Hnot.
match type of Hrun with context [S.initialize_access_sets tx ?entry ?precompiles] ⇒
set (beforeVm := S.initialize_access_sets tx entry precompiles) in × end.
match type of Hrun with context [E.Host.call_from_eoa tx ?message beforeVm] ⇒
set (msg := message) in × end.
change (worldProtectedStorage query P (S.t.world_state
(if migrated then beforeVm else snd (E.Host.call_from_eoa tx msg beforeVm)))) in HP.
change (¬ In query (S.t.self_destruct
(if migrated then beforeVm else snd (E.Host.call_from_eoa tx msg beforeVm)))) in Hnot.
destruct (E.Host.call_from_eoa tx msg beforeVm) as [result afterVm].
destruct migrated; cbn beta iota zeta delta [fst snd] in Hrun, HP, Hnot.
all: try (destruct (Evmc.Message.CallKind.is_create (Evmc.Message.t.kind msg));
cbn beta iota zeta in Hrun).
all: match type of Hrun with Result._return ?computed = inl ?target ⇒
assert (Hpost : computed = target) by
(exact (f_equal (fun r ⇒ match r with inl value ⇒ value | inr _ ⇒ target end) Hrun));
rewrite <- Hpost; clear Hpost Hrun end.
all: cbn beta iota zeta delta [B.t.with_transactions_processed B.t.with_transaction_frames
B.t.with_gas_used B.t.world_state].
all: match goal with |- context [E.bump_emptying_transaction_counters (?who :: nil) ?entry] ⇒
set (final := E.bump_emptying_transaction_counters (who :: nil) entry) in × end.
all: assert (Hfinal : worldProtectedStorage query P (S.t.world_state final)) by
(unfold final; apply bump_world_config; exact HP).
all: apply delete_accounts_protected_storage; [apply world_protected_storage_balance; exact Hfinal|exact Hnot].
Qed.
End Transaction.
Print Assumptions process_transaction_retains_finished_config.