Skip to content

Commit 6e59c75

Browse files
authored
SCP-2515 CEK => CK (IntersectMBO#3949)
This PR adds the high level proof of that a CEK execution corresponds to a CK execution. I have postulated several syntactic lemmas related to whether you discharge CEK values or convert them to CK values and then discharge them, and when you perform syntactic operations such as substitution. I have also postulated that the CEK and CK builtin machinery behaves the same.
1 parent b43f14e commit 6e59c75

File tree

2 files changed

+77
-11
lines changed

2 files changed

+77
-11
lines changed

plutus-metatheory/src/Algorithmic/CEKV.lagda.md

Lines changed: 74 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,12 @@ convBApp b p p' q rewrite unique<>> p p' = q
209209
210210
BUILTIN' : ∀ b {A}{az}(p : az <>> [] ∈ arity b)
211211
→ BAPP b p A
212-
Value A ⊎ ∅ ⊢Nf⋆ *
212+
→ ∅ ⊢ A
213213
BUILTIN' b {az = az} p q
214214
with sym (trans (cong ([] <><_) (sym (<>>2<>>' _ _ _ p))) (lemma<>2 az []))
215-
... | refl = BUILTIN b (convBApp b p (saturated (arity b)) q)
215+
... | refl with BUILTIN b (convBApp b p (saturated (arity b)) q)
216+
... | inj₁ V = discharge V
217+
... | inj₂ A = error _
216218
217219
open import Data.Product using (∃)
218220
@@ -884,16 +886,12 @@ step ((s , (V-ƛ M ρ ·-)) ◅ V) = s ; ρ ∷ V ▻ M
884886
step ((s , -·⋆ A) ◅ V-Λ M ρ) = s ; ρ ▻ (M [ A ]⋆)
885887
step ((s , wrap- {A = A}{B = B}) ◅ V) = s ◅ V-wrap V
886888
step ((s , unwrap-) ◅ V-wrap V) = s ◅ V
887-
step ((s , (V-I⇒ b {as' = []} p vs ·-)) ◅ V)
888-
with BUILTIN' b (bubble p) (app p vs V)
889-
... | inj₁ V' = s ◅ V'
890-
... | inj₂ A = ◆ A
889+
step ((s , (V-I⇒ b {as' = []} p vs ·-)) ◅ V) =
890+
s ; [] ▻ (BUILTIN' b (bubble p) (app p vs V))
891891
step ((s , (V-I⇒ b {as' = x₂ ∷ as'} p vs ·-)) ◅ V) =
892892
s ◅ V-I b (bubble p) (app p vs V)
893-
step ((s , -·⋆ A) ◅ V-IΠ b {as' = []} p vs)
894-
with BUILTIN' b (bubble p) (app⋆ p vs refl)
895-
... | inj₁ V = s ◅ V
896-
... | inj₂ A' = ◆ A'
893+
step ((s , -·⋆ A) ◅ V-IΠ b {as' = []} p vs) =
894+
s ; [] ▻ BUILTIN' b (bubble p) (app⋆ p vs refl)
897895
step ((s , -·⋆ A) ◅ V-IΠ b {as' = x₂ ∷ as'} p vs) =
898896
s ◅ V-I b (bubble p) (app⋆ p vs refl)
899897
step (□ V) = □ V
@@ -949,7 +947,7 @@ ck2cekState (CK.□ V) = □ (ck2cekVal V)
949947
ck2cekState (CK.◆ A) = ◆ A
950948
951949
952-
-- conver CEK things to CK things
950+
-- convert CEK things to CK things
953951
954952
cek2ckVal : ∀{A} → (V : Value A) → Red.Value (discharge V)
955953
@@ -994,3 +992,68 @@ cek2ckState (s ; ρ ▻ L) = cek2ckStack s CK.▻ cek2ckClos L ρ
994992
cek2ckState (s ◅ V) = cek2ckStack s CK.◅ cek2ckVal V
995993
cek2ckState (□ V) = CK.□ (cek2ckVal V)
996994
cek2ckState (◆ A) = CK.◆ A
995+
996+
data _-→s_ {A : ∅ ⊢Nf⋆ *} : State A → State A → Set where
997+
base : {s : State A} → s -→s s
998+
step* : {s s' s'' : State A}
999+
→ step s ≡ s'
1000+
→ s' -→s s''
1001+
→ s -→s s''
1002+
1003+
step** : ∀{A}{s : State A}{s' : State A}{s'' : State A}
1004+
→ s -→s s'
1005+
→ s' -→s s''
1006+
→ s -→s s''
1007+
step** base q = q
1008+
step** (step* x p) q = step* x (step** p q)
1009+
1010+
-- some syntactic assumptions
1011+
1012+
postulate ival-lem : ∀ b {A}{s : CK.Stack A _} → (s CK.◅ Red.ival b) ≡ (s CK.◅ cek2ckVal (ival b))
1013+
1014+
postulate dischargeBody-lem : ∀{A B}{Γ}{C}{s : CK.Stack A B}(M : Γ , C ⊢ _) ρ V → (s CK.▻ (dischargeBody M ρ [ CK.discharge (cek2ckVal V) ])) ≡ (s CK.▻ cek2ckClos M (ρ ∷ V))
1015+
1016+
postulate discharge-lem : ∀{A}(V : Value A) → Red.deval (cek2ckVal V) ≡ discharge V
1017+
1018+
postulate dischargeBody⋆-lem : ∀{Γ K B A C}{s : CK.Stack C _}(M : Γ ,⋆ K ⊢ B) ρ → (s CK.▻ (dischargeBody⋆ M ρ [ A ]⋆)) ≡ (s CK.▻ cek2ckClos (M [ A ]⋆) ρ)
1019+
1020+
postulate dischargeB-lem : ∀ {K A}{B : ∅ ,⋆ K ⊢Nf⋆ *}{C b}{as a as'}{p : as <>> Type ∷ a ∷ as' ∈ arity b}{x : BAPP b p (Π B)} (s : CK.Stack C (B [ A ]Nf)) → s CK.◅ Red.V-I b (bubble p) (Red.step⋆ p (cek2ckBAPP x)) ≡ (s CK.◅ cek2ckVal (V-I b (bubble p) (app⋆ p x refl)))
1021+
1022+
postulate dischargeB'-lem : ∀ {A}{C b}{as a as'}{p : as <>> a ∷ as' ∈ arity b}{x : BAPP b p A} (s : CK.Stack C _) → s CK.◅ Red.V-I b p (cek2ckBAPP x) ≡ (s CK.◅ cek2ckVal (V-I b p x))
1023+
1024+
1025+
-- assuming that buitins work the same way for CEK and red/CK
1026+
1027+
postulate BUILTIN-lem : ∀ b {A}{az}(p : az <>> [] ∈ arity b)(q : BAPP b p A) → Red.BUILTIN' b p (cek2ckBAPP q) ≡ cek2ckClos (BUILTIN' b p q) []
1028+
1029+
import Algorithmic.CC as CC
1030+
thm64 : ∀{A}(s s' : State A) → s -→s s' → cek2ckState s CK.-→s cek2ckState s'
1031+
thm64 s s base = CK.base
1032+
thm64 (s ; ρ ▻ ` x) s' (step* refl q) = CK.step** (CK.lemV (discharge (lookup x ρ)) (cek2ckVal (lookup x ρ)) (cek2ckStack s)) (thm64 _ s' q)
1033+
thm64 (s ; ρ ▻ ƛ L) s' (step* refl q) = CK.step* refl (thm64 _ s' q)
1034+
thm64 (s ; ρ ▻ (L · M)) s' (step* refl q) = CK.step* refl (thm64 _ s' q)
1035+
thm64 (s ; ρ ▻ Λ L) s' (step* refl q) = CK.step* refl (thm64 _ s' q)
1036+
thm64 (s ; ρ ▻ (L ·⋆ A)) s' (step* refl q) = CK.step* refl (thm64 _ s' q)
1037+
thm64 (s ; ρ ▻ wrap A B L) s' (step* refl q) = CK.step* refl (thm64 _ s' q)
1038+
thm64 (s ; ρ ▻ unwrap L) s' (step* refl q) = CK.step* refl (thm64 _ s' q)
1039+
thm64 (s ; ρ ▻ con c) s' (step* refl q) = CK.step* refl (thm64 _ s' q)
1040+
thm64 (s ; ρ ▻ ibuiltin b) s' (step* refl q) = CK.step* (ival-lem b) (thm64 _ s' q)
1041+
thm64 (s ; ρ ▻ error _) s' (step* refl q) = CK.step* refl (thm64 _ s' q)
1042+
thm64 (ε ◅ V) s' (step* refl q) = CK.step* refl (thm64 _ s' q)
1043+
thm64 ((s , -· L ρ) ◅ V) s' (step* refl q) = CK.step* refl (thm64 _ s' q)
1044+
thm64 ((s , (V-ƛ M ρ ·-)) ◅ V) s' (step* refl q) = CK.step*
1045+
(dischargeBody-lem M ρ V)
1046+
(thm64 _ s' q)
1047+
thm64 ((s , (V-I⇒ b {as' = []} p x ·-)) ◅ V) s' (step* refl q) = CK.step*
1048+
(cong (cek2ckStack s CK.▻_) (BUILTIN-lem b (bubble p) (app p x V)))
1049+
(thm64 _ s' q)
1050+
thm64 ((s , (V-I⇒ b {as' = x₁ ∷ as'} p x ·-)) ◅ V) s' (step* refl q) = CK.step* (dischargeB'-lem (cek2ckStack s)) (thm64 _ s' q)
1051+
thm64 ((s , -·⋆ A) ◅ V-Λ M ρ) s' (step* refl q) = CK.step* (dischargeBody⋆-lem M ρ) (thm64 _ s' q)
1052+
thm64 ((s , -·⋆ A) ◅ V-IΠ b {as' = []} p x) s' (step* refl q) = CK.step*
1053+
(cong (cek2ckStack s CK.▻_) (BUILTIN-lem b (bubble p) (app⋆ p x refl)))
1054+
(thm64 _ s' q)
1055+
thm64 ((s , -·⋆ A) ◅ V-IΠ b {as' = x₁ ∷ as'} p x) s' (step* refl q) = CK.step* (dischargeB-lem (cek2ckStack s)) (thm64 _ s' q)
1056+
thm64 ((s , wrap-) ◅ V) s' (step* refl q) = CK.step* refl (thm64 _ s' q)
1057+
thm64 ((s , unwrap-) ◅ V-wrap V) s' (step* refl q) = CK.step* (cong (cek2ckStack s CK.▻_) (discharge-lem V)) (CK.step** (CK.lemV _ (cek2ckVal V) (cek2ckStack s)) (thm64 _ s' q))
1058+
thm64 (□ V) s' (step* refl q) = CK.step* refl (thm64 _ s' q)
1059+
thm64 (◆ A) s' (step* refl q) = CK.step* refl (thm64 _ s' q)

plutus-metatheory/src/Algorithmic/CK.lagda.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,3 +236,6 @@ thm64b (◆ A) s' (step* refl p) = CC.step* refl (thm64b _ s' p)
236236
237237
test : State (con unit)
238238
test = ε ▻ (ƛ (con unit) · (ibuiltin iData · con (integer (+ 0))))
239+
240+
postulate
241+
lemV : ∀{A B}(M : ∅ ⊢ B)(V : Value M)(E : Stack A B) → (E ▻ M) -→s (E ◅ V)

0 commit comments

Comments
 (0)