Library SetcodeConcrete.rules
Local MIP-19 rules in the generated implementation
From Stdlib Require Import ZArith Bool Lia.
Require Import MonadVM.Setcode_rules.
Local Open Scope Z_scope.
Set Default Goal Selector "!".
Module U := Numeric.U64.
Module A := Chain.Ethereum.Account.
Lemma u64_eq (a b : U.t) : U.op_eq a b = Z.eqb a b.
Proof.
change (Z.eqb (match Z.compare a b with Eq ⇒ 0 | Lt ⇒ -1 | Gt ⇒ 1 end) 0 = Z.eqb a b).
destruct (Z.compare_spec a b) as [-> | H | H]; cbn;
[symmetry; apply Z.eqb_refl | symmetry; apply Z.eqb_neq; lia | symmetry; apply Z.eqb_neq; lia].
Qed.
Lemma u64_max (a b : U.t) : U.max a b = Z.max a b.
Proof.
change ((if Z.ltb (match Z.compare a b with Eq ⇒ 0 | Lt ⇒ -1 | Gt ⇒ 1 end) 0
then b else a) = Z.max a b).
destruct (Z.compare_spec a b); cbn;
[subst; symmetry; apply Z.max_id | symmetry; apply Z.max_r; lia | symmetry; apply Z.max_l; lia].
Qed.
Lemma u64_increment (a : U.t) :
0 ≤ a < 2^64-1 → U.op_plus a U.one = a+1.
Proof.
intro Hrange.
change (Z.land (Z.shiftl (a+1) 0) (Z.ones 64) = a+1).
rewrite Z.shiftl_0_r, Z.land_ones by lia.
apply Z.mod_small. lia.
Qed.
Theorem migrated_nonce (actual proposed : U.t) :
0 ≤ actual < 2^64-1 → 0 ≤ proposed < 2^64-1 →
Setcode_rules.next_sender_nonce true actual proposed =
Some (Z.max actual proposed + 1).
Proof.
intros Ha Hp. unfold Setcode_rules.next_sender_nonce.
rewrite !u64_eq. change U.max_t with (2^64-1).
assert (Ea : Z.eqb actual (2^64-1) = false) by (apply Z.eqb_neq; lia).
assert (Ep : Z.eqb proposed (2^64-1) = false) by (apply Z.eqb_neq; lia).
rewrite Ea, Ep. cbn [orb]. unfold Setcode_rules.advance_sender_nonce.
rewrite u64_max, u64_increment; [reflexivity|lia].
Qed.
Corollary migrated_nonce_strictly_increases actual proposed next :
0 ≤ actual < 2^64-1 → 0 ≤ proposed < 2^64-1 →
Setcode_rules.next_sender_nonce true actual proposed = Some next →
actual < next ∧ proposed < next ∧ next < 2^64.
Proof.
intros Ha Hp Hnext. rewrite migrated_nonce in Hnext by assumption.
injection Hnext as <-. lia.
Qed.
Theorem maximum_nonce_rejected proposed :
Setcode_rules.next_sender_nonce true U.max_t proposed = None.
Proof.
unfold Setcode_rules.next_sender_nonce. rewrite u64_eq, Z.eqb_refl. reflexivity.
Qed.
Theorem fresh_admission_rejects_regular_code account :
A.is_smart_contract account = true → Setcode_rules.sender_admissible account = false.
Proof. intro Hcode. unfold Setcode_rules.sender_admissible. rewrite Hcode. reflexivity. Qed.
Theorem regular_sender_is_not_exempt recent :
Setcode_rules.contract_exempt true true recent = false.
Proof. reflexivity. Qed.
Theorem recent_regular_sender_is_not_exempt sender :
Setcode_rules.contract_exempt true sender true = false.
Proof. destruct sender; reflexivity. Qed.
Theorem regular_account_exempt_after_sender_window :
Setcode_rules.contract_exempt true false false = true.
Proof. reflexivity. Qed.
Theorem relayed_delegated_adoption_requires_zero reserve :
Setcode_rules.adoption_allowed true false reserve = true ↔ reserve = 0.
Proof.
change (Z.eqb (match Z.compare reserve 0 with Eq ⇒ 0 | Lt ⇒ -1 | Gt ⇒ 1 end) 0 = true ↔ reserve = 0).
destruct (Z.compare_spec reserve 0) as [Heq | Hlt | Hgt]; cbn;
split; intro H; try assumption; try reflexivity; try discriminate; lia.
Qed.
Theorem self_sent_adoption_allowed reserve :
Setcode_rules.adoption_allowed true true reserve = true.
Proof. reflexivity. Qed.
Print Assumptions migrated_nonce.
Print Assumptions relayed_delegated_adoption_requires_zero.
Require Import MonadVM.Setcode_rules.
Local Open Scope Z_scope.
Set Default Goal Selector "!".
Module U := Numeric.U64.
Module A := Chain.Ethereum.Account.
Lemma u64_eq (a b : U.t) : U.op_eq a b = Z.eqb a b.
Proof.
change (Z.eqb (match Z.compare a b with Eq ⇒ 0 | Lt ⇒ -1 | Gt ⇒ 1 end) 0 = Z.eqb a b).
destruct (Z.compare_spec a b) as [-> | H | H]; cbn;
[symmetry; apply Z.eqb_refl | symmetry; apply Z.eqb_neq; lia | symmetry; apply Z.eqb_neq; lia].
Qed.
Lemma u64_max (a b : U.t) : U.max a b = Z.max a b.
Proof.
change ((if Z.ltb (match Z.compare a b with Eq ⇒ 0 | Lt ⇒ -1 | Gt ⇒ 1 end) 0
then b else a) = Z.max a b).
destruct (Z.compare_spec a b); cbn;
[subst; symmetry; apply Z.max_id | symmetry; apply Z.max_r; lia | symmetry; apply Z.max_l; lia].
Qed.
Lemma u64_increment (a : U.t) :
0 ≤ a < 2^64-1 → U.op_plus a U.one = a+1.
Proof.
intro Hrange.
change (Z.land (Z.shiftl (a+1) 0) (Z.ones 64) = a+1).
rewrite Z.shiftl_0_r, Z.land_ones by lia.
apply Z.mod_small. lia.
Qed.
Theorem migrated_nonce (actual proposed : U.t) :
0 ≤ actual < 2^64-1 → 0 ≤ proposed < 2^64-1 →
Setcode_rules.next_sender_nonce true actual proposed =
Some (Z.max actual proposed + 1).
Proof.
intros Ha Hp. unfold Setcode_rules.next_sender_nonce.
rewrite !u64_eq. change U.max_t with (2^64-1).
assert (Ea : Z.eqb actual (2^64-1) = false) by (apply Z.eqb_neq; lia).
assert (Ep : Z.eqb proposed (2^64-1) = false) by (apply Z.eqb_neq; lia).
rewrite Ea, Ep. cbn [orb]. unfold Setcode_rules.advance_sender_nonce.
rewrite u64_max, u64_increment; [reflexivity|lia].
Qed.
Corollary migrated_nonce_strictly_increases actual proposed next :
0 ≤ actual < 2^64-1 → 0 ≤ proposed < 2^64-1 →
Setcode_rules.next_sender_nonce true actual proposed = Some next →
actual < next ∧ proposed < next ∧ next < 2^64.
Proof.
intros Ha Hp Hnext. rewrite migrated_nonce in Hnext by assumption.
injection Hnext as <-. lia.
Qed.
Theorem maximum_nonce_rejected proposed :
Setcode_rules.next_sender_nonce true U.max_t proposed = None.
Proof.
unfold Setcode_rules.next_sender_nonce. rewrite u64_eq, Z.eqb_refl. reflexivity.
Qed.
Theorem fresh_admission_rejects_regular_code account :
A.is_smart_contract account = true → Setcode_rules.sender_admissible account = false.
Proof. intro Hcode. unfold Setcode_rules.sender_admissible. rewrite Hcode. reflexivity. Qed.
Theorem regular_sender_is_not_exempt recent :
Setcode_rules.contract_exempt true true recent = false.
Proof. reflexivity. Qed.
Theorem recent_regular_sender_is_not_exempt sender :
Setcode_rules.contract_exempt true sender true = false.
Proof. destruct sender; reflexivity. Qed.
Theorem regular_account_exempt_after_sender_window :
Setcode_rules.contract_exempt true false false = true.
Proof. reflexivity. Qed.
Theorem relayed_delegated_adoption_requires_zero reserve :
Setcode_rules.adoption_allowed true false reserve = true ↔ reserve = 0.
Proof.
change (Z.eqb (match Z.compare reserve 0 with Eq ⇒ 0 | Lt ⇒ -1 | Gt ⇒ 1 end) 0 = true ↔ reserve = 0).
destruct (Z.compare_spec reserve 0) as [Heq | Hlt | Hgt]; cbn;
split; intro H; try assumption; try reflexivity; try discriminate; lia.
Qed.
Theorem self_sent_adoption_allowed reserve :
Setcode_rules.adoption_allowed true true reserve = true.
Proof. reflexivity. Qed.
Print Assumptions migrated_nonce.
Print Assumptions relayed_delegated_adoption_requires_zero.