paint-brush
What on earth is a smart contract?by@kunal.shah
4,556 reads
4,556 reads

What on earth is a smart contract?

by Kunal ShahNovember 21st, 2017
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

In 2009, Satoshi Nakamoto <a href="https://bitcoin.org/bitcoin.pdf" target="_blank">introduced bitcoin</a> and shook the world as it spawned a $150 billion cryptocurrency, a network 10,000 times more powerful than the 500 leading supercomputers, and a movement towards a decentralized financial system.

People Mentioned

Mention Thumbnail
Mention Thumbnail

Companies Mentioned

Mention Thumbnail
Mention Thumbnail
featured image - What on earth is a smart contract?
Kunal Shah HackerNoon profile picture

Bitcoin vs. Ethereum

Bitcoin overview

In 2009, Satoshi Nakamoto introduced bitcoin and shook the world as it spawned a $150 billion cryptocurrency, a network 10,000 times more powerful than the 500 leading supercomputers, and a movement towards a decentralized financial system.

Bitcoin is a continuously growing list of blocks and each block contains a set of transactions which represent the transfer of ownership of a bitcoin and a hash of the previous block to link the history of transactions and create an immutable set of records. A public/private key cryptographic scheme is used by the network to verify the validity of these transactions. Bitcoin uses proof of work to for block generation by requiring a key that is enormously costly and time-consuming to produce, but easy for other nodes in the blockchain to verify. Finally, Producing a proof of work is colloquially known as mining.

Enter Ethereum

While bitcoin is a peer to peer electronic cash system used to track ownership of a digital currency, Ethereum was created as a peer to peer system used to keep track of state changes to a decentralized database. Ethereum is also a continuously growing list of blocks: each block contains a set of state changes to the decentralized database. Furthermore, Ethereum makes use of a proof of work system similar to that of bitcoin for mining.

Ethereum introduces decentralized database detailed in the Ethereum whitepaper. It provides a decentralized Turing-complete virtual machine, called the Ethereum Virtual Machine (or EVM for short). The difference from bitcoin is that this new data layer provided by Ethereum on top of the blockchain makes it possible for functional code to be distributed along the decentralized set of nodes. The code is run by each of nodes in the network, which maintain and alter states within the database. This is why Ethereum is often described as a “world computer.

However, the EVM must be governed by a set of rules separate from a central authority that dictate what state changes are permitted.

Smart contracts

A smart contract is a “computerized transaction protocol that executes the terms of a contract.” These are not entirely unique to Ethereum, as Bitcoin allows using smart contracts to build services to add functionality on top of bitcoin transactions. Although these services use bitcoin, they’re inherently centralized because their smart contracts must be hosted on a centralized server.

Ethereum, on the other hand, lets developers program their own smart contracts to define EVM instructions. These smart contracts can be written using friendly programming languages modelled on existing languages like JS and python.

Smart contracts live in the form of bytecode within the decentralized database. This is the root of the innovation and disruptive potential of Ethereum

All nodes on network executing the code using the EVM must come to the same result and reach consensus to agree on the next block’s state. Anyone can deploy a smart contract to the decentralized database for a fee proportional to the storage size of the containing code. Nodes wishing to use the smart contract must somehow indicate the result of their participation to the rest of the network.

Gas

Gas is what incentivizes nodes for participating in the network and computing jobs to deploy smart contract into the database or perform jobs corresponding to user interactions with existing contracts. In other works, smart contract transactions require operation to perform, but someone has to perform these operations, and that takes gas. When a user makes a smart contract function call, they must declare the amount of gas and pay that amount. This not only motivates miners to compute jobs, but motivates developers to deploy efficient code to optimize the use of deployed protocols for users and ensure an appropriate fee is paid for transactions submitted to the network. Since the EVM can execute code of arbitrary complexity (which is what makes it Turing-complete), choosing a free based on the length of a transaction is not always accurate.

So how do you write a smart contract?

Solidity is a Javascript-like language developed specifically for writing smart contracts. The solidity compiler turns code into EVM bytecode, which can then by sent to the ethereum network as a deployment transaction. Such deployments have larger transaction fees than smart contract interactions and must be paid by the owner of the contract.

Why does this all matter?

Let’s use crowdfunding as an example. Popular crowdfunding websites like Kickstarter and Gofundme aim to bring novel products, causes, and missions to life, but the crowdfunding systems are often plagued by founders who fail to meet expectations. Even worse, we’ve all heard of stories where fraudulent founders introduce a visionary — but technologically impossible — product, and proceed to raise tens of thousands of dollars, only to drop their mission soon after and disappear with the money. This phenomenon is a systematic failure and inefficiency caused by placing all authority over funding in the hands of a single center figure to hold both donors and founders accountable.

Centralized authority inefficiencies can be solved by Ethereum.

The smart contracts enforced by Ethereum as previously described can hold all parties who engage in a contractual agreement or transaction accountable by enforcing the following process:

  1. The database collects money from donors and stores funding in an account with no owner.
  2. Funds are kept from founders until they provide proof of progress that satisfies a sufficient proportion of donors, similar to the way public companies are accountable to their shareholders.
  3. When milestones are met, funds are released.
  4. If founders fail to meet expectations or to bring a product to market, funds are returned to donors.

Finally, all four steps are performed without a central authority like Kickstarter or Gofundme. The EVM brings a system of security, decentralization, reputation, and accountability that will expand upon and eventually revolutionize centralized applications in every industry.

Thanks for reading!

This post was derived from a lecture delivered as part of Rice Blockchain. Material and slides were prepared by Kunal Shah, May Zhong, Yorke Rhodes IV, and Yucheng He. You can learn more about what we’re doing at Rice Blockchain by visiting our website.