Skip to content

Instantly share code, notes, and snippets.

@gavinandresen
Created April 10, 2012 23:09
Show Gist options
  • Save gavinandresen/2355445 to your computer and use it in GitHub Desktop.
Save gavinandresen/2355445 to your computer and use it in GitHub Desktop.
Suggestions on more smoothly rolling out blockchain validation rule changes

Blockchain Rule Update Process

We recently rolled out two changes to the Bitcoin block acceptance rules (BIP16 and BIP30); this document records the lessons learned and makes recommendations for handling future blockchain rule changes.

Note: there are "soft" rule changes and "hard" rule changes. "Soft" changes tighten up the rules-- old software will accept all the blocks and transactions created by new software, but the opposite may not be true. "Soft" changes do not require the entire network of miners and merchants and users to upgrade or be left behind.

"Hard" changes modify the rules in a way that old, un-upgraded software consider illegal. At this point it is much, much more difficult (some might say impossible) to roll out "hard" changes, because they require every miner and merchant and user to upgrade.

Lessons Learned

  • Be sure to consider all 4 combinations of old/new software running before/after the majority of the network supports the new rule(s).
  • Backwards compatibility with old clients/miners is extremely important.
  • Arrange for changes to become active on testnet before the main network.
  • Think about laying a solid foundation, and then rolling out changes in stages. Baby steps instead of change-it-all-at-once.

If I was doing BIP16 over again and knew everything then I know now, I would propose rolling out support in three stages:

  1. Tighten up the "IsStandard" rule so it checked for 'standard' inputs. This would have prevented old miners from accidently putting invalid-under-new-rules transactions into their blocks.
  2. Add n-of-3 CHECKMULTISIGs as 'standard' transactions.
  3. Add BIP16 "pay to script hash" as 'standard' transactions.
  • Completely non-controversial changes can happen relatively quickly (1-2 weeks).

BIP30 is a good example of a completely non-controversial change.

  • Controversial changes can take months to deploy, even after there is rough consensus among the core developer, users, and miners.

BIP16 is a good example of a controversial change.

  • People are error-prone; expect mistakes if you rely on people to set a configuration switch to support a new feature.

During the BIP16 adoption period some BIP16-supporting miners failed to update the switchover date for some of their nodes, and wasted time hashing on a minority chain. Several users also had the same problem because they were using an older 'release candidate' and hadn't upgraded.

They quickly realized and fixed their mistake, but it would be better if the switchover date/time was automatic based on the blockchain history. Code to do that could be written and tested once and then re-used for future upgrades.

  • Blocks and transactions have version numbers; use them!

Late in the BIP12/BIP16/BIP17 debate somebody suggested that the new transactions should have a new version number. Which is a very good idea that "we" should have thought of at the beginning of the process. We should have used both block and transaction version numbers to support the new transaction form.

Block version numbers will be a better way for miners to indicate the rules they're using for validation, and to judge whether or not there is majority support for some new validation rule (BIP16 put the string "/P2SH/" in the coinbase transaction to judge support).

Old software that sees a majority of recent blocks in the chain with a version number that they do not understand should warn the user that their software is out of date and should be upgraded, but will otherwise ignore the version number and perform normal block and transaction validation.

Transaction version numbers will be a better way to specify exactly what rues should be used to validate a transaction; transactions with old version numbers will be validated under the old rules, transactions with new version numbers will always be validated under the new rules before being relayed or included in mined blocks. To avoid being in the minority fork of a block chain split, transactions with new version numbers appearing in blocks will only be validated using the new rules when a super-majority of the network (as expressed by block version numbers in the last N blocks) supports the new feature.

A transaction's version number is part of it's hash (transaction ID) and is part of the signature hash, so cannot be changed by an attacker. However, software using new transaction features will need to make sure that transactions have the correct version number before asking users to provide signatures or telling users that the transaction has been properly signed, etc.

Upgrade Process Recommendations

There are some changes to core Bitcoin that should be made now that will make future upgrades smoother:

  • Consider a transaction non-standard (do not accept it into the memory pool) if it has an unknown version number.
  • Implement code to keep track of counts of block version numbers over the last 1,000 blocks.
  • If 55% or more of the last 1000 blocks have an unknown version number, warn the user that they need to upgrade.

Upgrade scenarios:

Here are some thumbnail sketches of how possible future upgrades could be handled in a way that minimizes risk and disruption.

Example: re-define OP_NOP1 to be OP_Q_CHECKSIGVERIFY, using a quantum-resistant digital signature algorithm.

  1. The opcode must be designed so that either the transaction fails validation OR it behaves exactly like a no-op. Any other design (e.g. one that consumes or leaves values on the stack) lets an attacker craft transactions that will be valid under the new rules but invalid for old miners/clients, causing a blockchain split.
  2. Transactions that use the new opcode are given a new version number.
  3. Miners running the new code produce blocks with a new version number, so support for the new feature can be measured.
  4. Older nodes will not relay or mine the new transactions, or transactions that spend the new transactions.
  5. New nodes will interpret OP_NOP1 as OP_Q_CHECKSIGVERIFY only if the transaction version number is correct, and 75+% of blocks created over the last 1000 blocks have an updated version number (51% of the last 100 blocks if on testnet).

Note that the "75% of the blocks created...." rule automatically handles old parts of the old block chain that might have invalid-under-the-new-rules transactions and also handles fluctuations in support; parts of the block-chain with less than 75% support will be validated under the old rules, parts with more than 75% support under the new. Users should not rely on the new feature until there is clear, consistent support.

Example: increasing MAX_BLOCK_SIZE (a 'hard' blockchain split change)

Increasing the maximum block size beyond the current 1MB per block (perhaps changing it to a floating limit based on a multiple of the median size of the last few hundred blocks) is a likely future change to accomodate more transactions per block. A new maximum block size rule might be rolled out by:

  1. New software creates blocks with a new block.version
  2. Allow greater-than-MAX_BLOCK_SIZE blocks if their version is the new block.version or greater and 100% of the last 1000 blocks are new blocks. (51% of the last 100 blocks if on testnet)

100% of the last 1000 blocks is a straw-man; the actual criteria would probably be different (maybe something like block.timestamp is after 1-Jan-2015 and 99% of the last 2000 blocks are new-version), since this change means the first valid greater-than-MAX_BLOCK_SIZE-block immediately kicks anybody running old software off the main block chain.

@DanielBrewster1111
Copy link

0000_0000_0000_0000_0001

@RaviRaj167
Copy link

Wonderful Creations To Sathosi Nakamoto Sir
handn"s of to you sir
i am your fan
iam a indian

@Thisdick69
Copy link

Thanks

@Thisdick69
Copy link

Sweet

@Manny27nyc
Copy link

Thank you

@Manny27nyc
Copy link

Wonderful Creations To Sathosi Nakamoto Sir
handn"s of to you sir
i am your fan
iam a indian

Thank you

@Thisdick69
Copy link

Thanks

@Thisdick69
Copy link

Sweet

@Thisdick69
Copy link

satoshi-genesis-wallet

@Thisdick69
Copy link

Thisdick69 commented Jul 15, 2023

![34903ccd4c0f4dfcb6b1065a3dc80fe2](https://user- (Anthony Dewayne Hunt) images.githubusercontent.com/90084154/253704031-0313a60b-2dfe-48ef-bd0c-4513225c99a7.jpg)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment