fbpx

A BRIEF ANALYSIS AT THE ETHEREUM SMART CONTRACTS

INSIGHT

A BRIEF ANALYSIS AT THE ETHEREUM SMART CONTRACTS

Initially, I thought that Ethereum was a thing that would be used for people to write simple financial scripts. As it turns out, people are writing stuff like Augur on top of it. -Vitalik Buterin

In last years, with the increasing of Blockchain-based technologies and with the born of always new cryptocurrencies, the concept of Smart Contract started to sound louder and louder. Let’s try to briefly explain what they are and why they are becoming increasingly important and used in in the most varied contexts.

A Smart Contract is just a program, written in a particular programming language (either Turing-complete or not) that run as programmed, without being able to be censured or manipulated, where the code is law and with the aim to facilitate operations between people and institutions.

We can find Smart Contracts in many environments.

how do smart contract work

Examples of Smart Contract on different platforms.

For example, Bitcoin utilizes Script, a Forth-like reverse-polish notation stack-based, processed from left to right, very simple programming language. A Smart Contract in Script is just a list of Opcodes instructions recorded with each transaction. However, although Bitcoin Smart Contracts are functional to the objectives set, they are not widely used in many scenarios. One reason could be the fact that Script is not Turing-complete, avoiding the possibility of using loops or cycles.

Currently, the most known Smart Contracts are those of Ethereum, which are also the main focus of this brief discussion. They can be written in several programming languages such as Solidity, Serpent and LLL. Solidity, the most popular among these, is a high-level language, influenced by C++, Python and JavaScript. It is designed to target the Ethereum Virtual Machine, the Ethereum byte-code execution environment that every node runs to be able to send and receive transactions.

A Solidity Smart Contract looks like this

pragma solidity ^0.4.21;
contract Coin {

// “public” rende le variabili
// accessibili dall’esterno
address public minter;
mapping (address => uint) public balances;

// Gli eventi permettono ai client di
// visualizzare i cambianti nella Blockchain
//  in maniera efficiente
event Sent(address from, address to, uint amount);

// Costruttore che viene eseguito
// solamente quando il contratto viene creato
function Coin() public {
minter = msg.sender;
}

function mint(address receiver, uint amount) public {
// msg.sender è l’indirizzo di colui che fa la transazione
if (msg.sender != minter) return;
balances[receiver] += amount;
}

function send(address receiver, uint amount) public {
if (balances[msg.sender] < amount) return;
balances[msg.sender] -= amount;
balances[receiver] += amount;
emit Sent(msg.sender, receiver, amount);
}

}

As one can see, Solidity is also a contract-oriented programming language, meaning that it there exists keywords dedicated to who makes transactions, to ether send and received and much more. We don’t go deeper in further technical details about the syntax. A complete guide can be find here.

With a Smart Contract one can program many type of scenarios, from a simple storage of data, to the triggering of certain operation after receiving money, from decentralized application (Dapps) to decentralized games.

how do smart contract work

CryptoKitties is one of the world’s first games to be built on blockchain technology.

As all the transactions in Blockchain, also Smart Contracts are permanently stored without any possibility of modifications. This means that once done the deploy of the contract on the chain, it cannot be altered. For this reason, security in Smart Contract is of fundamental importance. In fact, just think that ether can be managed by them and so, even just a small error in the logic of programming, can result in large economic losses. A “famous” example is about the drama of DAO, where wrong implementations of a part of the code led to millions of dollars/ether losses.

Developing Smart Contracts is not an easy task. To help with it, there exist some best practices, that allow a programmer to know how not to set up a contract preventing serious points of failures. Also, as support tools there exist many software, such as Truffle in case of Ethereum, that allow to safety code in a local environment to better test in all possible ways Smart Contracts before the final deploy.

Smart Contracts can be a very powerful tool able both to create value, security and efficiency, but also to being used to create chaos from even simple errors. For this reason, one should be particularly careful in coding them and deploying in the main network, if they manage sensitive data or money.

2018-05-11T11:37:43+00:00 By |Categories: Insight|Tags: , |

About the Author:

LATEST ARTICLES

By | August 10, 2018|

GRAALVM: THE HOLY GRAIL OF VIRTUAL MACHINES

Read more

By | August 2, 2018|

FROM THE DESIGNER’S TOOLBOX: USABILITY TESTING

Read more

By | July 27, 2018|

SOFT SKILLS, HANDLE WITH CARE

Read more