Gambling with Oracles

[casino kurhaus*]
[casino kurhaus*]

 

How to create a provably-fair high risk financial product with live data feeds provided by oracles.

Introducing Binary Options

This time, we gonna gamble. We will construct a financial product, more specifcally: a binary option, European style, cash-or-nothing.

[binary*]

Binary options are “a type of option in which the payoff is structured to be either a fixed amount of compensation if the option expires in the money, or nothing at all if the option expires out of the money” [1], therefore cash-or-nothing. European style means the option “can only be exercised at the end of its life, at its maturity” [2].

This is a high risk product which is “most likely traded over the Internet on platforms existing outside of regulations” [1], so “the customer is betting against the broker, who is acting as a bucket shop.” [3]

In general, this means that “because these platforms operate outside of regulations, investors are at greater risk of fraud” [1] and “manipulation of price data to cause customers to lose is common” [1].

BinaryOption (3)So, in contrast to common regulated financial products we have a really comprehensible option, which is mostly valued as high-risk, because there is a real clash of interests if the broker also evaluates the stock against the strike price and thus is highly motivated to manipulate this evaluation.

Smart Contracts to the Rescue

So, can smart contracts help here? You bet! The blockchain is trust-less, so you just don’t have to trust anyone, be it broker or bucket shop or both, but you can just prove if everything’s ok.

If a smart contract guarantees you that you will get 195% if you predict correctly and 0% if not, this rule has to be implemented in the contract.

Meeting the Oracle

Given that we can trust the contract, it should be easy to implement a binary option like this:

After deploying the contract, you have 1 hour to invest Ether on calls or puts on the contracts conditions (eg. DAX is above the strike price in 1 hour). After the 1 hour offering period, it's rien ne va plus, no purchase of calls or puts are possible. At this point of time, the current value of the DAX is stored. After exactly 1 hour the DAX is evaluated against the stored DAX value.
  • if the value is above or equal to the stored value, all calls are returned 195% of their investment, all puts lose all invested money
  • if the value is below the stored value, all puts are returned 195% of their investment, all calls lose all invested money

Sounds simple? It is!

[oracle*]
[oracle*]

You can easily prove that the contract actually implements the described rules, but there are two problems: how does the contract know the DAX spot? Contracts in Ethereum intentionally cannot connect to the outside world, therefore the outside world has to call the contract and provide the necessary data. Who tells the contract the exact time it has to retrieve the DAX spot? There must be some callback mechanism, since Ethereum smart contracts are not able to call themselves, have a Daemon, Threading etc.

Let’s gonna oraclize.it

There is a startup solving this problems in a elegant way: oraclize.it

You should look up and understand how oraclize.it works and helps us to solve our problems. In short, callbacks are used by oraclize.it and you can determine the exact data feed of the data which oraclize.it will provide at a certain point of time to our contract.BinaryOptionOrale (1)Here the two problems are addressed:

  1. The contract has to provide a callback for the oracle to call. The data feed is configured when the callback is provided, as well as the time interval.
  2. The oracle facilitates a scheduling to call the provided smart contract callback at the configured time interval.

Both solutions require the user and the contract owner to actually trust the “trusted datasource” (the contract’s user can decide if he trusts this datasource) and the oracle itself to have a working scheduling and not to manipulate the data. In contrast to the “broker” above, the oracle has no interest in manipulating the data.

However, oraclize.it not only offers a service, but even more defines a protocol, so there will most likely be more than one oracle to choose from to offer redundancy in the future.

Building Binary Options in Ethereum Studio

…in the next post.

Realizing how long this post already is, we decided to split the tutorial and the theoretical part. The tutorial will follow soon! Please let us know in the comments if you’d like to have this tutorial and what you expect of it.

Meanwhile, try out this ether.camp tutorial which describes the integration of oraclize.it into Ethereum Studio.

images:
[casino kurhaus] Kurhaus Casino by fr4dd under CC
[binary] binary by christine592 under CC
[
oracle] Oracle by Bob Doran under CC

