bitcoin – Finematics https://finematics.com decentralized finance education Wed, 23 Dec 2020 18:00:23 +0000 en-GB hourly 1 https://wordpress.org/?v=5.8.1 https://finematics.com/wp-content/uploads/2017/09/cropped-favicon-32x32.png bitcoin – Finematics https://finematics.com 32 32 Bitcoin on Ethereum? (renBTC, wBTC, tBTC, sBTC) https://finematics.com/bitcoin-on-ethereum-renbtc-wbtc-tbtc-sbtc/?utm_source=rss&utm_medium=rss&utm_campaign=bitcoin-on-ethereum-renbtc-wbtc-tbtc-sbtc&utm_source=rss&utm_medium=rss&utm_campaign=bitcoin-on-ethereum-renbtc-wbtc-tbtc-sbtc https://finematics.com/bitcoin-on-ethereum-renbtc-wbtc-tbtc-sbtc/#respond Wed, 16 Dec 2020 21:34:50 +0000 https://finematics.com/?p=1184

So Bitcoin on Ethereum – a good or a bad idea? What are the use cases for moving your precious BTC to Ethereum? What are the risks? And what are the protocols that make all of this possible? You’ll find answers to these questions in this article. 

Why 

Okay, so let’s start with why someone would want to move their Bitcoin to Ethereum in the first place? 

The short answer is decentralized finance. Let’s try to understand why this is the case. 

DeFi took the whole crypto space by storm, showing that payments is not the only area of finance that can be decentralized. In fact, DeFi focuses on rebuilding all financial services in a completely decentralized, open and permissionless way. On top of that, it allows for creating financial applications that were previously just impossible to make. 

Ether and other tokens that are native to the Ethereum blockchain (ERC-20) can take full advantage of this amazing new space. These tokens can be used as collateral in the lending protocols such as Compound or Aave. They can also be traded in a completely permissionless way on Uniswap. 

On top of that, these tokens can generate yield. For example, by being lent out or by providing liquidity to a decentralized exchange.

BTC on the Bitcoin network, although very secure, has very limited use cases. You can mainly send your BTC from one address to the other or just hold (hodl) it and wait until it appreciates in value.

When it comes to other financial services, you have to rely on centralized companies. Let’s take lending as an example. If you would like to make a yield on your BTC or use it as collateral to take out a loan you would have to use a centralized company, for example, BlockFi. This means giving up custody of your BTC and having to provide KYC information – not an ideal solution, especially for people who believe in decentralized and permissionless nature of cryptocurrencies. 

Not being able to use BTC in DeFi was one of the main driving forces for making BTC available on Ethereum. Using BTC in DeFi also just makes sense. For example, Bitcoin as a fixed-supply store of value asset with established history can be valuable collateral. A user would be able to lock their BTC and borrow against it in a decentralized fashion.  

Currently, there are over 140k BTC on Ethereum worth over $2.5B – an astonishing amount – considering there was only around 1k BTC on Ethereum at the beginning of 2020. 

Now, let’s see what options are available when it comes to moving BTC to Ethereum. 

Wrapped BTC

Wrapped BTC or wBTC is an ERC20 token that is backed 1:1 by the actual Bitcoin. With over 115,000 coins in existence, wBTC is currently the most popular option for moving BTC to Ethereum. 

The Wrapped BTC protocol works by allowing merchants to mint and burn wBTC.

If a merchant wants to exchange their BTC to wBTC they initiate the minting procedure by providing an Ethereum address to the wrapped token contract. In the next step, the merchant sends the actual Bitcoin to a custodian. The custodian mints wBTC and it is then sent to the merchant’s Ethereum address. 

The original BTC is now held by the custodian and the total supply of wBTC increases by the amount of the BTC provided. 

If the merchant decides to redeem their BTC on the Bitcoin network they must request a withdrawal. After the withdrawal process is initiated the merchant burns their wBTC by sending them to the wrapped token contract. The custodian confirms the burn and releases the BTC back to the merchant.

Once the original BTC is withdrawn, the total supply of wBTC decreases by the amount that was burnt. 

Merchants are usually companies or protocols that are able to mint and burn wBTC. Other DeFi users can purchase wBTC on multiple exchanges including Uniswap. They can also use services such as wbtc.cafe powered by RenVM to move their BTC to wBTC. 

