README.md 2.28 KB
Newer Older
Jakob Botsch Nielsen's avatar
Jakob Botsch Nielsen committed
1
# Smart Contracts
Jakob Botsch Nielsen's avatar
Jakob Botsch Nielsen committed
2
This repo is a formalization of execution layers of modern blockchains in Coq.
Jakob Botsch Nielsen's avatar
Jakob Botsch Nielsen committed
3

4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
## Structure of the project
The best place to start exploring the project is in
[Blockchain.v](Blockchain.v). Here we define the basic types describing
blockchains, smart contracts and the semantics of the execution layer of
blockchains. We give proofs of some interesting general lemmata here as well,
for instances that undeployed contracts cannot have sent out any transactions.

We also define a typeclass that captures what it means to satisfy
our semantics. We exhibit two instances of this typeclass in
[LocalBlockchain.v](LocalBLockchain.v): one with depth-first execution order of
smart contracts, and one with breadth-first execution order.

In [Circulation.v](Circulation.v) we prove a small sanity check for our
semantics. Specifically we prove that the total sum of the money in the system
is equal to the sum of the rewards handed out in blocks.

In [Congress.v](Congress.v) we implement the _Congress_ contract, a
simplified version of the DAO, which does complex dynamic interactions with the
blockchain and other contracts deployed on the blockchain. We specify
and prove a property about this contract at the end of this file. This property
is somewhat related to reentrancy in that it caps the number of transactions the
Congress will make.

In [Congress_Buggy.v](Congress_Buggy.v) we try something different: we take the
same contract as above, but introduce a reentrancy issue into it. We then
formally prove that this version of the Congress does _not_ satisfy the property
proven for the other version. This is proven by using one of our implementations
of our semantics and just asking Coq to compute.

In [LocalBlockchainTests.v](LocalBlockchainTests.v) we test that Coq is able to
compute with the Congress by deploying it and interacting with it using one of
our implementations of blockchains.

Jakob Botsch Nielsen's avatar
Jakob Botsch Nielsen committed
37
## Building/Developing
38
This repo uses the std++ library. This must be installed first and can be
39
40
41
42
43
44
installed via Opam, after adding the dev repo of Iris:
```bash
opam repo add iris-dev https://gitlab.mpi-sws.org/iris/opam.git
opam install coq-stdpp
```
For more instructions, see [the stdpp readme](https://gitlab.mpi-sws.org/iris/stdpp).
Jakob Botsch Nielsen's avatar
Jakob Botsch Nielsen committed
45

46
After stdpp is installed, this repo should build with
47
48
49
```bash
make
```