Library QedkConcrete.transactionformat
Representation through concrete transaction execution
From Stdlib Require Import List ZArith Lia.
Require Import RocqOfOCaml.RocqOfOCaml.
Require Import MonadVM.Execution QedkConcrete.executioncontext
QedkConcrete.authorization QedkConcrete.validation QedkConcrete.emptyinghistory
QedkConcrete.hostaccountformat QedkConcrete.hoststoragewords.
Set Default Goal Selector "!".
Module E := Execution.Make.
Module S := State.TransactionState.
Module B := State.BlockState.
Module W := State.WorldState.
Module A := Chain.Ethereum.Account.
Module T := Chain.Ethereum.Transaction.
Section Execution.
Context {F : E.FArgs}.
Lemma bump_counters_format s addresses :
hostFormat s → hostFormat (@E.bump_emptying_transaction_counters F addresses s).
Proof.
intros [Hworld Htransient]. split; [|exact Htransient].
unfold worldFormat, E.bump_emptying_transaction_counters.
cbn beta iota zeta delta [S.t.with_world_state S.t.world_state].
rewrite counter_writes_accounts. exact Hworld.
Qed.
Lemma delete_accounts_format block addresses :
worldFormat (B.t.world_state block) →
worldFormat (B.t.world_state (OCamlSeq.fold_left
(fun s addr ⇒ State.op_pointcaretlparenrparenltminus s
(@B.account_opt None addr) None) block addresses)).
Proof.
revert block. induction addresses as [|addr addresses IH]; intros block Hformat.
- exact Hformat.
- cbn [OCamlSeq.fold_left]. apply IH.
change (List.Forall (fun entry ⇒ accountFormat (snd entry))
(OCamlMap.Make.remove stringmaps.stringOrder addr (W.t.accounts (B.t.world_state block)))).
apply map_remove_value_property. exact Hformat.
Qed.
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)}.
Theorem process_transaction_preserves_format block tx :
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
List.Forall (fun auth ⇒ OCamlString.length (T.Authorization.t.address auth) = 20%Z)
(T.authorization_list tx) →
worldFormat (B.t.world_state block) →
match @E.process_transaction F block tx with
| inl post ⇒ worldFormat (B.t.world_state post)
| inr _ ⇒ True
end.
Proof.
intros Hrevision Hwidth Hworld. unfold E.process_transaction.
destruct (@E.validate_transaction F block tx) as [validation|error] eqn:Hvalidation.
2: exact I.
destruct validation as [sender fee price intrinsic].
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 (initial := @S.make block sender tx)
end.
assert (Hinitial : hostFormat initial) by (apply transaction_initial_format; exact Hworld).
pose proof (@transaction_entry_format F initial sender fee (T.authorization_list tx) Hwidth Hinitial) as Hauth.
match goal with |- context [Result.List.fold_left ?f ?start (T.authorization_list tx)] ⇒
set (authorized := Result.List.fold_left f start (T.authorization_list tx))
end.
change (hostFormat (snd authorized)) in Hauth.
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 : hostFormat beforeVm).
{ change (hostFormat (@E.bump_emptying_transaction_counters F authorities prepared)).
apply bump_counters_format. 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] ⇒
pose proof (@execution_call_from_eoa_preserves_format F
tx message Hrevision Hgas 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_format afterVm (sender :: nil) Hvm) as [Hafter _].
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_format.
apply write_account_format; [exact Hafter|].
apply balance_update_format, read_account_format. exact Hafter.
Qed.
Theorem process_monad_system_transaction_preserves_format block tx :
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
worldFormat (B.t.world_state block) →
match @E.process_monad_system_transaction F block tx with
| inl post ⇒ worldFormat (B.t.world_state post)
| inr _ ⇒ True
end.
Proof.
intros Hrevision Hworld. unfold E.process_monad_system_transaction.
destruct (@E.validate_monad_system_transaction F block tx Chain.Monad.system_sender)
as [[]|error]; [|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.
match goal with |- context [@S.initialize_access_sets tx ?s ?precompiles] ⇒
set (beforeVm := @S.initialize_access_sets tx s precompiles)
end.
assert (Hbefore : hostFormat beforeVm).
{ split; [|constructor].
apply write_account_format; [exact Hworld|].
apply nonce_update_format, read_account_format. exact Hworld. }
match goal with |- context [E.Host.call_from_monad_system_transaction ?message beforeVm] ⇒
assert (Hgas : (0 ≤ Evmc.Message.t.gas message < 2^63)%Z) by
(unfold E.prepare_message; destruct (T.call_or_create_value tx) as [[]|[]];
change (0 ≤ 0 < 2^63)%Z; lia);
pose proof (@execution_call_from_monad_system_transaction_preserves_format F
message Hrevision Hgas beforeVm Hbefore) as [Hafter _];
destruct (E.Host.call_from_monad_system_transaction message beforeVm) as [result afterVm]
end.
unfold Result.when_.
destruct (negb (Evmc.Result.StatusCode.is_success (Evmc.Result.t.status_code result)));
[exact I|].
exact Hafter.
Qed.
Lemma dispatch_transaction_cases block tx post :
@E.dispatch_transaction F block tx = inl post →
(∃ sender, @E.sender_kind_value F tx = Some (E.EOA sender) ∧
@E.process_transaction F block tx = inl post) ∨
(@E.sender_kind_value F tx = Some E.System ∧
@E.process_monad_system_transaction F block tx = inl post).
Proof.
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));
[discriminate|]|].
all: destruct (@E.sender_kind_value F tx) as [[sender|]|] eqn:Hkind;
[intro Hrun; left; ∃ sender; split; [reflexivity|exact Hrun]
|intro Hrun; right; split; [reflexivity|exact Hrun]
|discriminate].
Qed.
Theorem dispatch_transaction_preserves_format block tx :
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
List.Forall (fun auth ⇒ OCamlString.length (T.Authorization.t.address auth) = 20%Z)
(T.authorization_list tx) →
worldFormat (B.t.world_state block) →
match @E.dispatch_transaction F block tx with
| inl post ⇒ worldFormat (B.t.world_state post)
| inr _ ⇒ True
end.
Proof.
intros Hrevision Hwidth Hworld. 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_preserves_format; assumption
|apply process_monad_system_transaction_preserves_format; assumption
|exact I].
Qed.
Require Import RocqOfOCaml.RocqOfOCaml.
Require Import MonadVM.Execution QedkConcrete.executioncontext
QedkConcrete.authorization QedkConcrete.validation QedkConcrete.emptyinghistory
QedkConcrete.hostaccountformat QedkConcrete.hoststoragewords.
Set Default Goal Selector "!".
Module E := Execution.Make.
Module S := State.TransactionState.
Module B := State.BlockState.
Module W := State.WorldState.
Module A := Chain.Ethereum.Account.
Module T := Chain.Ethereum.Transaction.
Section Execution.
Context {F : E.FArgs}.
Lemma bump_counters_format s addresses :
hostFormat s → hostFormat (@E.bump_emptying_transaction_counters F addresses s).
Proof.
intros [Hworld Htransient]. split; [|exact Htransient].
unfold worldFormat, E.bump_emptying_transaction_counters.
cbn beta iota zeta delta [S.t.with_world_state S.t.world_state].
rewrite counter_writes_accounts. exact Hworld.
Qed.
Lemma delete_accounts_format block addresses :
worldFormat (B.t.world_state block) →
worldFormat (B.t.world_state (OCamlSeq.fold_left
(fun s addr ⇒ State.op_pointcaretlparenrparenltminus s
(@B.account_opt None addr) None) block addresses)).
Proof.
revert block. induction addresses as [|addr addresses IH]; intros block Hformat.
- exact Hformat.
- cbn [OCamlSeq.fold_left]. apply IH.
change (List.Forall (fun entry ⇒ accountFormat (snd entry))
(OCamlMap.Make.remove stringmaps.stringOrder addr (W.t.accounts (B.t.world_state block)))).
apply map_remove_value_property. exact Hformat.
Qed.
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)}.
Theorem process_transaction_preserves_format block tx :
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
List.Forall (fun auth ⇒ OCamlString.length (T.Authorization.t.address auth) = 20%Z)
(T.authorization_list tx) →
worldFormat (B.t.world_state block) →
match @E.process_transaction F block tx with
| inl post ⇒ worldFormat (B.t.world_state post)
| inr _ ⇒ True
end.
Proof.
intros Hrevision Hwidth Hworld. unfold E.process_transaction.
destruct (@E.validate_transaction F block tx) as [validation|error] eqn:Hvalidation.
2: exact I.
destruct validation as [sender fee price intrinsic].
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 (initial := @S.make block sender tx)
end.
assert (Hinitial : hostFormat initial) by (apply transaction_initial_format; exact Hworld).
pose proof (@transaction_entry_format F initial sender fee (T.authorization_list tx) Hwidth Hinitial) as Hauth.
match goal with |- context [Result.List.fold_left ?f ?start (T.authorization_list tx)] ⇒
set (authorized := Result.List.fold_left f start (T.authorization_list tx))
end.
change (hostFormat (snd authorized)) in Hauth.
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 : hostFormat beforeVm).
{ change (hostFormat (@E.bump_emptying_transaction_counters F authorities prepared)).
apply bump_counters_format. 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] ⇒
pose proof (@execution_call_from_eoa_preserves_format F
tx message Hrevision Hgas 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_format afterVm (sender :: nil) Hvm) as [Hafter _].
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_format.
apply write_account_format; [exact Hafter|].
apply balance_update_format, read_account_format. exact Hafter.
Qed.
Theorem process_monad_system_transaction_preserves_format block tx :
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
worldFormat (B.t.world_state block) →
match @E.process_monad_system_transaction F block tx with
| inl post ⇒ worldFormat (B.t.world_state post)
| inr _ ⇒ True
end.
Proof.
intros Hrevision Hworld. unfold E.process_monad_system_transaction.
destruct (@E.validate_monad_system_transaction F block tx Chain.Monad.system_sender)
as [[]|error]; [|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.
match goal with |- context [@S.initialize_access_sets tx ?s ?precompiles] ⇒
set (beforeVm := @S.initialize_access_sets tx s precompiles)
end.
assert (Hbefore : hostFormat beforeVm).
{ split; [|constructor].
apply write_account_format; [exact Hworld|].
apply nonce_update_format, read_account_format. exact Hworld. }
match goal with |- context [E.Host.call_from_monad_system_transaction ?message beforeVm] ⇒
assert (Hgas : (0 ≤ Evmc.Message.t.gas message < 2^63)%Z) by
(unfold E.prepare_message; destruct (T.call_or_create_value tx) as [[]|[]];
change (0 ≤ 0 < 2^63)%Z; lia);
pose proof (@execution_call_from_monad_system_transaction_preserves_format F
message Hrevision Hgas beforeVm Hbefore) as [Hafter _];
destruct (E.Host.call_from_monad_system_transaction message beforeVm) as [result afterVm]
end.
unfold Result.when_.
destruct (negb (Evmc.Result.StatusCode.is_success (Evmc.Result.t.status_code result)));
[exact I|].
exact Hafter.
Qed.
Lemma dispatch_transaction_cases block tx post :
@E.dispatch_transaction F block tx = inl post →
(∃ sender, @E.sender_kind_value F tx = Some (E.EOA sender) ∧
@E.process_transaction F block tx = inl post) ∨
(@E.sender_kind_value F tx = Some E.System ∧
@E.process_monad_system_transaction F block tx = inl post).
Proof.
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));
[discriminate|]|].
all: destruct (@E.sender_kind_value F tx) as [[sender|]|] eqn:Hkind;
[intro Hrun; left; ∃ sender; split; [reflexivity|exact Hrun]
|intro Hrun; right; split; [reflexivity|exact Hrun]
|discriminate].
Qed.
Theorem dispatch_transaction_preserves_format block tx :
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
List.Forall (fun auth ⇒ OCamlString.length (T.Authorization.t.address auth) = 20%Z)
(T.authorization_list tx) →
worldFormat (B.t.world_state block) →
match @E.dispatch_transaction F block tx with
| inl post ⇒ worldFormat (B.t.world_state post)
| inr _ ⇒ True
end.
Proof.
intros Hrevision Hwidth Hworld. 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_preserves_format; assumption
|apply process_monad_system_transaction_preserves_format; assumption
|exact I].
Qed.
System messages have no authorizations and use the protocol's fixed gas
allowance. This covers their actual Host calls, not an assumption that
the system contracts have no state effects.
Lemma system_message_preserves_format block addr data :
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
worldFormat (B.t.world_state block) →
worldFormat (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 ?initial] ⇒
assert (Hinitial : hostFormat initial) by (split; [exact Hworld|constructor]);
assert (Hgas : (0 ≤ Evmc.Message.t.gas message < 2^63)%Z)
by (change (0 ≤ 30000000 < 2^63)%Z; lia);
pose proof (@execution_call_preserves_format F
message Hrevision Hgas initial Hinitial) as Hcall;
destruct (E.Host.call message initial) as [result after]
end.
exact (proj1 Hcall).
Qed.
Lemma withdrawal_preserves_format block withdrawal :
worldFormat (B.t.world_state block) →
worldFormat (B.t.world_state (@E.process_withdrawal F block withdrawal)).
Proof.
intro Hworld. unfold E.process_withdrawal.
apply write_account_format; [exact Hworld|].
apply balance_update_format, read_account_format. exact Hworld.
Qed.
Local Lemma result_fold_invariant {Acc Element Error : Set}
(P : Acc → Prop) (Q : Element → Prop) (step : Acc → Element → Acc + Error) entries :
(∀ acc entry, Q entry → P acc →
match step acc entry with inl next ⇒ P next | inr _ ⇒ True end) →
List.Forall Q entries → ∀ acc, P acc →
match Result.List.fold_leftM step acc entries with inl next ⇒ P next | inr _ ⇒ True end.
Proof.
intros Hstep Hentries. induction Hentries as [|entry entries Hentry Hrest IH]; intros acc Hacc.
- exact Hacc.
- change (match Result.op_letdollar (step acc entry)
(fun next ⇒ Result.List.fold_leftM step next entries) with
| inl final ⇒ P final | inr _ ⇒ True end).
specialize (Hstep acc entry Hentry Hacc).
destruct (step acc entry) as [next|error]; [apply IH; exact Hstep|exact I].
Qed.
Lemma transactions_preserve_format block txs :
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
List.Forall (fun tx ⇒ List.Forall
(fun auth ⇒ OCamlString.length (T.Authorization.t.address auth) = 20%Z)
(T.authorization_list tx)) txs →
worldFormat (B.t.world_state block) →
match Result.List.fold_leftM (@E.process_transaction F) block txs with
| inl post ⇒ worldFormat (B.t.world_state post) | inr _ ⇒ True end.
Proof.
intros Hrevision Hwidth Hworld.
apply result_fold_invariant with (Q := fun tx ⇒ List.Forall
(fun auth ⇒ OCamlString.length (T.Authorization.t.address auth) = 20%Z)
(T.authorization_list tx)); try assumption.
intros state tx Htx Hstate. apply process_transaction_preserves_format; assumption.
Qed.
Lemma dispatched_transactions_preserve_format block txs :
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
List.Forall (fun tx ⇒ List.Forall
(fun auth ⇒ OCamlString.length (T.Authorization.t.address auth) = 20%Z)
(T.authorization_list tx)) txs →
worldFormat (B.t.world_state block) →
match Result.List.fold_leftM (@E.dispatch_transaction F) block txs with
| inl post ⇒ worldFormat (B.t.world_state post) | inr _ ⇒ True end.
Proof.
intros Hrevision Hwidth Hworld.
apply result_fold_invariant with (Q := fun tx ⇒ List.Forall
(fun auth ⇒ OCamlString.length (T.Authorization.t.address auth) = 20%Z)
(T.authorization_list tx)); try assumption.
intros state tx Htx Hstate. apply dispatch_transaction_preserves_format; assumption.
Qed.
Lemma withdrawals_preserve_format block withdrawals :
worldFormat (B.t.world_state block) →
worldFormat (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 (worldFormat (B.t.world_state (Result.List.fold_left
(@E.process_withdrawal F) (@E.process_withdrawal F block wd) withdrawals))).
apply IH, withdrawal_preserves_format. exact Hworld.
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}.
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
worldFormat (B.t.world_state block) →
worldFormat (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 ?initial] ⇒
assert (Hinitial : hostFormat initial) by (split; [exact Hworld|constructor]);
assert (Hgas : (0 ≤ Evmc.Message.t.gas message < 2^63)%Z)
by (change (0 ≤ 30000000 < 2^63)%Z; lia);
pose proof (@execution_call_preserves_format F
message Hrevision Hgas initial Hinitial) as Hcall;
destruct (E.Host.call message initial) as [result after]
end.
exact (proj1 Hcall).
Qed.
Lemma withdrawal_preserves_format block withdrawal :
worldFormat (B.t.world_state block) →
worldFormat (B.t.world_state (@E.process_withdrawal F block withdrawal)).
Proof.
intro Hworld. unfold E.process_withdrawal.
apply write_account_format; [exact Hworld|].
apply balance_update_format, read_account_format. exact Hworld.
Qed.
Local Lemma result_fold_invariant {Acc Element Error : Set}
(P : Acc → Prop) (Q : Element → Prop) (step : Acc → Element → Acc + Error) entries :
(∀ acc entry, Q entry → P acc →
match step acc entry with inl next ⇒ P next | inr _ ⇒ True end) →
List.Forall Q entries → ∀ acc, P acc →
match Result.List.fold_leftM step acc entries with inl next ⇒ P next | inr _ ⇒ True end.
Proof.
intros Hstep Hentries. induction Hentries as [|entry entries Hentry Hrest IH]; intros acc Hacc.
- exact Hacc.
- change (match Result.op_letdollar (step acc entry)
(fun next ⇒ Result.List.fold_leftM step next entries) with
| inl final ⇒ P final | inr _ ⇒ True end).
specialize (Hstep acc entry Hentry Hacc).
destruct (step acc entry) as [next|error]; [apply IH; exact Hstep|exact I].
Qed.
Lemma transactions_preserve_format block txs :
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
List.Forall (fun tx ⇒ List.Forall
(fun auth ⇒ OCamlString.length (T.Authorization.t.address auth) = 20%Z)
(T.authorization_list tx)) txs →
worldFormat (B.t.world_state block) →
match Result.List.fold_leftM (@E.process_transaction F) block txs with
| inl post ⇒ worldFormat (B.t.world_state post) | inr _ ⇒ True end.
Proof.
intros Hrevision Hwidth Hworld.
apply result_fold_invariant with (Q := fun tx ⇒ List.Forall
(fun auth ⇒ OCamlString.length (T.Authorization.t.address auth) = 20%Z)
(T.authorization_list tx)); try assumption.
intros state tx Htx Hstate. apply process_transaction_preserves_format; assumption.
Qed.
Lemma dispatched_transactions_preserve_format block txs :
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
List.Forall (fun tx ⇒ List.Forall
(fun auth ⇒ OCamlString.length (T.Authorization.t.address auth) = 20%Z)
(T.authorization_list tx)) txs →
worldFormat (B.t.world_state block) →
match Result.List.fold_leftM (@E.dispatch_transaction F) block txs with
| inl post ⇒ worldFormat (B.t.world_state post) | inr _ ⇒ True end.
Proof.
intros Hrevision Hwidth Hworld.
apply result_fold_invariant with (Q := fun tx ⇒ List.Forall
(fun auth ⇒ OCamlString.length (T.Authorization.t.address auth) = 20%Z)
(T.authorization_list tx)); try assumption.
intros state tx Htx Hstate. apply dispatch_transaction_preserves_format; assumption.
Qed.
Lemma withdrawals_preserve_format block withdrawals :
worldFormat (B.t.world_state block) →
worldFormat (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 (worldFormat (B.t.world_state (Result.List.fold_left
(@E.process_withdrawal F) (@E.process_withdrawal F block wd) withdrawals))).
apply IH, withdrawal_preserves_format. exact Hworld.
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}.
Block-entry reserve-precompile activation, both system messages, all
transactions, and withdrawals preserve the representation. Validation
errors return no post-state; successful root checks only add history.
Theorem process_block_preserves_format verify world block :
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
List.Forall (fun tx ⇒ List.Forall
(fun auth ⇒ OCamlString.length (T.Authorization.t.address auth) = 20%Z)
(T.authorization_list tx)) (Chain.Ethereum.Block.t.transactions block) →
worldFormat world →
match @E.process_block F verify world block with
| inl post ⇒ worldFormat post | inr _ ⇒ True end.
Proof.
intros Hrevision Hwidth Hworld. 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 : worldFormat (B.t.world_state initial)).
{ apply activate_preserves_format. exact Hworld. }
match goal with |- context [E.process_system_message initial ?addr ?data] ⇒
pose proof (system_message_preserves_format initial addr data Hrevision Hinitial) as Hbeacon;
destruct (E.process_system_message initial addr data) as [beaconResult afterBeacon]
end.
cbn beta iota zeta delta [snd] in Hbeacon |- ×.
match goal with |- context [E.process_system_message afterBeacon ?addr ?data] ⇒
pose proof (system_message_preserves_format afterBeacon addr data Hrevision Hbeacon) as Hhistory;
destruct (E.process_system_message afterBeacon addr data) as [historyResult afterHistory]
end.
cbn beta iota zeta delta [snd] in Hhistory |- ×.
pose proof (dispatched_transactions_preserve_format afterHistory
(Chain.Ethereum.Block.t.transactions block) Hrevision Hwidth Hhistory) 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 |- ×.
pose proof (withdrawals_preserve_format 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.
End Execution.
Print Assumptions process_transaction_preserves_format.
Print Assumptions process_block_preserves_format.
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
List.Forall (fun tx ⇒ List.Forall
(fun auth ⇒ OCamlString.length (T.Authorization.t.address auth) = 20%Z)
(T.authorization_list tx)) (Chain.Ethereum.Block.t.transactions block) →
worldFormat world →
match @E.process_block F verify world block with
| inl post ⇒ worldFormat post | inr _ ⇒ True end.
Proof.
intros Hrevision Hwidth Hworld. 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 : worldFormat (B.t.world_state initial)).
{ apply activate_preserves_format. exact Hworld. }
match goal with |- context [E.process_system_message initial ?addr ?data] ⇒
pose proof (system_message_preserves_format initial addr data Hrevision Hinitial) as Hbeacon;
destruct (E.process_system_message initial addr data) as [beaconResult afterBeacon]
end.
cbn beta iota zeta delta [snd] in Hbeacon |- ×.
match goal with |- context [E.process_system_message afterBeacon ?addr ?data] ⇒
pose proof (system_message_preserves_format afterBeacon addr data Hrevision Hbeacon) as Hhistory;
destruct (E.process_system_message afterBeacon addr data) as [historyResult afterHistory]
end.
cbn beta iota zeta delta [snd] in Hhistory |- ×.
pose proof (dispatched_transactions_preserve_format afterHistory
(Chain.Ethereum.Block.t.transactions block) Hrevision Hwidth Hhistory) 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 |- ×.
pose proof (withdrawals_preserve_format 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.
End Execution.
Print Assumptions process_transaction_preserves_format.
Print Assumptions process_block_preserves_format.