Why Bitcoin Uses C++

Last Updated on January 7, 2023

A system like Bitcoin has extremely strong requirements about consistency in behavior: all nodes on the network must accept and reject the exact same blocks. The first choice to avoid bugs that risk introducing inconsistency is to not rewrite the code from scratch.

Memory

C++ provides very tight control over memory usage. Many modern languages (especially those that rely on garbage collection) make it hard if not impossible to reason about tight bounds of memory usage.

Bitcoin Core is a security-critical application directly exposed to the internet, it is nontrivial to guarantee that there is no way to trigger allocation of large amounts of memory, either thrashing machine swap space, or worse, killing the process.

Performance

The network relies on quick validation and propagation of blocks. If blocks take too long to validate compared to their creation frequency, economic factors start to unfairly advantage larger and faster miners – enabling a Selfish Mining Attack.

Under extreme conditions, if blocks would take ~minutes to validate, the network may fail to converge at all, as nodes simply don’t hear about blocks in time anymore.