https://gitlab.com/nomadic-labs/mi-cho-coq
Tip revision: 303c8f22d072c93669d255aea03bc1575eb17a8d authored by Arvid Jakobsson on 15 May 2020, 13:49:00 UTC
[dexter] boilerplate to verify main
[dexter] boilerplate to verify main
Tip revision: 303c8f2
dexter_verification.v
(* Open Source License *)
(* Copyright (c) 2019 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 Michocoq.macros.
Import syntax.
Import comparable.
Require Import NArith.
Require Import semantics.
Require Import util.
Import error.
Require List.
Require Import Coq.micromega.Lia.
Require dexter_definition.
Require dexter_spec.
Module Dexter_verification (C : ContractContext).
Module Def := dexter_definition.Dexter_definition C.
Module Spec := dexter_spec.Dexter_spec C.
Module semantics := Semantics C. Import semantics.
Section entrypoints.
Variable (env : @proto_env dexter_definition.self_info).
Lemma ep_addLiquidity_correct
(p : data dexter_definition.parameter_ep_addLiquidity_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 *)
400 <= fuel ->
eval_precond fuel env Def.ep_addLiquidity
(fun x => x = (ret_ops, ret_sto, tt))
(p, (sto, tt)) <->
Spec.ep_addLiquidity p sto ret_ops ret_sto.
Proof.
(* TODO: add proof *)
Admitted.
Lemma ep_approve_correct
(p : data dexter_definition.parameter_ep_approve_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 *)
400 <= fuel ->
eval_precond fuel env Def.ep_approve
(fun x => x = (ret_ops, ret_sto, tt))
(p, (sto, tt)) <->
Spec.ep_approve p sto ret_ops ret_sto.
Proof.
(* TODO: add proof *)
Admitted.
Lemma ep_default_correct
(p : data dexter_definition.parameter_ep_default_ty)
(sto : data dexter_definition.storage_ty)
(ret_ops : Datatypes.list (data operation))
(ret_sto : data dexter_definition.storage_ty)
(fuel : Datatypes.nat) :
400 <= fuel ->
eval_precond fuel env Def.ep_default
(fun x => x = (ret_ops, ret_sto, tt))
(p, (sto, tt)) <->
Spec.ep_default p sto ret_ops ret_sto.
Proof.
intro Hfuel.
do 5 more_fuel; simpl.
unfold Spec.ep_default.
intuition congruence.
Qed.
Lemma ep_removeLiquidity_correct
(p : data dexter_definition.parameter_ep_removeLiquidity_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 *)
400 <= fuel ->
eval_precond fuel env Def.ep_removeLiquidity
(fun x => x = (ret_ops, ret_sto, tt))
(p, (sto, tt)) <->
Spec.ep_removeLiquidity p sto ret_ops ret_sto.
Proof.
(* TODO: add proof *)
Admitted.
Lemma ep_setBaker_correct
(p : data dexter_definition.parameter_ep_setBaker_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 *)
400 <= fuel ->
eval_precond fuel env Def.ep_setBaker
(fun x => x = (ret_ops, ret_sto, tt))
(p, (sto, tt)) <->
Spec.ep_setBaker p sto ret_ops ret_sto.
Proof.
(* TODO: add proof *)
Admitted.
Lemma ep_updateTokenPool_correct
(p : data dexter_definition.parameter_ep_updateTokenPool_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 *)
400 <= fuel ->
eval_precond fuel env Def.ep_updateTokenPool
(fun x => x = (ret_ops, ret_sto, tt))
(p, (sto, tt)) <->
Spec.ep_updateTokenPool p sto ret_ops ret_sto.
Proof.
(* TODO: add proof *)
Admitted.
Lemma ep_tokenToXtz_correct
(p : data dexter_definition.parameter_ep_tokenToXtz_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 *)
400 <= fuel ->
eval_precond fuel env Def.ep_tokenToXtz
(fun x => x = (ret_ops, ret_sto, tt))
(p, (sto, tt)) <->
Spec.ep_tokenToXtz p sto ret_ops ret_sto.
Proof.
(* TODO: add proof *)
Admitted.
Lemma ep_xtzToToken_correct
(p : data dexter_definition.parameter_ep_xtzToToken_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 *)
400 <= fuel ->
eval_precond fuel env Def.ep_xtzToToken
(fun x => x = (ret_ops, ret_sto, tt))
(p, (sto, tt)) <->
Spec.ep_xtzToToken p sto ret_ops ret_sto.
Proof.
(* TODO: add proof *)
Admitted.
End entrypoints.
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.main fuel ((p, sto), tt) = Return ((ret_ops, ret_sto), tt) <->
Spec.main 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
[ [ [ | ] | [ | ]] |
[ [ | ] | [ | ]] ];
simpl Spec.main;
unfold Def.main;
do 7 more_fuel; simpl.
- apply ep_approve_correct; lia.
- apply ep_addLiquidity_correct; lia.
- apply ep_removeLiquidity_correct; lia.
- apply ep_xtzToToken_correct; lia.
- apply ep_tokenToXtz_correct; lia.
- apply ep_updateTokenPool_correct; lia.
- apply ep_setBaker_correct; lia.
- apply ep_default_correct; lia.
Qed.
End Dexter_verification.