Stacks Blockchain : Building a web3 ecosystem on top of Bitcoin | by ThatCat | Coinmonks | Aug, 2022 - Rvpg media

Stacks Blockchain : Building a web3 ecosystem on top of Bitcoin | by ThatCat | Coinmonks | Aug, 2022

What is Stacks?

Have you ever wondered why are there so many different blockchains in existence today? not referring to coins, but networks and chains like Bitcoin, ETH. Bitcoin was already there, its market cap has always been the highest; then why do other blockchains exist and what purpose do they serve?

The simple answer is, they’re trying to address whatever Bitcoin lacks as a blockchain. Take Ethereum for example, it’s not just a store of value like Bitcoin but you can do a lot more. You cannot make a decentralized Spotify or twitter on top of Bitcoin, but you can do this on Ethereum, Solana and other chains. Lens protocol and Audius are two examples of the above reference that you simply can’t build on Bitcoin.

There was this void in the Bitcoin ecosystem that needed to be filled, the ability to create applications (decentralized apps) on top of Bitcoin using its consensus and security.

Filling in on this void there’s one blockchain that’s working alongside with Bitcoin. Instead of disassociating itself completely from the OG Chain, it works to “unleash the power of Bitcoin”. This is the Stacks blockchain, previously known as Blockstacks.

What really does Stacks do? Well, pretty much everything that Bitcoin cannot and many other networks can. But Stacks does this without leaving the Bitcoin Ecosystem. Rather, the success of Stacks majorly depends on the distribution that Bitcoin provides and how it’s adopted in the future.

Stacks can be thought of as the application layer of the decentralized web, just like Ethereum or Solana. If you aren’t yet familiar with these, this is an area that you might have noticed is predominantly ruled by tech giants like Google, Facebook. Unlike these giants Stacks makes it possible to build dapps (decentralized apps) where your privacy remains completely to you. As Muneeb, founder of Stacks puts it — None of it should be third party’s business. Web3 allows you to be the owner of your own data.

The thread explains Stacks in ELI5 fashion

Stacks is unique in many ways, it uses Bitcoin’s security and transaction settlement, it also uses BTC as a reserve currency against their own token, which is the STX token. Stacks adds smart contract functionality and privacy of bitcoin without altering Bitcoin (as of now). It’s not a Layer 2 scaling solution like Polygon but a Layer 1 ecosystem anchored to Bitcoin. Let’s dive deep into what’s happening beneath.

At this point you must be curious what does Stacks really have to do with Bitcoin how do they both work together, what’s this Bitcoin’s security that we’re talking about?

Like we discussed above, Stacks has a lot to do with Bitcoin.

Stacks follows a new consensus, the Proof of Transfer (POX) mining protocol, running in parallel to Bitcoin. This enables a reliable broadcast medium for its block headers.

What is a block header? Well, a Block header serves as a summary of the rest of the block. It’s made up of some useful date like how much time did it take to mine that block and how difficult was it to mine; along with this, it contains more useful metadata.

The Stacks blockchain state is distinct from Bitcoin and is maintained by Stacks nodes, Stacks transactions are completely separate from Bitcoin transactions.

In this case the miners elect using the stored metadata implementing a variant of Nakamoto consensus independent of Bitcoin. This is done by selecting a winning block with a probability proportional to the amount of BTC which was spent to record it on the Bitcoin chain utilizing the POW.

But why are we even doing all this? Well, Stacks brings Smart Contracts to Bitcoin with this mech, running in parallel to it. Smart contracts are bsically agreements that brings in business logics, for eg, a decision is made automatically based on the predefined conditions laid down in the smart contracts. Basically enabling you to make complex applications on top of blockchains like Ethereum, Stacks and other chains. Bitcoin lacks this features. Though it has some smart contract features like peer-to-peer Key Hash (P2PKH). Bitcoin uses Script to enables these basic (yet secure) logics, but Script is not Turing complete — Which basically means cannot solve very complex computational problems.

