Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coq: Add vec #154

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
08c220e
Empty Coq setup
nomeata Nov 30, 2020
fcaeaa1
Formalize IDL-Soundness
nomeata Nov 30, 2020
f2a1868
Try to add CI
nomeata Nov 30, 2020
29e29d5
State assumptions of soundness proof
nomeata Dec 1, 2020
e963b0b
Outline some of the proof
nomeata Dec 1, 2020
f1dd58f
Finish IDL-Soundess proof
nomeata Dec 3, 2020
88551a3
Small cleanup
nomeata Dec 3, 2020
b5ca271
Coq: MiniCandid
nomeata Dec 3, 2020
0f7a326
Show that is_not_opt_like_type t <-> ~ (NullT <: t)
nomeata Dec 3, 2020
ab7f474
Merge branch 'master' of github.com:dfinity/candid into joachim/coq-c…
nomeata Dec 4, 2020
40f45ab
Play around with named cases
nomeata Dec 4, 2020
d1d72b1
Add VoidT
nomeata Dec 4, 2020
091c951
Add ReservedT
nomeata Dec 4, 2020
614b112
Make named_constructor more strict
nomeata Dec 4, 2020
f50f0de
Simplify
nomeata Dec 4, 2020
ebd6081
Prettier case names
nomeata Dec 4, 2020
1ee3044
A little bit of cleanup
nomeata Dec 5, 2020
5ffd78d
Use NamedCases in IDLSoundness
nomeata Dec 5, 2020
db700e2
Towards the opportunistic subtyping
nomeata Dec 9, 2020
e8f24ee
Conclude the proof for opportunistic decoding
nomeata Dec 10, 2020
9c8d3fd
Move NamedCasesDemo into own file
nomeata Dec 11, 2020
72cb55c
Wrap up the proofs
nomeata Dec 11, 2020
458551d
Introduce does-not-coerce relation
nomeata Dec 11, 2020
d9ce594
Merge branch 'master' into joachim/coq-candid
nomeata Dec 11, 2020
2d9af91
Use does-not-coerce relation more
nomeata Dec 11, 2020
13595fd
Simpler, faster tactics
nomeata Dec 11, 2020
419a7a5
Coq: Add vec
nomeata Dec 20, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 44 additions & 19 deletions coq/IDLSoundness.v
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ Require Import Coq.Relations.Relation_Operators.
Require Import Coq.Relations.Relation_Definitions.
Require Import Coq.Relations.Operators_Properties.

Require Import candid.NamedCases.

Set Bullet Behavior "Strict Subproofs".

Section IDL.
Expand All @@ -41,8 +43,8 @@ Section IDL.
Variable evolves : S -> S -> Prop.
Notation "s1 ~> s2" := (evolves s1 s2) (at level 70, no associativity).

Variable hostSubtyping : S -> S -> Prop.
Notation "s1 <<: s2" := (hostSubtyping s1 s2) (at level 70, no associativity).
Variable hostSubtypeOf : S -> S -> Prop.
Notation "s1 <<: s2" := (hostSubtypeOf s1 s2) (at level 70, no associativity).

(* Service Identifiers *)
Variable I : Set.
Expand All @@ -60,36 +62,45 @@ Section IDL.
(forall i' s, ~ In st (HasRef i' i s)).

