Library SetcodeConcrete.consensusvalidation
Public checks exclude every non-fee transaction-validation error
From Stdlib Require Import List String ZArith Bool.
Require Import RocqOfOCaml.RocqOfOCaml MonadVM.Execution.
Require Import QedkConcrete.blockentry QedkConcrete.transactionchecks.
Require Import SetcodeConcrete.nonceagreement SetcodeConcrete.nonceagreementsequence
SetcodeConcrete.windownonceagreement SetcodeConcrete.blocknonceagreement
SetcodeConcrete.validationerrors SetcodeConcrete.validatedexecution
SetcodeConcrete.consensuschecks SetcodeConcrete.transactioncode
SetcodeConcrete.codeevolution SetcodeConcrete.consensusnonce
SetcodeConcrete.blockcode SetcodeConcrete.blocknonce SetcodeConcrete.supplysequence.
Set Default Goal Selector "!".
Import ListNotations.
Module E := Execution.Make.
Module B := State.BlockState.
Module W := State.WorldState.
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 checked_transactions_validation_errors snapshot previous next state txs 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)) txs →
Forall (fun tx ⇒ ∀ a,
T.sender E.Params.(Execution.Make_Params_signature.chain_id) tx = Some a → In a senders) txs →
NonceAgreement (eligibleAt snapshot) (admissionNonces previous) (B.t.world_state state) senders →
transactionsAvoidSenderCreation senders state txs →
checkTransactions snapshot (Block.t.header (B.t.current_block state)) previous txs = Some next →
match Result.List.fold_leftM E.process_transaction state txs with
| inl post ⇒ NonceAgreement (eligibleAt snapshot) (admissionNonces next) (B.t.world_state post) senders
| inr error ⇒ feeOrNonceOverflow error
end.
Proof.
intros Hnative Hwidth. revert previous state.
induction Hwidth as [|tx rest Hwidth Hrest IH];
intros previous state Hsenders Hbefore Hcreated Hcheck.
- cbn [checkTransactions] in Hcheck. injection Hcheck as <-. exact Hbefore.
- inversion Hsenders as [|? ? HsenderIn HsenderRest]; subst.
cbn [checkTransactions] in Hcheck.
destruct (checkTransaction snapshot (Block.t.header (B.t.current_block state)) previous tx)
as [middle|] eqn:Htx; [|discriminate].
unfold checkTransaction in Htx.
destruct (T.sender _ tx) as [sender|] eqn:Hsender; [|discriminate].
destruct (Gas.tx_effective_gas_price _ tx) as [price|] eqn:Hprice; [|discriminate].
destruct (transactionChecks _ _ _ _) eqn:Hchecks; [|discriminate].
cbn zeta in Htx. match type of Htx with context [if ?test then _ else _] ⇒
destruct test end; [|discriminate].
injection Htx as <-.
destruct Hcreated as [Hcreation Hcreated].
change (Result.List.fold_leftM E.process_transaction state (tx :: rest)) with
(Result.op_letdollar (E.process_transaction state tx)
(fun after ⇒ Result.List.fold_leftM E.process_transaction after rest)).
destruct (E.process_transaction state tx) as [after|error] eqn:Hrun.
+ match type of Hcheck with checkTransactions _ _ ?p _ = _ ⇒
apply (IH p after HsenderRest) end.
× exact (process_transaction_nonce_agreement cold warm access write reserve Hrevision Hcold Hwarm
state tx after (eligibleAt snapshot) (admissionNonces previous) senders sender
Hnative Hwidth Hsender Hbefore Hcreation Hrun).
× exact (Hcreated after eq_refl).
× rewrite (process_transaction_current_block state tx after Hrun). exact Hcheck.
+ destruct (Hbefore sender (HsenderIn sender eq_refl)) as [Heligible [Hmap Hagree]].
unfold eligibleAt in Heligible. apply Bool.negb_true_iff in Heligible.
rewrite Heligible in Hchecks.
apply (admitted_validation_error state tx sender (admissionNonces previous sender) price error).
× rewrite Hrevision. reflexivity.
× exact Hsender.
× exact Hchecks.
× destruct Hagree as [Hcode|Hnonce]; [left; apply regular_code_contract; exact Hcode|right; exact Hnonce].
× exact Hprice.
× exact (transaction_error_from_validation state tx error Hrun).
Qed.
Lemma transaction_error_has_valid_block_header verify world block details :
E.process_block verify world block = inr (Execution.Error.Invalid_transaction details) →
E.validate_block world block = inl tt.
Proof.
intro Hrun. unfold E.process_block in Hrun.
destruct (E.validate_block world block) as [[]|error] eqn:Hvalid; [reflexivity|].
cbn in Hrun. injection Hrun as Heq. subst error.
exfalso. exact (validate_block_no_transaction_error world block details Hvalid).
Qed.
Lemma checked_block_validation_errors verify snapshot previous next world block senders details :
(∀ 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) →
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 →
NonceAgreement (eligibleAt snapshot) (admissionNonces previous) world senders →
(E.validate_block world block = inl tt →
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 = inr (Execution.Error.Invalid_transaction details) →
feeOrNonceOverflow (Execution.Error.Invalid_transaction details).
Proof.
intros Hnative Hwidth Hsenders Hsystem Hbefore Hcreation Hcheck Hrun.
pose proof (block_entry_nonce_agreement cold warm access write reserve Hrevision Hcold Hwarm
world block _ _ senders Hnative Hsystem Hbefore) as Hentry.
pose proof (checked_transactions_validation_errors snapshot previous next
(blockTransactionEntry world block) (Block.t.transactions block) senders Hnative Hwidth Hsenders Hentry
(Hcreation (transaction_error_has_valid_block_header _ _ _ _ Hrun))
ltac:(rewrite block_entry_current; exact Hcheck)) as Htxs.
rewrite (block_transaction_error_from_entry cold warm access write reserve Hrevision
verify world block details Hrun) in Htxs. exact Htxs.
Qed.
Theorem checked_blocks_validation_errors verify snapshot previous next world blocks senders details :
(∀ 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 →
Forall (fun tx ⇒ ∀ a,
T.sender E.Params.(Execution.Make_Params_signature.chain_id) tx = Some a → In a senders)
(windownonce.windowTransactions blocks) →
prescribedSystemCode world →
NonceAgreement (eligibleAt snapshot) (admissionNonces previous) world senders →
blocksAvoidSenderCreation senders verify world blocks →
checkBlocks snapshot previous blocks = Some next →
Result.List.fold_leftM (E.process_block verify) world blocks =
inr (Execution.Error.Invalid_transaction details) →
feeOrNonceOverflow (Execution.Error.Invalid_transaction details).
Proof.
intros Hnative Hwidth. revert previous world.
induction Hwidth as [|block rest Hwidth Hrest IH];
intros previous world Hsenders Hsystem Hbefore Hcreation Hcheck Hrun; [discriminate|].
change (windownonce.windowTransactions (block :: rest)) with
(Block.t.transactions block ++ windownonce.windowTransactions rest) in Hsenders.
apply Forall_app in Hsenders as [Hsenders HtailSenders].
cbn [checkBlocks] in Hcheck.
match type of Hcheck with context [checkTransactions ?s ?h ?p ?txs] ⇒
set (capped := p) in *;
destruct (checkTransactions s h capped txs) 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) =
inr (Execution.Error.Invalid_transaction details)) in Hrun.
destruct Hcreation as [Hcreation Htail].
destruct (E.process_block verify world block) as [after|error] eqn:Hblock.
- apply (IH middle after HtailSenders).
+ 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 Hbefore
(Hcreation (processed_block_valid_header _ _ _ _ Hblock)) Htxs Hblock).
+ exact (Htail after eq_refl).
+ exact Hcheck.
+ exact Hrun.
- cbn in Hrun. injection Hrun as Heq. subst error.
exact (checked_block_validation_errors verify snapshot capped middle world block senders details
Hnative Hwidth Hsenders Hsystem Hbefore Hcreation Htxs Hblock).
Qed.
Require Import RocqOfOCaml.RocqOfOCaml MonadVM.Execution.
Require Import QedkConcrete.blockentry QedkConcrete.transactionchecks.
Require Import SetcodeConcrete.nonceagreement SetcodeConcrete.nonceagreementsequence
SetcodeConcrete.windownonceagreement SetcodeConcrete.blocknonceagreement
SetcodeConcrete.validationerrors SetcodeConcrete.validatedexecution
SetcodeConcrete.consensuschecks SetcodeConcrete.transactioncode
SetcodeConcrete.codeevolution SetcodeConcrete.consensusnonce
SetcodeConcrete.blockcode SetcodeConcrete.blocknonce SetcodeConcrete.supplysequence.
Set Default Goal Selector "!".
Import ListNotations.
Module E := Execution.Make.
Module B := State.BlockState.
Module W := State.WorldState.
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 checked_transactions_validation_errors snapshot previous next state txs 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)) txs →
Forall (fun tx ⇒ ∀ a,
T.sender E.Params.(Execution.Make_Params_signature.chain_id) tx = Some a → In a senders) txs →
NonceAgreement (eligibleAt snapshot) (admissionNonces previous) (B.t.world_state state) senders →
transactionsAvoidSenderCreation senders state txs →
checkTransactions snapshot (Block.t.header (B.t.current_block state)) previous txs = Some next →
match Result.List.fold_leftM E.process_transaction state txs with
| inl post ⇒ NonceAgreement (eligibleAt snapshot) (admissionNonces next) (B.t.world_state post) senders
| inr error ⇒ feeOrNonceOverflow error
end.
Proof.
intros Hnative Hwidth. revert previous state.
induction Hwidth as [|tx rest Hwidth Hrest IH];
intros previous state Hsenders Hbefore Hcreated Hcheck.
- cbn [checkTransactions] in Hcheck. injection Hcheck as <-. exact Hbefore.
- inversion Hsenders as [|? ? HsenderIn HsenderRest]; subst.
cbn [checkTransactions] in Hcheck.
destruct (checkTransaction snapshot (Block.t.header (B.t.current_block state)) previous tx)
as [middle|] eqn:Htx; [|discriminate].
unfold checkTransaction in Htx.
destruct (T.sender _ tx) as [sender|] eqn:Hsender; [|discriminate].
destruct (Gas.tx_effective_gas_price _ tx) as [price|] eqn:Hprice; [|discriminate].
destruct (transactionChecks _ _ _ _) eqn:Hchecks; [|discriminate].
cbn zeta in Htx. match type of Htx with context [if ?test then _ else _] ⇒
destruct test end; [|discriminate].
injection Htx as <-.
destruct Hcreated as [Hcreation Hcreated].
change (Result.List.fold_leftM E.process_transaction state (tx :: rest)) with
(Result.op_letdollar (E.process_transaction state tx)
(fun after ⇒ Result.List.fold_leftM E.process_transaction after rest)).
destruct (E.process_transaction state tx) as [after|error] eqn:Hrun.
+ match type of Hcheck with checkTransactions _ _ ?p _ = _ ⇒
apply (IH p after HsenderRest) end.
× exact (process_transaction_nonce_agreement cold warm access write reserve Hrevision Hcold Hwarm
state tx after (eligibleAt snapshot) (admissionNonces previous) senders sender
Hnative Hwidth Hsender Hbefore Hcreation Hrun).
× exact (Hcreated after eq_refl).
× rewrite (process_transaction_current_block state tx after Hrun). exact Hcheck.
+ destruct (Hbefore sender (HsenderIn sender eq_refl)) as [Heligible [Hmap Hagree]].
unfold eligibleAt in Heligible. apply Bool.negb_true_iff in Heligible.
rewrite Heligible in Hchecks.
apply (admitted_validation_error state tx sender (admissionNonces previous sender) price error).
× rewrite Hrevision. reflexivity.
× exact Hsender.
× exact Hchecks.
× destruct Hagree as [Hcode|Hnonce]; [left; apply regular_code_contract; exact Hcode|right; exact Hnonce].
× exact Hprice.
× exact (transaction_error_from_validation state tx error Hrun).
Qed.
Lemma transaction_error_has_valid_block_header verify world block details :
E.process_block verify world block = inr (Execution.Error.Invalid_transaction details) →
E.validate_block world block = inl tt.
Proof.
intro Hrun. unfold E.process_block in Hrun.
destruct (E.validate_block world block) as [[]|error] eqn:Hvalid; [reflexivity|].
cbn in Hrun. injection Hrun as Heq. subst error.
exfalso. exact (validate_block_no_transaction_error world block details Hvalid).
Qed.
Lemma checked_block_validation_errors verify snapshot previous next world block senders details :
(∀ 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) →
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 →
NonceAgreement (eligibleAt snapshot) (admissionNonces previous) world senders →
(E.validate_block world block = inl tt →
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 = inr (Execution.Error.Invalid_transaction details) →
feeOrNonceOverflow (Execution.Error.Invalid_transaction details).
Proof.
intros Hnative Hwidth Hsenders Hsystem Hbefore Hcreation Hcheck Hrun.
pose proof (block_entry_nonce_agreement cold warm access write reserve Hrevision Hcold Hwarm
world block _ _ senders Hnative Hsystem Hbefore) as Hentry.
pose proof (checked_transactions_validation_errors snapshot previous next
(blockTransactionEntry world block) (Block.t.transactions block) senders Hnative Hwidth Hsenders Hentry
(Hcreation (transaction_error_has_valid_block_header _ _ _ _ Hrun))
ltac:(rewrite block_entry_current; exact Hcheck)) as Htxs.
rewrite (block_transaction_error_from_entry cold warm access write reserve Hrevision
verify world block details Hrun) in Htxs. exact Htxs.
Qed.
Theorem checked_blocks_validation_errors verify snapshot previous next world blocks senders details :
(∀ 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 →
Forall (fun tx ⇒ ∀ a,
T.sender E.Params.(Execution.Make_Params_signature.chain_id) tx = Some a → In a senders)
(windownonce.windowTransactions blocks) →
prescribedSystemCode world →
NonceAgreement (eligibleAt snapshot) (admissionNonces previous) world senders →
blocksAvoidSenderCreation senders verify world blocks →
checkBlocks snapshot previous blocks = Some next →
Result.List.fold_leftM (E.process_block verify) world blocks =
inr (Execution.Error.Invalid_transaction details) →
feeOrNonceOverflow (Execution.Error.Invalid_transaction details).
Proof.
intros Hnative Hwidth. revert previous world.
induction Hwidth as [|block rest Hwidth Hrest IH];
intros previous world Hsenders Hsystem Hbefore Hcreation Hcheck Hrun; [discriminate|].
change (windownonce.windowTransactions (block :: rest)) with
(Block.t.transactions block ++ windownonce.windowTransactions rest) in Hsenders.
apply Forall_app in Hsenders as [Hsenders HtailSenders].
cbn [checkBlocks] in Hcheck.
match type of Hcheck with context [checkTransactions ?s ?h ?p ?txs] ⇒
set (capped := p) in *;
destruct (checkTransactions s h capped txs) 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) =
inr (Execution.Error.Invalid_transaction details)) in Hrun.
destruct Hcreation as [Hcreation Htail].
destruct (E.process_block verify world block) as [after|error] eqn:Hblock.
- apply (IH middle after HtailSenders).
+ 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 Hbefore
(Hcreation (processed_block_valid_header _ _ _ _ Hblock)) Htxs Hblock).
+ exact (Htail after eq_refl).
+ exact Hcheck.
+ exact Hrun.
- cbn in Hrun. injection Hrun as Heq. subst error.
exact (checked_block_validation_errors verify snapshot capped middle world block senders details
Hnative Hwidth Hsenders Hsystem Hbefore Hcreation Htxs Hblock).
Qed.
For the whole accepted window, nonce exhaustion and nonce mismatches
are excluded. If transaction validation fails at all, its reason is
insufficient balance. This does not assume that any prefix succeeds.
Theorem consensus_only_fee_validation_error verify snapshot height blocks senders details :
(∀ 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 →
Forall (fun tx ⇒ ∀ a,
T.sender E.Params.(Execution.Make_Params_signature.chain_id) tx = Some a → In a senders)
(windownonce.windowTransactions blocks) →
prescribedSystemCode snapshot →
(∀ a, In a senders → A.is_smart_contract (accountAt snapshot a) = false) →
noncebudget.InitialNonceBounds senders snapshot blocks →
blocksAvoidSenderCreation senders verify snapshot blocks →
consensusAccepts snapshot height blocks →
Result.List.fold_leftM (E.process_block verify) snapshot blocks =
inr (Execution.Error.Invalid_transaction details) →
∃ fee, Execution.Error.t.Invalid_transaction.reason details = Execution.Error.Insufficient_balance fee.
Proof.
intros Hnative Hwidth Hsenders Hsystem Hcode Hnonces Hcreation Hadmit Hrun.
pose proof (consensus_window_no_nonce_overflow cold warm access write reserve verify snapshot
height blocks senders Hrevision Hcold Hwarm Hnative Hsenders Hadmit Hsystem Hnonces) as Hmax.
rewrite Hrun in Hmax.
destruct Hadmit as [next Hcheck].
pose proof (initial_nonce_agreement snapshot senders (proj1 (proj1 Hsystem)) Hcode) as Hinitial.
destruct (checked_blocks_validation_errors verify snapshot (initialAdmission snapshot height) next
snapshot blocks senders details Hnative Hwidth Hsenders Hsystem Hinitial Hcreation Hcheck Hrun)
as [Hoverflow|Hfee]; [contradiction|exact Hfee].
Qed.
End Execution.
Print Assumptions consensus_only_fee_validation_error.
(∀ 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 →
Forall (fun tx ⇒ ∀ a,
T.sender E.Params.(Execution.Make_Params_signature.chain_id) tx = Some a → In a senders)
(windownonce.windowTransactions blocks) →
prescribedSystemCode snapshot →
(∀ a, In a senders → A.is_smart_contract (accountAt snapshot a) = false) →
noncebudget.InitialNonceBounds senders snapshot blocks →
blocksAvoidSenderCreation senders verify snapshot blocks →
consensusAccepts snapshot height blocks →
Result.List.fold_leftM (E.process_block verify) snapshot blocks =
inr (Execution.Error.Invalid_transaction details) →
∃ fee, Execution.Error.t.Invalid_transaction.reason details = Execution.Error.Insufficient_balance fee.
Proof.
intros Hnative Hwidth Hsenders Hsystem Hcode Hnonces Hcreation Hadmit Hrun.
pose proof (consensus_window_no_nonce_overflow cold warm access write reserve verify snapshot
height blocks senders Hrevision Hcold Hwarm Hnative Hsenders Hadmit Hsystem Hnonces) as Hmax.
rewrite Hrun in Hmax.
destruct Hadmit as [next Hcheck].
pose proof (initial_nonce_agreement snapshot senders (proj1 (proj1 Hsystem)) Hcode) as Hinitial.
destruct (checked_blocks_validation_errors verify snapshot (initialAdmission snapshot height) next
snapshot blocks senders details Hnative Hwidth Hsenders Hsystem Hinitial Hcreation Hcheck Hrun)
as [Hoverflow|Hfee]; [contradiction|exact Hfee].
Qed.
End Execution.
Print Assumptions consensus_only_fee_validation_error.