Library SetcodeConcrete.blockemptyingagreement
Empty-code agreement through complete blocks
From Stdlib Require Import List String ZArith.
Require Import RocqOfOCaml.RocqOfOCaml MonadVM.Execution.
Require Import QedkConcrete.blockentry.
Require Import SetcodeConcrete.emptyingagreement SetcodeConcrete.nonceagreement
SetcodeConcrete.nonceagreementsequence SetcodeConcrete.blocknonceagreement
SetcodeConcrete.windownonceagreement SetcodeConcrete.blockcode
SetcodeConcrete.transactionaccountfinalize SetcodeConcrete.consensuschecks.
Set Default Goal Selector "!".
#[local] Hint Extern 100 (Basics.Unreachable _) ⇒
(apply Opaque.legacy_witness; Opaque.opaque_inhabit 64%nat) : typeclass_instances.
Import ListNotations.
Module E := Execution.Make.
Module W := State.WorldState.
Module B := State.BlockState.
Module A := Chain.Ethereum.Account.
Module T := Chain.Ethereum.Transaction.
Module Block := Chain.Ethereum.Block.
Section Execution.
Context {F : E.FArgs}.
Context (cold warm access write reserve : N).
Context (Hrevision : E.Params.(Execution.Make_Params_signature.revision) =
Support.Variants.Revision.Setcode (cold, warm, access, write, reserve)).
Context (Hcold : (0 < cold)%N) (Hwarm : (0 < warm)%N).
Lemma block_entry_empty_code snapshot activity world block senders :
prescribedSystemCode world →
EmptyCodeAgreement snapshot activity world senders →
EmptyCodeAgreement snapshot activity
(B.t.world_state (blockTransactionEntry world block)) senders.
Proof.
intros Hsystem Hbefore a Ha Hnot Hempty. apply (Hbefore a Ha Hnot).
exact (eq_trans (eq_sym (block_entry_code cold warm access write reserve
Hrevision Hcold Hwarm world block a Hsystem)) Hempty).
Qed.
Lemma withdrawals_empty_code snapshot activity eligible predicted senders withdrawals state :
NonceAgreement eligible predicted (B.t.world_state state) senders →
EmptyCodeAgreement snapshot activity (B.t.world_state state) senders →
EmptyCodeAgreement snapshot activity (B.t.world_state
(Result.List.fold_left E.process_withdrawal state withdrawals)) senders.
Proof.
revert state. induction withdrawals as [|wd rest IH]; intros state Hnonce Hbefore;
[exact Hbefore|].
change (EmptyCodeAgreement snapshot activity (B.t.world_state
(Result.List.fold_left E.process_withdrawal (E.process_withdrawal state wd) rest)) senders).
apply IH.
- intros a Ha. destruct (Hnonce a Ha) as [He HP]. split; [exact He|].
unfold E.process_withdrawal. apply credit_world_account. exact HP.
- intros a Ha Hnot.
assert (HP : worldAccount a
(fun code _ ⇒ code = Byte_string.Bytes.empty →
A.t.code (accountAt snapshot a) = Byte_string.Bytes.empty) (B.t.world_state state)).
{ split; [exact (proj1 (proj2 (Hnonce a Ha)))|exact (Hbefore a Ha Hnot)]. }
unfold E.process_withdrawal.
apply (proj2 (credit_world_account a _ _ _ _ HP)).
Qed.
Theorem block_empty_code_agreement verify snapshot previous next world block post senders :
(∀ a, In a senders → a ≠ Reserve_balance.precompile_address) →
Forall (fun tx ⇒ Forall (fun auth ⇒ OCamlString.length (T.Authorization.t.address auth) = 20%Z)
(T.authorization_list tx)) (Block.t.transactions block) →
prescribedSystemCode world →
NonceAgreement (eligibleAt snapshot) (admissionNonces previous) world senders →
EmptyCodeAgreement snapshot (admissionActivity previous) world senders →
transactionsAvoidSenderCreation senders (blockTransactionEntry world block) (Block.t.transactions block) →
checkTransactions snapshot (Block.t.header block) previous (Block.t.transactions block) = Some next →
E.process_block verify world block = inl post →
EmptyCodeAgreement snapshot (admissionActivity next) post senders.
Proof.
intros Hnative Hwidth Hsystem Hnonce Hbefore Hcreation Hcheck Hrun.
pose proof (block_entry_nonce_agreement cold warm access write reserve Hrevision Hcold Hwarm
world block _ _ senders Hnative Hsystem Hnonce) as HentryNonce.
pose proof (block_entry_empty_code snapshot _ world block senders Hsystem Hbefore) as Hentry.
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 world block) as [[]|error]; [|discriminate].
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 E.process_transaction (blockTransactionEntry world block)
(Block.t.transactions block)) as [after|error] eqn:Htxs; [|discriminate].
pose proof (transactions_nonce_agreement cold warm access write reserve Hrevision Hcold Hwarm
snapshot previous next (blockTransactionEntry world block) (Block.t.transactions block) after senders
Hnative Hwidth HentryNonce Hcreation ltac:(rewrite block_entry_current; exact Hcheck) Htxs) as HnonceAfter.
pose proof (checked_transactions_empty_code cold warm access write reserve Hrevision Hcold Hwarm
snapshot previous next (blockTransactionEntry world block) (Block.t.transactions block) after senders
Hnative Hwidth HentryNonce Hentry Hcreation
ltac:(rewrite block_entry_current; exact Hcheck) Htxs) as Htransactions.
pose proof (withdrawals_empty_code snapshot _ _ _ senders (Block.t.withdrawals block) after
HnonceAfter Htransactions) as Hwithdrawals.
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;
[|discriminate].
destruct verify; [|injection Hrun as <-; exact Hwithdrawals].
match type of Hrun with context [match ?check with inl _ ⇒ _ | inr _ ⇒ _ end] ⇒
destruct check as [[]|error] end;
[injection Hrun as <-; exact Hwithdrawals|discriminate].
Qed.
Theorem blocks_empty_code_agreement verify snapshot previous next world blocks post senders :
(∀ a, In a senders → a ≠ Reserve_balance.precompile_address) →
Forall (fun block ⇒ Forall (fun tx ⇒ Forall
(fun auth ⇒ OCamlString.length (T.Authorization.t.address auth) = 20%Z)
(T.authorization_list tx)) (Block.t.transactions block)) blocks →
prescribedSystemCode world →
NonceAgreement (eligibleAt snapshot) (admissionNonces previous) world senders →
EmptyCodeAgreement snapshot (admissionActivity previous) world senders →
blocksAvoidSenderCreation senders verify world blocks →
checkBlocks snapshot previous blocks = Some next →
Result.List.fold_leftM (E.process_block verify) world blocks = inl post →
EmptyCodeAgreement snapshot (admissionActivity next) post senders.
Proof.
intros Hnative Hwidth. revert previous world.
induction Hwidth as [|block rest Hwidth Hrest IH];
intros previous world Hsystem Hnonce Hbefore Hcreation Hcheck Hrun.
- cbn [checkBlocks] in Hcheck. injection Hcheck as <-.
injection Hrun as <-. exact Hbefore.
- cbn [checkBlocks] in Hcheck.
match type of Hcheck with context [checkTransactions ?s ?h ?p ?ts] ⇒
set (capped := p) in *;
destruct (checkTransactions s h capped ts) as [middle|] eqn:Htxs end; [|discriminate].
change (Result.op_letdollar (E.process_block verify world block)
(fun after ⇒ Result.List.fold_leftM (E.process_block verify) after rest) = inl post) in Hrun.
destruct (E.process_block verify world block) as [after|error] eqn:Hblock; [|discriminate].
destruct Hcreation as [Hcreation Htail].
apply (IH middle after).
+ exact (block_preserves_system_code cold warm access write reserve verify world block after
Hrevision Hcold Hwarm Hsystem Hblock).
+ exact (block_nonce_agreement cold warm access write reserve Hrevision Hcold Hwarm
verify snapshot capped middle world block after senders Hnative Hwidth Hsystem Hnonce
(Hcreation (processed_block_valid_header _ _ _ _ Hblock)) Htxs Hblock).
+ exact (block_empty_code_agreement verify snapshot capped middle world block after senders
Hnative Hwidth Hsystem Hnonce Hbefore
(Hcreation (processed_block_valid_header _ _ _ _ Hblock)) Htxs Hblock).
+ exact (Htail after Hblock).
+ exact Hcheck.
+ exact Hrun.
Qed.
End Execution.
Print Assumptions blocks_empty_code_agreement.
Require Import RocqOfOCaml.RocqOfOCaml MonadVM.Execution.
Require Import QedkConcrete.blockentry.
Require Import SetcodeConcrete.emptyingagreement SetcodeConcrete.nonceagreement
SetcodeConcrete.nonceagreementsequence SetcodeConcrete.blocknonceagreement
SetcodeConcrete.windownonceagreement SetcodeConcrete.blockcode
SetcodeConcrete.transactionaccountfinalize SetcodeConcrete.consensuschecks.
Set Default Goal Selector "!".
#[local] Hint Extern 100 (Basics.Unreachable _) ⇒
(apply Opaque.legacy_witness; Opaque.opaque_inhabit 64%nat) : typeclass_instances.
Import ListNotations.
Module E := Execution.Make.
Module W := State.WorldState.
Module B := State.BlockState.
Module A := Chain.Ethereum.Account.
Module T := Chain.Ethereum.Transaction.
Module Block := Chain.Ethereum.Block.
Section Execution.
Context {F : E.FArgs}.
Context (cold warm access write reserve : N).
Context (Hrevision : E.Params.(Execution.Make_Params_signature.revision) =
Support.Variants.Revision.Setcode (cold, warm, access, write, reserve)).
Context (Hcold : (0 < cold)%N) (Hwarm : (0 < warm)%N).
Lemma block_entry_empty_code snapshot activity world block senders :
prescribedSystemCode world →
EmptyCodeAgreement snapshot activity world senders →
EmptyCodeAgreement snapshot activity
(B.t.world_state (blockTransactionEntry world block)) senders.
Proof.
intros Hsystem Hbefore a Ha Hnot Hempty. apply (Hbefore a Ha Hnot).
exact (eq_trans (eq_sym (block_entry_code cold warm access write reserve
Hrevision Hcold Hwarm world block a Hsystem)) Hempty).
Qed.
Lemma withdrawals_empty_code snapshot activity eligible predicted senders withdrawals state :
NonceAgreement eligible predicted (B.t.world_state state) senders →
EmptyCodeAgreement snapshot activity (B.t.world_state state) senders →
EmptyCodeAgreement snapshot activity (B.t.world_state
(Result.List.fold_left E.process_withdrawal state withdrawals)) senders.
Proof.
revert state. induction withdrawals as [|wd rest IH]; intros state Hnonce Hbefore;
[exact Hbefore|].
change (EmptyCodeAgreement snapshot activity (B.t.world_state
(Result.List.fold_left E.process_withdrawal (E.process_withdrawal state wd) rest)) senders).
apply IH.
- intros a Ha. destruct (Hnonce a Ha) as [He HP]. split; [exact He|].
unfold E.process_withdrawal. apply credit_world_account. exact HP.
- intros a Ha Hnot.
assert (HP : worldAccount a
(fun code _ ⇒ code = Byte_string.Bytes.empty →
A.t.code (accountAt snapshot a) = Byte_string.Bytes.empty) (B.t.world_state state)).
{ split; [exact (proj1 (proj2 (Hnonce a Ha)))|exact (Hbefore a Ha Hnot)]. }
unfold E.process_withdrawal.
apply (proj2 (credit_world_account a _ _ _ _ HP)).
Qed.
Theorem block_empty_code_agreement verify snapshot previous next world block post senders :
(∀ a, In a senders → a ≠ Reserve_balance.precompile_address) →
Forall (fun tx ⇒ Forall (fun auth ⇒ OCamlString.length (T.Authorization.t.address auth) = 20%Z)
(T.authorization_list tx)) (Block.t.transactions block) →
prescribedSystemCode world →
NonceAgreement (eligibleAt snapshot) (admissionNonces previous) world senders →
EmptyCodeAgreement snapshot (admissionActivity previous) world senders →
transactionsAvoidSenderCreation senders (blockTransactionEntry world block) (Block.t.transactions block) →
checkTransactions snapshot (Block.t.header block) previous (Block.t.transactions block) = Some next →
E.process_block verify world block = inl post →
EmptyCodeAgreement snapshot (admissionActivity next) post senders.
Proof.
intros Hnative Hwidth Hsystem Hnonce Hbefore Hcreation Hcheck Hrun.
pose proof (block_entry_nonce_agreement cold warm access write reserve Hrevision Hcold Hwarm
world block _ _ senders Hnative Hsystem Hnonce) as HentryNonce.
pose proof (block_entry_empty_code snapshot _ world block senders Hsystem Hbefore) as Hentry.
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 world block) as [[]|error]; [|discriminate].
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 E.process_transaction (blockTransactionEntry world block)
(Block.t.transactions block)) as [after|error] eqn:Htxs; [|discriminate].
pose proof (transactions_nonce_agreement cold warm access write reserve Hrevision Hcold Hwarm
snapshot previous next (blockTransactionEntry world block) (Block.t.transactions block) after senders
Hnative Hwidth HentryNonce Hcreation ltac:(rewrite block_entry_current; exact Hcheck) Htxs) as HnonceAfter.
pose proof (checked_transactions_empty_code cold warm access write reserve Hrevision Hcold Hwarm
snapshot previous next (blockTransactionEntry world block) (Block.t.transactions block) after senders
Hnative Hwidth HentryNonce Hentry Hcreation
ltac:(rewrite block_entry_current; exact Hcheck) Htxs) as Htransactions.
pose proof (withdrawals_empty_code snapshot _ _ _ senders (Block.t.withdrawals block) after
HnonceAfter Htransactions) as Hwithdrawals.
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;
[|discriminate].
destruct verify; [|injection Hrun as <-; exact Hwithdrawals].
match type of Hrun with context [match ?check with inl _ ⇒ _ | inr _ ⇒ _ end] ⇒
destruct check as [[]|error] end;
[injection Hrun as <-; exact Hwithdrawals|discriminate].
Qed.
Theorem blocks_empty_code_agreement verify snapshot previous next world blocks post senders :
(∀ a, In a senders → a ≠ Reserve_balance.precompile_address) →
Forall (fun block ⇒ Forall (fun tx ⇒ Forall
(fun auth ⇒ OCamlString.length (T.Authorization.t.address auth) = 20%Z)
(T.authorization_list tx)) (Block.t.transactions block)) blocks →
prescribedSystemCode world →
NonceAgreement (eligibleAt snapshot) (admissionNonces previous) world senders →
EmptyCodeAgreement snapshot (admissionActivity previous) world senders →
blocksAvoidSenderCreation senders verify world blocks →
checkBlocks snapshot previous blocks = Some next →
Result.List.fold_leftM (E.process_block verify) world blocks = inl post →
EmptyCodeAgreement snapshot (admissionActivity next) post senders.
Proof.
intros Hnative Hwidth. revert previous world.
induction Hwidth as [|block rest Hwidth Hrest IH];
intros previous world Hsystem Hnonce Hbefore Hcreation Hcheck Hrun.
- cbn [checkBlocks] in Hcheck. injection Hcheck as <-.
injection Hrun as <-. exact Hbefore.
- cbn [checkBlocks] in Hcheck.
match type of Hcheck with context [checkTransactions ?s ?h ?p ?ts] ⇒
set (capped := p) in *;
destruct (checkTransactions s h capped ts) as [middle|] eqn:Htxs end; [|discriminate].
change (Result.op_letdollar (E.process_block verify world block)
(fun after ⇒ Result.List.fold_leftM (E.process_block verify) after rest) = inl post) in Hrun.
destruct (E.process_block verify world block) as [after|error] eqn:Hblock; [|discriminate].
destruct Hcreation as [Hcreation Htail].
apply (IH middle after).
+ exact (block_preserves_system_code cold warm access write reserve verify world block after
Hrevision Hcold Hwarm Hsystem Hblock).
+ exact (block_nonce_agreement cold warm access write reserve Hrevision Hcold Hwarm
verify snapshot capped middle world block after senders Hnative Hwidth Hsystem Hnonce
(Hcreation (processed_block_valid_header _ _ _ _ Hblock)) Htxs Hblock).
+ exact (block_empty_code_agreement verify snapshot capped middle world block after senders
Hnative Hwidth Hsystem Hnonce Hbefore
(Hcreation (processed_block_valid_header _ _ _ _ Hblock)) Htxs Hblock).
+ exact (Htail after Hblock).
+ exact Hcheck.
+ exact Hrun.
Qed.
End Execution.
Print Assumptions blocks_empty_code_agreement.