Library SetcodeConcrete.windownonce
Initial nonce headroom prevents exhaustion throughout block execution
From Stdlib Require Import List String ZArith NArith Lia.
Require Import RocqOfOCaml.RocqOfOCaml MonadVM.Execution.
Require Import QedkConcrete.blockentry QedkConcrete.worldaccounts
QedkConcrete.admissionnonces.
Require Import SetcodeConcrete.noncebudget SetcodeConcrete.noncesequence
SetcodeConcrete.blocknonce SetcodeConcrete.blockcode SetcodeConcrete.noncefinalize.
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 B := State.BlockState.
Module W := State.WorldState.
Module T := Chain.Ethereum.Transaction.
Module Block := Chain.Ethereum.Block.
Definition windowTransactions blocks := Stdlib.Lists.List.concat
(Stdlib.Lists.List.map Block.t.transactions blocks).
Lemma window_transaction_budget blocks :
transactionsNonceBudget (windowTransactions blocks) = windowNonceBudget blocks.
Proof.
induction blocks as [|block rest IH]; [reflexivity|].
change (transactionsNonceBudget (Block.t.transactions block ++ windowTransactions rest) =
transactionsNonceBudget (Block.t.transactions block) + windowNonceBudget rest).
rewrite transactions_nonce_budget_app, IH. reflexivity.
Qed.
Lemma signed_nonce_bounds_append upper prefix rest :
signedNonceBounds upper (prefix ++ rest) ↔
signedNonceBounds upper prefix ∧
signedNonceBounds (upper + transactionsNonceBudget prefix) rest.
Proof.
revert upper. induction prefix as [|tx prefix IH]; intro upper.
- cbn [app signedNonceBounds nonceBoundedData transactionsNonceBudget fold_right].
rewrite Z.add_0_r. tauto.
- cbn [app signedNonceBounds nonceBoundedData]. rewrite IH.
change (transactionsNonceBudget (tx :: prefix)) with
(transactionNonceBudget tx + transactionsNonceBudget prefix).
replace (upper + (transactionNonceBudget tx + transactionsNonceBudget prefix)) with
(upper + transactionNonceBudget tx + transactionsNonceBudget prefix) by lia. tauto.
Qed.
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 withdrawals_nonce withdrawals state senders upper :
stringmaps.WellFormed (W.t.accounts (B.t.world_state state)) →
accountNonceBound senders (B.t.world_state state) upper →
let post := Result.List.fold_left E.process_withdrawal state withdrawals in
stringmaps.WellFormed (W.t.accounts (B.t.world_state post)) ∧
accountNonceBound senders (B.t.world_state post) upper.
Proof.
revert state. induction withdrawals as [|wd rest IH]; intros state Hmap Hbound.
- split; assumption.
- change (let post := Result.List.fold_left E.process_withdrawal
(E.process_withdrawal state wd) rest in
stringmaps.WellFormed (W.t.accounts (B.t.world_state post)) ∧
accountNonceBound senders (B.t.world_state post) upper).
apply IH.
+ unfold E.process_withdrawal. apply account_write_wellformed. exact Hmap.
+ intros a Ha.
assert (Hnonce : nonceAt (B.t.world_state (E.process_withdrawal state wd)) a =
nonceAt (B.t.world_state state) a).
{ unfold E.process_withdrawal. apply balance_write_nonce. exact Hmap. }
rewrite Hnonce. exact (Hbound a Ha).
Qed.
Theorem block_nonce_bound verify world block senders upper :
(∀ a, In a senders → a ≠ Reserve_balance.precompile_address) →
Forall (fun tx ⇒ ∃ a,
T.sender E.Params.(Execution.Make_Params_signature.chain_id) tx = Some a ∧ In a senders)
(Block.t.transactions block) →
prescribedSystemCode world → accountNonceBound senders world upper →
signedNonceBounds upper (Block.t.transactions block) →
upper + transactionsNonceBudget (Block.t.transactions block) < 2^64-1 →
match E.process_block verify world block with
| inl post ⇒ prescribedSystemCode post ∧
accountNonceBound senders post (upper + transactionsNonceBudget (Block.t.transactions block))
| inr error ⇒ ¬ nonceOverflowError error
end.
Proof.
intros Hnative Hsenders Hsystem Hbound Hsigned Hcapacity.
destruct Hsystem as [[Hmap Hbeacon] [_ Hhistory]].
assert (HentryMap : stringmaps.WellFormed (W.t.accounts (B.t.world_state (blockTransactionEntry world block)))).
{ exact (proj1 (block_entry_nonce cold warm access write reserve Hrevision Hcold Hwarm
world block EmptyString ltac:(vm_compute; discriminate) Hmap Hbeacon Hhistory)). }
assert (HentryNonces : accountNonceBound senders (B.t.world_state (blockTransactionEntry world block)) upper).
{ intros a Ha. rewrite (proj2 (block_entry_nonce cold warm access write reserve Hrevision Hcold Hwarm
world block a (Hnative a Ha) Hmap Hbeacon Hhistory)). exact (Hbound a Ha). }
pose proof (transactions_do_not_exhaust_nonces cold warm access write reserve Hrevision Hcold Hwarm
(Block.t.transactions block) (blockTransactionEntry world block) senders upper
Hnative Hsenders HentryMap HentryNonces Hsigned Hcapacity) as Htransactions.
destruct (E.process_block verify world block) as [post|error] eqn:Hrun.
2: { destruct error as [details|details]; [exact (fun H ⇒ H)|].
rewrite (block_transaction_error_from_entry cold warm access write reserve Hrevision
verify world block details Hrun) in Htransactions. exact Htransactions. }
split.
- exact (block_preserves_system_code cold warm access write reserve verify world block post
Hrevision Hcold Hwarm (conj (conj Hmap Hbeacon) (conj Hmap Hhistory)) 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 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].
destruct Htransactions as [HafterMap HafterBound].
pose proof (withdrawals_nonce (Block.t.withdrawals block) after senders
(upper + transactionsNonceBudget (Block.t.transactions block)) HafterMap HafterBound) 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 (proj2 Hwithdrawals)].
match type of Hrun with context [match ?check with inl _ ⇒ _ | inr _ ⇒ _ end] ⇒
destruct check as [[]|error] end;
[injection Hrun as <-; exact (proj2 Hwithdrawals)|discriminate].
Qed.
Theorem blocks_do_not_exhaust_nonces verify blocks world senders upper :
(∀ a, In a senders → a ≠ Reserve_balance.precompile_address) →
Forall (fun tx ⇒ ∃ a,
T.sender E.Params.(Execution.Make_Params_signature.chain_id) tx = Some a ∧ In a senders)
(windowTransactions blocks) →
prescribedSystemCode world → accountNonceBound senders world upper →
signedNonceBounds upper (windowTransactions blocks) →
upper + windowNonceBudget blocks < 2^64-1 →
match Result.List.fold_leftM (E.process_block verify) world blocks with
| inl post ⇒ prescribedSystemCode post ∧
accountNonceBound senders post (upper + windowNonceBudget blocks)
| inr error ⇒ ¬ nonceOverflowError error
end.
Proof.
revert world upper. induction blocks as [|block rest IH];
intros world upper Hnative Hsenders Hsystem Hbound Hsigned Hcapacity.
- change (prescribedSystemCode world ∧ accountNonceBound senders world (upper + 0)).
rewrite Z.add_0_r. split; assumption.
- change (windowTransactions (block :: rest)) with (Block.t.transactions block ++ windowTransactions rest) in ×.
apply Forall_app in Hsenders as [Hsenders Htail].
apply signed_nonce_bounds_append in Hsigned as [Hsigned HsignedRest].
change (windowNonceBudget (block :: rest)) with
(transactionsNonceBudget (Block.t.transactions block) + windowNonceBudget rest) in ×.
pose proof (window_nonce_budget_nonnegative rest) as Hremaining.
pose proof (block_nonce_bound verify world block senders upper Hnative Hsenders
Hsystem Hbound Hsigned ltac:(lia)) as Hblock.
change (Result.List.fold_leftM (E.process_block verify) world (block :: rest)) with
(Result.op_letdollar (E.process_block verify world block)
(fun middle ⇒ Result.List.fold_leftM (E.process_block verify) middle rest)).
destruct (E.process_block verify world block) as [middle|error] eqn:Hrun;
cbn beta iota zeta delta [Result.op_letdollar]; [|exact Hblock].
destruct Hblock as [Hsystem' Hbound'].
replace (upper + (transactionsNonceBudget (Block.t.transactions block) + windowNonceBudget rest)) with
((upper + transactionsNonceBudget (Block.t.transactions block)) + windowNonceBudget rest) by lia.
exact (IH middle _ Hnative Htail Hsystem' Hbound' HsignedRest ltac:(lia)).
Qed.
End Execution.
Require Import RocqOfOCaml.RocqOfOCaml MonadVM.Execution.
Require Import QedkConcrete.blockentry QedkConcrete.worldaccounts
QedkConcrete.admissionnonces.
Require Import SetcodeConcrete.noncebudget SetcodeConcrete.noncesequence
SetcodeConcrete.blocknonce SetcodeConcrete.blockcode SetcodeConcrete.noncefinalize.
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 B := State.BlockState.
Module W := State.WorldState.
Module T := Chain.Ethereum.Transaction.
Module Block := Chain.Ethereum.Block.
Definition windowTransactions blocks := Stdlib.Lists.List.concat
(Stdlib.Lists.List.map Block.t.transactions blocks).
Lemma window_transaction_budget blocks :
transactionsNonceBudget (windowTransactions blocks) = windowNonceBudget blocks.
Proof.
induction blocks as [|block rest IH]; [reflexivity|].
change (transactionsNonceBudget (Block.t.transactions block ++ windowTransactions rest) =
transactionsNonceBudget (Block.t.transactions block) + windowNonceBudget rest).
rewrite transactions_nonce_budget_app, IH. reflexivity.
Qed.
Lemma signed_nonce_bounds_append upper prefix rest :
signedNonceBounds upper (prefix ++ rest) ↔
signedNonceBounds upper prefix ∧
signedNonceBounds (upper + transactionsNonceBudget prefix) rest.
Proof.
revert upper. induction prefix as [|tx prefix IH]; intro upper.
- cbn [app signedNonceBounds nonceBoundedData transactionsNonceBudget fold_right].
rewrite Z.add_0_r. tauto.
- cbn [app signedNonceBounds nonceBoundedData]. rewrite IH.
change (transactionsNonceBudget (tx :: prefix)) with
(transactionNonceBudget tx + transactionsNonceBudget prefix).
replace (upper + (transactionNonceBudget tx + transactionsNonceBudget prefix)) with
(upper + transactionNonceBudget tx + transactionsNonceBudget prefix) by lia. tauto.
Qed.
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 withdrawals_nonce withdrawals state senders upper :
stringmaps.WellFormed (W.t.accounts (B.t.world_state state)) →
accountNonceBound senders (B.t.world_state state) upper →
let post := Result.List.fold_left E.process_withdrawal state withdrawals in
stringmaps.WellFormed (W.t.accounts (B.t.world_state post)) ∧
accountNonceBound senders (B.t.world_state post) upper.
Proof.
revert state. induction withdrawals as [|wd rest IH]; intros state Hmap Hbound.
- split; assumption.
- change (let post := Result.List.fold_left E.process_withdrawal
(E.process_withdrawal state wd) rest in
stringmaps.WellFormed (W.t.accounts (B.t.world_state post)) ∧
accountNonceBound senders (B.t.world_state post) upper).
apply IH.
+ unfold E.process_withdrawal. apply account_write_wellformed. exact Hmap.
+ intros a Ha.
assert (Hnonce : nonceAt (B.t.world_state (E.process_withdrawal state wd)) a =
nonceAt (B.t.world_state state) a).
{ unfold E.process_withdrawal. apply balance_write_nonce. exact Hmap. }
rewrite Hnonce. exact (Hbound a Ha).
Qed.
Theorem block_nonce_bound verify world block senders upper :
(∀ a, In a senders → a ≠ Reserve_balance.precompile_address) →
Forall (fun tx ⇒ ∃ a,
T.sender E.Params.(Execution.Make_Params_signature.chain_id) tx = Some a ∧ In a senders)
(Block.t.transactions block) →
prescribedSystemCode world → accountNonceBound senders world upper →
signedNonceBounds upper (Block.t.transactions block) →
upper + transactionsNonceBudget (Block.t.transactions block) < 2^64-1 →
match E.process_block verify world block with
| inl post ⇒ prescribedSystemCode post ∧
accountNonceBound senders post (upper + transactionsNonceBudget (Block.t.transactions block))
| inr error ⇒ ¬ nonceOverflowError error
end.
Proof.
intros Hnative Hsenders Hsystem Hbound Hsigned Hcapacity.
destruct Hsystem as [[Hmap Hbeacon] [_ Hhistory]].
assert (HentryMap : stringmaps.WellFormed (W.t.accounts (B.t.world_state (blockTransactionEntry world block)))).
{ exact (proj1 (block_entry_nonce cold warm access write reserve Hrevision Hcold Hwarm
world block EmptyString ltac:(vm_compute; discriminate) Hmap Hbeacon Hhistory)). }
assert (HentryNonces : accountNonceBound senders (B.t.world_state (blockTransactionEntry world block)) upper).
{ intros a Ha. rewrite (proj2 (block_entry_nonce cold warm access write reserve Hrevision Hcold Hwarm
world block a (Hnative a Ha) Hmap Hbeacon Hhistory)). exact (Hbound a Ha). }
pose proof (transactions_do_not_exhaust_nonces cold warm access write reserve Hrevision Hcold Hwarm
(Block.t.transactions block) (blockTransactionEntry world block) senders upper
Hnative Hsenders HentryMap HentryNonces Hsigned Hcapacity) as Htransactions.
destruct (E.process_block verify world block) as [post|error] eqn:Hrun.
2: { destruct error as [details|details]; [exact (fun H ⇒ H)|].
rewrite (block_transaction_error_from_entry cold warm access write reserve Hrevision
verify world block details Hrun) in Htransactions. exact Htransactions. }
split.
- exact (block_preserves_system_code cold warm access write reserve verify world block post
Hrevision Hcold Hwarm (conj (conj Hmap Hbeacon) (conj Hmap Hhistory)) 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 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].
destruct Htransactions as [HafterMap HafterBound].
pose proof (withdrawals_nonce (Block.t.withdrawals block) after senders
(upper + transactionsNonceBudget (Block.t.transactions block)) HafterMap HafterBound) 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 (proj2 Hwithdrawals)].
match type of Hrun with context [match ?check with inl _ ⇒ _ | inr _ ⇒ _ end] ⇒
destruct check as [[]|error] end;
[injection Hrun as <-; exact (proj2 Hwithdrawals)|discriminate].
Qed.
Theorem blocks_do_not_exhaust_nonces verify blocks world senders upper :
(∀ a, In a senders → a ≠ Reserve_balance.precompile_address) →
Forall (fun tx ⇒ ∃ a,
T.sender E.Params.(Execution.Make_Params_signature.chain_id) tx = Some a ∧ In a senders)
(windowTransactions blocks) →
prescribedSystemCode world → accountNonceBound senders world upper →
signedNonceBounds upper (windowTransactions blocks) →
upper + windowNonceBudget blocks < 2^64-1 →
match Result.List.fold_leftM (E.process_block verify) world blocks with
| inl post ⇒ prescribedSystemCode post ∧
accountNonceBound senders post (upper + windowNonceBudget blocks)
| inr error ⇒ ¬ nonceOverflowError error
end.
Proof.
revert world upper. induction blocks as [|block rest IH];
intros world upper Hnative Hsenders Hsystem Hbound Hsigned Hcapacity.
- change (prescribedSystemCode world ∧ accountNonceBound senders world (upper + 0)).
rewrite Z.add_0_r. split; assumption.
- change (windowTransactions (block :: rest)) with (Block.t.transactions block ++ windowTransactions rest) in ×.
apply Forall_app in Hsenders as [Hsenders Htail].
apply signed_nonce_bounds_append in Hsigned as [Hsigned HsignedRest].
change (windowNonceBudget (block :: rest)) with
(transactionsNonceBudget (Block.t.transactions block) + windowNonceBudget rest) in ×.
pose proof (window_nonce_budget_nonnegative rest) as Hremaining.
pose proof (block_nonce_bound verify world block senders upper Hnative Hsenders
Hsystem Hbound Hsigned ltac:(lia)) as Hblock.
change (Result.List.fold_leftM (E.process_block verify) world (block :: rest)) with
(Result.op_letdollar (E.process_block verify world block)
(fun middle ⇒ Result.List.fold_leftM (E.process_block verify) middle rest)).
destruct (E.process_block verify world block) as [middle|error] eqn:Hrun;
cbn beta iota zeta delta [Result.op_letdollar]; [|exact Hblock].
destruct Hblock as [Hsystem' Hbound'].
replace (upper + (transactionsNonceBudget (Block.t.transactions block) + windowNonceBudget rest)) with
((upper + transactionsNonceBudget (Block.t.transactions block)) + windowNonceBudget rest) by lia.
exact (IH middle _ Hnative Htail Hsystem' Hbound' HsignedRest ltac:(lia)).
Qed.
End Execution.
Public nonce admission and the two initial half-range conditions suffice.
There is no successful-prefix, successful-validation, per-block system-code,
or reached-state nonce premise. Other errors are deliberately separate.
Theorem admitted_window_does_not_exhaust_nonces {F : E.FArgs}
cold warm access write reserve verify blocks world senders eligible :
E.Params.(Execution.Make_Params_signature.revision) =
Support.Variants.Revision.Setcode (cold, warm, access, write, reserve) →
(0 < cold)%N → (0 < warm)%N →
(∀ a, In a senders → a ≠ Reserve_balance.precompile_address) →
Forall (fun tx ⇒ ∀ a,
T.sender E.Params.(Execution.Make_Params_signature.chain_id) tx = Some a → In a senders)
(windowTransactions blocks) →
NonceAdmission eligible (nonceAt world) (windowTransactions blocks) →
prescribedSystemCode world → InitialNonceBounds senders world blocks →
match Result.List.fold_leftM (E.process_block verify) world blocks with
| inl post ⇒ prescribedSystemCode post ∧
accountNonceBound senders post (2^63-1 + windowNonceBudget blocks)
| inr error ⇒ ¬ nonceOverflowError error
end.
Proof.
intros Hrevision Hcold Hwarm Hnative Hsenders Hadmission Hsystem [Hnonces Hbudget].
apply (blocks_do_not_exhaust_nonces cold warm access write reserve Hrevision Hcold Hwarm
verify blocks world senders (2^63-1)); try assumption.
- exact (nonce_admission_senders eligible _ _ _ Hadmission Hsenders).
- intros a Ha. specialize (Hnonces a Ha). lia.
- eapply nonce_admission_bounds.
+ exact Hadmission.
+ exact Hsenders.
+ intros a Ha. specialize (Hnonces a Ha). lia.
+ intro tx. unfold transactionNonceBudget. lia.
- lia.
Qed.
Print Assumptions admitted_window_does_not_exhaust_nonces.
cold warm access write reserve verify blocks world senders eligible :
E.Params.(Execution.Make_Params_signature.revision) =
Support.Variants.Revision.Setcode (cold, warm, access, write, reserve) →
(0 < cold)%N → (0 < warm)%N →
(∀ a, In a senders → a ≠ Reserve_balance.precompile_address) →
Forall (fun tx ⇒ ∀ a,
T.sender E.Params.(Execution.Make_Params_signature.chain_id) tx = Some a → In a senders)
(windowTransactions blocks) →
NonceAdmission eligible (nonceAt world) (windowTransactions blocks) →
prescribedSystemCode world → InitialNonceBounds senders world blocks →
match Result.List.fold_leftM (E.process_block verify) world blocks with
| inl post ⇒ prescribedSystemCode post ∧
accountNonceBound senders post (2^63-1 + windowNonceBudget blocks)
| inr error ⇒ ¬ nonceOverflowError error
end.
Proof.
intros Hrevision Hcold Hwarm Hnative Hsenders Hadmission Hsystem [Hnonces Hbudget].
apply (blocks_do_not_exhaust_nonces cold warm access write reserve Hrevision Hcold Hwarm
verify blocks world senders (2^63-1)); try assumption.
- exact (nonce_admission_senders eligible _ _ _ Hadmission Hsenders).
- intros a Ha. specialize (Hnonces a Ha). lia.
- eapply nonce_admission_bounds.
+ exact Hadmission.
+ exact Hsenders.
+ intros a Ha. specialize (Hnonces a Ha). lia.
+ intro tx. unfold transactionNonceBudget. lia.
- lia.
Qed.
Print Assumptions admitted_window_does_not_exhaust_nonces.
Execute any prefix of the originally admitted window. On success,
every protected sender retains capacity for all remaining transactions.
The initial half-range conditions are not required of the returned state.
Corollary admitted_prefix_retains_nonce_capacity {F : E.FArgs}
cold warm access write reserve verify past rest world senders eligible :
E.Params.(Execution.Make_Params_signature.revision) =
Support.Variants.Revision.Setcode (cold, warm, access, write, reserve) →
(0 < cold)%N → (0 < warm)%N →
(∀ a, In a senders → a ≠ Reserve_balance.precompile_address) →
Forall (fun tx ⇒ ∀ a,
T.sender E.Params.(Execution.Make_Params_signature.chain_id) tx = Some a → In a senders)
(windowTransactions (past ++ rest)) →
NonceAdmission eligible (nonceAt world) (windowTransactions (past ++ rest)) →
prescribedSystemCode world → InitialNonceBounds senders world (past ++ rest) →
match Result.List.fold_leftM (E.process_block verify) world past with
| inl post ⇒ prescribedSystemCode post ∧
∀ a, In a senders →
0 ≤ nonceAt post a ∧ nonceAt post a + windowNonceBudget rest < 2^64-1
| inr error ⇒ ¬ nonceOverflowError error
end.
Proof.
intros Hrevision Hcold Hwarm Hnative Hsenders Hadmission Hsystem [Hnonces Hbudget].
assert (Htransactions : windowTransactions (past ++ rest) =
windowTransactions past ++ windowTransactions rest).
{ unfold windowTransactions. rewrite map_app, concat_app. reflexivity. }
pose proof (nonce_admission_senders eligible _ _ _ Hadmission Hsenders) as Hmembers.
assert (Hbounds : signedNonceBounds (2^63-1) (windowTransactions (past ++ rest))).
{ eapply nonce_admission_bounds.
- exact Hadmission.
- exact Hsenders.
- intros a Ha. specialize (Hnonces a Ha). lia.
- intro tx. unfold transactionNonceBudget. lia. }
rewrite Htransactions, Forall_app in Hmembers. destruct Hmembers as [Hmembers _].
rewrite Htransactions, signed_nonce_bounds_append in Hbounds. destruct Hbounds as [Hbounds _].
rewrite window_nonce_budget_app in Hbudget.
pose proof (window_nonce_budget_nonnegative rest) as Hremaining.
pose proof (blocks_do_not_exhaust_nonces cold warm access write reserve Hrevision Hcold Hwarm
verify past world senders (2^63-1) Hnative Hmembers Hsystem
ltac:(intros a Ha; specialize (Hnonces a Ha); lia) Hbounds ltac:(lia)) as Hrun.
destruct (Result.List.fold_leftM (E.process_block verify) world past) as [post|error];
[|exact Hrun].
destruct Hrun as [Hsystem' Hbound]. split; [exact Hsystem'|].
intros a Ha. specialize (Hbound a Ha). lia.
Qed.
Print Assumptions admitted_prefix_retains_nonce_capacity.
cold warm access write reserve verify past rest world senders eligible :
E.Params.(Execution.Make_Params_signature.revision) =
Support.Variants.Revision.Setcode (cold, warm, access, write, reserve) →
(0 < cold)%N → (0 < warm)%N →
(∀ a, In a senders → a ≠ Reserve_balance.precompile_address) →
Forall (fun tx ⇒ ∀ a,
T.sender E.Params.(Execution.Make_Params_signature.chain_id) tx = Some a → In a senders)
(windowTransactions (past ++ rest)) →
NonceAdmission eligible (nonceAt world) (windowTransactions (past ++ rest)) →
prescribedSystemCode world → InitialNonceBounds senders world (past ++ rest) →
match Result.List.fold_leftM (E.process_block verify) world past with
| inl post ⇒ prescribedSystemCode post ∧
∀ a, In a senders →
0 ≤ nonceAt post a ∧ nonceAt post a + windowNonceBudget rest < 2^64-1
| inr error ⇒ ¬ nonceOverflowError error
end.
Proof.
intros Hrevision Hcold Hwarm Hnative Hsenders Hadmission Hsystem [Hnonces Hbudget].
assert (Htransactions : windowTransactions (past ++ rest) =
windowTransactions past ++ windowTransactions rest).
{ unfold windowTransactions. rewrite map_app, concat_app. reflexivity. }
pose proof (nonce_admission_senders eligible _ _ _ Hadmission Hsenders) as Hmembers.
assert (Hbounds : signedNonceBounds (2^63-1) (windowTransactions (past ++ rest))).
{ eapply nonce_admission_bounds.
- exact Hadmission.
- exact Hsenders.
- intros a Ha. specialize (Hnonces a Ha). lia.
- intro tx. unfold transactionNonceBudget. lia. }
rewrite Htransactions, Forall_app in Hmembers. destruct Hmembers as [Hmembers _].
rewrite Htransactions, signed_nonce_bounds_append in Hbounds. destruct Hbounds as [Hbounds _].
rewrite window_nonce_budget_app in Hbudget.
pose proof (window_nonce_budget_nonnegative rest) as Hremaining.
pose proof (blocks_do_not_exhaust_nonces cold warm access write reserve Hrevision Hcold Hwarm
verify past world senders (2^63-1) Hnative Hmembers Hsystem
ltac:(intros a Ha; specialize (Hnonces a Ha); lia) Hbounds ltac:(lia)) as Hrun.
destruct (Result.List.fold_leftM (E.process_block verify) world past) as [post|error];
[|exact Hrun].
destruct Hrun as [Hsystem' Hbound]. split; [exact Hsystem'|].
intros a Ha. specialize (Hbound a Ha). lia.
Qed.
Print Assumptions admitted_prefix_retains_nonce_capacity.