wBTC can be used across multiple DeFi protocols. For example, it can be supplied as collateral on Compound or Aave. Or it can be used to provide liquidity to a 50/50 WBTC/ETH liquidity pool on Uniswap. 

This all sounds cool, but as you have probably already noticed there is one major problem here. Wrapped BTC uses a custodian which means it’s centralized. 

A good analogy here is a centralized stable coin such as USDC that is backed by USD. Both wBTC and USDC can be extremely useful, as they unlock Bitcoin’s and Dollar’s potential in DeFi. Saying this, I personally don’t believe that this is the end goal. The DeFi community strives for decentralization and we can observe ongoing attempts at bringing multiple external assets to Ethereum and DeFi in a more decentralized way. 

This is also a good segue into something a bit more decentralized – RenBTC. 

RenBTC

RenVM is an open protocol that allows for bridging assets to Ethereum. It enables the permissionless exchange of value between blockchains. One of the most popular assets to move between blockchains is, of course, Bitcoin. renBTC is Ren’s ERC20 representation of Bitcoin. 

Ren, similarly to wBTC, allows for minting renBTC by supplying BTC and redeeming BTC by burning renBTC. Each renBTC is also backed 1:1 by BTC. The main difference is that Ren decentralizes the custody of BTC and makes the process of minting/burning available to everyone – not only the merchants. 

Ren protocol runs by operating a network of decentralized nodes called Darknodes. It also leverages a few interesting elements in cryptography such as Shamir’s Secret Sharing and Secure Multiparty Computation. 

renBTC is currently the second most popular option with around 17,000 renBTC in existence. 

Ren, although aiming to be fully decentralized, is not there just yet. I’d recommend reading a Medium post on RenVM’s road to decentralization that I will link in the description box below.

tBTC

Next one is tBTC. tBTC is the next contender to the title of a go-to protocol for bringing Bitcoin to Ethereum in a decentralized way. 

After a bumpy start earlier this year, KEEP – the team behind tBTC – fixed the underlying issues and successfully relaunched the protocol. 

In tBTC, similarily to renBTC, there is no central party taking custody over the locked Bitcoin and also each tBTC is backed 1:1 by BTC. 

tBTC allows users with BTC to mint tBTC by using a network of signers. Signers are chosen randomly and a different group of signers is selected for each minted tBTC. The signers have to provide ETH as collateral to ensure they cannot walk away with locked BTC. In fact, they have to overcollateralize their deposit by providing 1.5 BTC worth of ETH. The signers are willing to lock up their ETH as they are rewarded with fees that are paid at the time of redemption. 

tBTC is gaining more and more traction – having around 1900 BTC locked in the protocol. 

In comparison to renBTC, tBTC uses a different approach to achieve the same goal – decentralized custody of BTC. 

sBTC

sBTC is yet another way of making Bitcoin useful in DeFi. sBTC differs from the previous options as in this case there is no underlying Bitcoin at all. sBTC is one of the synthetic assets created by the Synthetix protocol. Synthetic assets or synths track the value of different assets such as S&P500 index, TESLA stock, oil price or Bitcoin. 

In Synthetix, all synths are secured by collateral in form of the SNX token. The protocol is highly overcollateralized – currently at 750%. This is mainly to absorb any sharp price changes in synthetic assets. 

There is currently around 1,700 sBTC in existence. 

sBTC, wBTC, renBTC and tBTC can all trade at slightly different prices, usually at a premium to the actual BTC price. This is mainly because the demand for each of these tokens is different. Also, for all but sBTC, it matters how hard it is to redeem the underlying BTC. 

So Is It A Good Idea?

So is it worth moving your precious Bitcoin to one of the mentioned protocols? 

It depends. First of all, we have to understand if we have an actual way of benefiting from moving BTC to Ethereum. Maybe we want to use it as collateral in one of the DeFi lending protocols and take a loan based on that collateral. 

Or maybe we found an amazing yield farming opportunity. As an example, it was possible to get around 20% APY on providing liquidity to the Uniswap’s wBTC-ETH liquidity pool. Providing liquidity on Uniswap, of course, comes with its own challenges such as impermanent loss. Nevertheless, Uniswap liquidity mining brought a massive amount of BTC to the Ethereum network in form of wBTC.

