https://gitlab.com/nomadic-labs/mi-cho-coq
Raw File
Tip revision: 08edb74856d05a9ecdbc5dc5e40903aee308bd1b authored by Arvid Jakobsson on 28 September 2020, 21:46:43 UTC
[dexter] update proof for exchange entrypoints
Tip revision: 08edb74
dexter_verification_main.v
(* Open Source License *)
(* Copyright (c) 2020 Nomadic Labs. <contact@nomadic-labs.com> *)

(* Permission is hereby granted, free of charge, to any person obtaining a *)
(* copy of this software and associated documentation files (the "Software"), *)
(* to deal in the Software without restriction, including without limitation *)
(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *)
(* and/or sell copies of the Software, and to permit persons to whom the *)
(* Software is furnished to do so, subject to the following conditions: *)

(* The above copyright notice and this permission notice shall be included *)
(* in all copies or substantial portions of the Software. *)

(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *)
(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *)
(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *)
(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *)
(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *)
(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *)
(* DEALINGS IN THE SOFTWARE. *)


Require Import String.
Require Import NArith.
Require Import ZArith.
Require List.
Require Import Coq.micromega.Lia.

Require Import Michocoq.macros.
Import syntax.
Import comparable.
Require Import semantics.
Require Import util.
Import error.

Require dexter_definition.
Require dexter_spec.
Require dexter_verification.

Module Dexter_verification_main (C : ContractContext).

  Module Ep_verif := dexter_verification.Dexter_verification C.
  Import Ep_verif.
  Import Ep_verif.Spec.semantics.


  Lemma main_correct
        (env : @proto_env (Some (dexter_definition.parameter_ty, None)))
        (p : data dexter_definition.parameter_ty)
        (sto : data dexter_definition.storage_ty)
        (ret_ops : Datatypes.list (data operation))
        (ret_sto : data dexter_definition.storage_ty)
        (fuel : Datatypes.nat) :
    (* TODO: fuel may have to be adapted to suit the entrypoint *)
    500 <= fuel ->
    eval env Def.main2 fuel ((p, sto), tt) = Return ((ret_ops, ret_sto), tt) <->
    Spec.main env p sto ret_ops ret_sto.
  Proof.
    (* Case distinction on parameter p, and then apply lemmas from
    section entrypoints. *)

    unfold ">=".
    intros Hfuel.
    rewrite return_precond.
    rewrite eval_precond_correct.

    destruct p as
        [ [ [ | ] | [ | ]] |
          [ [ | ] | [ | ]] ];
      do 4 (more_fuel; simpl).

    - apply ep_approve_correct; lia.
    - apply ep_addLiquidity_correct; lia.
    - apply ep_removeLiquidity_correct; lia.
    - destruct d as [ | ]; do 1 (more_fuel; simpl).
       + apply ep_xtzToToken_correct; lia.
       + apply ep_tokenToXtz_correct; lia.
    - apply ep_tokenToToken_correct; lia.
    - destruct d as [ | ]; do 1 (more_fuel; simpl).
      + apply ep_updateTokenPool_correct; lia.
      + apply ep_updateTokenPoolInternal_correct; lia.
    - apply ep_setBaker_correct; lia.
    - destruct d as [ | ];  do 1 (more_fuel; simpl).
      + apply ep_setManager_correct; lia.
      + apply ep_default_correct; lia.
  Qed.
End Dexter_verification_main.
back to top