Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: Coding Enthusiast on June 24, 2019, 04:57:52 PM



Title: For educational purposes, I've created a bitcoin miner!
Post by: Coding Enthusiast on June 24, 2019, 04:57:52 PM
I've started a new project: https://github.com/Autarkysoft/LearnMining
It serves 3 purposes:
1. Helps with learning how mining works
2. It works with the hash algorithm under the hood
3. Explores optimization of code written in C#

It is a work in progress and I have written everything from scratch purely based on documentations without any kind of "code translation" or "code copying" from other projects so it might contain some mistakes.
Currently it only has bitcoin mining (double SHA256). But I plan on adding other hash algorithms, possibly Scrypt (what LTC uses) be next. I am open to suggestions.
The code has tons of comment on it and I believe it is easy to understand what is going on, I can add more if something is unclear.
Since this is obviously not meant for actually mining anything, parallelization is avoided and it works only on CPU.

Please check it out and tell me what you think. Specially the part about Target here (https://github.com/Autarkysoft/LearnMining/blob/5b8f6665262124f8f01cc0baa19dc5fbf8741c07/LearnMining/DoubleSha256Miner.cs#L74-L96) and here (https://github.com/Autarkysoft/LearnMining/blob/5b8f6665262124f8f01cc0baa19dc5fbf8741c07/LearnMining/DoubleSha256Miner.cs#L207-L227), not sure if I'm missing some endian swaps there.


Title: Re: For educational purposes, I've created a bitcoin miner!
Post by: Coding Enthusiast on July 07, 2019, 06:05:46 AM
Since this project has been getting some traffic on GitHub and some clones I decided to prioritize it for now.

Added scrypt-miner for litecoin to only work with the algorithm and see how LTC mining works, it is not optimized at all. Also since every code I post is written 100% by me from scratch sometimes I end up with much faster code (SHA256 and HMAC are 60% faster than .Net framework's) and sometimes I end up with much slower code (scrypt). These functions are from the library I'm working on so they are thoroughly tested and they are all generalized instead of being specific to mining the 80 byte array!

https://github.com/Autarkysoft/LearnMining/commit/0dd1c4121e0aa8b0654ac1fe07df79efae9df118

I haven't decided whether to focus on optimizing this or move to CryptoNight algorithm since it uses AES among other things and I've already been working on that for my AEZEED project.


Title: Re: For educational purposes, I've created a bitcoin miner!
Post by: AverageGlabella on July 09, 2019, 08:07:30 PM
Appreciate the comments including in the miner. I think this could be a good thing combined with a mining introduction course where students could potentially take a look at the inner workings of the miner. Possibly a thought when theymos implements these courses he indicated he might be doing.


Title: Re: For educational purposes, I've created a bitcoin miner!
Post by: Coding Enthusiast on July 19, 2019, 08:48:43 AM
Since scrypt (used for Litecoin) is more complicated, I decided to start a visual demonstration of the algorithm and also did the same for Double_SHA256. Since the pictures are big here are the direct links:
SHA256: https://i.imgur.com/KhItpCG.jpg
scrypt: https://i.imgur.com/dfOwNyY.jpg
Hopefully they can help. I'll also publish the optimized version of scrypt algorithm soon.

https://i.imgur.com/KhItpCG.jpg

https://i.imgur.com/dfOwNyY.jpg