Stacks uses a different programming language, which too btw is not a Turing Complete language. But that’s because of some great advantages that it has to offer (discussed ahead). This language is the Clarity Smart Contract Language. This has been discussed in depth ahead in this article.

Source — https://twitter.com/castig/status/1550805898519511040?s=20&t=aS9fP2NyXeGhJ5jnQVyrXg

People Often confuse Stacks’ POX with the Proof of Stake (POS) consensus, not to mention, they often also mistake Stacks to be a L2 blockchain instead of a L1.

Stacks is an independent layer 1 blockchain which is only utilizing Bitcoin’s security, stability and ecosystem.

As explained before, Stacks’ state is different from Bitcoin. It is maintained by and for the Stacks nodes. Stacks transactions are separate from Bitcoin’s layer 2 transaction systems like Lightning, which only helps enhance bitcoin payments experience in many ways.

Proof of Transfer is a mining mechanism an extension of Proof-of-Burn (PoB) mechanism- which, was originally proposed as a consensus mechanism for the Stacks blockchain. However, they furthered this idea — instead of burning the tokens, miners transfer it other participants. PoX recyles proof-of-work energy to provide Nakamoto-style consensus for the connected chain/layer.

Proof Stake, on the other hand has some shortcomings. For instance,

Limitations of PoS involve —

  • History Alteration: in PoS if a node has been disconnected for a long period and is presented with two conflicting transaction histories, then it’d be impossible for it to determine the “true” chain without some external input. (Read more here). In PoS hard forks and rewriting the history cost very little energy to produce. Selecting the true history requires a buy-in from the user’s end.
    If something happens and the nodes are off-line for too long, an attacker can enforce their chosen history to be accepted. This is also important for IoT products trying to bring blockchain clients, where disconnected operations are common for security purposes.
    In such a situation, the attacker can try and trick users to accept their alternate history. Such attacks are not possible on PoW blockchains, like Bitcoin and Ethereum. In Independent L1 PoS, the external input to determine the right PoS history should be the available from a PoW chain history to make it more safer.
  • Lack of initial Liquidity: Mining is proportional to the tokens staked, therefore no one wishes to transfer tokens initially.
  • 51% risk: if someone owns 51% or more of the token they can corrupt the blockchain.

PoX was invented by Stacks after thorough research on the shortcomings of PoS and PoB (proof of burn).

Stacks calculates a per-block consensus hash that helps users select the right transaction history.

In Stacks, the process of mining is energy efficient as it uses consensus of the existing PoW blockchain (Bitcoin, in this case).

Mining is done through the following steps:

  • Validating nodes transfer Bitcoins to protocol defined address (Stackers). The coin holdings are maintained in a separate address which is not part of the consensus network.
  • The Bitcoin amount is used as input to a Verifiable Random Function (VRF)
  • The output of VRF is used to elect a leader miner who appends the new block to the chain and earn STX as a reward

A leader is elected and instead of burning the tokens they are transferred to the Stackers who have been nominated by the protocol itself.

A depiction of the mechanism from the official Stacks docs page —read here

All fun and games until someone asks on the utility, is Stacks really good for Bitcoin 🤔 if so does it really bring any utility?

Well, let’s start with the obvious limitation of Bitcoin — we couldn’t make dapps on bitcoin (until Stacks). This is a big enough problem already and this is the reason why Ethereum came into the limelight. Vitalik started Ethereum to address this main issue. The same way, Solana came into the picture with the features of ETH network but addressed it’s shortcoming.

As explained above, Stacks clearly brings real value to the Bitcoin ecosystem by bringing whatever features other newer chains have. Stacks does this while being native to Bitcoin and running in parallel.

There are several new use cases this could bring to Bitcoin