icons:
icons made by Freepik from www.flaticon.com 

KW 21.16 – Weekly Blockchainers Recap

From Blockchain to Distributed Ledger Technology (DLT) If you follow the news, you might have realized that the term DLT is currently more and more used to describe what we usually describe with “the Blockchain”. Even though the definitions are more or less subjective, a good comparison between these technologies is here. In really easy terms, the DLT is the Blockchain without the “chain of blocks”, which also means without the security and immutability of the blockchain. However, as with private chains vs. public chains, this might exactly be what you need for your use case. So, keep in mind that Bitcoins are not the Blockchain and that the Blockchain is more than DLR and all of these technologies fit perfectly to their use cases, which are certainly not the same. It helps to know about the definitions to get more information about the complete topic, since DLT is not as spammed (aka SEOed) as Blockchain, a Google searchs gets you more valuable results like the BaFin evaluation and the really well made UK Government Science report. Even more about the Blockchain Fed up with all the small bits and pieces about Blockchain technology on all those news sites? Then read a book, we recommend “The Blockchain” from leanpub and hope that it will be completed soon. More into videos? Then watch primavera in her talk about Skynet or Freenet or her more current talks.  

Ethereum Development Tools – an Evaluation Matrix

Developing for the Ethereum World Computer – Revisited

When comparing development methods for and in the Ethereum space, it becomes obvious how brilliant the people involved actually are: as a developer, you have several choices of great development tools and environments, even though the development process for Dapps is quite difficult: it involves different “layers” (frontend with HTML/CSS/JavaScript and backend with the Ethereum blockchain), different languages (JavaScript for frontend dev, Solidity for backend dev), different contexts (public/private/proprietary blockchains).

Taking these different contexts into account, evaluating the different development environments is only possible by identifying the different aspects and value them according to the own preferred usage.

Aspects of Dapp Development

Ethereum-docs-intro (1)

  • Solidity Development / Solidity Environment
    User can edit Solidity content in a text editor, there should be at least syntax highlighting.
  • JavaScript/Web Environment
    User can edit JavaScript, HTML and CSS in a text editor and gets different levels of support like syntax highlighting, code completion, etc.
  • IDE
    User can not only edit code (Solidity and JavaScript), but can also compile, check into a versioning system, debug and deploy to some operating environment.
  • Versioning
    Versioning is supported, eg. by enabling the user to check edited content into a versioning system, show diffs, apply patches, etc.
  • Collaboration
    Modification of code by multiple users is supported, at minimum support of different versions of the code is possible to avoid conflicts.
  • Deployment
    Working code can be deployed to some environment which enables the user and other users to use the working program (a sandbox or real blockchain and a web application server for JavaScript like node.js and static content like HTML and CSS files)

A first Categorization and a Teaser

We will summarize in short the different aspects which are supported in these development environment: Solidity Browser / Ethereum Wallet, Truffle and Ethereum Studio.

This is also a teaser for the upcoming blog posts, which will explain the environments in detail.

Solidity Browser / Ethereum Wallet

In terms of architectural styles, both environments represent minimalism. They are slim and handy, easy to use and fast to learn, but lack some functionality if real development “in the large” is necessary.

Ethereum-docs-browser
Solidity Browser, only Solidity Development, no Environment, ie. not even save of file is possible

Ethereum-docs-wallet
Ethereum Wallet (Mist), only Solidity Environment, no save of file possible, but integrated compiler

Truffle (also: Embark, Dapple)

Truffle satisfies all aspects which a usual client application can offer, therefore you can think of Gothik, it is mighty, almost lavish, and well structured. If you come from web development in JavaScript with node.js, who should look no further, this environment is for you (at least if you don’t need support for online development, versioning and multi user directly in your environment, but use external tools like Git and testrpc for these aspects).

Ethereum-docs-truffle
Truffle, also Embark and Dapple: web development environments, usefully extended with Solidity support

Ethereum Studio, the all-in-one-solution

