Giter Site home page Giter Site logo

btc-target-bits-difficulty's Introduction

Target, nBits, Difficulty, Time to mine

This project shows how to calculate those three values that are used in the Bitcoin protocol.

nBits

This is the compressed value that is used in the block header. It's a 4 byte (32 bits) value defined by:

  • exponent: the first byte. It tells how "far to the left" is the value;
  • coefficient: the last 3 bytes. It is the value itself (with some precision, but not full).

Example:

image From https://learnmeabitcoin.com/technical/block/bits/

Note that the nBits is a value that is not 100% accurate, but nevertheless it is used by the miners.

Target

This is the uncompressed value that miners use to validate the block found, i.e., if the block hash is below it. It's a 32-byte (256 bits) value.

It is defined by:

$$target = coefficient * 2^{8(exponent-3)}$$

Difficulty

This value actually does not exist in the protocol, it is more to provide a human-readable information to how difficult it is to mine a block. It has the inverse meaning of the target, i.e., higher the target, lower the difficulty (easier it is to mine a block); lower it is the target, higher the difficulty (harder to mine a block).

It is defined by:

$$difficulty = \frac{max_{-}target}{current_{-}target}$$

where:

  • max_target: hardcoded value defined in the protocol that has the value of 0x00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff (but because of how the protocol is implemented, it is truncated to 0x00000000ffff0000000000000000000000000000000000000000000000000000;
  • current_target: the current (uncompressed) value.

Time to mine a valid block

The time to mine a valid block is an equation that brings into consideration the current hashrate. The formula is given by:

$$time = \frac{difficulty * 2^{32}}{hashrate}$$

If the hashrate is given in hashes/seconds, then the result will be in seconds.

With this information, you can check in how many blocks (estatistically) the miner will find a valid block by knowing that each block is mined roughly every 10 minutes:

$$\frac{time}{60 * 10}$$

btc-target-bits-difficulty's People

Contributors

guilospanck avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.