What is a Smart Contract?

The Power of Smart Contracts

Smart contracts can be defined as autonomously executing contracts implemented in computer code. This concept has been around for many years and was written about by Nick Szabo in 1996. However, real-world applications have only been possible since the advent of blockchain technology.

The Blockchain allows smart contracts to be stored immutably and executed with no trusted third parties, such as notaries and lawyers.  Our Hatch students will be thoroughly trained and practiced in smart contract development.

The Ethereum Smart Contract Platform

In practical terms, smart contracts require a powerful Turing complete virtual machine implementation of a blockchain that allows the programming of any operation that can be expressed in computational terms.

Ethereum was the first such platform and after overcoming some initial problems has moved on to become the de facto standard for smart contract development based on an open permissionless blockchain.

Smart contracts on Ethereum can be programmed in several languages to be compiled into Ethereum bytecode, with Solidity being the most common. Contract deployed on Ethereum exist at a contract address which apart from the smart contract can hold value in Ether, Ethereum’s own currency. Ether is also required to invoke contract transactions in the form of gas, a payment required to stop contracts from misbehaving and hugging resources. Contract transactions are validated by consensus amongst nodes through mining. Hence, once a transaction has been confirmed a single version of the transaction and the contract’s state exists throughout the whole system.


Smart Contract Example

Let’s look at a simple but powerful example contract:

  1.  contract timedPayment {  
  2.  uint unlockTime;  
  3.  address recipient;  
  5.  function timedPayment(address _recipient, uint timeDelta) public payable {  
  6.  recipient = _recipient;  
  7.  unlockTime += timeDelta;  
  8.  }  
  10. function withdraw() public {  
  11. require(msg.sender == recipient && now >= unlockTime);  
  12. msg.sender.transfer(this.balance);  
  13. }  
  14. }  

The contract allows making a time-locked payment between two parties. A sender creates this contract including a certain amount of Ether in the contract creation transaction (constructor call) and specifies a recipient address and a waiting time in seconds. The recipient can call withdraw() to receive the payment only after the waiting time has expired. If a withdrawal is attempted earlier, or by someone else, the transaction fails.

Even without knowing Solidity, if you are familiar with another programming language you can probably make sense of the code. If not, do not worry for now. The example just serves to show how powerful smart contracts can be.

Software Engineering Challenges

Smart contracts are computer programs that run on a decentralized peer-to-peer network transparently. This means that designing and writing smart contracts presents challenges that do not exist in other software engineering disciplines:

  •   Nothing is private: Whilst the concept of private variables exists in Solidity, there is no protection on the underlying Blockchain. Storage is readable by everyone on the network which makes it impossible to store secrets without worrying about complex encryption patterns.
  •   Functions calls execute in transactions:  The transactional nature of the Blockchain means it is inherently asynchronous. Transactions are sent and only confirmed sometime after when a miner includes them in a block.
  •   The Blockchain is deterministic: A transaction executed on different nodes has to execute exactly alike. This makes things like generating random numbers very difficult because of a lack of entropy.  
  •   Gas costs: As mentioned, code execution and storage on the Blockchain comes with a cost. Being aware of this cost and optimizing gas usage is essential to a successful business on the Blockchain.

Besides the above, smart contracts often move large sums of money and are therefore attractive targets for cyber-criminals. In the recent past, quirks of the Solidity language and simple mistakes have caused incidents in which large amounts of Ether have been stolen or frozen.

Whilst smart contracts are about removing trusted third parties, this means there is no arbitration or manual backup in place. Software engineers are not lawyers and the absence of banks means that securing any money involved is now the responsibility of the end-user.

The Blockchain requires a new software engineering paradigm with a focus on cybersecurity and other Blockchain specific elements. There is a lack of trained professionals which we at Hatch Crypto will do our best to solve.  Join a Blockchain class or hire a developer, or just stay in touch with us! 

By | 2018-05-06T12:14:44+00:00 May 6th, 2018|Uncategorized|

Leave A Comment