The Ethereum Studio, in our opinion, resembles Deconstructivism. Why’s that? Because here all aforementioned aspects of software development are taken apart and are reconstructed to fit perfectly to Dapp development. This is an all-in-one-solution which we can really recommend, with two limitation: you have to agree to a uncertain pricing model (it just doesn’t exist right now, you can still test the product) and a “closed” environment, which works seemless and smooth, but expects you to let in to this tool and the development process.

But no other tool lets you test your code this easy with manual and even unit testing built into the environment.

Ethereum-docs-studio
The all-in-one-solution, steep learning curve, but all you will ever need in multi user, versionized, unit tested Dapp development

Stay tuned for the detailed explanations of these great development tools.

Wir machen uns die Welt … wie sie uns gefällt

Nach der Entdeckung der neuen Welt und dem Überwinden der ersten Hindernisse wollen wir uns nun sesshaft machen und anfangen, Applikationen und Smart Contracts jenseits von “Hello World” zu entwickeln.

Aber wie fangen wir an? Die ersten Erfahrungen mit dem fantastischen Tool cosmo.to waren viel versprechend, leider ist das Tool mittlerweile online nicht mehr verfügbar. Der wahrscheinliche Grund ist die Tatsache, dass das Standard-Ethereum-Wallet von ethereum.org die gleiche Funktionalität und noch viel mehr bietet. Allerdings zu Lasten der Übersichtlichkeit.

Wir wollen deshalb hier einen Überblick der bekanntesten Entwicklungsumgebungen geben, mit einer subjektiven Einordnung in Architekturstile:

  • Minimalismus: minimal, übersichtlich, aber auch schlicht: der Solidity Browser. Super zum Erlernen der Sprache Solidity, aber das war’s dann auch schon. Persistierung? Versionierung? Alles nicht vorgesehen. Super für den Einstieg.
  • Bauhaus: funktional und praktisch: das Ethereum Wallet dient nicht nur als Wallet selbst, sondern ermöglicht die Erstellung und das Deployment von Smart Contracts und die Verwaltung von eigenen Tokens.
  • Gotik: opulent, gut strukturiert, mächtig: Truffle ist ein reines Javascript-Framework und verwendet alle Komponenten, die moderne Javascript-Entwicklung bietet: Gulp, Mocha, Chai, etc. Sehr gut dokumentiert, ebenfalls gut für den Einstieg geeignet, bietet darüber hinaus aber auch viel mehr.
  • Kubismus: ganz anders, aber erfolg- und einflussreich: die Entwicklungsumgebung von Microsoft, Visual Studio (Community) oder der neue Open Source Editor Visual Studio Code zusammen mit BlockApps STRATO, einer zentralisierten Blockchain. Leicht zu nutzen, mit automatischer Frontenderstellung. Etwas für den anderen, schnellen Einstieg in private Chains mit Microsoft Azure.
  • Dekonstruktivismus: das “new kid on the block”, das Ethereum Studio von <ether.camp> macht alles etwas anders, nach unserer Meinung auch besser: eine verteilte Entwicklungsumgebung auf Basis von cloud9, ein integrierter Sandbox-Ethereum-Node, eine Deploymentmöglichkeit in alle möglichen Umgebungen (die JSON-RPC verstehen). Leider auf Dauer nicht kostenlos, Preise sind noch nicht bekannt.

In den nächsten Wochen werden wir die hier erwähnten (es gibt noch zahlreiche andere!) Entwicklungsumgebungen genauer testen, immer mit dem gleichen Tokenbeispiel. Stay tuned!

Homestead … settling down

Having crossed frontiers in unknown and unsafe land, finally, we are settling down.

After having described last time how to create our own cryptocurrency in Ethereum Frontier – the description of which was way to complicated as we have learnt – we will repeat it, this time in Ethereum Homestead, and we assure you: this time it will be really easy.

In fact, creating a new cryptocurrency is even built into the new Ethereum wallet, so if you use the proposed “coin-interface“, your own currency is even supported with an own pocket in the wallet itself, besides your real Ether – this is just gorgeous and if you are still unsure about the world dominance about Ethereum, try this out and hopefully, just be astonished.

