34 votes

Why is bitcoin written in C++?

The most important reason is that the original Satoshi codebase was written in C++. A system like Bitcoin has extremely strong requirements about consistency in behaviour: all nodes on the network ...
Pieter Wuille's user avatar
30 votes

Why is bitcoin written in C++?

I gave a keynote address at cppcon 2016 about almost this exact issue. There are a variety of reasons why C++ is an excellent language choice for blockchain applications like Bitcoin. Blockchain ...
David Schwartz's user avatar
13 votes
Accepted

Why many classes in the Bitcoin Core prefix with a `C` while it is prohibited in the developer notes?

These classes predate the coding style guidelines. Guidelines are a recommendation for newly added code and refactoring patches for the purpose of only changing the coding style are discouraged. In ...
Antoine Poinsot's user avatar
11 votes

How to understand Bitcoin source code

I have a different approach to it. You can use this too. Bitcoin uses Doxygen comments to explain the code. You can take the most recent copy of the code, build class hierarchy yourself using ...
thenakulchawla's user avatar
9 votes
Accepted

Is it doable to supplant the current Bitcoin Core implementation with another rewritten in a different language?

There are many implementations of the Bitcoin protocol written in other languages, e.g., Bcoin in JavaScript, btcd in Go, bitcoin-s in Scala, etc. Bitcoin Core is widely considered as the "...
Michael Folkson's user avatar
9 votes
Accepted

How to understand Bitcoin source code

Recently I was in a situation where I had to work on Bitcoin-core c++ code base. Being from c# background, I had the same problem which you faced. I also looked into the solutions which everyone is ...
Vishwas Bhushan's user avatar
9 votes
Accepted

What version of C++ is used in Bitcoin Core?

Bitcoin Core: v0.1.0...v0.12.x: C++03 v0.13.0...v0.21.x: C++11 v22.0...: C++17
Pieter Wuille's user avatar
7 votes

Was the addition of OP_NOP codes in Bitcoin 0.3.6 a hard or soft fork?

When the script interpreter encounters an unknown opcode (the default: case inside the switch statement), it returns false. That aborts verification and considers the transaction to be invalid. This ...
Pieter Wuille's user avatar
7 votes

Why Bitcoin Core source code use #include bracket syntax instead of quote syntax

Double quotes means that the compiler will search for the include relative to the source file. Angle brackets means the compiler will search only the include paths. By using angle brackets and ...
Ava Chow's user avatar
  • 70.4k
5 votes

Is it doable to supplant the current Bitcoin Core implementation with another rewritten in a different language?

It is extremely difficult to write a specification for a complex format that is 100% watertight and has no poorly defined corner cases. Further even if the specification itself is watertight it's ...
Peter Green's user avatar
5 votes
Accepted

Why is CAmount a signed integer?

CAmount is used for multiple purposes in Bitcoin Core, not just in transaction validation logic. It is also used to represent the net effect transactions have on wallet balance, for example, and that ...
Pieter Wuille's user avatar
5 votes

What protocol do bitcoin nodes use to talk to each other?

What protocol do bitcoin nodes use to talk to each other? Most Bitcoin nodes will primarily use: Layer Protocol Application Layer Bitcoin Protocol Transport Layer Transport Control Protocol (TCP) ...
RedGrittyBrick's user avatar
4 votes
Accepted

Why future Bitcoin Core release shouldn't be in python?

Apart, from having to tear down the entire code, and re-write it in python and check for vulnerabilities, This is what is known as a self-answering question. The obstacles you list are not trivial. ...
RedGrittyBrick's user avatar
4 votes

Bitcoin value as int64_t or as double

I want to do program that doing some calculations with bitcoin values. I know bitcoin have 8 digits after decimal point (please correct me). There is no decimal in bitcoin at code level. There is no &...
Coding Enthusiast's user avatar
3 votes
Accepted

Was libbitcoin a part of bitcoin core in the past?

libbitcoin is not, and was never a part of Bitcoin Core. Both are standalone implementations of the Bitcoin protocol. Bitcoin Core, in its build process, will create a number of files named "...
Pieter Wuille's user avatar
3 votes

Transaction signature algorithm

