Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: add getting started #17

Merged
merged 1 commit into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions coq/docs/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

[Introduction](./introduction.md)

<!-- # User Guide
# User Guide

- [Installation](guide/installation.md) -->
- [Getting Started](guide/getting_started.md)
66 changes: 66 additions & 0 deletions coq/docs/src/guide/getting_started.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Getting Started

Here we give you the instructions to get started to translate Solidity smart contracts to Coq.

## Translate Solidity to Coq

If you have a smart contract named `contract.sol`, generate the JSON of its unoptimized Yul code with the following command:

```
solc --ir-ast-json contract.sol \
| tail -1 \
> contract.yul.json
```

assuming you have installed the Solidity compiler `solc`.

Then clone the repository of [coq-of-solidity](https://github.com/formal-land/coq-of-solidity):

```
git clone --recursive https://github.com/formal-land/coq-of-solidity.git
cd coq-of-solidity
```

Then translate it to Coq with the following command:

```
python coq/scripts/shallow_embed.py path/to/contract.yul.json \
> shallow.v
```

The resulting file `shallow.v` contains the Coq code of the smart contract. Generally the first part is the deployment code (constructor), and then comes the code for the entrypoints of the smart contract.

## Compile the generated Coq code

Assuming you have a working installation of the [opam]() package manager that we use for Coq, from the root of the `coq-of-solidity` repository, run the following command to install the `CoqOfSolidity` library:

```
opam install --deps-only coq/CoqOfSolidity/coq-of-solidity.opam
```

Then go to the directory with the Coq code:

```
cd coq
```

Install the `coq-evm` dependency including the definition of cryptographic primitives such as Keccak256:

```
third-party/coq-evm
./configure
make
make install
cd ../..
```

Compile and install the `CoqOfSolidity` library:

```
cd CoqOfSolidity
make
make install
cd ..
```

You can now compile your generated `shallow.v` file, for example opening it in VSCode with the Coq extension installed.
3 changes: 0 additions & 3 deletions coq/docs/src/guide/installation.md

This file was deleted.

Loading