Sonkeng ::

Git Evangelist,C++ Alchemist,
Engineering Africa

:: BIP 9 or how to do Soft Fork


Posted on by sdmg15

For context about how this article idea came to me, was the recent BIP-110 soft fork activation. During that time window of the proposal a lot of websites created visualization tools in order to help monitor the network for counting the nodes that are signaling the BIP and those that aren’t alongside with making simulation of any case that could happen depending on the network hashrates etc.

While reading those visualizations there were some recurring jargon: Threshold, Lock in, Defined, Started. I knew about BIP9 before but I couldn’t wrap my head around while reading those and have to go back and forth reading the BIP9 spec to understand what every terms mean.

In this relatively short post we will go a little bit over BIP9 and understand better how are softforks done in Bitcoin.

1 - https://wehodlbtc.com/observatory/signaling

2 - https://fork.observer/?network=mainnet

What’s a fork?

Not to be confused with software repository fork like what we have on Github/Gitlab.

A fork here can refers to a state in which nodes have different consensus/validation rules. One rejecting blocks from another one because they couldn’t meet… Consensus! This state could be temporarily in case of blocks reorg or permanent as a result of changes in the consensus rules.

They come in two flavors, soft forks and hard forks.

Hard forks are aggressive changes, they will usually split the network because they’re mandatory, and make the machines that haven’t updated to the latest version incompatible with those running recent versions. This will also certainly have economical impacts with miners or participants interacting with a network with a worthless currency.

It’s worth mentionning that sometimes the hard forks could happen non intentionally. It could be because of a bug or a feature that did not take into account some computer architectures. This is why the review and test process inside Bitcoin Core is thorough and sometimes long.

Soft forks as their name suggests in the other hand are more soft changes. There’s actually no “fork” happening here, the term was coined to have a kind of opposite to hard forks. The changes made using this technic are forward compatible, meaning transactions and blocks created under the new rule must be valid under the old rules too, but not vice versa. This type of fork allow nodes with old versions to still continue to operate in consensus with the new rules.

Nodes could decide or be unable to update for multiple reasons: hardware/network constraints, not agreeing with the changes made to the recent version of the protocol etc.

Unlike traditional softwares, upgrades to decentralized system as Bitcoin is much more difficult and require coordination between all the participants. The preferred way of doing changes in Bitcoin is the soft forks way, so that a complete BIP on his own was released to describe the whole mechanism which is what will further retain our attention.

The soft forking mechanics

Before the advent of BIP 9, some alternatives were suggesting incrementing the value of the block version when deploying a feature. That’s what was used by BIP 34 (used version 2 in block header), 66 (strict DER, used version 3 in block header), 65 (CLTV, used version 4 in block header).

But the approach quickly shown some shortcomings, like we can’t deploy another feature until the previous one is failed or fully deployed and each new change was reducing the set of available block versions for future changes.

In contrast BIP 9 repurposed the version field from block header, which was initially a 4 bytes in size field. It is now considered as a bit vector and allow deploying up to 29 soft forks in parallel. Each bit could be used to deploy a feature, once a deployment has succeeded or failed, it could be reuse for other purposes.

In order to indicate that you’re making use of the version field as a bit field for signaling, the first three bits must be set to 001. This is the reason why you can only deploy 29 different proposals at time (32 - 3 = 29 bits).

Block Header

For deploying any changes that follow BIP 9 rules, the proposal must have a particular structure:

  • Name, it’s selected such that two concurrent deployments do not have the same value. BIP 9 recommends setting this value as “bipN” with N representing the BIP number.
  • Bit determines which bit in the version field of the block header should be used to signal the soft fork. It should be selected such that two concurrent deployment do not have the same value.
  • Start time specifies the time at which the selected Bit will start gaining its meaning. BIP 9 recommends setting this value around a month after software release.
  • Timeout this specifies a time at which the deployment will be considered as failed. Recommendation for this value is 1 year approximately 31536000 after start time.

start time and timeout here are defined to be using Median Time Past (MTP) which is the average time between the last 12 blocks created.

