kaspanet / kaspad

Kaspad is the reference full node Kaspa implementation written in Go (golang).
ISC License
440 stars 227 forks source link

What exactly does "difficulty" mean? #2241

Open fingolfin0 opened 7 months ago

fingolfin0 commented 7 months ago

This page says that difficulty "is the probability of ..." But this is complete nonsense, because the probability cannot be more than one. Help me figure out what is a "difficulty" in Kaspa?

I'm trying to find out the difficulty using kaspactl GetBlockDagInfo. There is a formula that says that the expected number of hashes we need to calculate to find a block with difficulty D is D * 2**48 / 0xffff. This formula works for Bitcoin, but gives absurd results for Kaspa.

adlai commented 4 months ago

Without reading any of the documentation, I imagine that the omission was normalising the difficulty value, when interpreted as a probability, with a denominator equal to the total search space; for Bitcoin, this would be 2^256, and could be computed similarly for any proof-of-work system.

ShaiW commented 4 months ago

The complete sentence is "Difficulty is the probability of a block hash being less than or equal to the target bits", what about this strikes you as "more than one"? (When modeling the hash function as a random oracle) hashing ablock after changing the nonce outputs a uniformly random 256-bits number, and the difficulty is the probability that this bit-string has sufficiently many leading zeros.