Library QedkConcrete.transactionreservestorage
Concrete transactions preserve native reserve storage
From Stdlib Require Import List String ZArith Lia.
Require Import RocqOfOCaml.RocqOfOCaml.
Require Import MonadVM.Execution QedkConcrete.protectedstorageboundary
QedkConcrete.protectedstorage QedkConcrete.protectedstoragenative
QedkConcrete.executionreservestorage QedkConcrete.transactionhistory
QedkConcrete.hostframe QedkConcrete.worldaccounts QedkConcrete.validation
QedkConcrete.emptyinghistory QedkConcrete.authorizationcode
QedkConcrete.transactionfinalize QedkConcrete.transactionsupply
QedkConcrete.transactionchecked QedkConcrete.hostcode QedkConcrete.reservestorage.
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 B := State.BlockState.
Module T := Chain.Ethereum.Transaction.
Section Execution.
Context {F : E.FArgs}.
Local Abbreviation args := (@E.Instantiation_fargs F).
Local Abbreviation native := (@Reserve_balance.precompile_address).
Local Abbreviation U64 := (Opaque.legacy_witness 0%Z).
Local Abbreviation UF := (Opaque.legacy_witness 0%Z).
Local Abbreviation reachable := (@reachableReserveStorage).
Local Abbreviation worldProtected := (@worldProtectedStorage native).
Local Abbreviation protected := (@protectedStorage native).
Local Abbreviation blockNumber := (fun b ⇒
Chain.Ethereum.Block.Header.t.number (Chain.Ethereum.Block.t.header (B.t.current_block b))).
Context {UI0 : Basics.Unreachable Support.UintN.Impl.t}
{UB : Basics.Unreachable Bloom.t}
{U8 : Basics.Unreachable Byte_string.B8.(Byte_string.Fixed.Fixed_result.t)}.
Local Abbreviation prefix := (@transactionPrefix F).
Theorem process_transaction_only_reserve_settings block tx initial :
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
worldProtected (reachable (blockNumber block) initial (blockNumber block)) (B.t.world_state block) →
(∀ validation, @E.validate_transaction F block tx = inl validation →
E.transaction_validation.sender validation ≠ native ∧
¬ List.In native (fst (prefix block tx validation))) →
match @E.process_transaction F block tx with
| inl post ⇒ worldProtected (reachable (blockNumber block) initial (blockNumber block))
(B.t.world_state post)
| inr _ ⇒ True
end.
Proof.
intros Hrevision Hworld Hsignatures. unfold E.process_transaction.
destruct (@E.validate_transaction F block tx) as [validation|error] eqn:Hvalidation.
2: exact I.
destruct (Hsignatures validation eq_refl) as [Hsender Habsent].
destruct validation as [sender fee price intrinsic].
cbn [E.transaction_validation.sender] in Hsender.
change (@Result.op_letdollar) with
(fun (A B C : Set) (r : A + B) (f : A → C + B) ⇒
match r with inl value ⇒ f value | inr error ⇒ inr error end).
cbn beta iota zeta delta [E.transaction_validation.sender E.transaction_validation.total_fee
E.transaction_validation.intrinsic_gas E.transaction_validation.effective_gas_price].
match goal with |- context [@S.make block sender tx] ⇒
set (entry := @S.make block sender tx)
end.
assert (Hentry : protected (reachable (blockNumber block) initial) entry).
{ destruct Hworld as [Hmap [Hnonce [Hcode Hcontents]]]. constructor.
- exact Hmap.
- exact Hnonce.
- exact Hcode.
- exact Hcontents.
- cbn [entry S.make]. tauto.
- cbn [entry S.make]. tauto. }
match goal with |- context [Result.List.fold_left ?f ?charged (T.authorization_list tx)] ⇒
set (chargedState := snd charged);
set (authorized := Result.List.fold_left f charged (T.authorization_list tx))
end.
assert (Hcharged : protected (reachable (blockNumber block) initial) chargedState).
{ unfold chargedState. cbn [snd]. apply protected_storage_write; [exact Hentry|].
intro Heq. contradiction. }
pose proof (@authorizations_preserve_protected_storage F native
(reachable (blockNumber block) initial) (T.authorization_list tx) nil chargedState Hcharged) as Hauth.
change (¬ List.In native (fst authorized) →
protected (reachable (blockNumber block) initial) (snd authorized)) in Hauth.
change (¬ List.In native (fst authorized)) in Habsent.
specialize (Hauth Habsent).
destruct authorized as [authorities prepared]. cbn beta iota zeta delta [snd] in Hauth |- ×.
match goal with |- context [@S.initialize_access_sets tx ?s ?precompiles] ⇒
set (beforeVm := @S.initialize_access_sets tx s precompiles)
end.
assert (Hbefore : protected (reachable (blockNumber block) initial) beforeVm).
{ eapply protected_storage_same_fields with
(before := @E.bump_emptying_transaction_counters F authorities prepared).
- reflexivity.
- reflexivity.
- reflexivity.
- reflexivity.
- apply bump_counters_protected_storage. exact Hauth. }
pose proof (validated_message_gas block tx _ (S.t.world_state beforeVm) Hvalidation) as Hgas.
match goal with |- context [E.Host.call_from_eoa tx ?message beforeVm] ⇒
assert (Htarget : Evmc.Message.t.kind message = Evmc.Message.CallKind.Create ∨
Evmc.Message.t.kind message = Evmc.Message.CallKind.Create2 ∨
(Evmc.Message.t.recipient message = native → Evmc.Message.t.code_address message = native)) by
(unfold E.prepare_message; destruct (T.call_or_create_value tx); cbn; auto);
pose proof (@execution_call_from_eoa_only_reserve_settings F
(blockNumber block) initial tx message
Hrevision Hgas Htarget beforeVm Hbefore) as Hvm;
destruct (E.Host.call_from_eoa tx message beforeVm) as [result afterVm]
end.
cbn [snd] in Hvm.
pose proof (@bump_counters_protected_storage F native
(reachable (blockNumber block) initial) afterVm (sender :: nil) Hvm) as Hafter.
pose proof (protected_storage_undestroyed _ _ _ Hafter) as HnotDeleted.
pose proof (protected_storage_world _ _ _ Hafter) as Hfinal.
destruct Hfinal as [Hmap [Hnonce [Hcode [Hblock Hwrites]]]].
assert (Hfinal : worldProtected (reachable (blockNumber block) initial (blockNumber block))
(S.t.world_state (@E.bump_emptying_transaction_counters F (sender :: nil) afterVm))).
{ split; [exact Hmap|]. split; [exact Hnonce|]. split; [exact Hcode|].
split; [reflexivity|exact Hwrites]. }
change (@Result._return) with (fun (A B : Set) (value : A) ⇒ @inl A B value).
cbn beta iota zeta delta [B.t.with_transactions_processed B.t.with_gas_used B.t.world_state].
apply delete_accounts_protected_storage; [|exact HnotDeleted].
apply world_protected_storage_balance. exact Hfinal.
Qed.
Lemma system_message_only_reserve_settings block addr data initial :
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
worldProtected (reachable (blockNumber block) initial (blockNumber block)) (B.t.world_state block) →
worldProtected (reachable (blockNumber block) initial (blockNumber block))
(B.t.world_state (snd (@E.process_system_message F
block addr data))).
Proof.
intros Hrevision Hworld. unfold E.process_system_message.
match goal with |- context [if ?b then _ else _] ⇒ destruct b end.
{ exact Hworld. }
cbn beta iota zeta.
match goal with |- context [E.Host.call ?message ?entry] ⇒
assert (Hentry : protected (reachable (blockNumber block) initial) entry) by
(destruct Hworld as [Hmap [Hnonce [Hcode Hcontents]]]; constructor;
[exact Hmap|exact Hnonce|exact Hcode|exact Hcontents|cbn; tauto|cbn; tauto]);
assert (Hgas : (0 ≤ Evmc.Message.t.gas message < 2^63)%Z) by
(change (0 ≤ 30000000 < 2^63)%Z; lia);
assert (Hsender : Evmc.Message.t.sender message ≠ native) by
(vm_compute; discriminate);
pose proof (@execution_system_call_only_reserve_settings F
(blockNumber block) initial message
Hrevision Hgas Hsender eq_refl (fun Heq ⇒ Heq) entry Hentry) as Hcall;
destruct (E.Host.call message entry) as [result afterVm]
end.
cbn [snd] in Hcall.
destruct (protected_storage_world _ _ _ Hcall) as [Hmap [Hnonce [Hcode [Hblock Hwrites]]]].
split; [exact Hmap|]. split; [exact Hnonce|]. split; [exact Hcode|].
split; [reflexivity|exact Hwrites].
Qed.
Lemma withdrawal_preserves_protected_storage block withdrawal P :
worldProtected P (B.t.world_state block) →
worldProtected P (B.t.world_state (@E.process_withdrawal F block withdrawal)).
Proof.
intro Hworld. unfold E.process_withdrawal.
apply world_protected_storage_balance. exact Hworld.
Qed.
Lemma withdrawals_preserve_protected_storage block withdrawals P :
worldProtected P (B.t.world_state block) →
worldProtected P (B.t.world_state
(Result.List.fold_left (@E.process_withdrawal F) block withdrawals)).
Proof.
revert block. induction withdrawals as [|wd withdrawals IH]; intros block Hworld.
- exact Hworld.
- change (worldProtected P (B.t.world_state (Result.List.fold_left
(@E.process_withdrawal F) (@E.process_withdrawal F block wd) withdrawals))).
apply IH, withdrawal_preserves_protected_storage. exact Hworld.
Qed.
Local Abbreviation processTransaction := (@E.process_transaction F).
Local Lemma bind_success {A B Error : Set}
(first : A + Error) (next : A → B + Error) value :
MonadVM.Result.op_letdollar first next = inl value →
∃ intermediate, first = inl intermediate ∧ next intermediate = inl value.
Proof.
destruct first; cbn; [intro H; eexists; split; [reflexivity|exact H]|discriminate].
Qed.
Lemma validated_monad_system_transaction_call_kind block tx sender available_gas world :
@E.validate_monad_system_transaction F block tx sender = inl tt →
Evmc.Message.t.kind (@E.prepare_message F sender available_gas tx world) =
Evmc.Message.CallKind.Call.
Proof.
intro Hvalidated. unfold E.validate_monad_system_transaction in Hvalidated.
cbn zeta in Hvalidated.
do 3 (apply bind_success in Hvalidated;
let step := fresh "step" in let Hstep := fresh "Hstep" in
destruct Hvalidated as [step [Hstep Hvalidated]];
cbn beta iota zeta in Hvalidated).
destruct tx as [tx_impl| | |]; [|cbn in Hstep0; discriminate Hstep0..].
cbn in Hstep0. injection Hstep0 as <-.
destruct tx_impl. cbn in Hstep1 |- ×.
match type of Hstep1 with match ?o with Some _ ⇒ _ | None ⇒ _ end = inl _ ⇒
destruct o; [reflexivity|discriminate Hstep1]
end.
Qed.
Theorem process_monad_system_transaction_only_reserve_settings block tx initial :
worldProtected (reachable (blockNumber block) initial (blockNumber block)) (B.t.world_state block) →
match @E.process_monad_system_transaction F block tx with
| inl post ⇒ worldProtected (reachable (blockNumber block) initial (blockNumber block))
(B.t.world_state post)
| inr _ ⇒ True
end.
Proof.
intro Hworld. unfold E.process_monad_system_transaction.
destruct (@E.validate_monad_system_transaction F block tx Chain.Monad.system_sender)
as [[]|error] eqn:Hvalidation; [|exact I].
change (@Result.op_letdollar) with
(fun (A B C : Set) (r : A + B) (f : A → C + B) ⇒
match r with inl value ⇒ f value | inr error ⇒ inr error end).
cbv beta iota zeta.
set (sender := Chain.Monad.system_sender).
match goal with |- context [@S.make block sender tx] ⇒
set (entry := @S.make block sender tx)
end.
assert (Hentry : protected (reachable (blockNumber block) initial) entry).
{ destruct Hworld as [Hmap [Hnonce [Hcode Hcontents]]]. constructor.
- exact Hmap.
- exact Hnonce.
- exact Hcode.
- exact Hcontents.
- cbn [entry S.make]. tauto.
- cbn [entry S.make]. tauto. }
match goal with |- context [@S.initialize_access_sets tx ?charged ?precompiles] ⇒
set (chargedState := charged);
set (beforeVm := @S.initialize_access_sets tx chargedState precompiles)
end.
assert (Hsender : sender ≠ native) by (vm_compute; discriminate).
assert (Hcharged : protected (reachable (blockNumber block) initial) chargedState).
{ unfold chargedState. apply protected_storage_write; [exact Hentry|].
intro Heq. contradiction. }
assert (Hbefore : protected (reachable (blockNumber block) initial) beforeVm).
{ eapply protected_storage_same_fields with (before := chargedState);
[reflexivity|reflexivity|reflexivity|reflexivity|exact Hcharged]. }
match goal with |- context [E.Host.call_from_monad_system_transaction ?message beforeVm] ⇒
pose proof (validated_monad_system_transaction_call_kind block tx sender Gas.zero
(S.t.world_state beforeVm) Hvalidation) as Hkind;
pose proof (@execution_call_from_monad_system_transaction_only_reserve_settings F
(blockNumber block) initial message Hkind beforeVm Hbefore) as Hvm;
destruct (E.Host.call_from_monad_system_transaction message beforeVm) as [result afterVm]
end.
cbn [snd] in Hvm.
unfold Result.when_.
destruct (negb (Evmc.Result.StatusCode.is_success (Evmc.Result.t.status_code result)));
[exact I|].
destruct (protected_storage_world _ _ _ Hvm) as [Hmap [Hnonce [Hcode [Hblock Hwrites]]]].
split; [exact Hmap|]. split; [exact Hnonce|]. split; [exact Hcode|].
split; [reflexivity|exact Hwrites].
Qed.
Theorem dispatch_transaction_only_reserve_settings block tx initial :
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
worldProtected (reachable (blockNumber block) initial (blockNumber block)) (B.t.world_state block) →
(∀ validation, @E.validate_transaction F block tx = inl validation →
E.transaction_validation.sender validation ≠ native ∧
¬ List.In native (fst (prefix block tx validation))) →
match @E.dispatch_transaction F block tx with
| inl post ⇒ worldProtected (reachable (blockNumber block) initial (blockNumber block))
(B.t.world_state post)
| inr _ ⇒ True
end.
Proof.
intros Hrevision Hworld Hsignatures. unfold E.dispatch_transaction.
destruct (T.chain_id tx) as [cid|];
[destruct (Support.UintN.op_ltgt cid (@E.Params F).(Execution.Make_Params_signature.chain_id));
[exact I|]|].
all: destruct (@E.sender_kind_value F tx) as [[sender|]|];
[apply process_transaction_only_reserve_settings; assumption
|apply process_monad_system_transaction_only_reserve_settings; assumption
|exact I].
Qed.
Lemma dispatch_transaction_current_block block tx post :
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
@E.dispatch_transaction F block tx = inl post →
B.t.current_block post = B.t.current_block block.
Proof.
intros Hrevision Hrun.
destruct (transactionformat.dispatch_transaction_cases block tx post Hrun)
as [[sender [_ Hstep]] | [_ Hstep]].
- exact (@process_transaction_current_block F block tx post Hstep).
- exact (proj2 (proj2 (@process_monad_system_transaction_activity_history F
block tx post Hrevision Hstep))).
Qed.
Lemma dispatched_transactions_only_reserve_settings block txs initial :
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
worldProtected (reachable (blockNumber block) initial (blockNumber block)) (B.t.world_state block) →
(∀ tx state validation, List.In tx txs →
@E.validate_transaction F state tx = inl validation →
E.transaction_validation.sender validation ≠ native ∧
¬ List.In native (fst (prefix state tx validation))) →
match Result.List.fold_leftM (@E.dispatch_transaction F) block txs with
| inl post ⇒ B.t.current_block post = B.t.current_block block ∧
worldProtected (reachable (blockNumber block) initial (blockNumber block)) (B.t.world_state post)
| inr _ ⇒ True end.
Proof.
intro Hrevision. revert block.
induction txs as [|tx txs IH]; intros block Hworld Hsignatures.
- split; [reflexivity|exact Hworld].
- change (match Result.op_letdollar (@E.dispatch_transaction F block tx)
(fun next ⇒ Result.List.fold_leftM (@E.dispatch_transaction F) next txs) with
| inl post ⇒ B.t.current_block post = B.t.current_block block ∧
worldProtected (reachable (blockNumber block) initial (blockNumber block)) (B.t.world_state post)
| inr _ ⇒ True end).
pose proof (dispatch_transaction_only_reserve_settings block tx initial Hrevision Hworld
(fun v Hv ⇒ Hsignatures tx block v (or_introl eq_refl) Hv)) as Hnext.
destruct (@E.dispatch_transaction F block tx) as [next|error] eqn:Hstep; [|exact I].
pose proof (dispatch_transaction_current_block block tx next Hrevision Hstep) as Hcurrent.
assert (Hnext' : worldProtected (reachable (blockNumber next) initial (blockNumber next))
(B.t.world_state next)).
{ cbv beta. rewrite Hcurrent. exact Hnext. }
specialize (IH next Hnext' (fun t state v Hin Hv ⇒
Hsignatures t state v (or_intror Hin) Hv)).
change (match Result.List.fold_leftM (@E.dispatch_transaction F) next txs with
| inl post ⇒ B.t.current_block post = B.t.current_block block ∧
worldProtected (reachable (blockNumber block) initial (blockNumber block)) (B.t.world_state post)
| inr _ ⇒ True end).
destruct (Result.List.fold_leftM (@E.dispatch_transaction F) next txs) as [post|error]; [|exact I].
destruct IH as [Hblock Hpost]. split.
+ exact (eq_trans Hblock Hcurrent).
+ cbv beta in Hpost |- ×. rewrite Hcurrent in Hpost. exact Hpost.
Qed.
Lemma transactions_only_reserve_settings block txs initial :
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
worldProtected (reachable (blockNumber block) initial (blockNumber block)) (B.t.world_state block) →
(∀ tx state validation, List.In tx txs →
@E.validate_transaction F state tx = inl validation →
E.transaction_validation.sender validation ≠ native ∧
¬ List.In native (fst (prefix state tx validation))) →
match Result.List.fold_leftM processTransaction block txs with
| inl post ⇒ B.t.current_block post = B.t.current_block block ∧
worldProtected (reachable (blockNumber block) initial (blockNumber block)) (B.t.world_state post)
| inr _ ⇒ True end.
Proof.
intro Hrevision. revert block.
induction txs as [|tx txs IH]; intros block Hworld Hsignatures.
- split; [reflexivity|exact Hworld].
- change (match Result.op_letdollar (processTransaction block tx)
(fun next ⇒ Result.List.fold_leftM processTransaction next txs) with
| inl post ⇒ B.t.current_block post = B.t.current_block block ∧
worldProtected (reachable (blockNumber block) initial (blockNumber block)) (B.t.world_state post)
| inr _ ⇒ True end).
pose proof (process_transaction_only_reserve_settings block tx initial Hrevision Hworld
(fun v Hv ⇒ Hsignatures tx block v (or_introl eq_refl) Hv)) as Hnext.
destruct (processTransaction block tx) as [next|error] eqn:Hstep; [|exact I].
pose proof (@process_transaction_current_block F
block tx next Hstep) as Hcurrent.
assert (Hnext' : worldProtected (reachable (blockNumber next) initial (blockNumber next))
(B.t.world_state next)).
{ cbv beta. rewrite Hcurrent. exact Hnext. }
specialize (IH next Hnext' (fun t state v Hin Hv ⇒
Hsignatures t state v (or_intror Hin) Hv)).
change (match Result.List.fold_leftM processTransaction next txs with
| inl post ⇒ B.t.current_block post = B.t.current_block block ∧
worldProtected (reachable (blockNumber block) initial (blockNumber block)) (B.t.world_state post)
| inr _ ⇒ True end).
destruct (Result.List.fold_leftM processTransaction next txs) as [post|error]; [|exact I].
destruct IH as [Hblock Hpost]. split.
+ exact (eq_trans Hblock Hcurrent).
+ cbv beta in Hpost |- ×. rewrite Hcurrent in Hpost. exact Hpost.
Qed.
Context {UTries : Basics.Unreachable (OCamlIarray.t Mpt.Trie.t)}
{UChar : Basics.Unreachable OCamlChar.t} {UWorld : Basics.Unreachable W.t}
{UTrie : Basics.Unreachable Mpt.Trie.t} {UNibbles : Basics.Unreachable Mpt.Nibbles.t}
{UBlock : Basics.Unreachable Chain.Ethereum.Block.t}.
Local Abbreviation readAccount := (fun world addr ⇒
State.op_pointcaretlparenrparen world (@W.account None addr)).
Require Import RocqOfOCaml.RocqOfOCaml.
Require Import MonadVM.Execution QedkConcrete.protectedstorageboundary
QedkConcrete.protectedstorage QedkConcrete.protectedstoragenative
QedkConcrete.executionreservestorage QedkConcrete.transactionhistory
QedkConcrete.hostframe QedkConcrete.worldaccounts QedkConcrete.validation
QedkConcrete.emptyinghistory QedkConcrete.authorizationcode
QedkConcrete.transactionfinalize QedkConcrete.transactionsupply
QedkConcrete.transactionchecked QedkConcrete.hostcode QedkConcrete.reservestorage.
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 B := State.BlockState.
Module T := Chain.Ethereum.Transaction.
Section Execution.
Context {F : E.FArgs}.
Local Abbreviation args := (@E.Instantiation_fargs F).
Local Abbreviation native := (@Reserve_balance.precompile_address).
Local Abbreviation U64 := (Opaque.legacy_witness 0%Z).
Local Abbreviation UF := (Opaque.legacy_witness 0%Z).
Local Abbreviation reachable := (@reachableReserveStorage).
Local Abbreviation worldProtected := (@worldProtectedStorage native).
Local Abbreviation protected := (@protectedStorage native).
Local Abbreviation blockNumber := (fun b ⇒
Chain.Ethereum.Block.Header.t.number (Chain.Ethereum.Block.t.header (B.t.current_block b))).
Context {UI0 : Basics.Unreachable Support.UintN.Impl.t}
{UB : Basics.Unreachable Bloom.t}
{U8 : Basics.Unreachable Byte_string.B8.(Byte_string.Fixed.Fixed_result.t)}.
Local Abbreviation prefix := (@transactionPrefix F).
Theorem process_transaction_only_reserve_settings block tx initial :
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
worldProtected (reachable (blockNumber block) initial (blockNumber block)) (B.t.world_state block) →
(∀ validation, @E.validate_transaction F block tx = inl validation →
E.transaction_validation.sender validation ≠ native ∧
¬ List.In native (fst (prefix block tx validation))) →
match @E.process_transaction F block tx with
| inl post ⇒ worldProtected (reachable (blockNumber block) initial (blockNumber block))
(B.t.world_state post)
| inr _ ⇒ True
end.
Proof.
intros Hrevision Hworld Hsignatures. unfold E.process_transaction.
destruct (@E.validate_transaction F block tx) as [validation|error] eqn:Hvalidation.
2: exact I.
destruct (Hsignatures validation eq_refl) as [Hsender Habsent].
destruct validation as [sender fee price intrinsic].
cbn [E.transaction_validation.sender] in Hsender.
change (@Result.op_letdollar) with
(fun (A B C : Set) (r : A + B) (f : A → C + B) ⇒
match r with inl value ⇒ f value | inr error ⇒ inr error end).
cbn beta iota zeta delta [E.transaction_validation.sender E.transaction_validation.total_fee
E.transaction_validation.intrinsic_gas E.transaction_validation.effective_gas_price].
match goal with |- context [@S.make block sender tx] ⇒
set (entry := @S.make block sender tx)
end.
assert (Hentry : protected (reachable (blockNumber block) initial) entry).
{ destruct Hworld as [Hmap [Hnonce [Hcode Hcontents]]]. constructor.
- exact Hmap.
- exact Hnonce.
- exact Hcode.
- exact Hcontents.
- cbn [entry S.make]. tauto.
- cbn [entry S.make]. tauto. }
match goal with |- context [Result.List.fold_left ?f ?charged (T.authorization_list tx)] ⇒
set (chargedState := snd charged);
set (authorized := Result.List.fold_left f charged (T.authorization_list tx))
end.
assert (Hcharged : protected (reachable (blockNumber block) initial) chargedState).
{ unfold chargedState. cbn [snd]. apply protected_storage_write; [exact Hentry|].
intro Heq. contradiction. }
pose proof (@authorizations_preserve_protected_storage F native
(reachable (blockNumber block) initial) (T.authorization_list tx) nil chargedState Hcharged) as Hauth.
change (¬ List.In native (fst authorized) →
protected (reachable (blockNumber block) initial) (snd authorized)) in Hauth.
change (¬ List.In native (fst authorized)) in Habsent.
specialize (Hauth Habsent).
destruct authorized as [authorities prepared]. cbn beta iota zeta delta [snd] in Hauth |- ×.
match goal with |- context [@S.initialize_access_sets tx ?s ?precompiles] ⇒
set (beforeVm := @S.initialize_access_sets tx s precompiles)
end.
assert (Hbefore : protected (reachable (blockNumber block) initial) beforeVm).
{ eapply protected_storage_same_fields with
(before := @E.bump_emptying_transaction_counters F authorities prepared).
- reflexivity.
- reflexivity.
- reflexivity.
- reflexivity.
- apply bump_counters_protected_storage. exact Hauth. }
pose proof (validated_message_gas block tx _ (S.t.world_state beforeVm) Hvalidation) as Hgas.
match goal with |- context [E.Host.call_from_eoa tx ?message beforeVm] ⇒
assert (Htarget : Evmc.Message.t.kind message = Evmc.Message.CallKind.Create ∨
Evmc.Message.t.kind message = Evmc.Message.CallKind.Create2 ∨
(Evmc.Message.t.recipient message = native → Evmc.Message.t.code_address message = native)) by
(unfold E.prepare_message; destruct (T.call_or_create_value tx); cbn; auto);
pose proof (@execution_call_from_eoa_only_reserve_settings F
(blockNumber block) initial tx message
Hrevision Hgas Htarget beforeVm Hbefore) as Hvm;
destruct (E.Host.call_from_eoa tx message beforeVm) as [result afterVm]
end.
cbn [snd] in Hvm.
pose proof (@bump_counters_protected_storage F native
(reachable (blockNumber block) initial) afterVm (sender :: nil) Hvm) as Hafter.
pose proof (protected_storage_undestroyed _ _ _ Hafter) as HnotDeleted.
pose proof (protected_storage_world _ _ _ Hafter) as Hfinal.
destruct Hfinal as [Hmap [Hnonce [Hcode [Hblock Hwrites]]]].
assert (Hfinal : worldProtected (reachable (blockNumber block) initial (blockNumber block))
(S.t.world_state (@E.bump_emptying_transaction_counters F (sender :: nil) afterVm))).
{ split; [exact Hmap|]. split; [exact Hnonce|]. split; [exact Hcode|].
split; [reflexivity|exact Hwrites]. }
change (@Result._return) with (fun (A B : Set) (value : A) ⇒ @inl A B value).
cbn beta iota zeta delta [B.t.with_transactions_processed B.t.with_gas_used B.t.world_state].
apply delete_accounts_protected_storage; [|exact HnotDeleted].
apply world_protected_storage_balance. exact Hfinal.
Qed.
Lemma system_message_only_reserve_settings block addr data initial :
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
worldProtected (reachable (blockNumber block) initial (blockNumber block)) (B.t.world_state block) →
worldProtected (reachable (blockNumber block) initial (blockNumber block))
(B.t.world_state (snd (@E.process_system_message F
block addr data))).
Proof.
intros Hrevision Hworld. unfold E.process_system_message.
match goal with |- context [if ?b then _ else _] ⇒ destruct b end.
{ exact Hworld. }
cbn beta iota zeta.
match goal with |- context [E.Host.call ?message ?entry] ⇒
assert (Hentry : protected (reachable (blockNumber block) initial) entry) by
(destruct Hworld as [Hmap [Hnonce [Hcode Hcontents]]]; constructor;
[exact Hmap|exact Hnonce|exact Hcode|exact Hcontents|cbn; tauto|cbn; tauto]);
assert (Hgas : (0 ≤ Evmc.Message.t.gas message < 2^63)%Z) by
(change (0 ≤ 30000000 < 2^63)%Z; lia);
assert (Hsender : Evmc.Message.t.sender message ≠ native) by
(vm_compute; discriminate);
pose proof (@execution_system_call_only_reserve_settings F
(blockNumber block) initial message
Hrevision Hgas Hsender eq_refl (fun Heq ⇒ Heq) entry Hentry) as Hcall;
destruct (E.Host.call message entry) as [result afterVm]
end.
cbn [snd] in Hcall.
destruct (protected_storage_world _ _ _ Hcall) as [Hmap [Hnonce [Hcode [Hblock Hwrites]]]].
split; [exact Hmap|]. split; [exact Hnonce|]. split; [exact Hcode|].
split; [reflexivity|exact Hwrites].
Qed.
Lemma withdrawal_preserves_protected_storage block withdrawal P :
worldProtected P (B.t.world_state block) →
worldProtected P (B.t.world_state (@E.process_withdrawal F block withdrawal)).
Proof.
intro Hworld. unfold E.process_withdrawal.
apply world_protected_storage_balance. exact Hworld.
Qed.
Lemma withdrawals_preserve_protected_storage block withdrawals P :
worldProtected P (B.t.world_state block) →
worldProtected P (B.t.world_state
(Result.List.fold_left (@E.process_withdrawal F) block withdrawals)).
Proof.
revert block. induction withdrawals as [|wd withdrawals IH]; intros block Hworld.
- exact Hworld.
- change (worldProtected P (B.t.world_state (Result.List.fold_left
(@E.process_withdrawal F) (@E.process_withdrawal F block wd) withdrawals))).
apply IH, withdrawal_preserves_protected_storage. exact Hworld.
Qed.
Local Abbreviation processTransaction := (@E.process_transaction F).
Local Lemma bind_success {A B Error : Set}
(first : A + Error) (next : A → B + Error) value :
MonadVM.Result.op_letdollar first next = inl value →
∃ intermediate, first = inl intermediate ∧ next intermediate = inl value.
Proof.
destruct first; cbn; [intro H; eexists; split; [reflexivity|exact H]|discriminate].
Qed.
Lemma validated_monad_system_transaction_call_kind block tx sender available_gas world :
@E.validate_monad_system_transaction F block tx sender = inl tt →
Evmc.Message.t.kind (@E.prepare_message F sender available_gas tx world) =
Evmc.Message.CallKind.Call.
Proof.
intro Hvalidated. unfold E.validate_monad_system_transaction in Hvalidated.
cbn zeta in Hvalidated.
do 3 (apply bind_success in Hvalidated;
let step := fresh "step" in let Hstep := fresh "Hstep" in
destruct Hvalidated as [step [Hstep Hvalidated]];
cbn beta iota zeta in Hvalidated).
destruct tx as [tx_impl| | |]; [|cbn in Hstep0; discriminate Hstep0..].
cbn in Hstep0. injection Hstep0 as <-.
destruct tx_impl. cbn in Hstep1 |- ×.
match type of Hstep1 with match ?o with Some _ ⇒ _ | None ⇒ _ end = inl _ ⇒
destruct o; [reflexivity|discriminate Hstep1]
end.
Qed.
Theorem process_monad_system_transaction_only_reserve_settings block tx initial :
worldProtected (reachable (blockNumber block) initial (blockNumber block)) (B.t.world_state block) →
match @E.process_monad_system_transaction F block tx with
| inl post ⇒ worldProtected (reachable (blockNumber block) initial (blockNumber block))
(B.t.world_state post)
| inr _ ⇒ True
end.
Proof.
intro Hworld. unfold E.process_monad_system_transaction.
destruct (@E.validate_monad_system_transaction F block tx Chain.Monad.system_sender)
as [[]|error] eqn:Hvalidation; [|exact I].
change (@Result.op_letdollar) with
(fun (A B C : Set) (r : A + B) (f : A → C + B) ⇒
match r with inl value ⇒ f value | inr error ⇒ inr error end).
cbv beta iota zeta.
set (sender := Chain.Monad.system_sender).
match goal with |- context [@S.make block sender tx] ⇒
set (entry := @S.make block sender tx)
end.
assert (Hentry : protected (reachable (blockNumber block) initial) entry).
{ destruct Hworld as [Hmap [Hnonce [Hcode Hcontents]]]. constructor.
- exact Hmap.
- exact Hnonce.
- exact Hcode.
- exact Hcontents.
- cbn [entry S.make]. tauto.
- cbn [entry S.make]. tauto. }
match goal with |- context [@S.initialize_access_sets tx ?charged ?precompiles] ⇒
set (chargedState := charged);
set (beforeVm := @S.initialize_access_sets tx chargedState precompiles)
end.
assert (Hsender : sender ≠ native) by (vm_compute; discriminate).
assert (Hcharged : protected (reachable (blockNumber block) initial) chargedState).
{ unfold chargedState. apply protected_storage_write; [exact Hentry|].
intro Heq. contradiction. }
assert (Hbefore : protected (reachable (blockNumber block) initial) beforeVm).
{ eapply protected_storage_same_fields with (before := chargedState);
[reflexivity|reflexivity|reflexivity|reflexivity|exact Hcharged]. }
match goal with |- context [E.Host.call_from_monad_system_transaction ?message beforeVm] ⇒
pose proof (validated_monad_system_transaction_call_kind block tx sender Gas.zero
(S.t.world_state beforeVm) Hvalidation) as Hkind;
pose proof (@execution_call_from_monad_system_transaction_only_reserve_settings F
(blockNumber block) initial message Hkind beforeVm Hbefore) as Hvm;
destruct (E.Host.call_from_monad_system_transaction message beforeVm) as [result afterVm]
end.
cbn [snd] in Hvm.
unfold Result.when_.
destruct (negb (Evmc.Result.StatusCode.is_success (Evmc.Result.t.status_code result)));
[exact I|].
destruct (protected_storage_world _ _ _ Hvm) as [Hmap [Hnonce [Hcode [Hblock Hwrites]]]].
split; [exact Hmap|]. split; [exact Hnonce|]. split; [exact Hcode|].
split; [reflexivity|exact Hwrites].
Qed.
Theorem dispatch_transaction_only_reserve_settings block tx initial :
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
worldProtected (reachable (blockNumber block) initial (blockNumber block)) (B.t.world_state block) →
(∀ validation, @E.validate_transaction F block tx = inl validation →
E.transaction_validation.sender validation ≠ native ∧
¬ List.In native (fst (prefix block tx validation))) →
match @E.dispatch_transaction F block tx with
| inl post ⇒ worldProtected (reachable (blockNumber block) initial (blockNumber block))
(B.t.world_state post)
| inr _ ⇒ True
end.
Proof.
intros Hrevision Hworld Hsignatures. unfold E.dispatch_transaction.
destruct (T.chain_id tx) as [cid|];
[destruct (Support.UintN.op_ltgt cid (@E.Params F).(Execution.Make_Params_signature.chain_id));
[exact I|]|].
all: destruct (@E.sender_kind_value F tx) as [[sender|]|];
[apply process_transaction_only_reserve_settings; assumption
|apply process_monad_system_transaction_only_reserve_settings; assumption
|exact I].
Qed.
Lemma dispatch_transaction_current_block block tx post :
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
@E.dispatch_transaction F block tx = inl post →
B.t.current_block post = B.t.current_block block.
Proof.
intros Hrevision Hrun.
destruct (transactionformat.dispatch_transaction_cases block tx post Hrun)
as [[sender [_ Hstep]] | [_ Hstep]].
- exact (@process_transaction_current_block F block tx post Hstep).
- exact (proj2 (proj2 (@process_monad_system_transaction_activity_history F
block tx post Hrevision Hstep))).
Qed.
Lemma dispatched_transactions_only_reserve_settings block txs initial :
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
worldProtected (reachable (blockNumber block) initial (blockNumber block)) (B.t.world_state block) →
(∀ tx state validation, List.In tx txs →
@E.validate_transaction F state tx = inl validation →
E.transaction_validation.sender validation ≠ native ∧
¬ List.In native (fst (prefix state tx validation))) →
match Result.List.fold_leftM (@E.dispatch_transaction F) block txs with
| inl post ⇒ B.t.current_block post = B.t.current_block block ∧
worldProtected (reachable (blockNumber block) initial (blockNumber block)) (B.t.world_state post)
| inr _ ⇒ True end.
Proof.
intro Hrevision. revert block.
induction txs as [|tx txs IH]; intros block Hworld Hsignatures.
- split; [reflexivity|exact Hworld].
- change (match Result.op_letdollar (@E.dispatch_transaction F block tx)
(fun next ⇒ Result.List.fold_leftM (@E.dispatch_transaction F) next txs) with
| inl post ⇒ B.t.current_block post = B.t.current_block block ∧
worldProtected (reachable (blockNumber block) initial (blockNumber block)) (B.t.world_state post)
| inr _ ⇒ True end).
pose proof (dispatch_transaction_only_reserve_settings block tx initial Hrevision Hworld
(fun v Hv ⇒ Hsignatures tx block v (or_introl eq_refl) Hv)) as Hnext.
destruct (@E.dispatch_transaction F block tx) as [next|error] eqn:Hstep; [|exact I].
pose proof (dispatch_transaction_current_block block tx next Hrevision Hstep) as Hcurrent.
assert (Hnext' : worldProtected (reachable (blockNumber next) initial (blockNumber next))
(B.t.world_state next)).
{ cbv beta. rewrite Hcurrent. exact Hnext. }
specialize (IH next Hnext' (fun t state v Hin Hv ⇒
Hsignatures t state v (or_intror Hin) Hv)).
change (match Result.List.fold_leftM (@E.dispatch_transaction F) next txs with
| inl post ⇒ B.t.current_block post = B.t.current_block block ∧
worldProtected (reachable (blockNumber block) initial (blockNumber block)) (B.t.world_state post)
| inr _ ⇒ True end).
destruct (Result.List.fold_leftM (@E.dispatch_transaction F) next txs) as [post|error]; [|exact I].
destruct IH as [Hblock Hpost]. split.
+ exact (eq_trans Hblock Hcurrent).
+ cbv beta in Hpost |- ×. rewrite Hcurrent in Hpost. exact Hpost.
Qed.
Lemma transactions_only_reserve_settings block txs initial :
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
worldProtected (reachable (blockNumber block) initial (blockNumber block)) (B.t.world_state block) →
(∀ tx state validation, List.In tx txs →
@E.validate_transaction F state tx = inl validation →
E.transaction_validation.sender validation ≠ native ∧
¬ List.In native (fst (prefix state tx validation))) →
match Result.List.fold_leftM processTransaction block txs with
| inl post ⇒ B.t.current_block post = B.t.current_block block ∧
worldProtected (reachable (blockNumber block) initial (blockNumber block)) (B.t.world_state post)
| inr _ ⇒ True end.
Proof.
intro Hrevision. revert block.
induction txs as [|tx txs IH]; intros block Hworld Hsignatures.
- split; [reflexivity|exact Hworld].
- change (match Result.op_letdollar (processTransaction block tx)
(fun next ⇒ Result.List.fold_leftM processTransaction next txs) with
| inl post ⇒ B.t.current_block post = B.t.current_block block ∧
worldProtected (reachable (blockNumber block) initial (blockNumber block)) (B.t.world_state post)
| inr _ ⇒ True end).
pose proof (process_transaction_only_reserve_settings block tx initial Hrevision Hworld
(fun v Hv ⇒ Hsignatures tx block v (or_introl eq_refl) Hv)) as Hnext.
destruct (processTransaction block tx) as [next|error] eqn:Hstep; [|exact I].
pose proof (@process_transaction_current_block F
block tx next Hstep) as Hcurrent.
assert (Hnext' : worldProtected (reachable (blockNumber next) initial (blockNumber next))
(B.t.world_state next)).
{ cbv beta. rewrite Hcurrent. exact Hnext. }
specialize (IH next Hnext' (fun t state v Hin Hv ⇒
Hsignatures t state v (or_intror Hin) Hv)).
change (match Result.List.fold_leftM processTransaction next txs with
| inl post ⇒ B.t.current_block post = B.t.current_block block ∧
worldProtected (reachable (blockNumber block) initial (blockNumber block)) (B.t.world_state post)
| inr _ ⇒ True end).
destruct (Result.List.fold_leftM processTransaction next txs) as [post|error]; [|exact I].
destruct IH as [Hblock Hpost]. split.
+ exact (eq_trans Hblock Hcurrent).
+ cbv beta in Hpost |- ×. rewrite Hcurrent in Hpost. exact Hpost.
Qed.
Context {UTries : Basics.Unreachable (OCamlIarray.t Mpt.Trie.t)}
{UChar : Basics.Unreachable OCamlChar.t} {UWorld : Basics.Unreachable W.t}
{UTrie : Basics.Unreachable Mpt.Trie.t} {UNibbles : Basics.Unreachable Mpt.Nibbles.t}
{UBlock : Basics.Unreachable Chain.Ethereum.Block.t}.
Local Abbreviation readAccount := (fun world addr ⇒
State.op_pointcaretlparenrparen world (@W.account None addr)).
Activation establishes the native nonce invariant; both system calls,
all transactions and withdrawals then preserve storage isolation. The
conclusion includes empty blocks and ordinary execution reverts. Invalid
block/transaction validation returns no post-state.
Theorem process_block_only_reserve_settings verify world block :
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
stringmaps.WellFormed (W.t.accounts world) →
A.t.code (readAccount world native) = Byte_string.Bytes.empty →
(∀ tx state validation, List.In tx (Chain.Ethereum.Block.t.transactions block) →
@E.validate_transaction F state tx = inl validation →
E.transaction_validation.sender validation ≠ native ∧
¬ List.In native (fst (prefix state tx validation))) →
let n := Chain.Ethereum.Block.Header.t.number (Chain.Ethereum.Block.t.header block) in
let initial := A.t.storage (readAccount world native) in
match @E.process_block F verify world block with
| inl post ⇒ worldProtected (reachable n initial n) post | inr _ ⇒ True end.
Proof.
intros Hrevision Hmap Hempty Hsignatures n initialStorage.
unfold E.process_block. rewrite Hrevision.
change (@Result.op_letdollar) with
(fun (A B C : Set) (r : A + B) (f : A → C + B) ⇒
match r with inl value ⇒ f value | inr error ⇒ inr error end).
destruct (@E.validate_block F world block) as [[]|error] eqn:Hvalidation.
2: exact I.
cbn beta iota zeta.
match goal with |- context [B.make ?w block] ⇒ set (initial := B.make w block) end.
assert (Hinitial : worldProtected (reachable n initialStorage n) (B.t.world_state initial)).
{ pose proof (@active_account world Hmap) as [Hstorage Hnonce].
split; [apply account_write_wellformed; exact Hmap|].
split; [exact Hnonce|]. split.
- change (A.t.code (readAccount (B.t.world_state initial) native) = Byte_string.Bytes.empty).
unfold initial. cbn [B.make B.t.world_state].
unfold Reserve_balance.activate_precompile. cbv beta zeta.
change (A.t.code (readAccount (State.op_pointcaretlparenrparenltminus world
(@W.account (Some false) native)
(A.t.with_nonce (Numeric.U64.max (A.t.nonce (readAccount world native))
(@Numeric.U64.one)) (readAccount world native))) native) = Byte_string.Bytes.empty).
cbv beta. rewrite account_write_same_code by (first [exact Hmap|reflexivity]). exact Hempty.
- split; [reflexivity|]. ∃ nil. unfold initial. cbn [B.make B.t.world_state].
match goal with |- ?relation ?output ⇒ change (output = initialStorage) in Hstorage end.
rewrite Hstorage. constructor. }
assert (HinitialNumber : blockNumber initial = n) by reflexivity.
assert (Hinitial' : worldProtected (reachable (blockNumber initial) initialStorage (blockNumber initial))
(B.t.world_state initial)) by (rewrite HinitialNumber; exact Hinitial).
match goal with |- context [E.process_system_message initial ?addr ?data] ⇒
pose proof (system_message_only_reserve_settings initial addr data initialStorage Hrevision Hinitial') as Hbeacon;
pose proof (@system_message_current_block F
initial addr data) as HbeaconCurrent;
destruct (E.process_system_message initial addr data) as [beaconResult afterBeacon]
end.
cbn beta iota zeta delta [snd] in Hbeacon, HbeaconCurrent |- ×.
assert (HbeaconNumber : blockNumber afterBeacon = n).
{ cbv beta. rewrite HbeaconCurrent. exact HinitialNumber. }
assert (Hbeacon' : worldProtected (reachable (blockNumber afterBeacon) initialStorage (blockNumber afterBeacon))
(B.t.world_state afterBeacon)).
{ rewrite HbeaconNumber. rewrite HinitialNumber in Hbeacon. exact Hbeacon. }
match goal with |- context [E.process_system_message afterBeacon ?addr ?data] ⇒
pose proof (system_message_only_reserve_settings afterBeacon addr data initialStorage Hrevision Hbeacon') as Hhistory;
pose proof (@system_message_current_block F
afterBeacon addr data) as HhistoryCurrent;
destruct (E.process_system_message afterBeacon addr data) as [historyResult afterHistory]
end.
cbn beta iota zeta delta [snd] in Hhistory, HhistoryCurrent |- ×.
assert (HhistoryNumber : blockNumber afterHistory = n).
{ cbv beta. rewrite HhistoryCurrent. exact HbeaconNumber. }
assert (Hhistory' : worldProtected (reachable (blockNumber afterHistory) initialStorage (blockNumber afterHistory))
(B.t.world_state afterHistory)).
{ rewrite HhistoryNumber. rewrite HbeaconNumber in Hhistory. exact Hhistory. }
pose proof (dispatched_transactions_only_reserve_settings afterHistory
(Chain.Ethereum.Block.t.transactions block) initialStorage Hrevision Hhistory' Hsignatures) as Htransactions.
match goal with |- context [Result.List.fold_leftM ?step afterHistory ?txs] ⇒
destruct (Result.List.fold_leftM step afterHistory txs) as [afterTransactions|error]
end.
2: exact I.
cbn beta iota zeta in Htransactions |- ×.
destruct Htransactions as [HtxCurrent Htransactions].
rewrite HhistoryNumber in Htransactions.
pose proof (withdrawals_preserve_protected_storage afterTransactions
(Chain.Ethereum.Block.t.withdrawals block) _ Htransactions) as Hwithdrawals.
match goal with |- context [E.validate_block ?world ?block] ⇒
destruct (E.validate_block world block) as [[]|error]
end.
2: exact I.
match goal with |- context [if verify then ?check else _] ⇒
destruct verify; [destruct check as [[]|error]; [|exact I]|]
end.
all: exact Hwithdrawals.
Qed.
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
stringmaps.WellFormed (W.t.accounts world) →
A.t.code (readAccount world native) = Byte_string.Bytes.empty →
(∀ tx state validation, List.In tx (Chain.Ethereum.Block.t.transactions block) →
@E.validate_transaction F state tx = inl validation →
E.transaction_validation.sender validation ≠ native ∧
¬ List.In native (fst (prefix state tx validation))) →
let n := Chain.Ethereum.Block.Header.t.number (Chain.Ethereum.Block.t.header block) in
let initial := A.t.storage (readAccount world native) in
match @E.process_block F verify world block with
| inl post ⇒ worldProtected (reachable n initial n) post | inr _ ⇒ True end.
Proof.
intros Hrevision Hmap Hempty Hsignatures n initialStorage.
unfold E.process_block. rewrite Hrevision.
change (@Result.op_letdollar) with
(fun (A B C : Set) (r : A + B) (f : A → C + B) ⇒
match r with inl value ⇒ f value | inr error ⇒ inr error end).
destruct (@E.validate_block F world block) as [[]|error] eqn:Hvalidation.
2: exact I.
cbn beta iota zeta.
match goal with |- context [B.make ?w block] ⇒ set (initial := B.make w block) end.
assert (Hinitial : worldProtected (reachable n initialStorage n) (B.t.world_state initial)).
{ pose proof (@active_account world Hmap) as [Hstorage Hnonce].
split; [apply account_write_wellformed; exact Hmap|].
split; [exact Hnonce|]. split.
- change (A.t.code (readAccount (B.t.world_state initial) native) = Byte_string.Bytes.empty).
unfold initial. cbn [B.make B.t.world_state].
unfold Reserve_balance.activate_precompile. cbv beta zeta.
change (A.t.code (readAccount (State.op_pointcaretlparenrparenltminus world
(@W.account (Some false) native)
(A.t.with_nonce (Numeric.U64.max (A.t.nonce (readAccount world native))
(@Numeric.U64.one)) (readAccount world native))) native) = Byte_string.Bytes.empty).
cbv beta. rewrite account_write_same_code by (first [exact Hmap|reflexivity]). exact Hempty.
- split; [reflexivity|]. ∃ nil. unfold initial. cbn [B.make B.t.world_state].
match goal with |- ?relation ?output ⇒ change (output = initialStorage) in Hstorage end.
rewrite Hstorage. constructor. }
assert (HinitialNumber : blockNumber initial = n) by reflexivity.
assert (Hinitial' : worldProtected (reachable (blockNumber initial) initialStorage (blockNumber initial))
(B.t.world_state initial)) by (rewrite HinitialNumber; exact Hinitial).
match goal with |- context [E.process_system_message initial ?addr ?data] ⇒
pose proof (system_message_only_reserve_settings initial addr data initialStorage Hrevision Hinitial') as Hbeacon;
pose proof (@system_message_current_block F
initial addr data) as HbeaconCurrent;
destruct (E.process_system_message initial addr data) as [beaconResult afterBeacon]
end.
cbn beta iota zeta delta [snd] in Hbeacon, HbeaconCurrent |- ×.
assert (HbeaconNumber : blockNumber afterBeacon = n).
{ cbv beta. rewrite HbeaconCurrent. exact HinitialNumber. }
assert (Hbeacon' : worldProtected (reachable (blockNumber afterBeacon) initialStorage (blockNumber afterBeacon))
(B.t.world_state afterBeacon)).
{ rewrite HbeaconNumber. rewrite HinitialNumber in Hbeacon. exact Hbeacon. }
match goal with |- context [E.process_system_message afterBeacon ?addr ?data] ⇒
pose proof (system_message_only_reserve_settings afterBeacon addr data initialStorage Hrevision Hbeacon') as Hhistory;
pose proof (@system_message_current_block F
afterBeacon addr data) as HhistoryCurrent;
destruct (E.process_system_message afterBeacon addr data) as [historyResult afterHistory]
end.
cbn beta iota zeta delta [snd] in Hhistory, HhistoryCurrent |- ×.
assert (HhistoryNumber : blockNumber afterHistory = n).
{ cbv beta. rewrite HhistoryCurrent. exact HbeaconNumber. }
assert (Hhistory' : worldProtected (reachable (blockNumber afterHistory) initialStorage (blockNumber afterHistory))
(B.t.world_state afterHistory)).
{ rewrite HhistoryNumber. rewrite HbeaconNumber in Hhistory. exact Hhistory. }
pose proof (dispatched_transactions_only_reserve_settings afterHistory
(Chain.Ethereum.Block.t.transactions block) initialStorage Hrevision Hhistory' Hsignatures) as Htransactions.
match goal with |- context [Result.List.fold_leftM ?step afterHistory ?txs] ⇒
destruct (Result.List.fold_leftM step afterHistory txs) as [afterTransactions|error]
end.
2: exact I.
cbn beta iota zeta in Htransactions |- ×.
destruct Htransactions as [HtxCurrent Htransactions].
rewrite HhistoryNumber in Htransactions.
pose proof (withdrawals_preserve_protected_storage afterTransactions
(Chain.Ethereum.Block.t.withdrawals block) _ Htransactions) as Hwithdrawals.
match goal with |- context [E.validate_block ?world ?block] ⇒
destruct (E.validate_block world block) as [[]|error]
end.
2: exact I.
match goal with |- context [if verify then ?check else _] ⇒
destruct verify; [destruct check as [[]|error]; [|exact I]|]
end.
all: exact Hwithdrawals.
Qed.
The execution-dependent exclusions above follow from the input
signatures alone. In particular no VM or authorization-processing
postcondition is assumed here. The reserved-address exclusion itself
remains a cryptographic premise for the eventual solvency theorem.
Corollary process_block_reserve_storage verify world block :
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
stringmaps.WellFormed (W.t.accounts world) →
A.t.code (readAccount world native) = Byte_string.Bytes.empty →
List.Forall (fun tx ⇒ @signaturesAvoidAddress F tx native)
(Chain.Ethereum.Block.t.transactions block) →
let n := Chain.Ethereum.Block.Header.t.number (Chain.Ethereum.Block.t.header block) in
let initial := A.t.storage (readAccount world native) in
match @E.process_block F verify world block with
| inl post ⇒ worldProtected (reachable n initial n) post | inr _ ⇒ True end.
Proof.
intros Hrevision Hmap Hempty Hsignatures.
apply process_block_only_reserve_settings; [exact Hrevision|exact Hmap|exact Hempty|].
intros tx state validation Hin Hvalidation.
apply (@signature_exclusions_for_prefix F state tx validation native).
- apply List.Forall_forall with (x := tx) in Hsignatures; assumption.
- exact Hvalidation.
Qed.
Local Abbreviation writes := (@reserveStorageWrites).
Local Abbreviation readConfig := (@Reserve_balance.stored_config).
Local Abbreviation slotsDisjoint := (@reserveencoding.configSlotsDisjoint).
Local Abbreviation active := (@Reserve_config.active).
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
stringmaps.WellFormed (W.t.accounts world) →
A.t.code (readAccount world native) = Byte_string.Bytes.empty →
List.Forall (fun tx ⇒ @signaturesAvoidAddress F tx native)
(Chain.Ethereum.Block.t.transactions block) →
let n := Chain.Ethereum.Block.Header.t.number (Chain.Ethereum.Block.t.header block) in
let initial := A.t.storage (readAccount world native) in
match @E.process_block F verify world block with
| inl post ⇒ worldProtected (reachable n initial n) post | inr _ ⇒ True end.
Proof.
intros Hrevision Hmap Hempty Hsignatures.
apply process_block_only_reserve_settings; [exact Hrevision|exact Hmap|exact Hempty|].
intros tx state validation Hin Hvalidation.
apply (@signature_exclusions_for_prefix F state tx validation native).
- apply List.Forall_forall with (x := tx) in Hsignatures; assumption.
- exact Hvalidation.
Qed.
Local Abbreviation writes := (@reserveStorageWrites).
Local Abbreviation readConfig := (@Reserve_balance.stored_config).
Local Abbreviation slotsDisjoint := (@reserveencoding.configSlotsDisjoint).
Local Abbreviation active := (@Reserve_config.active).
Every successful concrete block admits a finite explanation by native
settings. For any queried account whose slots do not collide with those
settings, the next K thresholds are unchanged. This does not postulate
global hash injectivity or an arbitrary VM storage invariant.
Corollary process_block_configured_window verify world block post :
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
stringmaps.WellFormed (W.t.accounts world) →
A.t.code (readAccount world native) = Byte_string.Bytes.empty →
stringmaps.WellFormed (A.t.storage (readAccount world native)) →
hoststoragewords.storageWords (A.t.storage (readAccount world native)) →
List.Forall (fun tx ⇒ @signaturesAvoidAddress F tx native)
(Chain.Ethereum.Block.t.transactions block) →
@E.process_block F verify world block = inl post →
let n := Chain.Ethereum.Block.Header.t.number (Chain.Ethereum.Block.t.header block) in
∃ updates,
writes n (A.t.storage (readAccount world native)) updates (A.t.storage (readAccount post native)) ∧
∀ query target,
List.Forall (fun update ⇒ fst update = query ∨ slotsDisjoint (fst update) query) updates →
(n ≤ target < n + 3)%N →
active (readConfig post query) target = active (readConfig world query) target.
Proof using F UChar UNibbles.
intros Hrevision Hmap Hempty Hstorage Hwords Hsignatures Hrun n.
pose proof (process_block_reserve_storage verify world block Hrevision Hmap Hempty Hsignatures) as Hpost.
rewrite Hrun in Hpost.
destruct Hpost as [HpostMap [HpostNonce [HpostCode [Hblock [updates Hupdates]]]]].
∃ updates. split; [exact Hupdates|].
intros query target Hslots Hrange.
exact (reserve_storage_writes_threshold n (A.t.storage (readAccount world native)) updates
(A.t.storage (readAccount post native)) query target Hstorage Hwords Hupdates Hslots Hrange).
Qed.
Local Abbreviation configured := (@Reserve_balance.user_reserve_balance).
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
stringmaps.WellFormed (W.t.accounts world) →
A.t.code (readAccount world native) = Byte_string.Bytes.empty →
stringmaps.WellFormed (A.t.storage (readAccount world native)) →
hoststoragewords.storageWords (A.t.storage (readAccount world native)) →
List.Forall (fun tx ⇒ @signaturesAvoidAddress F tx native)
(Chain.Ethereum.Block.t.transactions block) →
@E.process_block F verify world block = inl post →
let n := Chain.Ethereum.Block.Header.t.number (Chain.Ethereum.Block.t.header block) in
∃ updates,
writes n (A.t.storage (readAccount world native)) updates (A.t.storage (readAccount post native)) ∧
∀ query target,
List.Forall (fun update ⇒ fst update = query ∨ slotsDisjoint (fst update) query) updates →
(n ≤ target < n + 3)%N →
active (readConfig post query) target = active (readConfig world query) target.
Proof using F UChar UNibbles.
intros Hrevision Hmap Hempty Hstorage Hwords Hsignatures Hrun n.
pose proof (process_block_reserve_storage verify world block Hrevision Hmap Hempty Hsignatures) as Hpost.
rewrite Hrun in Hpost.
destruct Hpost as [HpostMap [HpostNonce [HpostCode [Hblock [updates Hupdates]]]]].
∃ updates. split; [exact Hupdates|].
intros query target Hslots Hrange.
exact (reserve_storage_writes_threshold n (A.t.storage (readAccount world native)) updates
(A.t.storage (readAccount post native)) query target Hstorage Hwords Hupdates Hslots Hrange).
Qed.
Local Abbreviation configured := (@Reserve_balance.user_reserve_balance).
Native storage is initialized by block entry. A complete transaction
may perform arbitrarily many successful settings, including settings
from delegated contexts, but none can change a threshold before K blocks.
The finite write witness exposes exactly where slot separation is needed.
Theorem process_transaction_configured_window block tx post :
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
worldProtected (fun _ ⇒ True) (B.t.world_state block) →
stringmaps.WellFormed (A.t.storage (readAccount (B.t.world_state block) native)) →
hoststoragewords.storageWords (A.t.storage (readAccount (B.t.world_state block) native)) →
@signaturesAvoidAddress F tx native →
processTransaction block tx = inl post →
∃ updates,
worldProtected (writes (blockNumber block)
(A.t.storage (readAccount (B.t.world_state block) native)) updates) (B.t.world_state post) ∧
∀ query target,
List.Forall (fun update ⇒ fst update = query ∨ slotsDisjoint (fst update) query) updates →
(blockNumber block ≤ target < blockNumber block + 3)%N →
configured (B.t.world_state post) target query = configured (B.t.world_state block) target query.
Proof using F UChar UNibbles.
intros Hrevision [Hmap [Hnonce [Hcode _]]] Hstorage Hwords Hsignatures Hrun.
assert (Hinitial : worldProtected
(reachable (blockNumber block) (A.t.storage (readAccount (B.t.world_state block) native)) (blockNumber block))
(B.t.world_state block)).
{ split; [exact Hmap|]. split; [exact Hnonce|]. split; [exact Hcode|].
split; [reflexivity|]. ∃ nil. constructor. }
pose proof (process_transaction_only_reserve_settings block tx
(A.t.storage (readAccount (B.t.world_state block) native)) Hrevision Hinitial
(fun validation Hvalidation ⇒ @signature_exclusions_for_prefix F block tx validation native Hsignatures Hvalidation)) as Hpost.
rewrite Hrun in Hpost.
destruct Hpost as [HpostMap [HpostNonce [HpostCode [_ [updates Hupdates]]]]].
∃ updates. split.
- split; [exact HpostMap|]. split; [exact HpostNonce|]. split; assumption.
- intros query target Hslots Hrange.
pose proof (reserve_storage_writes_threshold (blockNumber block) (A.t.storage (readAccount (B.t.world_state block) native)) updates
(A.t.storage (readAccount (B.t.world_state post) native)) query target Hstorage Hwords Hupdates Hslots Hrange)
as Hthreshold.
unfold Reserve_balance.user_reserve_balance. f_equal. exact Hthreshold.
Qed.
End Execution.
Print Assumptions process_transaction_only_reserve_settings.
Print Assumptions system_message_only_reserve_settings.
Print Assumptions process_block_only_reserve_settings.
Print Assumptions process_block_configured_window.
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
worldProtected (fun _ ⇒ True) (B.t.world_state block) →
stringmaps.WellFormed (A.t.storage (readAccount (B.t.world_state block) native)) →
hoststoragewords.storageWords (A.t.storage (readAccount (B.t.world_state block) native)) →
@signaturesAvoidAddress F tx native →
processTransaction block tx = inl post →
∃ updates,
worldProtected (writes (blockNumber block)
(A.t.storage (readAccount (B.t.world_state block) native)) updates) (B.t.world_state post) ∧
∀ query target,
List.Forall (fun update ⇒ fst update = query ∨ slotsDisjoint (fst update) query) updates →
(blockNumber block ≤ target < blockNumber block + 3)%N →
configured (B.t.world_state post) target query = configured (B.t.world_state block) target query.
Proof using F UChar UNibbles.
intros Hrevision [Hmap [Hnonce [Hcode _]]] Hstorage Hwords Hsignatures Hrun.
assert (Hinitial : worldProtected
(reachable (blockNumber block) (A.t.storage (readAccount (B.t.world_state block) native)) (blockNumber block))
(B.t.world_state block)).
{ split; [exact Hmap|]. split; [exact Hnonce|]. split; [exact Hcode|].
split; [reflexivity|]. ∃ nil. constructor. }
pose proof (process_transaction_only_reserve_settings block tx
(A.t.storage (readAccount (B.t.world_state block) native)) Hrevision Hinitial
(fun validation Hvalidation ⇒ @signature_exclusions_for_prefix F block tx validation native Hsignatures Hvalidation)) as Hpost.
rewrite Hrun in Hpost.
destruct Hpost as [HpostMap [HpostNonce [HpostCode [_ [updates Hupdates]]]]].
∃ updates. split.
- split; [exact HpostMap|]. split; [exact HpostNonce|]. split; assumption.
- intros query target Hslots Hrange.
pose proof (reserve_storage_writes_threshold (blockNumber block) (A.t.storage (readAccount (B.t.world_state block) native)) updates
(A.t.storage (readAccount (B.t.world_state post) native)) query target Hstorage Hwords Hupdates Hslots Hrange)
as Hthreshold.
unfold Reserve_balance.user_reserve_balance. f_equal. exact Hthreshold.
Qed.
End Execution.
Print Assumptions process_transaction_only_reserve_settings.
Print Assumptions system_message_only_reserve_settings.
Print Assumptions process_block_only_reserve_settings.
Print Assumptions process_block_configured_window.