Library QedkConcrete.consensusbudgetrefinement

The arithmetic check is the existing QEDK consensus check

This equality prevents the concrete-execution port from silently proving a different, more restrictive budget algorithm. The abstract model has a separate storage-fee allowance; the concrete executor charges storage through gas, so that allowance is zero for its transaction projection.
From Stdlib Require Import ZArith Lia.
Require Import monadpure.reservebaldelayed monadpure.reservebaldelayed_qedk.
Require Import QedkConcrete.consensusbudget.
From stdpp Require Import decidable tactics.
Require Import QedkConcrete.consensusdecisions.
Set Default Goal Selector "!".

Theorem check_sender_budget_refines_qedk K snapshot previousBudget previous tx :
  checkSenderBudget (isAllowedToEmpty K snapshot previous tx)
    (Z.of_N (balanceOfAc (fst snapshot) (sender tx)))
    (Z.of_N (delayedReserveBalOfAddr K (snd snapshot) (sender tx) (txBlockNum tx)))
    previousBudget (Z.of_N (maxTxFee tx))
    (Z.of_N (value tx) + Z.of_N (maxStorageFee tx)) =
  reservebaldelayed_qedk.senderBudget K snapshot previousBudget previous tx.
Proof.
  unfold checkSenderBudget. rewrite !bool_decide_Z_le.
  unfold reservebaldelayed_qedk.senderBudget.
  destruct (isAllowedToEmpty K snapshot previous tx).
  - case_bool_decide as Hfee.
    + assert (Hle : Z.leb (Z.of_N (maxTxFee tx))
        (Z.of_N (balanceOfAc (fst snapshot) (sender tx))) = true)
        by (apply Z.leb_le; lia).
      rewrite Hle.
      replace (Z.of_N (balanceOfAc (fst snapshot) (sender tx)) -
        Z.of_N (maxTxFee tx) - (Z.of_N (value tx) + Z.of_N (maxStorageFee tx)))%Z
        with (Z.of_N (balanceOfAc (fst snapshot) (sender tx)) -
          Z.of_N (maxTxFee tx) - Z.of_N (value tx) - Z.of_N (maxStorageFee tx))%Z by lia.
      reflexivity.
    + assert (Hle : Z.leb (Z.of_N (maxTxFee tx))
        (Z.of_N (balanceOfAc (fst snapshot) (sender tx))) = false)
        by (apply Z.leb_gt; lia).
      rewrite Hle. reflexivity.
  - case_bool_decide as Hfee.
    + assert (Hle : Z.leb (Z.of_N (maxTxFee tx)) previousBudget = true)
        by (apply Z.leb_le; exact Hfee).
      rewrite Hle. reflexivity.
    + assert (Hle : Z.leb (Z.of_N (maxTxFee tx)) previousBudget = false)
        by (apply Z.leb_gt; lia).
      rewrite Hle. reflexivity.
Qed.