Once a soft fork has set all the previous values and is ready to be deployed, it will follow the following state transition diagram defined by BIP9:

State Transitions

Any proposal starts in DEFINED state. From there it can either times out, or for blocks with MTP after the Start Time, transition to STARTED. The proposal can then stay in STARTED state until it also times out or the signaling threshold is reached.

The value of the threshold here is determine based on a retarget period (2016 blocks). Its current value is set to be 95% (1916) of the blocks generated during the retarget period.

So If more than 95% of the blocks created during the previous retarget period have their bit in the version field set to 1, then the proposal state would transition to LOCKED_IN and one retarget period later, the proposal becomes ACTIVE and remains so perpetually.

Any proposal that times out before the voting threshold is reached will be a rejected. FAILED proposals remain in that state perpetually too and the bit could be reused for futur deployments.

Although soft forks keep everyone in the network communicating together, there have been a lot of critisim around them such as technical debt that they’re leaving behind, validation relaxation and irreversible upgrades.

Practical case: Deployment of Taproot using BIP 9

Taproot did not quite use BIP 9 but a modified variant of it. The important thing here is the general idea.

Parameters definition

  • Name: taproot
  • Bit: 2
  • Starttime: 24th April 2021, 00:00 (UTC)
  • Timeout: 11th August 2021, 00:00 (UTC)
  • Threshold: 90% of 2016 blocks

The BIP9 deployment parameters definition could be found at https://github.com/bitcoin/bitcoin/blob/f979b3237f1cfc28f9c4ccb07beab558d5357a55/src/chainparams.cpp#L88-L92

State transitions

The first period of blocks produced with the bit enabled was between 681408 and 683423. The signaling threshold was then reached at height 687455.

We can note that the threshold used for Taproot was 90% (1815 blocks) instead of the initial 95% we stated about previously. You can also notice that it did not use the 1 year guideline.

Taproot was activated on mainnet at height 709632 on 14 November 2021, 05:15:27.

Bonus: At which stage is BIP 110?

Parameters definition

BIP 110 which was proposing to temporarily reduce the size of arbitrary data that can be inserted in a block defined the following parameters:

  • name: reduced_data
  • bit: 4
  • starttime: 1764547200 (~December 1, 2025)
  • timeout: NO_TIMEOUT
  • min_activation_height: 0
  • max_activation_height: 965664 (~September 1, 2026)
  • active_duration: 52416 blocks (~1 year after activation)
  • threshold: 1109/2016 (55%)

As we can see it used also a variant of BIP 9 but this time with a threshold of only 55% ! and a NO_TIMEOUT 😮

If you’re curious enough I recommend checking more details about it https://bips.dev/110/.

State transition

BIP 110 used a parameter max_activation_height which was forcing lock-in regardless of sufficient signaling, means node implementing the changes were rejecting blocks that didn’t have the bit set from that height. This effectively splitted the network in two sides. Not enough nodes were found running BIP 110. From point of view of those not running it, the proposal transitioned to FAILED, but for those still running nodes with BIP 110 enabled it’s actually an ACTIVE proposal.

Conclusion

BIP9 is a good choice for doing soft forks in Bitcoin but it comes itself with some flaws, like miners refusing to signal activation of a feature until timeout is reached, to remediate that there’s an alternative BIP that was proposed, BIP8. It introduces some new fields and make few updates to the way soft forks are done.

Consensus developement is hard and we’re forced to recognize that there’s no perfect solution on the way of doing upgrades. Both soft forks and hard forks have their trade-offs. For some types of changes soft forks may be good choice and for other hard forks may be. You can see this a weakness or strength of consensus systems.

References

  • https://en.bitcoin.it/wiki/Softfork
  • https://en.bitcoin.it/wiki/Hardfork
  • https://bips.dev/9/
  • https://bips.dev/8/
  • https://learnmeabitcoin.com/technical/upgrades/taproot/
  • https://github.com/bitcoinbook/bitcoinbook/blob/develop/ch12_mining.adoc#soft-forks