These features opens a sea of opportunity for the $600B money/settlement layer that Bitcoin is. Stacks can help unleash the defi potentials of Bitcoin that other L1 blockchains have gained a large market capital due to this leverage that they provide to their users. Bitcoin so far seems to be rigidly contained to its limited capabilities, majorly being used as just a store of value. Growth of Stacks ecosystem could be tremendously beneficial to Bitcoin, imagine being able to trade NFTs using Bitcoin, or being able to earn yield on your locked Bitcoin. Using an ENS counterpart to send and receive payments in bitcoin and Stacks with a 5$ ID, also known as BNS.

To start with BNS itself, it is Blockchain Name System. In this a user can register a .BTC domain which can work as a user’s payment ID (same way as .eth works in Ethereum). One can send and receive STX and BTC using this domain in the near future. Services like these have existed for a while now, but what makes it different is that the .btc domain names are registered through a smart contract on the Stacks layer which is further secured by Bitcoin. Every BNS .btc is represented in a hash of the Bitcoin blockchain.

Stacks allows settling thousands of transactions in a single transaction on the bitcoin blockchain. Thus avoiding bottleneck situation that could be caused by Stacks when it grows big.

Another example of an important utility that Stacks could bring in for Bitcoin is DLCs — Discreet Log Contracts. Use of DLCs with a trusted oracle solution (like chainlink) solves the problem of unlocking Bitcoin’s liquidity in a non-custodial manner. For trustless defi UX on a Stacks application like Alex defi, the need for a reliable on-chain price oracle is a critical component. This would allow users to use bitcoin as collateral in a truly trustless manner, retaining Bitcoin’s immutability of a program. This is still under development, soon to to be launched 👀

Now let’s jump on to the code side of things, starting with the limitations of Bitcoin’s script

Stacks exists because Bitcoin has some limitations in its script. BTC script is based on several script types;

Pay to Public Key Hash (p2pkh), which is used to pay bitcoin addresses.

Pay to Multisig (p2ms) — allows for several users to control bitcoins in a single wallet (like Gnosis safe).

Pay to Script Hash (p2sh) — The pending txn must provide a script matching the script hash and data which makes the script evaluate to true.

Bitcoin scripting language lacks loops, but it does not need looping instructions, it has a very basic use case.

To understand better, we could directly look into why Ethereum exists. Quoting from the Ethereum whitepaper (read here), Bitcoin scripting has these limitations

(UTXO means “unspent transaction outputs”)

Lack of Turing-completeness — that is to say, while there is a large subset of computation that the Bitcoin scripting language supports, it does not nearly support everything. The main category that is missing is loops. This is done to avoid infinite loops during transaction verification; theoretically it is a surmountable obstacle for script programmers, since any loop can be simulated by simply repeating the underlying code many times with an if statement, but it does lead to scripts that are very space-inefficient. For example, implementing an alternative elliptic curve signature algorithm would likely require 256 repeated multiplication rounds all individually included in the code.

Value-blindness — there is no way for a UTXO script to provide fine-grained control over the amount that can be withdrawn. For example, one powerful use case of an oracle contract would be a hedging contract, where A and B put in $1000 worth of BTC and after 30 days the script sends $1000 worth of BTC to A and the rest to B. This would require an oracle to determine the value of 1 BTC in USD, but even then it is a massive improvement in terms of trust and infrastructure requirement over the fully centralized solutions that are available now. However, because UTXO are all-or-nothing, the only way to achieve this is through the very inefficient hack of having many UTXO of varying denominations (eg. one UTXO of 2k for every k up to 30) and having O pick which UTXO to send to A and which to B.

Lack of state — UTXO can either be spent or unspent; there is no opportunity for multi-stage contracts or scripts which keep any other internal state beyond that. This makes it hard to make multi-stage options contracts, decentralized exchange offers or two-stage cryptographic commitment protocols (necessary for secure computational bounties). It also means that UTXO can only be used to build simple, one-off contracts and not more complex “stateful” contracts such as decentralized organizations, and makes meta-protocols difficult to implement. Binary state combined with value-blindness also mean that another important application, withdrawal limits, is impossible.