EtherumWallet

Ok, enough propaganga, let’s get down to the nitty-gritty.

Objective

Create you own cryptocurrency in Ethereum Homestead. You should be able to fund yourself with some amount of initial value (let’s say 10000 items) of your own currency and be able to send it around to any valid Ethereum address.
This currency should in no way be related or dependent on an existing crytocurrency like Bitcoins or Ether and creating it should cost you not one penny of your fiat or “real” crypto-money.

Setup

The easiest way to archieve the goal would be to just follow the instructions on the new ethereum.org Homestead site closely, you can then use your cryptocurrency in the real and in the Morden testnet.

However, this approach has two limitations:

  • It takes longer than five minutes, which is our definition of really easy (but afterwards you will know why it works)
  • It runs on the real Ethereum blockchain or on the Morden testnet, but we want to build this using own very own, local and/or private, Ethereum blockchain.

If these limitations do not apply for me, stop here and go ahead and read the official tutorial.

Ok, I want my local, private blockchain, really fast, so let’s go…

Ready, Set…

  • Start Geth with an own genesis file and an unique networkid (greater than 1), for details see this post.
    You can use this genesis file, just store it as /ethereum/genesis.json (always add the drive for Windows, eg. c:/ethereum/genesis.json)

    {
        "nonce": "0xdeadbeefdeadbeef",
        "timestamp": "0x0",
        "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
        "extraData": "0x0",
        "gasLimit": "0x8000000",
        "difficulty": "0x400",
        "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
        "coinbase": "0x3333333333333333333333333333333333333333",
        "alloc": {
        }
    }

    and create the empty directory /ethereum/data
    The start command then is

    geth --genesis /ethereum/genesis.json --datadir /ethereum/data --networkid 123 --nodiscover --maxpeers 0 console

    we need this initial start with the console to create our first account, which we need to start mining.
    In the console, type

    personal.newAccount()

    and create your “etherbase”-account. Subsequent accounts can be created in the Ethereum Wallet.
    Make sure that you exit geth afterwards.

    …Go

  • Now, start the Ethereum Wallet, make sure Geth is not running currently
    There will be several dialogs, it does not really matter what you type in there. You should choose testnet if asked for real or Morden testnet.
  • Afterwards, when all steps have been completed, you will see an empty account in the Morden testnet

    ethereum-morden

  • Quit the Wallet.
  • To start the Wallet using our local testnet, consult the readme.txt in the installation folder and make sure you set the ipcpath cli argument correctly. On Windows, you can skip this step.
  • Start geth with this parameters (plus the ipcpath, if on Linux)
    geth --genesis /ethereum/genesis.json --datadir /ethereum/data --networkid 123 --nodiscover --maxpeers 0 --mine

After restarting the Wallet, we should see our created account with some Ether in it (we are mining currently and the difficulty is really low and we have no peers, so we get all the money)

account-start

Choose Contracts and Copy & Paste the code from the tutorial…

created-my-token

…linked on the contracts page

build-token

Don’t forget to set the arguments for your token/currency (like display name, initial supply, etc.)

arguments-token

Choose the fastest possible deployment (we have enough Ether right now).

fastest-deploy

Here we go, congrats to your very own cryptocurrency with Wallet support.

etherbase-mouc

Please comment on this tutorial, does it work for you? Did you get stuck at some step? We want to improve out tutorials to make sure more people use this great technology.

Entering the World Computer

Ever wanted to create your own, individual cryptocurrency?
Read on, if you reach the end of this post and have followed all instructions in the hands-on guide, you will have created your own working cryptocurrency in less than 20 mins.

How’s that?
The magic-happens-here part is done by the revolutionary technology named Ethereum or Ethereum Virtual Machine (EVM).

What is it?
Summarizing this great explanation: “blockchains are peer-to-peer cloud computers that collectively enforce a set of rules on a historical record that they create together. Bitcoin’s rules define a currency: how are new tokens produced, how many are allowed, how they can be transferred from one person to another, etc.
Ethereum’s rules define a process for defining new rules.”

