Blockchains and crypto currencies are an exciting topic, and they are trending right now because the price of crypto currencies are shooting up. You’ve probably heard of Bitcoin, the largest crypto currency by market cap, and probably also heard of Ethereum, the second largest crypto currency by market. What might come as a surprise for you (it did for me) is that Ethereum dos not sell itself as a crypto-currency. It sells itself as a globally shared virtual machine.
- What exactly does this mean?
- Where does the blockchain fit in to this?
- Where does the crypto currency fit in
- What’s the use? Why not just use a giant JVM?
I’m no expert and there are plenty of good references out there for you to learn these topics in detail. In this post I will just try to briefly answer these 4 questions.
What is a Virtual machine
Lets start by answering what is a virtual machine. A virtual machine is a program that will abstract away the details of the machine its being run on. When we write in a higher level language, like python o C for example, a simple adding statement will be unwrapped into “machine-code”. Ex.
c = a + b
The above statement might be unwrapped to something like:
MOV R1, A ; Move value from memory address A to register R1
MOV R2, B ; Move value from memory address B to register R2
ADD R1, R2 ; Add value in register R1 with register R2 and store in register R1
MOV C, R1 ; Move value from register R1 to memory address C
So even simple language operations get translated into quite a few processor instructions. The annoying thing is that each processor can be slightly different, with a different number of registers or some special instructions that make some operations faster. There are also some of these instructions that delegate work to the underlining operating system So in order to have your program run on lots of different processors and operating systems, you will need to recompile your program for every combination of processor-OS that you want.
A Virtual Machine (VM) can help solve this problem by defining a single set of of instructions that the virtual machine will understand. Instead of compiling your program to the OS/processor instruction set you will compile your program to the VM instruction set. Then any computer, phone or toster that has this VM will be able to run your program. Of course the virtual machine itself still needs to be compiled for each architecture, but its still better than having to recompile every program.
This is what Java does with the Java Virtual Machine (JVM) and its one of the reasons Java became so popular. Its also one of the reasons android uses Java.
So the Etheruem Virtual Machine defines a set of basic instructions it will understand. This answers our first question about what is a virtual machine, but we still haven’t talked about blockchain.
Where is the Blockchain in all of this?
You might have heard that a blockchain constitutes of blocks of transactions chained together by hashes of their parents. I will not explain the mechanics of this, if you are not familiar this is video is a good starting point. What I want to cover is the idea that a blockchain is actually a database. To understand the connection, lets take a moment to look at a simple key-value store.
Key value stores accept 2 kinds of operations, GET and SET. GET is read only but the SET operation modifies the state of the database. Now that we have a database lets think about how we can make a copy of it. The most straight forward way is just to create a snapshot of all records and send it.
But what happens when a new SET operation comes in. The copies are now out of sync. If we keep sending full copies every time there is an update it can become very expensive and slow. An alternative is sending a stream of all SET operations so that the copy database can replay them in order.
This idea that a database is a snapshot of a series of operations is very common and is even used internally in some databases to be able to recover from crashes mid operation. Replication Wiki
In the case of blockchains, the blockchain itself is a log of all database transactions. By replaying all transactions in order you get the current state of the database. In the case of Bitcoin this database is a key-value store of account balances. In the case of Ethereum this database includes the account balances but also includes all the programs (smart contracts) available and some program “logs” and some general information storage, essentially it is the full state of the Ethereum Virtual Machine.
Wasn’t Ethereum a Crypto currency?
So we’ve covered how ethereum is a virtual machine and how blockchains are a form of database replication. But what about the crypto-currency, wasn’t that the main part? The currency does play an important role in tying up the loose ends. Lets look how.
We have our virtual machine, and we have made it replicated world wide and freely available online. How can we prevent malicious attackers from filling up our database with cat pictures?
To solve this we add fees to our virtual machine. Just like in a normal machine computation takes energy and time, in our virtual machine each computation takes energy and time from every node on the network. With Fees for each transaction the attackers will only put in the amount of cat pictures that fit in there budget. :) problem averted! But of course we cant use normal credit cards or third-party payment system because that would defeat the decentralized nature of blockchains. So the payment will be done in a native currency ETH. Every transaction has a transaction fee called gas.
The currency in the network has 2 sides to it. On one side, it disincentivizes attacks to the network by making it less economically viable. On the other it offers an incentive for those who help make the network more secure executing the proof of work. (There is also proof-of-stake which ethereum will switch to in the future.)
Why not just use java virtual machine?
So whats the point of all of this? Why create a new type of virtual machine? why put it on a blockchain? And why should we take a made up currency seriously? Plus all this validation and replication makes computations on EVM very slow, we are used to subsecond latency from backend services, EVM operates in the range of ~10s. I can’t say I know the answer to any of these questions, unfortunately. But I am excited about this tecnology and curious about what it could bring.
The main selling point of blockchain is that it is a shared state. Its not just shared in the sense that we can all send a document to each other, its shared in the sense that we can all be sure we are looking at the same data. We can be sure that the copy we got wasn’t tampered with. What applications will need decentralized consensus at its core, is the billion dollar question.
There are few applications that are already taking advantage of this: Decentralized Financial Services (DeFi) and Ownership Certificates backed by the block chain, mostly called Non-fungible tokens (NFTs). I encourage you to read about these applications. But I also think that there could be more exciting applications that we haven’t thought of yet.
No one would have guessed 30 years ago how central the internet could be today. And yet today we only remember it when it is slow or not working. The internet is not exciting, its just infrastructure, its what we build on top of it that we have come to rely on. I see the Ethereum Virtual Machine as a great piece of infrastructure and I think a successful future for Ethereum is one where people use apps that rely on it but only remember about the blockchain when it is slow or congested.