Blockchain-blindness — UTXO are blind to blockchain data such as the nonce, the timestamp and previous block hash. This severely limits applications in gambling, and several other categories, by depriving the scripting language of a potentially valuable source of randomness.

Ethereum was specifically designed to address these limitations. It’s a Turing-complete virtual machine (Ethereum Virtual Machine) on the blockchain. It enables to run any program irrespective of language. Ethereum makes applications possible, while Bitcoin natively doesn’t allow any such feature.

This opened the floodgates for developers to build apps on the Ethereum blockchain. But Stacks and its Smart contract language — Clarity have the ability to bring a dramatic change to the space.

We’ve been mentioning Clarity for a While now, but what is Clarity Language and what functionalities does it bring to Stacks?

It is the language that is used to write smart contract on the stacks chain. It is a decidable programming language, which is designed as a Turing incomplete language and is also not intended to compile.

Bitcoin’s Scripting language too has often been referred to as Turing incomplete, pointing out its limitations. Yet, in Clarity’s case, this serves as an advantage for Stacks based smart contracts.

Smart contracts are at the epicenter of this decentralization that we’re talking about. They are more or less like a usual contract, just on code and it executes itself when the conditions are met.

Ethereum uses the Solidity Language for its Smart Contract Development. In the past few years we’ve witnessed how useful they’re, yet smart contracts carrying bugs could be a real BIG threat. There are multiple examples on just how big an issue this is.

The snippet explains how Clarity Smart contract language can help prevent exploitation

Solidity for example is a statically typed language; yet its Turing completeness also serves as a limitation in many cases. Unfortunate Events like the ETH DAO hack could be prevented if done on Clarity. Other instances like the Reentrancy attacks, and txn fee prediction is difficult to do beforehand.

Turing Incompleteness of Clarity allows Static analysis to determine txn fees in advance. Clarity is an interpreted language, solidity is not. Smart contracts in Clarity are easily readable by an auditor to understand or recognize any bugs. It’s intended to not compile. Whereas, in solidity one can only read the compiled version of the source code on the blockchain, making auditing a little difficult after deployment. One can check the static analysis of the whole call graph for a specific smart contract.

Clarity is a functional style language, like — Scala, LISP etc. Rust and Solidity are object oriented languages that support inheritance, libraries and user defined types. Clarity prioritizes preciseness, clarity and decisive syntax that allows developers to understand the execution of the smart contract they’re deploying. It’s unambiguous in nature and helps avoid multiple interpretations of the same stuff.

Trevor explaining why Clarity is better than Solidity as a Smart Contract Language to warn users of wallet draining contracts or other exploits. Clarity is decidable, Solidity is not.

From the Clarity Docs —

Some key Clarity language rules and limitation are —

— The only primitive types are booleans, integers, buffers, and principals.

— Recursion is illegal and there are no anonymous functions.

— Looping is only performed via map, filter, or fold.

— There is support for lists, however, the only variable length lists in the language appear as function inputs; there is no support for list operations like append or join.

— Variables are immutable.

How can Stacks boost Bitcoin’s economy, bring in new cases and how it adds the req functionalities –

Smart contracts on Stacks brings a very high leverage for Bitcoin and it’s adopters. Many countries have allowed Bitcoin as a legal tender, Bitcoin’s adoption is growing but more as a store of value (since currently it has very less to offer). Stacks’ ability to bring Smart contracts into the scene can bring a new wave of developers and enthusiasts wanting to do more in web3 with Bitcoin.

We’re still early in this space even though the tech has existed for long now. Fear, random scams, market crashes, they all contribute to slower onboarding at the moment.

Stacks can jump right in and and leverage this large distribution that Bitcoin has, brining NFTs, defi, game-fi for Bitcoin users.



Source link

Leave a Comment