https://gitlab.com/nomadic-labs/mi-cho-coq
Raw File
Tip revision: cfc357cb84eaf248a44b324d7efc9de856b25d42 authored by Raphaƫl Cauderlier on 18 March 2021, 11:08:58 UTC
Use the fuel-free WP in Dexter proofs
Tip revision: cfc357c
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. *)


(* Coq *)
Require Import Coq.micromega.Lia.

(* Mi-Cho-Coq *)
Require Import Michocoq.macros.
Import syntax.
Import comparable.
Require Import util.
Import error.

(* Contracts Coq *)
Require Import contract_semantics.

(* Dexter *)
Require dexter_definition.
Require dexter_spec.

Require Import dexter_verification_ep_xtzToToken.
Require Import dexter_verification_ep_addLiquidity.
Require Import dexter_verification_ep_removeLiquidity.
Require Import dexter_verification_ep_xtzToToken.
Require Import dexter_verification_ep_tokenToXtz.
Require Import dexter_verification_ep_tokenToToken.
Require Import dexter_verification_ep_updateTokenPool.
Require Import dexter_verification_ep_updateTokenPoolInternal.
Require Import dexter_verification_ep_setBaker.
Require Import dexter_verification_ep_setManager.
Require Import dexter_verification_ep_setLqtAddress.
Require Import dexter_verification_ep_default.

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) :
  11 <= fuel ->
  eval_seq env dexter_definition.main2 fuel ((p, sto), tt) = Return ((ret_ops, ret_sto), tt) <->
  dexter_spec.main env p sto ret_ops ret_sto.
Proof.
  (* Case distinction on parameter p, and then apply lemmas from
    section entrypoints. *)

  intro Hfuel.
  rewrite return_precond.
  rewrite eval0_seq_precond_enough; [|vm_compute; exact Hfuel].

  unfold dexter_definition.main2.
  remember dexter_definition.ep_addLiquidity as ep_addLiquidity.
  remember dexter_definition.ep_default as ep_default.
  remember dexter_definition.ep_removeLiquidity as ep_removeLiquidity.
  remember dexter_definition.ep_setBaker as ep_setBaker.
  remember dexter_definition.ep_setLqtAddress as ep_setLqtAddress.
  remember dexter_definition.ep_setManager as ep_setManager.
  remember dexter_definition.ep_tokenToToken as ep_tokenToToken.
  remember dexter_definition.ep_tokenToXtz as ep_tokenToXtz.
  remember dexter_definition.ep_updateTokenPool as ep_updateTokenPool.
  remember dexter_definition.ep_updateTokenPoolInternal as ep_updateTokenPoolInternal.
  remember dexter_definition.ep_xtzToToken as ep_xtzToToken.
  simpl.
  destruct p as
      [ [ [ [ p_addLiquidity | p_default ] | [p_removeLiquidity | p_setBaker] ]
        | [ [ p_setLqtAddress | p_setManager ] | [p_tokenToToken | p_tokenToXtz] ] ]
      | [ [ p_updateTokenPool | p_updateTokenPoolInternal ] | p_xtzToToken ]
      ]; simpl; subst; repeat rewrite fold_eval_precond; try rewrite fold_eval_seq_precond_aux.
  - apply ep_addLiquidity_correct.
  - apply ep_default_correct.
  - apply ep_removeLiquidity_correct.
  - apply ep_setBaker_correct.
  - apply ep_setLqtAddress_correct.
  - apply ep_setManager_correct.
  - apply ep_tokenToToken_correct.
  - apply ep_tokenToXtz_correct.
  - apply ep_updateTokenPool_correct.
  - apply ep_updateTokenPoolInternal_correct.
  - apply ep_xtzToToken_correct.
Qed.
back to top