Thursday, August 30, 2018

Raising op code limits while holding up the sky

Introduction

In the original Bitcoin client created by Satoshi (version 0.1.0), the script engine had significant differences to the one we have today. Notable capabilities include math operations on integers of any size (Crypto math anyone?) and no limits on things like script size. At some point in bitcoin’s history, a limit of 201 op codes per script was imposed.
The team behind the Bitcoin SV implementation is proposing to remove altogether (or alternatively, raise) this limit of 201 op codes per script, which has caused concern about attacks invoking high computational load.
In this post I will seek to quantify this risk and explain mitigating measures that make it quite possible to do this without the sky falling in.

But why remove the limit?

Leaving aside the possibilities that large scripts create, like unrolled loops and complex algorithmic constructs, allow me for a moment to indulge in a bit of musing.
Bitcoin SV’s remit is to restore the Bitcoin protocol and lock it down (with the exception of security fixes and those changes absolutely necessary to meet scaling goals). What constitutes the ‘protocol’ in our view is a common sense combination of
  1. The whitepaper
  2. The original code
  3. The obvious example Satoshi set by fixing bugs
  4. His subsequent musings on protocol matters.
Whilst not a technical argument, perhaps the reason I personally believe in this goal is this: While Satoshi was around, Bitcoin was in its infancy. It was a system that relied on critical mass for many of properties to begin being expressed. Limits began being imposed even while he was still around (although with the express intent of lifting them later when critical mass HAD been achieved) and this trend continued after he was gone with more an more divergence away from the original vision. This culminated in RBF and SegWit. The straws that finally broke the camel’s back and ultimately triggered the rebirth of Bitcoin as Bitcoin Cash.
Now that the yoke of Core is finally lifted and we have the potential for some real critical mass, Bitcoin is finally on the verge of becoming, for the first time in history, what it was originally intended to be. The thing is, we don’t know what that is. Bitcoin is a system that relies on a complex interplay between game theory, economic incentives, cryptography, and more. We know that Satoshi didn’t think we needed any artificial limits and that a central pillar of his plan was to give miners strong, profit based incentives to figure it out. Given the impact that Bitcoin has already had on the world and profound potential for change it represents, I personally feel it’s worth returning the protocol back to the way it was always supposed to be and leaving it alone for a few years - to let Bitcoin become what it has never yet had a chance to be. Only then will we have a chance to see what comes of that and what we can learn about the interplay of technology and sociology that Bitcoin represents.. We owe Satoshi that.
The mere existence of bitcoin script and the fact that it did not originally have limits is a strong suggestion that Satoshi envisaged this language being used in ways we haven’t yet conceived.
Now back to the fun technical detail.

What constrains script sizes?

In current implementations, there are actually a few limits that come into play with script sizes:
  1. 201 op codes per script
  2. 10000 bytes per script
  3. 20000 sigops per transaction
  4. 20000 sigops per mb (3 and 4 are widely acknowledged to have completely broken implementations however)
  5. 1mb per transaction
Point 2 is important to note, because there is a common misconception that lifting the 201 op code limit per script equates to unlimited script size. It does not, because the 10000 byte limit then comes into play. Also important to note is that this limit counts both op codes AND data.
The other more important thing that constrains script sizes is the constraint that was built into bitcoin from the very beginning: transaction fees. It is ok to run a really long script if you're willing to PAY a miner for it.

100 * 10 = 10 * 100

The commonly cited concern with raising the limit on op codes per script is computational cost. Won’t a 201 op code script cost a lot less CPU cycles to run than a 10000 op code script? Yes of course it will (although as we are about to see only marginally), but it will also be commensurately more lucrative for the miner to mine. From the miner’s point of view, the revenue gained from 100 lots of 10 satoshis is the same as from 10 lots of 100 satoshis.
This is a simplistic view because it doesn’t account for the variance in computational cost of different op codes but it’s a good starting point. Let take a look at how much that variance changes the game.

