Library QedkConcrete.blocktransactionentry
The transaction-loop entry of the generated block executor
From Stdlib Require Import List String ZArith Lia Bool.
Require Import RocqOfOCaml.RocqOfOCaml.
Require Export QedkConcrete.consensusrequirements.
Require Import MonadVM.Execution QedkConcrete.consensusboundaries
QedkConcrete.consensusbacking QedkConcrete.consensuswindow
QedkConcrete.transactionhistoryprojection QedkConcrete.blockhistoryprojection
QedkConcrete.systemmessages QedkConcrete.systemcode
QedkConcrete.blockpersistentcode QedkConcrete.transactionformat
QedkConcrete.transactionchecked QedkConcrete.transactionstage
QedkConcrete.transactioncode QedkConcrete.transactionnonces
QedkConcrete.publictransaction QedkConcrete.supply
QedkConcrete.hashwords QedkConcrete.wordrange QedkConcrete.reservewrites
QedkConcrete.hostaccountformat QedkConcrete.hostcode.
Set Default Goal Selector "!".
#[local] Hint Extern 100 (Basics.Unreachable _) ⇒
(apply Opaque.legacy_witness; Opaque.opaque_inhabit 64%nat) : typeclass_instances.
Import ListNotations.
Local Open Scope Z_scope.
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.
Module Addr := Chain.Ethereum.Address.
Section Execution.
Context {F : E.FArgs}.
Local Abbreviation args := (@E.Instantiation_fargs F).
Local Abbreviation params := args.(Host.Instantiate.ChainParams).
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 readAccount := (fun world addr ⇒ State.op_pointcaretlparenrparen
world (@W.account None addr)).
Local Abbreviation native := (@Reserve_balance.precompile_address).
Local Abbreviation recoveredAuthority := (@Chain.Ethereum.Transaction.Authorization.authority).
Local Abbreviation blockNumber := (fun block ⇒ Chain.Ethereum.Block.Header.t.number
(Chain.Ethereum.Block.t.header (B.t.current_block block))).
Local Abbreviation emptying := (@Reserve_balance.is_emptying_tx).
Local Abbreviation configured := (@Reserve_balance.user_reserve_balance).
Local Abbreviation balance := (fun world a ⇒ Numeric.U256.to_z (A.t.balance (readAccount world a))).
Local Abbreviation systemMessage := (@E.process_system_message F).
Local Abbreviation activate := (@Reserve_balance.activate_precompile).
Context {UBlock : Basics.Unreachable Chain.Ethereum.Block.t}.
Local Abbreviation blockTransactionEntry := (@consensusrequirements.blockTransactionEntry F).
Lemma block_transaction_entry_header world block :
B.t.current_block (blockTransactionEntry world block) = block.
Proof.
unfold blockTransactionEntry. rewrite !system_message_current_block. reflexivity.
Qed.
Require Import RocqOfOCaml.RocqOfOCaml.
Require Export QedkConcrete.consensusrequirements.
Require Import MonadVM.Execution QedkConcrete.consensusboundaries
QedkConcrete.consensusbacking QedkConcrete.consensuswindow
QedkConcrete.transactionhistoryprojection QedkConcrete.blockhistoryprojection
QedkConcrete.systemmessages QedkConcrete.systemcode
QedkConcrete.blockpersistentcode QedkConcrete.transactionformat
QedkConcrete.transactionchecked QedkConcrete.transactionstage
QedkConcrete.transactioncode QedkConcrete.transactionnonces
QedkConcrete.publictransaction QedkConcrete.supply
QedkConcrete.hashwords QedkConcrete.wordrange QedkConcrete.reservewrites
QedkConcrete.hostaccountformat QedkConcrete.hostcode.
Set Default Goal Selector "!".
#[local] Hint Extern 100 (Basics.Unreachable _) ⇒
(apply Opaque.legacy_witness; Opaque.opaque_inhabit 64%nat) : typeclass_instances.
Import ListNotations.
Local Open Scope Z_scope.
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.
Module Addr := Chain.Ethereum.Address.
Section Execution.
Context {F : E.FArgs}.
Local Abbreviation args := (@E.Instantiation_fargs F).
Local Abbreviation params := args.(Host.Instantiate.ChainParams).
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 readAccount := (fun world addr ⇒ State.op_pointcaretlparenrparen
world (@W.account None addr)).
Local Abbreviation native := (@Reserve_balance.precompile_address).
Local Abbreviation recoveredAuthority := (@Chain.Ethereum.Transaction.Authorization.authority).
Local Abbreviation blockNumber := (fun block ⇒ Chain.Ethereum.Block.Header.t.number
(Chain.Ethereum.Block.t.header (B.t.current_block block))).
Local Abbreviation emptying := (@Reserve_balance.is_emptying_tx).
Local Abbreviation configured := (@Reserve_balance.user_reserve_balance).
Local Abbreviation balance := (fun world a ⇒ Numeric.U256.to_z (A.t.balance (readAccount world a))).
Local Abbreviation systemMessage := (@E.process_system_message F).
Local Abbreviation activate := (@Reserve_balance.activate_precompile).
Context {UBlock : Basics.Unreachable Chain.Ethereum.Block.t}.
Local Abbreviation blockTransactionEntry := (@consensusrequirements.blockTransactionEntry F).
Lemma block_transaction_entry_header world block :
B.t.current_block (blockTransactionEntry world block) = block.
Proof.
unfold blockTransactionEntry. rewrite !system_message_current_block. reflexivity.
Qed.
The block's unchecked system calls do not invalidate a fee budget that
was backed at block entry. The proof runs their prescribed bytecode;
it does not assume balance monotonicity of arbitrary system code.
Theorem block_transaction_entry_backing snapshot consensus signers height until world block :
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
keccak256OutputSize → wordRange (Support.UintN.to_z (Chain.Monad.PARAMS.chain_id params)) →
headerWords (Chain.Ethereum.Block.t.header block) →
OCamlString.length (Chain.Ethereum.Block.Header.t.parent_beacon_block_root
(Chain.Ethereum.Block.t.header block)) = 32 →
balanceInvariant world → worldFormat world → @prescribedSystemCode F world →
(∀ a, List.In a signers → a ≠ native) →
BudgetBacking snapshot consensus world signers height until →
let entry := blockTransactionEntry world block in
BudgetBacking snapshot consensus (B.t.world_state entry) signers height until ∧
balanceInvariant (B.t.world_state entry) ∧ worldFormat (B.t.world_state entry) ∧
totalBalance (B.t.world_state entry) ≤ totalBalance world ∧
@prescribedSystemCode F (B.t.world_state entry).
Proof using F.
intros Hrevision Hhash Hchain Hheader Hroot Hbalance Hformat Hsystem Hnative Hbacked.
unfold blockTransactionEntry. cbn zeta.
match goal with |- context [B.make ?w block] ⇒ set (initial := B.make w block) end.
assert (HinitialBacked : BudgetBacking snapshot consensus (B.t.world_state initial) signers height until).
{ apply (activation_backing); assumption. }
assert (HinitialFormat : worldFormat (B.t.world_state initial)).
{ apply activate_preserves_format. exact Hformat. }
assert (HinitialSupply : balanceInvariant (B.t.world_state initial) ∧
totalBalance (B.t.world_state initial) = totalBalance world).
{ apply activate_preserves_supply. exact Hbalance. }
assert (HinitialSystem : @prescribedSystemCode F (B.t.world_state initial)).
{ destruct Hsystem as [Hbeacon Hhistory]. split; etransitivity;
first [eapply hostcode.account_write_same_code; [exact (proj1 Hbalance)|reflexivity] | eassumption]. }
match goal with |- context [E.process_system_message initial ?systemAddr ?systemData] ⇒
assert (Hdata : OCamlString.length systemData < 2^62) by
(change (OCamlString.length (Chain.Ethereum.Block.Header.t.parent_beacon_block_root
(Chain.Ethereum.Block.t.header block)) < 2^62); rewrite Hroot; lia);
pose proof (@system_message_backing F
snapshot consensus signers height until initial systemAddr systemData
Hrevision Hhash Hchain Hheader Hdata (proj1 HinitialSupply) HinitialFormat
(or_introl (proj1 HinitialSystem)) Hnative HinitialBacked) as HbeaconBacked;
pose proof (@system_message_prescribed_code F
initial systemAddr systemData Hrevision Hhash Hchain Hheader Hdata
(proj1 HinitialSupply) HinitialFormat (or_introl (proj1 HinitialSystem))) as Hbeacon;
pose proof (system_message_preserves_format initial systemAddr systemData Hrevision HinitialFormat)
as HbeaconFormat;
pose proof (@system_message_current_block F
initial systemAddr systemData) as HbeaconBlock;
destruct (E.process_system_message initial systemAddr systemData) as [beaconResult afterBeacon]
end.
cbn beta iota zeta delta [snd] in HbeaconBacked, Hbeacon, HbeaconFormat, HbeaconBlock |- ×.
destruct Hbeacon as [HbeaconBalance [HbeaconTotal [HbeaconCodes _]]].
assert (HbeaconHeader : headerWords (Chain.Ethereum.Block.t.header (B.t.current_block afterBeacon))).
{ rewrite HbeaconBlock. exact Hheader. }
clear Hdata.
match goal with |- context [E.process_system_message afterBeacon ?systemAddr ?systemData] ⇒
assert (Hdata : OCamlString.length systemData < 2^62) by
(lazymatch systemData with ?toBytes ?hash ⇒ change (OCamlString.length hash < 2^62) end;
rewrite (block_hash_length Hhash); lia);
assert (Hcode : A.t.code (readAccount (B.t.world_state afterBeacon) systemAddr) = historyStorageCode) by
(rewrite HbeaconCodes; exact (proj2 HinitialSystem));
pose proof (@system_message_backing F
snapshot consensus signers height until afterBeacon systemAddr systemData
Hrevision Hhash Hchain HbeaconHeader Hdata HbeaconBalance HbeaconFormat
(or_intror Hcode) Hnative HbeaconBacked) as HhistoryBacked;
pose proof (@system_message_prescribed_code F
afterBeacon systemAddr systemData Hrevision Hhash Hchain HbeaconHeader Hdata
HbeaconBalance HbeaconFormat (or_intror Hcode)) as Hhistory;
pose proof (system_message_preserves_format afterBeacon systemAddr systemData Hrevision HbeaconFormat)
as HhistoryFormat;
destruct (E.process_system_message afterBeacon systemAddr systemData) as [historyResult afterHistory]
end.
cbn beta iota zeta delta [snd] in HhistoryBacked, Hhistory, HhistoryFormat |- ×.
destruct Hhistory as [HhistoryBalance [HhistoryTotal [HhistoryCodes _]]].
split; [exact HhistoryBacked|]. split; [exact HhistoryBalance|].
split; [exact HhistoryFormat|]. split.
- pose proof (proj2 HinitialSupply). lia.
- unfold prescribedSystemCode. rewrite !HhistoryCodes, !HbeaconCodes. exact HinitialSystem.
Qed.
Local Lemma result_fold_leftM_error {Acc A Err : Set}
(f : Acc → A → Acc + Err) (xs : list A) (init : Acc) (err : Err)
(P : Err → Prop) :
(∀ acc x e, f acc x = inr e → P e) →
Result.List.fold_leftM f init xs = inr err →
P err.
Proof.
intros Hf. revert init.
induction xs as [|x xs IH]; intros init Hfold.
- discriminate Hfold.
- change (Result.op_letdollar (f init x)
(fun next ⇒ Result.List.fold_leftM f next xs) = inr err) in Hfold.
destruct (f init x) as [next|e] eqn:Hstep.
+ exact (IH next Hfold).
+ injection Hfold as <-. exact (Hf init x e Hstep).
Qed.
Lemma validate_monad_block_no_transaction_error block details :
@E.validate_monad_block F block ≠
inr (Execution.Error.Invalid_transaction details).
Proof.
unfold E.validate_monad_block.
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).
change (@Result.when_) with
(fun (A : Set) (condition : bool) (r : unit + A) ⇒ if condition then r else inl tt).
change (@Result._return) with (fun (A B : Set) (x : A) ⇒ @inl A B x).
unfold E.invalid_block. cbn beta iota zeta.
repeat (match goal with |- context [if ?condition then _ else _] ⇒ destruct condition end;
cbn beta iota zeta; try discriminate).
match goal with |- context [Result.List.fold_leftM ?f ?init ?xs] ⇒
destruct (Result.List.fold_leftM f init xs) as [v|err] eqn:Hfold
end; cbn [Result.op_ltdollargt Result.map]; [discriminate|].
intro Heq. injection Heq as →.
eapply (result_fold_leftM_error _ _ _ _
(fun e ⇒ e ≠ Execution.Error.Invalid_transaction details)) in Hfold;
[exact (Hfold eq_refl)|].
intros seen tx e Hstep.
unfold Result.Option.or_fail in Hstep.
destruct (@E.System_transaction_type.of_transaction F tx) as [ty|];
cbn beta iota zeta in Hstep; [|injection Hstep as <-; discriminate].
destruct (andb _ _);
cbn beta iota zeta in Hstep; [injection Hstep as <-; discriminate|].
destruct seen as [|last_ty more]; [discriminate Hstep|].
destruct (E.System_transaction_type.equal last_ty ty);
[injection Hstep as <-; discriminate|].
destruct (negb (E.System_transaction_type.can_come_before last_ty ty));
[injection Hstep as <-; discriminate|discriminate Hstep].
Qed.
Lemma validate_block_no_transaction_error world block details :
@E.validate_block F world block ≠
inr (Execution.Error.Invalid_transaction details).
Proof.
unfold E.validate_block.
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).
change (@Result.when_) with
(fun (A : Set) (condition : bool) (r : unit + A) ⇒ if condition then r else inl tt).
change (@Result._return) with (fun (A B : Set) (x : A) ⇒ @inl A B x).
unfold E.invalid_block. cbn beta iota zeta.
repeat (match goal with |- context [if ?condition then _ else _] ⇒ destruct condition end;
cbn beta iota zeta; try discriminate).
all: try discriminate.
pose proof (validate_monad_block_no_transaction_error block details) as Hmonad.
destruct (@E.validate_monad_block F block) as [[]|err]; [discriminate | congruence].
Qed.
Lemma validate_output_no_transaction_error block post details :
@E.validate_input_block_against_output F block post ≠
inr (Execution.Error.Invalid_transaction details).
Proof.
unfold E.validate_input_block_against_output.
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).
change (@Result.when_) with
(fun (A : Set) (condition : bool) (r : unit + A) ⇒ if condition then r else inl tt).
change (@Result._return) with (fun (A B : Set) (x : A) ⇒ @inl A B x).
unfold E.invalid_block. cbn beta iota zeta.
repeat (match goal with |- context [if ?condition then _ else _] ⇒ destruct condition end;
cbn beta iota zeta; try discriminate).
all: discriminate.
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}.
Local Abbreviation processBlock := (@E.process_block F).
Local Abbreviation processTransaction := (@E.process_transaction F).
Local Abbreviation dispatchTransaction := (@E.dispatch_transaction F).
Lemma sender_not_system_kind tx :
@transactionSender F tx ≠ Some Chain.Monad.system_sender →
@E.sender_kind_value F tx ≠ Some E.System.
Proof.
intro Hne. unfold E.sender_kind_value.
change (@T.sender (@E.Params F).(Execution.Make_Params_signature.chain_id) tx)
with (@transactionSender F tx).
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 (@transactionSender F tx) as [sender|]; [|discriminate].
all: destruct (Chain.Ethereum.Address.op_eq sender Chain.Monad.system_sender) eqn:Heq;
[apply stringmaps.equal_true in Heq; subst sender; contradiction (Hne eq_refl) | discriminate].
Qed.
Lemma sender_not_system_is_system_transaction tx :
@transactionSender F tx ≠ Some Chain.Monad.system_sender →
@E.is_system_transaction F tx = false.
Proof.
intro Hne. unfold E.is_system_transaction.
pose proof (sender_not_system_kind tx Hne) as Hkind.
destruct (@E.sender_kind_value F tx) as [[sender|]|];
[reflexivity | contradiction (Hkind eq_refl) | reflexivity].
Qed.
Lemma dispatch_transaction_eq_process_transaction state tx sender :
@transactionSender F tx = Some sender →
sender ≠ Chain.Monad.system_sender →
dispatchTransaction state tx = processTransaction state tx.
Proof.
intros Hsender Hne.
unfold E.dispatch_transaction, E.process_transaction, E.validate_transaction, E.sender_kind_value.
change (@T.sender (@E.Params F).(Execution.Make_Params_signature.chain_id) tx)
with (@transactionSender F tx).
rewrite Hsender.
assert (Heq : Chain.Ethereum.Address.op_eq sender Chain.Monad.system_sender = false).
{ apply Bool.not_true_is_false. intro H. apply stringmaps.equal_true in H. exact (Hne H). }
rewrite Heq.
destruct (T.chain_id tx) as [cid|];
[destruct (Support.UintN.op_ltgt cid (@E.Params F).(Execution.Make_Params_signature.chain_id));
reflexivity
| reflexivity].
Qed.
Lemma dispatched_transactions_eq_process_transactions start txs :
Forall (fun tx ⇒ ∃ sender, @transactionSender F tx = Some sender ∧
sender ≠ Chain.Monad.system_sender) txs →
Result.List.fold_leftM dispatchTransaction start txs =
Result.List.fold_leftM processTransaction start txs.
Proof.
intro Htxs. revert start.
induction Htxs as [|tx txs [sender [Hsender Hne]] Htxs IH]; intro start.
- reflexivity.
- change (Result.op_letdollar (dispatchTransaction start tx)
(fun next ⇒ Result.List.fold_leftM dispatchTransaction next txs) =
Result.op_letdollar (processTransaction start tx)
(fun next ⇒ Result.List.fold_leftM processTransaction next txs)).
rewrite (dispatch_transaction_eq_process_transaction start tx sender Hsender Hne).
destruct (processTransaction start tx) as [next|error]; [exact (IH next)|reflexivity].
Qed.
Lemma check_transactions_senders_non_system snapshot header previous txs next :
Forall (fun tx ⇒ @transactionSender F tx ≠ Some Chain.Monad.system_sender) txs →
checkTransactions snapshot header previous txs = Some next →
Forall (fun tx ⇒ ∃ sender, @transactionSender F tx = Some sender ∧
sender ≠ Chain.Monad.system_sender) txs.
Proof.
intro HnotSys. revert previous.
induction HnotSys as [|tx txs Hne HnotSys IH]; intros previous Hcheck.
- constructor.
- cbn [checkTransactions] in Hcheck.
destruct (checkTransaction snapshot header previous tx) as [middle|] eqn:Htx; [|discriminate Hcheck].
unfold checkTransaction, transactionQuote in Htx.
destruct (@transactionSender F tx) as [sender|] eqn:Hsender; [|discriminate Htx].
constructor.
+ ∃ sender. split; [exact Hsender | intro Heq; subst sender; exact (Hne eq_refl)].
+ exact (IH middle Hcheck).
Qed.
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
keccak256OutputSize → wordRange (Support.UintN.to_z (Chain.Monad.PARAMS.chain_id params)) →
headerWords (Chain.Ethereum.Block.t.header block) →
OCamlString.length (Chain.Ethereum.Block.Header.t.parent_beacon_block_root
(Chain.Ethereum.Block.t.header block)) = 32 →
balanceInvariant world → worldFormat world → @prescribedSystemCode F world →
(∀ a, List.In a signers → a ≠ native) →
BudgetBacking snapshot consensus world signers height until →
let entry := blockTransactionEntry world block in
BudgetBacking snapshot consensus (B.t.world_state entry) signers height until ∧
balanceInvariant (B.t.world_state entry) ∧ worldFormat (B.t.world_state entry) ∧
totalBalance (B.t.world_state entry) ≤ totalBalance world ∧
@prescribedSystemCode F (B.t.world_state entry).
Proof using F.
intros Hrevision Hhash Hchain Hheader Hroot Hbalance Hformat Hsystem Hnative Hbacked.
unfold blockTransactionEntry. cbn zeta.
match goal with |- context [B.make ?w block] ⇒ set (initial := B.make w block) end.
assert (HinitialBacked : BudgetBacking snapshot consensus (B.t.world_state initial) signers height until).
{ apply (activation_backing); assumption. }
assert (HinitialFormat : worldFormat (B.t.world_state initial)).
{ apply activate_preserves_format. exact Hformat. }
assert (HinitialSupply : balanceInvariant (B.t.world_state initial) ∧
totalBalance (B.t.world_state initial) = totalBalance world).
{ apply activate_preserves_supply. exact Hbalance. }
assert (HinitialSystem : @prescribedSystemCode F (B.t.world_state initial)).
{ destruct Hsystem as [Hbeacon Hhistory]. split; etransitivity;
first [eapply hostcode.account_write_same_code; [exact (proj1 Hbalance)|reflexivity] | eassumption]. }
match goal with |- context [E.process_system_message initial ?systemAddr ?systemData] ⇒
assert (Hdata : OCamlString.length systemData < 2^62) by
(change (OCamlString.length (Chain.Ethereum.Block.Header.t.parent_beacon_block_root
(Chain.Ethereum.Block.t.header block)) < 2^62); rewrite Hroot; lia);
pose proof (@system_message_backing F
snapshot consensus signers height until initial systemAddr systemData
Hrevision Hhash Hchain Hheader Hdata (proj1 HinitialSupply) HinitialFormat
(or_introl (proj1 HinitialSystem)) Hnative HinitialBacked) as HbeaconBacked;
pose proof (@system_message_prescribed_code F
initial systemAddr systemData Hrevision Hhash Hchain Hheader Hdata
(proj1 HinitialSupply) HinitialFormat (or_introl (proj1 HinitialSystem))) as Hbeacon;
pose proof (system_message_preserves_format initial systemAddr systemData Hrevision HinitialFormat)
as HbeaconFormat;
pose proof (@system_message_current_block F
initial systemAddr systemData) as HbeaconBlock;
destruct (E.process_system_message initial systemAddr systemData) as [beaconResult afterBeacon]
end.
cbn beta iota zeta delta [snd] in HbeaconBacked, Hbeacon, HbeaconFormat, HbeaconBlock |- ×.
destruct Hbeacon as [HbeaconBalance [HbeaconTotal [HbeaconCodes _]]].
assert (HbeaconHeader : headerWords (Chain.Ethereum.Block.t.header (B.t.current_block afterBeacon))).
{ rewrite HbeaconBlock. exact Hheader. }
clear Hdata.
match goal with |- context [E.process_system_message afterBeacon ?systemAddr ?systemData] ⇒
assert (Hdata : OCamlString.length systemData < 2^62) by
(lazymatch systemData with ?toBytes ?hash ⇒ change (OCamlString.length hash < 2^62) end;
rewrite (block_hash_length Hhash); lia);
assert (Hcode : A.t.code (readAccount (B.t.world_state afterBeacon) systemAddr) = historyStorageCode) by
(rewrite HbeaconCodes; exact (proj2 HinitialSystem));
pose proof (@system_message_backing F
snapshot consensus signers height until afterBeacon systemAddr systemData
Hrevision Hhash Hchain HbeaconHeader Hdata HbeaconBalance HbeaconFormat
(or_intror Hcode) Hnative HbeaconBacked) as HhistoryBacked;
pose proof (@system_message_prescribed_code F
afterBeacon systemAddr systemData Hrevision Hhash Hchain HbeaconHeader Hdata
HbeaconBalance HbeaconFormat (or_intror Hcode)) as Hhistory;
pose proof (system_message_preserves_format afterBeacon systemAddr systemData Hrevision HbeaconFormat)
as HhistoryFormat;
destruct (E.process_system_message afterBeacon systemAddr systemData) as [historyResult afterHistory]
end.
cbn beta iota zeta delta [snd] in HhistoryBacked, Hhistory, HhistoryFormat |- ×.
destruct Hhistory as [HhistoryBalance [HhistoryTotal [HhistoryCodes _]]].
split; [exact HhistoryBacked|]. split; [exact HhistoryBalance|].
split; [exact HhistoryFormat|]. split.
- pose proof (proj2 HinitialSupply). lia.
- unfold prescribedSystemCode. rewrite !HhistoryCodes, !HbeaconCodes. exact HinitialSystem.
Qed.
Local Lemma result_fold_leftM_error {Acc A Err : Set}
(f : Acc → A → Acc + Err) (xs : list A) (init : Acc) (err : Err)
(P : Err → Prop) :
(∀ acc x e, f acc x = inr e → P e) →
Result.List.fold_leftM f init xs = inr err →
P err.
Proof.
intros Hf. revert init.
induction xs as [|x xs IH]; intros init Hfold.
- discriminate Hfold.
- change (Result.op_letdollar (f init x)
(fun next ⇒ Result.List.fold_leftM f next xs) = inr err) in Hfold.
destruct (f init x) as [next|e] eqn:Hstep.
+ exact (IH next Hfold).
+ injection Hfold as <-. exact (Hf init x e Hstep).
Qed.
Lemma validate_monad_block_no_transaction_error block details :
@E.validate_monad_block F block ≠
inr (Execution.Error.Invalid_transaction details).
Proof.
unfold E.validate_monad_block.
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).
change (@Result.when_) with
(fun (A : Set) (condition : bool) (r : unit + A) ⇒ if condition then r else inl tt).
change (@Result._return) with (fun (A B : Set) (x : A) ⇒ @inl A B x).
unfold E.invalid_block. cbn beta iota zeta.
repeat (match goal with |- context [if ?condition then _ else _] ⇒ destruct condition end;
cbn beta iota zeta; try discriminate).
match goal with |- context [Result.List.fold_leftM ?f ?init ?xs] ⇒
destruct (Result.List.fold_leftM f init xs) as [v|err] eqn:Hfold
end; cbn [Result.op_ltdollargt Result.map]; [discriminate|].
intro Heq. injection Heq as →.
eapply (result_fold_leftM_error _ _ _ _
(fun e ⇒ e ≠ Execution.Error.Invalid_transaction details)) in Hfold;
[exact (Hfold eq_refl)|].
intros seen tx e Hstep.
unfold Result.Option.or_fail in Hstep.
destruct (@E.System_transaction_type.of_transaction F tx) as [ty|];
cbn beta iota zeta in Hstep; [|injection Hstep as <-; discriminate].
destruct (andb _ _);
cbn beta iota zeta in Hstep; [injection Hstep as <-; discriminate|].
destruct seen as [|last_ty more]; [discriminate Hstep|].
destruct (E.System_transaction_type.equal last_ty ty);
[injection Hstep as <-; discriminate|].
destruct (negb (E.System_transaction_type.can_come_before last_ty ty));
[injection Hstep as <-; discriminate|discriminate Hstep].
Qed.
Lemma validate_block_no_transaction_error world block details :
@E.validate_block F world block ≠
inr (Execution.Error.Invalid_transaction details).
Proof.
unfold E.validate_block.
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).
change (@Result.when_) with
(fun (A : Set) (condition : bool) (r : unit + A) ⇒ if condition then r else inl tt).
change (@Result._return) with (fun (A B : Set) (x : A) ⇒ @inl A B x).
unfold E.invalid_block. cbn beta iota zeta.
repeat (match goal with |- context [if ?condition then _ else _] ⇒ destruct condition end;
cbn beta iota zeta; try discriminate).
all: try discriminate.
pose proof (validate_monad_block_no_transaction_error block details) as Hmonad.
destruct (@E.validate_monad_block F block) as [[]|err]; [discriminate | congruence].
Qed.
Lemma validate_output_no_transaction_error block post details :
@E.validate_input_block_against_output F block post ≠
inr (Execution.Error.Invalid_transaction details).
Proof.
unfold E.validate_input_block_against_output.
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).
change (@Result.when_) with
(fun (A : Set) (condition : bool) (r : unit + A) ⇒ if condition then r else inl tt).
change (@Result._return) with (fun (A B : Set) (x : A) ⇒ @inl A B x).
unfold E.invalid_block. cbn beta iota zeta.
repeat (match goal with |- context [if ?condition then _ else _] ⇒ destruct condition end;
cbn beta iota zeta; try discriminate).
all: discriminate.
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}.
Local Abbreviation processBlock := (@E.process_block F).
Local Abbreviation processTransaction := (@E.process_transaction F).
Local Abbreviation dispatchTransaction := (@E.dispatch_transaction F).
Lemma sender_not_system_kind tx :
@transactionSender F tx ≠ Some Chain.Monad.system_sender →
@E.sender_kind_value F tx ≠ Some E.System.
Proof.
intro Hne. unfold E.sender_kind_value.
change (@T.sender (@E.Params F).(Execution.Make_Params_signature.chain_id) tx)
with (@transactionSender F tx).
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 (@transactionSender F tx) as [sender|]; [|discriminate].
all: destruct (Chain.Ethereum.Address.op_eq sender Chain.Monad.system_sender) eqn:Heq;
[apply stringmaps.equal_true in Heq; subst sender; contradiction (Hne eq_refl) | discriminate].
Qed.
Lemma sender_not_system_is_system_transaction tx :
@transactionSender F tx ≠ Some Chain.Monad.system_sender →
@E.is_system_transaction F tx = false.
Proof.
intro Hne. unfold E.is_system_transaction.
pose proof (sender_not_system_kind tx Hne) as Hkind.
destruct (@E.sender_kind_value F tx) as [[sender|]|];
[reflexivity | contradiction (Hkind eq_refl) | reflexivity].
Qed.
Lemma dispatch_transaction_eq_process_transaction state tx sender :
@transactionSender F tx = Some sender →
sender ≠ Chain.Monad.system_sender →
dispatchTransaction state tx = processTransaction state tx.
Proof.
intros Hsender Hne.
unfold E.dispatch_transaction, E.process_transaction, E.validate_transaction, E.sender_kind_value.
change (@T.sender (@E.Params F).(Execution.Make_Params_signature.chain_id) tx)
with (@transactionSender F tx).
rewrite Hsender.
assert (Heq : Chain.Ethereum.Address.op_eq sender Chain.Monad.system_sender = false).
{ apply Bool.not_true_is_false. intro H. apply stringmaps.equal_true in H. exact (Hne H). }
rewrite Heq.
destruct (T.chain_id tx) as [cid|];
[destruct (Support.UintN.op_ltgt cid (@E.Params F).(Execution.Make_Params_signature.chain_id));
reflexivity
| reflexivity].
Qed.
Lemma dispatched_transactions_eq_process_transactions start txs :
Forall (fun tx ⇒ ∃ sender, @transactionSender F tx = Some sender ∧
sender ≠ Chain.Monad.system_sender) txs →
Result.List.fold_leftM dispatchTransaction start txs =
Result.List.fold_leftM processTransaction start txs.
Proof.
intro Htxs. revert start.
induction Htxs as [|tx txs [sender [Hsender Hne]] Htxs IH]; intro start.
- reflexivity.
- change (Result.op_letdollar (dispatchTransaction start tx)
(fun next ⇒ Result.List.fold_leftM dispatchTransaction next txs) =
Result.op_letdollar (processTransaction start tx)
(fun next ⇒ Result.List.fold_leftM processTransaction next txs)).
rewrite (dispatch_transaction_eq_process_transaction start tx sender Hsender Hne).
destruct (processTransaction start tx) as [next|error]; [exact (IH next)|reflexivity].
Qed.
Lemma check_transactions_senders_non_system snapshot header previous txs next :
Forall (fun tx ⇒ @transactionSender F tx ≠ Some Chain.Monad.system_sender) txs →
checkTransactions snapshot header previous txs = Some next →
Forall (fun tx ⇒ ∃ sender, @transactionSender F tx = Some sender ∧
sender ≠ Chain.Monad.system_sender) txs.
Proof.
intro HnotSys. revert previous.
induction HnotSys as [|tx txs Hne HnotSys IH]; intros previous Hcheck.
- constructor.
- cbn [checkTransactions] in Hcheck.
destruct (checkTransaction snapshot header previous tx) as [middle|] eqn:Htx; [|discriminate Hcheck].
unfold checkTransaction, transactionQuote in Htx.
destruct (@transactionSender F tx) as [sender|] eqn:Hsender; [|discriminate Htx].
constructor.
+ ∃ sender. split; [exact Hsender | intro Heq; subst sender; exact (Hne eq_refl)].
+ exact (IH middle Hcheck).
Qed.
Block-header and output verification failures have a different error
constructor. Any transaction error returned by process_block therefore
comes from its actual transaction fold, starting at the entry above.
Theorem process_block_dispatch_error_from_entry verify world block details :
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
processBlock verify world block = inr (Execution.Error.Invalid_transaction details) →
Result.List.fold_leftM dispatchTransaction (blockTransactionEntry world block)
(Chain.Ethereum.Block.t.transactions block) = inr (Execution.Error.Invalid_transaction details).
Proof.
intros Hrevision Hrun. unfold E.process_block in Hrun. rewrite Hrevision in Hrun.
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) in Hrun.
destruct (@E.validate_block F world block) as [[]|error] eqn:Hvalid.
2: { cbn in Hrun. injection Hrun as Heq. subst error.
exfalso. exact (validate_block_no_transaction_error world block details Hvalid). }
cbn beta iota zeta in Hrun.
match type of Hrun with context [Result.List.fold_leftM ?step ?entry ?txs] ⇒
change entry with (blockTransactionEntry world block) in Hrun
end.
destruct (Result.List.fold_leftM dispatchTransaction (blockTransactionEntry world block)
(Chain.Ethereum.Block.t.transactions block)) as [after|error] eqn:Htxs.
2: { cbn in Hrun. injection Hrun as →. reflexivity. }
cbn beta iota zeta in Hrun.
match type of Hrun with context [E.validate_block ?w ?b] ⇒
pose proof (validate_block_no_transaction_error w b details) as Hnot;
destruct (E.validate_block w b) as [[]|error] eqn:Hpost
end.
2: { cbn in Hrun. injection Hrun as Heq. subst error. contradiction. }
match type of Hrun with context [if verify then ?check else _] ⇒
destruct verify; [destruct check as [[]|error] eqn:Hcheck|]
end.
- discriminate Hrun.
- cbn in Hrun. injection Hrun as Heq. subst error.
exfalso. eapply validate_output_no_transaction_error. exact Hcheck.
- discriminate Hrun.
Qed.
Theorem process_block_transaction_error_from_entry verify world block details :
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
Forall (fun tx ⇒ ∃ sender, @transactionSender F tx = Some sender ∧
sender ≠ Chain.Monad.system_sender) (Chain.Ethereum.Block.t.transactions block) →
processBlock verify world block = inr (Execution.Error.Invalid_transaction details) →
Result.List.fold_leftM processTransaction (blockTransactionEntry world block)
(Chain.Ethereum.Block.t.transactions block) = inr (Execution.Error.Invalid_transaction details).
Proof.
intros Hrevision Htxs Hrun.
rewrite <- (dispatched_transactions_eq_process_transactions (blockTransactionEntry world block)
(Chain.Ethereum.Block.t.transactions block) Htxs).
exact (process_block_dispatch_error_from_entry verify world block details Hrevision Hrun).
Qed.
Lemma fold_leftM_first_error {X Y Err : Set} (step : X → Y → X + Err) values start error :
Result.List.fold_leftM step start values = inr error →
∃ before value after reached,
values = before ++ value :: after ∧
Result.List.fold_leftM step start before = inl reached ∧ step reached value = inr error.
Proof.
revert start. induction values as [|value rest IH]; intros start Hrun; [discriminate Hrun|].
change (Result.op_letdollar (step start value)
(fun next ⇒ Result.List.fold_leftM step next rest) = inr error) in Hrun.
destruct (step start value) as [next|failure] eqn:Hstep.
- destruct (IH next Hrun) as [before [candidate [after [reached [Hsplit [Hprefix Herror]]]]]].
∃ (value :: before), candidate, after, reached. split; [cbn [app]; now rewrite Hsplit|].
split; [|exact Herror].
change (Result.op_letdollar (step start value)
(fun next ⇒ Result.List.fold_leftM step next before) = inl reached).
rewrite Hstep. exact Hprefix.
- cbn in Hrun. injection Hrun as <-.
∃ [], value, rest, start. split; [reflexivity|]. split; [reflexivity|exact Hstep].
Qed.
Lemma transaction_validation_error_metadata state tx details :
@E.validate_transaction F state tx = inr (Execution.Error.Invalid_transaction details) →
Execution.Error.t.Invalid_transaction.block details = B.t.current_block state ∧
Execution.Error.t.Invalid_transaction.transaction details = tx.
Proof.
unfold E.validate_transaction. cbn zeta.
unfold E.validate_authorizations.
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).
change (@Result._return) with (fun (A Error : Set) (value : A) ⇒ @inl A Error value).
change (@Result.when_) with (fun (Error : Set) (condition : bool) (failure : unit + Error) ⇒
if condition then failure else inl tt).
cbv beta iota zeta. destruct tx; cbn beta iota zeta.
all: repeat (first
[ match goal with |- context [E.invalid_transaction _ _ _] ⇒
unfold E.invalid_transaction; intro Heq; injection Heq as <-; split; reflexivity end
| discriminate
| match goal with
| |- context [match ?x with Some _ ⇒ _ | None ⇒ _ end] ⇒ destruct x
| |- context [match ?x with [] ⇒ _ | _ :: _ ⇒ _ end] ⇒ destruct x
| |- context [if ?b then _ else _] ⇒ destruct b
end ]; cbn beta iota zeta).
Qed.
Lemma process_transaction_error_from_validation state tx error :
processTransaction state tx = inr error → @E.validate_transaction F state tx = inr error.
Proof.
intro Hrun. unfold E.process_transaction in Hrun.
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.
destruct (@E.validate_transaction F state tx) as [[sender fee price intrinsic]|failure] eqn:Hvalid.
2: { cbn in Hrun. injection Hrun as →. reflexivity. }
cbn beta iota zeta in Hrun.
match type of Hrun with context [Result.List.fold_left ?step ?initial ?auths] ⇒
destruct (Result.List.fold_left step initial auths) as [authorities authorized]
end.
cbn beta iota zeta in Hrun.
match type of Hrun with context [E.Host.call_from_eoa ?transaction ?message ?entry] ⇒
destruct (E.Host.call_from_eoa transaction message entry) as [receipt after]
end.
discriminate Hrun.
Qed.
Lemma process_block_dispatch_success_from_entry verify world block post :
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
processBlock verify world block = inl post →
∃ after finalHistory,
Result.List.fold_leftM dispatchTransaction (blockTransactionEntry world block)
(Chain.Ethereum.Block.t.transactions block) = inl after ∧
post = W.t.with_history finalHistory
(B.t.world_state (Result.List.fold_left (@E.process_withdrawal F) after
(Chain.Ethereum.Block.t.withdrawals block))).
Proof.
intros Hrevision Hrun. unfold E.process_block in Hrun. rewrite Hrevision in Hrun.
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) in Hrun.
destruct (@E.validate_block F world block) as [[]|error]; [|discriminate Hrun].
cbn beta iota zeta in Hrun.
match type of Hrun with context [Result.List.fold_leftM ?step ?entry ?txs] ⇒
change entry with (blockTransactionEntry world block) in Hrun
end.
destruct (Result.List.fold_leftM dispatchTransaction (blockTransactionEntry world block)
(Chain.Ethereum.Block.t.transactions block)) as [after|error] eqn:Htxs; [|discriminate Hrun].
cbn beta iota zeta in Hrun.
match type of Hrun with context [E.validate_block ?w ?b] ⇒
destruct (E.validate_block w b) as [[]|error]
end.
2: discriminate Hrun.
match type of Hrun with context [if verify then ?check else _] ⇒
destruct verify; [destruct check as [[]|error]; [|discriminate Hrun]|]
end.
all: injection Hrun as <-; ∃ after; eexists; split; reflexivity.
Qed.
Lemma process_block_success_from_entry verify world block post :
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
Forall (fun tx ⇒ @E.sender_kind_value F tx ≠ Some E.System)
(Chain.Ethereum.Block.t.transactions block) →
processBlock verify world block = inl post →
∃ after finalHistory,
Result.List.fold_leftM processTransaction (blockTransactionEntry world block)
(Chain.Ethereum.Block.t.transactions block) = inl after ∧
post = W.t.with_history finalHistory
(B.t.world_state (Result.List.fold_left (@E.process_withdrawal F) after
(Chain.Ethereum.Block.t.withdrawals block))).
Proof.
intros Hrevision HnotSys Hrun.
destruct (process_block_dispatch_success_from_entry verify world block post Hrevision Hrun)
as [after [finalHistory [Htxs Hpost]]].
∃ after, finalHistory.
split.
- exact (dispatched_transactions_inl_process_transactions
(blockTransactionEntry world block) (Chain.Ethereum.Block.t.transactions block)
after HnotSys Htxs).
- exact Hpost.
Qed.
End Execution.
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
processBlock verify world block = inr (Execution.Error.Invalid_transaction details) →
Result.List.fold_leftM dispatchTransaction (blockTransactionEntry world block)
(Chain.Ethereum.Block.t.transactions block) = inr (Execution.Error.Invalid_transaction details).
Proof.
intros Hrevision Hrun. unfold E.process_block in Hrun. rewrite Hrevision in Hrun.
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) in Hrun.
destruct (@E.validate_block F world block) as [[]|error] eqn:Hvalid.
2: { cbn in Hrun. injection Hrun as Heq. subst error.
exfalso. exact (validate_block_no_transaction_error world block details Hvalid). }
cbn beta iota zeta in Hrun.
match type of Hrun with context [Result.List.fold_leftM ?step ?entry ?txs] ⇒
change entry with (blockTransactionEntry world block) in Hrun
end.
destruct (Result.List.fold_leftM dispatchTransaction (blockTransactionEntry world block)
(Chain.Ethereum.Block.t.transactions block)) as [after|error] eqn:Htxs.
2: { cbn in Hrun. injection Hrun as →. reflexivity. }
cbn beta iota zeta in Hrun.
match type of Hrun with context [E.validate_block ?w ?b] ⇒
pose proof (validate_block_no_transaction_error w b details) as Hnot;
destruct (E.validate_block w b) as [[]|error] eqn:Hpost
end.
2: { cbn in Hrun. injection Hrun as Heq. subst error. contradiction. }
match type of Hrun with context [if verify then ?check else _] ⇒
destruct verify; [destruct check as [[]|error] eqn:Hcheck|]
end.
- discriminate Hrun.
- cbn in Hrun. injection Hrun as Heq. subst error.
exfalso. eapply validate_output_no_transaction_error. exact Hcheck.
- discriminate Hrun.
Qed.
Theorem process_block_transaction_error_from_entry verify world block details :
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
Forall (fun tx ⇒ ∃ sender, @transactionSender F tx = Some sender ∧
sender ≠ Chain.Monad.system_sender) (Chain.Ethereum.Block.t.transactions block) →
processBlock verify world block = inr (Execution.Error.Invalid_transaction details) →
Result.List.fold_leftM processTransaction (blockTransactionEntry world block)
(Chain.Ethereum.Block.t.transactions block) = inr (Execution.Error.Invalid_transaction details).
Proof.
intros Hrevision Htxs Hrun.
rewrite <- (dispatched_transactions_eq_process_transactions (blockTransactionEntry world block)
(Chain.Ethereum.Block.t.transactions block) Htxs).
exact (process_block_dispatch_error_from_entry verify world block details Hrevision Hrun).
Qed.
Lemma fold_leftM_first_error {X Y Err : Set} (step : X → Y → X + Err) values start error :
Result.List.fold_leftM step start values = inr error →
∃ before value after reached,
values = before ++ value :: after ∧
Result.List.fold_leftM step start before = inl reached ∧ step reached value = inr error.
Proof.
revert start. induction values as [|value rest IH]; intros start Hrun; [discriminate Hrun|].
change (Result.op_letdollar (step start value)
(fun next ⇒ Result.List.fold_leftM step next rest) = inr error) in Hrun.
destruct (step start value) as [next|failure] eqn:Hstep.
- destruct (IH next Hrun) as [before [candidate [after [reached [Hsplit [Hprefix Herror]]]]]].
∃ (value :: before), candidate, after, reached. split; [cbn [app]; now rewrite Hsplit|].
split; [|exact Herror].
change (Result.op_letdollar (step start value)
(fun next ⇒ Result.List.fold_leftM step next before) = inl reached).
rewrite Hstep. exact Hprefix.
- cbn in Hrun. injection Hrun as <-.
∃ [], value, rest, start. split; [reflexivity|]. split; [reflexivity|exact Hstep].
Qed.
Lemma transaction_validation_error_metadata state tx details :
@E.validate_transaction F state tx = inr (Execution.Error.Invalid_transaction details) →
Execution.Error.t.Invalid_transaction.block details = B.t.current_block state ∧
Execution.Error.t.Invalid_transaction.transaction details = tx.
Proof.
unfold E.validate_transaction. cbn zeta.
unfold E.validate_authorizations.
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).
change (@Result._return) with (fun (A Error : Set) (value : A) ⇒ @inl A Error value).
change (@Result.when_) with (fun (Error : Set) (condition : bool) (failure : unit + Error) ⇒
if condition then failure else inl tt).
cbv beta iota zeta. destruct tx; cbn beta iota zeta.
all: repeat (first
[ match goal with |- context [E.invalid_transaction _ _ _] ⇒
unfold E.invalid_transaction; intro Heq; injection Heq as <-; split; reflexivity end
| discriminate
| match goal with
| |- context [match ?x with Some _ ⇒ _ | None ⇒ _ end] ⇒ destruct x
| |- context [match ?x with [] ⇒ _ | _ :: _ ⇒ _ end] ⇒ destruct x
| |- context [if ?b then _ else _] ⇒ destruct b
end ]; cbn beta iota zeta).
Qed.
Lemma process_transaction_error_from_validation state tx error :
processTransaction state tx = inr error → @E.validate_transaction F state tx = inr error.
Proof.
intro Hrun. unfold E.process_transaction in Hrun.
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.
destruct (@E.validate_transaction F state tx) as [[sender fee price intrinsic]|failure] eqn:Hvalid.
2: { cbn in Hrun. injection Hrun as →. reflexivity. }
cbn beta iota zeta in Hrun.
match type of Hrun with context [Result.List.fold_left ?step ?initial ?auths] ⇒
destruct (Result.List.fold_left step initial auths) as [authorities authorized]
end.
cbn beta iota zeta in Hrun.
match type of Hrun with context [E.Host.call_from_eoa ?transaction ?message ?entry] ⇒
destruct (E.Host.call_from_eoa transaction message entry) as [receipt after]
end.
discriminate Hrun.
Qed.
Lemma process_block_dispatch_success_from_entry verify world block post :
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
processBlock verify world block = inl post →
∃ after finalHistory,
Result.List.fold_leftM dispatchTransaction (blockTransactionEntry world block)
(Chain.Ethereum.Block.t.transactions block) = inl after ∧
post = W.t.with_history finalHistory
(B.t.world_state (Result.List.fold_left (@E.process_withdrawal F) after
(Chain.Ethereum.Block.t.withdrawals block))).
Proof.
intros Hrevision Hrun. unfold E.process_block in Hrun. rewrite Hrevision in Hrun.
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) in Hrun.
destruct (@E.validate_block F world block) as [[]|error]; [|discriminate Hrun].
cbn beta iota zeta in Hrun.
match type of Hrun with context [Result.List.fold_leftM ?step ?entry ?txs] ⇒
change entry with (blockTransactionEntry world block) in Hrun
end.
destruct (Result.List.fold_leftM dispatchTransaction (blockTransactionEntry world block)
(Chain.Ethereum.Block.t.transactions block)) as [after|error] eqn:Htxs; [|discriminate Hrun].
cbn beta iota zeta in Hrun.
match type of Hrun with context [E.validate_block ?w ?b] ⇒
destruct (E.validate_block w b) as [[]|error]
end.
2: discriminate Hrun.
match type of Hrun with context [if verify then ?check else _] ⇒
destruct verify; [destruct check as [[]|error]; [|discriminate Hrun]|]
end.
all: injection Hrun as <-; ∃ after; eexists; split; reflexivity.
Qed.
Lemma process_block_success_from_entry verify world block post :
(@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
Forall (fun tx ⇒ @E.sender_kind_value F tx ≠ Some E.System)
(Chain.Ethereum.Block.t.transactions block) →
processBlock verify world block = inl post →
∃ after finalHistory,
Result.List.fold_leftM processTransaction (blockTransactionEntry world block)
(Chain.Ethereum.Block.t.transactions block) = inl after ∧
post = W.t.with_history finalHistory
(B.t.world_state (Result.List.fold_left (@E.process_withdrawal F) after
(Chain.Ethereum.Block.t.withdrawals block))).
Proof.
intros Hrevision HnotSys Hrun.
destruct (process_block_dispatch_success_from_entry verify world block post Hrevision Hrun)
as [after [finalHistory [Htxs Hpost]]].
∃ after, finalHistory.
split.
- exact (dispatched_transactions_inl_process_transactions
(blockTransactionEntry world block) (Chain.Ethereum.Block.t.transactions block)
after HnotSys Htxs).
- exact Hpost.
Qed.
End Execution.