Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: Flevio23 on August 30, 2020, 10:52:46 PM



Title: Study Bitcoin core source code
Post by: Flevio23 on August 30, 2020, 10:52:46 PM
Hi,

I have read a lot of documentation and books where they explain the general functioning of Bitcoin and I think that the time has come to study the source code of Bitcoin core.

I have knowledge of c++ and python but due to the large size of the project and the number of files, I don't know where it would be correct to start.

Could someone help me on how to properly perform that task?


Title: Re: Study Bitcoin core source code
Post by: NotATether on August 31, 2020, 09:05:07 AM
You should start by reading the Bitcoin developer documentation (https://developer.bitcoin.org/), it has a section about examples that show you the outputs different parts of bitcoin core make, along with their input parameters. The Reference, Developer guide and Glossary are also good resources.

You can also study the various BIPs inside the codebase and the associated Github issues and pull requests that implement those BIPs. These BIPs give a high level description of how the protocol works and since Bitcoin core is an implementation of this protocol you get to see how each part of it is implemented in C++.

The bitcoin-dev (https://lists.linuxfoundation.org/pipermail/bitcoin-dev/) mailing list also contains a few gems that explain why some parts of bitcoin core code are written the way they are.


Title: Re: Study Bitcoin core source code
Post by: Pmalek on August 31, 2020, 02:26:57 PM
You can try reading Mastering Bitcoin by Andreas Antonopoulos if you haven't already. It's a technical piece meant for programmers. 
https://www.oreilly.com/library/view/mastering-bitcoin-2nd/9781491954379/

This is a very basic guide on Bitcoin development that could be useful.
https://blockgeeks.com/guides/bitcoin-developer/


Title: Re: Study Bitcoin core source code
Post by: hugeblack on August 31, 2020, 06:31:48 PM
You need to rethink it a bit, Bitcoin is not a program but rather a set of protocols that are cooperated by the community. As long as you follow these rules, you can set up your own Core.
To simplify things, choose the first versions[1] (less than 20K lines,) follow the changes and updates that have occurred and then it will be easier for you.
You can also ask any questions here.

[1] https://github.com/bitcoin/bitcoin/releases/tag/v0.1.5


Title: Re: Study Bitcoin core source code
Post by: Heisenberg_Hunter on September 01, 2020, 11:02:37 AM
If you already have a really good overview of how bitcoin works on a practical scale, then you should be skipping the Mastering Bitcoin book suggested by Pmalek. Mastering Bitcoin will take you from the start of what bitcoin is and will end with the most advanced concepts of the complete protocol. The book itself is over 2 years old and might be a little bit outdated with minor changes which has happened in these 2 years.

If you are willing to get into the protocol development or testing or understanding them in a raw level, you should probably practice more source code examples from Programming Bitcoin book by Jimmy Song. The book itself is written for python developers and covers some of the difficult tech which bitcoin has currently. You will be able to interact with the protocol and once you have done that, read a lot of resources from Jameson Lopp's website which ETFbitcoin has said.

Later when you have read a few resources, try finishing off Chaincode Labs curriculum (https://github.com/chaincodelabs/bitcoin-curriculum) This is really a good syllabus book like material for you to understand protocol and cryptography at a basic level and will help you in getting forward in the code. So if you have done with all the above resources, start with reading example_test.py (https://github.com/bitcoin/bitcoin/blob/master/test/functional/example_test.py) from functional tests. You should be knowing atleast a little bit of python testing code before you get into the main code. example_test.py is really a good starting point and has been written with keeping newbies in mind.

Participate in a lot of weekly PR review club (https://bitcoincore.reviews/) hosted by John Newbery and other lead devs. You can ask doubts regarding the PR on a technical scale and they will be happy to help. This week, I think we have Taproot review and I hope it will be exciting for you to attend the meeting.


Title: Re: Study Bitcoin core source code
Post by: unsigned_long_long on September 03, 2020, 12:31:53 AM
Hi,

I have read a lot of documentation and books where they explain the general functioning of Bitcoin and I think that the time has come to study the source code of Bitcoin core.

I have knowledge of c++ and python but due to the large size of the project and the number of files, I don't know where it would be correct to start.

Could someone help me on how to properly perform that task?

Speaking as somebody who has tinkered with the C++ codebase a few times, I find a good way to learn it is to first look in the test (https://github.com/bitcoin/bitcoin/tree/master/src/test) directory, and run some of the tests individually, try them with different inputs, etc.

All the tests for most of the core protocol stuff are in here - scripts, base58, transaction, etc. So you can relate the core data structures back to all the books you've read on the topic.

It's not the easiest code base to understand, I find it's helpful to use an IDE with a bookmarking facility so you can "map out" the important parts.

Good luck!


Title: Re: Study Bitcoin core source code
Post by: pooya87 on September 03, 2020, 03:52:58 AM
the problem with looking at bitcoin core source code and trying to "study" that is that it has little to no documentation. there are some comments in some parts that are doing very specific things (such as preventing a very special attack vector) but the basic things (block verification, scripts,...) are never explained and some of them are very difficult to understand.
that means you first have to have a very good understanding of bitcoin protocol before you start looking at the source code. using some of the sources mentioned before (dev. doc.) should be your first step.


Title: Re: Study Bitcoin core source code
Post by: Wind_FURY on September 03, 2020, 11:56:35 AM
OP, you can also reach out to some of the other developers. I'm not sure if it's active, but the IRC channel bitcoin-core-dev on freenode might have people there who can help you.

I believe reaching out to achow and gmaxwell in the forum could also help start your journey. There's also Bitcoin Stack Exchange. The resources are everywhere if you know where to look, and as long as you persist. Good luck.


Title: Re: Study Bitcoin core source code
Post by: Flevio23 on September 08, 2020, 07:25:13 PM
Thank you all for the answers. I think I have been very presumptuous in trying to understand, with my current knowledge, the code. Your advice will be very useful to me to continue moving forward. Studying bitcoin is one of the few things that motivates me, as my current job frustrates and bores me.


Title: Re: Study Bitcoin core source code
Post by: Wind_FURY on September 11, 2020, 09:28:22 AM
Thank you all for the answers. I think I have been very presumptuous in trying to understand, with my current knowledge, the code. Your advice will be very useful to me to continue moving forward. Studying bitcoin is one of the few things that motivates me, as my current job frustrates and bores me.


It's not for everyone, but if you're passionate enough, follow what feels right for you. Plus if you want to be a good developer of Bitcoin/cryptocurrencies, I heard that some adequate understanding of applied cryptography is needed. Good luck.


Title: Re: Study Bitcoin core source code
Post by: Wind_FURY on October 15, 2020, 07:22:16 AM
OP, here is another good resource for people like you, who are aspiring to be Bitcoin developers, https://twitch.tv/videos/768401215

achow shows some of his work in real time. I believe you can also show some support through Twitch donations in the chat-box.


Title: Re: Study Bitcoin core source code
Post by: DaCryptoRaccoon on October 19, 2020, 05:16:13 PM
I started a topic on the breakdown of the Satoshi codebase feel free to add to it.

https://bitcointalk.org/index.php?topic=5077159.msg48300324#msg48300324


Title: Re: Study Bitcoin core source code
Post by: Wind_FURY on October 24, 2020, 08:55:12 AM
I started a topic on the breakdown of the Satoshi codebase feel free to add to it.

https://bitcointalk.org/index.php?topic=5077159.msg48300324#msg48300324


To all actual coders who have actual experience in cryptography. Based on Satoshi's code, would you give thought to some of the doubts that Satoshi wasn't a "cypherpunk" before Bitcoin? Or was he that good in concealing his real identity?


Title: Re: Study Bitcoin core source code
Post by: DaCryptoRaccoon on October 26, 2020, 05:20:11 PM
I started a topic on the breakdown of the Satoshi codebase feel free to add to it.

https://bitcointalk.org/index.php?topic=5077159.msg48300324#msg48300324


To all actual coders who have actual experience in cryptography. Based on Satoshi's code, would you give thought to some of the doubts that Satoshi wasn't a "cypherpunk" before Bitcoin? Or was he that good in concealing his real identity?

I don't think it matters if he was or was not a cypherpunk he had the right idea and released it at the right time sometimes that is all that matters.  He did leave a few trails about the place but I would say he did a pretty good job keeping his identity a secret.

What I find amazing is the fact that no one has yet been able to uncover the person behind the name and I really hope that it continues to stay that way.


Title: Re: Study Bitcoin core source code
Post by: seoincorporation on November 09, 2020, 11:45:08 PM
A good start would be to put your hands on the code... Install the core and make it run, see what can you do from the command line, create a test net, make transactions, sign them and send them. Learn as much as you can on the fly and then modify parameter on the code.

A nice challenge for a coder like you would be to create a genesis block and start your own bitcoin. I think this is the best way to get familiarized with the code.


Title: Re: Study Bitcoin core source code
Post by: Wind_FURY on November 13, 2020, 06:16:10 AM
I started a topic on the breakdown of the Satoshi codebase feel free to add to it.

https://bitcointalk.org/index.php?topic=5077159.msg48300324#msg48300324


To all actual coders who have actual experience in cryptography. Based on Satoshi's code, would you give thought to some of the doubts that Satoshi wasn't a "cypherpunk" before Bitcoin? Or was he that good in concealing his real identity?

I don't think it matters if he was or was not a cypherpunk he had the right idea and released it at the right time sometimes that is all that matters.  He did leave a few trails about the place but I would say he did a pretty good job keeping his identity a secret.


That wasn't the question. You as a coder, I was asking based on the code he wrote, can you tell if he was a cypherpunk, or an outsider?

I believe the only person in the cryptography mailing that appreciated Bitcoin was Hal.

Quote

What I find amazing is the fact that no one has yet been able to uncover the person behind the name and I really hope that it continues to stay that way.


He might be hiding in plain sight. 8)


Title: Re: Study Bitcoin core source code
Post by: chrisvl on November 15, 2020, 01:08:06 PM
This questions has not a single answer and you should to explore diffrent opinions in order to find the ideal for you.
My opinion is to not read the source code files like a book you will not gain anything, Back in school, when student reads something he thinks that understand it..But, doing is where the real learning takes place, you can create an altcoin based on bitcoin 0.9v its easy you have to change only 2-3 lines of code, and start perfome changes to code then test test test!!


Title: Re: Study Bitcoin core source code
Post by: BrewMaster on November 15, 2020, 03:39:33 PM
But, doing is where the real learning takes place, you can create an altcoin based on bitcoin 0.9v its easy you have to change only 2-3 lines of code, and start perfome changes to code then test test test!!

that would only create a parrot who can edit text files after reading some guide on the internet not someone who understands how bitcoin works.
you have to understand what you change, what those changes affect and why you are changing them.


Title: Re: Study Bitcoin core source code
Post by: TofuDefi on November 29, 2020, 08:33:00 AM
Hi,

I have read a lot of documentation and books where they explain the general functioning of Bitcoin and I think that the time has come to study the source code of Bitcoin core.

I have knowledge of c++ and python but due to the large size of the project and the number of files, I don't know where it would be correct to start.

Could someone help me on how to properly perform that task?

Start with src/chainparams.cpp.