Even after finding out that we can put BTC into good use in DeFi, there are still other factors to consider. For example, how comfortable we are with decentralization and security assumptions of the protocol that we want to go with. We also have to be aware of potential smart contract or admin key risks, especially in less established DeFi protocols. 

Also, even after deciding that we want to move our BTC to Ethereum, we should still consider doing so with only a portion of our total BTC allocation to protect ourselves from unknown unknowns. 

It’s also worth mentioning that the actual BTC is never on Ethereum, so it’s a bit of a mental shortcut. When it comes to wBTC, tBTC or renBTC, the BTC is locked on the Bitcoin network and the protocols issue the locked BTC equivalent on the Ethereum network. With sBTC there is no BTC at all – it’s just a purely synthetic asset – a derivative backed by SNX collateral. 

It’s also interesting to keep an eye on quite an opposite approach. Instead of bringing BTC to DeFi, some projects focus on bringing DeFi to the Bitcoin network. This, of course, comes with its own challenges and I’ll dedicate a separate article to this topic. 

So what do you think about the concept of moving Bitcoin to Ethereum? Would you be willing to do it? If so, what’s your favourite option? 

If you enjoyed reading this article you can also check out Finematics on Youtube and Twitter.

]]>
https://finematics.com/bitcoin-on-ethereum-renbtc-wbtc-tbtc-sbtc/feed/ 0
Bitcoin Halving Explained. Code analysis. https://finematics.com/bitcoin-halving-explained-code-analysis/?utm_source=rss&utm_medium=rss&utm_campaign=bitcoin-halving-explained-code-analysis&utm_source=rss&utm_medium=rss&utm_campaign=bitcoin-halving-explained-code-analysis https://finematics.com/bitcoin-halving-explained-code-analysis/#respond Sat, 14 Mar 2020 22:51:05 +0000 https://finematics.com/?p=583

What is Bitcoin halving?

Bitcoin halving is an event that reduces the supply of newly produced bitcoins by half. It occurs every 4 years or to be precise every 210000 blocks and it is a part of the validation logic in the Bitcoin source code.

Bitcoin halving is important to discuss as it affects miners profitability and often has an impact on the Bitcoin price. It is also one of the main reasons why Bitcoin is perceived as sound (hard) money with the inflation rate steadily trending to zero and becoming deflationary in a long run in opposite to all the other fiat currencies.

To understand it better let’s quickly recap how miners are being rewarded for validating transactions on the Bitcoin network.

Proof of Work

Transactions on the Bitcoin network are validated and confirmed by miners using a consensus mechanism called Proof of Work. In Proof of Work, miners are constantly validating transactions and grouping them in blocks. To prove that they did all the necessary work for the Proof of Work algorithm they try to solve a simple but laborious mathematical problem. The first miner who finds the correct solution submits a newly created block to the network and is rewarded for their hard work with a block reward. The block reward consists of two elements: transaction fees and block subsidy. The block subsidy is the number of bitcoins that is the exact subject to the Bitcoin halvings.

Previous Halvings

In January 2009, when the Bitcoin network was started, the first block called genesis block was mined. According to the algorithm, the block subsidy for the first block started from 50 bitcoins which was an arbitrary number chosen by the creator of the network Satoshi Nakamoto. In November 2012, Bitcoin went through its first halving at the block height of 210000 where the block reward cut in half from 50 to 25 bitcoins. At that time there was already 10.5 millions of bitcoins in existence. The second halving happened in July 2016 at the block height of 420000 with 15.75 millions of bitcoins in the circulation. The third, highly anticipated halving will be happening in May 2020 at the block height of 630000 with 18.375 millions of bitcoins in the circulation. After that Bitcoin halvings will be occurring every 4 years until roughly the year 2140 when the Bitcoin blockchain reaches the final number of 32 halvings and stops rewarding miners with block subsidy, so they will have to rely solely on the transaction fees.

Why does Bitcoin halving matter?

There are a few main reasons why Bitcoin halving matters. Let’s dive into some of them.