Inductive CanSend : State -> I -> T -> T -> I -> Prop :=
| CanCall: forall st A B t1 t1' t2 t2',
| CanCall:
case canCall,
forall st A B t1 t1' t2 t2',
In st (HasRef A B (t1 --> t1')) ->
In st (HasType B (t2 --> t2')) ->
CanSend st A t1 t2 B
| CanReply: forall st A B t1 t1' t2 t2',
| CanReply:
case canReply,
forall st A B t1 t1' t2 t2',
In st (HasRef B A (t1 --> t1')) ->
In st (HasType A (t2 --> t2')) ->
CanSend st A t2' t1' B.

Inductive step : State -> State -> Prop :=
| NewService :
case newService,
forall (i : I) (s : S) st,
FreshIn i st ->
step st (Add st (HasType i s))
| EvolveService :
case evolveService,
forall (i : I) (s1 s2 : S) st,
~ In st (HasType i s1) ->
s1 ~> s2 ->
step (Add st (HasType i s1)) (Add st (HasType i s2))
| LearnService :
case learnService,
forall (i1 i2 : I) (s: S) st,
In st (HasType i1 s) ->
step st (Add st (HasRef i2 i1 s))
| TransmitService :
case transmitService,
forall (A B C : I) (s1 s2 : S) (t1 t2 : T) st,
In st (HasRef A C s1) ->
CanSend st A t1 t2 B ->
(s1 ∈ t1 <: s2 ∈ t2) ->
step st (Add st (HasRef B C s2))
| HostSubtyping :
case hostSubtyping,
forall (A B : I) (s1 s2 : S) st,
s1 <<: s2 ->
step (Add st (HasRef A B s1)) (Add st (HasRef A B s2))
Expand Down Expand Up @@ -160,11 +171,15 @@ Section IDL.
Proof.
intros st Hinvariant.
intros A t1 t2 B HCanSend.
destruct HCanSend.
* pose proof (Hinvariant B A (t2 --> t2') (t1 --> t1') H0 H) as H1.
destruct HCanSend; name_cases.
[canCall]: {
pose proof (Hinvariant B A (t2 --> t2') (t1 --> t1') H0 H) as H1.
apply H1.
* pose proof (Hinvariant A B (t2 --> t2') (t1 --> t1') H0 H) as H1.
}
[canReply]: {
pose proof (Hinvariant A B (t2 --> t2') (t1 --> t1') H0 H) as H1.
apply H1.
}
Qed.

Lemma invariant_Add_HasType:
Expand Down Expand Up @@ -290,8 +305,8 @@ Section IDL.
forall st1 st2, step st1 st2 -> unique st1 -> unique st2.
Proof.
intros st1 st2 Hstep Huniq.
induction Hstep.
* (* NewService *)
induction Hstep; name_cases.
[newService]: {
intros A' s1' s2' HType1 HType2.
inversion HType1; subst; clear HType1;
inversion HType2; subst; clear HType2.
Expand All @@ -303,7 +318,8 @@ Section IDL.
- inversion H1; subst; clear H1;
inversion H0; subst; clear H0.
reflexivity.
* (* EvolveService *)
}
[evolveService]: {
intros A' s1' s2' HType1 HType2.
inversion HType1; subst; clear HType1;
inversion HType2; subst; clear HType2.
Expand All @@ -325,43 +341,50 @@ Section IDL.
- inversion H1; subst; clear H1;
inversion H2; subst; clear H0.
reflexivity.
* (* LearnService *)
}
[learnService]: {
rewrite unique_Add_HasRef in *.
assumption.
* (* TransmitService *)
}
[transmitService]: {
rewrite unique_Add_HasRef in *.
assumption.
* (* HostSubtyping *)
}
[hostSubtyping]: {
rewrite unique_Add_HasRef in *.
assumption.
}
Qed.

Lemma step_preserves_invariant:
forall st1 st2, step st1 st2 -> unique st1 -> invariant st1 -> invariant st2.
Proof.
intros st1 st2 Hstep Huniq Hinv.
induction Hstep.
* (* NewService *)
induction Hstep; name_cases.
[newService]: {
apply invariant_Add_HasType.
- apply Hinv.
- intros B s2 HB.
eapply H in HB.
inversion HB.
* (* EvolveService *)
}
[evolveService]: {
eapply invariant_Change_HasType.
- apply Hinv.
- intros B s3 HB Hsub.
apply evolves_correctly in H0.
eapply service_subtype_trans; eassumption.
* (* LearnService *)
}
[learnService]: {
apply invariant_Add_HasRef.
- apply Hinv.
- intros s2 HHasType.
(* Uniqueness of HasType, reflexivity *)
replace s2 with s.
+ apply service_subtype_refl.
+ eapply Huniq; eassumption.
* (* TransmitService *)
}
[transmitService]: {
apply invariant_Add_HasRef.
- apply Hinv.
- intros s3 HC.
Expand All @@ -370,12 +393,14 @@ Section IDL.
assert (t1 <: t2) by (eapply HSound; apply H0).
assert (s1 <:: s2) by (eapply compositional; eassumption).
eapply service_subtype_trans; eassumption.
* (* HostSubtyping *)
}
[hostSubtyping]: {
eapply invariant_Change_HasRef.
- apply Hinv.
- intros s3 HB Hsub.
apply host_subtyping_sound in H.
eapply service_subtype_trans; eassumption.
}
Qed.

Lemma canonical_soundness: IDLSound.
Expand Down
Loading