Google-apper
Hovedmeny

Post a Comment On: Ken Shirriff's blog

"Bitcoin mining the hard way: the algorithms, protocols, and bytes"

70 Comments -

1 – 70 of 70
Anonymous Peter Todd said...

> Personally, I think the Merkle tree is a pointless optimization for Bitcoin and for reasonable transaction numbers it would be faster to do a single large hash, rather than multiple hashes up the Merkle tree.

The merkle tree is a critical optimization for Bitcoin - it's what makes SPV wallets like Multibit possible. In fact the among the experts there's consensus that the merkle tree should have extended into transactions themselves, so that all the inputs and outputs of a transaction would be committed to via a merkle tree. In the future this will probably be done, and is needed for things like fraud proofs.


Incidentally, here's a fairly complete and "pythonistic" Python library for Bitcoin: https://github.com/petertodd/python-bitcoinlib It's a "ground up" library that re-implements all the Satoshi bitcoin functionality, and is focused on making low-level code easy to write in Python. Network code is still in flux, but there exists an RPC module for use with a local bitcoin node. A simple example of that type of use is in my dust-b-gone.

February 23, 2014 at 5:22 PM

Anonymous Peter Todd said...

As for the overhead of using a merkle tree to hash some data verses hashing it in one go, it's roughly speaking double the work. It's easy to see why if you remember your sum-of-series stuff from highschool: So the first pass consumes n 64-byte blocks, producing n/2 digests. The second takes those n/2 digests, and produces the next level, n/4 digests. Summing that up you get n + n/2 + n/4 + ... = 2*n

A constant factor of two for something as fast as hashing is basically irrelevant.

February 23, 2014 at 5:31 PM

Blogger Ken Shirriff said...

Thanks for the detailed comments, Peter. The funny thing is I realized when looking at mining pool computations that the Merkle hash was in fact useful. I thought I had removed the part about it being pointless, but I guess not :-)

February 23, 2014 at 7:55 PM

Anonymous Anonymous said...

A typo?

>make a mining request to the GHash.IO mining pool ... sock.connect(("stratum.btcguild.com",

February 23, 2014 at 11:04 PM

Blogger Ken Shirriff said...

Thanks Anonymous - I've fixed that.

February 24, 2014 at 10:25 PM

Anonymous Peter Todd said...

No problem! There's a lot of stuff in Bitcoin that at first glance doesn't look useful, and then only later do you realize why it's so important.

On the other hand, there's also a lot of stuff that makes you wonder WTF was Satoshi smoking... but that's hindsight for you.

February 25, 2014 at 2:05 AM

Blogger KovaaK said...

> If the hash meets the pool difficulty, you get a share. If the hash also meets the much, much harder Bitcoin difficulty, the block has been successfully mined. In this case the pool submits the block to the Bitcoin network and everyone with shares gets paid accordingly.

I'm still quite new to the mechanics of Bitcoins and pools, but hypothetically, could a malicious pool participant be programmed to send hashes that met the pool difficulty to the pool, but keep the Bitcoin difficulty-level hashes for himself and submit them directly to the Bitcoin network? Are there any checks that could be implemented on the pool software to make sure malicious clients aren't stealing successes?

February 25, 2014 at 9:53 AM

Blogger Stephen Cagle said...

Thanks for this article, especially footnote number 7. In reading about this mining pool stuff, I had always wondered why people didn't just cheat and not submit the winning share to their pool if they happened to find it. Thanks to your article I finally (duh) figured it out.

February 25, 2014 at 12:33 PM

Blogger Unknown said...

Ken, this is great stuff, I find myself already looking forward to your next post, and cutting and pasting the code to play with it. One question: your python code for the merkle root ignores the last transaction if it is odd...correct? I was under the impression that the odd one out was hashed with itself and that hash was then included as a branch. Thanks again. James

February 28, 2014 at 6:04 AM

Blogger Unknown said...

Ahhh. As soon as I posted I saw the line of code that does it. Silly me. So yes you do hash the odd transaction at the end to itself. Thanks again for a great post, with code!!

February 28, 2014 at 6:20 AM

Anonymous Anonymous said...

I'm a little confused if the pool informs the clients of all of the transactions it wants to include in a block (if one is found.

From the wiki (https://en.bitcoin.it/wiki/Block_hashing_algorithm)
You hash the entire header
The header includes the merkle root
The merkle root is a hash of all of the transactions including coinbase

Wouldn't that mean the pool has to constantly update miners about which transactions need to be included in their merkle root calculation?

March 5, 2014 at 5:22 PM

Anonymous Anonymous said...

Still confused. The transaction, with each scriptPubKey copied into scriptSig, is double SHA256 hashed... is that the hash that becomes the txid? Is that the hash that is used to sign each input?

I'm trying to get my head around inputs that are signed by different owners (and at different times). Is the above double hash used to sign each input (no matter who the owner), or are different hashes signed?

Thx

March 25, 2014 at 9:53 AM

Blogger Unknown said...

I rewrote your sample Python hashing script for merkle trees in PHP if anyone is interested.

http://pastebin.com/JbCVyRiu

April 16, 2014 at 12:44 PM

Blogger Unknown said...

Hello Ken,
excellent deep article.

I wonder how you get the figure of 11 million years on average ?

"My Python program does about 42,000 hashes per second, which is a million times slower than the hardware used by real miners. My program would take about 11 million years on average to mine a block from scratch."

April 25, 2014 at 8:37 AM

Anonymous Michael said...

Very detailed article for those wanting to know how mining actually works. Will point readers here when they ask how mining results in BTC. Very good.

August 13, 2014 at 12:10 PM

Blogger عبدالله said...

I ask for your permission to copy the article and translate it into another language .

September 28, 2014 at 11:39 AM

Anonymous Anonymous said...

Ken, how is it your articles on Bitcoin are always the only ones that provide answers to the questions I have in my head? Uncanny. Thank you.

October 17, 2014 at 12:42 AM

Anonymous Anonymous said...

The [2] need more precision. The length mean « The 'length' of the entire block chain refers to the chain with the most combined difficulty, not the one with the most blocks »

As stated here: https://en.bitcoin.it/wiki/Blocks

December 1, 2014 at 9:58 AM

Blogger __ said...

Great post. Helped me understand the details. I trained a machine learning classifier to answer the question "Is the nonce greater than k", similar but not the same as your Notes and references point 1. Posted here. Thanks again for a great post.

March 19, 2015 at 8:37 PM

Anonymous Anonymous said...

The statement that the Merkle tree idea is patented is rather pointless, because the patent expired more than 10 years ago (it was issued in 1982 and patents last for 20 years).

October 31, 2015 at 10:48 AM

Anonymous Ruslan said...

Ken, can you please explain more about "Creating a block for a pool",
coinb1 and extranonce1 is ok, but from where you get - "000017e4" and continue "46522cfa...." of "extranonce2, and coinb2" are difference from first block?

I try to write it on VB.net

Thank you ~

November 1, 2015 at 6:39 AM

Blogger Gilberto said...

Good night, excuse me my poor english, My name is Gilberto, I'm Mexican and I'm Master student, and I'm trying to investigate a new form to do mining of Bitcoins, but I have a lot of questions about How is the manual procedure to do mining of Bitcoins?, How I use the algorithms SHA-256, RIPEMD160 and Base58 in Bitcoins?, You have libraries about these? I want to do a embedded system in a 7.E64G401 Ephifany 64-core card and use computing paralell and I not have idea How begin?, please help me.

December 12, 2015 at 8:06 PM

Anonymous Anonymous said...

Gilberto, first lean how to hash SHA1 manually from this guy and then go from there.
https://www.youtube.com/watch?v=5q8q4PhN0cw

March 22, 2016 at 8:17 PM

Anonymous benwest said...

Hi ken;
Question1:
do the miners start all from the same nonce (nonce=1 for example) and every miner increase its nonce depending of the speed of the hardware where and software he use for mining ?
otherwise could someone enter manually the beginning nonce0 and by luck he find the right nonce to get a valid hash for a new block ?

Question2:
a part the coinbase rewarding transaction; do the miners receive the same transactions in the block to mine ?
Question3:
we suppose 2 miners find a valid blocks block1 and block2 at the same time.
do block1 and block2 contain the same number of transactions?

Thanks.

January 8, 2017 at 11:24 AM

Blogger Ken Shirriff said...

benwest: Q1: Miners normally all start with the same nonce value and then count through as fast as they can. But other parts of the block will be different, so they're trying different blocks.

Q2: In a mining pool, miners probably get the same transactions but a different extranonce1, to avoid different miners duplicating work. But different miners could get different transactions, if the pool operator updates the block as time goes on.

Q3: Two blocks mined at the same time could have the same number of transactions, or could be totally different. It's possible they have no transactions in common. Or they could have identical transactions.

January 9, 2017 at 2:47 PM

Anonymous benwest said...

Q4: does a single miner, that he is not a part of a pool, has any controle over the block he work on ?
for example: work only the block containing only the coinbase rewarding transaction and another transaction?

Q5: could someone who has a very slow pc (old pc) find a block before other miners by luck (like a lotto game) ?

Thanks.

January 10, 2017 at 7:36 AM

Blogger Ken Shirriff said...

benwest: Q4: Yes, a single miner can pick the transactions that go into the block the miner is working on. Normally the miner would pick a bunch of transactions (to get more fees) but they don't need to. Q5: Yes, it's like a lotto. Someone with a slow PC could get lucky and mine a block (or even someone mining on an old punchcard computer. It's just very unlikely since fast hardware gives you many more chances to "win"

January 10, 2017 at 11:31 PM

Anonymous Anonymous said...

Great article and given that you're still answering questions 3 years later I thought I'd repeat an unanswered question from earlier that piqued my curiosity.

"... could a malicious pool participant be programmed to send hashes that met the pool difficulty to the pool, but keep the Bitcoin difficulty-level hashes for himself and submit them directly to the Bitcoin network? Are there any checks that could be implemented on the pool software to make sure malicious clients aren't stealing successes?"

January 12, 2017 at 6:31 AM

Blogger Ken Shirriff said...

Anonymous: can a pool participant steal the successful hashes? That's a good question, but no. The coinbase transaction contains the pool owner's scriptPubKey, so the pool owner is the only one who can access the reward. If the miner changes the scriptPubKey, the hash is no longer valid. There's a theoretical attack where the miner throws away a fully-successful hash so nobody collects. Then the miner gets paid for the partially successful hashes but the pool owner doesn't get the reward payout. This is known as the withholding attack. Since it doesn't benefit the miner, it's not too useful as an attack.

January 12, 2017 at 3:41 PM

Anonymous benwest said...

a mining-pool is seen by the network as a single node (as a solo miner).
the nonce run from 1 to n-1 to find the good bock's hash.
how to avoid miners not doing the same work by testing the same values of the nonce ?
does the pool give every miner a part of the set containing all possible nonce value ?
thank you.

January 15, 2017 at 12:45 PM

Blogger Ken Shirriff said...

benwest: I believe the mining pool gives each miner different extranonce1 values. A miner can then run through all the nonce and extranonce2 values without duplicating work. Because of the different values for extranonce1, each miner can work with the same transactions but will still be generating unique blocks.

January 16, 2017 at 11:17 PM

Anonymous benwest said...

what I believe from the following comment I found in another blog is:
we can change manually the nonce.
for example begin with nonce = 2677 or even try to predict the right nonce that would give the valid block hash.

This comment is extract from another blog:

There is no precise nonce finding protocol.

The miner can arbitrarily choose a nonce c to perform the hashing operation.

Mining is a mathematical game where the goal is to make the result of the hash function smaller than a given number (this is what "a result starting with x zeros" is looking for). The number is directly based on the current Bitcoin network difficulty and changes every two weeks to keep average block finding time at 600 seconds.

Most nonce generators just increment by 1 but the key is where they start. If you are solo mining, you can pick a random number. If you are mining with multiple devices or you are a pool administrator, you have to divide the work to avoid calculating the same hash twice (make sure they never use the same c).

January 19, 2017 at 2:04 PM

Anonymous Andreza said...

Hi! I'm a big fan of your articles. Can I translate some of them to my blog in Portuguese? Thank you in advance.

January 30, 2017 at 7:14 AM

Blogger Ken Shirriff said...

Andreza: go ahead and translate. Thanks for asking. If you send me a link to your translation, I can add it to this page.

January 30, 2017 at 10:21 AM

Blogger Jonathan Annett said...

about this:

http://static.righto.com/images/bitcoin/coinbase_txn2-s400.png
(it's a table with data from your page)

are we sure about the contents?

for example the last line has 9 zeros.

i'm trying to code a parser to break apart statum messages and this does not seem to line up to the earlier data.

May 9, 2017 at 6:41 AM

Blogger Ken Shirriff said...

Jonathan: the block in that figure is different from the block discussed earlier, so you can't expect them to match up. (The text above the figure should mention this.)

May 9, 2017 at 1:36 PM

Blogger Jonathan Annett said...

it does mention that.

what it does not mention is how a 32 bit lock time is expressed using 9 hex digits. what black magic is this?

all good, i managed to glean enough to parse stratum messages in node js, dumping the relevant parts of the coinbase snippets to the console log - verifying that a solo pool does in fact split the coinbase transaction 2 ways.

the trick was using a jsonrpc call to bitcoind (happpens to be running on same server) to decode the second script segment revealing the transaction containing my wallet address. i didn't feel like deep diving into the pecularities of the internal script format when i don't really need to get that concerned with that side of the proticol.

i've coded a pass through proxy that dumps each stratum message to a log, while saving pertinent parts of the messages to memory.

i am now going throufh the academic exercise of hashing a block alongside the miner (fairly pointless, but i want to understand the protocol completely, so i'm inventing a separete extranonce2 of the appropriate length, collating the coinbase, hashing it,
building a merkle root from the coinbase tx hash and supplied merkle branch array, forming a block header, hashing it and .... well i suppose if the proxy gets lucky it could go ahead and submit it on behalf of the miner!

i'm pretty sure once i've completed that, your captcha ("i am not a robot") feature will reject my post, as tbh, you need to think like one to code this stuff.

May 18, 2017 at 3:27 PM

Blogger Ken Shirriff said...

Jonathan, you're right - there's an extra digit for the lock time in the diagram. You get points for studying the diagram more carefully than anyone else ;-) Your post got through fine, by the way (along with a lot of spam I'm constantly removing).

May 18, 2017 at 7:04 PM

Blogger Unknown said...

Hi

first of all thanks for this really fantastic series,this really helpful.

but i really wondering about solo mining ,i read an ebook(mastering bitcoin) i was good but i don't understand completely about solo mining ,how we select transaction and make Merkle Root and even timespan (because for example when check in blockchain.info and see last block all transaction is selected and merkle rook is made so we have to solve this hash or we can select transaction that we want and then solve the hash?)
and after that how we can submit the hush to blockchain ?

could you please write another article about solo mining and such this problem?

thanks.

May 25, 2017 at 3:14 AM

Blogger Ken Shirriff said...

Pooriya: solo mining is pretty much the same except you have the choice of what goes in the block. You pick which valid transactions you want to put in the block. You pick a roughly accurate value for the timestamp. The Merkle root is formed by hashing pairs of transactions and then hashing pairs of hashes until you have a single value (see footnote 4 for details). Then you try to hash the resulting block with different nonces, hoping to find a successful block

If you succeed in mining, you send the block to the Bitcoin network. Since the network is peer-to-peer, you send your successfully mined block to other computers (peers) in the Bitcoin network, who send it to other computers, until everyone has received it in a few seconds. Peers are always sharing blocks, which is how they get passed around the network, and there is nothing special about you sharing a block that you just mined versus a block that you received from someone else. Miners will then start using your block as the previous block for their mining, which is how your mined block becomes part of the blockchain.

May 25, 2017 at 7:39 AM

Blogger Unknown said...

Hi

thanks for reply

your explanation was helpful but there is 2 point that steel unclear for me.

for example at this time the block no #468323 is found (by F2Pool) and we want to find next block so we have to make block header and search

1) the most unclear part for me is how making coinbase (for example for block no #468323 is 036a6f397243382eae70626e631469c74bdf40d5e3db6539ca41fe928cc857aa and Of course it is related to F2Pool) how should i make mine?

2) what value i have to use for Difficulty (for block no #468323 is 402774100 but it is for Previous, is it specified for next block that we want to find (#468324)?

May 26, 2017 at 10:13 PM

Blogger ..i.. said...

No, because the address to grant the reward is the pools address. If you put your own address in, then you are not getting pools rewards. You could throw away the block chain difficulty reward as a denial of money but that does nobody any good.

July 10, 2017 at 3:32 PM

Blogger Dilli Raj Maharjan said...

Hi Ken,
Thank you for the detailed post on Bitcoin mining. I have setup the BTC Full Node. I have six cores of CPU and around 16GB. I have installed cpuminer to test the mining process. Can you share some information on how to setup mining process just to mine own transaction. I want to speed up my low fee transaction with my own mining server. Can we do it with CPU Mining or we need GPU,FRGA Mining and ASIC Mining.

August 1, 2017 at 11:14 PM

Comment deleted

This comment has been removed by the author.

August 8, 2017 at 5:13 AM

Blogger Unknown said...

Please, can you send me the already compiled program for bulkhead nonce for Windows? The one that you have in the example. Thank you

August 8, 2017 at 5:24 AM

Blogger NGR TV said...

how to create mining software for
Alt coins . which are on coinmarket cap . and source code available on github.

September 1, 2017 at 7:35 AM

Anonymous Anonymous said...

I've not yet seen any discussion of how we can be certain that any/every block can be mined. Is it not possible one day, to encounter a block that simply never meets the criteria, that can never meet the criteria?

September 24, 2017 at 6:51 AM

Blogger Ken Shirriff said...

Anonymous: you ask if we know every block can be mined. Given current difficulty it is very likely that a specific block can't be mined - there's no nonce that works. In that case, miners simply change the block slightly (e.g. change the time, use different transactions) and try again. Eventually some block will work. In other words, there's not one specific block that has to be the next block, but zillions of possibilities and miners just need to find one that works.

September 24, 2017 at 9:45 AM

Anonymous benwest said...

who is the authority who protect the bitcoin core code or protocol or software against attacks or hacks?

October 3, 2017 at 9:41 AM

Blogger Stuart Cracraft said...

benwest --> https://github.com/bitcoin/bitcoin

October 4, 2017 at 8:07 PM

Anonymous Anonymous said...

Hi

Great post. Let's say we have 1000 computers and would like to mine. But these computers are slow. That's why they can not mine strong diffs. So is it possible to divide the job for them? and give them a less diff?

Here is the example:

A standard pc can do 42.000 hashes /s. But my pcs can do only 10.000 hashes. Because i already have 1.000 pcs which means 10.000.000 hashes /s. is it possible to merge their powers?

Andy

December 19, 2017 at 4:44 PM

Blogger Ken Shirriff said...

Andy: yes, computers can mine in parallel. Finding the hash is a matter of trying lots and lots of hashes until you find a good one, so it's easy to have many machines working in parallel. The only trick is to make sure all the machines are doing different hashes and not duplicating work, which is straightforward. This is basically what mining pools do; they also spread the winnings across all the participants.

December 19, 2017 at 4:48 PM

Blogger Antonio said...

Hi Ken, I saw you are answering interesting questions about how BTC mining works, I have a couple of questions I have not found the proper answer: Q1: How can I try to solve a block (educational purposes) after getting the GBT information from my Full node fully synced. Q2: How do I parse that with python program to obtain the merkle root with my coinbase transaction and Q3: How do I antually submit work once nonce found.

Thanks in advance.

January 11, 2018 at 3:10 PM

Anonymous James said...

Hi Ken - in regards to Anonymous' question above: "A standard pc can do 42.000 hashes /s. But my pcs can do only 10.000 hashes. Because i already have 1.000 pcs which means 10.000.000 hashes /s. is it possible to merge their powers?"

This is what a stratum proxy would do, correct? Split the nonces etc an issue proxy-local 'jobs' between the 1000 'slow' computers? I'd be interested in just how a proxy would 'split' the work, to ensure each of the 1000 computers wasn't duplicating work.

January 26, 2018 at 12:43 PM

Anonymous paul said...

hey man, cool blog. I really appreciate the clarity concerning the algo. Excellent work.

Really interesting stuff about the alto and the ibm mainframes and stuff also. thank you.

my 3rd gen i5 laptop ran your python code at around 42 kH/s. Next i'll be trying to port it to perl.

good reading

January 27, 2018 at 8:23 PM

Blogger Unknown said...

some basic questions that seem to be unaddressed beyond anything than vague generalities within the hype.
what data is being mined ? what is the purpose of it ?
who is paying for the number-crunching results ?

February 17, 2018 at 7:43 PM

Blogger wheezil said...

I'm having a hard time grasping the "degrees of freedom" available to the miner. Clearly, the nonce comes first (32 bits) and the timestamp can be adjusted (but by how much?). Also there is some freedom in choosing which transactions to include (although it would seem you always want to include the most transactions possible so as to be the winner in case of a fork)? And finally, "the coinbase transaction can be modified". I *think* this refers to the "coinbase parameter" of the coinbase block, which in the case of the genesis block had the message "The Times 03/Jan/2009 Chancellor on brink of second bailout for banks". That being the case, the coinbase parameter itself would seem to offer unlimited degrees of freedom.

February 21, 2018 at 6:22 AM

Blogger tanglewood said...

Hi Ken; I am not sure if this blog is still active but in the paragraph 'How Mining Works' you say 'In more detail, to mine a block, you first collect the new transactions into a block. Then you hash the block to form a 256-bit block hash value. If the hash starts with enough zeros[3], the block has been successfully mined' You didn't mention the nonce, also, I thought that in addition to the leading zeroes the hash has to be lower than the 'target hash'. If that's true, can you explain what the target hash is? Is it possible to reverse engineer and wind up with a valid nonce?

April 29, 2018 at 5:54 PM

Blogger Ken Shirriff said...

wheezil: you seem to have a good grasp on the degrees of freedom, i.e. how much miners can change the block. Also note that the order of transactions gives you N factorial choices. As far as modifying the coinbase transaction, typically this is a combination of values from the mining pool (to ensure miners aren't doing the same mining) and "extranonce" values from the miner. Overall, there's enough degrees of freedom that mining isn't going to get "stuck".

tanglewood: the transactions are collected into a block, along a few other fields including the nonce. The diagram and text describe these fields in more detail. And yes, the hash has to be lower than the target hash; "enough zeros" is a slight simplification. (The "last zero" could be a small digit, small enough that the hash is still under the target value. ) The target hash is a number generated by an algorithm every 2016 blocks to ensure that Bitcoin blocks are generated on the average every 10 minutes (details). As far as reverse engineering, the idea of SHA-256 is there's no way to go backwards to find a valid nonce; you need to use brute force. (It's possible that a sufficiently smart mathematician could break SHA-256 but based on the state of cryptography research this seems very unlikely.)

April 29, 2018 at 7:21 PM

Anonymous Anonymous said...

This is a most elucidating blog.
It helped me so much when implementing a C++ miner from scratch.
From the general discussion down to the byte layout.

May 15, 2018 at 1:39 PM

Anonymous Anonymous said...

Fantastic work a great read well done!

May 21, 2018 at 3:24 PM

Anonymous Anonymous said...

I am new to cryptocurrency. I have a doubt: when you implement these cryptocurrency algorithms (in python or some other programming languages), how do you tell machine to use GPU and not CPU in order to do math calculations? or it is always used GPU by default automatically and not need to explicitly tell it? In that case, how do you ensure that GPU is being used instead of CPU?

August 25, 2018 at 4:30 AM

Anonymous Anonymous said...

Amazing! Thanks for great stuff :)

October 6, 2018 at 7:49 AM

Anonymous Anonymous said...

Thanks to Mr josehp who help me become a millionaire by connecting my wallet to his mining stream i am so happy today i can get what i want i just got a new house,He make me earn 0.6 BTC daily, you can earn BTC also by email him and request for his help and he will also connect you to his stream right Away 24hoursbitcoinminer@gmail.com

November 21, 2018 at 8:03 AM

Blogger Marcelo Maico said...

Hi Ken. Wonderful article, congratulation!

I have a question regarding competition between the pools. All pool will try to put the next node, but the pool with less power will have to start the job because the previous block was change. That is, the computer with greater computational power will always win, but this is not what happens in practice. How does it work?

January 18, 2019 at 3:32 AM

Blogger Unknown said...

Here we are 7+ years after this article was posted and it is still relevant and more informative than any single article I’ve seen. Thanks Ken for such a great contribution!

I was on the edge of my seat between the part explaining the nonce and the structure of the pool header. Today’s miners can rip through the 2^32 hash variations provided by nonce variations thousands of times in one second so I was anxious to see how the throughput problem that creates got solved.

One thing I’m curious about: what happens to transactions in an orphaned block that were not also in the competing block that made it into an orphan? Will they go back into the queue and get picked up in a subsequent block or do they just become invalid and have to be reissued?

Rodney

March 27, 2021 at 7:58 PM

Anonymous Anonymous said...

A wildly speculative question, but i just couldn't resist:

Due to mining, the SHA-256 hash is being exercised like no other cryptographic primitive ever, by a wide margin. However, like any other crypto Hash, it's built in essentially an adhoc manner, lacking any comprehensive, fundamental theory (which simply doesn't exist). So, even though it's built to resemble a random function when given different inputs, noone can be sure this is actually the case.

Therefore, my question: Suppose that as Difficulty increases, the Target diminishes to a point where the first 100 bits must be zero in order to successfully mine a block; however, due to some unforeseen quirk in the design of SHA-256, there are actually no inputs which can generate a hash having all zeroes in the first 100 bits. What would then happen to the Bitcoin network, and how could such a disaster be remedied?

I realise this is borderline science fiction, but still somewhat more plausible than related questions along the lines of: What if someone found a way to break elliptic curve crypto?

April 13, 2021 at 5:45 PM

Anonymous Adam said...

Hey Anon above: I just read through all of the comments and looks like your question has been partially answered already; essentially the miner has enough parameters they can change about the block/hash (coinbase transaction, timestamp, nonce) that your proposal will effectively *never* happen, or at least be infinitely less likely than it is to find the correct hash.

But, if it *did* happen, then I imagine that block will just never get mined, and the theoretical supply is lowered, making BTC more scarce than it already is (albeit not by much, since the new reward is 6.25 coins). From what I'm reading, the blocks aren't required to be sequential - failure to mine an impossible block does not mean that future blocks can't be mined.

June 25, 2021 at 8:14 AM

Blogger Unknown said...

Hello Ken, Hope you're doing great!!

Awesome Content.. Really appreciate the time and effort you put into all your published articles.

I have a questions that need answers and I feel like this is the right place to place them.



I'm trying to create a lightweight script that takes the necessary functions needed to mine blocks.

A few of these functions I feel are needed to interact with bitcoind are:

1. Get blocktemplete (I believe it is given as Big endian)
2. Function to Separate 76 bytes of block data and Hash midstate
3. Alter mutable variables (nNonce, nTime)
3. Alter Extranonce) coinbase transaction (if necessary
Function to merge midstate and hexadecimal nonce together
5. Hash block header twice
6. Convert block header to little endian
7. Check internally if 64 hexadecimal hash is lower than target
8. Function to convert hexadecimal difficulty and calculate target that will be used for comparison.
9. Submit hash if hash is lower or equal to target
10. In the case that hash is not successful, Check if block height has changed so that new block template can be requested and worked on. (At this point start from step1)
11. If block template hasn't changed, continue altering variables and repeating steps( This will be handled by the overall While loop).

September 2, 2021 at 4:56 AM

Blogger Unknown said...

Now to those questions I told you I had...

1. Is the hash compared to the target before or after being converted to little endian??

2. Is the coinbase reward transaction/script automatically created or does the developer /solo miner need to create it manually?

3. The reward is to be paid to the miners address - the public key. Is there a field within the mining script where the miner can hard-code the address or is the address gotten from the gui application? How is the address derived?

4. Block data is 80 bytes in total, midstate consists of first 76bytes. In the event that I want to change the number of bytes to be included in the midstate creation. What function handles the hashing of the midstate?

5. Is 'curtime' adjusted automatically or does the developer have to create a function to handle that?

6. Considering that miners from different parts of the world operate on different timezones, is the blocks limit of timestamp expansion 2 hours as published by multiple articles? or is it lesser than that?

7. Do different timezones make timestamps slightly greater or lesser without altering timestamp or is the timestamp as seconds since 1970-01-01T00:00 UTC the same regardless of timezone and GMT variations?

8. Many articles advice miners to change wallet address each time they successfully mine a block in order to maintain a level of anonymity. If a new address is created, does the previous wallet address get deleted along with the funds or are the funds transferred to the new address?

9. If the funds are transferred to the new address, Do I have to copy the function that handles new address creation?

10. Is there a way to make my public key / wallet receiving address static in my script so that I don't have to worry about changing it? or is the code behind getting a new address as simple as 'bitcoin-cli getnewaddress'...?

11. Would bitcoind handle everything for me - in terms of funds transfer to new wallet address?

12. Is there a function or a GUI text-box that allows a miner to alter the coinbase transaction in real-time in order to change Merkle hash; while multiple hashes are being generated ? Like if I wanted to insert unique pre-typed texts into the coinbase transaction after exhausting nonce range.

13. What function handles the hashing of midstate within the Bitcoin Core source code, CpuMiner, BfgMiner or any other mining source code? Any would do since I can recreate the solution but the softwares listed would be preferred. Preferably one with the easiest source code.

14. The padding carried out while computing the block header, is it done automatically or manually by the developer(if creating new script) or by the miner (if running slightly modified version of Cpuminer, Bitcoin Core or BfgMiner)?

15. Is it possible to create Parallel thread/process handlers that parse or wrap specific cpp scripts in order to run simultaneously??

16. Can specific cpp files within bitcoin source code or any other program source code be made to run on a specific core alone? Affinity stuff...

17. Is nNonce incremented as hexadecimal directly or is it incremented as an integer and then gets converted to its hex equivalent?


They say one of the mistakes to avoid is the mistake of not asking for help when stuck!! Well right now I'm stuck, badly... And I really need a clear and direct code sample, not theories, not links to more technical explanations but actual help with actual codes that work along with libraries that make them work. I'm working with c++.

I'm really sorry to bombard you like this..

My email just in case you want to email me directly.. >> jaskrest@gmail.com || krestcrypto457@gmail.com

Thanks in advance.

September 2, 2021 at 4:56 AM

You can use some HTML tags, such as <b>, <i>, <a>

Comment moderation has been enabled. All comments must be approved by the blog author.

You will be asked to sign in after submitting your comment.
Please prove you're not a robot