Welcome to the Monastery | |
PerlMonks |
Implementing the "Icarus" crypto mining protocol for some old hardwareby cavac (Parson) |
on Feb 05, 2022 at 20:50 UTC ( [id://11141158]=perlquestion: print w/replies, xml ) | Need Help?? |
cavac has asked for the wisdom of the Perl Monks concerning the following question: I found an old USB "ASIC Miner Block Erupter" thing in my box of old hardware that waits for the day i find a new purpose for it. This crypto dongle does about 330 Megahashes per second. Not planning to use it to mine bitcoin, but it could be a nice proof-of-concept hardware for a blockchain thing i'm playing around with. No commercial purpose, just me playing around on how a blockchain could be integrated with a project that uses a PostgreSQL database. Basically, just me looking into how crypto blockchains work, but hating the idea of using a big-ass file when you could use SQL ;-) I normally wouldn't even play with mining hardware devices because they waste tons of power and they are bad for the environment. But this little toy only uses about 2.5 Watts, so i figured i could experiment with it without boiling the oceans. Before we can use that device for anything, we'd better find out how to communicate with it. There isn't much technical info on the internet about the hardware. Most articles are all about "yadayada blockchains are the future yadayada get rich quick yadayada bitcoin not a pyramid scheme yadayada". I found some very old discussions that mention it uses the Icarus protocol, whatever that is. Another few minutes of googling found this old article. It describes the "Communication protocol V3". It's not very detailed, but it says what data to send and what data comes back. Except it only mentions "last 12 bytes of block header", whatever that entails. Eventually, Google found me this post, which helped me in finding out what those mysterious 12 bytes are supposed to be. Timestamp and Nonce are easy, these are just basically 8 bytes i can play around with. The Difficulty target supposedly changes on how difficult it is for the hardware to find a matching block. To be honest, i have absolutely no idea how that "difficulty" is encoded and what it does on my specific hardware. Changing the value doesn't seem to change on how fast i get the result on average, it just changes the results. I'm probably doing something wrong or i'm missing a step or something. So, if you have any ideas/bugfixes/patches or just want to shout at me for doing something incredibly stupid, feel free to write a comment :-) Ok, here is the code i have. It's not pretty, it's full of debug stuff. And i'm doing quite a bit of data manipulation the hard way, just to make it easier for me to play around with the bits. But, as a proof of concept, it should be a decent start for you to play around with.
So, if you have even a basic understanding about the internals of Bitcoin, i appreciate if you can show me on how to properly calculate the difficulty bits and verify that i have got a valid result. And if you see any error in my protocol implementation, i'd also be glad for any help you can give me.
perl -e 'use Crypt::Digest::SHA256 qw[sha256_hex]; print substr(sha256_hex("the Answer To Life, The Universe And Everything"), 6, 2), "\n";'
Back to
Seekers of Perl Wisdom
|
|