A critical bug fix was provided in an emergency release of Bitcoin 0.8.5 earlier this evening. On September 9, Bitcoin-Qt users with versions more recent than 0.8.0 were unable to start their software and received errors that their database was corrupt:
coin database inconsistencies found
Users were then prompted to reindex the block chain, a process that could take hours and was ineffective in resolving the inconsistencies. Bitcoin-Qt is the graphical version of the standard bitcoin client and the problem was later observed in Bitcoind, the command line version.
The problem was caused by an abnormal transaction published in block 256818 around midnight EST on September 9. Bitcoin transactions contain fields including a version number, input parameters and output parameters among other things. The version number is currently set to 1 and allows for the network to adapt to different transaction types in the future while still providing support for older transactions.
The transaction number is stored as a 32 bit (4 byte) positive integer. The leftmost bit is reserved to indicate positive (0) or negative (1) values of the integer. When the bitcoin client read any version numbers larger than 0x7fffffff (which is 0 followed by 31 digits of 1 in hexadecimal) it would return an error since negative numbers were not expected.
The problem block contained a transaction which used a negative version number, causing errors when any database consistency checks were run. Since this is not possible to do using the standard bitcoin client, it is likely that a developer incorrectly set the transaction parameters before publishing it to the network. This bug only affected users starting-up the bitcoin client, since that is when the database consistency check was run. Those continuously running bitcoin software were unaffected.
Gregory Maxwell, a bitcoin core developer, quickly provided a solution on the forums which could be used until an updated version of the client could be released. He recommended adding “-checklevel=2” to the bitcoin configuration file. This used a less aggressive consistency check but did not create any security concerns.
This issue was not observed to affect any critical infrastructure, such as miners or exchanges, since they do not frequently restart their bitcoin software and use multiple nodes simultaneously. If they were forced to restart they could use the less aggressive consistency check and operate normally.
Maxwell submitted a workaround to be included in bitcoin version 0.8.5 four days ago which also made negative version numbers in transactions non-standard, preventing the issue from occurring in the future. This was tested by the bitcoin core development team and other members of the community before being released for public use.