Sound (hard) money theory. Bitcoin halvings create controlled issuance of Bitcoin the currency with predictable inflation and eventual deflation when all bitcoins are mined. The current inflation rate is at around 3.6% and will decrease to around 1.8% after the 3rd halving. The inflation rate will be decreasing until 2140 when there will be no new supply of bitcoins. After that Bitcoin becomes deflationary as some of the already existing bitcoins will be lost.

Price impact caused by a supply shock. Assuming the demand for Bitcoin stays the same and the supply is cut in half, it should cause the price of Bitcoin to go up (at least in theory). With the current supply, the market is able to absorb 1800 new bitcoins per day (considering the most miners sell their rewards instead of hoarding). After the halving, the amount of newly created bitcoins will drop to 900 per day. If the demand stays the same it should increase the price of each coin. Bitcoin market of course is not that easily predictable and even though previous halvings had an impact on the price there is no guarantee it will happen again. This is also broadly discussed in the Bitcoin stock to flow model which can be used to try to predict Bitcoin future price based on the current stock (coins already in existence) and flow (issuance of new coins).

Rewarding early adopters. To incentivise the early adopters and help with bootstrapping the network the inflation rate was the highest at the time of starting the network. This means that early miners were able to receive the highest rewards (50 bitcoins per block) and accumulate more bitcoins. By looking at Bitcoin Money Supply we can see that at the time of creating this video 18 out of 21 million bitcoins were already minted which again incentives early adopters.

How does the Bitcoin halving actually look like in the code?

Now let’s get a bit more technical and jump into the code that is actually responsible for the Bitcoin halving. This code snippet is taken from the Bitcoin Core Github repository from the validation.cpp file that is responsible, as you may guess, for validation. I will put a link to this piece of code in the description box below.

Bitcoin halving instead of being defined as a time constant is actually defined using the number of blocks. We can see that the number of halvings is calculated using current block height (nHeight) and subsidy halving interval (nSubsidyHalvingInterval) which is a constant equal to 210000 that represents the number of blocks after which a halving should occur.

210000*10/60/24/365.25 = 3.9926990646.

Assuming that a block is mined on average every 10 minutes we can quickly calculate that it should take roughly 4 years to mine 210000 blocks. 619894 is the current block height at the time of making this video. This means that the halvings variable is currently set to 619894/210000=2.9518761905 which in integer division is just 2 although it’s getting very close to 3.

Next two steps are also quite interesting. We have an ‘if’ check that returns 0 when halving is greater or equal to 64 which is mostly used to protect the right-shift operator that comes later. This doesn’t mean there will be 64 halvings as we will quickly realise the actual subsidy will be 0 from 33rd halving onwards. The next step is to just get the first block subsidy in satoshis. COIN constant represents 1 bitcoin in satoshis (100 000 000 satoshis).

Now we’re getting to the actual calculation which is performed by using the right-shift bit operation instead of division for performance reasons. If we start with 5 000 000 000 and begin right shifting it, we can quickly see that the maximum number of times we can do it is 32. At the 32nd attempt, our reward will be 1 satoshi if we shift one more time it will give us 0 as the result. We can quickly calculate that if one halving occurs every 4 years on average, this means that the mining reward will stop around the year 2140. We can get to that number by using Bitcoin genesis block date which is the 3rd of January 2009 + 32*4 + 4 ( last halving, all 4 years before 33rd halving). This leads us to the 3rd January 2141 which is often rounded to 2140 as the final year for Bitcoin mining block subsidy rewards.

Let’s see what happens in the code in the next halving estimated for around the 5th of May 2020. When block height reaches 630000 the halvings variable starts returning 3 (630000/210000). After that we’ll be doing right bit shifting going from 50 * 100 000 000 = 5 000 000 000 >> 3 = 625 000 000 satoshis = 6.25 BTC. And that will be the new block subsidy reward for the next 4 years.

Summary

Bitcoin halving is one of the most important mechanisms when it comes to the Bitcoin network and its monetary system. It allows for predictable, decreasing inflation rate of the currency and incentives early adopters to bootstrap and secure the network.

Extras

Mastering Bitcoin (by Andreas Antonopoulos) ► https://amzn.to/2ILqylp