Sigops and why they matter

Note that one of the limits above is max sigops per megabyte. Sigops are a generic term for the ECDSA signature verification operations invoked by the OP_CHECKSIG and OP_CHECKMULTISIG opcodes (and their verify variants). These op codes are orders of magnitude more expensive to process than any other op code. And until recently most clients processed them in single threads.
So how could this fact be exploited to try and break bitcoin? In examining the potential impact of a change, it isn’t really sufficient to make impact impact comparisons between normal usage and the post change attack scenario. It is more informative to compare the pre-change attack scenario with the post-change scenario.

Sigop stuffing for fun and not-for-profit

In order to analyse different attack scenarios, I will use a metric called sigop density. That is a measure of how many sigops you can pack into a fixed number of bytes. This is useful because the fixed number of bytes is proportional to transaction fees (under the current fee model). So it is really a measure of the transaction fee cost of computational load.
Because sigops are currently so computationally expensive it is feasible that creating a block packed with as many sigops as possible will cause miners to take a long time validating a block, in part due to the inefficient signature verification code in bitcoin client software. Executing this attack requires making a block as sigop dense as possible which means a lot of non-standard transactions in place of standard ones. Likely the attacker would have to mine the block themself unless there is a miner willing to accept any type of transaction.

The worst case attack that no one did in 10 years

I’m going to make a few assumptions here to simplify this examination. They have very little impact on the final numbers but would complicate the explanation significantly:
  1. I will assume that we are talking about just one script as opposed to two seperate ones (scriptSig and scriptPubKey)
  2. In calculating data sizes, I will ignore the rest of the transaction and only consider the bytes in the script itself (doing this actually makes the numbers sound slightly worse so it’s a bias AGAINST the case I’m making)
Invoking a sigop requires 3 op codes and about 107 bytes in the script. Two data pushes (signature and public key) and OP_CHECKSIG itself.
<sig> = 1 + 71 bytes (avg)
<pubkey> = 1 + 33 bytes
CHECKSIG = 1 byte
Total = 107 bytes (avg)
There are a couple of alternative to achieving even higher sigop density.
  1. Only pushing one signature and public key then using OP_DUP2 to repeatedly copy them for each new sigop. This is easily defeated however with a signature cache, reducing the cost of each sigop to a cache lookup.
  2. Pushing many signatures but reusing the same public key. This requires 5 op codes rather than 3 but saves about 32 bytes. The script looks something like this: <sig> <pk> DUP TOALTSTACK CHECKSIG <sig> FROMALTSTACK DUP TOALTSTACK CHECKSIG…
As it happens with the 201 op code limit in place, neither of these methods achieve greater sigop density than simply repeating <sig> <pubkey> CHECKSIG over and over.
You can fit in 67 sigops before you hit the limit which consumes about 7169 bytes

The new worst case attack

With the 201 op code limit per script raised we are now free to use the 2nd alternative method since we are no longer worried about the higher number of op codes, only the number of bytes.
In this case, each of these uses about 76 bytes. And in the same 7169 bytes you can fit 94 sigops. This equates to an increase in maximum sigop density of (94/67 - 1) * 100% = 40%
Interestingly removing the 10000 byte limit has little effect on this sigop density. It costs only an extra 34 bytes to setup this up which would contribute less that 1% to the efficiency of this attack.
So to sum up, in the absolute worst case of someone constructing and mining a full attack block we have a computational cost 40% higher than the previous maximum. Nothing to sneeze at but in a system that is supposed to be resilient to peak loads also not the end of the world.

Defense against the dark arts

