Why Marlowe

Many people in the business world are familiar with escrows and other common financial contracts. These people, interested in the blockchain space, may be tempted to encode their contract onto the blockchain. However, this leads leads to two problems:

High engineering cost to hire a developer for even simple contracts. Hard to convince all parties that the code really matches the contract they agreed to.

To solve these problems and enable blockchain adoption in the business world, we therefore need a way to write smart contracts that

Can be written without knowing how to code highly secure programs. Can easily be read and understood by all parties.

It seems it should be possible to build such a system. After all, many contracts are build by a composition of well-known building blocks. Indeed, this is the problem we try to solve with Marlowe.

What is Marlowe

Marlowe is a project built and funded by IOHK in cooperation with the University of Kent (UKC). Although it is built for the Cardano blockchain, it tries to be a blockchain-independent framework for writing financial smart contracts by simply visually composing known building blocks.

These contracts make progress through concrete actions such as users depositing / withdrawing money. Every concrete action makes the state of the program irreversibly advance towards a final state (final state is defined as an empty contract). This is useful because we want to guarantee that financial contracts always eventually terminate (contract was fulfilled, expired, etc).

More formally, every block in the blockchain is considered a “step”. For each step, we take the following inputs:

The contract itself. User transactions (deposit money, etc). The current state of your contract (who has deposited how much, etc). The environment (block number, etc).

We then produce the following output:

Updated contract (content of contract may have changed due to a timeout, etc.). Updated contract state.

For example, let us visualize a contract that takes money from 2 different users and then simply terminates. The contract content is not too important ― the important thing to note is that the contract progresses over time towards the empty contract.

How to use Marlowe

Marlowe currently runs inside the browser in a system that simulates a blockchain called Meadow. This allows for easy prototyping and development but Marlowe will eventually run on its own testnet and then run as part of the Cardano mainnet.

Let us explain Meadow in 6 different parts

(1) Build block toolbox

A few different blocks already exists and they are separated into 3 categories:

Observations: These values come from the environment. Although what you can do now is limited, in this future this section will include all things related to Oracles and blockchain-based data. Contract: These are the primary composable building blocks for the smart contract. Money: Represents operations or values on ADA.

(2) Design space

In this space you can drag and drop blocks together to create your smart contract.

(3) Code view

In this section you can see the code generated by the design space. This is what you should save if you want to share your smart contract with others or save it for a later date. The language is a custom domain-specific language (DSL) that should be translated to whatever language is support by your blockchain (in the case of Cardano, this would be translated to Plutus). Since the current version of Marlowe runs on Haskell, you can also open up a Haskell editor and write your own custom script.

(4) Contract state

The state represents the part of the smart contract that needs to be stored on the blockchain (i.e. information that is needed to re-run and verify the result of a smart contract).

Currently it only stores the status of cash commitments (deposits into the contract) and user “choices” (one of the observable behaviors), but in the future this will store all the data used from the environment / any oracle.

(5) User inputs

Inputs consist of:

Cash commitments (deposits) Cash redemptions (withdrawals) Payment requests Choices (ex: choose 1 of 2 options)

These inputs can either be forced through the “manual interface” but Meadow provides a “smart interface” that will only show you which actions will actually make your smart contract progress.

Once you’re inserted your input you can press the “Execute’ button at the top-right of the screen. This will progress to the next block and consume all your input.

(6) Outputs

This will show the result of applying your input in a given block. Output is used to log information and in a real-world system you would use this output to drive a web interface (similar to how you may interact with many Ethereum smart contracts through web interfaces)

Learn more and try it yourself!

You can try Marlowe in your browser at https://input-output-hk.github.io/marlowe/

You can also learn more by watching my video at https://www.youtube.com/watch?v=S41GIRl0kVY

You can find the code for the semantics of Marlowe at https://github.com/input-output-hk/marlowe/blob/master/src/Semantics.hs

You can find the paper for Marlowe at https://iohk.io/research/papers/#2WHKDRA8

Author: Sebastien Guillemot