Library QedkConcrete.reservechecktests

Excessive-fee rejection in every executable revision

These examples evaluate the generated execution reserve check, not a replacement predicate. They are checkpoint tests, not full transactions. The sender has 20 MON before execution, no code or configured reserve, and therefore a protected amount of 10 MON. The fee and balances below are in MON. Emptying is controlled by the actual activity counter.
From Stdlib Require Import List String NArith ZArith.
Require Import QedkConcrete.reservecheck.
Import ListNotations.
Set Default Goal Selector "!".

Definition feeTestSender : Addr.t := String.String (Ascii.ascii_of_nat 32)
  (Lists.List.fold_right String.String String.EmptyString
    (List.repeat (Ascii.ascii_of_nat 0) 19)).

Definition feeTestWorld (balance : Z) (emptying : bool) : W.t :=
  {| W.t.history := [];
     W.t.accounts := [(feeTestSender, A.t.with_balance (balance × 10^18)%Z A.empty)];
     W.t.next_emptying_transaction_block :=
       [(feeTestSender, if emptying then 0%N else 100%N)] |}.

fee: maximum gas charge; balance: balance at the reserve checkpoint; emptying: whether the sender may use the emptying exception at block 0. No other accounts, code changes or selfdestructions are present.
Definition feeTestState (fee : N) (balance : Z) (emptying : bool) : S.t :=
  S.t.with_initial_world_state (feeTestWorld 20 emptying)
    (S.t.with_world_state (feeTestWorld balance emptying)
      (S.t.with_tx_origin feeTestSender
        (S.t.with_tx_gas_limit fee (S.t.with_tx_gas_price (10^18)%N S.empty)))).

Section Revisions.
Variable revision : Support.Variants.Revision.t.
Hypothesis executable_revision : List.In revision
  [Support.Variants.Revision.Eight; Support.Variants.Revision.Nine;
   Support.Variants.Revision.Eleven].

Example excessive_fee_rejects_even_with_surplus :
  fst (Reserve_balance.dipped_into_reserve revision (feeTestState 11 20 false)) = true.
Proof.
  destruct executable_revision as [<-|[<-|[<-|[]]]]; vm_compute; reflexivity.
Qed.

Example excessive_fee_allows_emptying :
  fst (Reserve_balance.dipped_into_reserve revision (feeTestState 11 0 true)) = false.
Proof.
  destruct executable_revision as [<-|[<-|[<-|[]]]]; vm_compute; reflexivity.
Qed.

Example fee_equal_to_reserve_allows_zero_balance :
  fst (Reserve_balance.dipped_into_reserve revision (feeTestState 10 0 false)) = false.
Proof.
  destruct executable_revision as [<-|[<-|[<-|[]]]]; vm_compute; reflexivity.
Qed.

Example insufficient_remaining_balance_rejects :
  fst (Reserve_balance.dipped_into_reserve revision (feeTestState 9 0 false)) = true.
Proof.
  destruct executable_revision as [<-|[<-|[<-|[]]]]; vm_compute; reflexivity.
Qed.

Example exact_remaining_balance_passes :
  fst (Reserve_balance.dipped_into_reserve revision (feeTestState 9 1 false)) = false.
Proof.
  destruct executable_revision as [<-|[<-|[<-|[]]]]; vm_compute; reflexivity.
Qed.

Example fee_outside_u256_rejects_without_wrapping :
  fst (Reserve_balance.dipped_into_reserve revision
    (S.t.with_tx_gas_price 1%N (feeTestState (2^256)%N 20 false))) = true.
Proof.
  destruct executable_revision as [<-|[<-|[<-|[]]]]; vm_compute; reflexivity.
Qed.
End Revisions.