0

So, I'm currently doing a personal project where I'm creating my own crypto blockchain (just for fun). I'm currently coding the Difficulty Target part of the Blockchain, but I'm not entirely sure how the difficulty part affects the process for completing the block? I know that with Bitcoin, the difficulty adjusts every 2016 blocks based on how long it took to complete the 2016 blocks, but what is the difficulty applied to and how does it make subsequent blocks harder/easier to complete?

Thanks.

0
0

Have you read this? It is sort of technical, and goes into How is difficulty calculated? and How is difficulty stored in blocks?

https://en.bitcoin.it/wiki/Difficulty

re your comment about nonces: The nonce is not the difficulty. In the example below, I'm trying to find a sha256 that starts with 0. On my imaginary blockchain, a proof-of-work that starts with a single 0 is good enough. Notice that I don't change anything but the number after foo. The number after foo can be thought of as the nonce. It's just some thing I change to get a new proof-of-work.

[I] ➜  ~ echo -n "foo" | shasum -a 256
2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae  -
[I] ➜  ~ echo -n "foo1" | shasum -a 256
bb4eca334f61af3b67b5d528907d30285151610200539302f4c8cabe66225b53  -
[I] ➜  ~ echo -n "foo2" | shasum -a 256
4963bd713a7eb1bce458868b0c8472bdc8bc5929a7892a92dd24344aea92093d  -
[I] ➜  ~ echo -n "foo19" | shasum -a 256
06651ba147df6422edcd47690fd3d68795bc59636f37f10b67a94fa70fe1fdbb  - yay

Compare that with miners on the bitcoin blockchain. Currently they have to find a sha256 hash that starts with 19 0's. e.g: 00000000000000000006d31a10b4190a8f86c93189debe87a4d1fff54fbd5b23

2
  • Yeah, I did read that but unfortuantely, it was a bit too technical for my current understanding. I don't quite understand what the difficulty target changes. From my understanding, the nonce is what people need to find in order to complete the block. But currently the bitcoin blockchain has a difficulty of 20,823,531,150,111.52. That's 20 trillion, yet the nonce from what I can see currently varies between the hundreds of millions and 5 billion ish. Basically I don't understand how (or whether it even does) it affects the nonce and the persons ability to complete the block. – L M Feb 1 at 23:04
  • 2
    The nonce isn't the only thing that varies between attempts. In fact, difficulty 1 means that only one in ~4 billion attempts will succeed. The current difficulty means you need trillions of times that many attempts (yes, really). In order to do so, miners change other things in the block to get more chances - the timestamp, an additional nonce inside the block data itself, the composition of transactions, ... – Pieter Wuille Feb 2 at 7:38

Not the answer you're looking for? Browse other questions tagged or ask your own question.