Feeling a little “meta” here? For sure. Let’s try another definition:

“If you think of Bitcoin as a decentralized version of Microsoft Excel, then Ethereum is a decentralized Excel where we’ve made the visual basic macros functional, […] with the Bitcoin blockchain, each cell on this hypothetical Excel table holds just a number; on the Ethereum blockchain, each cell is home to an entire computer program.”

Before reading on, make sure that you understand this new dimension Ethereum adds to existing blockchain technology.
Your Bitcoins are static data blobs (yes, we are oversimplifying here, Bitcoins can be scripted. But nobody does.)
Your Ethereum contract can be a static data blob as well. However, it might as well be a condition checking for the release of your home’s lock after you paid your rent or Skynet trying to take over the world.

In essence, the new dimension of Ethereum consists in each “coin” being a turing complete computer program running in a peer to peer cloud.

Not excited by now? Ok, let’s take another perspective.

Even if you don’t hack a new facebook or google at night, you should be able to read and understand this program

contract token {
 mapping (address => uint) public balanceOf; // [1]

 function token(uint supply) { // [2]
   if (supply == 0) supply = 10000;
   balanceOf[msg.sender] = supply;
 }

 function send(address receiver, uint amount) { // [3]
   if (balanceOf[msg.sender] < amount) return;
   balanceOf[msg.sender] -= amount;
   balanceOf[receiver] += amount;
 }
}

with a little help by this walk-through:

[1] We are assigning an address to an “amount” (in many languages a dictionary, in Java a Map, you name it. A simple Key/Value Store)
[2] A constructor (in many (OO-)languages a initializer for the new object). Here this initializer is called once during the whole lifecycle of a smart contract: when the contract is written in the ledger (deployed). msg.sender is the address of the creator of the contract. He gets all the money.
[3] A very simple function which makes sure that the storage status can be changed, otherwise the programm would be completely static. Changing the storage status means transfering/sending amounts from one key (address) of the dictionary to another key.

So, here we are. Maybe you got it already, this is your own, individual cryptocoin. It starts with an amount of 10000 “items” which can be subdivided and sent to other addresses. This is exactly the minimum functionality of a cryptocoin.

Before you go on, try hard to understand what happens here – we are facilitating the properties of a cryptocurrency blockchain (cryptography, consensus algorithms, peer to peer technology), everything eg. the Bitcoin blockchain has, for our own rules. These rules are just transfering a value from one address to another and storing the result. That’s exactly as usual cryptocurrencies do.

Our cryptocurrency is one app (also called dapp for decentralized app) inside the Ethereum blockchain. See it as one really smart Bitcoin simulating the whole Bitcoin system itself (we are going meta again).

Ok, enough head spinning, let’s try this out.

Hands-on Guide to your own Cryptocurrency

One word of warning: after this tutorial, you will have your running smart contract in the (local, private) Ethereum chain, but you will most certainly not have understood how this is working.

To understand the principles and technologies behind Ethereum, I strongly advise visiting these sites:

  1. The Ethereum Main site: your entry point to Ethereum
  2. The Ethereum Frontier Guide Gitbook
  3. The Ethereum Builder’s Guide Gitbook
  4. A 101 Noob Intro to Programming Smart Contracts on Ethereum
  5. (Hands-on) How to create a Private Ethereum Chain 

This tutorial mainly is just a very compressed rewrite of those sites.

Ok, to be clear about the 20 minutes: reset your stopwatch now, we are counting the time from now on.

What’s the tutorial about?

  1. Creating a  local, private Ethereum chain
  2. Setting the stage
  3. Deploying our cryptocurrency in cosmo.to

Creating a local, private Ethereum Chain

We will start with installing Geth, the Go implementation of the Ethereum protocol. We chose Geth because it runs in Linux as well as Windows without having to install any dependencies before and with a dead easy installation procedure. (Might be a good point for Golang)

All instructions are in the Ethereum Guide, however the Windows link is wrong currently, use this one.