Given that we haven’t seen this attack carried out in bitcoin’s lifetime and particularly in the year that Bitcoin Cash has existed with a plethora of hostile actors arrayed against it, it is questionable whether this is something we even need to worry about. However, it pays to be prepared so what would be the impact and what could we do to mitigate against it?
The first is obvious: know your peak capacity. As explained in my previous post about block size, Bitcoin SV is firing up our own version of the Gigablock Testnet (more than one of them in fact) and we will be performing stress tests of the SV client (and other clients) on those. This will include simulating this attack and work on the attack scripts is already underway. Capacity information will be made available to miners and will also be used to inform our development priorities. The impact of this change is likely limited to increasing block validation times by a maximum of 40% and only in a full blown (expensive) attack scenario.
Should it turn out that liting this op code limit per script creates a viable attack, then of course we will revisit it. For miners, a simple tool already exist to mitigate it i.e. choose a block size hard cap that results in acceptable validation time.
An additional defensive measure is parallel block validation (so you can switch to a more easily validatable block if one comes in) - which we’ll prioritise based on miner demand for the feature.
The real mitigation is improving the speed of signature verification, which is one of the first priorities on our roadmap.

Final thoughts: to risk or not to risk?

If Bitcoin is going to grow its capacity, there is no choice but to embrace the increased loads this will place on network, storage and computational infrastructure. Our challenge is not to avoid this load but to take it on safely with a professional enterprise approach to capacity management and testing. This is what has been requested of us by the miners that commissioned the SV project and is precisely what we have commited to do. Additional sigop load is a natural consequence of growing transaction volume and significant gains can be made with efficiency increases. These are some of the low hanging fruit which the Bitcoin SV team will be focussing on early. In my previous post I mentioned several items on our roadmap directly related to accelerating signature verification but there is a natural limit to efficiency gains, after which we must turn to horizontal scaling strategies.
In the end, these limits are not for the SV team to decide but for miners to choose using their knowledge and accurate performance metrics to inform their decisions. It is our job is to provide those metrics and improve the tools miners use to exercise their ability to optimise the mining process.

Tuesday, August 28, 2018

An interesting review of IOTA which has problems and issues still to be resolved.




Introducing IOTA Coin: What is IOTA?

IOTA-coin
So, you’re interested in the relatively new and exciting cryptocurrency — IOTA. But you have no idea what it is or how it works? Well, don’t worry, we have you covered on the IOTA coin question.
Spoiler alert: Did you know that IOTA doesn’t actually have a blockchain?
Anyway, in this “What is IOTA coin?” guide, I will start by explaining the very basics of the project, as well as how the technology works. I will explain everything in the simplest way possible, using real-world examples.
After that, I will then talk about IOTA’s current stage of development and how secure (or unsecure) their protocol is.
So, by the end of reading this guide, you will no longer be asking What is IOTA? In fact, you’ll almost be an expert on the topic.

The Basics of IOTA

IOTA Coin
The IOTA project was originally created in late 2015 by Sergey Ivancheglo, David Sontesbo, Serguei Popov and Dominik
Schiener. Since IOTA was launched, it has been managed by the IOTA foundation, who are located in Germany.
Like many other cryptocurrency projects, IOTA wanted to create a payments system that could process faster, more secure, cheaper and more scalable transactions.
IOTA does not want to not limit itself to just financial transactions, but also to allow the movement of any data from one machine to another.
The IOTA project also has its own cryptocurrency too which is calls MIOTA, however, to keep things simple, I will refer to it as the IOTA coin!
Before IOTA officially launched, it raised funds through an initial coin offering (ICO). In total, the project received more than 3000 Bitcoin, which at the time was worth $434,000. Since then, the market capitalization of IOTA has reached heights of more than $14 billion!
One of the most interesting concepts to the IOTA coin project is that is doesn’t use blockchain technology like Bitcoin or Ethereum. Instead, it uses something called Directed Acyclic Graph, which IOTA calls “Tangle”.
IOTA Coin
What this means is that all the pieces of data are linked together — take a look at the screenshot below.IOTA Coin
The next part of my “What is IOTA” guide is going to look at how transactions are confirmed!

IOTA Mining – How Does The Network Confirm Transactions?

Another interesting thing about Tangle is that it doesn’t use miners.
For example, when transactions are confirmed in Bitcoin, people who volunteer their extra computing power are rewarded with extra Bitcoin for using their resources. These miners are not actually involved in the transaction itself. Instead, they are confirming other people’s transactions.
This particular consensus mechanism is called Proof-of-Work (PoW). The issue when using only PoW is that it gets more and more expensive to confirm a transaction as time goes by. This is because the difficulty to mine becomes harder, meaning that more computing power and electricity is required.
This has also resulted in slow and expensive transactions. Most importantly, it means that the Bitcoin blockchain is only able to confirm a maximum of 7 transactions per second.
In the IOTA network, things work differently, as anybody who wants to use the system to send funds must also contribute to the network by confirming other people’s transactions. Here is an example of how it works:
  1. John sends funds to Charlie.
  2. During the transfer, John also needs to confirm the transactions for two other people – Billy and Kate.
  3. He does this by contributing his computing power.
  4. Next time Billy or Kate wants to send someone money, they must do the same thing by confirming the transactions of two other people.
The idea behind this is that as more and more people use the IOTA system, the network becomes more and more scalable. This means that in reality, there is no limit to the amount of transactions the network can process each second, meaning that it is “infinitely scalable”.
IOTA Coin
Interestingly, the IOTA team state that this small contribution is still a type of PoW, however, it is a much more efficient system!
So, now that you know how transactions are confirmed, the next part of this IOTA coin guide is going to look at transaction fees.

IOTA Coin Transaction Fees

A further advantage of Tangle is that because there is no IOTA mining, transactions are basically free. This is because everybody contributes to the network by confirming other transactions, meaning that the only cost is the small amount of extra electricity required. This is very appealing to a lot of people and makes IOTA coin an ideal payments system.
By removing the need to pay transaction fees, the IOTA coin protocol can also be used to process micropayments. A micropayment is within the name — a really small amount of money.
An example of an industry that would benefit from using IOTA for micropayments are affiliate link providers. This is when somebody advertises a company on their website and when the user clicks it, the website makes a small amount of money as commission.
However, traditional payment systems are unable to do this as they charge such high transaction fees. Blockchains such as Bitcoin cannot handle micropayments are their fees are way too high. In fact, in late December 2017, Bitcoin fees reached up to $40 per transaction!

IOTA Coin Transaction Speed

As IOTA is still in its early days, there is no official transaction time yet. There are various factors that determine how quickly funds arrive in your wallet, which I will explain below.
Firstly, as everyone who wants to send funds must confirm two previous transactions, they need to perform a very quick PoW action. How long this takes will depend on how fast the user’s computer is. The faster it is able to solve the PoW puzzle, the faster it can verify someone’s transaction.
Secondly, I mentioned earlier that as more and more people use the IOTA coin network, it can process more and more transactions. However, as IOTA is still a new project, not many people are using it yet.
To make sure the network is operational, the IOTA team have installed something called a “coordinator”. This is like a centralized protocol which performs the same task as individual users. When IOTA becomes more main-stream and attracts more users, it will no longer need a coordinator.
So, in its current stage of development, transactions could take a couple of minutes, or if the network is not performing well, it could take much longer. Ultimately, for the IOTA coin network to perform at its full potential, it needs lots of people to use it.
The team are working on a protocol called “Flash Channels”, which it claims will have the ability to confirm transactions instantly. If they are able to achieve this, it could become the faster cryptocurrency in the world!

Is IOTA Safe and Secure?

