How does the Blockchain know about the World? And what do Oracles have to do with it?

in #cryptocurrency7 years ago (edited)

Well, the world knows about Blockchain, that's for sure. My mother heard about it. Even financial dinosaurs like JPMorgan get het up on it!

However, how about the other direction? Does Blockchain know about the world? In fact, the good ol' Bitcoin Blockchain does not have to care about the World that much. If Alice wants to send Bob 1 BTC, there are only two things that matter to the chain. First, it needs to know if Alice has the appropriate funds and does not double spend her money. Secondly, the chain checks that Alice has her private key ready to sign her transaction and prove that the funds were really hers.

btcvsteth.png

Still, there is another Blockchain (indeed there are a couple, but let's focus on one) where the things in the real world matter much more to the inner workings of the chain. I am talking about Ethereum. The Ethereum Blockchain or, more precisely, the Ethereum Virtual Machine (EVM) is Turing complete. In other words, it's a a computer a bit like the laptop I'm writing this article on.

Computers excel when they have data to crunch on. For instance, Google maps finds you the shortest path from A to B almost anywhere on the planet, Spotify servers select songs that suit your mood perfectly out of a catalog of millions of entries, or you can query the Wikipedia servers for knowledge about basically anything. In comparison to all of these applications that harvest information from the real world, the Ethereum Virtual Machine has a substantial shortcoming. It is a closed system! By design, it cannot interact with the real world directly. And this is a real problem!

Let's found an Umbrella Start Up

Imagine you design a smart contract, that's how programs in Ethereum are called, that allows the rental of umbrellas. Yes, that's right, this is a real business (and so are Trump Tokens ;-) )! In fact, China is currently drowning in rental umbrellas, but that's another story.

So, people can send ETH to your contract and in exchange take an umbrella. And your contract is indeed smart: You check the weather forecast and in case of upcoming rain, you want to increase prices. But wait, how does the weather forecast get into your smart contract if Ethereum is a closed system? It never rains in Southern Ethereum!

Now you have to bear with me a little while. Let's first understand why Ethereum is such a closed system before we try to figure out a way to get around this.

Ethereum Blockchain and Virtual Machine in a Nutshell and why it's locked up!

Basically, any Blockchain is a distributed database with data organized in chunks or so called blocks. Each block only contains data that can be verified and agreed upon by anyone participating in the network. For Bitcoin this data is simply transaction logs. In terms of Bitcoin, verification means checking that money is only spend once and only by nodes that do own the money. In contrast, in Ethereum data can be more complicated. It can actually contain (compiled) source code. This means the process of verification involves executing the code and computing results.

And that is the hook! Such that everyone in the Ethereum network agrees on a new block of data, the code execution must yield the very same results in every EVM, i.e. in every computer on every node participating in the network. Imagine one computer node executing your smart contract with an API call to a weather forecast website, and the forecast predicts rain. A few seconds later another node executes your contract code in the same block and the forecast server decides to change its prediction to a sunny day. Both nodes could not agree that the new block is legit because the execution of the very same code gave two different results, like in the image below. In blue the blocks of the chain are given, and your contract is executed in the newest one with number 200124:

oraclize_steemit_post.png

Finding network consensus and building a Blockchain would be impossible in this case. Therefore, EVM computations live in a closed system. Your contracts cannot access data from the outside world directly in order to guarantee that Ethereum code execution within one particular block produces always the same results.

The Miracle of Oracles

Still, for your umbrella contract weather data would be terrific. How do we get it into the closed system?
The solution to our problem is called an Oracle. By the way one of the most widely used ones in the realm of Ethereum is Oraclize.

1024px-Tholos_Athena_Pronaia.JPG

As discussed above, code execution must always yield the same results within the same block. So, if we could spread the weather data request and weather forecast receiving across different blocks, our problem would be solved. Indeed, this is what Oracles can do for us. Instead of sending an API call to the weather server directly, we send an Ethereum transaction to an Oracle account. We put our wish to call an API into the data payload of the transaction. The Oracle is basically another server that listens for incoming Ethereum transactions and parses their data payload. In our case it will identify our API call, forward it to the weather forecast server, and collect the forecast result. Subsequently, it will pack the forecast result into another Ethereum transaction with our contract as the recipient and send it at least one or even several blocks later, see image below:

oraclize_steemit_post2.png

The transaction will be broadcast to all the nodes in the Ethereum network. Thus, when executing our contract code, all nodes will know that the forecast result was indeed rainy and only rainy weather. Now your umbrella contract can utilize (and monetize) the weather forecast without breaking network consensus. We will further dive into Oracles and discuss in detail how to use them in smart contracts in future stories. So stay tuned!

By the way, we also apply Oracle calls in one of our contracts. In our case the contract needs to know who the president of the United States is (by the time of writing it's still Donald Trump :-/). You can check out our application of Oracles in our Trump Tokens ICO!

Sort:  

@trump-tokens So much information thanks for sharing.

Thanks, stay tuned for the next parts with the nitty gritty details :-), and check our application of an Oracle with our Trump Tokens!

Coin Marketplace

STEEM 0.30
TRX 0.12
JST 0.033
BTC 63642.15
ETH 3126.93
USDT 1.00
SBD 3.87