Library SetcodeConcrete.rechecking
Why the QEDK suffix conclusion cannot be copied unchanged
From Stdlib Require Import List Bool.
Require Import RocqOfOCaml.RocqOfOCaml.
Require Import SetcodeConcrete.consensuschecks QedkConcrete.transactionchecks.
Set Default Goal Selector "!".
Import ListNotations.
Section Checks.
Context {F : E.FArgs}.
Lemma transaction_checks_require_noncontract header tx expected contract :
transactionChecks header tx expected contract = true → contract = false.
Proof.
unfold transactionChecks. intro H.
repeat rewrite Bool.andb_true_iff in H.
destruct H as [[[[[[[[[_ _] _] _] _] _] _] Hcode] _] _].
now apply Bool.negb_true_iff in Hcode.
Qed.
Lemma checked_sender_not_contract snapshot header previous tx next sender :
T.sender E.Params.(Execution.Make_Params_signature.chain_id) tx = Some sender →
checkTransaction snapshot header previous tx = Some next →
A.is_smart_contract (accountAt snapshot sender) = false.
Proof.
intros Hsender Hcheck. unfold checkTransaction in Hcheck. rewrite Hsender in Hcheck.
destruct (Gas.tx_effective_gas_price _ tx); [|discriminate].
destruct (transactionChecks header tx _ _) eqn:Hvalid; [|discriminate].
exact (transaction_checks_require_noncontract _ _ _ _ Hvalid).
Qed.
Lemma checked_transactions_not_contract snapshot header previous txs next :
checkTransactions snapshot header previous txs = Some next →
∀ tx sender, In tx txs →
T.sender E.Params.(Execution.Make_Params_signature.chain_id) tx = Some sender →
A.is_smart_contract (accountAt snapshot sender) = false.
Proof.
revert previous. induction txs as [|first rest IH]; intros previous Hcheck tx sender Hin Hsender.
- contradiction.
- cbn [checkTransactions] in Hcheck.
destruct (checkTransaction snapshot header previous first) as [middle|] eqn:Hfirst; [|discriminate].
destruct Hin as [<-|Hin].
+ eapply checked_sender_not_contract; eassumption.
+ exact (IH middle Hcheck tx sender Hin Hsender).
Qed.
Lemma checked_blocks_not_contract snapshot previous blocks next :
checkBlocks snapshot previous blocks = Some next →
∀ block tx sender, In block blocks → In tx (Block.t.transactions block) →
T.sender E.Params.(Execution.Make_Params_signature.chain_id) tx = Some sender →
A.is_smart_contract (accountAt snapshot sender) = false.
Proof.
revert previous. induction blocks as [|first rest IH];
intros previous Hcheck block tx sender Hin Htx Hsender; [contradiction|].
cbn [checkBlocks] in Hcheck.
match type of Hcheck with context [checkTransactions ?s ?h ?p ?ts] ⇒
destruct (checkTransactions s h p ts) as [middle|] eqn:Hfirst end; [|discriminate].
destruct Hin as [<-|Hin].
- eapply checked_transactions_not_contract; eassumption.
- exact (IH middle Hcheck block tx sender Hin Htx Hsender).
Qed.
Require Import RocqOfOCaml.RocqOfOCaml.
Require Import SetcodeConcrete.consensuschecks QedkConcrete.transactionchecks.
Set Default Goal Selector "!".
Import ListNotations.
Section Checks.
Context {F : E.FArgs}.
Lemma transaction_checks_require_noncontract header tx expected contract :
transactionChecks header tx expected contract = true → contract = false.
Proof.
unfold transactionChecks. intro H.
repeat rewrite Bool.andb_true_iff in H.
destruct H as [[[[[[[[[_ _] _] _] _] _] _] Hcode] _] _].
now apply Bool.negb_true_iff in Hcode.
Qed.
Lemma checked_sender_not_contract snapshot header previous tx next sender :
T.sender E.Params.(Execution.Make_Params_signature.chain_id) tx = Some sender →
checkTransaction snapshot header previous tx = Some next →
A.is_smart_contract (accountAt snapshot sender) = false.
Proof.
intros Hsender Hcheck. unfold checkTransaction in Hcheck. rewrite Hsender in Hcheck.
destruct (Gas.tx_effective_gas_price _ tx); [|discriminate].
destruct (transactionChecks header tx _ _) eqn:Hvalid; [|discriminate].
exact (transaction_checks_require_noncontract _ _ _ _ Hvalid).
Qed.
Lemma checked_transactions_not_contract snapshot header previous txs next :
checkTransactions snapshot header previous txs = Some next →
∀ tx sender, In tx txs →
T.sender E.Params.(Execution.Make_Params_signature.chain_id) tx = Some sender →
A.is_smart_contract (accountAt snapshot sender) = false.
Proof.
revert previous. induction txs as [|first rest IH]; intros previous Hcheck tx sender Hin Hsender.
- contradiction.
- cbn [checkTransactions] in Hcheck.
destruct (checkTransaction snapshot header previous first) as [middle|] eqn:Hfirst; [|discriminate].
destruct Hin as [<-|Hin].
+ eapply checked_sender_not_contract; eassumption.
+ exact (IH middle Hcheck tx sender Hin Hsender).
Qed.
Lemma checked_blocks_not_contract snapshot previous blocks next :
checkBlocks snapshot previous blocks = Some next →
∀ block tx sender, In block blocks → In tx (Block.t.transactions block) →
T.sender E.Params.(Execution.Make_Params_signature.chain_id) tx = Some sender →
A.is_smart_contract (accountAt snapshot sender) = false.
Proof.
revert previous. induction blocks as [|first rest IH];
intros previous Hcheck block tx sender Hin Htx Hsender; [contradiction|].
cbn [checkBlocks] in Hcheck.
match type of Hcheck with context [checkTransactions ?s ?h ?p ?ts] ⇒
destruct (checkTransactions s h p ts) as [middle|] eqn:Hfirst end; [|discriminate].
destruct Hin as [<-|Hin].
- eapply checked_transactions_not_contract; eassumption.
- exact (IH middle Hcheck block tx sender Hin Htx Hsender).
Qed.
post is any proposed fresh snapshot. If rest contains a transaction
from sender, and that address has regular code in post, fresh
consensus rejects rest, regardless of balances, heights or gas budgets.
This does not say that previously admitted execution rejects it.
Theorem regular_sender_prevents_fresh_admission post height rest block tx sender :
In block rest → In tx (Block.t.transactions block) →
T.sender E.Params.(Execution.Make_Params_signature.chain_id) tx = Some sender →
A.is_smart_contract (accountAt post sender) = true →
¬ consensusAccepts post height rest.
Proof.
intros Hblock Htx Hsender Hregular [next Hcheck].
pose proof (checked_blocks_not_contract _ _ _ _ Hcheck block tx sender Hblock Htx Hsender).
congruence.
Qed.
End Checks.
Print Assumptions regular_sender_prevents_fresh_admission.
In block rest → In tx (Block.t.transactions block) →
T.sender E.Params.(Execution.Make_Params_signature.chain_id) tx = Some sender →
A.is_smart_contract (accountAt post sender) = true →
¬ consensusAccepts post height rest.
Proof.
intros Hblock Htx Hsender Hregular [next Hcheck].
pose proof (checked_blocks_not_contract _ _ _ _ Hcheck block tx sender Hblock Htx Hsender).
congruence.
Qed.
End Checks.
Print Assumptions regular_sender_prevents_fresh_admission.