Now, here’s the important part missing in the main guide for using specific Ethereum chains:

A Ethereum chain is defined by two factors, which are unique to each chain: the network id and the genesis block. The genesis block is the big bang of your own Ethereum universe and the values there are the cosmological constants of your universe. If you want to participate in a specific Ethereum chain, you will have to

  • have a network connection to a running node
  • know and use the network id (given as command line parameter)
  • use the identical genesis block

Our genesis block looks like this, save this as genesis.json to some directory. All parameters are explained in detail here.

{
 "nonce": "0xdeadbeefdeadbeef",
 "timestamp": "0x0",
 "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
 "extraData": "0x0",
 "gasLimit": "0x8000000",
 "difficulty": "0x400",
 "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
 "coinbase": "0x3333333333333333333333333333333333333333",
 "alloc": {
 }
}

Now, if you start Geth with these parameters

geth --genesis genesis.json --datadir somedatadir --networkid 23 --rpc --rpcaddr="localhost" --rpcport="8080" --rpccorsdomain="*" --maxpeers=1 console

the most important part is already done. With genesis.json and network id 23 your chain is defined and whoever wants to play with it has to agree on the genesis and the network id. Or she could just start her own universe with different cosmological constants, just like in real life. If you believe in multiverse theory. And in real life.

Setting the stage

Actually, the node we started above does not do much, it just sits around and does not mine Ether. Therefore, our universe has no “time”, it is static. We have to create a primary, “etherbase” account, to facilitate mining which we need for deploying our contract.

We are in the console now, just type

personal.newAccount()

you will get back a address like ‘0x693309002d4fbb672c90df7063b75b42055f5449’, which is your primary account address. Do it a second time to have another account. You will feel lonely otherwise transfering your new currency between you and you.

Now exit the console and restart with

geth --genesis genesis.json --datadir somedatadir --networkid 23 --rpc --rpcaddr="localhost" --unlock="0x693309002d4fbb672c90df7063b75b42055f5449" --rpcport="8080" --rpccorsdomain="*" --maxpeers=0 --mine

At startup, you will be asked for the password, just type it in, even if the console is moving, your keystrokes will be recognized.

This time, our universe is ticking. We can go on.

Deploying our cryptocurrency in cosmo.to

Right now our operating system is running, but using it as a developer is quite complicated. You have to compile your contract to bytecode first, using a compiler like solc and afterwards have to deploy the contract.

Of course, using it is also not the most intuitive thing. Remember the first days of the internet, of Java Applets, mobile application development on Android – there you are.

However, for this early stage in the history of the “internet of value” there exist quite a lot tools which ease development, one (to me the most stunning) projects is cosmo.to

It is based on the solidity browser, but adds a lot of usibility, try it yourself. Open cosmo and follow the notes in the attached screenshot.

Choose “auto” compile, copy the sample token source code from above and deploy it. The last step is crucial, since this makes our application usable. It is like running your executable or, in more modern terms, deploying your application to Bluemix, Amazon AWS, the Google Cloud, whatever. But your application has guaranteed 100% availability, and noone can shut it down. If you deploy it to the real Ether chain that is.

For our local Ethereum chain, your contract has now been mined (by yourself) and added to the ledger.

cosmo

Congratulations! The logic can now be executed and cosmo helps you a lot in using it. Use “call” to query the state and “transact” to change the state. Send your new currency to your 2nd account. You will have to wait some time (depending on the speed of your somputer) till the transaction is executed, so don’t wonder if the call does not succeed for some time.

Now play around. Do you get it? Create new accounts, send your token/coins around. This really is a value-exchange (even a currency) if you want to and the others, who are using your contract, agree with you.

They do not have to trust you at all, anybody can easily deduct that the initial amount of your coins is fixed at 10000 and cannot be extended. This is written in the contract and really nobody can change this, as nobody can change the Bitcoin ledger.

When people will really understand this trustless system, which can now not only transfer static value, but also run any application you can think of, we are sure that great things will emerge. And now you can be part of the universal Dapp system development. Have fun!