Sunday, November 29, 2020

Oracles on Clarity with Blockstack’s Stacks

Blockchain technology relies on its pillars of distributed ledger technology & cryptography for data authentication & segregation of what is right from the wrong. Its origins date back to 2008, the period which was marked by a global financial crisis of 2007-08, which impacted all the economies of the world. Second only to the great depression, it caused a loss of over $2 trillion in global economic growth. The period saw the decline of major financial giant Lehman Brothers on 15th September 2008, it was a 150 year old company bankruptcy of which couldn't be revived ever. It raised questions on the entire banking system, if such an old company could die then none of the existing financial entities could be relied on. The integrity of the whole financial system became questionable. 

It led to the birth of Bitcoin on 31st October 2008, a term most synonymous with Blockchain, Cryptocurrency & DLT (Distributed Ledger Technology). It was invented by the pseudonymous Satoshi Nakamoto. Any blockchain technology relies on three basic tenets:

  1. Distributed Ledger: it is a form of a database which is synchronised across multiple nodes, it has the details of all the transactions that have been completed to date, the amount transferred, ownership details etc. It is called distributed as multiple copies of the same ledger exist which are carried by multiple people/nodes. The traditional banking system had just one ledger present with the main entity. As this is distributed, all the nodes speak the same version of truth and fraud is kept under check. It can also be referred to as a global public ledger of past transactions.
  2. Hashing & cryptography: Hash is a generated value from a string of text using a mathematical function. While recording a transaction its value & time of the transaction are fed to a mathematical function and a hash is generated which is the value stored in the distributed ledger. The mathematical function is also called the ‘Hashing Algorithm’. Hashing is a one way function, once the hash is generated the input data cannot be retrieved from it as it would have been a case if it was just an encryption function, hence it is called cryptography and is more secure than encryption. All the hash values have similar character length.
  3. Blockchain: it's the digital system of recording transactions in a manner in which individual records called blocks are linked together to form a large chain. Any new transaction is recorded with the past transactions related to it. Hash of one block is fed as an input along with the transaction data to be recorded in the next block. The first block in the blockchain is called the genesis block. To date 659297 BTC blocks have been mined, to check the current count refer to Blockchain.com 
  4. Peer-to-Peer System: blockchain is a decentralised peer-to-peer system with no central agency. This is devoid of corruption from a single source as a distributed ledger is available to all nodes and this transparency is the mark of authenticity.

Recording Transactions on Distributed Ledger

In a blockchain governed financial system, all the transactions have to be recorded on a distributed ledger, the copy of which is carried by all the participating nodes. To make sure only the authentic transactions are recorded, a cryptographic hash is obtained through a complex mathematical function whose input includes the hash of previous authentic transfer, the value of transaction, timestamp, nonce (value to be checked during mining), current owner's digital signature and payee wallet address.

The process of validating transactions and recording them on the global ledger is called mining, and nodes engaged in this process are called miners. For BTC (Bitcoin) it takes approximately 10 minutes for a transaction to be confirmed or mined. Once the block (or transaction structure) is mined all the nodes reach a common agreement about verification & security of the transaction and the consensus is reached. 

Miners for contributing to the consensus and to offset their cost of operation are rewarded with cryptocurrency (the type & amount is dependent on the particular blockchain technology ledger they are working on). By the process of mining Smart contracts are executed, which are the digitally executed contracts or promises between two entities comprising a pledge to complete a certain task.

Using Smart Contracts for Tokenization & Real Events

Bitcoin, the largest and by far the most widely used cryptocurrency does not offer support for complex smart contracts. Moreover, simple contracts that can be executed on Bitcoin are often cumbersome to design and very costly to execute. Blockstack has solved this by introducing PoX based Smart Contracts.

Blockstack PBC and Chainlink are joining forces to integrate Chainlink as the preferred oracle solution for the Blockstack and Algorand-supported Clarity smart contract language. It's a language for predictable smart contracts. It enables utilising the strength of the BTC chain by using PoX as the consensus mechanism. It's more powerful than Solidity (used for ETH based smart contracts) and helps in writing detailed contracts which secure and hack proof.

The existing Smart contract languages don't support the inclusion of real world data limiting the application of blockchain. Chainlink methodology allows integration of real world data by use of APIs increasing the scope of utility of blockchain technology. 

\"Oracle Problem\" for Smart Contracts

Why choose Clarity over others?

These are shortcomings of ETH based contracts addressed by Clarity:

  1. Reentrancy: it occurs when an external contract calls for the current contract before initial execution is over, this leads to change of state of the first contract which can be exploited
  2. Access Control: contracts have been found with insecure visibility settings exposing the private keys to hackers
  3. Overflow & Underflow: while defining the data types if the contacts are not well written, the processed values may overflow or underflow the defined size and its a potential bug
  4. Unchecked Return Values For Low Level Calls: if any function keeps on continuing with processing even after returning a value eg: FALSE, it can result to unwanted outcomes
  5. Denial of Service: hackers can exploit ETH smart contracts by repeatedly abusing access control, artificially increasing GAS to compute a function, behaving maliciously when being the recipient of a transaction causing DoS
  6. Bad Randomness: ETH being open source, hackers have been able to figure out predictable answers to random function outputs, this has given them a chance to exploit
  7. Time Manipulation: as the time is recorded for each transaction, malicious nodes may record it incorrectly making the chain vulnerable
  8. Short Address Attack: malicious miners may pass incorrect inputs to technical functions resulting in giving a chance for hackers to take over

Smart Contracts with External Events

Chainlink's decentralized oracle network provides reliable, tamper-proof inputs and outputs for complex smart contracts on any blockchain. The open source code provides a unique opportunity to connect to access any external data through API calls.

Final Thoughts

Secure Smart Contracts

PoX (Proof of Transfer) is a unique sustainable consensus mechanism that combines the merits of existing mechanisms. This allows application of detailed smart contracts on BTC chain which was previously not possible. The proposed Chainlink's solution solves the Oracle problem of smart contracts not able to use real world data. Using Clarity smart contracts can now be written which are more secure and enhanced. The whole arrangement would increase the scope of smart contracts from mere tokenization to encompassing real events. 

This article is a repost of my recent Publish0x article.


No comments:

Post a Comment