GithubHelp home page GithubHelp logo

clarus / coq-chick-blog Goto Github PK

View Code? Open in Web Editor NEW
177.0 10.0 9.0 124 KB

๐Ÿฃ A blog engine written and proven in Coq

License: MIT License

Coq 93.51% Shell 0.09% Makefile 0.34% OCaml 6.06%

coq-chick-blog's Introduction

ChickBlog

A blog engine written and proven in Coq.

This is a demo blog engine where a user can login (no passwords), add, edit or delete posts. The code is written mostly in Coq, compiled to OCaml and linked to the CoHTTP library to handle the HTTP protocol.

The aim of this project is to demonstrate that applications with I/Os can be written and specified naturally using the (new) concept of symbolic simulations in Coq.

Install

Add the Coq repository with opam if not already done:

opam repo add coq-released https://coq.inria.fr/opam/released

Install the package:

opam install coq-chick-blog

Run:

coq-chick-blog

You can now open localhost:8008 to navigate the blog. Posts will be saved in the current folder. There is not password for this demo project.

To build the project by hand for development, read the build instructions from the coq-chick-blog.opam file.

Specification

The blog is defined in Main.v as the function:

Definition server (path : Path.t) (cookies : Cookies.t) : C.t Response.t.

It handles an HTTP request and generate an answer using system calls to the file system. The type C.t A represents a computation doing I/O operations:

Inductive t (A : Type) : Type :=
| Ret : forall (x : A), t A
| Call : forall (command : Command.t), (Command.answer command -> t A) -> t A.

A computation can either:

  • return a pure value of type A
  • call an external command and wait for its result

The purity of Coq ensures that each request is answered exactly once in finite time. We specify the behavior of the server in Spec.v.

Scenarios

A scenario is a set of runs of the server. A type-checking scenario shows that the server behaves as expected in a certain use case. For example, we check that when we create, edit and view a post we get the same result as what we entered. You can think of a scenario as a unit test with universally quantified variables.

Here is a simple check of the execution of the index page:

(** The index page when the list of posts is available. *)
Definition index_ok (cookies : Cookies.t) (post_headers : list Post.Header.t)
    : Run.t (Main.server Path.Index cookies).
    (* The handler asks the list of available posts. We return `post_headers`. *)
    apply (Call (Command.ListPosts _ ) (Some post_headers)).
    (* The handler terminates without other system calls. *)
    apply (Ret (Response.Index (Cookies.is_logged cookies) post_headers)).
Defined.

Given any cookies and post_headers, we execute the server handler on the page Request.Path.Index. The handler does exactly one system call, to which we answer Some post_headers, playing the role of the system. The final response of the server is then Response.Public.Index post_headers. Note that we do not need to execute index_ok on every instances of cookies and post_headers: since the type-system of Coq is supposed sound, it is enough to type-check index_ok.

Privacy

We check that, for any runs of a program, an unauthenticated user cannot access private pages (like edit) or modify the file system with system calls.

License

All the code is under the open-source MIT license.

coq-chick-blog's People

Contributors

alokmenghrajani avatar clarus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

coq-chick-blog's Issues

coq 8.5beta2 - cannot guess decreasing argument of fix.

Using coq 8.5 beta2 (which got installed when using opam, compilation failed in src/Extraction.v:

"coqc"  -q  -R "src" ChickBlog   src/Extraction
File "./src/Extraction.v", line 98, characters 0-1002:
Error: Cannot guess decreasing argument of fix.
make: *** [src/Extraction.vo] Error 1

I'm an absolute beginner at coq so can't help much further.

How to step through Spec.v in CoqIDE?

Your project is extremely interesting to me, as the aspects it touches on are exactly what I want to learn with using Coq.

Right now I'm trying to step through Spec.v using CoqIDE, but it can't find Computation.vos. Why, I have no clue, because I've compiled the source files using configure.sh && make.

Here is a screenshot:

1598202616

In your README it would be nice to mention you need to download the other projects you've written (coq-moment, coq-list-strings, etc) ๐Ÿ™‚ I can make a PR for this.

All in all, awesome work. I think it's a fantastic piece to learn from. How long have you been using Coq before you wrote this?

Doesn't find cohttp.lwt even though it's installed :(

Apologies if I'm missing something silly. I'm learning Coq and wanted to play around with this some, but it seems to not be able to find cohttp.lwt even though it appears to be installed.

ricky@t520 99% /tmp/coq-chick-blog/extraction (master)$ opam install --jobs=4 lwt cohttp
[NOTE] Package lwt is already installed (current version is 2.4.5).
[NOTE] Package cohttp is already installed (current version is 0.11.2).
ricky@t520 99% /tmp/coq-chick-blog/extraction (master)$ make
ocamlbuild chickBlog.native -use-ocamlfind -package cohttp.lwt,lwt,lwt.unix,num,str
+ ocamlfind ocamldep -package cohttp.lwt,lwt,lwt.unix,num,str -modules chickBlog.ml > chickBlog.ml.depends
ocamlfind: Package `cohttp.lwt' not found
Command exited with code 2.
Compilation unsuccessful after building 1 target (0 cached) in 00:00:00.
Makefile:2: recipe for target 'build' failed
make: *** [build] Error 10

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.