If you have any questions regarding Bitcoin or Bitcoin Halving comment down below.

]]>
https://finematics.com/bitcoin-halving-explained-code-analysis/feed/ 0
Lightning Network Explained https://finematics.com/lightning-network-explained/?utm_source=rss&utm_medium=rss&utm_campaign=lightning-network-explained&utm_source=rss&utm_medium=rss&utm_campaign=lightning-network-explained https://finematics.com/lightning-network-explained/#respond Wed, 17 Apr 2019 07:35:06 +0000 https://finematics.com/?p=443

What is the Lightning Network?

Lightning Network is a payment protocol that operates on the top of the Bitcoin network (“Layer 2” solution). It’s a network of decentralised nodes that allows for sending a huge number of transactions exteremly fast and for a negligible fee (even sub-satoshi level). The Lightning Network facilitates micropayments, making the existence of a completely new type of applications possible.

To illustrate how the Lightning Network works, let’s imagine ordering drinks in the pub. The first option is to pay for every single drink separately, this means you have to pay each time you want to order a drink. Each of these transactions will be settled with the pub separately. If we imagine these are Bitcoin transactions, each of them would have to be settled (mined) on the Bitcoin blockchain.

The second option is to open a bar tab. Now, you can order as many drinks as you want without having to settle each transaction separately. At the end, you can just pay once, settling the whole bill in one transaction. This is similar approach to how the Lightning Network works and it’s consider a Layer 2 solution as not every transaction is settled on the blockchain.

Not settling every transaction on the blockchain allows for achieving a dramatic increase in both transaction speed and throughput and makes Bitcoin scalable to the level necessary to become a viable mean of payment for the whole world.

The Lightning Network was first described by Joseph Poon and Thaddeus Dryja in February 2015. You can find a link to the whitepaper here/below.
Lightning Network is built on the concept of payment channels that can be established between two parties. We are going to dive into it later in this post. Before we do that let’s understand why do we even need the Lightning Network in the first place.

Why does Bitcoin even need the Lightning Network?

Okay, this all sounds really cool, but why does Bitcoin even need the Lightning Network?
The quick answer is – scaling. Concerns about Bitcoin’s scaling problems were raised multiple times and they became obvious during the end of 2017 bull run. In Bitcoin, every single transaction has to be broadcast to every single node in the network. Broadcasted transactions have to be included in a block to be mined and settled on the blockchain. As Bitcoin’s blocks are created every 10 minutes on average and each block has a limited size, it creates a natural bottleneck on the number of transactions that can be processed.

When it comes to fixing Bitcoin’s scalability problems, developers came up with a few different approaches, mainly increasing the block size (Bitcoin Cash approach) or moving part of the transactions off-chain (Bitcoin approach). Both of the approaches come with their own tradeoffs, but the Lightning Network tries to increase the network throughput and speed by processing some of the transactions in the second layer.

Currently, Bitcoin network can process, on average, between 3 and 7 transactions per second (tps). If Bitcoin wants to become a viable mean of payment it has to start competing with already existing solutions. One of them is, of course, Visa which processes around 4000 tps and can handle spikes up to 65 000 tps quite easily. The good news is that the Lightning Network can potentially scale to millions of tps and dramatically increase the transaction speed, that is exactly why the technology started attracting a lot of attention.

Payment Channels

Now as we went through the necessary overview, let’s get into the nitty-gritty details of the Lightning Network. We cannot talk about the Lightning Network without mentioning payment channels which are the basic building blocks of the network. Payment channels are examples of state channels which represent an off-chain state alteration which is secured by eventual settlement on the blockchain.

In order to open a new payment channel, two parties – Alice and Bob, have to commit funds to a 2-of-2 multisig address by sending a transaction, also called a funding transaction to the Bitcoin network. Committed funds represent the maximum channel capacity which is the amount of Bitcoin that can be transferred via this channel.

After the channel is established, two parties can start signing and exchanging transactions (called commitment transactions) that alter the initial state and are not broadcast to the Bitcoin network. This allows for exchanging thousands of transaction without having to interact with the underlying Bitcoin network and makes the whole solution scalable.

When Alice and Bob at some point decide they want to close their payment channel, they can sign a closing transaction. This transaction will be mined and it will resolve the final balance between the two parties. In the whole lifetime of a payment channel, there are only two transactions that have to be mined and these are the opening and the closing transactions.

The Lightning Network is built on the concept of multiple payment channels connected end-to-end that allow for routing transactions to any of the network participants. In the Lightning Network, a transaction can be sent through the network of payment channels without trusting any of the intermediaries leveraging a mechanism called Hash Time Lock Contract (HTLC).

Every time a node wants to send a payment to another node, it must first construct a path. It does so by connecting channels with enough capacity using possibly the shortest route. It also takes into account fees of the intermediate nodes.

The communication between LN nodes is encrypted point-to-point. The Lightning Network achieves that by implementing an onion-routed protocol (similar to TOR) which ensures that intermediate nodes can verify and decrypt only their portion of the route and they cannot identify the length of the payment path or their own position in the path.

To deal with the bad actors the Lightning Network leverages a lot of game theoretical elements that incentivise nodes to act honestly. These are mostly timelocks, asymmetric revocable commitments and HTLC.

This was only a quick overview of the payment channels and we are going to cover more details in the following post.

Possible applications of the Lightning Network

The beauty of Bitcoin and the Lightning Network is that it can not only provide a better alternative to the already existing systems but also facilitates the creation of the completely new types of applications.

Have you ever realised you kept paying a subscription fee, even though you barely used a service? What if the service instead of a monthly fee was charging you by a minute or maybe even by a second? A good example would be a movie streaming service which actually charges you a small fee for every second of watched content. This type of business is currently not a viable option due to high fees for processing card transactions.

How about receiving your salary every hour (or even every minute) instead of once or twice per month. This is where the Time Value of Money comes to play. With the Lightning Network micropayments become a new possibility. This opens the world to a new concept of streaming money, a new way of transacting that was hard to imagine before.

Lightning Network and other cryptocurrencies

Lightning Network although mostly discussed as a Bitcoin Lightning Network is not only limited to Bitcoin. In fact, most of the cryptocurrencies supporting basic constructs like timelocks or HTLC can make use of the Lightning Network to exchange value off-chain. There is also a possibility of exchanging one coin to another via Lightning Network in a process called atomic swap. This concept can power Decentralized Exchanges and allow people to exchange coins without losing control of their private keys.

BOLT, Lightning Wallets and current state of the Lightning Network adoption

As the Lightning Network continues to grow at a very high rate, it’s important to make sure that different implementations can communicate with each other. To achieve that, the community came up with a BOLT (Basis of Lightning Network) standard which specifies guidelines which allow for seamless interoperability between different implementations. This also allows different teams to work on their own Lightning Network implementation at their own pace which speeds up innovation. The most popular implementations with the highest number of developers are c-lightning, LND and Eclair.

When it comes to wallet apps supporting Lightning Network there are already a few good solution, but we have to remember that most of them are still in beta stage and they can contain bugs, so it might not be the best idea to deposit a lot of money into them. The most popular wallets are Blue Wallet, Wallet of Satoshi, and Zap.

As we mentioned before, the Lightning Network grows at a very hight rate. These are some of the current network statistics:

Number of nodes: 7991 (+8.35%)
Number of channels: 38707 (+2.3%)
Network capacity: 1066 BTC (+9%)

If you’re curious about more Lightning Network stats, check a link to a website that tracks them in the description box below.

Summary

The Lightning Network is currently one of the most exciting projects in the crypto industry and it has a big chance of bringing a scalable second layer solution to Bitcoin which will enable micropayments and create a new way of building financial applications.

We need to remember that the Lightning Network is still a very new technology and despite its potential, it is also facing a lot of challenges. Some of them are: lack of incentives to open a new channel with a new user, capped channel capacity or storing a lot of intermediate state. Fortunately, there is also a lot of improvements currently being developed to deal with some of those challenges (e.g. dual funding, AMP, splicing, eltoo).

The Lightning Network recently started attracting more and more attention from the broader community with people like Jack Dorsey (Twitter CEO) endorsing the technology.

Extras

Lightning Network Whitepaper ► https://lightning.network/lightning-network-paper.pdf

Mastering Bitcoin by Andreas M. Antonopoulos ► https://amzn.to/2Lr4iS0 (affiliate)

]]>
https://finematics.com/lightning-network-explained/feed/ 0