README.md 2.33 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
## Structure of the project
The best place to start exploring the project is in
Jakob Botsch Nielsen's avatar
Jakob Botsch Nielsen committed
6
[Blockchain.v](theories/Blockchain.v). Here we define the basic types describing
7
8
9
10
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.

Jakob Botsch Nielsen's avatar
Jakob Botsch Nielsen committed
11
12
13
14
We also define a typeclass that captures what it means to satisfy our semantics.
We exhibit two instances of this typeclass in
[LocalBlockchain.v](theories/LocalBlockchain.v): one with depth-first execution
order of smart contracts, and one with breadth-first execution order.
15

Jakob Botsch Nielsen's avatar
Jakob Botsch Nielsen committed
16
In [Circulation.v](theories/Circulation.v) we prove a small sanity check for our
17
18
19
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.

Jakob Botsch Nielsen's avatar
Jakob Botsch Nielsen committed
20
In [Congress.v](theories/Congress.v) we implement the _Congress_ contract, a
21
simplified version of the DAO, which does complex dynamic interactions with the
Jakob Botsch Nielsen's avatar
Jakob Botsch Nielsen committed
22
23
24
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
25
26
Congress will make.

Jakob Botsch Nielsen's avatar
Jakob Botsch Nielsen committed
27
28
29
30
31
In [Congress_Buggy.v](theories/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.
32

Jakob Botsch Nielsen's avatar
Jakob Botsch Nielsen committed
33
34
35
In [LocalBlockchainTests.v](theories/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.
36

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
```