Library QedkConcrete.accountnonces
Nonces through concrete account-map writes
From Stdlib Require Import String ZArith Bool.
Require Import RocqOfOCaml.RocqOfOCaml QedkConcrete.worldaccounts.
Set Default Goal Selector "!".
Local Open Scope Z_scope.
Section Accounts.
Context {U64 : Basics.Unreachable Numeric.U64.t} {UF : Basics.Unreachable Numeric.U256.t}.
Local Abbreviation readAccount := (fun world addr ⇒
State.op_pointcaretlparenrparen world (@W.account None addr)).
Lemma empty_account_nonce account :
@A.is_empty account = true → A.t.nonce account = 0%Z.
Proof.
unfold A.is_empty. intro Hempty.
apply Bool.andb_true_iff in Hempty as [_ Hempty].
apply Bool.andb_true_iff in Hempty as [Hnonce _].
change (Z.eqb (match Z.compare (A.t.nonce account) 0 with
Eq ⇒ 0 | Lt ⇒ -1 | Gt ⇒ 1 end) 0 = true) in Hnonce.
destruct (Z.compare_spec (A.t.nonce account) 0); cbn in Hnonce;
[assumption|discriminate|discriminate].
Qed.
Lemma nonce_after_account_write keep world addr value query :
stringmaps.WellFormed (W.t.accounts world) →
A.t.nonce (readAccount (State.op_pointcaretlparenrparenltminus world
(@W.account (Some keep) addr) value) query) =
if String.eqb addr query then A.t.nonce value else A.t.nonce (readAccount world query).
Proof.
intro Hmap. cbv beta. rewrite account_read_after_write by exact Hmap.
destruct (String.eqb addr query); [|reflexivity].
destruct keep; [reflexivity|].
destruct (@A.is_empty value) eqn:Hempty; [|reflexivity].
symmetry. exact (empty_account_nonce value Hempty).
Qed.
End Accounts.
Require Import RocqOfOCaml.RocqOfOCaml QedkConcrete.worldaccounts.
Set Default Goal Selector "!".
Local Open Scope Z_scope.
Section Accounts.
Context {U64 : Basics.Unreachable Numeric.U64.t} {UF : Basics.Unreachable Numeric.U256.t}.
Local Abbreviation readAccount := (fun world addr ⇒
State.op_pointcaretlparenrparen world (@W.account None addr)).
Lemma empty_account_nonce account :
@A.is_empty account = true → A.t.nonce account = 0%Z.
Proof.
unfold A.is_empty. intro Hempty.
apply Bool.andb_true_iff in Hempty as [_ Hempty].
apply Bool.andb_true_iff in Hempty as [Hnonce _].
change (Z.eqb (match Z.compare (A.t.nonce account) 0 with
Eq ⇒ 0 | Lt ⇒ -1 | Gt ⇒ 1 end) 0 = true) in Hnonce.
destruct (Z.compare_spec (A.t.nonce account) 0); cbn in Hnonce;
[assumption|discriminate|discriminate].
Qed.
Lemma nonce_after_account_write keep world addr value query :
stringmaps.WellFormed (W.t.accounts world) →
A.t.nonce (readAccount (State.op_pointcaretlparenrparenltminus world
(@W.account (Some keep) addr) value) query) =
if String.eqb addr query then A.t.nonce value else A.t.nonce (readAccount world query).
Proof.
intro Hmap. cbv beta. rewrite account_read_after_write by exact Hmap.
destruct (String.eqb addr query); [|reflexivity].
destruct keep; [reflexivity|].
destruct (@A.is_empty value) eqn:Hempty; [|reflexivity].
symmetry. exact (empty_account_nonce value Hempty).
Qed.
End Accounts.