showing a cakeml program is safe cakeml a verified
play

Showing a CakeML program is safe CakeML A verified implementation - PowerPoint PPT Presentation

First steps towards a semantic type system for CakeML Hrutvik Kanabar 1 January 23, 2020 University of Kent 1 Supervised by Scott Owens. Supported by the UK Research Institute in Verified Trustworthy Software Systems (VeTSS). Showing a CakeML


  1. First steps towards a semantic type system for CakeML Hrutvik Kanabar 1 January 23, 2020 University of Kent 1 Supervised by Scott Owens. Supported by the UK Research Institute in Verified Trustworthy Software Systems (VeTSS). Showing a CakeML program is safe

  2. CakeML

  3. • A verified implementation of ML • Formally specified • Implemented using HOL4 • Verified, bootstrappable compiler Showing a CakeML program is safe – Hrutvik Kanabar 1 Introduction to CakeML

  4. Showing a CakeML program is safe – Hrutvik Kanabar 2 Compiler Correctness ∀ . semantics ( ) ̸ = Error = ⇒ semantics ( ) = semantics_x86 ( compile ( ))

  5. Showing a CakeML program is safe – Hrutvik Kanabar 3 Guaranteeing Well-defined Semantics semantics ( ) ̸ = Error ?

  6. translate CakeML + proof • HOL • P cf e v Q Showing a CakeML program is safe – Hrutvik Kanabar 3 Guaranteeing Well-defined Semantics • Γ ⊢ e : ? + sound ( _ ⊢ _ : _ )

  7. 3 • • HOL translate Showing a CakeML program is safe – Hrutvik Kanabar Q v cf e P Guaranteeing Well-defined Semantics • Γ ⊢ e : ? + sound ( _ ⊢ _ : _ ) − − − − − → CakeML + proof

  8. • HOL translate Showing a CakeML program is safe – Hrutvik Kanabar 3 Guaranteeing Well-defined Semantics • Γ ⊢ e : ? + sound ( _ ⊢ _ : _ ) − − − − − → CakeML + proof • { P } cf ( e ) { λ v . Q }

  9. Fast imperative code? • HOL translate Showing a CakeML program is safe – Hrutvik Kanabar 3 Guaranteeing Well-defined Semantics • Γ ⊢ e : ? + sound ( _ ⊢ _ : _ ) − − − − − → CakeML + proof • { P } cf ( e ) { λ v . Q }

  10. Fast imperative code? • HOL translate Non-termination? Showing a CakeML program is safe – Hrutvik Kanabar 3 Guaranteeing Well-defined Semantics • Γ ⊢ e : ? + sound ( _ ⊢ _ : _ ) − − − − − → CakeML + proof • { P } cf ( e ) { λ v . Q }

  11. Fast imperative code? • HOL translate Non-termination? Showing a CakeML program is safe – Hrutvik Kanabar 3 Guaranteeing Well-defined Semantics • Γ ⊢ e : ? + sound ( _ ⊢ _ : _ ) − − − − − → CakeML + proof • { P } cf ( e ) { λ v . Q } Proof effort?

  12. Semantic typing

  13. Showing a CakeML program is safe – Hrutvik Kanabar 4 Syntactic . . . Γ ⊢ e : τ e “looks like” it has type τ

  14. Showing a CakeML program is safe – Hrutvik Kanabar 5 . . . Becomes Semantic Γ ⊨ e : τ e “behaves like” it has type τ

  15. Showing a CakeML program is safe – Hrutvik Kanabar 5 . . . Becomes Semantic Γ ⊨ e : τ e is safe to use as if it has type τ

  16. • Type-indexed family of predicates on terms • Step-indexed (“fuelled”) for impredicativity • Compositional: • We use unary relations so far Showing a CakeML program is safe – Hrutvik Kanabar 6 Logical Relations R τ 1 → τ 2 ( e 1 ) ∧ R τ 1 ( e 2 ) = ⇒ R τ 2 ( e 1 e 2 ) .

  17. Next steps: ref • System F with: • CakeML-like semantics, formalised in HOL4 • A model for our use cases! Showing a CakeML program is safe – Hrutvik Kanabar 7 The Story So Far . . . ∃ α . τ , µα . τ (iso) , τ 1 × τ 2 , τ 1 + τ 2 , crash e.g. if i ≤ a . length then a [ i ] else crash

  18. • System F with: • CakeML-like semantics, formalised in HOL4 • A model for our use cases! Showing a CakeML program is safe – Hrutvik Kanabar 7 The Story So Far . . . ∃ α . τ , µα . τ (iso) , τ 1 × τ 2 , τ 1 + τ 2 , crash e.g. if i ≤ a . length then a [ i ] else crash Next steps: ref τ

  19. Use cases

  20. 8 Showing a CakeML program is safe – Hrutvik Kanabar Composing Safe and Unsafe code

  21. then compose safe and unsafe code, e.g. user lib user lib Showing a CakeML program is safe – Hrutvik Kanabar 8 Composing Safe and Unsafe code First prove compatibility lemmas . . . ⊢ · · · ⊢ ⊨ · · · ⊨ = ⇒ ⊢ ⊨

  22. 8 user Showing a CakeML program is safe – Hrutvik Kanabar lib user lib Composing Safe and Unsafe code First prove compatibility lemmas . . . ⊢ · · · ⊢ ⊨ · · · ⊨ = ⇒ ⊢ ⊨ . . . then compose safe and unsafe code, e.g. ⊢ · · · ⊢ ⊢ · · · ⊢ ⊬ ⊨ ⊨ ⊨ − → ⊨ ⊬ ⊨ ⊨

  23. 9 Showing a CakeML program is safe – Hrutvik Kanabar Reasoning about Module Invariants

  24. We can express invariants as semantic types, and so prove they are preserved. A HOL kernel implemented in CakeML. LCF-style – relies on type abstraction for soundness! Showing a CakeML program is safe – Hrutvik Kanabar 9 Reasoning about Module Invariants Candle

  25. Obj.magic + Obj.magic Current unverified extraction to OCaml: Coq extract OCaml Proposed verified extraction to CakeML: Coq extract CakeML Showing a CakeML program is safe – Hrutvik Kanabar 10 Extracting Coq to CakeML

  26. + Obj.magic 10 Proposed verified extraction to CakeML: Showing a CakeML program is safe – Hrutvik Kanabar CakeML extract Coq OCaml extract Current unverified extraction to OCaml: Coq Extracting Coq to CakeML + Obj.magic − − − →

  27. 10 OCaml Showing a CakeML program is safe – Hrutvik Kanabar CakeML extract Coq Current unverified extraction to OCaml: Proposed verified extraction to CakeML: extract Coq Extracting Coq to CakeML + Obj.magic − − − → + Obj.magic − − − →

  28. Thanks for listening! Showing a CakeML program is safe – Hrutvik Kanabar 11

Recommend


More recommend