Analyzing Smart Contracts - Executable Distributed Code Contract (EDCC)

Words
1143
Reading
6 min
Listen
Play
8y

Smart Contracts are EDCC (Executable Distributed Code Contract) which are the digital version of written agreements between parties. They are programmable code that execute according to a set of terms and conditions. It follows the “IF-This-Then-That” logic of execution. They require a platform to perform functions on a blockchain network. Once the contract executes code, the resulting transaction is then recorded on the blockchain. The most popular and widely used is on the Ethereum blockchain. To develop an Ethereum Smart Contract, the programming language used is called Solidity. Many cryptocurrency projects use a type of Smart Contract called an ERC20 token during their ICO (Initial Coin Offering). These tokens defined how funds were allocated, which is how money is raised during an ICO. The buyers of the token purchase an ERC20 in order to get into the system. The ERC20 tokens are issued since there is no direct fiat pairing for a new cryptocurrency. So what happens here is the Smart Contract in the form of the ERC20 token allows the project to raise money in fiat which goes to funding. Smart Contract’s are applied with business logic to execute code to transfer funds upon meeting a certain condition (IFTTT logic ). In order to execute these contracts on the Ethereum network, a fee is charged called “gas” which pays the nodes or computers on the network that process the transaction. It is distributed to all nodes and executed on an EVM Ethereum Virtual Machine in bytecode, interpreted by the rest of the network. The transaction then becomes transparent to all once it is put on the blockchain.

Screen Shot 2018-05-06 at 4.33.02 PM.png

Example environment using Javascript VM for testing

Screen Shot 2018-05-06 at 4.37.34 PM.png

Some details found in a Smart Contract

Here are things that Smart Contracts can do:

  • Allow “multi-signature” accounts, allowing execution only when a certain number of people verify it
  • Manage agreements when purchasing assets and other settlements
  • Transfer of ownership of an asset
  • Provide a utility to other contracts
  • Store information that is immutable and tamper proof

There are 2 main features a Smart Contract has:

  1. Turing Completeness - A simulated system that can compute anything given the resources to do so. It allows logic to be written to perform an operation from code. It is needed for to implement more complex and sophisticated rules that are written in code to be executed by Smart Contracts.
  2. Rich Statefulness - The ability of a system to remember things at a blockchain level. What is coded must be consistent across the entirety of the blockchain, big or small. It is this flexibility in Ethereum that makes it more robust for distributed application development or DApps.

Both features are key, as you cannot have a Turing complete system without statefulness in most cases. Vitalik Buterin, Ethereum’s founder, has said before that ETH should not have been marketed as just Turing complete. It is the feature of rich statefulness that makes it work, though it still needs to be Turing complete.

The biggest criticism against Smart Contracts is also what it was designed for, transparency. It is visible to all users on the blockchain. That means it is prone to security holes, bugs and even exploits. This has already happened before because of poorly written code in the Smart Contract. The Ethereum blockchain and Smart Contracts are not themselves vulnerable to hackers, it is the bugs in the Smart Contract that developers wrote. These bugs are mostly errors in logic that can be exploited. A fine example of this is the DAO hack, which allowed a bad actor to get away with large funds due to a a "recursive call bug”. That would eventually lead to a hard fork which split Ethereum, as that was the fix the core developers agreed on, though it was not something everyone agreed on. Another incident is the infamous “Parity Wallet Hack” which hinted at a hard fork to recover funds that were “accidentally locked” due to a bug in the wallet’s design. A user named “devops99” made a critical mistake using a critical kill() method to change ownership of a Smart Contract. Unfortunately this locked the funds instead. It appears the library for the wallet was not properly initialized which means anyone could take ownership. Devops99 may have accidentally taken ownership of a wallet, but instead made some mistakes along the way. This lead to 500,000 ETH getting locked permanently, which is how the system was designed to handle such situations.

Despite the security flaws, smart contracts have evolved to Blockchain version 3. Projects like EOS and NEO are building platforms for a new generation of smart contracts that offer zero to lower fees and faster transaction speeds. Much of the emphasis on Smart Contracts is that it can simplify many types of transactions in sectors like real estate, property sales and even actual business contracts. The reasoning for Smart Contracts is that when it is developed solidly, it can be deployed successfully.

In real world applications these are a way to automate a business process, like transactions in selling items. It provides transparency and convenience and also speeds things up. Here is an example in real estate. This is has been simplified as a proof of concept. The execution of the Smart Contract is conducted on a digital public ledger which is recorded permanently thus there can be no dispute of ownership. The Smart Contract is activated once the payment has been made, in this case using ETH. The first actual real estate Smart Contract was successfully executed on the Ethereum blockchain by Propy, announced back in October 2017.

Screen Shot 2018-05-06 at 4.15.29 PM.png

/* Allow the contract to spend ETH token
Function APPROVE(Sellers_Address, Amount_Value)

/* Buyer AGREES TO PAY Seller
If Amount_Value is 1 THEN
EXECUTE SMART CONTRACT
TransferFROM Buyers_Address to Sellers_Address
Transfer RETURN 1

The rules and logic are coded in the smart contract so there is no need for a broker and lawyer to confirm. There is no other party but the buyer and seller of the house with the ETH network as the facilitator of the transaction. There is trust because the documents are encrypted in the smart contract on the blockchain accessible as a shared ledger. There is no way the buyer or seller can deny what they agreed on and it is secured from manipulation. The process can be done in minutes rather than hours since most of the business process is in the smart contract code. Just note that for legality purposes, the documents still require compliance with contracts in selling a house. This also saves money since no intermediary is required. So the benefits are autonomy, trust, security and savings.

Screen Shot 2018-05-06 at 4.43.37 PM.png

A schematic diagram of a Smart Contract (Source: Blockchain Council)

Suggested Reading:

World's First Real Estate Smart Contract
https://www.blockchaintechnology-news.com/2017/10/02/worlds-first-real-estate-purchase-ethereum-blockchain-completed/

Simplified How Smart Contracts Work
https://www.coindesk.com/information/ethereum-smart-contracts-work/

If you found this presentation useful let me know. I also appreciate tips of any sort, thank you.

Ether
0x6FD4d4f9DF72ce1af115aa87d12E846A1D7e5e23

Analyzing Smart Contracts - Executable Distributed Code Contract (E... | Ecency