The ECDSA digital signature scheme returns two values. To be specific, the X and Y values computed on the elliptic curve are returned. In Bitcoin the signture is DER encoded, which is represented as ...
Bjarne Magnussen's user avatar
3 votes
Accepted

C++ and secp256k1

Maybe libsecp256k1, which is what Bitcoin Core itself uses. Not sure about Android usability, but it compiles on many architectures.
Jannes's user avatar
  • 6,344
3 votes
Accepted

Why does the chacha20 implemented in the Bitcoin Core use a 64 bit nonce?

It doesn't matter. The old version has a 64-bit nonce and 64-bit counter, while the new one replaces it with a 96-bit nonce and 32-bit counter. For our purposes however, they can reasonably both be ...
Pieter Wuille's user avatar
3 votes
Accepted

What is the actual working implementation code used in double hashing a block header in c++?

Note that I am analyzing your code as if I compiled it as is. That means anything that is commented out is ignored. The first major issue is this line: kk = GetBinaryStringFromHexString(...
Ava Chow's user avatar
  • 70.4k
3 votes

Was the addition of OP_NOP codes in Bitcoin 0.3.6 a hard or soft fork?

There is nothing to suggest in the code diff you linked to that older clients ignored unknown opcodes in script execution and effectively treated them as OP_NOPs. That doesn't guarantee they didn't of ...
Michael Folkson's user avatar
3 votes
Accepted

What is the nBits field in the CBlockHeader class?

I interpret that it's a representation of the difficulty for the block. ... Is my understanding correct? Yes, it is a compact representation of the network target for that block. The target being a ...
RedGrittyBrick's user avatar
3 votes
Accepted

Is it possible to use the getboolarg function in interpreter.cpp

interpreter.cpp is part of the internal libbitcoin_consensus library, while GetBoolArg() is in common/args.{h/cpp} which is part of the internal libbitcoin_common library. The Makefile specifies a ...
Ava Chow's user avatar
  • 70.4k
2 votes

What is most efficient way to validate bitcoin target (difficulty) value in C++

Bitcoin Core has its own arith_uint256 class for calculations on 256-bit unsigned integers. Its code to convert "bits" (so-called compact format) to arith_uint256 can be found in arith_uint256::...
Nate Eldredge's user avatar
2 votes

How to debug bitcoin core in "real time"

There is no "makefile" command. If you don't build the project, there is no way for you to debug it. The released binaries do not contain any debugging symbols so it will be very difficult for you to ...
Ava Chow's user avatar
  • 70.4k
2 votes

How to understand wallets?

The address 13ggzjqKyFGQZtxNWUoG4BFDPAgdBijUe4 is generated from a different word list, not the one you mentioned.
yahiheb's user avatar
  • 169
2 votes
Accepted

How to update an older C++ code from Antonopoulos' book to work with current libraries?

I just found out there is a github where the code is updated. The specific code for addr.cpp is this. Compilation works with --static e.g. g++ -o addr addr.cpp $(pkg-config --cflags --libs --static ...
bomben's user avatar
  • 518
2 votes
Accepted

What is cs_main? Why is it called cs_main?

What is cs_main? cs_main is a recursive mutex which is used to ensure that validation is carried out in an atomic way. It guards access to validation specific variables (such as CChainState and CNode)...
Michael Folkson's user avatar
2 votes

How to generate private/public key pairs in c++ using openssl

Usually you'd just pass around the EVP_PKEY structure to other OpenSSL calls. To put the secret into memory, you can use char* secret_key; BIO* bio_priv = BIO_new(BIO_s_mem()); ...
meshcollider's user avatar
  • 11.8k
2 votes
Accepted

How does AttachChain function works in the Bitcoin Core?

ReadBestBlock doesn't look at the locator it is given, rather it reads a specific record from the wallet database and loads the data into the provided locator. locator is used as an output parameter. ...
Ava Chow's user avatar
  • 70.4k
2 votes

What protocol do bitcoin nodes use to talk to each other?

Bitcoin nodes use a custom tcp-based protocol to communicate with each other. There's a work in progress to deploy a new one with some privacy enhancements.
Davidson Souza's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible