Commit 308fdae7 authored by David Declerck's avatar David Declerck Committed by Léo Andrès
Browse files

Porting articles

parent ebc2eac2
title=A Solidity parser in OCaml with Menhir
authors=David Declerck
date=2020-05-19
category=Blockchains
tags=
<!-- [![Solidity Logo](assets/img/solidity-cover.png "A Solidity parser in OCaml with Menhir")](https://www.ocamlpro.com/2020/05/19/ocaml-solidity-parser-with-menhir/) -->
<div align="center">
<a href="https://www.ocamlpro.com/2020/05/19/ocaml-solidity-parser-with-menhir/">
<img width="420" height="420" alt="Solidity Logo" title="A Solidity parser in OCaml with Menhir" src="assets/img/solidity-cover.png">
</a>
</div>
> This article is cross-posted on Origin Labs’ Dune Network [blog](https://medium.com/dune-network/a-solidity-parser-in-ocaml-with-menhir-e1064f94e76b)
We are happy to announce the first release of [our Solidity parser](https://gitlab.com/o-labs/solidity-parser-ocaml), written in OCaml using [Menhir](http://gallium.inria.fr/~fpottier/menhir/). This is a joint effort with [Origin Labs](https://www.origin-labs.com/), the company dedicated to blockchain challenges, to implement a full interpreter for the [Solidity language](https://solidity.readthedocs.io/en/v0.6.8/) directly in a blockchain.
![Solidity Logo](assets/img/solidity-title.png)
Solidity is probably the most popular language for smart-contracts, small pieces of code triggered when accounts receive transactions on a blockchain.Solidity is an object-oriented strongly-typed language with a Javascript-like syntax.
![Ethereum Logo](assets/img/ethereum-title.png)
Solidity was first implemented for the [Ethereum](https://ethereum.org/) blockchain, with a compiler to the EVM, the Ethereum Virtual Machine.
![Dune Network Logo](assets/img/dune-title.png)
Dune Network takes a different approach, as Solidity smart-contracts will be executed natively, after type-checking. Solidity will be the third native language on Dune Network, with [Michelson](https://dune.network/docs/dune-node-mainnet/whitedoc/michelson.html), a low-level strongly-typed language inherited from Tezos, and [Love](https://dune.network/docs/dune-node-mainnet/love-doc/introduction.html), an higher-level strongly-typed language, also implemented jointly by OCamlPro and Origin Labs.
A first step has been accomplished, with the completion of the Solidity parser and printer, written in OCaml with Menhir.
This parser (and its printer companion) is now available as a standalone library under the LGPLv3 license with Linking Exception, allowing its integration in all projects. The source code is available at https://gitlab.com/o-labs/solidity-parser-ocaml.
Our parser should support all of Solidity 0.6, with the notable exception of inline assembly (may be added in a future release).
## Example contract
Here is an example of a very simple contract that stores an integer value and allows the contract’s owner to add an arbitrary value to this value, and any other contract to read this value:
```solidity
pragma solidity >=0.6.0 <0.7.0;
contract C {
address owner;
int x;
constructor() public {
owner = msg.sender;
x = 0;
}
function add(int d) public {
require(msg.sender == owner);
x += d;
}
function read_x() public view returns(int) {
return x;
}
}
```
## Parser Usage
### Executable
Our parser comes with a small executable that demonstrates the library usage. Simply run:
```bash
./solp contract.sol
```
This will parse the file `contract.sol` and reprint it on the terminal.
### Library
To use our parser as a library, add it to your program’s dependencies and use the following function:
```ocaml
Solidity_parser.parse_contract_file : string -> Solidity_parser.Solidity_types.module_
```
It takes a filename and returns a Solidity AST.
If you wish to print this AST, you may turn it into its string representation by sending it to the following function:
```ocaml
Solidity_parser.Printer.string_of_code : Solidity_parser.Solidity_types.module_ -> string
```
## Conclusion
Of course, all of this is Work In Progress, but we are quite happy to share it with the OCaml community. We think there is a tremendous work to be done around blockchains for experts in formal methods. Do not hesitate to contact us if you want to use this library!
> ## About Origin Labs
> Origin Labs is a company founded in 2019 by the former blockchain team at OCamlPro. At Origin Labs, they have been developing Dune Network, a fork of the Tezos blockchain, its ecosystem, and applications over the Dune Network platform. At OCamlPro, they developed TzScan, the most popular block explorer at the time, Liquidity, a smart contract language, and were involved in the development of the core protocol and node.Do not hesitate to reach out by email: contact@origin-labs.com.
title=A Dune Love story: From Liquidity to Love
authors=Steven De Oliveira
date=2020-06-09
category=Blockchains
tags=
<!-- [![Liquidity & Love](assets/img/liq-love-1.png "A Dune Love story: From Liquidity to Love")](https://www.ocamlpro.com/2020/06/09/a-dune-love-story-from-liquidity-to-love/) -->
<div align="center">
<a href="https://www.ocamlpro.com/2020/06/09/a-dune-love-story-from-liquidity-to-love/">
<img width="900" height="900" alt="Liquidity & Love" title="A Dune Love story: From Liquidity to Love" src="assets/img/liq-love-1.png">
</a>
</div>
*By OCamlPro & Origin Labs*
Writing smart contacts may often be a burdensome task, as you need to learn a new language for each blockchain you target. In the Dune Network team, we are willing to provide as many possibilities as possible for developers to thrive in an accessible and secure framework.
There are two kinds of languages on a blockchain: “native” languages that are directly understood by the blockchain, but with some difficulty by the developers, and “compiled” languages that are more transparent to developers, but need to be translated to a native language to run on the blockchain. For example, Solidity is a developer-friendly language, compiled to the native EVM language on the Ethereum blockchain.
Dune Network supports multiple native languages:
- [**Love**](https://medium.com/dune-network/love-a-new-smart-contract-language-for-the-dune-network-a217ab2255be), a type-safe language with a ML syntax and suited for formal verification
- [**Michelson**](https://dune.network/docs/dune-node-mainnet/whitedoc/michelson.html), inherited from [Tezos](https://tezos.com), also type-safe, much more difficult to read
- [**Solidity**](https://en.wikipedia.org/wiki/Solidity), the Ethereum language, of which we are currently implementing the interpreter after releasing [its parser in OCaml](https://medium.com/dune-network/a-solidity-parser-in-ocaml-with-menhir-e1064f94e76b) a few weeks ago
On the side of compiled languages, Dune Network supports:
- [**Liquidity**](https://www.liquidity-lang.org/), a type-safe ML language suited for formal verification, that compiles to Michelson (and allows developers to decompile Michelson for auditing)
- [**ReasonML**](https://reasonml.github.io/), a JavaScript language designed by Facebook that compiles down to Michelson through Liquidity
- All other Tezos languages that compile to Michelson (for example [**Ligo**](https://ligolang.org/), [**SmartPy**](https://smartpy.io/), [**Albert**](https://albert-lang.io/)...)
Though Liquidity and Love are both part of the ML family, Liquidity is much more developer-friendly: types are inferred, whereas in Love they have to be explicit, and Liquidity supports the ReasonML JavaScript syntax while Love is bound to its ML syntax.
For all these reasons, we are pleased to announce a wedding: Liquidity now supports the Love language!
![Liquidity & Love](assets/img/liq-love-2.png)
*Liquidity now supports generating Love smart contracts*
This is great news for Love, as Liquidity is easier to use, and comes with an online web editor, [Try-Liquidity](https://www.liquidity-lang.org/edit/). Liquidity is also being targeted by the [ConCert project](https://arxiv.org/pdf/1907.10674.pdf), aiming at **verifying smart contracts** with the formal verification framework Coq.
![Dune Languages](assets/img/dune-compilers.png)
*The Smart Contract Framework on the Dune Network*
Compiling contracts from Liquidity to Love has several benefits compared to Michelson. First, Love contracts are about 60% smaller than Michelson contracts, hence they are **60% cheaper** to deploy. Also, the compiler outputs a Love contract that can be easily read and audited.
The Love compiler is part of the [Liquidity project](https://github.com/OCamlPro/liquidity). It works as follows:
- **The Liquidity contract is type-checked by the Liquidity compiler.** The strong type system of liquidity enforces structural & semantic properties on data.
- **The typed Liquidity contract is compiled to a typed Love contract.** During this step, the Liquidity contract is scanned to check if it complies with the Love requirements (correct use of operators, no reentrancy, etc.).
- **The Love contract is type-checked.** Once this step is completed, the contract is ready to be deployed on the chain!
Want to try it out? Check the [Try-Liquidity](https://www.liquidity-lang.org/edit/) website: you can now compile and deploy your Liquidity contracts in Love from the online editor directly to the Mainnet and Testnet using [Dune Metal](https://metal.dune.network)!
---
These are some of the resources you might find interesting when building your own smart contracts:
- **The Love Language Documentation**: https://dune.network/docs/dune-dev-docs/love-doc/introduction.html
- **Try-Liquidity:** https://www.liquidity-lang.org/edit/
- **The Liquidity Website:** https://www.liquidity-lang.org/
- **The Dune Network Website:** https://dune.network
> ## About Origin Labs
> Origin Labs is a company founded in 2019 by the former blockchain team at OCamlPro. At Origin Labs, they have been developing Dune Network, a fork of the Tezos blockchain, its ecosystem, and applications over the Dune Network platform. At OCamlPro, they developed TzScan, the most popular block explorer at the time, Liquidity, a smart contract language, and were involved in the development of the core protocol and node. Feel free to reach out by email: contact@origin-labs.com.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment