Bitcoin Forum
April 02, 2026, 10:40:02 PM *
News: Latest Bitcoin Core release: 30.2 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Anyone has a minimalistic, C++ Implementation of the original bitcoin protocol?  (Read 287 times)
bitcurve (OP)
Member
**
Offline Offline

Activity: 76
Merit: 11


View Profile
November 27, 2024, 05:40:19 AM
Merited by vapourminer (1), ABCbits (1)
 #1

I was wondering if anyone has a minimalistic, C++ (can also be C, or any other lang, as long as it's minimalistic but complete) Implementation of the original bitcoin protocol, and by "the original bitcoin protocol" I mean just the most basic features, legacy addresses and maybe basic multisig functionality only, only what is necessary to form a working bitcoin chain.

I searched for it for sometime in github with no luck. any implementation i find is either something like btcd, with more advanced non-minimalistic features or a miniature blockchain.
pooya87
Legendary
*
Offline Offline

Activity: 4102
Merit: 12279



View Profile
November 27, 2024, 06:27:57 AM
 #2

What exactly are you trying to do and what parts of the libraries do you find non-minimalistic and why is that a problem?  A Bitcoin library is either incomplete which is not a good idea to use or is a full implementation of Bitcoin Protocol. It would be pointless for someone to implement like half of the protocol.

In any case since you mentioned "original protocol", here is the bitcoin core's first version that can be found on the internet: https://github.com/benjiqq/bitcoinArchive maybe that helps.

███████████████████████████
███████▄████████████▄██████
████████▄████████▄████████
███▀█████▀▄███▄▀█████▀███
█████▀█▀▄██▀▀▀██▄▀█▀█████
███████▄███████████▄███████
███████████████████████████
███████▀███████████▀███████
████▄██▄▀██▄▄▄██▀▄██▄████
████▄████▄▀███▀▄████▄████
██▄███▀▀█▀██████▀█▀███▄███
██▀█▀████████████████▀█▀███
███████████████████████████
.
.Duelbits PREDICT..
█████████████████████████
█████████████████████████
███████████▀▀░░░░▀▀██████
██████████░░▄████▄░░████
█████████░░████████░░████
█████████░░████████░░████
█████████▄▀██████▀▄████
████████▀▀░░░▀▀▀▀░░▄█████
██████▀░░░░██▄▄▄▄████████
████▀░░░░▄███████████████
█████▄▄█████████████████
█████████████████████████
█████████████████████████
.
.WHERE EVERYTHING IS A MARKET..
█████
██
██







██
██
██████
Will Bitcoin hit $200,000
before January 1st 2027?

    No @1.15         Yes @6.00    
█████
██
██







██
██
██████

  CHECK MORE > 
bitcurve (OP)
Member
**
Offline Offline

Activity: 76
Merit: 11


View Profile
November 27, 2024, 06:49:11 AM
 #3

Well the original early versions are GUI versions with outdated libraries. Any GUI version is not minimalistic...


It's not a problem, i just want a minimalistic implementation
vjudeu
Copper Member
Legendary
*
Offline Offline

Activity: 909
Merit: 2363


View Profile
November 27, 2024, 07:32:59 AM
Merited by BlackHatCoiner (4), vapourminer (1), ABCbits (1), tiltedIceCream (1)
 #4

Quote
only what is necessary to form a working bitcoin chain
Then, just take version 0.1.0, and remove things, which you don't need. For example: instead of "scriptSig" and "scriptPubKey", you only need "sig" and "pubKey", and ECDSA implementation. I guess the bare minimum is hashing, so you can start from SHA-256 implementation (because then, you can form a chain). The next thing is public key cryptography, which means secp256k1 implementation. If you have those two, then you can form the basic chain. If you ignore everything else, then you will have "downgraded soft-fork", where your version will only check P2PK, and accept everything else as valid.

Quote
Anyone has a minimalistic, C++ Implementation of the original bitcoin protocol?
I was trying to do something like that, but it is not yet ready.

Quote
What exactly are you trying to do and what parts of the libraries do you find non-minimalistic and why is that a problem?
I guess it is about recreating the process of making Bitcoin from scratch. Because between empty main function, and the first released version, there are definitely more points, where you have "half-baked coin", and where you can learn, why things are set, the way they are. For example: the bare minimum doesn't need any Script. The bare minimum doesn't need versioning. And there are many other things, which you can remove, and still cover everything, what is described in the whitepaper.

So, to sum up: start from SHA-256 implementation, which will give you just "something mineable, without any public keys". Then, add public keys support. And then, you will have the bare minimum.

And if you want to test some basic concepts, then you can even downgrade it into SHA-1 with secp160k1, or even CRC-32 with some 32-bit elliptic curve, if you want some weaker test network.

Quote from: satoshi
I've moved on to other things.
ABCbits
Legendary
*
Offline Offline

Activity: 3570
Merit: 9884



View Profile
November 27, 2024, 08:54:37 AM
Merited by pooya87 (4), BlackHatCoiner (4), vapourminer (1), bitcurve (1)
 #5

I searched for it for sometime in github with no luck. any implementation i find is either something like btcd, with more advanced non-minimalistic features or a miniature blockchain.

Have you come across https://github.com/piotrnar/gocoin? The newest version have wallet, CLI and web UI, but the older version only have CLI and wallet where the wallet's code is separated from full node client. In addition, gocoin is created by only one person, so i expect he make things as simple as possible to make it easier to maintain.

But take note that gocoin simply load entire UTXO into RAM.

███████████████████████████
███████▄████████████▄██████
████████▄████████▄████████
███▀█████▀▄███▄▀█████▀███
█████▀█▀▄██▀▀▀██▄▀█▀█████
███████▄███████████▄███████
███████████████████████████
███████▀███████████▀███████
████▄██▄▀██▄▄▄██▀▄██▄████
████▄████▄▀███▀▄████▄████
██▄███▀▀█▀██████▀█▀███▄███
██▀█▀████████████████▀█▀███
███████████████████████████
.
.Duelbits PREDICT..
█████████████████████████
█████████████████████████
███████████▀▀░░░░▀▀██████
██████████░░▄████▄░░████
█████████░░████████░░████
█████████░░████████░░████
█████████▄▀██████▀▄████
████████▀▀░░░▀▀▀▀░░▄█████
██████▀░░░░██▄▄▄▄████████
████▀░░░░▄███████████████
█████▄▄█████████████████
█████████████████████████
█████████████████████████
.
.WHERE EVERYTHING IS A MARKET..
█████
██
██







██
██
██████
Will Bitcoin hit $200,000
before January 1st 2027?

    No @1.15         Yes @6.00    
█████
██
██







██
██
██████

  CHECK MORE > 
bitcurve (OP)
Member
**
Offline Offline

Activity: 76
Merit: 11


View Profile
November 27, 2024, 12:12:24 PM
 #6

I searched for it for sometime in github with no luck. any implementation i find is either something like btcd, with more advanced non-minimalistic features or a miniature blockchain.

Have you come across https://github.com/piotrnar/gocoin? The newest version have wallet, CLI and web UI, but the older version only have CLI and wallet where the wallet's code is separated from full node client. In addition, gocoin is created by only one person, so i expect he make things as simple as possible to make it easier to maintain.

But take note that gocoin simply load entire UTXO into RAM.

That's something quite close to what I was looking for. Thank you so much!
NotATether
Legendary
*
Offline Offline

Activity: 2296
Merit: 9604


┻┻ ︵㇏(°□°㇏)


View Profile WWW
November 28, 2024, 01:01:58 PM
 #7

I searched for it for sometime in github with no luck. any implementation i find is either something like btcd, with more advanced non-minimalistic features or a miniature blockchain.

Have you come across https://github.com/piotrnar/gocoin? The newest version have wallet, CLI and web UI, but the older version only have CLI and wallet where the wallet's code is separated from full node client. In addition, gocoin is created by only one person, so i expect he make things as simple as possible to make it easier to maintain.

But take note that gocoin simply load entire UTXO into RAM.

That's something quite close to what I was looking for. Thank you so much!

There is also a similar client written in Python called pycoin, but it's no longer maintained.

https://pypi.org/project/pycoin/

Quote
only what is necessary to form a working bitcoin chain
Then, just take version 0.1.0, and remove things, which you don't need. For example: instead of "scriptSig" and "scriptPubKey", you only need "sig" and "pubKey", and ECDSA implementation. I guess the bare minimum is hashing, so you can start from SHA-256 implementation (because then, you can form a chain). The next thing is public key cryptography, which means secp256k1 implementation. If you have those two, then you can form the basic chain. If you ignore everything else, then you will have "downgraded soft-fork", where your version will only check P2PK, and accept everything else as valid.

Actually, not even 0.1.0. In fact even versions like 0.2 - 0.6 would be suitable as well, not to mention OP will be able to see things like P2PKH and even be able to sync it to the chain fully (at least 0.4.something and up [I forgot exactly which version is the minimum but achow wrote it somewhere]).

 
 b1exch.to 
  ETH      DAI   
  BTC      LTC   
  USDT     XMR    
.███████████▄▀▄▀
█████████▄█▄▀
███████████
███████▄█▀
█▀█
▄▄▀░░██▄▄
▄▀██▄▀█████▄
██▄▀░▄██████
███████░█████
█░████░█████████
█░█░█░████░█████
█░█░█░██░█████
▀▀▀▄█▄████▀▀▀
bitcurve (OP)
Member
**
Offline Offline

Activity: 76
Merit: 11


View Profile
November 28, 2024, 01:45:00 PM
 #8

I searched for it for sometime in github with no luck. any implementation i find is either something like btcd, with more advanced non-minimalistic features or a miniature blockchain.

Have you come across https://github.com/piotrnar/gocoin? The newest version have wallet, CLI and web UI, but the older version only have CLI and wallet where the wallet's code is separated from full node client. In addition, gocoin is created by only one person, so i expect he make things as simple as possible to make it easier to maintain.

But take note that gocoin simply load entire UTXO into RAM.

That's something quite close to what I was looking for. Thank you so much!

There is also a similar client written in Python called pycoin, but it's no longer maintained.

https://pypi.org/project/pycoin/

Quote
only what is necessary to form a working bitcoin chain
Then, just take version 0.1.0, and remove things, which you don't need. For example: instead of "scriptSig" and "scriptPubKey", you only need "sig" and "pubKey", and ECDSA implementation. I guess the bare minimum is hashing, so you can start from SHA-256 implementation (because then, you can form a chain). The next thing is public key cryptography, which means secp256k1 implementation. If you have those two, then you can form the basic chain. If you ignore everything else, then you will have "downgraded soft-fork", where your version will only check P2PK, and accept everything else as valid.

Actually, not even 0.1.0. In fact even versions like 0.2 - 0.6 would be suitable as well, not to mention OP will be able to see things like P2PKH and even be able to sync it to the chain fully (at least 0.4.something and up [I forgot exactly which version is the minimum but achow wrote it somewhere]).

I think it's better off to start with the qt versions rather than the wxwidgets versions actually, but anyhow these old bitcoin source codes are not as good looking (in the sense of code readability) as a project like gocoin.

I actually found out that gocoin doesn't verify the block's hash values, it just trusts whoever sends them. I think there are many more issues with gocoin i'm yet to find.

So i choose to go with btcd, I'm now stripping it down to the bare minimum.
pooya87
Legendary
*
Offline Offline

Activity: 4102
Merit: 12279



View Profile
November 29, 2024, 06:37:39 AM
 #9

I actually found out that gocoin doesn't verify the block's hash values, it just trusts whoever sends them. I think there are many more issues with gocoin i'm yet to find.
What do you mean?
Gocoin is a full node which means it should verify the blocks it receives (the hash alone is not verified, the entire block is) and a quick look at the code seems like it does have the block verification code
https://github.com/piotrnar/gocoin/blob/master/lib/chain/block_check.go
And you can see it is verifying everything including but not limited to PoW, version, weight, transactions, etc.

███████████████████████████
███████▄████████████▄██████
████████▄████████▄████████
███▀█████▀▄███▄▀█████▀███
█████▀█▀▄██▀▀▀██▄▀█▀█████
███████▄███████████▄███████
███████████████████████████
███████▀███████████▀███████
████▄██▄▀██▄▄▄██▀▄██▄████
████▄████▄▀███▀▄████▄████
██▄███▀▀█▀██████▀█▀███▄███
██▀█▀████████████████▀█▀███
███████████████████████████
.
.Duelbits PREDICT..
█████████████████████████
█████████████████████████
███████████▀▀░░░░▀▀██████
██████████░░▄████▄░░████
█████████░░████████░░████
█████████░░████████░░████
█████████▄▀██████▀▄████
████████▀▀░░░▀▀▀▀░░▄█████
██████▀░░░░██▄▄▄▄████████
████▀░░░░▄███████████████
█████▄▄█████████████████
█████████████████████████
█████████████████████████
.
.WHERE EVERYTHING IS A MARKET..
█████
██
██







██
██
██████
Will Bitcoin hit $200,000
before January 1st 2027?

    No @1.15         Yes @6.00    
█████
██
██







██
██
██████

  CHECK MORE > 
NotATether
Legendary
*
Offline Offline

Activity: 2296
Merit: 9604


┻┻ ︵㇏(°□°㇏)


View Profile WWW
December 01, 2024, 09:52:06 AM
Merited by vapourminer (1), ABCbits (1)
 #10

I think it's better off to start with the qt versions rather than the wxwidgets versions actually, but anyhow these old bitcoin source codes are not as good looking (in the sense of code readability) as a project like gocoin.

Alright, but just a warning about the Qt builds:

I don't know when they started building with Qt5, but old builds using Qt4 (if any) are going to be extremely hard to compile since most distros stopped shipping Qt4 libraries in their repos. You're better off using an older distribution in that case.

Happened to me while I was trying to run Armory (a bitcoin wallet) so this could be relevant here.

 
 b1exch.to 
  ETH      DAI   
  BTC      LTC   
  USDT     XMR    
.███████████▄▀▄▀
█████████▄█▄▀
███████████
███████▄█▀
█▀█
▄▄▀░░██▄▄
▄▀██▄▀█████▄
██▄▀░▄██████
███████░█████
█░████░█████████
█░█░█░████░█████
█░█░█░██░█████
▀▀▀▄█▄████▀▀▀
bitcurve (OP)
Member
**
Offline Offline

Activity: 76
Merit: 11


View Profile
December 01, 2024, 11:34:33 AM
 #11

I think it's better off to start with the qt versions rather than the wxwidgets versions actually, but anyhow these old bitcoin source codes are not as good looking (in the sense of code readability) as a project like gocoin.

Alright, but just a warning about the Qt builds:

I don't know when they started building with Qt5, but old builds using Qt4 (if any) are going to be extremely hard to compile since most distros stopped shipping Qt4 libraries in their repos. You're better off using an older distribution in that case.

Happened to me while I was trying to run Armory (a bitcoin wallet) so this could be relevant here.


Thanks for the information,
I am currently working on some code based on btcd, however.
antanst
Sr. Member
****
Offline Offline

Activity: 295
Merit: 260


View Profile
December 06, 2024, 09:13:40 PM
 #12

I was wondering if anyone has a minimalistic, C++ (can also be C, or any other lang, as long as it's minimalistic but complete) Implementation of the original bitcoin protocol

https://github.com/chjj/mako

alexeyneu
Member
**
Offline Offline

Activity: 392
Merit: 44


View Profile
December 07, 2024, 06:35:12 PM
 #13

Quote
only what is necessary to form a working bitcoin chain
Then, just take version 0.1.0, and remove things, which you don't need. For example: instead of "scriptSig" and "scriptPubKey", you only need "sig" and "pubKey", and ECDSA implementation.
without scriptsig you'll have no first block.
https://github.com/alexeyneu/BlockZero/blob/master/BlockZero.cpp#L73-L77
garlonicon
Copper Member
Legendary
*
Offline Offline

Activity: 944
Merit: 2317


View Profile
December 07, 2024, 08:58:36 PM
 #14

Quote
without scriptsig you'll have no first block.
Why not? You can for example detect, if something is P2PK, and then handle it. And in all other cases, you can just assume it as valid. Then, it will be compatible with the rest of the network, just like a downgraded soft-fork. That's why old nodes have no Taproot or Segwit, and can still follow the same chain. And you can do that too, and throw away the whole Script implementation, then hardcode just some patterns for P2PK, and implement only ECDSA, and nothing else.
alexeyneu
Member
**
Offline Offline

Activity: 392
Merit: 44


View Profile
December 07, 2024, 09:57:46 PM
Last edit: December 08, 2024, 12:18:51 AM by alexeyneu
 #15

code i've posted is a collective work of 10 or so people. And it worked only after ~15 tries where we just wanna to reverse engineer satoshi stuff having easy way to test if it does right or not. where you offer to write his own .... I think you can guess the rest . All other projects eth included just copied this part with no-brainer (you can ask buterin why he'd used nbits = 486604799 for eth block #0).
tiltedIceCream
Newbie
*
Offline Offline

Activity: 8
Merit: 21


View Profile
December 16, 2024, 12:37:55 PM
 #16

Quote
only what is necessary to form a working bitcoin chain
Then, just take version 0.1.0, and remove things, which you don't need. For example: instead of "scriptSig" and "scriptPubKey", you only need "sig" and "pubKey", and ECDSA implementation. I guess the bare minimum is hashing, so you can start from SHA-256 implementation (because then, you can form a chain). The next thing is public key cryptography, which means secp256k1 implementation. If you have those two, then you can form the basic chain. If you ignore everything else, then you will have "downgraded soft-fork", where your version will only check P2PK, and accept everything else as valid.

Quote
Anyone has a minimalistic, C++ Implementation of the original bitcoin protocol?
I was trying to do something like that, but it is not yet ready.

Quote
What exactly are you trying to do and what parts of the libraries do you find non-minimalistic and why is that a problem?
I guess it is about recreating the process of making Bitcoin from scratch. Because between empty main function, and the first released version, there are definitely more points, where you have "half-baked coin", and where you can learn, why things are set, the way they are. For example: the bare minimum doesn't need any Script. The bare minimum doesn't need versioning. And there are many other things, which you can remove, and still cover everything, what is described in the whitepaper.

So, to sum up: start from SHA-256 implementation, which will give you just "something mineable, without any public keys". Then, add public keys support. And then, you will have the bare minimum.

And if you want to test some basic concepts, then you can even downgrade it into SHA-1 with secp160k1, or even CRC-32 with some 32-bit elliptic curve, if you want some weaker test network.

This is the most reasonable approach in my opinion
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!