So, the IOTA coin project has some big ambitions, however, it is really important to understand that they are still in the development stage. In fact, the network has already experienced quite a few technical issues, which I will discuss below.
The coordinator protocol that I mentioned earlier is centralized, which means that if it stopped working properly, then the entire network could be at risk. This has already happened multiple times, and at one point the IOTA system was unusable for days.
The centralized coordinator has also been installed to protect the network from a 34% attack. This is when somebody gains so much computing power on the network that they are able to make changes to it.
Bitcoin is also at risk of a similar attack; however, the hackers would need to get 51% of the total hashing power. This is virtually impossible now because the Bitcoin blockchain has so many miners.
However, in the case of IOTA, if the coordinator goes down then the network is at great risk. Although IOTA aims to be completely decentralized, it won’t be able to achieve this until it is able to function without the centralized coordinator.
There are also concerns that the IOTA coin system could be at risk of a replay attack. A replay attack is when hackers are able to repeat a transaction without the sender knowing. If successful, they can steal coins from someone’s personal wallet.
More bad news for the IOTA project — in late 2017, researchers at the Massachusetts Institute of Technology (MIT) released an academic paper that claimed the IOTA network had lots of security flaws. MIT is one of the best universities in the world and any research they perform is highly respected.
All of the above issues indicate that the IOTA coin project is far from a finished product. In fact, there is no official date that indicates when it will be, so it is best to keep checking their development blog, which you can access by clicking this link.
So, now that you know where the IOTA coin team are with their progress, I will now talk about how the IOTA coin can be used and abused.

How IOTA Can Be Used & Abused

If IOTA is able to meet all of their targets, then there are some really good real-world uses that it could be applied to. Firstly, if the platform is able to process instant, free and unlimited transactions, it would be ideal as a global payments system.
Both Individuals and organizations could send funds to and from anywhere in the world at the press of a button. I also mentioned earlier that because transactions are free, it is also perfect for the micro-payments industry.
It is also hoped that IOTA will be able to process more than just financial transactions, in what the team calls the “Machine-to-Machine Economy”. One example of this is in the electric vehicle charging industry.
IOTA recently announced that it has built a car charging facility in the Netherlands that will allow people to pay for the electricity they use, automatically. The electric car will be fitted with an automatic meter that will automatically calculate how much electricity was used and then it will take the payment.
This could be applied to absolutely anything that needs to transfer data from one device to another.
Another real-world advantage for IOTA is that it is being designed to be resistant to a quantum attack. Quantum computing is a really advanced area of science that hasn’t actually been invented yet, but organizations such as NASA and the CIA are working on it.
The current technology that first and second generation blockchains like Bitcoin and Ethereum use is based on cryptography, which at the moment is virtually impossible to hack. However, the theory is that once quantum computers are built, they will be able to override these blockchains easily.
To make sure that IOTA is fully protected against any quantum attacks of the future, it is designing a protocol that will be resistant to it!

Pros & Cons of IOTA

I know this What is IOTA Coin guide has already provided you with lots of information, but I will now summarize it all with some pros and cons!
 PROs
 Free transactions
 Unlimited scaling
 Can process any data, not just financial transactions
 Hopes to achieve instant transactions
 No IOTA mining – everyone contributes
Quantum resistant
 CONs
 No finished product yet
 Unclear when the project will be ready
 Currently needing to use a centralized coordinator
 Has experienced lots of technical flaws and bugs
 Many (including MIT) think it has really bad security











Conclusion

In my opinion, IOTA has a lot of potential to be used on a global scale. As long as the team can bring their goals to life, then I think the project will be a huge success.
Anyway, that draws the end of this What is IOTA coin guide! I know a lot of the information I’ve provided might seem really complicated, but I hope you have found my explanations easy enough to digest.
If you have read it from start to finish, you should have a good idea of what the IOTA coin project is and what they plan to do. You should also have a good understanding of how the technology works.
I also spoke about what the team has achieved so far and what they still need to work on. Hopefully you understand that the idea of the project is fantastic, but until they have a finished product it is just theoretical.
Why don’t you let me know your thoughts on IOTA? Feel free Let me know your thoughts in the comment sections below!