<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.bitcoinsv.io/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Angus+Adams</id>
	<title>Bitcoin Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.bitcoinsv.io/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Angus+Adams"/>
	<link rel="alternate" type="text/html" href="https://wiki.bitcoinsv.io/index.php/Special:Contributions/Angus_Adams"/>
	<updated>2026-05-12T20:50:58Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.33.0</generator>
	<entry>
		<id>https://wiki.bitcoinsv.io/index.php?title=Mining&amp;diff=2275</id>
		<title>Mining</title>
		<link rel="alternate" type="text/html" href="https://wiki.bitcoinsv.io/index.php?title=Mining&amp;diff=2275"/>
		<updated>2020-02-27T10:12:25Z</updated>

		<summary type="html">&lt;p&gt;Angus Adams: /* Rejected blocks */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
'''Mining''' is the process where nodes in the Bitcoin [[Network]] assemble newly broadcast [[Bitcoin Transactions]] into a data structure called a [[block]]. Nodes then compete to append their block to the public [[Block chain|blockchain]] by repeatedly mutating the block's header data structure, usually by incrementing the nonce field, then hashing it in an attempt to find a value that satisfies a difficult [[Proof of Work|proof-of-work]]. &lt;br /&gt;
&lt;br /&gt;
When a node finds a valid proof-of-work hash for a block, it broadcasts the block to all nodes. Other nodes accept this block only if all the transactions in it are valid and have not yet been included in a block. Other nodes in the network then express their acceptance of the block by building upon it to create the next block in the chain.&lt;br /&gt;
&lt;br /&gt;
Every block is [[Block timestamp|timestamped]] and references the hash of the block preceding it. Blocks form a backward reinforcing, timestamped chain – a [[Timechain]], the precursor to the term ‘blockchain’.&lt;br /&gt;
&lt;br /&gt;
The blockchain structures itself in a manner that is computationally and economically impractical to modify by any one entity. Due to this, transactions included in the blockchain are considered immutable. In addition to this quality, the blockchain establishes an authoritative order of these transactions throughout the network by establishing which out of any pair of conflicting transactions was seen first, thereby protecting users from [[Double-spending|attempts to re-spend coins]] that have already been spent elsewhere. This is the key innovation of mining and of Bitcoin.&lt;br /&gt;
&lt;br /&gt;
=== Nodes ===&lt;br /&gt;
Nodes are entities that run software that carries out the mining functions above. Nodes communicate using a [[P2P Network]] with its own protocol, and are the authors of the Bitcoin ledger and enforcers of the [[protocol]] rules.&lt;br /&gt;
&lt;br /&gt;
Interestingly, the Bitcoin whitepaper makes no reference to the term ‘miner’ or the concept of ‘mining’. These terms cover the actions described in section 5 of the [http://bitcoinsv.io/bitcoin.pdf Bitcoin whitepaper] which describes the responsibilities of nodes on the network. &lt;br /&gt;
&lt;br /&gt;
It is possible to run the node client software without performing block assembly or proof-of-work. Such a setup can be used as an interface to the network for other systems such as block explorers, payment gateways and archives. Eventually it is expected that customised client software will be developed for each of these services so they will no longer be dependent on the node client to operate.&lt;br /&gt;
&lt;br /&gt;
Computers that run a node client but which do not perform proof-of-work cannot append new blocks to the blockchain. This means they can neither express acceptance of valid blocks by working on extending them, nor reject invalid blocks by refusing to work on them. These computers exist as passive entities that follow the gatekeepers of the network, the miners.&lt;br /&gt;
&lt;br /&gt;
=== Mempool ===&lt;br /&gt;
Before a Bitcoin transaction can be committed to the blockchain it needs to be received and validated by a miner. If the miner deems the transaction valid, they add the transaction to one of several [[Protocol#mempool|mempools]]. Mempools are temporary transaction stores and can be used to hold transactions grouped in different ways, such as transactions to be mined in the next block, transactions to watch, or transactions which cannot be mined due to an nLocktime/nSequence lock.&lt;br /&gt;
&lt;br /&gt;
It is important to note every miner has their own mempools and that mempools vary across miners. It is also important to note that an individual transaction can be included in different mempools at the same time. &lt;br /&gt;
&lt;br /&gt;
A miner takes the transactions it intends to include in the next block and hashes them into a [[Protocol#Merkle_Trees|merkle tree]] structure and includes the resulting merkle root within a candidate [[Block hashing algorithm|block header]]. The miner then hashes this candidate block header, attempting to find a valid proof-of-work.&lt;br /&gt;
&lt;br /&gt;
=== Hashing ===&lt;br /&gt;
A hash is a function that converts a string of data into a fixed length value that represents the original string, called the hash value. Every hash value is unique. &lt;br /&gt;
&lt;br /&gt;
Hashing is a one-way function, meaning it is infeasible to determine what the input data is by looking at the hash produced from it. Conversely, it is trivial to run the same input data through the same hash function and reproduce the same hash. Because of this, a hash value of input data can be thought of as the digital fingerprint of that data. In Bitcoin mining, the input data is the 80-byte [[Block hashing algorithm|block header]].&lt;br /&gt;
&lt;br /&gt;
The hashing algorithm used in Bitcoin mining is [[SHA-256]]. SHA-256 stands for Secure Hash Algorithm – 256 bit. Passing the same block header data through this algorithm will always output the same 256-bit number. However if the header data is modified even by a single a bit a completely different and unrelated 256-bit number will result. &lt;br /&gt;
&lt;br /&gt;
Bitcoin mining passes the block header data through the SHA-256 algorithm twice (SHA-256d).&lt;br /&gt;
&lt;br /&gt;
=== Proof-of-work ===&lt;br /&gt;
Bitcoin uses a [[Proof of Work]] function based on the earlier work of [[hashcash]].&lt;br /&gt;
&lt;br /&gt;
A miner cannot create a new block without finding a valid proof-of-work hash for the block header they are hashing. To be valid, the SHA-256d hash (which is just a number) of the block header must be less than another number, called the [[target]]. The target value is defined by the [[Block hashing algorithm|Bits]] field in the block header that is being hashed.&lt;br /&gt;
 &lt;br /&gt;
The target adjusts so that the average time it takes for the entire network to find a valid proof-of-work hash is ten minutes. &lt;br /&gt;
&lt;br /&gt;
Because of the extraordinarily large SHA-256 target space, it is extremely unlikely that any given hash will be below the target. As a result of this, hashing entities invest large amounts of capital into specialized hashing hardware along with the associated electricity costs in order to produce as many of these hashes as possible in a given time period. Therefore, the only way a miner can append a block to the blockchain is through a substantial commitment of operational expenditure – proof-of-work.&lt;br /&gt;
&lt;br /&gt;
=== Incentive ===&lt;br /&gt;
The first transaction in every block is called the [[Coinbase]] transaction. The Coinbase transaction is a special transaction which pays bitcoins to the miner of the block. The Coinbase payment is made up of the [[Miner subsidy|subsidy]] amount and the sum of all [[transaction fees]] paid by transactions within the mined block.&lt;br /&gt;
&lt;br /&gt;
== Competition ==&lt;br /&gt;
&lt;br /&gt;
=== Propagation and validation ===&lt;br /&gt;
If a miner finds a valid proof-of-work for the block header they are hashing, they immediately announce this by sending the entire block to other miners. Meanwhile, they start working on finding the next block in the chain. &lt;br /&gt;
&lt;br /&gt;
Competing miners receive this block and immediately check that all transactions within the block, as well as the proof-of-work are valid. If the block is valid, they discontinue mining on top of the previous block and start working on hashing a new block header, building on the block just found by their competitor.&lt;br /&gt;
&lt;br /&gt;
There are incentives at play here. First, winning 'miner A' strives to get their winning block to all other miners as quickly as possible. This reduces the possibility that competing 'miner B' (who found a valid block at approximately the same time) propagates their block to some miners before 'miner A' could. This opens up the possibility that 'miner A's' block could later be [[Orphan Block|orphaned]] and the Coinbase reward rendered invalid and unusable by 'miner A'. The degree of bandwidth and connectivity to other miners can be seen as a competitive advantage and as such, the mining network tends toward a densely connected, small world structure with high bandwidth.&lt;br /&gt;
&lt;br /&gt;
There also exists a competitive advantage in validating transactions. When validating a block, each transaction's inputs must be looked up in the miner's [[VOUT|UTXO]] set to check they are unspent and the amount in satoshis is correct. Additionally, each input's locking and unlocking scripts need to be run by the miner to assess whether each transaction is valid.&lt;br /&gt;
&lt;br /&gt;
=== Rejected blocks ===&lt;br /&gt;
At any given point in time, two or more independent miners may mine a block at the same time. In this situation, nodes can be in disagreement about which of these blocks should be the tip of the blockchain.&lt;br /&gt;
&lt;br /&gt;
Miners always follow the longest chain they deem to be valid. Eventually another block will be found that builds on one of the competing chain tips. Miners then switch to this tip provided they consider it to be valid. As such, any fork scenario is eventually resolved back to one persistent chain through the actions of the majority of hash power. &lt;br /&gt;
&lt;br /&gt;
In this scenario, a block that doesn't end up forming part of the longest chain is rejected by the network and called an [[Orphan Block]]. An orphan block represents wasted effort on the behalf of a miner and an incentive to invest in infrastructure in order to reduce the frequency of these events. However, orphans do not reduce the overall revenues of the Bitcoin system as the wasted work is not factored into the difficulty adjustment, thus if a certain percentage of hashing work is wasted due to the orphaned blocks, the difficulty will adjust downwards by a similar percentage, maintaining the same rate of valid block production overall.  Additionally the fee paying transactions in the orphaned block will still be valid and included in the competing block or its descendants.&lt;br /&gt;
&lt;br /&gt;
Competing valid blocks are not the only way that blocks end up being rejected. Any miner can refuse to build on any block for any reason. Such an action by a particular miner is only meaningful if the majority of miners carry out the same action. It is through this mechanism that the mining network can establish consensus on variables that are miner configurable - such as maximum block size. This is the basis of Nakamoto Consensus:&lt;br /&gt;
&lt;br /&gt;
{{quote|1=''&amp;quot; They vote with their CPU power, expressing their acceptance of valid blocks by working on extending them and rejecting invalid blocks by refusing to work on them. Any needed rules and incentives can be enforced with this consensus mechanism.&amp;quot;''}}&lt;br /&gt;
&lt;br /&gt;
== The mining ecosystem ==&lt;br /&gt;
&lt;br /&gt;
=== Asic mining ===&lt;br /&gt;
An application-specific integrated circuit, or ASIC, is a microchip designed and manufactured for a very specific purpose. ASICs designed for Bitcoin mining were first released in 2013. For the amount of power they consume, they are vastly more energy efficient than predecessor approaches to mining - using CPU, GPU or FPGA.&lt;br /&gt;
&lt;br /&gt;
=== Pooled mining ===&lt;br /&gt;
Pooled mining is the use of a block template allocation system that provides distributed hashing infrastructure updated block headers against which they perform proof of work. This system of hash allocation to nodes is a primary part of [[Nakamoto Consensus]] in that individual operators of hash power can choose to re-allocate their hash to nodes producing blocks that meet their expectations in terms of maximised profitability and adherence to the Bitcoin ruleset. Miners who distribute block templates that don't maximise profit or which attempt to implement changed rule sets risk the owners of the hash machinery they depend on re-deploying it to a different node on the network.&lt;br /&gt;
 &lt;br /&gt;
==== Stratum ====&lt;br /&gt;
Stratum is an open-source mining protocol used by many mining pools. Stratum facilitates coordination between the mining pool operator and individual mining machines.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [https://bitcoinsv.io/bitcoin.pdf Bitcoin Whitepaper]&lt;br /&gt;
&lt;br /&gt;
==Attribution==&lt;br /&gt;
This content is based on content sourced from https://en.bitcoin.it/wiki/Mining under [https://creativecommons.org/licenses/by/3.0/ Creative Commons Attribution 3.0]. Although it may have been extensively revised and updated we acknowledge the original authors.&lt;/div&gt;</summary>
		<author><name>Angus Adams</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.bitcoinsv.io/index.php?title=Main_Page&amp;diff=2274</id>
		<title>Main Page</title>
		<link rel="alternate" type="text/html" href="https://wiki.bitcoinsv.io/index.php?title=Main_Page&amp;diff=2274"/>
		<updated>2020-02-27T10:06:43Z</updated>

		<summary type="html">&lt;p&gt;Angus Adams: /* Nodes and Mining */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Here we aim to provide a correct and up-to date set of information on the Bitcoin network and its features and functionality.&lt;br /&gt;
&lt;br /&gt;
===Bitcoin===&lt;br /&gt;
&lt;br /&gt;
'''Bitcoin''' is a peer to peer electronic cash system created by [https://craigwright.net/ Dr. Craig Wright] under the pseudonym [[Satoshi Nakamoto]].  It was first detailed in the [[Bitcoin whitepaper|Bitcoin white paper]] in October 2008, and the source code was [https://www.mail-archive.com/cryptography@metzdowd.com/msg10142.html released] in January 2009. The [[Genesis block|first block]] was mined on the 3rd of January 2009.&lt;br /&gt;
&lt;br /&gt;
Bitcoin allows electronic payments to be sent directly from one party to another, without requiring a central institution or server to process transactions and/or store funds. &lt;br /&gt;
 &lt;br /&gt;
The leaderless structure of the network is viewed as a resolution to [[The Byzantine Generals Problem]] allowing disconnected entities to follow a common direction without centralised instruction. This solves several issues previously seen as unsolvable in distributed networks, including the problem of preventing [[Double-spending]] of coins on the network&lt;br /&gt;
&lt;br /&gt;
===Applications===&lt;br /&gt;
Bitcoin is primarily a [[Payments in Bitcoin|payment system]] which supports peer to peer connection and [[Instant Transactions]]. Early in the [[History of Bitcoin]] payments required users to understand complicated technical details of Bitcoin's technological underpinnings to make transactions. But developments such as [[Paymail]] and [[Simplified Payment Verification]] are changing the landscape and making it much easier for users to connect.&lt;br /&gt;
&lt;br /&gt;
Bitcoin also supports the development of [[Application layer protocol|application layer protocols]] which make use of [[Bitcoin Transactions]] as a transport layer for information exchange. Several Application layer protocols already exist for BitcoinSV - for more detail see [[Building on Bitcoin]]. [[The Metanet]] fuses Bitcoin's highly secure and instant [[Transaction fees|sub-cent transactions]] with onchain data storage and transferability enabling efficient and secure web usage. This will bring forth an Internet of Value where Micropayments become a means to both access and monetize data.&lt;br /&gt;
&lt;br /&gt;
Applications which make use of the immutable nature of the [[Block_chain|Bitcoin Ledger]] to store and retrieve data are emerging at an increasingly rate. [[False Return]] scripts and other scripts that use [[Pushdata Opcodes]] to push data into Bitcoin transactions are creating new ways of recording data for public consumption. Bitcoin acts as a [[Timechain|timestamp server]] allowing data to be validated and referenced using transactions.&lt;br /&gt;
&lt;br /&gt;
===The Ledger===&lt;br /&gt;
The Bitcoin ledger is a record of all transactions that have ever been timestamped on the network. The ledger is formed as a [[wikipedia:Directed Acyclic Graph|Directed acyclic graph]] (DAG) where each transaction is a node. The graph starts at the [[Coinbase]] transaction of the [[Genesis block|first block ever found]] and via chains of [[Digital Signatures in Bitcoin|digital signatures]] maps out the entire history of valid exchange actions, allowing the tracing of all bitcoins back to their creation.&lt;br /&gt;
&lt;br /&gt;
[[File:Chain_of_Signatures.png|frame|centre|alt=Electronic coins are defined as a chain of digital signatures]]&lt;br /&gt;
&lt;br /&gt;
Valid transactions that are broadcast on [[The Bitcoin Network]] are committed to the ledger by miners in [[Block|Blocks]]. A block consists of an ordered list of [[TXID|transaction hashes]] and a [[Block hashing algorithm#Block_Header|header]] which includes the root generated by hashing the listed transactions into a [[wikipedia:Merkle tree|Merkle tree]], a timestamp, a reference to the block it builds upon and the means to validate the [[Proof of Work]] needed for other miners to accept the block as valid.&lt;br /&gt;
&lt;br /&gt;
Blocks form a second layer DAG called the [[Block chain]] which is built by [[Mining|network miners]] in a competitive process. Each block forms a node in the graph with a single incoming edge from the block it is built upon. A block may have more than one outgoing edge in a case where multiple blocks were built upon it, but only one of those edges can becomes part of the longest chain of proof of work. A block without an edge to the longest chain of proof of work is called an [[Orphan Block]].&lt;br /&gt;
&lt;br /&gt;
[[File:Block_Chain.png|frame|centre|alt=A chain of blocks]]&lt;br /&gt;
&lt;br /&gt;
The structure of the block chain DAG means that there is a clearly traceable path back to the [[Genesis block|first block mined]]. Blocks are discovered just under every 10 minutes on average, with miners using a predefined mathematical algorithm to control the [[difficulty]] of the proof of work process to maintain that time frame.&lt;br /&gt;
&lt;br /&gt;
Transactions can be exchanged peer to peer using [[Simplified Payment Verification]] (SPV) to manage trust. SPV involves sending accompanying information with a transaction input that proves it is from a transaction that has been timestamped on the ledger.&lt;br /&gt;
&lt;br /&gt;
[[File:Simplified_Payment_Verification.png|frame|centre|alt=Simplified payment verification]]&lt;br /&gt;
&lt;br /&gt;
Users can exchange unfinalised transactions without sending them to the network to be mined creating what are called [[Payment Channels]].&lt;br /&gt;
Payment channels allow users to conduct information exchange within valid Bitcoin transactions, only broadcasting a finalised transaction including the full value exchange to the mining network once the information transfer is complete.&lt;br /&gt;
&lt;br /&gt;
Once a transactions is sent to the network, global consensus can be reached on the validity in less than 2 seconds. If a transaction is not accepted by any miners and added to a block, it does not become part of the ledger.&lt;br /&gt;
&lt;br /&gt;
===Transactions===&lt;br /&gt;
All [[Bitcoin Transactions]] are [[Payments in Bitcoin|payments]] of some kind. Transactions are written in a flexible [[Advanced_Bitcoin_Scripting|scripting language]] that is used to assign custodial control to each transaction output via the creation of arbitrary spending conditions defined by scripts.&lt;br /&gt;
&lt;br /&gt;
Each transaction uses '[[UTXO|coins]]' as inputs and spends them into a new set of coins as [[VOUT|outputs]]. When coins are spent in a transaction they are destroyed.&lt;br /&gt;
&lt;br /&gt;
[[File:Transaction.png|frame|centre|alt=Transaction inputs and outputs]]&lt;br /&gt;
&lt;br /&gt;
The Bitcoin scripting language can be used in a way that is [[wikipedia:Turing_completeness|Turing complete]], creating a [[wikipedia:Turing_machine|Turing machine]] that uses the Bitcoin ledger as a tape, reading to and writing from the transaction graph as needed.&lt;br /&gt;
&lt;br /&gt;
The script also includes opcodes that allow users to embed arbitrary data in transactions, providing for the creation of [[Application layer protocol|application layer protocols]] that use Bitcoin transactions as a [[wikipedia:Transport layer|transport layer]].&lt;br /&gt;
&lt;br /&gt;
Rewards paid to miners for the creation of a block are inscribed in what is called a [[Coinbase]] transaction. This transaction has a specific format and is always the last transaction in the block's [[wikipedia:Merkle tree|Merkle tree]].&lt;br /&gt;
&lt;br /&gt;
===Nodes and Mining===&lt;br /&gt;
The ledger is held on a [https://en.wikipedia.org/wiki/Distributed_networking distributed network] of nodes who use hash based [[Proof of Work]] to compete for the right to extend it and as a means to enforce network rules. The proof of work of each block in the longest chain of work is incorporated into its subsequent block to form the chain structure.&lt;br /&gt;
&lt;br /&gt;
[[File:Proof_of_Work.png|frame|centre|alt=A chain of hash based proof of work]]&lt;br /&gt;
&lt;br /&gt;
During the [[mining]] process, a node gathers transactions from the network and evaluates whether they are profitable to mine before putting them into a block template. Block templates are created by calculating the root of a [https://en.wikipedia.org/wiki/Merkle_tree Merkle tree] containing all of the transactions being mined. The order of transactions in the Merkle tree is not related to their position in the transaction DAG. As new transactions arrive, they are added to the tree, creating a new, updated template. A block is found when a miner successfully discovers a value that generates a hash less than the [[difficulty]] [[target]]. The miner must then propagate the new block to the rest of the network who must then build an additional 100 blocks on top of it before the winner can claim the block reward.&lt;br /&gt;
&lt;br /&gt;
[[File:Merkle tree.png|frame|centre|alt=The structure of a Merkle Tree]]&lt;br /&gt;
&lt;br /&gt;
Nodes are operated by the [[Mining|Bitcoin mining enterprises]] who build the network. Bitcoin's economic incentives are structured such that for the nodes to be most profitable at building the ledger they must be as closely connected to other well performing nodes as possible. This leads to miners forming a [[Small World Network]] which trends towards a [[Nearly Complete Graph]] where all miners are connected to all other miners. Miners gather transactions from users who connect in a layered network over the nodes at the core forming a [[Mandala Network]]. In this shell network, peers use [[Simplified Payment Verification]] to form a much less densely packed structure where information is exchanged in [[Payment Channels]].&lt;br /&gt;
&lt;br /&gt;
As Bitcoin scales, the nodes who comprise the network will be variously compartmentalised into specialised hardware. These clustered systems will be distributed globally, each being placed in a location optimised for its task.&lt;br /&gt;
&lt;br /&gt;
As enterprise organisations, Bitcoin miners must operate as legal entities within a given jurisdiction and as such are bound to the laws and legal processes that exist in that jurisdiction. Through this, miners can be compelled to enact certain rules or perform certain actions in order to comply with the law. This can include the freezing or transferring of bitcoins stored on the ledger, or the rejection of transactions or blocks that try to spend bitcoins identified as proceeds of crime.&lt;br /&gt;
&lt;br /&gt;
===Unit of account===&lt;br /&gt;
[[Satoshis]] are the ledger's native unit of account and 100,000,000 satoshis is abstracted to one bitcoin. Satoshis are held in script puzzles called [[UTXO|Unspent Transaction Outputs or UTXOs]]. These are [[VOUT|transaction outputs]] which are held by miners in a quick access database called the UTXO set. During the spending process, UTXOs being used in a transaction are consumed and the solution to their puzzle script is recorded in the transaction.&lt;br /&gt;
&lt;br /&gt;
Satoshis are issued by miners to themselves as a [[Block subsidy|subsidy payment]] during the network establishment phase. As the network matures, the the subsidy dissipates forcing the miners to find alternate revenue streams. The payment allows miners to finance their operations through the payment of goods and services in bitcoin, spreading it through the economy.&lt;br /&gt;
&lt;br /&gt;
===Network rules===&lt;br /&gt;
Bitcoin operates on a fixed ruleset. So-called consensus rules include things such as the operation of the [[Opcodes used in Bitcoin Script|opcodes]] in Bitcoin Script, the rate at which new bitcoins are issued, the mathematical function used to calculate the [[target]] for the [[Difficulty]] algorithm and more. The protocol is agreed upon by the miners who control network operation.&lt;br /&gt;
&lt;br /&gt;
There are no limits in the [[Protocol|Bitcoin protocol]]. Any limits imposed are are put in place by miners who are incentivised to catch the largest profitable pools of transactions they can. Miners compete to offer better service to fee paying users by scaling their own capabilities.&lt;br /&gt;
&lt;br /&gt;
===History===&lt;br /&gt;
[[Bitcoin until today|Bitcoin has a rich history]] and has been [[Attacks on Bitcoin|attacked]] in many ways since its inception.   For example, at the time of writing, certain other groups are wrongly using the 'Bitcoin' name to refer to their own projects.  The most famous of these uses a software implementation known as 'Bitcoin core' with tokens from the ledger traded as 'BTC' [[Bitcoin until today|(more information)]].&lt;br /&gt;
&lt;br /&gt;
===Tools and Building on Bitcoin===&lt;br /&gt;
Bitcoin has a rich and diverse [[Building on Bitcoin|set of tools]] which are being added to all the time.&lt;/div&gt;</summary>
		<author><name>Angus Adams</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.bitcoinsv.io/index.php?title=Main_Page&amp;diff=2273</id>
		<title>Main Page</title>
		<link rel="alternate" type="text/html" href="https://wiki.bitcoinsv.io/index.php?title=Main_Page&amp;diff=2273"/>
		<updated>2020-02-27T10:02:06Z</updated>

		<summary type="html">&lt;p&gt;Angus Adams: /* Nodes and Mining */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Here we aim to provide a correct and up-to date set of information on the Bitcoin network and its features and functionality.&lt;br /&gt;
&lt;br /&gt;
===Bitcoin===&lt;br /&gt;
&lt;br /&gt;
'''Bitcoin''' is a peer to peer electronic cash system created by [https://craigwright.net/ Dr. Craig Wright] under the pseudonym [[Satoshi Nakamoto]].  It was first detailed in the [[Bitcoin whitepaper|Bitcoin white paper]] in October 2008, and the source code was [https://www.mail-archive.com/cryptography@metzdowd.com/msg10142.html released] in January 2009. The [[Genesis block|first block]] was mined on the 3rd of January 2009.&lt;br /&gt;
&lt;br /&gt;
Bitcoin allows electronic payments to be sent directly from one party to another, without requiring a central institution or server to process transactions and/or store funds. &lt;br /&gt;
 &lt;br /&gt;
The leaderless structure of the network is viewed as a resolution to [[The Byzantine Generals Problem]] allowing disconnected entities to follow a common direction without centralised instruction. This solves several issues previously seen as unsolvable in distributed networks, including the problem of preventing [[Double-spending]] of coins on the network&lt;br /&gt;
&lt;br /&gt;
===Applications===&lt;br /&gt;
Bitcoin is primarily a [[Payments in Bitcoin|payment system]] which supports peer to peer connection and [[Instant Transactions]]. Early in the [[History of Bitcoin]] payments required users to understand complicated technical details of Bitcoin's technological underpinnings to make transactions. But developments such as [[Paymail]] and [[Simplified Payment Verification]] are changing the landscape and making it much easier for users to connect.&lt;br /&gt;
&lt;br /&gt;
Bitcoin also supports the development of [[Application layer protocol|application layer protocols]] which make use of [[Bitcoin Transactions]] as a transport layer for information exchange. Several Application layer protocols already exist for BitcoinSV - for more detail see [[Building on Bitcoin]]. [[The Metanet]] fuses Bitcoin's highly secure and instant [[Transaction fees|sub-cent transactions]] with onchain data storage and transferability enabling efficient and secure web usage. This will bring forth an Internet of Value where Micropayments become a means to both access and monetize data.&lt;br /&gt;
&lt;br /&gt;
Applications which make use of the immutable nature of the [[Block_chain|Bitcoin Ledger]] to store and retrieve data are emerging at an increasingly rate. [[False Return]] scripts and other scripts that use [[Pushdata Opcodes]] to push data into Bitcoin transactions are creating new ways of recording data for public consumption. Bitcoin acts as a [[Timechain|timestamp server]] allowing data to be validated and referenced using transactions.&lt;br /&gt;
&lt;br /&gt;
===The Ledger===&lt;br /&gt;
The Bitcoin ledger is a record of all transactions that have ever been timestamped on the network. The ledger is formed as a [[wikipedia:Directed Acyclic Graph|Directed acyclic graph]] (DAG) where each transaction is a node. The graph starts at the [[Coinbase]] transaction of the [[Genesis block|first block ever found]] and via chains of [[Digital Signatures in Bitcoin|digital signatures]] maps out the entire history of valid exchange actions, allowing the tracing of all bitcoins back to their creation.&lt;br /&gt;
&lt;br /&gt;
[[File:Chain_of_Signatures.png|frame|centre|alt=Electronic coins are defined as a chain of digital signatures]]&lt;br /&gt;
&lt;br /&gt;
Valid transactions that are broadcast on [[The Bitcoin Network]] are committed to the ledger by miners in [[Block|Blocks]]. A block consists of an ordered list of [[TXID|transaction hashes]] and a [[Block hashing algorithm#Block_Header|header]] which includes the root generated by hashing the listed transactions into a [[wikipedia:Merkle tree|Merkle tree]], a timestamp, a reference to the block it builds upon and the means to validate the [[Proof of Work]] needed for other miners to accept the block as valid.&lt;br /&gt;
&lt;br /&gt;
Blocks form a second layer DAG called the [[Block chain]] which is built by [[Mining|network miners]] in a competitive process. Each block forms a node in the graph with a single incoming edge from the block it is built upon. A block may have more than one outgoing edge in a case where multiple blocks were built upon it, but only one of those edges can becomes part of the longest chain of proof of work. A block without an edge to the longest chain of proof of work is called an [[Orphan Block]].&lt;br /&gt;
&lt;br /&gt;
[[File:Block_Chain.png|frame|centre|alt=A chain of blocks]]&lt;br /&gt;
&lt;br /&gt;
The structure of the block chain DAG means that there is a clearly traceable path back to the [[Genesis block|first block mined]]. Blocks are discovered just under every 10 minutes on average, with miners using a predefined mathematical algorithm to control the [[difficulty]] of the proof of work process to maintain that time frame.&lt;br /&gt;
&lt;br /&gt;
Transactions can be exchanged peer to peer using [[Simplified Payment Verification]] (SPV) to manage trust. SPV involves sending accompanying information with a transaction input that proves it is from a transaction that has been timestamped on the ledger.&lt;br /&gt;
&lt;br /&gt;
[[File:Simplified_Payment_Verification.png|frame|centre|alt=Simplified payment verification]]&lt;br /&gt;
&lt;br /&gt;
Users can exchange unfinalised transactions without sending them to the network to be mined creating what are called [[Payment Channels]].&lt;br /&gt;
Payment channels allow users to conduct information exchange within valid Bitcoin transactions, only broadcasting a finalised transaction including the full value exchange to the mining network once the information transfer is complete.&lt;br /&gt;
&lt;br /&gt;
Once a transactions is sent to the network, global consensus can be reached on the validity in less than 2 seconds. If a transaction is not accepted by any miners and added to a block, it does not become part of the ledger.&lt;br /&gt;
&lt;br /&gt;
===Transactions===&lt;br /&gt;
All [[Bitcoin Transactions]] are [[Payments in Bitcoin|payments]] of some kind. Transactions are written in a flexible [[Advanced_Bitcoin_Scripting|scripting language]] that is used to assign custodial control to each transaction output via the creation of arbitrary spending conditions defined by scripts.&lt;br /&gt;
&lt;br /&gt;
Each transaction uses '[[UTXO|coins]]' as inputs and spends them into a new set of coins as [[VOUT|outputs]]. When coins are spent in a transaction they are destroyed.&lt;br /&gt;
&lt;br /&gt;
[[File:Transaction.png|frame|centre|alt=Transaction inputs and outputs]]&lt;br /&gt;
&lt;br /&gt;
The Bitcoin scripting language can be used in a way that is [[wikipedia:Turing_completeness|Turing complete]], creating a [[wikipedia:Turing_machine|Turing machine]] that uses the Bitcoin ledger as a tape, reading to and writing from the transaction graph as needed.&lt;br /&gt;
&lt;br /&gt;
The script also includes opcodes that allow users to embed arbitrary data in transactions, providing for the creation of [[Application layer protocol|application layer protocols]] that use Bitcoin transactions as a [[wikipedia:Transport layer|transport layer]].&lt;br /&gt;
&lt;br /&gt;
Rewards paid to miners for the creation of a block are inscribed in what is called a [[Coinbase]] transaction. This transaction has a specific format and is always the last transaction in the block's [[wikipedia:Merkle tree|Merkle tree]].&lt;br /&gt;
&lt;br /&gt;
===Nodes and Mining===&lt;br /&gt;
The ledger is held on a [https://en.wikipedia.org/wiki/Distributed_networking distributed network] of nodes who use hash based [[Proof of Work]] to compete for the right to extend it and as a means to enforce network rules. The proof of work of each block in the longest chain of work is incorporated into its subsequent block to form the chain structure.&lt;br /&gt;
&lt;br /&gt;
[[File:Proof_of_Work.png|frame|centre|alt=A chain of hash based proof of work]]&lt;br /&gt;
&lt;br /&gt;
During the mining process, a node gathers transactions from the network and evaluates whether they are profitable to mine before putting them into a block template. Block templates are created by calculating the root of a [https://en.wikipedia.org/wiki/Merkle_tree Merkle tree] containing all of the transactions being mined. The order of transactions in the Merkle tree is not related to their position in the transaction DAG. As new transactions arrive, they are added to the tree, creating a new, updated template. A block is found when a miner successfully discovers a value that generates a hash less than the [[difficulty]] [[target]]. The miner must then propagate the new block to the rest of the network who must then build an additional 100 blocks on top of it before the winner can claim the block reward.&lt;br /&gt;
&lt;br /&gt;
[[File:Merkle tree.png|frame|centre|alt=The structure of a Merkle Tree]]&lt;br /&gt;
&lt;br /&gt;
Nodes are operated by the [[Mining|Bitcoin mining enterprises]] who build the network. Bitcoin's economic incentives are structured such that for the nodes to be most profitable at building the ledger they must be as closely connected to other well performing nodes as possible. This leads to miners forming a [[Small World Network]] which trends towards a [[Nearly Complete Graph]] where all miners are connected to all other miners. Miners gather transactions from users who connect in a layered network over the nodes at the core forming a [[Mandala Network]]. In this shell network, peers use [[Simplified Payment Verification]] to form a much less densely packed structure where information is exchanged in [[Payment Channels]].&lt;br /&gt;
&lt;br /&gt;
As Bitcoin scales, the nodes who comprise the network will be variously compartmentalised into specialised hardware. These clustered systems will be distributed globally, each being placed in a location optimised for its task.&lt;br /&gt;
&lt;br /&gt;
As enterprise organisations, Bitcoin miners must operate as legal entities within a given jurisdiction and as such are bound to the laws and legal processes that exist in that jurisdiction. Through this, miners can be compelled to enact certain rules or perform certain actions in order to comply with the law. This can include the freezing or transferring of bitcoins stored on the ledger, or the rejection of transactions or blocks that try to spend bitcoins identified as proceeds of crime.&lt;br /&gt;
&lt;br /&gt;
===Unit of account===&lt;br /&gt;
[[Satoshis]] are the ledger's native unit of account and 100,000,000 satoshis is abstracted to one bitcoin. Satoshis are held in script puzzles called [[UTXO|Unspent Transaction Outputs or UTXOs]]. These are [[VOUT|transaction outputs]] which are held by miners in a quick access database called the UTXO set. During the spending process, UTXOs being used in a transaction are consumed and the solution to their puzzle script is recorded in the transaction.&lt;br /&gt;
&lt;br /&gt;
Satoshis are issued by miners to themselves as a [[Block subsidy|subsidy payment]] during the network establishment phase. As the network matures, the the subsidy dissipates forcing the miners to find alternate revenue streams. The payment allows miners to finance their operations through the payment of goods and services in bitcoin, spreading it through the economy.&lt;br /&gt;
&lt;br /&gt;
===Network rules===&lt;br /&gt;
Bitcoin operates on a fixed ruleset. So-called consensus rules include things such as the operation of the [[Opcodes used in Bitcoin Script|opcodes]] in Bitcoin Script, the rate at which new bitcoins are issued, the mathematical function used to calculate the [[target]] for the [[Difficulty]] algorithm and more. The protocol is agreed upon by the miners who control network operation.&lt;br /&gt;
&lt;br /&gt;
There are no limits in the [[Protocol|Bitcoin protocol]]. Any limits imposed are are put in place by miners who are incentivised to catch the largest profitable pools of transactions they can. Miners compete to offer better service to fee paying users by scaling their own capabilities.&lt;br /&gt;
&lt;br /&gt;
===History===&lt;br /&gt;
[[Bitcoin until today|Bitcoin has a rich history]] and has been [[Attacks on Bitcoin|attacked]] in many ways since its inception.   For example, at the time of writing, certain other groups are wrongly using the 'Bitcoin' name to refer to their own projects.  The most famous of these uses a software implementation known as 'Bitcoin core' with tokens from the ledger traded as 'BTC' [[Bitcoin until today|(more information)]].&lt;br /&gt;
&lt;br /&gt;
===Tools and Building on Bitcoin===&lt;br /&gt;
Bitcoin has a rich and diverse [[Building on Bitcoin|set of tools]] which are being added to all the time.&lt;/div&gt;</summary>
		<author><name>Angus Adams</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.bitcoinsv.io/index.php?title=Difficulty&amp;diff=2265</id>
		<title>Difficulty</title>
		<link rel="alternate" type="text/html" href="https://wiki.bitcoinsv.io/index.php?title=Difficulty&amp;diff=2265"/>
		<updated>2020-02-19T15:24:24Z</updated>

		<summary type="html">&lt;p&gt;Angus Adams: /* What is the maximum difficulty? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;''See also: [[Target]]''&lt;br /&gt;
&lt;br /&gt;
=== What is difficulty? ===&lt;br /&gt;
&lt;br /&gt;
Difficulty is a measure of how difficult it is to find a hash below a given [[target]]. Difficulty answers the question: &amp;quot;how many times more difficult is it to mine a block now, compared with how difficult it was to mine the [[Genesis block|Genesis Block]]?&amp;quot;. It has a close relationship with target but is not the same thing. Rather it has an inverse relationship where a higher difficulty implies a lower target value.&lt;br /&gt;
&lt;br /&gt;
The Bitcoin network has a global block difficulty. Valid blocks must have a hash below this target.&lt;br /&gt;
Mining pools also have a pool-specific share difficulty setting a lower limit for shares.&lt;br /&gt;
&lt;br /&gt;
=== How often does the network difficulty change? ===&lt;br /&gt;
&lt;br /&gt;
See [[Target|target]].&lt;br /&gt;
&lt;br /&gt;
=== What is the formula for difficulty? ===&lt;br /&gt;
difficulty = difficulty_1_target / current_target &lt;br /&gt;
&lt;br /&gt;
''target is a 256 bit number''&lt;br /&gt;
&lt;br /&gt;
''difficulty_1_target is the target used in the Genesis Block and represents a difficulty of 1.''&lt;br /&gt;
&lt;br /&gt;
difficulty_1_target can be different for various ways to measure difficulty.&lt;br /&gt;
Traditionally, it represents a hash where the leading 32 bits are zero and the rest are one (this is known as &amp;quot;pool difficulty&amp;quot; or &amp;quot;pdiff&amp;quot;).&lt;br /&gt;
The Bitcoin protocol represents targets as a custom floating point type with limited precision; as a result, Bitcoin clients often approximate difficulty based on this (this is known as &amp;quot;bdiff&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
===How is difficulty stored in blocks?===&lt;br /&gt;
&lt;br /&gt;
Each block stores a packed representation in its block header (called [[Block hashing algorithm|Bits]]) for its actual hexadecimal [[target]]. The target can be derived from Bits via a predefined formula. For example, if the packed target in the block is 0x1b0404cb, the hexadecimal target is:&lt;br /&gt;
 0x0404cb * 2**(8*(0x1b - 3)) = 0x00000000000404CB000000000000000000000000000000000000000000000000&lt;br /&gt;
&lt;br /&gt;
Note that the 0x0404cb value is a signed value in this format. The largest legal value for this field is 0x7fffff. To make a larger value you must shift it down one full byte. Also 0x008000 is the smallest positive valid value.&lt;br /&gt;
&lt;br /&gt;
===How is difficulty calculated? What is the difference between bdiff and pdiff?===&lt;br /&gt;
&lt;br /&gt;
The highest possible target (difficulty 1) is defined as 0x1d00ffff, which gives us a hex target of&lt;br /&gt;
 0x00ffff * 2**(8*(0x1d - 3)) = 0x00000000FFFF0000000000000000000000000000000000000000000000000000&lt;br /&gt;
&lt;br /&gt;
It should be noted that pooled mining often uses non-truncated targets, which puts &amp;quot;pool difficulty 1&amp;quot; at&lt;br /&gt;
 0x00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF&lt;br /&gt;
&lt;br /&gt;
So the difficulty at 0x1b0404cb is therefore:&lt;br /&gt;
 0x00000000FFFF0000000000000000000000000000000000000000000000000000 /&lt;br /&gt;
 0x00000000000404CB000000000000000000000000000000000000000000000000 &lt;br /&gt;
 = 16307.420938523983 (bdiff)&lt;br /&gt;
And:&lt;br /&gt;
 0x00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF /&lt;br /&gt;
 0x00000000000404CB000000000000000000000000000000000000000000000000 &lt;br /&gt;
 = 16307.669773817162 (pdiff)&lt;br /&gt;
&lt;br /&gt;
Here's a fast way to calculate Bitcoin difficulty. It uses a modified Taylor series for the logarithm (you can see tutorials on flipcode and wikipedia) and relies on logs to transform the difficulty calculation:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;cmath&amp;gt;&lt;br /&gt;
&lt;br /&gt;
inline float fast_log(float val)&lt;br /&gt;
{&lt;br /&gt;
   int * const exp_ptr = reinterpret_cast &amp;lt;int *&amp;gt;(&amp;amp;val);&lt;br /&gt;
   int x = *exp_ptr;&lt;br /&gt;
   const int log_2 = ((x &amp;gt;&amp;gt; 23) &amp;amp; 255) - 128;&lt;br /&gt;
   x &amp;amp;= ~(255 &amp;lt;&amp;lt; 23);&lt;br /&gt;
   x += 127 &amp;lt;&amp;lt; 23;&lt;br /&gt;
   *exp_ptr = x;&lt;br /&gt;
&lt;br /&gt;
   val = ((-1.0f/3) * val + 2) * val - 2.0f/3;&lt;br /&gt;
   return ((val + log_2) * 0.69314718f);&lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
float difficulty(unsigned int bits)&lt;br /&gt;
{&lt;br /&gt;
    static double max_body = fast_log(0x00ffff), scaland = fast_log(256);&lt;br /&gt;
    return exp(max_body - fast_log(bits &amp;amp; 0x00ffffff) + scaland * (0x1d - ((bits &amp;amp; 0xff000000) &amp;gt;&amp;gt; 24)));&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
    std::cout &amp;lt;&amp;lt; difficulty(0x1b0404cb) &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To see the math to go from the normal difficulty calculations (which require large big ints bigger than the space in any normal integer) to the calculation above, here's some python:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import decimal, math&lt;br /&gt;
l = math.log&lt;br /&gt;
e = math.e&lt;br /&gt;
&lt;br /&gt;
print 0x00ffff * 2**(8*(0x1d - 3)) / float(0x0404cb * 2**(8*(0x1b - 3)))&lt;br /&gt;
print l(0x00ffff * 2**(8*(0x1d - 3)) / float(0x0404cb * 2**(8*(0x1b - 3))))&lt;br /&gt;
print l(0x00ffff * 2**(8*(0x1d - 3))) - l(0x0404cb * 2**(8*(0x1b - 3)))&lt;br /&gt;
print l(0x00ffff) + l(2**(8*(0x1d - 3))) - l(0x0404cb) - l(2**(8*(0x1b - 3)))&lt;br /&gt;
print l(0x00ffff) + (8*(0x1d - 3))*l(2) - l(0x0404cb) - (8*(0x1b - 3))*l(2)&lt;br /&gt;
print l(0x00ffff / float(0x0404cb)) + (8*(0x1d - 3))*l(2) - (8*(0x1b - 3))*l(2)&lt;br /&gt;
print l(0x00ffff / float(0x0404cb)) + (0x1d - 0x1b)*l(2**8)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== What is the current difficulty? ===&lt;br /&gt;
[https://whatsonchain.com/ Current difficulty]&lt;br /&gt;
&lt;br /&gt;
=== What is the maximum difficulty? ===&lt;br /&gt;
&lt;br /&gt;
There is no minimum target. The maximum difficulty is roughly: maximum_target / 1 (since 0 would result in infinity), which is a ridiculously huge number (about 2^224).&lt;br /&gt;
&lt;br /&gt;
The actual maximum difficulty is when current_target=0, but we would not be able to calculate the difficulty if that happened. (fortunately it never will, so we're ok.)&lt;br /&gt;
&lt;br /&gt;
In the case of Bitcoin (BSV) and Bitcoin Cash (BCH), the network's difficulty can rise by a maximum of 100% of the current difficulty in a single adjustment.&lt;br /&gt;
&lt;br /&gt;
In the original implementation, still used by Bitcoin Core (BTC), the difficulty can rise by a maximum of 400% of the current difficulty in a single adjustment.&lt;br /&gt;
&lt;br /&gt;
=== Can the network difficulty decrease? ===&lt;br /&gt;
Yes it can. See discussion in [[target]]. &lt;br /&gt;
&lt;br /&gt;
In the case of Bitcoin (BSV) and Bitcoin Cash (BCH), the network's difficulty can adjust downwards by up to 50% of the current difficulty in a single adjustment.&lt;br /&gt;
&lt;br /&gt;
In the original implementation, still used by Bitcoin Core (BTC), the network's difficulty can adjust downwards by up to 75% of the current difficulty in a single adjustment.&lt;br /&gt;
&lt;br /&gt;
=== What is the minimum difficulty? ===&lt;br /&gt;
The minimum difficulty, when the target is at the maximum allowed value, is 1. This is the difficulty of the [[Genesis block]].&lt;br /&gt;
&lt;br /&gt;
=== What network hash rate results in a given difficulty? ===&lt;br /&gt;
The difficulty is adjusted every 2016 blocks based on the [[Block_timestamp|time]] it took to find the previous 2016 blocks.  At the desired rate of one block each 10 minutes, 2016 blocks would take exactly two weeks to find.  If the previous 2016 blocks took more than two weeks to find, the difficulty is reduced.  If they took less than two weeks, the difficulty is increased.  The change in difficulty is in proportion to the amount of time over or under two weeks the previous 2016 blocks took to find.&lt;br /&gt;
&lt;br /&gt;
To find a block, the hash must be less than the target.  The hash is effectively a random number between 0 and 2**256-1.  The offset for difficulty 1 is&lt;br /&gt;
 0xffff * 2**208&lt;br /&gt;
and for difficulty D is&lt;br /&gt;
 (0xffff * 2**208)/D&lt;br /&gt;
&lt;br /&gt;
The expected number of hashes we need to calculate to find a block with difficulty D is therefore&lt;br /&gt;
 D * 2**256 / (0xffff * 2**208)&lt;br /&gt;
or just&lt;br /&gt;
 D * 2**48 / 0xffff&lt;br /&gt;
&lt;br /&gt;
The difficulty is set such that the previous 2016 blocks would have been found at the rate of one every 10 minutes, so we were calculating (D * 2**48 / 0xffff) hashes in 600 seconds.  That means the hash rate of the network was&lt;br /&gt;
 D * 2**48 / 0xffff / 600&lt;br /&gt;
over the previous 2016 blocks.  Can be further simplified to&lt;br /&gt;
 D * 2**32 / 600&lt;br /&gt;
without much loss of accuracy.&lt;br /&gt;
&lt;br /&gt;
At difficulty 1, that is around 7 Mhashes per second.&lt;br /&gt;
&lt;br /&gt;
At the time of writing, the difficulty is 22012.4941572, which means that over the previous set of 2016 blocks found the average network hash rate was&lt;br /&gt;
 22012.4941572 * 2**32 / 600 = around 157 Ghashes per second.&lt;br /&gt;
&lt;br /&gt;
==Related Links==&lt;br /&gt;
&lt;br /&gt;
* See also: [[Target]]&lt;br /&gt;
&lt;br /&gt;
==Attribution==&lt;br /&gt;
This content is based on content sourced from https://en.bitcoin.it/wiki/Difficulty under [https://creativecommons.org/licenses/by/3.0/ Creative Commons Attribution 3.0]. Although it may have been extensively revised and updated we acknowledge the original authors.&lt;/div&gt;</summary>
		<author><name>Angus Adams</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.bitcoinsv.io/index.php?title=Difficulty&amp;diff=2264</id>
		<title>Difficulty</title>
		<link rel="alternate" type="text/html" href="https://wiki.bitcoinsv.io/index.php?title=Difficulty&amp;diff=2264"/>
		<updated>2020-02-19T15:23:49Z</updated>

		<summary type="html">&lt;p&gt;Angus Adams: /* Can the network difficulty decrease? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;''See also: [[Target]]''&lt;br /&gt;
&lt;br /&gt;
=== What is difficulty? ===&lt;br /&gt;
&lt;br /&gt;
Difficulty is a measure of how difficult it is to find a hash below a given [[target]]. Difficulty answers the question: &amp;quot;how many times more difficult is it to mine a block now, compared with how difficult it was to mine the [[Genesis block|Genesis Block]]?&amp;quot;. It has a close relationship with target but is not the same thing. Rather it has an inverse relationship where a higher difficulty implies a lower target value.&lt;br /&gt;
&lt;br /&gt;
The Bitcoin network has a global block difficulty. Valid blocks must have a hash below this target.&lt;br /&gt;
Mining pools also have a pool-specific share difficulty setting a lower limit for shares.&lt;br /&gt;
&lt;br /&gt;
=== How often does the network difficulty change? ===&lt;br /&gt;
&lt;br /&gt;
See [[Target|target]].&lt;br /&gt;
&lt;br /&gt;
=== What is the formula for difficulty? ===&lt;br /&gt;
difficulty = difficulty_1_target / current_target &lt;br /&gt;
&lt;br /&gt;
''target is a 256 bit number''&lt;br /&gt;
&lt;br /&gt;
''difficulty_1_target is the target used in the Genesis Block and represents a difficulty of 1.''&lt;br /&gt;
&lt;br /&gt;
difficulty_1_target can be different for various ways to measure difficulty.&lt;br /&gt;
Traditionally, it represents a hash where the leading 32 bits are zero and the rest are one (this is known as &amp;quot;pool difficulty&amp;quot; or &amp;quot;pdiff&amp;quot;).&lt;br /&gt;
The Bitcoin protocol represents targets as a custom floating point type with limited precision; as a result, Bitcoin clients often approximate difficulty based on this (this is known as &amp;quot;bdiff&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
===How is difficulty stored in blocks?===&lt;br /&gt;
&lt;br /&gt;
Each block stores a packed representation in its block header (called [[Block hashing algorithm|Bits]]) for its actual hexadecimal [[target]]. The target can be derived from Bits via a predefined formula. For example, if the packed target in the block is 0x1b0404cb, the hexadecimal target is:&lt;br /&gt;
 0x0404cb * 2**(8*(0x1b - 3)) = 0x00000000000404CB000000000000000000000000000000000000000000000000&lt;br /&gt;
&lt;br /&gt;
Note that the 0x0404cb value is a signed value in this format. The largest legal value for this field is 0x7fffff. To make a larger value you must shift it down one full byte. Also 0x008000 is the smallest positive valid value.&lt;br /&gt;
&lt;br /&gt;
===How is difficulty calculated? What is the difference between bdiff and pdiff?===&lt;br /&gt;
&lt;br /&gt;
The highest possible target (difficulty 1) is defined as 0x1d00ffff, which gives us a hex target of&lt;br /&gt;
 0x00ffff * 2**(8*(0x1d - 3)) = 0x00000000FFFF0000000000000000000000000000000000000000000000000000&lt;br /&gt;
&lt;br /&gt;
It should be noted that pooled mining often uses non-truncated targets, which puts &amp;quot;pool difficulty 1&amp;quot; at&lt;br /&gt;
 0x00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF&lt;br /&gt;
&lt;br /&gt;
So the difficulty at 0x1b0404cb is therefore:&lt;br /&gt;
 0x00000000FFFF0000000000000000000000000000000000000000000000000000 /&lt;br /&gt;
 0x00000000000404CB000000000000000000000000000000000000000000000000 &lt;br /&gt;
 = 16307.420938523983 (bdiff)&lt;br /&gt;
And:&lt;br /&gt;
 0x00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF /&lt;br /&gt;
 0x00000000000404CB000000000000000000000000000000000000000000000000 &lt;br /&gt;
 = 16307.669773817162 (pdiff)&lt;br /&gt;
&lt;br /&gt;
Here's a fast way to calculate Bitcoin difficulty. It uses a modified Taylor series for the logarithm (you can see tutorials on flipcode and wikipedia) and relies on logs to transform the difficulty calculation:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;cmath&amp;gt;&lt;br /&gt;
&lt;br /&gt;
inline float fast_log(float val)&lt;br /&gt;
{&lt;br /&gt;
   int * const exp_ptr = reinterpret_cast &amp;lt;int *&amp;gt;(&amp;amp;val);&lt;br /&gt;
   int x = *exp_ptr;&lt;br /&gt;
   const int log_2 = ((x &amp;gt;&amp;gt; 23) &amp;amp; 255) - 128;&lt;br /&gt;
   x &amp;amp;= ~(255 &amp;lt;&amp;lt; 23);&lt;br /&gt;
   x += 127 &amp;lt;&amp;lt; 23;&lt;br /&gt;
   *exp_ptr = x;&lt;br /&gt;
&lt;br /&gt;
   val = ((-1.0f/3) * val + 2) * val - 2.0f/3;&lt;br /&gt;
   return ((val + log_2) * 0.69314718f);&lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
float difficulty(unsigned int bits)&lt;br /&gt;
{&lt;br /&gt;
    static double max_body = fast_log(0x00ffff), scaland = fast_log(256);&lt;br /&gt;
    return exp(max_body - fast_log(bits &amp;amp; 0x00ffffff) + scaland * (0x1d - ((bits &amp;amp; 0xff000000) &amp;gt;&amp;gt; 24)));&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
    std::cout &amp;lt;&amp;lt; difficulty(0x1b0404cb) &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To see the math to go from the normal difficulty calculations (which require large big ints bigger than the space in any normal integer) to the calculation above, here's some python:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import decimal, math&lt;br /&gt;
l = math.log&lt;br /&gt;
e = math.e&lt;br /&gt;
&lt;br /&gt;
print 0x00ffff * 2**(8*(0x1d - 3)) / float(0x0404cb * 2**(8*(0x1b - 3)))&lt;br /&gt;
print l(0x00ffff * 2**(8*(0x1d - 3)) / float(0x0404cb * 2**(8*(0x1b - 3))))&lt;br /&gt;
print l(0x00ffff * 2**(8*(0x1d - 3))) - l(0x0404cb * 2**(8*(0x1b - 3)))&lt;br /&gt;
print l(0x00ffff) + l(2**(8*(0x1d - 3))) - l(0x0404cb) - l(2**(8*(0x1b - 3)))&lt;br /&gt;
print l(0x00ffff) + (8*(0x1d - 3))*l(2) - l(0x0404cb) - (8*(0x1b - 3))*l(2)&lt;br /&gt;
print l(0x00ffff / float(0x0404cb)) + (8*(0x1d - 3))*l(2) - (8*(0x1b - 3))*l(2)&lt;br /&gt;
print l(0x00ffff / float(0x0404cb)) + (0x1d - 0x1b)*l(2**8)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== What is the current difficulty? ===&lt;br /&gt;
[https://whatsonchain.com/ Current difficulty]&lt;br /&gt;
&lt;br /&gt;
=== What is the maximum difficulty? ===&lt;br /&gt;
&lt;br /&gt;
There is no minimum target. The maximum difficulty is roughly: maximum_target / 1 (since 0 would result in infinity), which is a ridiculously huge number (about 2^224).&lt;br /&gt;
&lt;br /&gt;
The actual maximum difficulty is when current_target=0, but we would not be able to calculate the difficulty if that happened. (fortunately it never will, so we're ok.)&lt;br /&gt;
&lt;br /&gt;
In the original implementation, still used by Bitcoin Core (BTC), the difficulty can rise by a maximum of 400% of the current difficulty in a single adjustment.&lt;br /&gt;
&lt;br /&gt;
In the case of Bitcoin (BSV) and Bitcoin Cash (BCH), the network's difficulty can rise by a maximum of 100% of the current difficulty in a single adjustment.&lt;br /&gt;
&lt;br /&gt;
=== Can the network difficulty decrease? ===&lt;br /&gt;
Yes it can. See discussion in [[target]]. &lt;br /&gt;
&lt;br /&gt;
In the case of Bitcoin (BSV) and Bitcoin Cash (BCH), the network's difficulty can adjust downwards by up to 50% of the current difficulty in a single adjustment.&lt;br /&gt;
&lt;br /&gt;
In the original implementation, still used by Bitcoin Core (BTC), the network's difficulty can adjust downwards by up to 75% of the current difficulty in a single adjustment.&lt;br /&gt;
&lt;br /&gt;
=== What is the minimum difficulty? ===&lt;br /&gt;
The minimum difficulty, when the target is at the maximum allowed value, is 1. This is the difficulty of the [[Genesis block]].&lt;br /&gt;
&lt;br /&gt;
=== What network hash rate results in a given difficulty? ===&lt;br /&gt;
The difficulty is adjusted every 2016 blocks based on the [[Block_timestamp|time]] it took to find the previous 2016 blocks.  At the desired rate of one block each 10 minutes, 2016 blocks would take exactly two weeks to find.  If the previous 2016 blocks took more than two weeks to find, the difficulty is reduced.  If they took less than two weeks, the difficulty is increased.  The change in difficulty is in proportion to the amount of time over or under two weeks the previous 2016 blocks took to find.&lt;br /&gt;
&lt;br /&gt;
To find a block, the hash must be less than the target.  The hash is effectively a random number between 0 and 2**256-1.  The offset for difficulty 1 is&lt;br /&gt;
 0xffff * 2**208&lt;br /&gt;
and for difficulty D is&lt;br /&gt;
 (0xffff * 2**208)/D&lt;br /&gt;
&lt;br /&gt;
The expected number of hashes we need to calculate to find a block with difficulty D is therefore&lt;br /&gt;
 D * 2**256 / (0xffff * 2**208)&lt;br /&gt;
or just&lt;br /&gt;
 D * 2**48 / 0xffff&lt;br /&gt;
&lt;br /&gt;
The difficulty is set such that the previous 2016 blocks would have been found at the rate of one every 10 minutes, so we were calculating (D * 2**48 / 0xffff) hashes in 600 seconds.  That means the hash rate of the network was&lt;br /&gt;
 D * 2**48 / 0xffff / 600&lt;br /&gt;
over the previous 2016 blocks.  Can be further simplified to&lt;br /&gt;
 D * 2**32 / 600&lt;br /&gt;
without much loss of accuracy.&lt;br /&gt;
&lt;br /&gt;
At difficulty 1, that is around 7 Mhashes per second.&lt;br /&gt;
&lt;br /&gt;
At the time of writing, the difficulty is 22012.4941572, which means that over the previous set of 2016 blocks found the average network hash rate was&lt;br /&gt;
 22012.4941572 * 2**32 / 600 = around 157 Ghashes per second.&lt;br /&gt;
&lt;br /&gt;
==Related Links==&lt;br /&gt;
&lt;br /&gt;
* See also: [[Target]]&lt;br /&gt;
&lt;br /&gt;
==Attribution==&lt;br /&gt;
This content is based on content sourced from https://en.bitcoin.it/wiki/Difficulty under [https://creativecommons.org/licenses/by/3.0/ Creative Commons Attribution 3.0]. Although it may have been extensively revised and updated we acknowledge the original authors.&lt;/div&gt;</summary>
		<author><name>Angus Adams</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.bitcoinsv.io/index.php?title=Difficulty&amp;diff=2263</id>
		<title>Difficulty</title>
		<link rel="alternate" type="text/html" href="https://wiki.bitcoinsv.io/index.php?title=Difficulty&amp;diff=2263"/>
		<updated>2020-02-19T15:23:28Z</updated>

		<summary type="html">&lt;p&gt;Angus Adams: /* What is the maximum difficulty? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;''See also: [[Target]]''&lt;br /&gt;
&lt;br /&gt;
=== What is difficulty? ===&lt;br /&gt;
&lt;br /&gt;
Difficulty is a measure of how difficult it is to find a hash below a given [[target]]. Difficulty answers the question: &amp;quot;how many times more difficult is it to mine a block now, compared with how difficult it was to mine the [[Genesis block|Genesis Block]]?&amp;quot;. It has a close relationship with target but is not the same thing. Rather it has an inverse relationship where a higher difficulty implies a lower target value.&lt;br /&gt;
&lt;br /&gt;
The Bitcoin network has a global block difficulty. Valid blocks must have a hash below this target.&lt;br /&gt;
Mining pools also have a pool-specific share difficulty setting a lower limit for shares.&lt;br /&gt;
&lt;br /&gt;
=== How often does the network difficulty change? ===&lt;br /&gt;
&lt;br /&gt;
See [[Target|target]].&lt;br /&gt;
&lt;br /&gt;
=== What is the formula for difficulty? ===&lt;br /&gt;
difficulty = difficulty_1_target / current_target &lt;br /&gt;
&lt;br /&gt;
''target is a 256 bit number''&lt;br /&gt;
&lt;br /&gt;
''difficulty_1_target is the target used in the Genesis Block and represents a difficulty of 1.''&lt;br /&gt;
&lt;br /&gt;
difficulty_1_target can be different for various ways to measure difficulty.&lt;br /&gt;
Traditionally, it represents a hash where the leading 32 bits are zero and the rest are one (this is known as &amp;quot;pool difficulty&amp;quot; or &amp;quot;pdiff&amp;quot;).&lt;br /&gt;
The Bitcoin protocol represents targets as a custom floating point type with limited precision; as a result, Bitcoin clients often approximate difficulty based on this (this is known as &amp;quot;bdiff&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
===How is difficulty stored in blocks?===&lt;br /&gt;
&lt;br /&gt;
Each block stores a packed representation in its block header (called [[Block hashing algorithm|Bits]]) for its actual hexadecimal [[target]]. The target can be derived from Bits via a predefined formula. For example, if the packed target in the block is 0x1b0404cb, the hexadecimal target is:&lt;br /&gt;
 0x0404cb * 2**(8*(0x1b - 3)) = 0x00000000000404CB000000000000000000000000000000000000000000000000&lt;br /&gt;
&lt;br /&gt;
Note that the 0x0404cb value is a signed value in this format. The largest legal value for this field is 0x7fffff. To make a larger value you must shift it down one full byte. Also 0x008000 is the smallest positive valid value.&lt;br /&gt;
&lt;br /&gt;
===How is difficulty calculated? What is the difference between bdiff and pdiff?===&lt;br /&gt;
&lt;br /&gt;
The highest possible target (difficulty 1) is defined as 0x1d00ffff, which gives us a hex target of&lt;br /&gt;
 0x00ffff * 2**(8*(0x1d - 3)) = 0x00000000FFFF0000000000000000000000000000000000000000000000000000&lt;br /&gt;
&lt;br /&gt;
It should be noted that pooled mining often uses non-truncated targets, which puts &amp;quot;pool difficulty 1&amp;quot; at&lt;br /&gt;
 0x00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF&lt;br /&gt;
&lt;br /&gt;
So the difficulty at 0x1b0404cb is therefore:&lt;br /&gt;
 0x00000000FFFF0000000000000000000000000000000000000000000000000000 /&lt;br /&gt;
 0x00000000000404CB000000000000000000000000000000000000000000000000 &lt;br /&gt;
 = 16307.420938523983 (bdiff)&lt;br /&gt;
And:&lt;br /&gt;
 0x00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF /&lt;br /&gt;
 0x00000000000404CB000000000000000000000000000000000000000000000000 &lt;br /&gt;
 = 16307.669773817162 (pdiff)&lt;br /&gt;
&lt;br /&gt;
Here's a fast way to calculate Bitcoin difficulty. It uses a modified Taylor series for the logarithm (you can see tutorials on flipcode and wikipedia) and relies on logs to transform the difficulty calculation:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;cmath&amp;gt;&lt;br /&gt;
&lt;br /&gt;
inline float fast_log(float val)&lt;br /&gt;
{&lt;br /&gt;
   int * const exp_ptr = reinterpret_cast &amp;lt;int *&amp;gt;(&amp;amp;val);&lt;br /&gt;
   int x = *exp_ptr;&lt;br /&gt;
   const int log_2 = ((x &amp;gt;&amp;gt; 23) &amp;amp; 255) - 128;&lt;br /&gt;
   x &amp;amp;= ~(255 &amp;lt;&amp;lt; 23);&lt;br /&gt;
   x += 127 &amp;lt;&amp;lt; 23;&lt;br /&gt;
   *exp_ptr = x;&lt;br /&gt;
&lt;br /&gt;
   val = ((-1.0f/3) * val + 2) * val - 2.0f/3;&lt;br /&gt;
   return ((val + log_2) * 0.69314718f);&lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
float difficulty(unsigned int bits)&lt;br /&gt;
{&lt;br /&gt;
    static double max_body = fast_log(0x00ffff), scaland = fast_log(256);&lt;br /&gt;
    return exp(max_body - fast_log(bits &amp;amp; 0x00ffffff) + scaland * (0x1d - ((bits &amp;amp; 0xff000000) &amp;gt;&amp;gt; 24)));&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
    std::cout &amp;lt;&amp;lt; difficulty(0x1b0404cb) &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To see the math to go from the normal difficulty calculations (which require large big ints bigger than the space in any normal integer) to the calculation above, here's some python:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import decimal, math&lt;br /&gt;
l = math.log&lt;br /&gt;
e = math.e&lt;br /&gt;
&lt;br /&gt;
print 0x00ffff * 2**(8*(0x1d - 3)) / float(0x0404cb * 2**(8*(0x1b - 3)))&lt;br /&gt;
print l(0x00ffff * 2**(8*(0x1d - 3)) / float(0x0404cb * 2**(8*(0x1b - 3))))&lt;br /&gt;
print l(0x00ffff * 2**(8*(0x1d - 3))) - l(0x0404cb * 2**(8*(0x1b - 3)))&lt;br /&gt;
print l(0x00ffff) + l(2**(8*(0x1d - 3))) - l(0x0404cb) - l(2**(8*(0x1b - 3)))&lt;br /&gt;
print l(0x00ffff) + (8*(0x1d - 3))*l(2) - l(0x0404cb) - (8*(0x1b - 3))*l(2)&lt;br /&gt;
print l(0x00ffff / float(0x0404cb)) + (8*(0x1d - 3))*l(2) - (8*(0x1b - 3))*l(2)&lt;br /&gt;
print l(0x00ffff / float(0x0404cb)) + (0x1d - 0x1b)*l(2**8)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== What is the current difficulty? ===&lt;br /&gt;
[https://whatsonchain.com/ Current difficulty]&lt;br /&gt;
&lt;br /&gt;
=== What is the maximum difficulty? ===&lt;br /&gt;
&lt;br /&gt;
There is no minimum target. The maximum difficulty is roughly: maximum_target / 1 (since 0 would result in infinity), which is a ridiculously huge number (about 2^224).&lt;br /&gt;
&lt;br /&gt;
The actual maximum difficulty is when current_target=0, but we would not be able to calculate the difficulty if that happened. (fortunately it never will, so we're ok.)&lt;br /&gt;
&lt;br /&gt;
In the original implementation, still used by Bitcoin Core (BTC), the difficulty can rise by a maximum of 400% of the current difficulty in a single adjustment.&lt;br /&gt;
&lt;br /&gt;
In the case of Bitcoin (BSV) and Bitcoin Cash (BCH), the network's difficulty can rise by a maximum of 100% of the current difficulty in a single adjustment.&lt;br /&gt;
&lt;br /&gt;
=== Can the network difficulty decrease? ===&lt;br /&gt;
Yes it can. See discussion in [[target]]. &lt;br /&gt;
&lt;br /&gt;
In the case of Bitcoin (BSV) and Bitcoin Cash (BCH), the network's difficulty can adjust downwards by up to 50% of the current difficulty in a single adjustment.&lt;br /&gt;
&lt;br /&gt;
In the original implementation, still used by BTC, the network's difficulty can adjust downwards by up to 75% of the current difficulty in a single adjustment.&lt;br /&gt;
&lt;br /&gt;
=== What is the minimum difficulty? ===&lt;br /&gt;
The minimum difficulty, when the target is at the maximum allowed value, is 1. This is the difficulty of the [[Genesis block]].&lt;br /&gt;
&lt;br /&gt;
=== What network hash rate results in a given difficulty? ===&lt;br /&gt;
The difficulty is adjusted every 2016 blocks based on the [[Block_timestamp|time]] it took to find the previous 2016 blocks.  At the desired rate of one block each 10 minutes, 2016 blocks would take exactly two weeks to find.  If the previous 2016 blocks took more than two weeks to find, the difficulty is reduced.  If they took less than two weeks, the difficulty is increased.  The change in difficulty is in proportion to the amount of time over or under two weeks the previous 2016 blocks took to find.&lt;br /&gt;
&lt;br /&gt;
To find a block, the hash must be less than the target.  The hash is effectively a random number between 0 and 2**256-1.  The offset for difficulty 1 is&lt;br /&gt;
 0xffff * 2**208&lt;br /&gt;
and for difficulty D is&lt;br /&gt;
 (0xffff * 2**208)/D&lt;br /&gt;
&lt;br /&gt;
The expected number of hashes we need to calculate to find a block with difficulty D is therefore&lt;br /&gt;
 D * 2**256 / (0xffff * 2**208)&lt;br /&gt;
or just&lt;br /&gt;
 D * 2**48 / 0xffff&lt;br /&gt;
&lt;br /&gt;
The difficulty is set such that the previous 2016 blocks would have been found at the rate of one every 10 minutes, so we were calculating (D * 2**48 / 0xffff) hashes in 600 seconds.  That means the hash rate of the network was&lt;br /&gt;
 D * 2**48 / 0xffff / 600&lt;br /&gt;
over the previous 2016 blocks.  Can be further simplified to&lt;br /&gt;
 D * 2**32 / 600&lt;br /&gt;
without much loss of accuracy.&lt;br /&gt;
&lt;br /&gt;
At difficulty 1, that is around 7 Mhashes per second.&lt;br /&gt;
&lt;br /&gt;
At the time of writing, the difficulty is 22012.4941572, which means that over the previous set of 2016 blocks found the average network hash rate was&lt;br /&gt;
 22012.4941572 * 2**32 / 600 = around 157 Ghashes per second.&lt;br /&gt;
&lt;br /&gt;
==Related Links==&lt;br /&gt;
&lt;br /&gt;
* See also: [[Target]]&lt;br /&gt;
&lt;br /&gt;
==Attribution==&lt;br /&gt;
This content is based on content sourced from https://en.bitcoin.it/wiki/Difficulty under [https://creativecommons.org/licenses/by/3.0/ Creative Commons Attribution 3.0]. Although it may have been extensively revised and updated we acknowledge the original authors.&lt;/div&gt;</summary>
		<author><name>Angus Adams</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.bitcoinsv.io/index.php?title=Target&amp;diff=2262</id>
		<title>Target</title>
		<link rel="alternate" type="text/html" href="https://wiki.bitcoinsv.io/index.php?title=Target&amp;diff=2262"/>
		<updated>2020-02-19T15:22:39Z</updated>

		<summary type="html">&lt;p&gt;Angus Adams: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The '''target''' is a 256-bit number that all Bitcoin clients share. The double SHA-256 [https://wiki.bitcoinsv.io/index.php/Mining#Hashing hash] of a [[Block hashing algorithm|block's header]] must be less than or equal to the current target for the block to be accepted by the network. The lower the target, the more [[difficulty|difficult]] it is to generate a block.&lt;br /&gt;
&lt;br /&gt;
It's important to realize that block generation is not a long, set problem (like doing a million hashes), but more like a lottery. Each hash is a random number between 0 and the maximum value of a 256-bit number (2^256-1). If a hash is below the target, the node wins. If not, you increment the nonce (completely changing the hash) and try again. &lt;br /&gt;
&lt;br /&gt;
The Bitcoin network tries to produce one block every ten minutes on average. As mining hash power changes over time, it achieves this through changing the target value.&lt;br /&gt;
&lt;br /&gt;
Historically (prior to forking from BTC in August 2017), Bitcoin changed its target every 2016 blocks (exactly two weeks if a block time of 10 minutes was kept perfectly). This change in the target is known as a 'difficulty adjustment'. Under the original difficulty adjustment paradigm, when adjusting the target, every Bitcoin client compared the actual time it took to generate 2016 blocks with the two week goal, and modified the target by the percentage difference. A single retarget never changes the target downwards (increasing difficulty) by more than a factor of 4, or upwards (decreasing difficulty) by more than a factor of 0.75. This prevents large changes in difficulty.&lt;br /&gt;
&lt;br /&gt;
After the hard fork of August 2017, Bitcoin changed the original difficulty adjustment algorithm to what was named the Emergency Difficulty Adjustment (EDA) algorithm. The EDA had the capacity to update the target value every time a new block was found (as opposed to every 2016 blocks), while still targeting a ten minute block time average. The EDA was changed to the Difficulty Adjustment Algorithm (DAA) on 17 November 2017 to address instabilities associated with the EDA. The DAA uses a moving average of the last 144 blocks to determine changes to the target and like the EDA, the target can change every block. A single DAA retarget never changes the target downwards (increasing difficulty) by more than a factor of 2, or upwards (decreasing difficulty) by more than a factor of 2. This sets the maximum bounds for any change in difficulty.&lt;br /&gt;
&lt;br /&gt;
The reason the EDA (and later the DAA) needed to be implemented was because of the creation of the competing BTC network which was expected to garner significantly more hash power than Bitcoin (known as Bitcoin Cash at the time). These measures were put in place so that block production could remain relatively stable due to miners' ability to instantaneously re-allocate hash between the networks.&lt;br /&gt;
&lt;br /&gt;
It is proposed that Bitcoin will move back to the original difficulty adjustment algorithm (still used by Bitcoin Core - BTC) in the future.&lt;br /&gt;
&lt;br /&gt;
===How is the target stored in blocks?===&lt;br /&gt;
Each block stores a packed representation in its block header (called [[Block hashing algorithm|Bits]]) for its actual hexadecimal target. The target can be derived from Bits via a predefined formula. For example, if the packed target in the block is 0x1b0404cb, the hexadecimal target is:&lt;br /&gt;
 0x0404cb * 2**(8*(0x1b - 3)) = 0x00000000000404CB000000000000000000000000000000000000000000000000&lt;br /&gt;
&lt;br /&gt;
Note that the 0x0404cb value is a signed value in this format. The largest legal value for this field is 0x7fffff. To make a larger value you must shift it down one full byte. Also 0x008000 is the smallest positive valid value.&lt;br /&gt;
&lt;br /&gt;
=== What is the current target? ===&lt;br /&gt;
Check the [[Block hashing algorithm|Bits]] field of the most recent block on a [https://whatsonchain.com/ block explorer].&lt;br /&gt;
&lt;br /&gt;
=== What is the maximum target? ===&lt;br /&gt;
The maximum target used by SHA256 mining devices is:&lt;br /&gt;
 0x00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF&lt;br /&gt;
Because Bitcoin stores the target as a floating-point type, this is truncated:&lt;br /&gt;
 0x00000000FFFF0000000000000000000000000000000000000000000000000000&lt;br /&gt;
&lt;br /&gt;
The maximum target is the target used in the [[Genesis block|Genesis Block]] and represents a [[difficulty]] of 1. Its packed representation as [[Block hashing algorithm|Bits]] is 0x1d00ffff.&lt;br /&gt;
&lt;br /&gt;
Since a lower target makes Bitcoin generation more difficult, the maximum target is the ''lowest'' possible [[difficulty]].&lt;br /&gt;
&lt;br /&gt;
==Related Links==&lt;br /&gt;
See also [[Difficulty]]&lt;br /&gt;
&lt;br /&gt;
==Attribution==&lt;br /&gt;
This content is based on content sourced from https://en.bitcoin.it/wiki/Target under [https://creativecommons.org/licenses/by/3.0/ Creative Commons Attribution 3.0]. Although it may have been extensively revised and updated we acknowledge the original authors.&lt;/div&gt;</summary>
		<author><name>Angus Adams</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.bitcoinsv.io/index.php?title=Script&amp;diff=2261</id>
		<title>Script</title>
		<link rel="alternate" type="text/html" href="https://wiki.bitcoinsv.io/index.php?title=Script&amp;diff=2261"/>
		<updated>2020-02-19T14:34:08Z</updated>

		<summary type="html">&lt;p&gt;Angus Adams: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Bitcoin uses a scripting system for [[Bitcoin_Transactions|transactions]]. [[Wikipedia:FORTH|Forth]]-like, '''Script''' is simple, stack-based, and processed from left to right. The script inside transaction outputs is intentionally not [https://en.wikipedia.org/wiki/Turing_completeness Turing-complete] and has no jump instructions to prevent the formation of loops, however with the use of an off-chain agent, turing-complete processes can be built using the ledger as a ticker tape to store computational results.&lt;br /&gt;
&lt;br /&gt;
A transaction output script is a predicate formed by a list of instructions that describe how the next person wanting to transfer the tokens locked in the script must unlock them. The script for a typical P2PKH script to Bitcoin address D simply encumbers future spending of the bitcoins with the provision of two things:&lt;br /&gt;
# a public key that, when hashed, yields destination address D embedded in the script, and&lt;br /&gt;
# a signature to prove ownership of the private key corresponding to the public key just provided.&lt;br /&gt;
&lt;br /&gt;
Scripting provides the flexibility to change the parameters of what's needed to spend transferred bitcoins.  For example, the scripting system could be used to require two private keys, or a combination of several keys, or even no keys at all. The tokens are unlocked if the solution provided by the spending party leaves a non-zero value on the top of the stack when the script terminates.&lt;br /&gt;
&lt;br /&gt;
De facto, Bitcoin script is defined by the code run by the nodes building the [[Block chain]]. Nodes collectively agree on the opcode set that is available for use, and how to process those opcodes. Throughout the history of Bitcoin there have been numerous changes to the way script is processed including the addition of new opcodes and disablement or outright removal of opcodes from the set. &lt;br /&gt;
&lt;br /&gt;
The nodes checking Bitcoin script process transaction inputs in a script evaluation engine. The engine is comprised of three stacks which are:&lt;br /&gt;
* The main stack&lt;br /&gt;
* The alt stack&lt;br /&gt;
&lt;br /&gt;
In addition, the system also uses a subscript management system to track the depth of nested [[Scripts with Flow Control (Conditional Clauses)|If-Loops]]&lt;br /&gt;
&lt;br /&gt;
The main and alt stacks hold byte vectors which can be used by Bitcoin opcodes to process script outcomes. &lt;br /&gt;
When used as numbers, byte vectors are interpreted as little-endian variable-length integers with the most significant bit determining the sign of the integer.&lt;br /&gt;
Thus 0x81 represents -1.&lt;br /&gt;
0x80 is another representation of zero (so called negative 0).&lt;br /&gt;
Positive 0 is represented by a null-length vector.&lt;br /&gt;
Byte vectors are interpreted as Booleans where False is represented by any representation of zero and True is represented by any representation of non-zero.&lt;br /&gt;
&lt;br /&gt;
Before the Genesis upgrade, byte vectors on the stack are not allowed to be more than 520 bytes long however in the unbounded Bitcoin protocol while pushdata opcodes are limited to pushing 4.3GB onto the stack it is theoretically possible to concatenate multiple objects on the stack to form larger singular data items for processing. &lt;br /&gt;
&lt;br /&gt;
Before Genesis, Opcodes which take integers and bools off the stack require that they be no more than 4 bytes long, but addition and subtraction can overflow and result in a 5 byte integer being put on the stack. After the Genesis upgrade in early 2020, miners are now free to mine transactions with data items of any size possible within protocol rules. These will be usable with mathematical functions within script. At this time, Miners will collectively agree on appropriate data limits rather than allowing a centralised committee to form a set of default constraints.&lt;br /&gt;
&lt;br /&gt;
==More on Bitcoin Script==&lt;br /&gt;
#[[Opcodes used in Bitcoin Script]]&lt;br /&gt;
#[[Number Encoding in Bitcoin Script]]&lt;br /&gt;
#[[Scripts with Flow Control (Conditional Clauses)]]&lt;br /&gt;
#[[Data passing in inputs]]&lt;br /&gt;
#[[OP_CODESEPARATOR]]&lt;br /&gt;
#[[OP_RETURN]]&lt;br /&gt;
#[[OP_VER]]&lt;br /&gt;
#[[Complex Script Examples]]&lt;br /&gt;
&lt;br /&gt;
==Attribution==&lt;br /&gt;
This content is based on content sourced from https://en.bitcoin.it/wiki/Script under [https://creativecommons.org/licenses/by/3.0/ Creative Commons Attribution 3.0]. Although it may have been extensively revised and updated we acknowledge the original authors.&lt;/div&gt;</summary>
		<author><name>Angus Adams</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.bitcoinsv.io/index.php?title=Difficulty&amp;diff=2259</id>
		<title>Difficulty</title>
		<link rel="alternate" type="text/html" href="https://wiki.bitcoinsv.io/index.php?title=Difficulty&amp;diff=2259"/>
		<updated>2020-02-19T14:26:53Z</updated>

		<summary type="html">&lt;p&gt;Angus Adams: /* What is the maximum difficulty? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;''See also: [[Target]]''&lt;br /&gt;
&lt;br /&gt;
=== What is difficulty? ===&lt;br /&gt;
&lt;br /&gt;
Difficulty is a measure of how difficult it is to find a hash below a given [[target]]. Difficulty answers the question: &amp;quot;how many times more difficult is it to mine a block now, compared with how difficult it was to mine the [[Genesis block|Genesis Block]]?&amp;quot;. It has a close relationship with target but is not the same thing. Rather it has an inverse relationship where a higher difficulty implies a lower target value.&lt;br /&gt;
&lt;br /&gt;
The Bitcoin network has a global block difficulty. Valid blocks must have a hash below this target.&lt;br /&gt;
Mining pools also have a pool-specific share difficulty setting a lower limit for shares.&lt;br /&gt;
&lt;br /&gt;
=== How often does the network difficulty change? ===&lt;br /&gt;
&lt;br /&gt;
See [[Target|target]].&lt;br /&gt;
&lt;br /&gt;
=== What is the formula for difficulty? ===&lt;br /&gt;
difficulty = difficulty_1_target / current_target &lt;br /&gt;
&lt;br /&gt;
''target is a 256 bit number''&lt;br /&gt;
&lt;br /&gt;
''difficulty_1_target is the target used in the Genesis Block and represents a difficulty of 1.''&lt;br /&gt;
&lt;br /&gt;
difficulty_1_target can be different for various ways to measure difficulty.&lt;br /&gt;
Traditionally, it represents a hash where the leading 32 bits are zero and the rest are one (this is known as &amp;quot;pool difficulty&amp;quot; or &amp;quot;pdiff&amp;quot;).&lt;br /&gt;
The Bitcoin protocol represents targets as a custom floating point type with limited precision; as a result, Bitcoin clients often approximate difficulty based on this (this is known as &amp;quot;bdiff&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
===How is difficulty stored in blocks?===&lt;br /&gt;
&lt;br /&gt;
Each block stores a packed representation in its block header (called [[Block hashing algorithm|Bits]]) for its actual hexadecimal [[target]]. The target can be derived from Bits via a predefined formula. For example, if the packed target in the block is 0x1b0404cb, the hexadecimal target is:&lt;br /&gt;
 0x0404cb * 2**(8*(0x1b - 3)) = 0x00000000000404CB000000000000000000000000000000000000000000000000&lt;br /&gt;
&lt;br /&gt;
Note that the 0x0404cb value is a signed value in this format. The largest legal value for this field is 0x7fffff. To make a larger value you must shift it down one full byte. Also 0x008000 is the smallest positive valid value.&lt;br /&gt;
&lt;br /&gt;
===How is difficulty calculated? What is the difference between bdiff and pdiff?===&lt;br /&gt;
&lt;br /&gt;
The highest possible target (difficulty 1) is defined as 0x1d00ffff, which gives us a hex target of&lt;br /&gt;
 0x00ffff * 2**(8*(0x1d - 3)) = 0x00000000FFFF0000000000000000000000000000000000000000000000000000&lt;br /&gt;
&lt;br /&gt;
It should be noted that pooled mining often uses non-truncated targets, which puts &amp;quot;pool difficulty 1&amp;quot; at&lt;br /&gt;
 0x00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF&lt;br /&gt;
&lt;br /&gt;
So the difficulty at 0x1b0404cb is therefore:&lt;br /&gt;
 0x00000000FFFF0000000000000000000000000000000000000000000000000000 /&lt;br /&gt;
 0x00000000000404CB000000000000000000000000000000000000000000000000 &lt;br /&gt;
 = 16307.420938523983 (bdiff)&lt;br /&gt;
And:&lt;br /&gt;
 0x00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF /&lt;br /&gt;
 0x00000000000404CB000000000000000000000000000000000000000000000000 &lt;br /&gt;
 = 16307.669773817162 (pdiff)&lt;br /&gt;
&lt;br /&gt;
Here's a fast way to calculate Bitcoin difficulty. It uses a modified Taylor series for the logarithm (you can see tutorials on flipcode and wikipedia) and relies on logs to transform the difficulty calculation:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;cmath&amp;gt;&lt;br /&gt;
&lt;br /&gt;
inline float fast_log(float val)&lt;br /&gt;
{&lt;br /&gt;
   int * const exp_ptr = reinterpret_cast &amp;lt;int *&amp;gt;(&amp;amp;val);&lt;br /&gt;
   int x = *exp_ptr;&lt;br /&gt;
   const int log_2 = ((x &amp;gt;&amp;gt; 23) &amp;amp; 255) - 128;&lt;br /&gt;
   x &amp;amp;= ~(255 &amp;lt;&amp;lt; 23);&lt;br /&gt;
   x += 127 &amp;lt;&amp;lt; 23;&lt;br /&gt;
   *exp_ptr = x;&lt;br /&gt;
&lt;br /&gt;
   val = ((-1.0f/3) * val + 2) * val - 2.0f/3;&lt;br /&gt;
   return ((val + log_2) * 0.69314718f);&lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
float difficulty(unsigned int bits)&lt;br /&gt;
{&lt;br /&gt;
    static double max_body = fast_log(0x00ffff), scaland = fast_log(256);&lt;br /&gt;
    return exp(max_body - fast_log(bits &amp;amp; 0x00ffffff) + scaland * (0x1d - ((bits &amp;amp; 0xff000000) &amp;gt;&amp;gt; 24)));&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
    std::cout &amp;lt;&amp;lt; difficulty(0x1b0404cb) &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To see the math to go from the normal difficulty calculations (which require large big ints bigger than the space in any normal integer) to the calculation above, here's some python:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import decimal, math&lt;br /&gt;
l = math.log&lt;br /&gt;
e = math.e&lt;br /&gt;
&lt;br /&gt;
print 0x00ffff * 2**(8*(0x1d - 3)) / float(0x0404cb * 2**(8*(0x1b - 3)))&lt;br /&gt;
print l(0x00ffff * 2**(8*(0x1d - 3)) / float(0x0404cb * 2**(8*(0x1b - 3))))&lt;br /&gt;
print l(0x00ffff * 2**(8*(0x1d - 3))) - l(0x0404cb * 2**(8*(0x1b - 3)))&lt;br /&gt;
print l(0x00ffff) + l(2**(8*(0x1d - 3))) - l(0x0404cb) - l(2**(8*(0x1b - 3)))&lt;br /&gt;
print l(0x00ffff) + (8*(0x1d - 3))*l(2) - l(0x0404cb) - (8*(0x1b - 3))*l(2)&lt;br /&gt;
print l(0x00ffff / float(0x0404cb)) + (8*(0x1d - 3))*l(2) - (8*(0x1b - 3))*l(2)&lt;br /&gt;
print l(0x00ffff / float(0x0404cb)) + (0x1d - 0x1b)*l(2**8)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== What is the current difficulty? ===&lt;br /&gt;
[https://whatsonchain.com/ Current difficulty]&lt;br /&gt;
&lt;br /&gt;
=== What is the maximum difficulty? ===&lt;br /&gt;
&lt;br /&gt;
There is no minimum target. The maximum difficulty is roughly: maximum_target / 1 (since 0 would result in infinity), which is a ridiculously huge number (about 2^224).&lt;br /&gt;
&lt;br /&gt;
The actual maximum difficulty is when current_target=0, but we would not be able to calculate the difficulty if that happened. (fortunately it never will, so we're ok.)&lt;br /&gt;
&lt;br /&gt;
In the original implementation, still used by BTC, the difficulty can rise by a maximum of 400% of the current difficulty in a single adjustment.&lt;br /&gt;
&lt;br /&gt;
In the case of Bitcoin (BSV) and Bitcoin Cash (BCH), the network's difficulty can rise by a maximum of 100% of the current difficulty in a single adjustment.&lt;br /&gt;
&lt;br /&gt;
=== Can the network difficulty decrease? ===&lt;br /&gt;
Yes it can. See discussion in [[target]]. &lt;br /&gt;
&lt;br /&gt;
In the case of Bitcoin (BSV) and Bitcoin Cash (BCH), the network's difficulty can adjust downwards by up to 50% of the current difficulty in a single adjustment.&lt;br /&gt;
&lt;br /&gt;
In the original implementation, still used by BTC, the network's difficulty can adjust downwards by up to 75% of the current difficulty in a single adjustment.&lt;br /&gt;
&lt;br /&gt;
=== What is the minimum difficulty? ===&lt;br /&gt;
The minimum difficulty, when the target is at the maximum allowed value, is 1. This is the difficulty of the [[Genesis block]].&lt;br /&gt;
&lt;br /&gt;
=== What network hash rate results in a given difficulty? ===&lt;br /&gt;
The difficulty is adjusted every 2016 blocks based on the [[Block_timestamp|time]] it took to find the previous 2016 blocks.  At the desired rate of one block each 10 minutes, 2016 blocks would take exactly two weeks to find.  If the previous 2016 blocks took more than two weeks to find, the difficulty is reduced.  If they took less than two weeks, the difficulty is increased.  The change in difficulty is in proportion to the amount of time over or under two weeks the previous 2016 blocks took to find.&lt;br /&gt;
&lt;br /&gt;
To find a block, the hash must be less than the target.  The hash is effectively a random number between 0 and 2**256-1.  The offset for difficulty 1 is&lt;br /&gt;
 0xffff * 2**208&lt;br /&gt;
and for difficulty D is&lt;br /&gt;
 (0xffff * 2**208)/D&lt;br /&gt;
&lt;br /&gt;
The expected number of hashes we need to calculate to find a block with difficulty D is therefore&lt;br /&gt;
 D * 2**256 / (0xffff * 2**208)&lt;br /&gt;
or just&lt;br /&gt;
 D * 2**48 / 0xffff&lt;br /&gt;
&lt;br /&gt;
The difficulty is set such that the previous 2016 blocks would have been found at the rate of one every 10 minutes, so we were calculating (D * 2**48 / 0xffff) hashes in 600 seconds.  That means the hash rate of the network was&lt;br /&gt;
 D * 2**48 / 0xffff / 600&lt;br /&gt;
over the previous 2016 blocks.  Can be further simplified to&lt;br /&gt;
 D * 2**32 / 600&lt;br /&gt;
without much loss of accuracy.&lt;br /&gt;
&lt;br /&gt;
At difficulty 1, that is around 7 Mhashes per second.&lt;br /&gt;
&lt;br /&gt;
At the time of writing, the difficulty is 22012.4941572, which means that over the previous set of 2016 blocks found the average network hash rate was&lt;br /&gt;
 22012.4941572 * 2**32 / 600 = around 157 Ghashes per second.&lt;br /&gt;
&lt;br /&gt;
==Related Links==&lt;br /&gt;
&lt;br /&gt;
* See also: [[Target]]&lt;br /&gt;
&lt;br /&gt;
==Attribution==&lt;br /&gt;
This content is based on content sourced from https://en.bitcoin.it/wiki/Difficulty under [https://creativecommons.org/licenses/by/3.0/ Creative Commons Attribution 3.0]. Although it may have been extensively revised and updated we acknowledge the original authors.&lt;/div&gt;</summary>
		<author><name>Angus Adams</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.bitcoinsv.io/index.php?title=Difficulty&amp;diff=2258</id>
		<title>Difficulty</title>
		<link rel="alternate" type="text/html" href="https://wiki.bitcoinsv.io/index.php?title=Difficulty&amp;diff=2258"/>
		<updated>2020-02-19T14:24:34Z</updated>

		<summary type="html">&lt;p&gt;Angus Adams: /* Can the network difficulty decrease? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;''See also: [[Target]]''&lt;br /&gt;
&lt;br /&gt;
=== What is difficulty? ===&lt;br /&gt;
&lt;br /&gt;
Difficulty is a measure of how difficult it is to find a hash below a given [[target]]. Difficulty answers the question: &amp;quot;how many times more difficult is it to mine a block now, compared with how difficult it was to mine the [[Genesis block|Genesis Block]]?&amp;quot;. It has a close relationship with target but is not the same thing. Rather it has an inverse relationship where a higher difficulty implies a lower target value.&lt;br /&gt;
&lt;br /&gt;
The Bitcoin network has a global block difficulty. Valid blocks must have a hash below this target.&lt;br /&gt;
Mining pools also have a pool-specific share difficulty setting a lower limit for shares.&lt;br /&gt;
&lt;br /&gt;
=== How often does the network difficulty change? ===&lt;br /&gt;
&lt;br /&gt;
See [[Target|target]].&lt;br /&gt;
&lt;br /&gt;
=== What is the formula for difficulty? ===&lt;br /&gt;
difficulty = difficulty_1_target / current_target &lt;br /&gt;
&lt;br /&gt;
''target is a 256 bit number''&lt;br /&gt;
&lt;br /&gt;
''difficulty_1_target is the target used in the Genesis Block and represents a difficulty of 1.''&lt;br /&gt;
&lt;br /&gt;
difficulty_1_target can be different for various ways to measure difficulty.&lt;br /&gt;
Traditionally, it represents a hash where the leading 32 bits are zero and the rest are one (this is known as &amp;quot;pool difficulty&amp;quot; or &amp;quot;pdiff&amp;quot;).&lt;br /&gt;
The Bitcoin protocol represents targets as a custom floating point type with limited precision; as a result, Bitcoin clients often approximate difficulty based on this (this is known as &amp;quot;bdiff&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
===How is difficulty stored in blocks?===&lt;br /&gt;
&lt;br /&gt;
Each block stores a packed representation in its block header (called [[Block hashing algorithm|Bits]]) for its actual hexadecimal [[target]]. The target can be derived from Bits via a predefined formula. For example, if the packed target in the block is 0x1b0404cb, the hexadecimal target is:&lt;br /&gt;
 0x0404cb * 2**(8*(0x1b - 3)) = 0x00000000000404CB000000000000000000000000000000000000000000000000&lt;br /&gt;
&lt;br /&gt;
Note that the 0x0404cb value is a signed value in this format. The largest legal value for this field is 0x7fffff. To make a larger value you must shift it down one full byte. Also 0x008000 is the smallest positive valid value.&lt;br /&gt;
&lt;br /&gt;
===How is difficulty calculated? What is the difference between bdiff and pdiff?===&lt;br /&gt;
&lt;br /&gt;
The highest possible target (difficulty 1) is defined as 0x1d00ffff, which gives us a hex target of&lt;br /&gt;
 0x00ffff * 2**(8*(0x1d - 3)) = 0x00000000FFFF0000000000000000000000000000000000000000000000000000&lt;br /&gt;
&lt;br /&gt;
It should be noted that pooled mining often uses non-truncated targets, which puts &amp;quot;pool difficulty 1&amp;quot; at&lt;br /&gt;
 0x00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF&lt;br /&gt;
&lt;br /&gt;
So the difficulty at 0x1b0404cb is therefore:&lt;br /&gt;
 0x00000000FFFF0000000000000000000000000000000000000000000000000000 /&lt;br /&gt;
 0x00000000000404CB000000000000000000000000000000000000000000000000 &lt;br /&gt;
 = 16307.420938523983 (bdiff)&lt;br /&gt;
And:&lt;br /&gt;
 0x00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF /&lt;br /&gt;
 0x00000000000404CB000000000000000000000000000000000000000000000000 &lt;br /&gt;
 = 16307.669773817162 (pdiff)&lt;br /&gt;
&lt;br /&gt;
Here's a fast way to calculate Bitcoin difficulty. It uses a modified Taylor series for the logarithm (you can see tutorials on flipcode and wikipedia) and relies on logs to transform the difficulty calculation:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;cmath&amp;gt;&lt;br /&gt;
&lt;br /&gt;
inline float fast_log(float val)&lt;br /&gt;
{&lt;br /&gt;
   int * const exp_ptr = reinterpret_cast &amp;lt;int *&amp;gt;(&amp;amp;val);&lt;br /&gt;
   int x = *exp_ptr;&lt;br /&gt;
   const int log_2 = ((x &amp;gt;&amp;gt; 23) &amp;amp; 255) - 128;&lt;br /&gt;
   x &amp;amp;= ~(255 &amp;lt;&amp;lt; 23);&lt;br /&gt;
   x += 127 &amp;lt;&amp;lt; 23;&lt;br /&gt;
   *exp_ptr = x;&lt;br /&gt;
&lt;br /&gt;
   val = ((-1.0f/3) * val + 2) * val - 2.0f/3;&lt;br /&gt;
   return ((val + log_2) * 0.69314718f);&lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
float difficulty(unsigned int bits)&lt;br /&gt;
{&lt;br /&gt;
    static double max_body = fast_log(0x00ffff), scaland = fast_log(256);&lt;br /&gt;
    return exp(max_body - fast_log(bits &amp;amp; 0x00ffffff) + scaland * (0x1d - ((bits &amp;amp; 0xff000000) &amp;gt;&amp;gt; 24)));&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
    std::cout &amp;lt;&amp;lt; difficulty(0x1b0404cb) &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To see the math to go from the normal difficulty calculations (which require large big ints bigger than the space in any normal integer) to the calculation above, here's some python:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import decimal, math&lt;br /&gt;
l = math.log&lt;br /&gt;
e = math.e&lt;br /&gt;
&lt;br /&gt;
print 0x00ffff * 2**(8*(0x1d - 3)) / float(0x0404cb * 2**(8*(0x1b - 3)))&lt;br /&gt;
print l(0x00ffff * 2**(8*(0x1d - 3)) / float(0x0404cb * 2**(8*(0x1b - 3))))&lt;br /&gt;
print l(0x00ffff * 2**(8*(0x1d - 3))) - l(0x0404cb * 2**(8*(0x1b - 3)))&lt;br /&gt;
print l(0x00ffff) + l(2**(8*(0x1d - 3))) - l(0x0404cb) - l(2**(8*(0x1b - 3)))&lt;br /&gt;
print l(0x00ffff) + (8*(0x1d - 3))*l(2) - l(0x0404cb) - (8*(0x1b - 3))*l(2)&lt;br /&gt;
print l(0x00ffff / float(0x0404cb)) + (8*(0x1d - 3))*l(2) - (8*(0x1b - 3))*l(2)&lt;br /&gt;
print l(0x00ffff / float(0x0404cb)) + (0x1d - 0x1b)*l(2**8)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== What is the current difficulty? ===&lt;br /&gt;
[https://whatsonchain.com/ Current difficulty]&lt;br /&gt;
&lt;br /&gt;
=== What is the maximum difficulty? ===&lt;br /&gt;
&lt;br /&gt;
There is no minimum target. The maximum difficulty is roughly: maximum_target / 1 (since 0 would result in infinity), which is a ridiculously huge number (about 2^224).&lt;br /&gt;
&lt;br /&gt;
The actual maximum difficulty is when current_target=0, but we would not be able to calculate the difficulty if that happened. (fortunately it never will, so we're ok.)&lt;br /&gt;
&lt;br /&gt;
The difficulty can rise by a maximum of 400% of the current difficulty, or by a factor of 4 in a single adjustment.&lt;br /&gt;
&lt;br /&gt;
=== Can the network difficulty decrease? ===&lt;br /&gt;
Yes it can. See discussion in [[target]]. &lt;br /&gt;
&lt;br /&gt;
In the case of Bitcoin (BSV) and Bitcoin Cash (BCH), the network's difficulty can adjust downwards by up to 50% of the current difficulty in a single adjustment.&lt;br /&gt;
&lt;br /&gt;
In the original implementation, still used by BTC, the network's difficulty can adjust downwards by up to 75% of the current difficulty in a single adjustment.&lt;br /&gt;
&lt;br /&gt;
=== What is the minimum difficulty? ===&lt;br /&gt;
The minimum difficulty, when the target is at the maximum allowed value, is 1. This is the difficulty of the [[Genesis block]].&lt;br /&gt;
&lt;br /&gt;
=== What network hash rate results in a given difficulty? ===&lt;br /&gt;
The difficulty is adjusted every 2016 blocks based on the [[Block_timestamp|time]] it took to find the previous 2016 blocks.  At the desired rate of one block each 10 minutes, 2016 blocks would take exactly two weeks to find.  If the previous 2016 blocks took more than two weeks to find, the difficulty is reduced.  If they took less than two weeks, the difficulty is increased.  The change in difficulty is in proportion to the amount of time over or under two weeks the previous 2016 blocks took to find.&lt;br /&gt;
&lt;br /&gt;
To find a block, the hash must be less than the target.  The hash is effectively a random number between 0 and 2**256-1.  The offset for difficulty 1 is&lt;br /&gt;
 0xffff * 2**208&lt;br /&gt;
and for difficulty D is&lt;br /&gt;
 (0xffff * 2**208)/D&lt;br /&gt;
&lt;br /&gt;
The expected number of hashes we need to calculate to find a block with difficulty D is therefore&lt;br /&gt;
 D * 2**256 / (0xffff * 2**208)&lt;br /&gt;
or just&lt;br /&gt;
 D * 2**48 / 0xffff&lt;br /&gt;
&lt;br /&gt;
The difficulty is set such that the previous 2016 blocks would have been found at the rate of one every 10 minutes, so we were calculating (D * 2**48 / 0xffff) hashes in 600 seconds.  That means the hash rate of the network was&lt;br /&gt;
 D * 2**48 / 0xffff / 600&lt;br /&gt;
over the previous 2016 blocks.  Can be further simplified to&lt;br /&gt;
 D * 2**32 / 600&lt;br /&gt;
without much loss of accuracy.&lt;br /&gt;
&lt;br /&gt;
At difficulty 1, that is around 7 Mhashes per second.&lt;br /&gt;
&lt;br /&gt;
At the time of writing, the difficulty is 22012.4941572, which means that over the previous set of 2016 blocks found the average network hash rate was&lt;br /&gt;
 22012.4941572 * 2**32 / 600 = around 157 Ghashes per second.&lt;br /&gt;
&lt;br /&gt;
==Related Links==&lt;br /&gt;
&lt;br /&gt;
* See also: [[Target]]&lt;br /&gt;
&lt;br /&gt;
==Attribution==&lt;br /&gt;
This content is based on content sourced from https://en.bitcoin.it/wiki/Difficulty under [https://creativecommons.org/licenses/by/3.0/ Creative Commons Attribution 3.0]. Although it may have been extensively revised and updated we acknowledge the original authors.&lt;/div&gt;</summary>
		<author><name>Angus Adams</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.bitcoinsv.io/index.php?title=Difficulty&amp;diff=2257</id>
		<title>Difficulty</title>
		<link rel="alternate" type="text/html" href="https://wiki.bitcoinsv.io/index.php?title=Difficulty&amp;diff=2257"/>
		<updated>2020-02-19T14:21:58Z</updated>

		<summary type="html">&lt;p&gt;Angus Adams: /* Can the network difficulty decrease? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;''See also: [[Target]]''&lt;br /&gt;
&lt;br /&gt;
=== What is difficulty? ===&lt;br /&gt;
&lt;br /&gt;
Difficulty is a measure of how difficult it is to find a hash below a given [[target]]. Difficulty answers the question: &amp;quot;how many times more difficult is it to mine a block now, compared with how difficult it was to mine the [[Genesis block|Genesis Block]]?&amp;quot;. It has a close relationship with target but is not the same thing. Rather it has an inverse relationship where a higher difficulty implies a lower target value.&lt;br /&gt;
&lt;br /&gt;
The Bitcoin network has a global block difficulty. Valid blocks must have a hash below this target.&lt;br /&gt;
Mining pools also have a pool-specific share difficulty setting a lower limit for shares.&lt;br /&gt;
&lt;br /&gt;
=== How often does the network difficulty change? ===&lt;br /&gt;
&lt;br /&gt;
See [[Target|target]].&lt;br /&gt;
&lt;br /&gt;
=== What is the formula for difficulty? ===&lt;br /&gt;
difficulty = difficulty_1_target / current_target &lt;br /&gt;
&lt;br /&gt;
''target is a 256 bit number''&lt;br /&gt;
&lt;br /&gt;
''difficulty_1_target is the target used in the Genesis Block and represents a difficulty of 1.''&lt;br /&gt;
&lt;br /&gt;
difficulty_1_target can be different for various ways to measure difficulty.&lt;br /&gt;
Traditionally, it represents a hash where the leading 32 bits are zero and the rest are one (this is known as &amp;quot;pool difficulty&amp;quot; or &amp;quot;pdiff&amp;quot;).&lt;br /&gt;
The Bitcoin protocol represents targets as a custom floating point type with limited precision; as a result, Bitcoin clients often approximate difficulty based on this (this is known as &amp;quot;bdiff&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
===How is difficulty stored in blocks?===&lt;br /&gt;
&lt;br /&gt;
Each block stores a packed representation in its block header (called [[Block hashing algorithm|Bits]]) for its actual hexadecimal [[target]]. The target can be derived from Bits via a predefined formula. For example, if the packed target in the block is 0x1b0404cb, the hexadecimal target is:&lt;br /&gt;
 0x0404cb * 2**(8*(0x1b - 3)) = 0x00000000000404CB000000000000000000000000000000000000000000000000&lt;br /&gt;
&lt;br /&gt;
Note that the 0x0404cb value is a signed value in this format. The largest legal value for this field is 0x7fffff. To make a larger value you must shift it down one full byte. Also 0x008000 is the smallest positive valid value.&lt;br /&gt;
&lt;br /&gt;
===How is difficulty calculated? What is the difference between bdiff and pdiff?===&lt;br /&gt;
&lt;br /&gt;
The highest possible target (difficulty 1) is defined as 0x1d00ffff, which gives us a hex target of&lt;br /&gt;
 0x00ffff * 2**(8*(0x1d - 3)) = 0x00000000FFFF0000000000000000000000000000000000000000000000000000&lt;br /&gt;
&lt;br /&gt;
It should be noted that pooled mining often uses non-truncated targets, which puts &amp;quot;pool difficulty 1&amp;quot; at&lt;br /&gt;
 0x00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF&lt;br /&gt;
&lt;br /&gt;
So the difficulty at 0x1b0404cb is therefore:&lt;br /&gt;
 0x00000000FFFF0000000000000000000000000000000000000000000000000000 /&lt;br /&gt;
 0x00000000000404CB000000000000000000000000000000000000000000000000 &lt;br /&gt;
 = 16307.420938523983 (bdiff)&lt;br /&gt;
And:&lt;br /&gt;
 0x00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF /&lt;br /&gt;
 0x00000000000404CB000000000000000000000000000000000000000000000000 &lt;br /&gt;
 = 16307.669773817162 (pdiff)&lt;br /&gt;
&lt;br /&gt;
Here's a fast way to calculate Bitcoin difficulty. It uses a modified Taylor series for the logarithm (you can see tutorials on flipcode and wikipedia) and relies on logs to transform the difficulty calculation:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;cmath&amp;gt;&lt;br /&gt;
&lt;br /&gt;
inline float fast_log(float val)&lt;br /&gt;
{&lt;br /&gt;
   int * const exp_ptr = reinterpret_cast &amp;lt;int *&amp;gt;(&amp;amp;val);&lt;br /&gt;
   int x = *exp_ptr;&lt;br /&gt;
   const int log_2 = ((x &amp;gt;&amp;gt; 23) &amp;amp; 255) - 128;&lt;br /&gt;
   x &amp;amp;= ~(255 &amp;lt;&amp;lt; 23);&lt;br /&gt;
   x += 127 &amp;lt;&amp;lt; 23;&lt;br /&gt;
   *exp_ptr = x;&lt;br /&gt;
&lt;br /&gt;
   val = ((-1.0f/3) * val + 2) * val - 2.0f/3;&lt;br /&gt;
   return ((val + log_2) * 0.69314718f);&lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
float difficulty(unsigned int bits)&lt;br /&gt;
{&lt;br /&gt;
    static double max_body = fast_log(0x00ffff), scaland = fast_log(256);&lt;br /&gt;
    return exp(max_body - fast_log(bits &amp;amp; 0x00ffffff) + scaland * (0x1d - ((bits &amp;amp; 0xff000000) &amp;gt;&amp;gt; 24)));&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
    std::cout &amp;lt;&amp;lt; difficulty(0x1b0404cb) &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To see the math to go from the normal difficulty calculations (which require large big ints bigger than the space in any normal integer) to the calculation above, here's some python:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import decimal, math&lt;br /&gt;
l = math.log&lt;br /&gt;
e = math.e&lt;br /&gt;
&lt;br /&gt;
print 0x00ffff * 2**(8*(0x1d - 3)) / float(0x0404cb * 2**(8*(0x1b - 3)))&lt;br /&gt;
print l(0x00ffff * 2**(8*(0x1d - 3)) / float(0x0404cb * 2**(8*(0x1b - 3))))&lt;br /&gt;
print l(0x00ffff * 2**(8*(0x1d - 3))) - l(0x0404cb * 2**(8*(0x1b - 3)))&lt;br /&gt;
print l(0x00ffff) + l(2**(8*(0x1d - 3))) - l(0x0404cb) - l(2**(8*(0x1b - 3)))&lt;br /&gt;
print l(0x00ffff) + (8*(0x1d - 3))*l(2) - l(0x0404cb) - (8*(0x1b - 3))*l(2)&lt;br /&gt;
print l(0x00ffff / float(0x0404cb)) + (8*(0x1d - 3))*l(2) - (8*(0x1b - 3))*l(2)&lt;br /&gt;
print l(0x00ffff / float(0x0404cb)) + (0x1d - 0x1b)*l(2**8)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== What is the current difficulty? ===&lt;br /&gt;
[https://whatsonchain.com/ Current difficulty]&lt;br /&gt;
&lt;br /&gt;
=== What is the maximum difficulty? ===&lt;br /&gt;
&lt;br /&gt;
There is no minimum target. The maximum difficulty is roughly: maximum_target / 1 (since 0 would result in infinity), which is a ridiculously huge number (about 2^224).&lt;br /&gt;
&lt;br /&gt;
The actual maximum difficulty is when current_target=0, but we would not be able to calculate the difficulty if that happened. (fortunately it never will, so we're ok.)&lt;br /&gt;
&lt;br /&gt;
The difficulty can rise by a maximum of 400% of the current difficulty, or by a factor of 4 in a single adjustment.&lt;br /&gt;
&lt;br /&gt;
=== Can the network difficulty decrease? ===&lt;br /&gt;
Yes it can. See discussion in [[target]]. &lt;br /&gt;
&lt;br /&gt;
In the original implementation, still used by BTC, the network's difficulty can adjust downwards by up to 75% of the current difficulty in a single adjustment.&lt;br /&gt;
&lt;br /&gt;
=== What is the minimum difficulty? ===&lt;br /&gt;
The minimum difficulty, when the target is at the maximum allowed value, is 1. This is the difficulty of the [[Genesis block]].&lt;br /&gt;
&lt;br /&gt;
=== What network hash rate results in a given difficulty? ===&lt;br /&gt;
The difficulty is adjusted every 2016 blocks based on the [[Block_timestamp|time]] it took to find the previous 2016 blocks.  At the desired rate of one block each 10 minutes, 2016 blocks would take exactly two weeks to find.  If the previous 2016 blocks took more than two weeks to find, the difficulty is reduced.  If they took less than two weeks, the difficulty is increased.  The change in difficulty is in proportion to the amount of time over or under two weeks the previous 2016 blocks took to find.&lt;br /&gt;
&lt;br /&gt;
To find a block, the hash must be less than the target.  The hash is effectively a random number between 0 and 2**256-1.  The offset for difficulty 1 is&lt;br /&gt;
 0xffff * 2**208&lt;br /&gt;
and for difficulty D is&lt;br /&gt;
 (0xffff * 2**208)/D&lt;br /&gt;
&lt;br /&gt;
The expected number of hashes we need to calculate to find a block with difficulty D is therefore&lt;br /&gt;
 D * 2**256 / (0xffff * 2**208)&lt;br /&gt;
or just&lt;br /&gt;
 D * 2**48 / 0xffff&lt;br /&gt;
&lt;br /&gt;
The difficulty is set such that the previous 2016 blocks would have been found at the rate of one every 10 minutes, so we were calculating (D * 2**48 / 0xffff) hashes in 600 seconds.  That means the hash rate of the network was&lt;br /&gt;
 D * 2**48 / 0xffff / 600&lt;br /&gt;
over the previous 2016 blocks.  Can be further simplified to&lt;br /&gt;
 D * 2**32 / 600&lt;br /&gt;
without much loss of accuracy.&lt;br /&gt;
&lt;br /&gt;
At difficulty 1, that is around 7 Mhashes per second.&lt;br /&gt;
&lt;br /&gt;
At the time of writing, the difficulty is 22012.4941572, which means that over the previous set of 2016 blocks found the average network hash rate was&lt;br /&gt;
 22012.4941572 * 2**32 / 600 = around 157 Ghashes per second.&lt;br /&gt;
&lt;br /&gt;
==Related Links==&lt;br /&gt;
&lt;br /&gt;
* See also: [[Target]]&lt;br /&gt;
&lt;br /&gt;
==Attribution==&lt;br /&gt;
This content is based on content sourced from https://en.bitcoin.it/wiki/Difficulty under [https://creativecommons.org/licenses/by/3.0/ Creative Commons Attribution 3.0]. Although it may have been extensively revised and updated we acknowledge the original authors.&lt;/div&gt;</summary>
		<author><name>Angus Adams</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.bitcoinsv.io/index.php?title=Target&amp;diff=2256</id>
		<title>Target</title>
		<link rel="alternate" type="text/html" href="https://wiki.bitcoinsv.io/index.php?title=Target&amp;diff=2256"/>
		<updated>2020-02-19T14:19:58Z</updated>

		<summary type="html">&lt;p&gt;Angus Adams: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The '''target''' is a 256-bit number that all Bitcoin clients share. The double SHA-256 [https://wiki.bitcoinsv.io/index.php/Mining#Hashing hash] of a [[Block hashing algorithm|block's header]] must be less than or equal to the current target for the block to be accepted by the network. The lower the target, the more [[difficulty|difficult]] it is to generate a block.&lt;br /&gt;
&lt;br /&gt;
It's important to realize that block generation is not a long, set problem (like doing a million hashes), but more like a lottery. Each hash is a random number between 0 and the maximum value of a 256-bit number (2^256-1). If a hash is below the target, the node wins. If not, you increment the nonce (completely changing the hash) and try again. &lt;br /&gt;
&lt;br /&gt;
The Bitcoin network tries to produce one block every ten minutes on average. As mining hash power changes over time, it achieves this through changing the target value.&lt;br /&gt;
&lt;br /&gt;
Historically (prior to forking from BTC in August 2017), Bitcoin changed its target every 2016 blocks (exactly two weeks if a block time of 10 minutes was kept perfectly). This change in the target is known as a 'difficulty adjustment'. Under the original difficulty adjustment paradigm, when adjusting the target, every Bitcoin client compared the actual time it took to generate 2016 blocks with the two week goal, and modified the target by the percentage difference. A single retarget never changes the target downwards (increasing difficulty) by more than a factor of 4, or upwards (decreasing difficulty) by more than a factor of 0.75. This prevents large changes in difficulty.&lt;br /&gt;
&lt;br /&gt;
After the hard fork of August 2017, Bitcoin changed the original difficulty adjustment algorithm to what was named the Emergency Difficulty Adjustment (EDA) algorithm. The EDA had the capacity to update the target value every time a new block was found (as opposed to every 2016 blocks), while still targeting a ten minute block time average. The EDA was changed to the Difficulty Adjustment Algorithm (DAA) on 17 November 2017 to address instabilities associated with the EDA. The DAA uses a moving average of the last 144 blocks to determine changes to the target and like the EDA, the target can change every block. A single DAA retarget never changes the target downwards (increasing difficulty) by more than a factor of 2, or upwards (decreasing difficulty) by more than a factor of 2. This sets the maximum bounds for any change in difficulty.&lt;br /&gt;
&lt;br /&gt;
The reason the EDA (and later the DAA) needed to be implemented was because of the creation of the competing BTC network which was expected to garner significantly more hash power than Bitcoin (known as Bitcoin Cash at the time). These measures were put in place so that block production could remain relatively stable due to miners' ability to instantaneously re-allocate hash between the networks.&lt;br /&gt;
&lt;br /&gt;
It is proposed that Bitcoin will move back to the original difficulty adjustment algorithm (still used by BTC) in the future.&lt;br /&gt;
&lt;br /&gt;
===How is the target stored in blocks?===&lt;br /&gt;
Each block stores a packed representation in its block header (called [[Block hashing algorithm|Bits]]) for its actual hexadecimal target. The target can be derived from Bits via a predefined formula. For example, if the packed target in the block is 0x1b0404cb, the hexadecimal target is:&lt;br /&gt;
 0x0404cb * 2**(8*(0x1b - 3)) = 0x00000000000404CB000000000000000000000000000000000000000000000000&lt;br /&gt;
&lt;br /&gt;
Note that the 0x0404cb value is a signed value in this format. The largest legal value for this field is 0x7fffff. To make a larger value you must shift it down one full byte. Also 0x008000 is the smallest positive valid value.&lt;br /&gt;
&lt;br /&gt;
=== What is the current target? ===&lt;br /&gt;
Check the [[Block hashing algorithm|Bits]] field of the most recent block on a [https://whatsonchain.com/ block explorer].&lt;br /&gt;
&lt;br /&gt;
=== What is the maximum target? ===&lt;br /&gt;
The maximum target used by SHA256 mining devices is:&lt;br /&gt;
 0x00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF&lt;br /&gt;
Because Bitcoin stores the target as a floating-point type, this is truncated:&lt;br /&gt;
 0x00000000FFFF0000000000000000000000000000000000000000000000000000&lt;br /&gt;
&lt;br /&gt;
The maximum target is the target used in the [[Genesis block|Genesis Block]] and represents a [[difficulty]] of 1. Its packed representation as [[Block hashing algorithm|Bits]] is 0x1d00ffff.&lt;br /&gt;
&lt;br /&gt;
Since a lower target makes Bitcoin generation more difficult, the maximum target is the ''lowest'' possible [[difficulty]].&lt;br /&gt;
&lt;br /&gt;
==Related Links==&lt;br /&gt;
See also [[Difficulty]]&lt;br /&gt;
&lt;br /&gt;
==Attribution==&lt;br /&gt;
This content is based on content sourced from https://en.bitcoin.it/wiki/Target under [https://creativecommons.org/licenses/by/3.0/ Creative Commons Attribution 3.0]. Although it may have been extensively revised and updated we acknowledge the original authors.&lt;/div&gt;</summary>
		<author><name>Angus Adams</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.bitcoinsv.io/index.php?title=Difficulty&amp;diff=2255</id>
		<title>Difficulty</title>
		<link rel="alternate" type="text/html" href="https://wiki.bitcoinsv.io/index.php?title=Difficulty&amp;diff=2255"/>
		<updated>2020-02-19T14:10:02Z</updated>

		<summary type="html">&lt;p&gt;Angus Adams: /* What is difficulty? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;''See also: [[Target]]''&lt;br /&gt;
&lt;br /&gt;
=== What is difficulty? ===&lt;br /&gt;
&lt;br /&gt;
Difficulty is a measure of how difficult it is to find a hash below a given [[target]]. Difficulty answers the question: &amp;quot;how many times more difficult is it to mine a block now, compared with how difficult it was to mine the [[Genesis block|Genesis Block]]?&amp;quot;. It has a close relationship with target but is not the same thing. Rather it has an inverse relationship where a higher difficulty implies a lower target value.&lt;br /&gt;
&lt;br /&gt;
The Bitcoin network has a global block difficulty. Valid blocks must have a hash below this target.&lt;br /&gt;
Mining pools also have a pool-specific share difficulty setting a lower limit for shares.&lt;br /&gt;
&lt;br /&gt;
=== How often does the network difficulty change? ===&lt;br /&gt;
&lt;br /&gt;
See [[Target|target]].&lt;br /&gt;
&lt;br /&gt;
=== What is the formula for difficulty? ===&lt;br /&gt;
difficulty = difficulty_1_target / current_target &lt;br /&gt;
&lt;br /&gt;
''target is a 256 bit number''&lt;br /&gt;
&lt;br /&gt;
''difficulty_1_target is the target used in the Genesis Block and represents a difficulty of 1.''&lt;br /&gt;
&lt;br /&gt;
difficulty_1_target can be different for various ways to measure difficulty.&lt;br /&gt;
Traditionally, it represents a hash where the leading 32 bits are zero and the rest are one (this is known as &amp;quot;pool difficulty&amp;quot; or &amp;quot;pdiff&amp;quot;).&lt;br /&gt;
The Bitcoin protocol represents targets as a custom floating point type with limited precision; as a result, Bitcoin clients often approximate difficulty based on this (this is known as &amp;quot;bdiff&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
===How is difficulty stored in blocks?===&lt;br /&gt;
&lt;br /&gt;
Each block stores a packed representation in its block header (called [[Block hashing algorithm|Bits]]) for its actual hexadecimal [[target]]. The target can be derived from Bits via a predefined formula. For example, if the packed target in the block is 0x1b0404cb, the hexadecimal target is:&lt;br /&gt;
 0x0404cb * 2**(8*(0x1b - 3)) = 0x00000000000404CB000000000000000000000000000000000000000000000000&lt;br /&gt;
&lt;br /&gt;
Note that the 0x0404cb value is a signed value in this format. The largest legal value for this field is 0x7fffff. To make a larger value you must shift it down one full byte. Also 0x008000 is the smallest positive valid value.&lt;br /&gt;
&lt;br /&gt;
===How is difficulty calculated? What is the difference between bdiff and pdiff?===&lt;br /&gt;
&lt;br /&gt;
The highest possible target (difficulty 1) is defined as 0x1d00ffff, which gives us a hex target of&lt;br /&gt;
 0x00ffff * 2**(8*(0x1d - 3)) = 0x00000000FFFF0000000000000000000000000000000000000000000000000000&lt;br /&gt;
&lt;br /&gt;
It should be noted that pooled mining often uses non-truncated targets, which puts &amp;quot;pool difficulty 1&amp;quot; at&lt;br /&gt;
 0x00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF&lt;br /&gt;
&lt;br /&gt;
So the difficulty at 0x1b0404cb is therefore:&lt;br /&gt;
 0x00000000FFFF0000000000000000000000000000000000000000000000000000 /&lt;br /&gt;
 0x00000000000404CB000000000000000000000000000000000000000000000000 &lt;br /&gt;
 = 16307.420938523983 (bdiff)&lt;br /&gt;
And:&lt;br /&gt;
 0x00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF /&lt;br /&gt;
 0x00000000000404CB000000000000000000000000000000000000000000000000 &lt;br /&gt;
 = 16307.669773817162 (pdiff)&lt;br /&gt;
&lt;br /&gt;
Here's a fast way to calculate Bitcoin difficulty. It uses a modified Taylor series for the logarithm (you can see tutorials on flipcode and wikipedia) and relies on logs to transform the difficulty calculation:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;cmath&amp;gt;&lt;br /&gt;
&lt;br /&gt;
inline float fast_log(float val)&lt;br /&gt;
{&lt;br /&gt;
   int * const exp_ptr = reinterpret_cast &amp;lt;int *&amp;gt;(&amp;amp;val);&lt;br /&gt;
   int x = *exp_ptr;&lt;br /&gt;
   const int log_2 = ((x &amp;gt;&amp;gt; 23) &amp;amp; 255) - 128;&lt;br /&gt;
   x &amp;amp;= ~(255 &amp;lt;&amp;lt; 23);&lt;br /&gt;
   x += 127 &amp;lt;&amp;lt; 23;&lt;br /&gt;
   *exp_ptr = x;&lt;br /&gt;
&lt;br /&gt;
   val = ((-1.0f/3) * val + 2) * val - 2.0f/3;&lt;br /&gt;
   return ((val + log_2) * 0.69314718f);&lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
float difficulty(unsigned int bits)&lt;br /&gt;
{&lt;br /&gt;
    static double max_body = fast_log(0x00ffff), scaland = fast_log(256);&lt;br /&gt;
    return exp(max_body - fast_log(bits &amp;amp; 0x00ffffff) + scaland * (0x1d - ((bits &amp;amp; 0xff000000) &amp;gt;&amp;gt; 24)));&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
    std::cout &amp;lt;&amp;lt; difficulty(0x1b0404cb) &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To see the math to go from the normal difficulty calculations (which require large big ints bigger than the space in any normal integer) to the calculation above, here's some python:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import decimal, math&lt;br /&gt;
l = math.log&lt;br /&gt;
e = math.e&lt;br /&gt;
&lt;br /&gt;
print 0x00ffff * 2**(8*(0x1d - 3)) / float(0x0404cb * 2**(8*(0x1b - 3)))&lt;br /&gt;
print l(0x00ffff * 2**(8*(0x1d - 3)) / float(0x0404cb * 2**(8*(0x1b - 3))))&lt;br /&gt;
print l(0x00ffff * 2**(8*(0x1d - 3))) - l(0x0404cb * 2**(8*(0x1b - 3)))&lt;br /&gt;
print l(0x00ffff) + l(2**(8*(0x1d - 3))) - l(0x0404cb) - l(2**(8*(0x1b - 3)))&lt;br /&gt;
print l(0x00ffff) + (8*(0x1d - 3))*l(2) - l(0x0404cb) - (8*(0x1b - 3))*l(2)&lt;br /&gt;
print l(0x00ffff / float(0x0404cb)) + (8*(0x1d - 3))*l(2) - (8*(0x1b - 3))*l(2)&lt;br /&gt;
print l(0x00ffff / float(0x0404cb)) + (0x1d - 0x1b)*l(2**8)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== What is the current difficulty? ===&lt;br /&gt;
[https://whatsonchain.com/ Current difficulty]&lt;br /&gt;
&lt;br /&gt;
=== What is the maximum difficulty? ===&lt;br /&gt;
&lt;br /&gt;
There is no minimum target. The maximum difficulty is roughly: maximum_target / 1 (since 0 would result in infinity), which is a ridiculously huge number (about 2^224).&lt;br /&gt;
&lt;br /&gt;
The actual maximum difficulty is when current_target=0, but we would not be able to calculate the difficulty if that happened. (fortunately it never will, so we're ok.)&lt;br /&gt;
&lt;br /&gt;
The difficulty can rise by a maximum of 400% of the current difficulty, or by a factor of 4 in a single adjustment.&lt;br /&gt;
&lt;br /&gt;
=== Can the network difficulty decrease? ===&lt;br /&gt;
Yes it can. See discussion in [[target]]. &lt;br /&gt;
&lt;br /&gt;
The network's difficulty can adjust downwards by up to 75% of the current difficulty in a single adjustment.&lt;br /&gt;
&lt;br /&gt;
=== What is the minimum difficulty? ===&lt;br /&gt;
The minimum difficulty, when the target is at the maximum allowed value, is 1. This is the difficulty of the [[Genesis block]].&lt;br /&gt;
&lt;br /&gt;
=== What network hash rate results in a given difficulty? ===&lt;br /&gt;
The difficulty is adjusted every 2016 blocks based on the [[Block_timestamp|time]] it took to find the previous 2016 blocks.  At the desired rate of one block each 10 minutes, 2016 blocks would take exactly two weeks to find.  If the previous 2016 blocks took more than two weeks to find, the difficulty is reduced.  If they took less than two weeks, the difficulty is increased.  The change in difficulty is in proportion to the amount of time over or under two weeks the previous 2016 blocks took to find.&lt;br /&gt;
&lt;br /&gt;
To find a block, the hash must be less than the target.  The hash is effectively a random number between 0 and 2**256-1.  The offset for difficulty 1 is&lt;br /&gt;
 0xffff * 2**208&lt;br /&gt;
and for difficulty D is&lt;br /&gt;
 (0xffff * 2**208)/D&lt;br /&gt;
&lt;br /&gt;
The expected number of hashes we need to calculate to find a block with difficulty D is therefore&lt;br /&gt;
 D * 2**256 / (0xffff * 2**208)&lt;br /&gt;
or just&lt;br /&gt;
 D * 2**48 / 0xffff&lt;br /&gt;
&lt;br /&gt;
The difficulty is set such that the previous 2016 blocks would have been found at the rate of one every 10 minutes, so we were calculating (D * 2**48 / 0xffff) hashes in 600 seconds.  That means the hash rate of the network was&lt;br /&gt;
 D * 2**48 / 0xffff / 600&lt;br /&gt;
over the previous 2016 blocks.  Can be further simplified to&lt;br /&gt;
 D * 2**32 / 600&lt;br /&gt;
without much loss of accuracy.&lt;br /&gt;
&lt;br /&gt;
At difficulty 1, that is around 7 Mhashes per second.&lt;br /&gt;
&lt;br /&gt;
At the time of writing, the difficulty is 22012.4941572, which means that over the previous set of 2016 blocks found the average network hash rate was&lt;br /&gt;
 22012.4941572 * 2**32 / 600 = around 157 Ghashes per second.&lt;br /&gt;
&lt;br /&gt;
==Related Links==&lt;br /&gt;
&lt;br /&gt;
* See also: [[Target]]&lt;br /&gt;
&lt;br /&gt;
==Attribution==&lt;br /&gt;
This content is based on content sourced from https://en.bitcoin.it/wiki/Difficulty under [https://creativecommons.org/licenses/by/3.0/ Creative Commons Attribution 3.0]. Although it may have been extensively revised and updated we acknowledge the original authors.&lt;/div&gt;</summary>
		<author><name>Angus Adams</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.bitcoinsv.io/index.php?title=Target&amp;diff=2254</id>
		<title>Target</title>
		<link rel="alternate" type="text/html" href="https://wiki.bitcoinsv.io/index.php?title=Target&amp;diff=2254"/>
		<updated>2020-02-19T14:09:17Z</updated>

		<summary type="html">&lt;p&gt;Angus Adams: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The '''target''' is a 256-bit number that all Bitcoin clients share. The double SHA-256 [https://wiki.bitcoinsv.io/index.php/Mining#Hashing hash] of a [[Block hashing algorithm|block's header]] must be less than or equal to the current target for the block to be accepted by the network. The lower the target, the more [[difficulty|difficult]] it is to generate a block.&lt;br /&gt;
&lt;br /&gt;
It's important to realize that block generation is not a long, set problem (like doing a million hashes), but more like a lottery. Each hash is a random number between 0 and the maximum value of a 256-bit number (2^256-1). If a hash is below the target, the node wins. If not, you increment the nonce (completely changing the hash) and try again. &lt;br /&gt;
&lt;br /&gt;
The Bitcoin network tries to produce one block every ten minutes on average. As mining hash power changes over time, it achieves this through changing the target value.&lt;br /&gt;
&lt;br /&gt;
Historically (prior to forking from BTC in August 2017), Bitcoin changed its target every 2016 blocks (exactly two weeks if a block time of 10 minutes was kept perfectly). This change in the target is known as a 'difficulty adjustment'. Under the original difficulty adjustment paradigm, when adjusting the target, every Bitcoin client compared the actual time it took to generate 2016 blocks with the two week goal, and modified the target by the percentage difference. A single retarget never changes the target downwards (increasing difficulty) by more than a factor of 4, or upwards (decreasing difficulty) by more than a factor of 0.75. This prevents large changes in difficulty.&lt;br /&gt;
&lt;br /&gt;
After the hard fork of August 2017, Bitcoin changed the original difficulty adjustment algorithm to what was named the Emergency Difficulty Adjustment (EDA) algorithm. The EDA had the capacity to update the target value every time a new block was found (as opposed to every 2016 blocks), while still targeting a ten minute block time average. The EDA was changed to the Difficulty Adjustment Algorithm (DAA) on 17 November 2017 to address instabilities associated with the EDA. The DAA uses a moving average of the last 144 blocks to determine changes to the target and like the EDA, the target can change every block. &lt;br /&gt;
&lt;br /&gt;
The reason the EDA (and later the DAA) needed to be implemented was because of the creation of the competing BTC network which was expected to garner significantly more hash power than Bitcoin (known as Bitcoin Cash at the time). These measures were put in place so that block production could remain relatively stable due to miners' ability to instantaneously re-allocate hash between the networks.&lt;br /&gt;
&lt;br /&gt;
It is proposed that Bitcoin will move back to the original difficulty adjustment algorithm (still used by BTC) in the future.&lt;br /&gt;
&lt;br /&gt;
===How is the target stored in blocks?===&lt;br /&gt;
Each block stores a packed representation in its block header (called [[Block hashing algorithm|Bits]]) for its actual hexadecimal target. The target can be derived from Bits via a predefined formula. For example, if the packed target in the block is 0x1b0404cb, the hexadecimal target is:&lt;br /&gt;
 0x0404cb * 2**(8*(0x1b - 3)) = 0x00000000000404CB000000000000000000000000000000000000000000000000&lt;br /&gt;
&lt;br /&gt;
Note that the 0x0404cb value is a signed value in this format. The largest legal value for this field is 0x7fffff. To make a larger value you must shift it down one full byte. Also 0x008000 is the smallest positive valid value.&lt;br /&gt;
&lt;br /&gt;
=== What is the current target? ===&lt;br /&gt;
Check the [[Block hashing algorithm|Bits]] field of the most recent block on a [https://whatsonchain.com/ block explorer].&lt;br /&gt;
&lt;br /&gt;
=== What is the maximum target? ===&lt;br /&gt;
The maximum target used by SHA256 mining devices is:&lt;br /&gt;
 0x00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF&lt;br /&gt;
Because Bitcoin stores the target as a floating-point type, this is truncated:&lt;br /&gt;
 0x00000000FFFF0000000000000000000000000000000000000000000000000000&lt;br /&gt;
&lt;br /&gt;
The maximum target is the target used in the [[Genesis block|Genesis Block]] and represents a [[difficulty]] of 1. Its packed representation as [[Block hashing algorithm|Bits]] is 0x1d00ffff.&lt;br /&gt;
&lt;br /&gt;
Since a lower target makes Bitcoin generation more difficult, the maximum target is the ''lowest'' possible [[difficulty]].&lt;br /&gt;
&lt;br /&gt;
==Related Links==&lt;br /&gt;
See also [[Difficulty]]&lt;br /&gt;
&lt;br /&gt;
==Attribution==&lt;br /&gt;
This content is based on content sourced from https://en.bitcoin.it/wiki/Target under [https://creativecommons.org/licenses/by/3.0/ Creative Commons Attribution 3.0]. Although it may have been extensively revised and updated we acknowledge the original authors.&lt;/div&gt;</summary>
		<author><name>Angus Adams</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.bitcoinsv.io/index.php?title=Target&amp;diff=2253</id>
		<title>Target</title>
		<link rel="alternate" type="text/html" href="https://wiki.bitcoinsv.io/index.php?title=Target&amp;diff=2253"/>
		<updated>2020-02-19T14:06:44Z</updated>

		<summary type="html">&lt;p&gt;Angus Adams: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The '''target''' is a 256-bit number that all Bitcoin clients share. The double SHA-256 [https://wiki.bitcoinsv.io/index.php/Mining#Hashing hash] of a [[Block hashing algorithm|block's header]] must be less than or equal to the current target for the block to be accepted by the network. The lower the target, the more [[difficulty|difficult]] it is to generate a block.&lt;br /&gt;
&lt;br /&gt;
It's important to realize that block generation is not a long, set problem (like doing a million hashes), but more like a lottery. Each hash is a random number between 0 and the maximum value of a 256-bit number (2^256-1). If a hash is below the target, the node wins. If not, you increment the nonce (completely changing the hash) and try again. &lt;br /&gt;
&lt;br /&gt;
The Bitcoin network tries to produce one block every ten minutes on average. As mining hash power changes over time, it achieves this through changing the target value.&lt;br /&gt;
&lt;br /&gt;
Historically (prior to forking from BTC in August 2017), Bitcoin changed its target every 2016 blocks (exactly two weeks if a block time of 10 minutes was kept perfectly). This change in the target is known as a 'difficulty adjustment'. Under the original difficulty adjustment paradigm, when adjusting the target, every Bitcoin client compared the actual time it took to generate 2016 blocks with the two week goal, and modified the target by the percentage difference. A single retarget never changes the target downwards (increasing difficulty) by more than a factor of 4, or upwards (decreasing difficulty) by more than a factor of 0.75. This prevents large changes in difficulty.&lt;br /&gt;
&lt;br /&gt;
After the hard fork of August 2017, Bitcoin changed the original difficulty adjustment algorithm to what was named the Emergency Difficulty Adjustment (EDA) algorithm. The EDA had the capacity to update the target value every time a new block was found (as opposed to every 2016 blocks), while still targeting a ten minute block time average. The EDA was changed to the Difficulty Adjustment Algorithm (DAA) on 17 November 2017 to address instabilities associated with the EDA. The DAA uses a moving average of the last 144 blocks to determine changes to the target and like the EDA, the target can change every block. &lt;br /&gt;
&lt;br /&gt;
The reason the EDA (and later the DAA) needed to be implemented was because of the creation of the competing BTC network and which was expected to garner significantly more hash power than Bitcoin (known as Bitcoin Cash at the time). These measures were put in place so that block production could remain relatively stable due to miners' ability to instantaneously re-allocate hash between the networks.&lt;br /&gt;
&lt;br /&gt;
It is proposed that Bitcoin will move back to the original difficulty adjustment algorithm (still used by BTC) in the future.&lt;br /&gt;
&lt;br /&gt;
===How is the target stored in blocks?===&lt;br /&gt;
Each block stores a packed representation in its block header (called [[Block hashing algorithm|Bits]]) for its actual hexadecimal target. The target can be derived from Bits via a predefined formula. For example, if the packed target in the block is 0x1b0404cb, the hexadecimal target is:&lt;br /&gt;
 0x0404cb * 2**(8*(0x1b - 3)) = 0x00000000000404CB000000000000000000000000000000000000000000000000&lt;br /&gt;
&lt;br /&gt;
Note that the 0x0404cb value is a signed value in this format. The largest legal value for this field is 0x7fffff. To make a larger value you must shift it down one full byte. Also 0x008000 is the smallest positive valid value.&lt;br /&gt;
&lt;br /&gt;
=== What is the current target? ===&lt;br /&gt;
Check the [[Block hashing algorithm|Bits]] field of the most recent block on a [https://whatsonchain.com/ block explorer].&lt;br /&gt;
&lt;br /&gt;
=== What is the maximum target? ===&lt;br /&gt;
The maximum target used by SHA256 mining devices is:&lt;br /&gt;
 0x00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF&lt;br /&gt;
Because Bitcoin stores the target as a floating-point type, this is truncated:&lt;br /&gt;
 0x00000000FFFF0000000000000000000000000000000000000000000000000000&lt;br /&gt;
&lt;br /&gt;
The maximum target is the target used in the [[Genesis block|Genesis Block]] and represents a [[difficulty]] of 1. Its packed representation as [[Block hashing algorithm|Bits]] is 0x1d00ffff.&lt;br /&gt;
&lt;br /&gt;
Since a lower target makes Bitcoin generation more difficult, the maximum target is the ''lowest'' possible [[difficulty]].&lt;br /&gt;
&lt;br /&gt;
==Related Links==&lt;br /&gt;
See also [[Difficulty]]&lt;br /&gt;
&lt;br /&gt;
==Attribution==&lt;br /&gt;
This content is based on content sourced from https://en.bitcoin.it/wiki/Target under [https://creativecommons.org/licenses/by/3.0/ Creative Commons Attribution 3.0]. Although it may have been extensively revised and updated we acknowledge the original authors.&lt;/div&gt;</summary>
		<author><name>Angus Adams</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.bitcoinsv.io/index.php?title=Mining&amp;diff=2252</id>
		<title>Mining</title>
		<link rel="alternate" type="text/html" href="https://wiki.bitcoinsv.io/index.php?title=Mining&amp;diff=2252"/>
		<updated>2020-02-19T13:45:47Z</updated>

		<summary type="html">&lt;p&gt;Angus Adams: /* Rejected blocks */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
'''Mining''' is the process where nodes in the Bitcoin [[Network]] assemble newly broadcast [[Bitcoin Transactions]] into a data structure called a [[block]]. Nodes then compete to append their block to the public [[Block chain|blockchain]] by repeatedly mutating the block's header data structure, usually by incrementing the nonce field, then hashing it in an attempt to find a value that satisfies a difficult [[Proof of Work|proof-of-work]]. &lt;br /&gt;
&lt;br /&gt;
When a node finds a valid proof-of-work hash for a block, it broadcasts the block to all nodes. Other nodes accept this block only if all the transactions in it are valid and have not yet been included in a block. Other nodes in the network then express their acceptance of the block by building upon it to create the next block in the chain.&lt;br /&gt;
&lt;br /&gt;
Every block is [[Block timestamp|timestamped]] and references the hash of the block preceding it. Blocks form a backward reinforcing, timestamped chain – a [[Timechain]], the precursor to the term ‘blockchain’.&lt;br /&gt;
&lt;br /&gt;
The blockchain structures itself in a manner that is computationally and economically impractical to modify by any one entity. Due to this, transactions included in the blockchain are considered immutable. In addition to this quality, the blockchain establishes an authoritative order of these transactions throughout the network by establishing which out of any pair of conflicting transactions was seen first, thereby protecting users from [[Double-spending|attempts to re-spend coins]] that have already been spent elsewhere. This is the key innovation of mining and of Bitcoin.&lt;br /&gt;
&lt;br /&gt;
=== Nodes ===&lt;br /&gt;
Nodes are entities that run software that carries out the mining functions above. Nodes communicate using a [[P2P Network]] with its own protocol, and are the authors of the Bitcoin ledger and enforcers of the [[protocol]] rules.&lt;br /&gt;
&lt;br /&gt;
Interestingly, the Bitcoin whitepaper makes no reference to the term ‘miner’ or the concept of ‘mining’. These terms cover the actions described in section 5 of the [http://bitcoinsv.io/bitcoin.pdf Bitcoin whitepaper] which describes the responsibilities of nodes on the network. &lt;br /&gt;
&lt;br /&gt;
It is possible to run the node client software without performing block assembly or proof-of-work. Such a setup can be used as an interface to the network for other systems such as block explorers, payment gateways and archives. Eventually it is expected that customised client software will be developed for each of these services so they will no longer be dependent on the node client to operate.&lt;br /&gt;
&lt;br /&gt;
Computers that run a node client but which do not perform proof-of-work cannot append new blocks to the blockchain. This means they can neither express acceptance of valid blocks by working on extending them, nor reject invalid blocks by refusing to work on them. These computers exist as passive entities that follow the gatekeepers of the network, the miners.&lt;br /&gt;
&lt;br /&gt;
=== Mempool ===&lt;br /&gt;
Before a Bitcoin transaction can be committed to the blockchain it needs to be received and validated by a miner. If the miner deems the transaction valid, they add the transaction to one of several [[Protocol#mempool|mempools]]. Mempools are temporary transaction stores and can be used to hold transactions grouped in different ways, such as transactions to be mined in the next block, transactions to watch, or transactions which cannot be mined due to an nLocktime/nSequence lock.&lt;br /&gt;
&lt;br /&gt;
It is important to note every miner has their own mempools and that mempools vary across miners. It is also important to note that an individual transaction can be included in different mempools at the same time. &lt;br /&gt;
&lt;br /&gt;
A miner takes the transactions it intends to include in the next block and hashes them into a [[Protocol#Merkle_Trees|merkle tree]] structure and includes the resulting merkle root within a candidate [[Block hashing algorithm|block header]]. The miner then hashes this candidate block header, attempting to find a valid proof-of-work.&lt;br /&gt;
&lt;br /&gt;
=== Hashing ===&lt;br /&gt;
A hash is a function that converts a string of data into a fixed length value that represents the original string, called the hash value. Every hash value is unique. &lt;br /&gt;
&lt;br /&gt;
Hashing is a one-way function, meaning it is infeasible to determine what the input data is by looking at the hash produced from it. Conversely, it is trivial to run the same input data through the same hash function and reproduce the same hash. Because of this, a hash value of input data can be thought of as the digital fingerprint of that data. In Bitcoin mining, the input data is the 80-byte [[Block hashing algorithm|block header]].&lt;br /&gt;
&lt;br /&gt;
The hashing algorithm used in Bitcoin mining is [[SHA-256]]. SHA-256 stands for Secure Hash Algorithm – 256 bit. Passing the same block header data through this algorithm will always output the same 256-bit number. However if the header data is modified even by a single a bit a completely different and unrelated 256-bit number will result. &lt;br /&gt;
&lt;br /&gt;
Bitcoin mining passes the block header data through the SHA-256 algorithm twice (SHA-256d).&lt;br /&gt;
&lt;br /&gt;
=== Proof-of-work ===&lt;br /&gt;
Bitcoin uses a [[Proof of Work]] function based on the earlier work of [[hashcash]].&lt;br /&gt;
&lt;br /&gt;
A miner cannot create a new block without finding a valid proof-of-work hash for the block header they are hashing. To be valid, the SHA-256d hash (which is just a number) of the block header must be less than another number, called the [[target]]. The target value is defined by the [[Block hashing algorithm|Bits]] field in the block header that is being hashed.&lt;br /&gt;
 &lt;br /&gt;
The target adjusts so that the average time it takes for the entire network to find a valid proof-of-work hash is ten minutes. &lt;br /&gt;
&lt;br /&gt;
Because of the extraordinarily large SHA-256 target space, it is extremely unlikely that any given hash will be below the target. As a result of this, hashing entities invest large amounts of capital into specialized hashing hardware along with the associated electricity costs in order to produce as many of these hashes as possible in a given time period. Therefore, the only way a miner can append a block to the blockchain is through a substantial commitment of operational expenditure – proof-of-work.&lt;br /&gt;
&lt;br /&gt;
=== Incentive ===&lt;br /&gt;
The first transaction in every block is called the [[Coinbase]] transaction. The Coinbase transaction is a special transaction which pays bitcoins to the miner of the block. The Coinbase payment is made up of the [[Miner subsidy|subsidy]] amount and the sum of all [[transaction fees]] paid by transactions within the mined block.&lt;br /&gt;
&lt;br /&gt;
== Competition ==&lt;br /&gt;
&lt;br /&gt;
=== Propagation and validation ===&lt;br /&gt;
If a miner finds a valid proof-of-work for the block header they are hashing, they immediately announce this by sending the entire block to other miners. Meanwhile, they start working on finding the next block in the chain. &lt;br /&gt;
&lt;br /&gt;
Competing miners receive this block and immediately check that all transactions within the block, as well as the proof-of-work are valid. If the block is valid, they discontinue mining on top of the previous block and start working on hashing a new block header, building on the block just found by their competitor.&lt;br /&gt;
&lt;br /&gt;
There are incentives at play here. First, winning 'miner A' strives to get their winning block to all other miners as quickly as possible. This reduces the possibility that competing 'miner B' (who found a valid block at approximately the same time) propagates their block to some miners before 'miner A' could. This opens up the possibility that 'miner A's' block could later be [[Orphan Block|orphaned]] and the Coinbase reward rendered invalid and unusable by 'miner A'. The degree of bandwidth and connectivity to other miners can be seen as a competitive advantage and as such, the mining network tends toward a densely connected, small world structure with high bandwidth.&lt;br /&gt;
&lt;br /&gt;
There also exists a competitive advantage in validating transactions. When validating a block, each transaction's inputs must be looked up in the miner's [[VOUT|UTXO]] set to check they are unspent and the amount in satoshis is correct. Additionally, each input's locking and unlocking scripts need to be run by the miner to assess whether each transaction is valid.&lt;br /&gt;
&lt;br /&gt;
=== Rejected blocks ===&lt;br /&gt;
At any given point in time, two or more independent miners may mine a block at the same time. In this situation, nodes can be in disagreement about which of these blocks should be the tip of the blockchain.&lt;br /&gt;
&lt;br /&gt;
Miners always follow the longest chain they deem to be valid. Eventually another block will be found that builds on one of the competing chain tips. Miners then switch to this tip provided they consider it to be valid. As such, any fork scenario is eventually resolved back to one persistent chain through the actions of the majority of hash power. &lt;br /&gt;
&lt;br /&gt;
In this scenario, a block that doesn't end up forming part of the longest chain is rejected by the network and called an [[Orphan Block]]. An orphan block represent wasted effort on the behalf of a miner and an incentive to invest in infrastructure in order to reduce the frequency of these events. However, orphans do not reduce the overall revenues of the Bitcoin system as the wasted work is not factored into the difficulty adjustment, thus if a certain percentage of hashing work is wasted due to the orphaned blocks, the difficulty will adjust downwards by a similar percentage, maintaining the same rate of valid block production overall.  Additionally the fee paying transactions in the orphaned block will still be valid and included in the competing block or its descendants.&lt;br /&gt;
&lt;br /&gt;
Competing valid blocks are not the only way that blocks end up being rejected. Any miner can refuse to build on any block for any reason. Such an action by a particular miner is only meaningful if the majority of miners carry out the same action. It is through this mechanism that the mining network can establish consensus on variables that are miner configurable - such as maximum block size. This is the basis of Nakamoto Consensus:&lt;br /&gt;
&lt;br /&gt;
{{quote|1=''&amp;quot; They vote with their CPU power, expressing their acceptance of valid blocks by working on extending them and rejecting invalid blocks by refusing to work on them. Any needed rules and incentives can be enforced with this consensus mechanism.&amp;quot;''}}&lt;br /&gt;
&lt;br /&gt;
== The mining ecosystem ==&lt;br /&gt;
&lt;br /&gt;
=== Asic mining ===&lt;br /&gt;
An application-specific integrated circuit, or ASIC, is a microchip designed and manufactured for a very specific purpose. ASICs designed for Bitcoin mining were first released in 2013. For the amount of power they consume, they are vastly more energy efficient than predecessor approaches to mining - using CPU, GPU or FPGA.&lt;br /&gt;
&lt;br /&gt;
=== Pooled mining ===&lt;br /&gt;
Pooled mining is the use of a block template allocation system that provides distributed hashing infrastructure updated block headers against which they perform proof of work. This system of hash allocation to nodes is a primary part of [[Nakamoto Consensus]] in that individual operators of hash power can choose to re-allocate their hash to nodes producing blocks that meet their expectations in terms of maximised profitability and adherence to the Bitcoin ruleset. Miners who distribute block templates that don't maximise profit or which attempt to implement changed rule sets risk the owners of the hash machinery they depend on re-deploying it to a different node on the network.&lt;br /&gt;
 &lt;br /&gt;
==== Stratum ====&lt;br /&gt;
Stratum is an open-source mining protocol used by many mining pools. Stratum facilitates coordination between the mining pool operator and individual mining machines.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [https://bitcoinsv.io/bitcoin.pdf Bitcoin Whitepaper]&lt;br /&gt;
&lt;br /&gt;
==Attribution==&lt;br /&gt;
This content is based on content sourced from https://en.bitcoin.it/wiki/Mining under [https://creativecommons.org/licenses/by/3.0/ Creative Commons Attribution 3.0]. Although it may have been extensively revised and updated we acknowledge the original authors.&lt;/div&gt;</summary>
		<author><name>Angus Adams</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.bitcoinsv.io/index.php?title=Mining&amp;diff=2251</id>
		<title>Mining</title>
		<link rel="alternate" type="text/html" href="https://wiki.bitcoinsv.io/index.php?title=Mining&amp;diff=2251"/>
		<updated>2020-02-19T13:43:25Z</updated>

		<summary type="html">&lt;p&gt;Angus Adams: /* Propagation and validation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
'''Mining''' is the process where nodes in the Bitcoin [[Network]] assemble newly broadcast [[Bitcoin Transactions]] into a data structure called a [[block]]. Nodes then compete to append their block to the public [[Block chain|blockchain]] by repeatedly mutating the block's header data structure, usually by incrementing the nonce field, then hashing it in an attempt to find a value that satisfies a difficult [[Proof of Work|proof-of-work]]. &lt;br /&gt;
&lt;br /&gt;
When a node finds a valid proof-of-work hash for a block, it broadcasts the block to all nodes. Other nodes accept this block only if all the transactions in it are valid and have not yet been included in a block. Other nodes in the network then express their acceptance of the block by building upon it to create the next block in the chain.&lt;br /&gt;
&lt;br /&gt;
Every block is [[Block timestamp|timestamped]] and references the hash of the block preceding it. Blocks form a backward reinforcing, timestamped chain – a [[Timechain]], the precursor to the term ‘blockchain’.&lt;br /&gt;
&lt;br /&gt;
The blockchain structures itself in a manner that is computationally and economically impractical to modify by any one entity. Due to this, transactions included in the blockchain are considered immutable. In addition to this quality, the blockchain establishes an authoritative order of these transactions throughout the network by establishing which out of any pair of conflicting transactions was seen first, thereby protecting users from [[Double-spending|attempts to re-spend coins]] that have already been spent elsewhere. This is the key innovation of mining and of Bitcoin.&lt;br /&gt;
&lt;br /&gt;
=== Nodes ===&lt;br /&gt;
Nodes are entities that run software that carries out the mining functions above. Nodes communicate using a [[P2P Network]] with its own protocol, and are the authors of the Bitcoin ledger and enforcers of the [[protocol]] rules.&lt;br /&gt;
&lt;br /&gt;
Interestingly, the Bitcoin whitepaper makes no reference to the term ‘miner’ or the concept of ‘mining’. These terms cover the actions described in section 5 of the [http://bitcoinsv.io/bitcoin.pdf Bitcoin whitepaper] which describes the responsibilities of nodes on the network. &lt;br /&gt;
&lt;br /&gt;
It is possible to run the node client software without performing block assembly or proof-of-work. Such a setup can be used as an interface to the network for other systems such as block explorers, payment gateways and archives. Eventually it is expected that customised client software will be developed for each of these services so they will no longer be dependent on the node client to operate.&lt;br /&gt;
&lt;br /&gt;
Computers that run a node client but which do not perform proof-of-work cannot append new blocks to the blockchain. This means they can neither express acceptance of valid blocks by working on extending them, nor reject invalid blocks by refusing to work on them. These computers exist as passive entities that follow the gatekeepers of the network, the miners.&lt;br /&gt;
&lt;br /&gt;
=== Mempool ===&lt;br /&gt;
Before a Bitcoin transaction can be committed to the blockchain it needs to be received and validated by a miner. If the miner deems the transaction valid, they add the transaction to one of several [[Protocol#mempool|mempools]]. Mempools are temporary transaction stores and can be used to hold transactions grouped in different ways, such as transactions to be mined in the next block, transactions to watch, or transactions which cannot be mined due to an nLocktime/nSequence lock.&lt;br /&gt;
&lt;br /&gt;
It is important to note every miner has their own mempools and that mempools vary across miners. It is also important to note that an individual transaction can be included in different mempools at the same time. &lt;br /&gt;
&lt;br /&gt;
A miner takes the transactions it intends to include in the next block and hashes them into a [[Protocol#Merkle_Trees|merkle tree]] structure and includes the resulting merkle root within a candidate [[Block hashing algorithm|block header]]. The miner then hashes this candidate block header, attempting to find a valid proof-of-work.&lt;br /&gt;
&lt;br /&gt;
=== Hashing ===&lt;br /&gt;
A hash is a function that converts a string of data into a fixed length value that represents the original string, called the hash value. Every hash value is unique. &lt;br /&gt;
&lt;br /&gt;
Hashing is a one-way function, meaning it is infeasible to determine what the input data is by looking at the hash produced from it. Conversely, it is trivial to run the same input data through the same hash function and reproduce the same hash. Because of this, a hash value of input data can be thought of as the digital fingerprint of that data. In Bitcoin mining, the input data is the 80-byte [[Block hashing algorithm|block header]].&lt;br /&gt;
&lt;br /&gt;
The hashing algorithm used in Bitcoin mining is [[SHA-256]]. SHA-256 stands for Secure Hash Algorithm – 256 bit. Passing the same block header data through this algorithm will always output the same 256-bit number. However if the header data is modified even by a single a bit a completely different and unrelated 256-bit number will result. &lt;br /&gt;
&lt;br /&gt;
Bitcoin mining passes the block header data through the SHA-256 algorithm twice (SHA-256d).&lt;br /&gt;
&lt;br /&gt;
=== Proof-of-work ===&lt;br /&gt;
Bitcoin uses a [[Proof of Work]] function based on the earlier work of [[hashcash]].&lt;br /&gt;
&lt;br /&gt;
A miner cannot create a new block without finding a valid proof-of-work hash for the block header they are hashing. To be valid, the SHA-256d hash (which is just a number) of the block header must be less than another number, called the [[target]]. The target value is defined by the [[Block hashing algorithm|Bits]] field in the block header that is being hashed.&lt;br /&gt;
 &lt;br /&gt;
The target adjusts so that the average time it takes for the entire network to find a valid proof-of-work hash is ten minutes. &lt;br /&gt;
&lt;br /&gt;
Because of the extraordinarily large SHA-256 target space, it is extremely unlikely that any given hash will be below the target. As a result of this, hashing entities invest large amounts of capital into specialized hashing hardware along with the associated electricity costs in order to produce as many of these hashes as possible in a given time period. Therefore, the only way a miner can append a block to the blockchain is through a substantial commitment of operational expenditure – proof-of-work.&lt;br /&gt;
&lt;br /&gt;
=== Incentive ===&lt;br /&gt;
The first transaction in every block is called the [[Coinbase]] transaction. The Coinbase transaction is a special transaction which pays bitcoins to the miner of the block. The Coinbase payment is made up of the [[Miner subsidy|subsidy]] amount and the sum of all [[transaction fees]] paid by transactions within the mined block.&lt;br /&gt;
&lt;br /&gt;
== Competition ==&lt;br /&gt;
&lt;br /&gt;
=== Propagation and validation ===&lt;br /&gt;
If a miner finds a valid proof-of-work for the block header they are hashing, they immediately announce this by sending the entire block to other miners. Meanwhile, they start working on finding the next block in the chain. &lt;br /&gt;
&lt;br /&gt;
Competing miners receive this block and immediately check that all transactions within the block, as well as the proof-of-work are valid. If the block is valid, they discontinue mining on top of the previous block and start working on hashing a new block header, building on the block just found by their competitor.&lt;br /&gt;
&lt;br /&gt;
There are incentives at play here. First, winning 'miner A' strives to get their winning block to all other miners as quickly as possible. This reduces the possibility that competing 'miner B' (who found a valid block at approximately the same time) propagates their block to some miners before 'miner A' could. This opens up the possibility that 'miner A's' block could later be [[Orphan Block|orphaned]] and the Coinbase reward rendered invalid and unusable by 'miner A'. The degree of bandwidth and connectivity to other miners can be seen as a competitive advantage and as such, the mining network tends toward a densely connected, small world structure with high bandwidth.&lt;br /&gt;
&lt;br /&gt;
There also exists a competitive advantage in validating transactions. When validating a block, each transaction's inputs must be looked up in the miner's [[VOUT|UTXO]] set to check they are unspent and the amount in satoshis is correct. Additionally, each input's locking and unlocking scripts need to be run by the miner to assess whether each transaction is valid.&lt;br /&gt;
&lt;br /&gt;
=== Rejected blocks ===&lt;br /&gt;
At any given point in time, two or more independent miners may mine a block at the same time. In this situation, nodes can be in disagreement about which of these blocks should be the tip of the blockchain.&lt;br /&gt;
&lt;br /&gt;
Miners always follow the longest chain they deem to be valid. Eventually another block will be found that builds on one of the competing chain tips. Miners then switch to this tip provided they consider it to be valid. As such, any fork scenario is eventually resolved back to one persistent chain through the actions of the majority of hash power. &lt;br /&gt;
&lt;br /&gt;
In this scenario, a block that doesn't end up forming part of the longest chain is rejected by the network and called an [[Orphan Block]]. An orphan block represent wasted effort on the behalf of a miner and an incentive to invest in infrastructure in order to reduce the frequency of these events. However, orphans do not reduce the overall revenues of the Bitcoin system as the wasted work is not factored into the difficulty adjustment, thus if a certain percentage of hashing work is wasted due to the orphaned blocks the difficulty will adjust downwards by a similar percentage, maintaining the same rate of valid block production overall.  Additionally the fee paying transactions in the orphaned block will still be valid and included in the competing block or its descendants.&lt;br /&gt;
&lt;br /&gt;
Competing valid blocks are not the only way that blocks end up being rejected. Any miner can refuse to build on any block for any reason. Such an action by a particular miner is only meaningful if the majority of miners carry out the same action. It is through this mechanism that the mining network can establish consensus on variables that are miner configurable - such as maximum block size. This is the basis of Nakamoto Consensus:&lt;br /&gt;
&lt;br /&gt;
{{quote|1=''&amp;quot; They vote with their CPU power, expressing their acceptance of valid blocks by working on extending them and rejecting invalid blocks by refusing to work on them. Any needed rules and incentives can be enforced with this consensus mechanism.&amp;quot;''}}&lt;br /&gt;
&lt;br /&gt;
== The mining ecosystem ==&lt;br /&gt;
&lt;br /&gt;
=== Asic mining ===&lt;br /&gt;
An application-specific integrated circuit, or ASIC, is a microchip designed and manufactured for a very specific purpose. ASICs designed for Bitcoin mining were first released in 2013. For the amount of power they consume, they are vastly more energy efficient than predecessor approaches to mining - using CPU, GPU or FPGA.&lt;br /&gt;
&lt;br /&gt;
=== Pooled mining ===&lt;br /&gt;
Pooled mining is the use of a block template allocation system that provides distributed hashing infrastructure updated block headers against which they perform proof of work. This system of hash allocation to nodes is a primary part of [[Nakamoto Consensus]] in that individual operators of hash power can choose to re-allocate their hash to nodes producing blocks that meet their expectations in terms of maximised profitability and adherence to the Bitcoin ruleset. Miners who distribute block templates that don't maximise profit or which attempt to implement changed rule sets risk the owners of the hash machinery they depend on re-deploying it to a different node on the network.&lt;br /&gt;
 &lt;br /&gt;
==== Stratum ====&lt;br /&gt;
Stratum is an open-source mining protocol used by many mining pools. Stratum facilitates coordination between the mining pool operator and individual mining machines.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [https://bitcoinsv.io/bitcoin.pdf Bitcoin Whitepaper]&lt;br /&gt;
&lt;br /&gt;
==Attribution==&lt;br /&gt;
This content is based on content sourced from https://en.bitcoin.it/wiki/Mining under [https://creativecommons.org/licenses/by/3.0/ Creative Commons Attribution 3.0]. Although it may have been extensively revised and updated we acknowledge the original authors.&lt;/div&gt;</summary>
		<author><name>Angus Adams</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.bitcoinsv.io/index.php?title=Mining&amp;diff=2250</id>
		<title>Mining</title>
		<link rel="alternate" type="text/html" href="https://wiki.bitcoinsv.io/index.php?title=Mining&amp;diff=2250"/>
		<updated>2020-02-19T13:39:42Z</updated>

		<summary type="html">&lt;p&gt;Angus Adams: /* Mempool */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
'''Mining''' is the process where nodes in the Bitcoin [[Network]] assemble newly broadcast [[Bitcoin Transactions]] into a data structure called a [[block]]. Nodes then compete to append their block to the public [[Block chain|blockchain]] by repeatedly mutating the block's header data structure, usually by incrementing the nonce field, then hashing it in an attempt to find a value that satisfies a difficult [[Proof of Work|proof-of-work]]. &lt;br /&gt;
&lt;br /&gt;
When a node finds a valid proof-of-work hash for a block, it broadcasts the block to all nodes. Other nodes accept this block only if all the transactions in it are valid and have not yet been included in a block. Other nodes in the network then express their acceptance of the block by building upon it to create the next block in the chain.&lt;br /&gt;
&lt;br /&gt;
Every block is [[Block timestamp|timestamped]] and references the hash of the block preceding it. Blocks form a backward reinforcing, timestamped chain – a [[Timechain]], the precursor to the term ‘blockchain’.&lt;br /&gt;
&lt;br /&gt;
The blockchain structures itself in a manner that is computationally and economically impractical to modify by any one entity. Due to this, transactions included in the blockchain are considered immutable. In addition to this quality, the blockchain establishes an authoritative order of these transactions throughout the network by establishing which out of any pair of conflicting transactions was seen first, thereby protecting users from [[Double-spending|attempts to re-spend coins]] that have already been spent elsewhere. This is the key innovation of mining and of Bitcoin.&lt;br /&gt;
&lt;br /&gt;
=== Nodes ===&lt;br /&gt;
Nodes are entities that run software that carries out the mining functions above. Nodes communicate using a [[P2P Network]] with its own protocol, and are the authors of the Bitcoin ledger and enforcers of the [[protocol]] rules.&lt;br /&gt;
&lt;br /&gt;
Interestingly, the Bitcoin whitepaper makes no reference to the term ‘miner’ or the concept of ‘mining’. These terms cover the actions described in section 5 of the [http://bitcoinsv.io/bitcoin.pdf Bitcoin whitepaper] which describes the responsibilities of nodes on the network. &lt;br /&gt;
&lt;br /&gt;
It is possible to run the node client software without performing block assembly or proof-of-work. Such a setup can be used as an interface to the network for other systems such as block explorers, payment gateways and archives. Eventually it is expected that customised client software will be developed for each of these services so they will no longer be dependent on the node client to operate.&lt;br /&gt;
&lt;br /&gt;
Computers that run a node client but which do not perform proof-of-work cannot append new blocks to the blockchain. This means they can neither express acceptance of valid blocks by working on extending them, nor reject invalid blocks by refusing to work on them. These computers exist as passive entities that follow the gatekeepers of the network, the miners.&lt;br /&gt;
&lt;br /&gt;
=== Mempool ===&lt;br /&gt;
Before a Bitcoin transaction can be committed to the blockchain it needs to be received and validated by a miner. If the miner deems the transaction valid, they add the transaction to one of several [[Protocol#mempool|mempools]]. Mempools are temporary transaction stores and can be used to hold transactions grouped in different ways, such as transactions to be mined in the next block, transactions to watch, or transactions which cannot be mined due to an nLocktime/nSequence lock.&lt;br /&gt;
&lt;br /&gt;
It is important to note every miner has their own mempools and that mempools vary across miners. It is also important to note that an individual transaction can be included in different mempools at the same time. &lt;br /&gt;
&lt;br /&gt;
A miner takes the transactions it intends to include in the next block and hashes them into a [[Protocol#Merkle_Trees|merkle tree]] structure and includes the resulting merkle root within a candidate [[Block hashing algorithm|block header]]. The miner then hashes this candidate block header, attempting to find a valid proof-of-work.&lt;br /&gt;
&lt;br /&gt;
=== Hashing ===&lt;br /&gt;
A hash is a function that converts a string of data into a fixed length value that represents the original string, called the hash value. Every hash value is unique. &lt;br /&gt;
&lt;br /&gt;
Hashing is a one-way function, meaning it is infeasible to determine what the input data is by looking at the hash produced from it. Conversely, it is trivial to run the same input data through the same hash function and reproduce the same hash. Because of this, a hash value of input data can be thought of as the digital fingerprint of that data. In Bitcoin mining, the input data is the 80-byte [[Block hashing algorithm|block header]].&lt;br /&gt;
&lt;br /&gt;
The hashing algorithm used in Bitcoin mining is [[SHA-256]]. SHA-256 stands for Secure Hash Algorithm – 256 bit. Passing the same block header data through this algorithm will always output the same 256-bit number. However if the header data is modified even by a single a bit a completely different and unrelated 256-bit number will result. &lt;br /&gt;
&lt;br /&gt;
Bitcoin mining passes the block header data through the SHA-256 algorithm twice (SHA-256d).&lt;br /&gt;
&lt;br /&gt;
=== Proof-of-work ===&lt;br /&gt;
Bitcoin uses a [[Proof of Work]] function based on the earlier work of [[hashcash]].&lt;br /&gt;
&lt;br /&gt;
A miner cannot create a new block without finding a valid proof-of-work hash for the block header they are hashing. To be valid, the SHA-256d hash (which is just a number) of the block header must be less than another number, called the [[target]]. The target value is defined by the [[Block hashing algorithm|Bits]] field in the block header that is being hashed.&lt;br /&gt;
 &lt;br /&gt;
The target adjusts so that the average time it takes for the entire network to find a valid proof-of-work hash is ten minutes. &lt;br /&gt;
&lt;br /&gt;
Because of the extraordinarily large SHA-256 target space, it is extremely unlikely that any given hash will be below the target. As a result of this, hashing entities invest large amounts of capital into specialized hashing hardware along with the associated electricity costs in order to produce as many of these hashes as possible in a given time period. Therefore, the only way a miner can append a block to the blockchain is through a substantial commitment of operational expenditure – proof-of-work.&lt;br /&gt;
&lt;br /&gt;
=== Incentive ===&lt;br /&gt;
The first transaction in every block is called the [[Coinbase]] transaction. The Coinbase transaction is a special transaction which pays bitcoins to the miner of the block. The Coinbase payment is made up of the [[Miner subsidy|subsidy]] amount and the sum of all [[transaction fees]] paid by transactions within the mined block.&lt;br /&gt;
&lt;br /&gt;
== Competition ==&lt;br /&gt;
&lt;br /&gt;
=== Propagation and validation ===&lt;br /&gt;
If a miner finds a valid proof-of-work for the block header they are hashing, they immediately announce this by sending the entire block to other miners. Meanwhile, they start working on finding the next block in the chain. &lt;br /&gt;
&lt;br /&gt;
Competing miners receive this block and immediately check that all transactions within the block, as well as the proof-of-work are valid. If the block is valid they discontinue mining on top of the previous block and start working on hashing a new block header, building on the block just found by their competitor.&lt;br /&gt;
&lt;br /&gt;
There are incentives at play here. First, winning 'miner A' strives to get their winning block to all other miners as quickly as possible. This reduces the possibility that competing 'miner B' (who found a valid block at approximately the same time) propagates their block to some miners before 'miner A' could. This opens up the possibility that 'miner A's' block could later be [[Orphan Block|orphaned]] and the Coinbase reward rendered invalid and unusable by 'miner A'. The degree of bandwidth and connectivity to other miners can be seen as a competitive advantage and as such, the mining network tends toward a densely connected, small world structure with high bandwidth.&lt;br /&gt;
&lt;br /&gt;
There also exists a competitive advantage in validating transactions. When validating a block, each transaction's inputs must be looked up in the miner's [[VOUT|UTXO]] set to check they are unspent and the amount in satoshis is correct. Additionally, each input's locking and unlocking scripts need to be run by the miner to assess whether each transaction is valid.&lt;br /&gt;
&lt;br /&gt;
=== Rejected blocks ===&lt;br /&gt;
At any given point in time, two or more independent miners may mine a block at the same time. In this situation, nodes can be in disagreement about which of these blocks should be the tip of the blockchain.&lt;br /&gt;
&lt;br /&gt;
Miners always follow the longest chain they deem to be valid. Eventually another block will be found that builds on one of the competing chain tips. Miners then switch to this tip provided they consider it to be valid. As such, any fork scenario is eventually resolved back to one persistent chain through the actions of the majority of hash power. &lt;br /&gt;
&lt;br /&gt;
In this scenario, a block that doesn't end up forming part of the longest chain is rejected by the network and called an [[Orphan Block]]. An orphan block represent wasted effort on the behalf of a miner and an incentive to invest in infrastructure in order to reduce the frequency of these events. However, orphans do not reduce the overall revenues of the Bitcoin system as the wasted work is not factored into the difficulty adjustment, thus if a certain percentage of hashing work is wasted due to the orphaned blocks the difficulty will adjust downwards by a similar percentage, maintaining the same rate of valid block production overall.  Additionally the fee paying transactions in the orphaned block will still be valid and included in the competing block or its descendants.&lt;br /&gt;
&lt;br /&gt;
Competing valid blocks are not the only way that blocks end up being rejected. Any miner can refuse to build on any block for any reason. Such an action by a particular miner is only meaningful if the majority of miners carry out the same action. It is through this mechanism that the mining network can establish consensus on variables that are miner configurable - such as maximum block size. This is the basis of Nakamoto Consensus:&lt;br /&gt;
&lt;br /&gt;
{{quote|1=''&amp;quot; They vote with their CPU power, expressing their acceptance of valid blocks by working on extending them and rejecting invalid blocks by refusing to work on them. Any needed rules and incentives can be enforced with this consensus mechanism.&amp;quot;''}}&lt;br /&gt;
&lt;br /&gt;
== The mining ecosystem ==&lt;br /&gt;
&lt;br /&gt;
=== Asic mining ===&lt;br /&gt;
An application-specific integrated circuit, or ASIC, is a microchip designed and manufactured for a very specific purpose. ASICs designed for Bitcoin mining were first released in 2013. For the amount of power they consume, they are vastly more energy efficient than predecessor approaches to mining - using CPU, GPU or FPGA.&lt;br /&gt;
&lt;br /&gt;
=== Pooled mining ===&lt;br /&gt;
Pooled mining is the use of a block template allocation system that provides distributed hashing infrastructure updated block headers against which they perform proof of work. This system of hash allocation to nodes is a primary part of [[Nakamoto Consensus]] in that individual operators of hash power can choose to re-allocate their hash to nodes producing blocks that meet their expectations in terms of maximised profitability and adherence to the Bitcoin ruleset. Miners who distribute block templates that don't maximise profit or which attempt to implement changed rule sets risk the owners of the hash machinery they depend on re-deploying it to a different node on the network.&lt;br /&gt;
 &lt;br /&gt;
==== Stratum ====&lt;br /&gt;
Stratum is an open-source mining protocol used by many mining pools. Stratum facilitates coordination between the mining pool operator and individual mining machines.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [https://bitcoinsv.io/bitcoin.pdf Bitcoin Whitepaper]&lt;br /&gt;
&lt;br /&gt;
==Attribution==&lt;br /&gt;
This content is based on content sourced from https://en.bitcoin.it/wiki/Mining under [https://creativecommons.org/licenses/by/3.0/ Creative Commons Attribution 3.0]. Although it may have been extensively revised and updated we acknowledge the original authors.&lt;/div&gt;</summary>
		<author><name>Angus Adams</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.bitcoinsv.io/index.php?title=Mining&amp;diff=1993</id>
		<title>Mining</title>
		<link rel="alternate" type="text/html" href="https://wiki.bitcoinsv.io/index.php?title=Mining&amp;diff=1993"/>
		<updated>2020-02-17T09:40:30Z</updated>

		<summary type="html">&lt;p&gt;Angus Adams: /* Mempool */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
'''Mining''' is the process where nodes in the Bitcoin [[Network]] assemble newly broadcast [[Bitcoin Transactions|bitcoin transactions]] into a data structure called a [[block]]. Nodes then compete to append their block to the public [[Block chain|blockchain]] by repeatedly mutating the block's header data structure, usually by incrementing the nonce field, then hashing it in an attempt to find a value that satisfies a difficult [[Proof of Work|proof-of-work]]. &lt;br /&gt;
&lt;br /&gt;
When a node finds a valid proof-of-work hash for a block, it broadcasts the block to all nodes. Other nodes accept this block only if all the transactions in it are valid and have not yet been included in a block. Other nodes in the network then express their acceptance of the block by building upon it to create the next block in the chain.&lt;br /&gt;
&lt;br /&gt;
Every block is [[Block timestamp|timestamped]] and references the hash of the block preceding it. Blocks form a backward reinforcing, timestamped chain – a [[Timechain]], the precursor to the term ‘blockchain’.&lt;br /&gt;
&lt;br /&gt;
The blockchain structures itself in a manner that is computationally and economically impractical to modify by any one entity. Due to this, transactions included in the blockchain are considered immutable. In addition to this quality, the blockchain establishes an authoritative order of these transactions throughout the network by establishing which out of any pair of conflicting transactions was seen first, thereby protecting users from [[Double-spending|attempts to re-spend coins]] that have already been spent elsewhere. This is the key innovation of mining and of bitcoin.&lt;br /&gt;
&lt;br /&gt;
=== Nodes ===&lt;br /&gt;
Nodes are entities that run software that carries out the mining functions above. Nodes communicate using a [[P2P Network]] with its own protocol, and are the authors of the Bitcoin ledger and enforcers of the [[protocol]] rules.&lt;br /&gt;
&lt;br /&gt;
Interestingly, the bitcoin whitepaper makes no reference to the term ‘miner’ or the concept of ‘mining’. These terms are encompassed within Satoshi Nakamoto’s description of a ‘node’. It is possible however to run the node client software without performing block assembly or proof-of-work. Such a setup can be used as an interface to the network for other systems such as block explorers, payment gateways and archives. Eventually it is expected that customised client software will be developed for each of these services so they will no longer be dependent on the node client for them to operate.&lt;br /&gt;
&lt;br /&gt;
Computers that run a node client but which do not perform proof-of-work cannot append new blocks to the blockchain. This means they can neither express acceptance of valid blocks by working on extending them, nor reject invalid blocks by refusing to work on them. These computers exist as passive entities that follow the gatekeepers of the network, the miners.&lt;br /&gt;
&lt;br /&gt;
=== Mempool ===&lt;br /&gt;
Before a bitcoin transaction can be committed to the blockchain it needs to be received and validated by a miner. If the miner deems the transaction valid, they add the transaction to one of several [[Protocol#mempool|mempools]]. Mempools are temporary transaction stores and can be used to hold transactions grouped in different ways such as transactions to be mined in the next block, transactions to watch, or transactions which cannot be mined due to an nLocktime/nSequence lock.&lt;br /&gt;
&lt;br /&gt;
It is important to note every miner has their own mempools and that mempools vary across miners. It is also important to note that an individual transaction can be included in different mempools at the same time. &lt;br /&gt;
&lt;br /&gt;
A miner takes the transactions to be mined in the next block and hashes them into a [[Protocol#Merkle_Trees|merkle tree]] structure and includes the resulting merkle root within a candidate [[Block hashing algorithm|block header]]. The miner then hashes this candidate block header, attempting to find a valid proof-of-work.&lt;br /&gt;
&lt;br /&gt;
=== Hashing ===&lt;br /&gt;
A hash is a function that converts a string of data into a fixed length value that represents the original string, called the hash value. Every hash value is unique. &lt;br /&gt;
&lt;br /&gt;
Hashing is a one-way function, meaning it is infeasible to determine what the input data is by looking at the hash produced from it. Conversely, it is trivial to run the same input data through the same hash function and reproduce the same hash. Because of this, a hash value of input data can be thought of as the digital fingerprint of that data. In bitcoin mining, the input data is the 80-byte [[Block hashing algorithm|block header]].&lt;br /&gt;
&lt;br /&gt;
The hashing algorithm used in bitcoin mining is [[SHA-256]]. SHA-256 stands for Secure Hash Algorithm – 256 bit. Passing the same block header data through this algorithm will always output the same 256-bit number. However if the header data is modified even by a single a bit a completely different and unrelated 256-bit number will result. &lt;br /&gt;
&lt;br /&gt;
Bitcoin mining passes the block header data through the SHA-256 algorithm twice (SHA-256d).&lt;br /&gt;
&lt;br /&gt;
=== Proof-of-work ===&lt;br /&gt;
Bitcoin uses a [[Proof of Work]] function based on the earlier work of [[hashcash]].&lt;br /&gt;
&lt;br /&gt;
A miner cannot create a new block without finding a valid proof-of-work hash for the block header they are hashing. To be valid, the SHA-256d hash (which is just a number) of the block header must be less than another number, called the [[target]]. The target value is defined by the [[Block hashing algorithm|Bits]] field in the block header that is being hashed.&lt;br /&gt;
 &lt;br /&gt;
The target adjusts so that the average time it takes for the entire network to find a valid proof-of-work hash is ten minutes. &lt;br /&gt;
&lt;br /&gt;
Because of the extraordinarily large SHA-256 target space, it is extremely unlikely that any given hash will be below the target. As a result of this, hashing entities invest large amounts of capital into specialized hashing hardware along with the associated electricity costs in order to produce as many of these hashes as possible in a given time period. Therefore, the only way a miner can append a block to the blockchain is through a substantial commitment of operational expenditure – proof-of-work.&lt;br /&gt;
&lt;br /&gt;
=== Incentive ===&lt;br /&gt;
The first transaction in every block is called the [[Coinbase]] transaction. The Coinbase transaction is a special transaction which pays bitcoins to the miner of the block. The Coinbase payment is made up of the [[Miner subsidy|subsidy]] amount and the sum of all [[transaction fees]] paid by transactions within the mined block.&lt;br /&gt;
&lt;br /&gt;
== Competition ==&lt;br /&gt;
&lt;br /&gt;
=== Propagation and validation ===&lt;br /&gt;
If a miner finds a valid proof-of-work for the block header they are hashing, they immediately announce this by sending the entire block to other miners. Meanwhile, they start working on finding the next block in the chain. &lt;br /&gt;
&lt;br /&gt;
Competing miners receive this block and immediately check that all transactions within the block, as well as the proof-of-work are valid. If the block is valid they discontinue mining on top of the previous block and start working on hashing a new block header, building on the block just found by their competitor.&lt;br /&gt;
&lt;br /&gt;
There are incentives at play here. First, winning 'miner A' strives to get their winning block to all other miners as quickly as possible. This reduces the possibility that competing 'miner B' (who found a valid block at approximately the same time) propagates their block to some miners before 'miner A' could. This opens up the possibility that 'miner A's' block could later be [[Orphan Block|orphaned]] and the Coinbase reward rendered invalid and unusable by 'miner A'. The degree of bandwidth and connectivity to other miners can be seen as a competitive advantage and as such, the mining network tends toward a densely connected, small world structure with high bandwidth.&lt;br /&gt;
&lt;br /&gt;
There also exists a competitive advantage in validating transactions. When validating a block, each transaction's inputs must be looked up in the miner's [[VOUT|UTXO]] set to check they are unspent and the amount in satoshis is correct. Additionally, each input's locking and unlocking scripts need to be run by the miner to assess whether each transaction is valid.&lt;br /&gt;
&lt;br /&gt;
=== Rejected blocks ===&lt;br /&gt;
At any given point in time, two or more independent miners may mine a block at the same time. In this situation, nodes can be in disagreement about which of these blocks should be the tip of the blockchain.&lt;br /&gt;
&lt;br /&gt;
Miners always follow the longest chain they deem to be valid. Eventually another block will be found that builds on one of the competing chain tips. Miners then switch to this tip provided they consider it to be valid. As such, any fork scenario is eventually resolved back to one persistent chain through the actions of the majority of hash power. &lt;br /&gt;
&lt;br /&gt;
In this scenario, blocks that don't end up forming part of the longest chain are rejected by the network and are called orphans. Orphaned blocks represent wasted effort on the behalf of a miner and an incentive to invest in infrastructure in order to reduce the frequency of these events. However, orphans do not reduce the overall revenues of the Bitcoin system as the wasted work is not factored into the difficulty adjustment, thus if a certain percentage of hashing work is wasted due to the orphaned blocks the difficulty will adjust downwards by a similar percentage, maintaining the same rate of valid block production overall.  Additionally the fee paying transactions in the orphaned block will still be valid and included in the competing block or its descendants.&lt;br /&gt;
&lt;br /&gt;
Competing valid blocks are not the only way that blocks end up being rejected. Any miner can refuse to build on any block for any reason. Such an action by a particular miner is only meaningful if the majority of miners carry out the same action. It is through this mechanism that the mining network can establish consensus on variables that are miner configurable - such as maximum block size. This is the basis of Nakamoto Consensus:&lt;br /&gt;
&lt;br /&gt;
&amp;quot;They vote with their CPU power, expressing their acceptance of valid blocks by working on extending them and rejecting invalid blocks by refusing to work on them. Any needed rules and incentives can be enforced with this consensus mechanism.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
== The mining ecosystem ==&lt;br /&gt;
&lt;br /&gt;
=== Asic mining ===&lt;br /&gt;
An application-specific integrated circuit, or ASIC, is a microchip designed and manufactured for a very specific purpose. ASICs designed for Bitcoin mining were first released in 2013. For the amount of power they consume, they are vastly more energy efficient than predecessor approaches to mining - using CPU, GPU or FPGA.&lt;br /&gt;
&lt;br /&gt;
=== Pooled mining ===&lt;br /&gt;
As more and more miners competed for the limited supply of blocks, individuals found that they were working for months without finding a block and receiving any reward for their mining efforts. To address the variance in their income, miners started organizing themselves into pools so that blocks could be found more frequently and with rewards distributed among participating miners proportionally to their work contribution.&lt;br /&gt;
 &lt;br /&gt;
==== Stratum ====&lt;br /&gt;
Stratum is an open-source mining protocol used by many mining pools. Stratum facilitates coordination between the mining pool operator and individual mining machines.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [https://bitcoinsv.io/bitcoin.pdf Bitcoin Whitepaper]&lt;/div&gt;</summary>
		<author><name>Angus Adams</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.bitcoinsv.io/index.php?title=Mining&amp;diff=1992</id>
		<title>Mining</title>
		<link rel="alternate" type="text/html" href="https://wiki.bitcoinsv.io/index.php?title=Mining&amp;diff=1992"/>
		<updated>2020-02-17T09:36:46Z</updated>

		<summary type="html">&lt;p&gt;Angus Adams: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
'''Mining''' is the process where nodes in the Bitcoin [[Network]] assemble newly broadcast [[Bitcoin Transactions|bitcoin transactions]] into a data structure called a [[block]]. Nodes then compete to append their block to the public [[Block chain|blockchain]] by repeatedly mutating the block's header data structure, usually by incrementing the nonce field, then hashing it in an attempt to find a value that satisfies a difficult [[Proof of Work|proof-of-work]]. &lt;br /&gt;
&lt;br /&gt;
When a node finds a valid proof-of-work hash for a block, it broadcasts the block to all nodes. Other nodes accept this block only if all the transactions in it are valid and have not yet been included in a block. Other nodes in the network then express their acceptance of the block by building upon it to create the next block in the chain.&lt;br /&gt;
&lt;br /&gt;
Every block is [[Block timestamp|timestamped]] and references the hash of the block preceding it. Blocks form a backward reinforcing, timestamped chain – a [[Timechain]], the precursor to the term ‘blockchain’.&lt;br /&gt;
&lt;br /&gt;
The blockchain structures itself in a manner that is computationally and economically impractical to modify by any one entity. Due to this, transactions included in the blockchain are considered immutable. In addition to this quality, the blockchain establishes an authoritative order of these transactions throughout the network by establishing which out of any pair of conflicting transactions was seen first, thereby protecting users from [[Double-spending|attempts to re-spend coins]] that have already been spent elsewhere. This is the key innovation of mining and of bitcoin.&lt;br /&gt;
&lt;br /&gt;
=== Nodes ===&lt;br /&gt;
Nodes are entities that run software that carries out the mining functions above. Nodes communicate using a [[P2P Network]] with its own protocol, and are the authors of the Bitcoin ledger and enforcers of the [[protocol]] rules.&lt;br /&gt;
&lt;br /&gt;
Interestingly, the bitcoin whitepaper makes no reference to the term ‘miner’ or the concept of ‘mining’. These terms are encompassed within Satoshi Nakamoto’s description of a ‘node’. It is possible however to run the node client software without performing block assembly or proof-of-work. Such a setup can be used as an interface to the network for other systems such as block explorers, payment gateways and archives. Eventually it is expected that customised client software will be developed for each of these services so they will no longer be dependent on the node client for them to operate.&lt;br /&gt;
&lt;br /&gt;
Computers that run a node client but which do not perform proof-of-work cannot append new blocks to the blockchain. This means they can neither express acceptance of valid blocks by working on extending them, nor reject invalid blocks by refusing to work on them. These computers exist as passive entities that follow the gatekeepers of the network, the miners.&lt;br /&gt;
&lt;br /&gt;
=== Mempool ===&lt;br /&gt;
Before a bitcoin transaction can be committed to the blockchain it needs to be received and validated by a miner. If the miner deems the transaction valid, they add the transaction to one of several [[Protocol#mempool|mempools]]. Mempools are temporary transaction stores and can be used to hold transactions grouped in different ways such as transactions to be mined in the next block, transactions to watch, or transactions which cannot be mined due to an nLocktime/nSequence lock.&lt;br /&gt;
&lt;br /&gt;
It is important to note every miner has their own mempools and that mempools vary across miners. It is also important to note that an individual transaction can be included in different mempools at the same time. &lt;br /&gt;
&lt;br /&gt;
A miner takes the transactions to be mined in the next block and hashes them into a [[Protocol#Merkle_Trees|merkle tree]] structure and includes the resulting merkle root within a block header candidate [[Block hashing algorithm|block header]]. The miner then hashes this candidate block header, attempting to find a valid proof-of-work.&lt;br /&gt;
&lt;br /&gt;
=== Hashing ===&lt;br /&gt;
A hash is a function that converts a string of data into a fixed length value that represents the original string, called the hash value. Every hash value is unique. &lt;br /&gt;
&lt;br /&gt;
Hashing is a one-way function, meaning it is infeasible to determine what the input data is by looking at the hash produced from it. Conversely, it is trivial to run the same input data through the same hash function and reproduce the same hash. Because of this, a hash value of input data can be thought of as the digital fingerprint of that data. In bitcoin mining, the input data is the 80-byte [[Block hashing algorithm|block header]].&lt;br /&gt;
&lt;br /&gt;
The hashing algorithm used in bitcoin mining is [[SHA-256]]. SHA-256 stands for Secure Hash Algorithm – 256 bit. Passing the same block header data through this algorithm will always output the same 256-bit number. However if the header data is modified even by a single a bit a completely different and unrelated 256-bit number will result. &lt;br /&gt;
&lt;br /&gt;
Bitcoin mining passes the block header data through the SHA-256 algorithm twice (SHA-256d).&lt;br /&gt;
&lt;br /&gt;
=== Proof-of-work ===&lt;br /&gt;
Bitcoin uses a [[Proof of Work]] function based on the earlier work of [[hashcash]].&lt;br /&gt;
&lt;br /&gt;
A miner cannot create a new block without finding a valid proof-of-work hash for the block header they are hashing. To be valid, the SHA-256d hash (which is just a number) of the block header must be less than another number, called the [[target]]. The target value is defined by the [[Block hashing algorithm|Bits]] field in the block header that is being hashed.&lt;br /&gt;
 &lt;br /&gt;
The target adjusts so that the average time it takes for the entire network to find a valid proof-of-work hash is ten minutes. &lt;br /&gt;
&lt;br /&gt;
Because of the extraordinarily large SHA-256 target space, it is extremely unlikely that any given hash will be below the target. As a result of this, hashing entities invest large amounts of capital into specialized hashing hardware along with the associated electricity costs in order to produce as many of these hashes as possible in a given time period. Therefore, the only way a miner can append a block to the blockchain is through a substantial commitment of operational expenditure – proof-of-work.&lt;br /&gt;
&lt;br /&gt;
=== Incentive ===&lt;br /&gt;
The first transaction in every block is called the [[Coinbase]] transaction. The Coinbase transaction is a special transaction which pays bitcoins to the miner of the block. The Coinbase payment is made up of the [[Miner subsidy|subsidy]] amount and the sum of all [[transaction fees]] paid by transactions within the mined block.&lt;br /&gt;
&lt;br /&gt;
== Competition ==&lt;br /&gt;
&lt;br /&gt;
=== Propagation and validation ===&lt;br /&gt;
If a miner finds a valid proof-of-work for the block header they are hashing, they immediately announce this by sending the entire block to other miners. Meanwhile, they start working on finding the next block in the chain. &lt;br /&gt;
&lt;br /&gt;
Competing miners receive this block and immediately check that all transactions within the block, as well as the proof-of-work are valid. If the block is valid they discontinue mining on top of the previous block and start working on hashing a new block header, building on the block just found by their competitor.&lt;br /&gt;
&lt;br /&gt;
There are incentives at play here. First, winning 'miner A' strives to get their winning block to all other miners as quickly as possible. This reduces the possibility that competing 'miner B' (who found a valid block at approximately the same time) propagates their block to some miners before 'miner A' could. This opens up the possibility that 'miner A's' block could later be [[Orphan Block|orphaned]] and the Coinbase reward rendered invalid and unusable by 'miner A'. The degree of bandwidth and connectivity to other miners can be seen as a competitive advantage and as such, the mining network tends toward a densely connected, small world structure with high bandwidth.&lt;br /&gt;
&lt;br /&gt;
There also exists a competitive advantage in validating transactions. When validating a block, each transaction's inputs must be looked up in the miner's [[VOUT|UTXO]] set to check they are unspent and the amount in satoshis is correct. Additionally, each input's locking and unlocking scripts need to be run by the miner to assess whether each transaction is valid.&lt;br /&gt;
&lt;br /&gt;
=== Rejected blocks ===&lt;br /&gt;
At any given point in time, two or more independent miners may mine a block at the same time. In this situation, nodes can be in disagreement about which of these blocks should be the tip of the blockchain.&lt;br /&gt;
&lt;br /&gt;
Miners always follow the longest chain they deem to be valid. Eventually another block will be found that builds on one of the competing chain tips. Miners then switch to this tip provided they consider it to be valid. As such, any fork scenario is eventually resolved back to one persistent chain through the actions of the majority of hash power. &lt;br /&gt;
&lt;br /&gt;
In this scenario, blocks that don't end up forming part of the longest chain are rejected by the network and are called orphans. Orphaned blocks represent wasted effort on the behalf of a miner and an incentive to invest in infrastructure in order to reduce the frequency of these events. However, orphans do not reduce the overall revenues of the Bitcoin system as the wasted work is not factored into the difficulty adjustment, thus if a certain percentage of hashing work is wasted due to the orphaned blocks the difficulty will adjust downwards by a similar percentage, maintaining the same rate of valid block production overall.  Additionally the fee paying transactions in the orphaned block will still be valid and included in the competing block or its descendants.&lt;br /&gt;
&lt;br /&gt;
Competing valid blocks are not the only way that blocks end up being rejected. Any miner can refuse to build on any block for any reason. Such an action by a particular miner is only meaningful if the majority of miners carry out the same action. It is through this mechanism that the mining network can establish consensus on variables that are miner configurable - such as maximum block size. This is the basis of Nakamoto Consensus:&lt;br /&gt;
&lt;br /&gt;
&amp;quot;They vote with their CPU power, expressing their acceptance of valid blocks by working on extending them and rejecting invalid blocks by refusing to work on them. Any needed rules and incentives can be enforced with this consensus mechanism.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
== The mining ecosystem ==&lt;br /&gt;
&lt;br /&gt;
=== Asic mining ===&lt;br /&gt;
An application-specific integrated circuit, or ASIC, is a microchip designed and manufactured for a very specific purpose. ASICs designed for Bitcoin mining were first released in 2013. For the amount of power they consume, they are vastly more energy efficient than predecessor approaches to mining - using CPU, GPU or FPGA.&lt;br /&gt;
&lt;br /&gt;
=== Pooled mining ===&lt;br /&gt;
As more and more miners competed for the limited supply of blocks, individuals found that they were working for months without finding a block and receiving any reward for their mining efforts. To address the variance in their income, miners started organizing themselves into pools so that blocks could be found more frequently and with rewards distributed among participating miners proportionally to their work contribution.&lt;br /&gt;
 &lt;br /&gt;
==== Stratum ====&lt;br /&gt;
Stratum is an open-source mining protocol used by many mining pools. Stratum facilitates coordination between the mining pool operator and individual mining machines.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [https://bitcoinsv.io/bitcoin.pdf Bitcoin Whitepaper]&lt;/div&gt;</summary>
		<author><name>Angus Adams</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.bitcoinsv.io/index.php?title=Mining&amp;diff=1991</id>
		<title>Mining</title>
		<link rel="alternate" type="text/html" href="https://wiki.bitcoinsv.io/index.php?title=Mining&amp;diff=1991"/>
		<updated>2020-02-17T09:35:06Z</updated>

		<summary type="html">&lt;p&gt;Angus Adams: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
'''Mining''' is the process where nodes in the Bitcoin [[Network]] assemble newly broadcast [[Bitcoin Transactions|bitcoin transactions]] into a data structure called a [[block]]. Nodes then compete to append their block to the public [[Block chain|blockchain]] by repeatedly mutating the block's header data structure, usually by incrementing the nonce field, then hashing it in an attempt to find a value that satisfies a difficult [[Proof of Work|proof-of-work]]. &lt;br /&gt;
&lt;br /&gt;
When a node finds a valid proof-of-work hash for a block, it broadcasts the block to all nodes. Other nodes accept this block only if all the transactions in it are valid and have not yet been included in a block. Other nodes in the network then express their acceptance of the block by building upon it to create the next block in the chain.&lt;br /&gt;
&lt;br /&gt;
Every block is [[Block timestamp|timestamped]] and references the hash of the block preceding it. Blocks form a backward reinforcing, timestamped chain – a [[Timechain]], the precursor to the term ‘blockchain’.&lt;br /&gt;
&lt;br /&gt;
The blockchain structures itself in a manner that is computationally and eonomically impractical to modify by any one entity. Due to this, transactions included in the blockchain are considered immutable. In addition to this quality, the blockchain establishes an authoritative order of these transactions throughout the network by establishing which out of any pair of conflicting transactions was seen first, thereby protecting users from [[Double-spending|attempts to re-spend coins]] that have already been spent elsewhere. This is the key innovation of mining and of bitcoin.&lt;br /&gt;
&lt;br /&gt;
=== Nodes ===&lt;br /&gt;
Nodes are entities that run software that carries out the mining functions above. Nodes communicate using a [[P2P Network]] with its own protocol, and are the authors of the Bitcoin ledger and enforcers of the [[protocol]] rules.&lt;br /&gt;
&lt;br /&gt;
Interestingly, the bitcoin whitepaper makes no reference to the term ‘miner’ or the concept of ‘mining’. These terms are encompassed within Satoshi Nakamoto’s description of a ‘node’. It is possible however to run the node client software without performing block assembly or proof-of-work. Such a setup can be used as an interface to the network for other systems such as block explorers, payment gateways and archives. Eventually it is expected that customised client software will be developed for each of these services so they will no longer be dependent on the node client for them to operate.&lt;br /&gt;
&lt;br /&gt;
Computers that run a node client but which do not perform proof-of-work cannot append new blocks to the blockchain. This means they can neither express acceptance of valid blocks by working on extending them, nor reject invalid blocks by refusing to work on them. These computers exist as passive entities that follow the gatekeepers of the network, the miners.&lt;br /&gt;
&lt;br /&gt;
=== Mempool ===&lt;br /&gt;
Before a bitcoin transaction can be committed to the blockchain it needs to be received and validated by a miner. If the miner deems the transaction valid, they add the transaction to one of several [[Protocol#mempool|mempools]]. Mempools are temporary transaction stores and can be used to hold transactions grouped in different ways such as transactions to be mined in the next block, transactions to watch, or transactions which cannot be mined due to an nLocktime/nSequence lock.&lt;br /&gt;
&lt;br /&gt;
It is important to note every miner has their own mempools and that mempools vary across miners. It is also important to note that an individual transaction can be included in different mempools at the same time. &lt;br /&gt;
&lt;br /&gt;
A miner takes the transactions to be mined in the next block and hashes them into a [[Protocol#Merkle_Trees|merkle tree]] structure and includes the resulting merkle root within a block header candidate [[Block hashing algorithm|block header]]. The miner then hashes this candidate block header, attempting to find a valid proof-of-work.&lt;br /&gt;
&lt;br /&gt;
=== Hashing ===&lt;br /&gt;
A hash is a function that converts a string of data into a fixed length value that represents the original string, called the hash value. Every hash value is unique. &lt;br /&gt;
&lt;br /&gt;
Hashing is a one-way function, meaning it is infeasible to determine what the input data is by looking at the hash produced from it. Conversely, it is trivial to run the same input data through the same hash function and reproduce the same hash. Because of this, a hash value of input data can be thought of as the digital fingerprint of that data. In bitcoin mining, the input data is the 80-byte [[Block hashing algorithm|block header]].&lt;br /&gt;
&lt;br /&gt;
The hashing algorithm used in bitcoin mining is [[SHA-256]]. SHA-256 stands for Secure Hash Algorithm – 256 bit. Passing the same block header data through this algorithm will always output the same 256-bit number. However if the header data is modified even by a single a bit a completely different and unrelated 256-bit number will result. &lt;br /&gt;
&lt;br /&gt;
Bitcoin mining passes the block header data through the SHA-256 algorithm twice (SHA-256d).&lt;br /&gt;
&lt;br /&gt;
=== Proof-of-work ===&lt;br /&gt;
Bitcoin uses a [[Proof of Work]] function based on the earlier work of [[hashcash]].&lt;br /&gt;
&lt;br /&gt;
A miner cannot create a new block without finding a valid proof-of-work hash for the block header they are hashing. To be valid, the SHA-256d hash (which is just a number) of the block header must be less than another number, called the [[target]]. The target value is defined by the [[Block hashing algorithm|Bits]] field in the block header that is being hashed.&lt;br /&gt;
 &lt;br /&gt;
The target adjusts so that the average time it takes for the entire network to find a valid proof-of-work hash is ten minutes. &lt;br /&gt;
&lt;br /&gt;
Because of the extraordinarily large SHA-256 target space, it is extremely unlikely that any given hash will be below the target. As a result of this, hashing entities invest large amounts of capital into specialized hashing hardware along with the associated electricity costs in order to produce as many of these hashes as possible in a given time period. Therefore, the only way a miner can append a block to the blockchain is through a substantial commitment of operational expenditure – proof-of-work.&lt;br /&gt;
&lt;br /&gt;
=== Incentive ===&lt;br /&gt;
The first transaction in every block is called the [[Coinbase]] transaction. The Coinbase transaction is a special transaction which pays bitcoins to the miner of the block. The Coinbase payment is made up of the [[Miner subsidy|subsidy]] amount and the sum of all [[transaction fees]] paid by transactions within the mined block.&lt;br /&gt;
&lt;br /&gt;
== Competition ==&lt;br /&gt;
&lt;br /&gt;
=== Propagation and validation ===&lt;br /&gt;
If a miner finds a valid proof-of-work for the block header they are hashing, they immediately announce this by sending the entire block to other miners. Meanwhile, they start working on finding the next block in the chain. &lt;br /&gt;
&lt;br /&gt;
Competing miners receive this block and immediately check that all transactions within the block, as well as the proof-of-work are valid. If the block is valid they discontinue mining on top of the previous block and start working on hashing a new block header, building on the block just found by their competitor.&lt;br /&gt;
&lt;br /&gt;
There are incentives at play here. First, winning 'miner A' strives to get their winning block to all other miners as quickly as possible. This reduces the possibility that competing 'miner B' (who found a valid block at approximately the same time) propagates their block to some miners before 'miner A' could. This opens up the possibility that 'miner A's' block could later be [[Orphan Block|orphaned]] and the Coinbase reward rendered invalid and unusable by 'miner A'. The degree of bandwidth and connectivity to other miners can be seen as a competitive advantage and as such, the mining network tends toward a densely connected, small world structure with high bandwidth.&lt;br /&gt;
&lt;br /&gt;
There also exists a competitive advantage in validating transactions. When validating a block, each transaction's inputs must be looked up in the miner's [[VOUT|UTXO]] set to check they are unspent and the amount in satoshis is correct. Additionally, each input's locking and unlocking scripts need to be run by the miner to assess whether each transaction is valid.&lt;br /&gt;
&lt;br /&gt;
=== Rejected blocks ===&lt;br /&gt;
At any given point in time, two or more independent miners may mine a block at the same time. In this situation, nodes can be in disagreement about which of these blocks should be the tip of the blockchain.&lt;br /&gt;
&lt;br /&gt;
Miners always follow the longest chain they deem to be valid. Eventually another block will be found that builds on one of the competing chain tips. Miners then switch to this tip provided they consider it to be valid. As such, any fork scenario is eventually resolved back to one persistent chain through the actions of the majority of hash power. &lt;br /&gt;
&lt;br /&gt;
In this scenario, blocks that don't end up forming part of the longest chain are rejected by the network and are called orphans. Orphaned blocks represent wasted effort on the behalf of a miner and an incentive to invest in infrastructure in order to reduce the frequency of these events. However, orphans do not reduce the overall revenues of the Bitcoin system as the wasted work is not factored into the difficulty adjustment, thus if a certain percentage of hashing work is wasted due to the orphaned blocks the difficulty will adjust downwards by a similar percentage, maintaining the same rate of valid block production overall.  Additionally the fee paying transactions in the orphaned block will still be valid and included in the competing block or its descendants.&lt;br /&gt;
&lt;br /&gt;
Competing valid blocks are not the only way that blocks end up being rejected. Any miner can refuse to build on any block for any reason. Such an action by a particular miner is only meaningful if the majority of miners carry out the same action. It is through this mechanism that the mining network can establish consensus on variables that are miner configurable - such as maximum block size. This is the basis of Nakamoto Consensus:&lt;br /&gt;
&lt;br /&gt;
&amp;quot;They vote with their CPU power, expressing their acceptance of valid blocks by working on extending them and rejecting invalid blocks by refusing to work on them. Any needed rules and incentives can be enforced with this consensus mechanism.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
== The mining ecosystem ==&lt;br /&gt;
&lt;br /&gt;
=== Asic mining ===&lt;br /&gt;
An application-specific integrated circuit, or ASIC, is a microchip designed and manufactured for a very specific purpose. ASICs designed for Bitcoin mining were first released in 2013. For the amount of power they consume, they are vastly more energy efficient than predecessor approaches to mining - using CPU, GPU or FPGA.&lt;br /&gt;
&lt;br /&gt;
=== Pooled mining ===&lt;br /&gt;
As more and more miners competed for the limited supply of blocks, individuals found that they were working for months without finding a block and receiving any reward for their mining efforts. To address the variance in their income, miners started organizing themselves into pools so that blocks could be found more frequently and with rewards distributed among participating miners proportionally to their work contribution.&lt;br /&gt;
 &lt;br /&gt;
==== Stratum ====&lt;br /&gt;
Stratum is an open-source mining protocol used by many mining pools. Stratum facilitates coordination between the mining pool operator and individual mining machines.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [https://bitcoinsv.io/bitcoin.pdf Bitcoin Whitepaper]&lt;/div&gt;</summary>
		<author><name>Angus Adams</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.bitcoinsv.io/index.php?title=Mining&amp;diff=1454</id>
		<title>Mining</title>
		<link rel="alternate" type="text/html" href="https://wiki.bitcoinsv.io/index.php?title=Mining&amp;diff=1454"/>
		<updated>2020-01-23T16:07:48Z</updated>

		<summary type="html">&lt;p&gt;Angus Adams: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
'''Mining''' is the process where nodes in the Bitcoin [[Network]] assemble newly broadcast [[Bitcoin Transactions|bitcoin transactions]] into a data structure called a [[block]]. Nodes then compete to append their block to the public [[Block chain|blockchain]] by attempting to find a hash value that satisfies a difficult [[Proof of Work|proof-of-work]]. &lt;br /&gt;
&lt;br /&gt;
When a node finds a valid proof-of-work hash for a block, it broadcasts the block to all nodes. Other nodes accept this block only if all the transactions in it are valid and have not yet been included in a block. Other nodes in the network then express their acceptance of the block by building upon it to create the next block in the chain.&lt;br /&gt;
&lt;br /&gt;
Every block is [[Block timestamp|timestamped]] and references the hash of the block preceding it. Blocks form a backward reinforcing, timestamped chain – a [[Timechain]], the precursor to the term ‘blockchain’.&lt;br /&gt;
&lt;br /&gt;
The blockchain structures itself in a manner that is computationally impractical to modify by any one entity. Due to this, transactions included in the blockchain are considered immutable. In addition to this quality, the blockchain establishes an authoritative order of these transactions throughout the network, thereby protecting users from [[Double-spending|attempts to re-spend coins]] that have already been spent elsewhere. This is the key innovation of mining and of bitcoin.&lt;br /&gt;
&lt;br /&gt;
=== Nodes ===&lt;br /&gt;
Nodes are entities that run software that adheres to the bitcoin [[protocol]] and carry out the mining functions above. &lt;br /&gt;
&lt;br /&gt;
Interestingly, the bitcoin whitepaper makes no reference to the term ‘miner’ or the concept of ‘mining’. These terms are encompassed within Satoshi Nakamoto’s description of a ‘node’. It is possible however to run a node and make no attempts to find a proof-of-work. Such a setup is called a ‘listener node’ – they only participate in receiving and broadcasting transactions. &lt;br /&gt;
&lt;br /&gt;
Listener nodes perform no proof-of-work and therefore cannot append new blocks to the blockchain. They can neither express acceptance of valid blocks by working on extending them, nor reject invalid blocks by refusing to work on them. Listener nodes are passive entities that follow the gatekeepers of the network, the miners. An example of a listener node is a [[block explorer]]. Block explorers are a useful service that allow users to query the blockchain for block or transaction information.&lt;br /&gt;
&lt;br /&gt;
=== Mempool ===&lt;br /&gt;
Before a bitcoin transaction can be committed to the blockchain it needs to be received and validated by a miner. If the miner deems the transaction valid, they add the transaction to one of several [[Protocol#mempool|mempools]]. Mempools are temporary transaction stores and can be used to hold transactions grouped in different ways such as transactions to be mined in the next block, transactions to watch, or transactions which cannot be mined due to an nLocktime/nSequence interlock.&lt;br /&gt;
&lt;br /&gt;
It is important to note every miner has their own mempools and that mempools vary across miners. It is also important to note that an individual transaction can be included in different mempools at the same time. &lt;br /&gt;
&lt;br /&gt;
A miner takes the transactions to be mined in the next block and hashes them into a [[Protocol#Merkle_Trees|merkle tree]] structure and includes the resulting merkle root within a candidate [[Block hashing algorithm|block header]]. The miner then hashes this candidate block header, attempting to find a valid proof-of-work.&lt;br /&gt;
&lt;br /&gt;
=== Hashing ===&lt;br /&gt;
A hash is a function that converts a string of data into a fixed length value that represents the original string, called the hash value. Every hash value is unique. &lt;br /&gt;
&lt;br /&gt;
Hashing is a one-way function, meaning it is infeasible to determine what the input data is by looking at the hash produced from it. Conversely, it is trivial to run the same input data through the same hash function and reproduce the same hash. Because of this, a hash value of input data can be thought of as the digital fingerprint of that data. In bitcoin mining, the input data is the 80-byte [[Block hashing algorithm|block header]].&lt;br /&gt;
&lt;br /&gt;
The hashing algorithm used in bitcoin mining is [[SHA-256]]. SHA-256 stands for Secure Hash Algorithm – 256 bit. Passing the block header data through this algorithm will always output a 256-bit number that is unique. &lt;br /&gt;
&lt;br /&gt;
Bitcoin mining passes the block header data through the SHA-256 algorithm twice (SHA-256d). The reason for this is to accommodate the presumed future fracture of mining interests into separate specialized entities. A double hash allows for a hashing entity to indicate they have a valid proof-of-work to another mining related entity without having to reveal the block header input data.&lt;br /&gt;
&lt;br /&gt;
=== Proof-of-work ===&lt;br /&gt;
Bitcoin uses the [[hashcash]] [[Proof of Work]] function.&lt;br /&gt;
&lt;br /&gt;
A miner cannot create a new block without finding a valid proof-of-work hash for the block header they are hashing. To be valid, the SHA-256d hash (which is just a number) of the block header must be less than another number, called the [[target]]. The target value is defined by the [[Block hashing algorithm|Bits]] field in the block header that is being hashed.&lt;br /&gt;
 &lt;br /&gt;
The target adjusts so that the average time it takes to find a valid proof-of-work hash is ten minutes. &lt;br /&gt;
&lt;br /&gt;
Because of the extraordinarily large SHA-256 target space, it is extremely unlikely that any given hash will be below the target. As a result of this, hashing entities invest large amounts of capital into specialized hashing hardware along with the associated electricity costs in order to produce as many of these hashes as possible. Therefore, the only way a miner can append a block to the blockchain is through substantial financial commitment – proof-of-work.&lt;br /&gt;
&lt;br /&gt;
=== Incentive ===&lt;br /&gt;
The first transaction in every block is called the [[Coinbase]] transaction. The Coinbase transaction is a special transaction which pays bitcoins to the miner of the block. The Coinbase payment is made up of the [[Miner subsidy|subsidy]] amount and the sum of all [[transaction fees]] paid by transactions within the mined block.&lt;br /&gt;
&lt;br /&gt;
== Competition ==&lt;br /&gt;
&lt;br /&gt;
=== Propagation and validation ===&lt;br /&gt;
If a miner finds a valid proof-of-work for the block header they are hashing, they immediately announce this by sending the entire block to other miners. Meanwhile, they start working on finding the next block in the chain. &lt;br /&gt;
&lt;br /&gt;
Competing miners receive this block and immediately check that all transactions within the block, as well as the proof-of-work are valid. If the block is valid they discontinue mining on the old block height and start working on hashing a new block header, building on the block just found by their competitor.&lt;br /&gt;
&lt;br /&gt;
There are incentives at play here. First, winning 'miner A' strives to get their winning block to all other miners as quickly as possible. This reduces the possibility that competing 'miner B' (who found a valid block at approximately the same time) propagates their block to some miners before 'miner A' could. This opens up the possibility that 'miner A's' block could later be [[Orphan Block|orphaned]]. The degree of bandwidth and connectivity to other miners can be seen as a competitive advantage and as such, the mining network tends toward a densely connected, small world structure with high bandwidth.&lt;br /&gt;
&lt;br /&gt;
There also exists a competitive advantage in validating transactions. When validating a block, each transaction's inputs must be looked up in the miner's [[VOUT|UTXO]] set to check they are unspent and the amount in satoshis is correct. Additionally, each input's locking and unlocking scripts need to be run by the miner to assess whether each transaction is valid.&lt;br /&gt;
&lt;br /&gt;
=== Rejected blocks ===&lt;br /&gt;
At any given point in time, two or more independent miners may mine a block at the same time. In this situation, nodes can be in disagreement about which of these blocks should be at the top of the blockchain.&lt;br /&gt;
&lt;br /&gt;
Miners always follow the longest chain they deem to be valid, in practice this means the chain with the most chainwork - the chain with the most proof-of-work invested in it. Eventually another block will be found that builds on one of the competing chain tips. Miners then switch to this tip provided they consider it to be valid. As such, any fork scenario is eventually resolved back to one persistent chain through the actions of the majority of hash power. &lt;br /&gt;
&lt;br /&gt;
In this scenario, blocks that don't end up forming part of the longest chain are rejected by the network and are called orphans. Orphaned blocks represent wasted effort on the behalf of a miner and an incentive to invest in infrastructure in order to reduce the frequency of these events.&lt;br /&gt;
&lt;br /&gt;
Competing valid blocks are not the only way that blocks end up being rejected. Any miner can refuse to build on any block for any reason. Such an action by a particular miner is only meaningful if the majority of miners carry out the same action. It is through this mechanism that the mining network can establish consensus on variables that are miner configurable - such as maximum block size. This is the basis of Nakamoto Consensus:&lt;br /&gt;
&lt;br /&gt;
&amp;quot;They vote with their CPU power, expressing their acceptance of valid blocks by working on extending them and rejecting invalid blocks by refusing to work on them. Any needed rules and incentives can be enforced with this consensus mechanism.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
== The mining ecosystem ==&lt;br /&gt;
&lt;br /&gt;
=== Asic mining ===&lt;br /&gt;
An application-specific integrated circuit, or ASIC, is a microchip designed and manufactured for a very specific purpose. ASICs designed for Bitcoin mining were first released in 2013. For the amount of power they consume, they are vastly superior to predecessor approaches to mining - using CPU, GPU or FPGA.&lt;br /&gt;
&lt;br /&gt;
=== Pooled mining ===&lt;br /&gt;
As more and more miners competed for the limited supply of blocks, individuals found that they were working for months without finding a block and receiving any reward for their mining efforts. To address the variance in their income, miners started organizing themselves into pools so that rewards could be shared evenly.&lt;br /&gt;
&lt;br /&gt;
==== Stratum ====&lt;br /&gt;
Stratum is an open-source mining protocol used by some mining pools. Stratum facilitates coordination between the mining pool operator and individual mining machines.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [https://bitcoinsv.io/bitcoin.pdf Bitcoin Whitepaper]&lt;/div&gt;</summary>
		<author><name>Angus Adams</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.bitcoinsv.io/index.php?title=Target&amp;diff=1357</id>
		<title>Target</title>
		<link rel="alternate" type="text/html" href="https://wiki.bitcoinsv.io/index.php?title=Target&amp;diff=1357"/>
		<updated>2020-01-20T10:40:49Z</updated>

		<summary type="html">&lt;p&gt;Angus Adams: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The '''target''' is a 256-bit number (extremely large) that all Bitcoin clients share. The SHA-256 [https://wiki.bitcoinsv.io/index.php/Mining#Hashing hash] of a [[Block hashing algorithm|block's header]] must be less than or equal to the current target for the block to be accepted by the network. The lower the target, the more [[difficulty|difficult]] it is to generate a block.&lt;br /&gt;
&lt;br /&gt;
It's important to realize that block generation is not a long, set problem (like doing a million hashes), but more like a lottery. Each hash is a random number between 0 and the maximum value of a 256-bit number (2^256-1). If a hash is below the target, the node wins. If not, you increment the nonce (completely changing the hash) and try again. &lt;br /&gt;
&lt;br /&gt;
The bitcoin network tries to produce one block every ten minutes on average. As mining hash power changes over time, it achieves this through changing the target value.&lt;br /&gt;
&lt;br /&gt;
Historically (prior to forking from BTC in August 2017), Bitcoin changed its target every 2016 blocks (exactly two weeks if a block time of 10 minutes was kept perfectly). This change in the target is known as a 'difficulty adjustment'. Under the original difficulty adjustment paradigm, when adjusting the target, every bitcoin client compared the actual time it took to generate 2016 blocks with the two week goal, and modified the target by the percentage difference. A single retarget never changes the target by more than a factor of 4 either way to prevent large changes in difficulty.&lt;br /&gt;
&lt;br /&gt;
Post forking from BTC in August 2017, bitcoin changed the original difficulty adjustment algorithm to what was named the Emergency Difficulty Adjustment (EDA) algorithm. The EDA had the capacity to update the target value every time a new block was found (as opposed to every 2016 blocks), while still targeting a ten minute block time average. The EDA was changed to the Difficulty Adjustment Algorithm (DAA) on 17 November 2017 to address instabilities associated with the EDA. The DAA uses a moving average of the last 144 blocks to determine changes to the target and like the EDA, the target can change every block. &lt;br /&gt;
&lt;br /&gt;
The reason the EDA (and later, it's improvement, the DAA) needed to be implemented was because of the fork from BTC (creating BCH) in August 2017. Because it was expected that BCH would garner significantly less hash power than BTC, measures were put in place so that block production on BCH would not slow to a crawl due to inheriting BTC's target difficulty and a small number of miners. &lt;br /&gt;
&lt;br /&gt;
It is proposed that bitcoin will move back to the original difficulty adjustment algorithm (still used by BTC) in the future.&lt;br /&gt;
&lt;br /&gt;
===How is the target stored in blocks?===&lt;br /&gt;
Each block stores a packed representation in its block header (called [[Block hashing algorithm|Bits]]) for its actual hexadecimal target. The target can be derived from Bits via a predefined formula. For example, if the packed target in the block is 0x1b0404cb, the hexadecimal target is:&lt;br /&gt;
 0x0404cb * 2**(8*(0x1b - 3)) = 0x00000000000404CB000000000000000000000000000000000000000000000000&lt;br /&gt;
&lt;br /&gt;
Note that the 0x0404cb value is a signed value in this format. The largest legal value for this field is 0x7fffff. To make a larger value you must shift it down one full byte. Also 0x008000 is the smallest positive valid value.&lt;br /&gt;
&lt;br /&gt;
=== What is the current target? ===&lt;br /&gt;
Check the [[Block hashing algorithm|Bits]] field of the most recent block on a [https://whatsonchain.com/ block explorer].&lt;br /&gt;
&lt;br /&gt;
=== What is the maximum target? ===&lt;br /&gt;
The maximum target used by SHA256 mining devices is:&lt;br /&gt;
 0x00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF&lt;br /&gt;
Because Bitcoin stores the target as a floating-point type, this is truncated:&lt;br /&gt;
 0x00000000FFFF0000000000000000000000000000000000000000000000000000&lt;br /&gt;
&lt;br /&gt;
The maximum target is the target used in the [[Genesis block|Genesis Block]] and represents a [[difficulty]] of 1. Its packed representation as [[Block hashing algorithm|Bits]] is 0x1d00ffff.&lt;br /&gt;
&lt;br /&gt;
Since a lower target makes Bitcoin generation more difficult, the maximum target is the ''lowest'' possible [[difficulty]].&lt;br /&gt;
&lt;br /&gt;
==Related Links==&lt;br /&gt;
See also [[Difficulty]]&lt;/div&gt;</summary>
		<author><name>Angus Adams</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.bitcoinsv.io/index.php?title=Block_timestamp&amp;diff=1065</id>
		<title>Block timestamp</title>
		<link rel="alternate" type="text/html" href="https://wiki.bitcoinsv.io/index.php?title=Block_timestamp&amp;diff=1065"/>
		<updated>2020-01-10T17:32:28Z</updated>

		<summary type="html">&lt;p&gt;Angus Adams: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Each block contains a [http://en.wikipedia.org/wiki/Unix_time Unix time] timestamp. In addition to serving as a source of variation for the [[Block_hashing_algorithm|block hash]], they also make it more difficult for an adversary to manipulate the block chain.&lt;br /&gt;
&lt;br /&gt;
A timestamp is accepted as valid if it is greater than the median timestamp of previous 11 blocks, and less than the network-adjusted time + 2 hours. &amp;quot;Network-adjusted time&amp;quot; is the median of the timestamps returned by all nodes connected to you. As a result, block timestamps are not exactly accurate, and they do not need to be. Block times are accurate only to within an hour or two.&lt;br /&gt;
&lt;br /&gt;
Whenever a node connects to another node, it gets a UTC timestamp from it, and stores its offset from node-local UTC. The network-adjusted time is then the node-local UTC plus the median offset from all connected nodes. Network time is never adjusted more than 70 minutes from local system time, however.&lt;br /&gt;
&lt;br /&gt;
Bitcoin uses an unsigned integer for the timestamp, so the [[:Wikipedia:Year_2038_problem|year 2038 problem]] is delayed for another 68 years.&lt;/div&gt;</summary>
		<author><name>Angus Adams</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.bitcoinsv.io/index.php?title=Block_timestamp&amp;diff=1064</id>
		<title>Block timestamp</title>
		<link rel="alternate" type="text/html" href="https://wiki.bitcoinsv.io/index.php?title=Block_timestamp&amp;diff=1064"/>
		<updated>2020-01-10T17:21:21Z</updated>

		<summary type="html">&lt;p&gt;Angus Adams: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Each block contains a [http://en.wikipedia.org/wiki/Unix_time Unix time] timestamp. In addition to serving as a source of variation for the [[Block_hashing_algorithm|block hash]], they also make it more difficult for an adversary to manipulate the block chain.&lt;br /&gt;
&lt;br /&gt;
A timestamp is accepted as valid if it is greater than the median timestamp of previous 11 blocks, and less than the network-adjusted time + 2 hours. &amp;quot;Network-adjusted time&amp;quot; is the median of the timestamps returned by all nodes connected to you. As a result block timestamps are not exactly accurate, and they do not need to be. Block times are accurate only to within an hour or two.&lt;br /&gt;
&lt;br /&gt;
Whenever a node connects to another node, it gets a UTC timestamp from it, and stores its offset from node-local UTC. The network-adjusted time is then the node-local UTC plus the median offset from all connected nodes. Network time is never adjusted more than 70 minutes from local system time, however.&lt;br /&gt;
&lt;br /&gt;
Bitcoin uses an unsigned integer for the timestamp, so the [[:Wikipedia:Year_2038_problem|year 2038 problem]] is delayed for another 68 years.&lt;/div&gt;</summary>
		<author><name>Angus Adams</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.bitcoinsv.io/index.php?title=Target&amp;diff=1063</id>
		<title>Target</title>
		<link rel="alternate" type="text/html" href="https://wiki.bitcoinsv.io/index.php?title=Target&amp;diff=1063"/>
		<updated>2020-01-10T14:46:33Z</updated>

		<summary type="html">&lt;p&gt;Angus Adams: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;''See also: [[Difficulty]]''&lt;br /&gt;
&lt;br /&gt;
The '''target''' is a 256-bit number (extremely large) that all Bitcoin clients share. The SHA-256 [https://wiki.bitcoinsv.io/index.php/Mining#Hashing hash] of a [[Block hashing algorithm|block's header]] must be less than or equal to the current target for the block to be accepted by the network. The lower the target, the more [[difficulty|difficult]] it is to generate a block.&lt;br /&gt;
&lt;br /&gt;
It's important to realize that block generation is not a long, set problem (like doing a million hashes), but more like a lottery. Each hash basically gives you a random number between 0 and the maximum value of a 256-bit number (2^256-1). If your hash is below the target, then you win. If not, you increment the nonce (completely changing the hash) and try again. &lt;br /&gt;
&lt;br /&gt;
The bitcoin network tries to produce one block every ten minutes on average. As mining hash power changes over time, it achieves this through changing the target value.&lt;br /&gt;
&lt;br /&gt;
Historically (prior to forking from BTC in August 2017), bitcoin changed its target every 2016 blocks (exactly two weeks if a block time of 10 minutes was kept perfectly). This change in the target is known as a 'difficulty adjustment'. Under the original difficulty adjustment paradigm, when adjusting the target, every bitcoin client compared the actual time it took to generate 2016 blocks with the two week goal, and modified the target by the percentage difference. A single retarget never changes the target by more than a factor of 4 either way to prevent large changes in difficulty.&lt;br /&gt;
&lt;br /&gt;
Post forking from BTC in August 2017, bitcoin changed the original difficulty adjustment algorithm to what was named the Emergency Difficulty Adjustment (EDA) algorithm. The EDA had the capacity to update the target value every time a new block was found (as opposed to every 2016 blocks), while still targeting a ten minute block time average. The EDA was changed to the Difficulty Adjustment Algorithm (DAA) on 17 November 2017 to address instabilities associated with the EDA. The DAA uses a moving average of the last 144 blocks to determine changes to the target and like the EDA, the target can change every block. &lt;br /&gt;
&lt;br /&gt;
The reason the EDA (and later, it's improvement, the DAA) needed to be implemented was because of the fork from BTC (creating BCH) in August 2017. Because it was expected that BCH would garner significantly less hash power than BTC, measures were put in place so that block production on BCH would not slow to a crawl due to inheriting BTC's target difficulty and a small number of miners. &lt;br /&gt;
&lt;br /&gt;
It is proposed that bitcoin will move back to the original difficulty adjustment algorithm (still used by BTC) in the future.&lt;br /&gt;
&lt;br /&gt;
===How is the target stored in blocks?===&lt;br /&gt;
Each block stores a packed representation in its block header (called [[Block hashing algorithm|Bits]]) for its actual hexadecimal target. The target can be derived from Bits via a predefined formula. For example, if the packed target in the block is 0x1b0404cb, the hexadecimal target is:&lt;br /&gt;
 0x0404cb * 2**(8*(0x1b - 3)) = 0x00000000000404CB000000000000000000000000000000000000000000000000&lt;br /&gt;
&lt;br /&gt;
Note that the 0x0404cb value is a signed value in this format. The largest legal value for this field is 0x7fffff. To make a larger value you must shift it down one full byte. Also 0x008000 is the smallest positive valid value.&lt;br /&gt;
&lt;br /&gt;
=== What is the current target? ===&lt;br /&gt;
Check the [[Block hashing algorithm|Bits]] field of the most recent block on a [https://whatsonchain.com/ block explorer].&lt;br /&gt;
&lt;br /&gt;
=== What is the maximum target? ===&lt;br /&gt;
The maximum target used by SHA256 mining devices is:&lt;br /&gt;
 0x00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF&lt;br /&gt;
Because Bitcoin stores the target as a floating-point type, this is truncated:&lt;br /&gt;
 0x00000000FFFF0000000000000000000000000000000000000000000000000000&lt;br /&gt;
&lt;br /&gt;
The maximum target is the target used in the [[Genesis block|Genesis Block]] and represents a [[difficulty]] of 1. Its packed representation as [[Block hashing algorithm|Bits]] is 0x1d00ffff.&lt;br /&gt;
&lt;br /&gt;
Since a lower target makes Bitcoin generation more difficult, the maximum target is the ''lowest'' possible [[difficulty]].&lt;br /&gt;
&lt;br /&gt;
==Related Links==&lt;br /&gt;
See also [[Difficulty]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Technical]]&lt;br /&gt;
[[Category:Vocabulary]]&lt;/div&gt;</summary>
		<author><name>Angus Adams</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.bitcoinsv.io/index.php?title=Difficulty&amp;diff=1062</id>
		<title>Difficulty</title>
		<link rel="alternate" type="text/html" href="https://wiki.bitcoinsv.io/index.php?title=Difficulty&amp;diff=1062"/>
		<updated>2020-01-10T14:41:44Z</updated>

		<summary type="html">&lt;p&gt;Angus Adams: /* Related Links */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;''See also: [[Target]]''&lt;br /&gt;
&lt;br /&gt;
=== What is difficulty? ===&lt;br /&gt;
&lt;br /&gt;
Difficulty is a measure of how difficult it is to find a hash below a given [[target]]. Difficulty answers the question: &amp;quot;how many times more difficult is it to mine a block now, compared with how difficult it was to mine the [[Genesis block|Genesis Block]]?&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The Bitcoin network has a global block difficulty. Valid blocks must have a hash below this target.&lt;br /&gt;
Mining pools also have a pool-specific share difficulty setting a lower limit for shares.&lt;br /&gt;
&lt;br /&gt;
=== How often does the network difficulty change? ===&lt;br /&gt;
&lt;br /&gt;
See [[Target|target]].&lt;br /&gt;
&lt;br /&gt;
=== What is the formula for difficulty? ===&lt;br /&gt;
difficulty = difficulty_1_target / current_target &lt;br /&gt;
&lt;br /&gt;
''target is a 256 bit number''&lt;br /&gt;
&lt;br /&gt;
''difficulty_1_target is the target used in the Genesis Block and represents a difficulty of 1.''&lt;br /&gt;
&lt;br /&gt;
difficulty_1_target can be different for various ways to measure difficulty.&lt;br /&gt;
Traditionally, it represents a hash where the leading 32 bits are zero and the rest are one (this is known as &amp;quot;pool difficulty&amp;quot; or &amp;quot;pdiff&amp;quot;).&lt;br /&gt;
The Bitcoin protocol represents targets as a custom floating point type with limited precision; as a result, Bitcoin clients often approximate difficulty based on this (this is known as &amp;quot;bdiff&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
===How is difficulty stored in blocks?===&lt;br /&gt;
&lt;br /&gt;
Each block stores a packed representation in its block header (called [[Block hashing algorithm|Bits]]) for its actual hexadecimal [[target]]. The target can be derived from Bits via a predefined formula. For example, if the packed target in the block is 0x1b0404cb, the hexadecimal target is:&lt;br /&gt;
 0x0404cb * 2**(8*(0x1b - 3)) = 0x00000000000404CB000000000000000000000000000000000000000000000000&lt;br /&gt;
&lt;br /&gt;
Note that the 0x0404cb value is a signed value in this format. The largest legal value for this field is 0x7fffff. To make a larger value you must shift it down one full byte. Also 0x008000 is the smallest positive valid value.&lt;br /&gt;
&lt;br /&gt;
===How is difficulty calculated? What is the difference between bdiff and pdiff?===&lt;br /&gt;
&lt;br /&gt;
The highest possible target (difficulty 1) is defined as 0x1d00ffff, which gives us a hex target of&lt;br /&gt;
 0x00ffff * 2**(8*(0x1d - 3)) = 0x00000000FFFF0000000000000000000000000000000000000000000000000000&lt;br /&gt;
&lt;br /&gt;
It should be noted that pooled mining often uses non-truncated targets, which puts &amp;quot;pool difficulty 1&amp;quot; at&lt;br /&gt;
 0x00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF&lt;br /&gt;
&lt;br /&gt;
So the difficulty at 0x1b0404cb is therefore:&lt;br /&gt;
 0x00000000FFFF0000000000000000000000000000000000000000000000000000 /&lt;br /&gt;
 0x00000000000404CB000000000000000000000000000000000000000000000000 &lt;br /&gt;
 = 16307.420938523983 (bdiff)&lt;br /&gt;
And:&lt;br /&gt;
 0x00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF /&lt;br /&gt;
 0x00000000000404CB000000000000000000000000000000000000000000000000 &lt;br /&gt;
 = 16307.669773817162 (pdiff)&lt;br /&gt;
&lt;br /&gt;
Here's a fast way to calculate bitcoin difficulty. It uses a modified Taylor series for the logarithm (you can see tutorials on flipcode and wikipedia) and relies on logs to transform the difficulty calculation:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;cmath&amp;gt;&lt;br /&gt;
&lt;br /&gt;
inline float fast_log(float val)&lt;br /&gt;
{&lt;br /&gt;
   int * const exp_ptr = reinterpret_cast &amp;lt;int *&amp;gt;(&amp;amp;val);&lt;br /&gt;
   int x = *exp_ptr;&lt;br /&gt;
   const int log_2 = ((x &amp;gt;&amp;gt; 23) &amp;amp; 255) - 128;&lt;br /&gt;
   x &amp;amp;= ~(255 &amp;lt;&amp;lt; 23);&lt;br /&gt;
   x += 127 &amp;lt;&amp;lt; 23;&lt;br /&gt;
   *exp_ptr = x;&lt;br /&gt;
&lt;br /&gt;
   val = ((-1.0f/3) * val + 2) * val - 2.0f/3;&lt;br /&gt;
   return ((val + log_2) * 0.69314718f);&lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
float difficulty(unsigned int bits)&lt;br /&gt;
{&lt;br /&gt;
    static double max_body = fast_log(0x00ffff), scaland = fast_log(256);&lt;br /&gt;
    return exp(max_body - fast_log(bits &amp;amp; 0x00ffffff) + scaland * (0x1d - ((bits &amp;amp; 0xff000000) &amp;gt;&amp;gt; 24)));&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
    std::cout &amp;lt;&amp;lt; difficulty(0x1b0404cb) &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To see the math to go from the normal difficulty calculations (which require large big ints bigger than the space in any normal integer) to the calculation above, here's some python:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import decimal, math&lt;br /&gt;
l = math.log&lt;br /&gt;
e = math.e&lt;br /&gt;
&lt;br /&gt;
print 0x00ffff * 2**(8*(0x1d - 3)) / float(0x0404cb * 2**(8*(0x1b - 3)))&lt;br /&gt;
print l(0x00ffff * 2**(8*(0x1d - 3)) / float(0x0404cb * 2**(8*(0x1b - 3))))&lt;br /&gt;
print l(0x00ffff * 2**(8*(0x1d - 3))) - l(0x0404cb * 2**(8*(0x1b - 3)))&lt;br /&gt;
print l(0x00ffff) + l(2**(8*(0x1d - 3))) - l(0x0404cb) - l(2**(8*(0x1b - 3)))&lt;br /&gt;
print l(0x00ffff) + (8*(0x1d - 3))*l(2) - l(0x0404cb) - (8*(0x1b - 3))*l(2)&lt;br /&gt;
print l(0x00ffff / float(0x0404cb)) + (8*(0x1d - 3))*l(2) - (8*(0x1b - 3))*l(2)&lt;br /&gt;
print l(0x00ffff / float(0x0404cb)) + (0x1d - 0x1b)*l(2**8)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== What is the current difficulty? ===&lt;br /&gt;
[https://whatsonchain.com/ Current difficulty]&lt;br /&gt;
&lt;br /&gt;
=== What is the maximum difficulty? ===&lt;br /&gt;
&lt;br /&gt;
There is no minimum target. The maximum difficulty is roughly: maximum_target / 1 (since 0 would result in infinity), which is a ridiculously huge number (about 2^224).&lt;br /&gt;
&lt;br /&gt;
The actual maximum difficulty is when current_target=0, but we would not be able to calculate the difficulty if that happened. (fortunately it never will, so we're ok.)&lt;br /&gt;
&lt;br /&gt;
=== Can the network difficulty go down? ===&lt;br /&gt;
Yes it can. See discussion in [[target]].&lt;br /&gt;
&lt;br /&gt;
=== What is the minimum difficulty? ===&lt;br /&gt;
The minimum difficulty, when the target is at the maximum allowed value, is 1. This is the difficulty of the [[Genesis block]].&lt;br /&gt;
&lt;br /&gt;
=== What network hash rate results in a given difficulty? ===&lt;br /&gt;
The difficulty is adjusted every 2016 blocks based on the [[Block_timestamp|time]] it took to find the previous 2016 blocks.  At the desired rate of one block each 10 minutes, 2016 blocks would take exactly two weeks to find.  If the previous 2016 blocks took more than two weeks to find, the difficulty is reduced.  If they took less than two weeks, the difficulty is increased.  The change in difficulty is in proportion to the amount of time over or under two weeks the previous 2016 blocks took to find.&lt;br /&gt;
&lt;br /&gt;
To find a block, the hash must be less than the target.  The hash is effectively a random number between 0 and 2**256-1.  The offset for difficulty 1 is&lt;br /&gt;
 0xffff * 2**208&lt;br /&gt;
and for difficulty D is&lt;br /&gt;
 (0xffff * 2**208)/D&lt;br /&gt;
&lt;br /&gt;
The expected number of hashes we need to calculate to find a block with difficulty D is therefore&lt;br /&gt;
 D * 2**256 / (0xffff * 2**208)&lt;br /&gt;
or just&lt;br /&gt;
 D * 2**48 / 0xffff&lt;br /&gt;
&lt;br /&gt;
The difficulty is set such that the previous 2016 blocks would have been found at the rate of one every 10 minutes, so we were calculating (D * 2**48 / 0xffff) hashes in 600 seconds.  That means the hash rate of the network was&lt;br /&gt;
 D * 2**48 / 0xffff / 600&lt;br /&gt;
over the previous 2016 blocks.  Can be further simplified to&lt;br /&gt;
 D * 2**32 / 600&lt;br /&gt;
without much loss of accuracy.&lt;br /&gt;
&lt;br /&gt;
At difficulty 1, that is around 7 Mhashes per second.&lt;br /&gt;
&lt;br /&gt;
At the time of writing, the difficulty is 22012.4941572, which means that over the previous set of 2016 blocks found the average network hash rate was&lt;br /&gt;
 22012.4941572 * 2**32 / 600 = around 157 Ghashes per second.&lt;br /&gt;
&lt;br /&gt;
=== How soon might I expect to generate a block? ===&lt;br /&gt;
The average time to find a block can be approximated by calculating:&lt;br /&gt;
 time = difficulty * 2**32 / hashrate&lt;br /&gt;
where difficulty is the current difficulty, hashrate is the number of hashes your miner calculates per second, and time is the average in seconds between the blocks you find.&lt;br /&gt;
&lt;br /&gt;
For example, using Python we calculate the average time to generate a block using a 1Ghash/s mining rig when the difficulty is 20000:&lt;br /&gt;
 $ python -c &amp;quot;print 20000 * 2**32 / 10**9 / 60 / 60.0&amp;quot;&lt;br /&gt;
 23.85&lt;br /&gt;
and find that it takes just under 24 hours on average.&lt;br /&gt;
&lt;br /&gt;
Remember - any one grinding of the hash stands the same chance of &amp;quot;winning&amp;quot; as any other.  The numbers game is how many attempts hardware can make per second.&lt;br /&gt;
&lt;br /&gt;
==Related Links==&lt;br /&gt;
&lt;br /&gt;
* See also: [[Target]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Technical]]&lt;br /&gt;
[[Category:Vocabulary]]&lt;/div&gt;</summary>
		<author><name>Angus Adams</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.bitcoinsv.io/index.php?title=Difficulty&amp;diff=1061</id>
		<title>Difficulty</title>
		<link rel="alternate" type="text/html" href="https://wiki.bitcoinsv.io/index.php?title=Difficulty&amp;diff=1061"/>
		<updated>2020-01-10T14:40:42Z</updated>

		<summary type="html">&lt;p&gt;Angus Adams: /* How soon might I expect to generate a block? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;''See also: [[Target]]''&lt;br /&gt;
&lt;br /&gt;
=== What is difficulty? ===&lt;br /&gt;
&lt;br /&gt;
Difficulty is a measure of how difficult it is to find a hash below a given [[target]]. Difficulty answers the question: &amp;quot;how many times more difficult is it to mine a block now, compared with how difficult it was to mine the [[Genesis block|Genesis Block]]?&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The Bitcoin network has a global block difficulty. Valid blocks must have a hash below this target.&lt;br /&gt;
Mining pools also have a pool-specific share difficulty setting a lower limit for shares.&lt;br /&gt;
&lt;br /&gt;
=== How often does the network difficulty change? ===&lt;br /&gt;
&lt;br /&gt;
See [[Target|target]].&lt;br /&gt;
&lt;br /&gt;
=== What is the formula for difficulty? ===&lt;br /&gt;
difficulty = difficulty_1_target / current_target &lt;br /&gt;
&lt;br /&gt;
''target is a 256 bit number''&lt;br /&gt;
&lt;br /&gt;
''difficulty_1_target is the target used in the Genesis Block and represents a difficulty of 1.''&lt;br /&gt;
&lt;br /&gt;
difficulty_1_target can be different for various ways to measure difficulty.&lt;br /&gt;
Traditionally, it represents a hash where the leading 32 bits are zero and the rest are one (this is known as &amp;quot;pool difficulty&amp;quot; or &amp;quot;pdiff&amp;quot;).&lt;br /&gt;
The Bitcoin protocol represents targets as a custom floating point type with limited precision; as a result, Bitcoin clients often approximate difficulty based on this (this is known as &amp;quot;bdiff&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
===How is difficulty stored in blocks?===&lt;br /&gt;
&lt;br /&gt;
Each block stores a packed representation in its block header (called [[Block hashing algorithm|Bits]]) for its actual hexadecimal [[target]]. The target can be derived from Bits via a predefined formula. For example, if the packed target in the block is 0x1b0404cb, the hexadecimal target is:&lt;br /&gt;
 0x0404cb * 2**(8*(0x1b - 3)) = 0x00000000000404CB000000000000000000000000000000000000000000000000&lt;br /&gt;
&lt;br /&gt;
Note that the 0x0404cb value is a signed value in this format. The largest legal value for this field is 0x7fffff. To make a larger value you must shift it down one full byte. Also 0x008000 is the smallest positive valid value.&lt;br /&gt;
&lt;br /&gt;
===How is difficulty calculated? What is the difference between bdiff and pdiff?===&lt;br /&gt;
&lt;br /&gt;
The highest possible target (difficulty 1) is defined as 0x1d00ffff, which gives us a hex target of&lt;br /&gt;
 0x00ffff * 2**(8*(0x1d - 3)) = 0x00000000FFFF0000000000000000000000000000000000000000000000000000&lt;br /&gt;
&lt;br /&gt;
It should be noted that pooled mining often uses non-truncated targets, which puts &amp;quot;pool difficulty 1&amp;quot; at&lt;br /&gt;
 0x00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF&lt;br /&gt;
&lt;br /&gt;
So the difficulty at 0x1b0404cb is therefore:&lt;br /&gt;
 0x00000000FFFF0000000000000000000000000000000000000000000000000000 /&lt;br /&gt;
 0x00000000000404CB000000000000000000000000000000000000000000000000 &lt;br /&gt;
 = 16307.420938523983 (bdiff)&lt;br /&gt;
And:&lt;br /&gt;
 0x00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF /&lt;br /&gt;
 0x00000000000404CB000000000000000000000000000000000000000000000000 &lt;br /&gt;
 = 16307.669773817162 (pdiff)&lt;br /&gt;
&lt;br /&gt;
Here's a fast way to calculate bitcoin difficulty. It uses a modified Taylor series for the logarithm (you can see tutorials on flipcode and wikipedia) and relies on logs to transform the difficulty calculation:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;cmath&amp;gt;&lt;br /&gt;
&lt;br /&gt;
inline float fast_log(float val)&lt;br /&gt;
{&lt;br /&gt;
   int * const exp_ptr = reinterpret_cast &amp;lt;int *&amp;gt;(&amp;amp;val);&lt;br /&gt;
   int x = *exp_ptr;&lt;br /&gt;
   const int log_2 = ((x &amp;gt;&amp;gt; 23) &amp;amp; 255) - 128;&lt;br /&gt;
   x &amp;amp;= ~(255 &amp;lt;&amp;lt; 23);&lt;br /&gt;
   x += 127 &amp;lt;&amp;lt; 23;&lt;br /&gt;
   *exp_ptr = x;&lt;br /&gt;
&lt;br /&gt;
   val = ((-1.0f/3) * val + 2) * val - 2.0f/3;&lt;br /&gt;
   return ((val + log_2) * 0.69314718f);&lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
float difficulty(unsigned int bits)&lt;br /&gt;
{&lt;br /&gt;
    static double max_body = fast_log(0x00ffff), scaland = fast_log(256);&lt;br /&gt;
    return exp(max_body - fast_log(bits &amp;amp; 0x00ffffff) + scaland * (0x1d - ((bits &amp;amp; 0xff000000) &amp;gt;&amp;gt; 24)));&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
    std::cout &amp;lt;&amp;lt; difficulty(0x1b0404cb) &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To see the math to go from the normal difficulty calculations (which require large big ints bigger than the space in any normal integer) to the calculation above, here's some python:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import decimal, math&lt;br /&gt;
l = math.log&lt;br /&gt;
e = math.e&lt;br /&gt;
&lt;br /&gt;
print 0x00ffff * 2**(8*(0x1d - 3)) / float(0x0404cb * 2**(8*(0x1b - 3)))&lt;br /&gt;
print l(0x00ffff * 2**(8*(0x1d - 3)) / float(0x0404cb * 2**(8*(0x1b - 3))))&lt;br /&gt;
print l(0x00ffff * 2**(8*(0x1d - 3))) - l(0x0404cb * 2**(8*(0x1b - 3)))&lt;br /&gt;
print l(0x00ffff) + l(2**(8*(0x1d - 3))) - l(0x0404cb) - l(2**(8*(0x1b - 3)))&lt;br /&gt;
print l(0x00ffff) + (8*(0x1d - 3))*l(2) - l(0x0404cb) - (8*(0x1b - 3))*l(2)&lt;br /&gt;
print l(0x00ffff / float(0x0404cb)) + (8*(0x1d - 3))*l(2) - (8*(0x1b - 3))*l(2)&lt;br /&gt;
print l(0x00ffff / float(0x0404cb)) + (0x1d - 0x1b)*l(2**8)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== What is the current difficulty? ===&lt;br /&gt;
[https://whatsonchain.com/ Current difficulty]&lt;br /&gt;
&lt;br /&gt;
=== What is the maximum difficulty? ===&lt;br /&gt;
&lt;br /&gt;
There is no minimum target. The maximum difficulty is roughly: maximum_target / 1 (since 0 would result in infinity), which is a ridiculously huge number (about 2^224).&lt;br /&gt;
&lt;br /&gt;
The actual maximum difficulty is when current_target=0, but we would not be able to calculate the difficulty if that happened. (fortunately it never will, so we're ok.)&lt;br /&gt;
&lt;br /&gt;
=== Can the network difficulty go down? ===&lt;br /&gt;
Yes it can. See discussion in [[target]].&lt;br /&gt;
&lt;br /&gt;
=== What is the minimum difficulty? ===&lt;br /&gt;
The minimum difficulty, when the target is at the maximum allowed value, is 1. This is the difficulty of the [[Genesis block]].&lt;br /&gt;
&lt;br /&gt;
=== What network hash rate results in a given difficulty? ===&lt;br /&gt;
The difficulty is adjusted every 2016 blocks based on the [[Block_timestamp|time]] it took to find the previous 2016 blocks.  At the desired rate of one block each 10 minutes, 2016 blocks would take exactly two weeks to find.  If the previous 2016 blocks took more than two weeks to find, the difficulty is reduced.  If they took less than two weeks, the difficulty is increased.  The change in difficulty is in proportion to the amount of time over or under two weeks the previous 2016 blocks took to find.&lt;br /&gt;
&lt;br /&gt;
To find a block, the hash must be less than the target.  The hash is effectively a random number between 0 and 2**256-1.  The offset for difficulty 1 is&lt;br /&gt;
 0xffff * 2**208&lt;br /&gt;
and for difficulty D is&lt;br /&gt;
 (0xffff * 2**208)/D&lt;br /&gt;
&lt;br /&gt;
The expected number of hashes we need to calculate to find a block with difficulty D is therefore&lt;br /&gt;
 D * 2**256 / (0xffff * 2**208)&lt;br /&gt;
or just&lt;br /&gt;
 D * 2**48 / 0xffff&lt;br /&gt;
&lt;br /&gt;
The difficulty is set such that the previous 2016 blocks would have been found at the rate of one every 10 minutes, so we were calculating (D * 2**48 / 0xffff) hashes in 600 seconds.  That means the hash rate of the network was&lt;br /&gt;
 D * 2**48 / 0xffff / 600&lt;br /&gt;
over the previous 2016 blocks.  Can be further simplified to&lt;br /&gt;
 D * 2**32 / 600&lt;br /&gt;
without much loss of accuracy.&lt;br /&gt;
&lt;br /&gt;
At difficulty 1, that is around 7 Mhashes per second.&lt;br /&gt;
&lt;br /&gt;
At the time of writing, the difficulty is 22012.4941572, which means that over the previous set of 2016 blocks found the average network hash rate was&lt;br /&gt;
 22012.4941572 * 2**32 / 600 = around 157 Ghashes per second.&lt;br /&gt;
&lt;br /&gt;
=== How soon might I expect to generate a block? ===&lt;br /&gt;
The average time to find a block can be approximated by calculating:&lt;br /&gt;
 time = difficulty * 2**32 / hashrate&lt;br /&gt;
where difficulty is the current difficulty, hashrate is the number of hashes your miner calculates per second, and time is the average in seconds between the blocks you find.&lt;br /&gt;
&lt;br /&gt;
For example, using Python we calculate the average time to generate a block using a 1Ghash/s mining rig when the difficulty is 20000:&lt;br /&gt;
 $ python -c &amp;quot;print 20000 * 2**32 / 10**9 / 60 / 60.0&amp;quot;&lt;br /&gt;
 23.85&lt;br /&gt;
and find that it takes just under 24 hours on average.&lt;br /&gt;
&lt;br /&gt;
Remember - any one grinding of the hash stands the same chance of &amp;quot;winning&amp;quot; as any other.  The numbers game is how many attempts hardware can make per second.&lt;br /&gt;
&lt;br /&gt;
==Related Links==&lt;br /&gt;
&lt;br /&gt;
* [https://docs.google.com/spreadsheet/ccc?key=0AiFMBvXvL2dtdEZkR2J4eU5rS3B4ei1iUmJxSWNlQ0E Bitcoin Difficulty History]&lt;br /&gt;
* [https://www.bitcoinmining.com/what-is-bitcoin-mining-difficulty/ What is Bitcoin Mining Difficulty?]&lt;br /&gt;
* See also: [[Target]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Technical]]&lt;br /&gt;
[[Category:Vocabulary]]&lt;br /&gt;
&lt;br /&gt;
[[pl:Trudność]]&lt;/div&gt;</summary>
		<author><name>Angus Adams</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.bitcoinsv.io/index.php?title=Difficulty&amp;diff=1060</id>
		<title>Difficulty</title>
		<link rel="alternate" type="text/html" href="https://wiki.bitcoinsv.io/index.php?title=Difficulty&amp;diff=1060"/>
		<updated>2020-01-10T14:38:35Z</updated>

		<summary type="html">&lt;p&gt;Angus Adams: /* How soon might I expect to generate a block? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;''See also: [[Target]]''&lt;br /&gt;
&lt;br /&gt;
=== What is difficulty? ===&lt;br /&gt;
&lt;br /&gt;
Difficulty is a measure of how difficult it is to find a hash below a given [[target]]. Difficulty answers the question: &amp;quot;how many times more difficult is it to mine a block now, compared with how difficult it was to mine the [[Genesis block|Genesis Block]]?&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The Bitcoin network has a global block difficulty. Valid blocks must have a hash below this target.&lt;br /&gt;
Mining pools also have a pool-specific share difficulty setting a lower limit for shares.&lt;br /&gt;
&lt;br /&gt;
=== How often does the network difficulty change? ===&lt;br /&gt;
&lt;br /&gt;
See [[Target|target]].&lt;br /&gt;
&lt;br /&gt;
=== What is the formula for difficulty? ===&lt;br /&gt;
difficulty = difficulty_1_target / current_target &lt;br /&gt;
&lt;br /&gt;
''target is a 256 bit number''&lt;br /&gt;
&lt;br /&gt;
''difficulty_1_target is the target used in the Genesis Block and represents a difficulty of 1.''&lt;br /&gt;
&lt;br /&gt;
difficulty_1_target can be different for various ways to measure difficulty.&lt;br /&gt;
Traditionally, it represents a hash where the leading 32 bits are zero and the rest are one (this is known as &amp;quot;pool difficulty&amp;quot; or &amp;quot;pdiff&amp;quot;).&lt;br /&gt;
The Bitcoin protocol represents targets as a custom floating point type with limited precision; as a result, Bitcoin clients often approximate difficulty based on this (this is known as &amp;quot;bdiff&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
===How is difficulty stored in blocks?===&lt;br /&gt;
&lt;br /&gt;
Each block stores a packed representation in its block header (called [[Block hashing algorithm|Bits]]) for its actual hexadecimal [[target]]. The target can be derived from Bits via a predefined formula. For example, if the packed target in the block is 0x1b0404cb, the hexadecimal target is:&lt;br /&gt;
 0x0404cb * 2**(8*(0x1b - 3)) = 0x00000000000404CB000000000000000000000000000000000000000000000000&lt;br /&gt;
&lt;br /&gt;
Note that the 0x0404cb value is a signed value in this format. The largest legal value for this field is 0x7fffff. To make a larger value you must shift it down one full byte. Also 0x008000 is the smallest positive valid value.&lt;br /&gt;
&lt;br /&gt;
===How is difficulty calculated? What is the difference between bdiff and pdiff?===&lt;br /&gt;
&lt;br /&gt;
The highest possible target (difficulty 1) is defined as 0x1d00ffff, which gives us a hex target of&lt;br /&gt;
 0x00ffff * 2**(8*(0x1d - 3)) = 0x00000000FFFF0000000000000000000000000000000000000000000000000000&lt;br /&gt;
&lt;br /&gt;
It should be noted that pooled mining often uses non-truncated targets, which puts &amp;quot;pool difficulty 1&amp;quot; at&lt;br /&gt;
 0x00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF&lt;br /&gt;
&lt;br /&gt;
So the difficulty at 0x1b0404cb is therefore:&lt;br /&gt;
 0x00000000FFFF0000000000000000000000000000000000000000000000000000 /&lt;br /&gt;
 0x00000000000404CB000000000000000000000000000000000000000000000000 &lt;br /&gt;
 = 16307.420938523983 (bdiff)&lt;br /&gt;
And:&lt;br /&gt;
 0x00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF /&lt;br /&gt;
 0x00000000000404CB000000000000000000000000000000000000000000000000 &lt;br /&gt;
 = 16307.669773817162 (pdiff)&lt;br /&gt;
&lt;br /&gt;
Here's a fast way to calculate bitcoin difficulty. It uses a modified Taylor series for the logarithm (you can see tutorials on flipcode and wikipedia) and relies on logs to transform the difficulty calculation:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;cmath&amp;gt;&lt;br /&gt;
&lt;br /&gt;
inline float fast_log(float val)&lt;br /&gt;
{&lt;br /&gt;
   int * const exp_ptr = reinterpret_cast &amp;lt;int *&amp;gt;(&amp;amp;val);&lt;br /&gt;
   int x = *exp_ptr;&lt;br /&gt;
   const int log_2 = ((x &amp;gt;&amp;gt; 23) &amp;amp; 255) - 128;&lt;br /&gt;
   x &amp;amp;= ~(255 &amp;lt;&amp;lt; 23);&lt;br /&gt;
   x += 127 &amp;lt;&amp;lt; 23;&lt;br /&gt;
   *exp_ptr = x;&lt;br /&gt;
&lt;br /&gt;
   val = ((-1.0f/3) * val + 2) * val - 2.0f/3;&lt;br /&gt;
   return ((val + log_2) * 0.69314718f);&lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
float difficulty(unsigned int bits)&lt;br /&gt;
{&lt;br /&gt;
    static double max_body = fast_log(0x00ffff), scaland = fast_log(256);&lt;br /&gt;
    return exp(max_body - fast_log(bits &amp;amp; 0x00ffffff) + scaland * (0x1d - ((bits &amp;amp; 0xff000000) &amp;gt;&amp;gt; 24)));&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
    std::cout &amp;lt;&amp;lt; difficulty(0x1b0404cb) &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To see the math to go from the normal difficulty calculations (which require large big ints bigger than the space in any normal integer) to the calculation above, here's some python:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import decimal, math&lt;br /&gt;
l = math.log&lt;br /&gt;
e = math.e&lt;br /&gt;
&lt;br /&gt;
print 0x00ffff * 2**(8*(0x1d - 3)) / float(0x0404cb * 2**(8*(0x1b - 3)))&lt;br /&gt;
print l(0x00ffff * 2**(8*(0x1d - 3)) / float(0x0404cb * 2**(8*(0x1b - 3))))&lt;br /&gt;
print l(0x00ffff * 2**(8*(0x1d - 3))) - l(0x0404cb * 2**(8*(0x1b - 3)))&lt;br /&gt;
print l(0x00ffff) + l(2**(8*(0x1d - 3))) - l(0x0404cb) - l(2**(8*(0x1b - 3)))&lt;br /&gt;
print l(0x00ffff) + (8*(0x1d - 3))*l(2) - l(0x0404cb) - (8*(0x1b - 3))*l(2)&lt;br /&gt;
print l(0x00ffff / float(0x0404cb)) + (8*(0x1d - 3))*l(2) - (8*(0x1b - 3))*l(2)&lt;br /&gt;
print l(0x00ffff / float(0x0404cb)) + (0x1d - 0x1b)*l(2**8)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== What is the current difficulty? ===&lt;br /&gt;
[https://whatsonchain.com/ Current difficulty]&lt;br /&gt;
&lt;br /&gt;
=== What is the maximum difficulty? ===&lt;br /&gt;
&lt;br /&gt;
There is no minimum target. The maximum difficulty is roughly: maximum_target / 1 (since 0 would result in infinity), which is a ridiculously huge number (about 2^224).&lt;br /&gt;
&lt;br /&gt;
The actual maximum difficulty is when current_target=0, but we would not be able to calculate the difficulty if that happened. (fortunately it never will, so we're ok.)&lt;br /&gt;
&lt;br /&gt;
=== Can the network difficulty go down? ===&lt;br /&gt;
Yes it can. See discussion in [[target]].&lt;br /&gt;
&lt;br /&gt;
=== What is the minimum difficulty? ===&lt;br /&gt;
The minimum difficulty, when the target is at the maximum allowed value, is 1. This is the difficulty of the [[Genesis block]].&lt;br /&gt;
&lt;br /&gt;
=== What network hash rate results in a given difficulty? ===&lt;br /&gt;
The difficulty is adjusted every 2016 blocks based on the [[Block_timestamp|time]] it took to find the previous 2016 blocks.  At the desired rate of one block each 10 minutes, 2016 blocks would take exactly two weeks to find.  If the previous 2016 blocks took more than two weeks to find, the difficulty is reduced.  If they took less than two weeks, the difficulty is increased.  The change in difficulty is in proportion to the amount of time over or under two weeks the previous 2016 blocks took to find.&lt;br /&gt;
&lt;br /&gt;
To find a block, the hash must be less than the target.  The hash is effectively a random number between 0 and 2**256-1.  The offset for difficulty 1 is&lt;br /&gt;
 0xffff * 2**208&lt;br /&gt;
and for difficulty D is&lt;br /&gt;
 (0xffff * 2**208)/D&lt;br /&gt;
&lt;br /&gt;
The expected number of hashes we need to calculate to find a block with difficulty D is therefore&lt;br /&gt;
 D * 2**256 / (0xffff * 2**208)&lt;br /&gt;
or just&lt;br /&gt;
 D * 2**48 / 0xffff&lt;br /&gt;
&lt;br /&gt;
The difficulty is set such that the previous 2016 blocks would have been found at the rate of one every 10 minutes, so we were calculating (D * 2**48 / 0xffff) hashes in 600 seconds.  That means the hash rate of the network was&lt;br /&gt;
 D * 2**48 / 0xffff / 600&lt;br /&gt;
over the previous 2016 blocks.  Can be further simplified to&lt;br /&gt;
 D * 2**32 / 600&lt;br /&gt;
without much loss of accuracy.&lt;br /&gt;
&lt;br /&gt;
At difficulty 1, that is around 7 Mhashes per second.&lt;br /&gt;
&lt;br /&gt;
At the time of writing, the difficulty is 22012.4941572, which means that over the previous set of 2016 blocks found the average network hash rate was&lt;br /&gt;
 22012.4941572 * 2**32 / 600 = around 157 Ghashes per second.&lt;br /&gt;
&lt;br /&gt;
=== How soon might I expect to generate a block? ===&lt;br /&gt;
The average time to find a block can be approximated by calculating:&lt;br /&gt;
 time = difficulty * 2**32 / hashrate&lt;br /&gt;
where difficulty is the current difficulty, hashrate is the number of hashes your miner calculates per second, and time is the average in seconds between the blocks you find.&lt;br /&gt;
&lt;br /&gt;
For example, using Python we calculate the average time to generate a block using a 1Ghash/s mining rig when the difficulty is 20000:&lt;br /&gt;
 $ python -c &amp;quot;print 20000 * 2**32 / 10**9 / 60 / 60.0&amp;quot;&lt;br /&gt;
 23.85&lt;br /&gt;
and find that it takes just under 24 hours on average.&lt;br /&gt;
&lt;br /&gt;
* Any one grinding of the hash stands the same chance of &amp;quot;winning&amp;quot; as any other.  The numbers game is how many attempts your hardware can make per second.&lt;br /&gt;
* You need to know the difficulty (above) and your khash/sec rate (reported by the client).&lt;br /&gt;
** [[Mining Hardware Comparison]] has some stats that may help you predict what you could get.&lt;br /&gt;
* Visit a calculator or perform the maths yourself,&lt;br /&gt;
** http://www.alloscomp.com/bitcoin/calculator.php&lt;br /&gt;
** http://www.vnbitcoin.org/bitcoincalculator.php&lt;br /&gt;
** https://bitknock.com/calculator&lt;br /&gt;
**https://99bitcoins.com/bitcoin-mining-calculator&lt;br /&gt;
* Remember it's just probability!  There are no guarantees you will win every N days.&lt;br /&gt;
&lt;br /&gt;
==Related Links==&lt;br /&gt;
&lt;br /&gt;
* [https://docs.google.com/spreadsheet/ccc?key=0AiFMBvXvL2dtdEZkR2J4eU5rS3B4ei1iUmJxSWNlQ0E Bitcoin Difficulty History]&lt;br /&gt;
* [https://www.bitcoinmining.com/what-is-bitcoin-mining-difficulty/ What is Bitcoin Mining Difficulty?]&lt;br /&gt;
* See also: [[Target]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Technical]]&lt;br /&gt;
[[Category:Vocabulary]]&lt;br /&gt;
&lt;br /&gt;
[[pl:Trudność]]&lt;/div&gt;</summary>
		<author><name>Angus Adams</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.bitcoinsv.io/index.php?title=Difficulty&amp;diff=1059</id>
		<title>Difficulty</title>
		<link rel="alternate" type="text/html" href="https://wiki.bitcoinsv.io/index.php?title=Difficulty&amp;diff=1059"/>
		<updated>2020-01-10T14:34:02Z</updated>

		<summary type="html">&lt;p&gt;Angus Adams: /* What is the minimum difficulty? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;''See also: [[Target]]''&lt;br /&gt;
&lt;br /&gt;
=== What is difficulty? ===&lt;br /&gt;
&lt;br /&gt;
Difficulty is a measure of how difficult it is to find a hash below a given [[target]]. Difficulty answers the question: &amp;quot;how many times more difficult is it to mine a block now, compared with how difficult it was to mine the [[Genesis block|Genesis Block]]?&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The Bitcoin network has a global block difficulty. Valid blocks must have a hash below this target.&lt;br /&gt;
Mining pools also have a pool-specific share difficulty setting a lower limit for shares.&lt;br /&gt;
&lt;br /&gt;
=== How often does the network difficulty change? ===&lt;br /&gt;
&lt;br /&gt;
See [[Target|target]].&lt;br /&gt;
&lt;br /&gt;
=== What is the formula for difficulty? ===&lt;br /&gt;
difficulty = difficulty_1_target / current_target &lt;br /&gt;
&lt;br /&gt;
''target is a 256 bit number''&lt;br /&gt;
&lt;br /&gt;
''difficulty_1_target is the target used in the Genesis Block and represents a difficulty of 1.''&lt;br /&gt;
&lt;br /&gt;
difficulty_1_target can be different for various ways to measure difficulty.&lt;br /&gt;
Traditionally, it represents a hash where the leading 32 bits are zero and the rest are one (this is known as &amp;quot;pool difficulty&amp;quot; or &amp;quot;pdiff&amp;quot;).&lt;br /&gt;
The Bitcoin protocol represents targets as a custom floating point type with limited precision; as a result, Bitcoin clients often approximate difficulty based on this (this is known as &amp;quot;bdiff&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
===How is difficulty stored in blocks?===&lt;br /&gt;
&lt;br /&gt;
Each block stores a packed representation in its block header (called [[Block hashing algorithm|Bits]]) for its actual hexadecimal [[target]]. The target can be derived from Bits via a predefined formula. For example, if the packed target in the block is 0x1b0404cb, the hexadecimal target is:&lt;br /&gt;
 0x0404cb * 2**(8*(0x1b - 3)) = 0x00000000000404CB000000000000000000000000000000000000000000000000&lt;br /&gt;
&lt;br /&gt;
Note that the 0x0404cb value is a signed value in this format. The largest legal value for this field is 0x7fffff. To make a larger value you must shift it down one full byte. Also 0x008000 is the smallest positive valid value.&lt;br /&gt;
&lt;br /&gt;
===How is difficulty calculated? What is the difference between bdiff and pdiff?===&lt;br /&gt;
&lt;br /&gt;
The highest possible target (difficulty 1) is defined as 0x1d00ffff, which gives us a hex target of&lt;br /&gt;
 0x00ffff * 2**(8*(0x1d - 3)) = 0x00000000FFFF0000000000000000000000000000000000000000000000000000&lt;br /&gt;
&lt;br /&gt;
It should be noted that pooled mining often uses non-truncated targets, which puts &amp;quot;pool difficulty 1&amp;quot; at&lt;br /&gt;
 0x00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF&lt;br /&gt;
&lt;br /&gt;
So the difficulty at 0x1b0404cb is therefore:&lt;br /&gt;
 0x00000000FFFF0000000000000000000000000000000000000000000000000000 /&lt;br /&gt;
 0x00000000000404CB000000000000000000000000000000000000000000000000 &lt;br /&gt;
 = 16307.420938523983 (bdiff)&lt;br /&gt;
And:&lt;br /&gt;
 0x00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF /&lt;br /&gt;
 0x00000000000404CB000000000000000000000000000000000000000000000000 &lt;br /&gt;
 = 16307.669773817162 (pdiff)&lt;br /&gt;
&lt;br /&gt;
Here's a fast way to calculate bitcoin difficulty. It uses a modified Taylor series for the logarithm (you can see tutorials on flipcode and wikipedia) and relies on logs to transform the difficulty calculation:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;cmath&amp;gt;&lt;br /&gt;
&lt;br /&gt;
inline float fast_log(float val)&lt;br /&gt;
{&lt;br /&gt;
   int * const exp_ptr = reinterpret_cast &amp;lt;int *&amp;gt;(&amp;amp;val);&lt;br /&gt;
   int x = *exp_ptr;&lt;br /&gt;
   const int log_2 = ((x &amp;gt;&amp;gt; 23) &amp;amp; 255) - 128;&lt;br /&gt;
   x &amp;amp;= ~(255 &amp;lt;&amp;lt; 23);&lt;br /&gt;
   x += 127 &amp;lt;&amp;lt; 23;&lt;br /&gt;
   *exp_ptr = x;&lt;br /&gt;
&lt;br /&gt;
   val = ((-1.0f/3) * val + 2) * val - 2.0f/3;&lt;br /&gt;
   return ((val + log_2) * 0.69314718f);&lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
float difficulty(unsigned int bits)&lt;br /&gt;
{&lt;br /&gt;
    static double max_body = fast_log(0x00ffff), scaland = fast_log(256);&lt;br /&gt;
    return exp(max_body - fast_log(bits &amp;amp; 0x00ffffff) + scaland * (0x1d - ((bits &amp;amp; 0xff000000) &amp;gt;&amp;gt; 24)));&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
    std::cout &amp;lt;&amp;lt; difficulty(0x1b0404cb) &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To see the math to go from the normal difficulty calculations (which require large big ints bigger than the space in any normal integer) to the calculation above, here's some python:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import decimal, math&lt;br /&gt;
l = math.log&lt;br /&gt;
e = math.e&lt;br /&gt;
&lt;br /&gt;
print 0x00ffff * 2**(8*(0x1d - 3)) / float(0x0404cb * 2**(8*(0x1b - 3)))&lt;br /&gt;
print l(0x00ffff * 2**(8*(0x1d - 3)) / float(0x0404cb * 2**(8*(0x1b - 3))))&lt;br /&gt;
print l(0x00ffff * 2**(8*(0x1d - 3))) - l(0x0404cb * 2**(8*(0x1b - 3)))&lt;br /&gt;
print l(0x00ffff) + l(2**(8*(0x1d - 3))) - l(0x0404cb) - l(2**(8*(0x1b - 3)))&lt;br /&gt;
print l(0x00ffff) + (8*(0x1d - 3))*l(2) - l(0x0404cb) - (8*(0x1b - 3))*l(2)&lt;br /&gt;
print l(0x00ffff / float(0x0404cb)) + (8*(0x1d - 3))*l(2) - (8*(0x1b - 3))*l(2)&lt;br /&gt;
print l(0x00ffff / float(0x0404cb)) + (0x1d - 0x1b)*l(2**8)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== What is the current difficulty? ===&lt;br /&gt;
[https://whatsonchain.com/ Current difficulty]&lt;br /&gt;
&lt;br /&gt;
=== What is the maximum difficulty? ===&lt;br /&gt;
&lt;br /&gt;
There is no minimum target. The maximum difficulty is roughly: maximum_target / 1 (since 0 would result in infinity), which is a ridiculously huge number (about 2^224).&lt;br /&gt;
&lt;br /&gt;
The actual maximum difficulty is when current_target=0, but we would not be able to calculate the difficulty if that happened. (fortunately it never will, so we're ok.)&lt;br /&gt;
&lt;br /&gt;
=== Can the network difficulty go down? ===&lt;br /&gt;
Yes it can. See discussion in [[target]].&lt;br /&gt;
&lt;br /&gt;
=== What is the minimum difficulty? ===&lt;br /&gt;
The minimum difficulty, when the target is at the maximum allowed value, is 1. This is the difficulty of the [[Genesis block]].&lt;br /&gt;
&lt;br /&gt;
=== What network hash rate results in a given difficulty? ===&lt;br /&gt;
The difficulty is adjusted every 2016 blocks based on the [[Block_timestamp|time]] it took to find the previous 2016 blocks.  At the desired rate of one block each 10 minutes, 2016 blocks would take exactly two weeks to find.  If the previous 2016 blocks took more than two weeks to find, the difficulty is reduced.  If they took less than two weeks, the difficulty is increased.  The change in difficulty is in proportion to the amount of time over or under two weeks the previous 2016 blocks took to find.&lt;br /&gt;
&lt;br /&gt;
To find a block, the hash must be less than the target.  The hash is effectively a random number between 0 and 2**256-1.  The offset for difficulty 1 is&lt;br /&gt;
 0xffff * 2**208&lt;br /&gt;
and for difficulty D is&lt;br /&gt;
 (0xffff * 2**208)/D&lt;br /&gt;
&lt;br /&gt;
The expected number of hashes we need to calculate to find a block with difficulty D is therefore&lt;br /&gt;
 D * 2**256 / (0xffff * 2**208)&lt;br /&gt;
or just&lt;br /&gt;
 D * 2**48 / 0xffff&lt;br /&gt;
&lt;br /&gt;
The difficulty is set such that the previous 2016 blocks would have been found at the rate of one every 10 minutes, so we were calculating (D * 2**48 / 0xffff) hashes in 600 seconds.  That means the hash rate of the network was&lt;br /&gt;
 D * 2**48 / 0xffff / 600&lt;br /&gt;
over the previous 2016 blocks.  Can be further simplified to&lt;br /&gt;
 D * 2**32 / 600&lt;br /&gt;
without much loss of accuracy.&lt;br /&gt;
&lt;br /&gt;
At difficulty 1, that is around 7 Mhashes per second.&lt;br /&gt;
&lt;br /&gt;
At the time of writing, the difficulty is 22012.4941572, which means that over the previous set of 2016 blocks found the average network hash rate was&lt;br /&gt;
 22012.4941572 * 2**32 / 600 = around 157 Ghashes per second.&lt;br /&gt;
&lt;br /&gt;
=== How soon might I expect to generate a block? ===&lt;br /&gt;
(The [https://www.bitcointalk.org/index.php?topic=1682.0 eternal question].)&lt;br /&gt;
&lt;br /&gt;
The average time to find a block can be approximated by calculating:&lt;br /&gt;
 time = difficulty * 2**32 / hashrate&lt;br /&gt;
where difficulty is the current difficulty, hashrate is the number of hashes your miner calculates per second, and time is the average in seconds between the blocks you find.&lt;br /&gt;
&lt;br /&gt;
For example, using Python we calculate the average time to generate a block using a 1Ghash/s mining rig when the difficulty is 20000:&lt;br /&gt;
 $ python -c &amp;quot;print 20000 * 2**32 / 10**9 / 60 / 60.0&amp;quot;&lt;br /&gt;
 23.85&lt;br /&gt;
and find that it takes just under 24 hours on average.&lt;br /&gt;
&lt;br /&gt;
* Any one grinding of the hash stands the same chance of &amp;quot;winning&amp;quot; as any other.  The numbers game is how many attempts your hardware can make per second.&lt;br /&gt;
* You need to know the difficulty (above) and your khash/sec rate (reported by the client).&lt;br /&gt;
** [[Mining Hardware Comparison]] has some stats that may help you predict what you could get.&lt;br /&gt;
* Visit a calculator or perform the maths yourself,&lt;br /&gt;
** http://www.alloscomp.com/bitcoin/calculator.php&lt;br /&gt;
** http://www.vnbitcoin.org/bitcoincalculator.php&lt;br /&gt;
** https://bitknock.com/calculator&lt;br /&gt;
**https://99bitcoins.com/bitcoin-mining-calculator&lt;br /&gt;
* Remember it's just probability!  There are no guarantees you will win every N days.&lt;br /&gt;
&lt;br /&gt;
==Related Links==&lt;br /&gt;
&lt;br /&gt;
* [https://docs.google.com/spreadsheet/ccc?key=0AiFMBvXvL2dtdEZkR2J4eU5rS3B4ei1iUmJxSWNlQ0E Bitcoin Difficulty History]&lt;br /&gt;
* [https://www.bitcoinmining.com/what-is-bitcoin-mining-difficulty/ What is Bitcoin Mining Difficulty?]&lt;br /&gt;
* See also: [[Target]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Technical]]&lt;br /&gt;
[[Category:Vocabulary]]&lt;br /&gt;
&lt;br /&gt;
[[pl:Trudność]]&lt;/div&gt;</summary>
		<author><name>Angus Adams</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.bitcoinsv.io/index.php?title=Difficulty&amp;diff=1058</id>
		<title>Difficulty</title>
		<link rel="alternate" type="text/html" href="https://wiki.bitcoinsv.io/index.php?title=Difficulty&amp;diff=1058"/>
		<updated>2020-01-10T14:32:11Z</updated>

		<summary type="html">&lt;p&gt;Angus Adams: /* What is the current difficulty? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;''See also: [[Target]]''&lt;br /&gt;
&lt;br /&gt;
=== What is difficulty? ===&lt;br /&gt;
&lt;br /&gt;
Difficulty is a measure of how difficult it is to find a hash below a given [[target]]. Difficulty answers the question: &amp;quot;how many times more difficult is it to mine a block now, compared with how difficult it was to mine the [[Genesis block|Genesis Block]]?&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The Bitcoin network has a global block difficulty. Valid blocks must have a hash below this target.&lt;br /&gt;
Mining pools also have a pool-specific share difficulty setting a lower limit for shares.&lt;br /&gt;
&lt;br /&gt;
=== How often does the network difficulty change? ===&lt;br /&gt;
&lt;br /&gt;
See [[Target|target]].&lt;br /&gt;
&lt;br /&gt;
=== What is the formula for difficulty? ===&lt;br /&gt;
difficulty = difficulty_1_target / current_target &lt;br /&gt;
&lt;br /&gt;
''target is a 256 bit number''&lt;br /&gt;
&lt;br /&gt;
''difficulty_1_target is the target used in the Genesis Block and represents a difficulty of 1.''&lt;br /&gt;
&lt;br /&gt;
difficulty_1_target can be different for various ways to measure difficulty.&lt;br /&gt;
Traditionally, it represents a hash where the leading 32 bits are zero and the rest are one (this is known as &amp;quot;pool difficulty&amp;quot; or &amp;quot;pdiff&amp;quot;).&lt;br /&gt;
The Bitcoin protocol represents targets as a custom floating point type with limited precision; as a result, Bitcoin clients often approximate difficulty based on this (this is known as &amp;quot;bdiff&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
===How is difficulty stored in blocks?===&lt;br /&gt;
&lt;br /&gt;
Each block stores a packed representation in its block header (called [[Block hashing algorithm|Bits]]) for its actual hexadecimal [[target]]. The target can be derived from Bits via a predefined formula. For example, if the packed target in the block is 0x1b0404cb, the hexadecimal target is:&lt;br /&gt;
 0x0404cb * 2**(8*(0x1b - 3)) = 0x00000000000404CB000000000000000000000000000000000000000000000000&lt;br /&gt;
&lt;br /&gt;
Note that the 0x0404cb value is a signed value in this format. The largest legal value for this field is 0x7fffff. To make a larger value you must shift it down one full byte. Also 0x008000 is the smallest positive valid value.&lt;br /&gt;
&lt;br /&gt;
===How is difficulty calculated? What is the difference between bdiff and pdiff?===&lt;br /&gt;
&lt;br /&gt;
The highest possible target (difficulty 1) is defined as 0x1d00ffff, which gives us a hex target of&lt;br /&gt;
 0x00ffff * 2**(8*(0x1d - 3)) = 0x00000000FFFF0000000000000000000000000000000000000000000000000000&lt;br /&gt;
&lt;br /&gt;
It should be noted that pooled mining often uses non-truncated targets, which puts &amp;quot;pool difficulty 1&amp;quot; at&lt;br /&gt;
 0x00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF&lt;br /&gt;
&lt;br /&gt;
So the difficulty at 0x1b0404cb is therefore:&lt;br /&gt;
 0x00000000FFFF0000000000000000000000000000000000000000000000000000 /&lt;br /&gt;
 0x00000000000404CB000000000000000000000000000000000000000000000000 &lt;br /&gt;
 = 16307.420938523983 (bdiff)&lt;br /&gt;
And:&lt;br /&gt;
 0x00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF /&lt;br /&gt;
 0x00000000000404CB000000000000000000000000000000000000000000000000 &lt;br /&gt;
 = 16307.669773817162 (pdiff)&lt;br /&gt;
&lt;br /&gt;
Here's a fast way to calculate bitcoin difficulty. It uses a modified Taylor series for the logarithm (you can see tutorials on flipcode and wikipedia) and relies on logs to transform the difficulty calculation:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;cmath&amp;gt;&lt;br /&gt;
&lt;br /&gt;
inline float fast_log(float val)&lt;br /&gt;
{&lt;br /&gt;
   int * const exp_ptr = reinterpret_cast &amp;lt;int *&amp;gt;(&amp;amp;val);&lt;br /&gt;
   int x = *exp_ptr;&lt;br /&gt;
   const int log_2 = ((x &amp;gt;&amp;gt; 23) &amp;amp; 255) - 128;&lt;br /&gt;
   x &amp;amp;= ~(255 &amp;lt;&amp;lt; 23);&lt;br /&gt;
   x += 127 &amp;lt;&amp;lt; 23;&lt;br /&gt;
   *exp_ptr = x;&lt;br /&gt;
&lt;br /&gt;
   val = ((-1.0f/3) * val + 2) * val - 2.0f/3;&lt;br /&gt;
   return ((val + log_2) * 0.69314718f);&lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
float difficulty(unsigned int bits)&lt;br /&gt;
{&lt;br /&gt;
    static double max_body = fast_log(0x00ffff), scaland = fast_log(256);&lt;br /&gt;
    return exp(max_body - fast_log(bits &amp;amp; 0x00ffffff) + scaland * (0x1d - ((bits &amp;amp; 0xff000000) &amp;gt;&amp;gt; 24)));&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
    std::cout &amp;lt;&amp;lt; difficulty(0x1b0404cb) &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To see the math to go from the normal difficulty calculations (which require large big ints bigger than the space in any normal integer) to the calculation above, here's some python:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import decimal, math&lt;br /&gt;
l = math.log&lt;br /&gt;
e = math.e&lt;br /&gt;
&lt;br /&gt;
print 0x00ffff * 2**(8*(0x1d - 3)) / float(0x0404cb * 2**(8*(0x1b - 3)))&lt;br /&gt;
print l(0x00ffff * 2**(8*(0x1d - 3)) / float(0x0404cb * 2**(8*(0x1b - 3))))&lt;br /&gt;
print l(0x00ffff * 2**(8*(0x1d - 3))) - l(0x0404cb * 2**(8*(0x1b - 3)))&lt;br /&gt;
print l(0x00ffff) + l(2**(8*(0x1d - 3))) - l(0x0404cb) - l(2**(8*(0x1b - 3)))&lt;br /&gt;
print l(0x00ffff) + (8*(0x1d - 3))*l(2) - l(0x0404cb) - (8*(0x1b - 3))*l(2)&lt;br /&gt;
print l(0x00ffff / float(0x0404cb)) + (8*(0x1d - 3))*l(2) - (8*(0x1b - 3))*l(2)&lt;br /&gt;
print l(0x00ffff / float(0x0404cb)) + (0x1d - 0x1b)*l(2**8)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== What is the current difficulty? ===&lt;br /&gt;
[https://whatsonchain.com/ Current difficulty]&lt;br /&gt;
&lt;br /&gt;
=== What is the maximum difficulty? ===&lt;br /&gt;
&lt;br /&gt;
There is no minimum target. The maximum difficulty is roughly: maximum_target / 1 (since 0 would result in infinity), which is a ridiculously huge number (about 2^224).&lt;br /&gt;
&lt;br /&gt;
The actual maximum difficulty is when current_target=0, but we would not be able to calculate the difficulty if that happened. (fortunately it never will, so we're ok.)&lt;br /&gt;
&lt;br /&gt;
=== Can the network difficulty go down? ===&lt;br /&gt;
Yes it can. See discussion in [[target]].&lt;br /&gt;
&lt;br /&gt;
=== What is the minimum difficulty? ===&lt;br /&gt;
The minimum difficulty, when the target is at the maximum allowed value, is 1.&lt;br /&gt;
&lt;br /&gt;
=== What network hash rate results in a given difficulty? ===&lt;br /&gt;
The difficulty is adjusted every 2016 blocks based on the [[Block_timestamp|time]] it took to find the previous 2016 blocks.  At the desired rate of one block each 10 minutes, 2016 blocks would take exactly two weeks to find.  If the previous 2016 blocks took more than two weeks to find, the difficulty is reduced.  If they took less than two weeks, the difficulty is increased.  The change in difficulty is in proportion to the amount of time over or under two weeks the previous 2016 blocks took to find.&lt;br /&gt;
&lt;br /&gt;
To find a block, the hash must be less than the target.  The hash is effectively a random number between 0 and 2**256-1.  The offset for difficulty 1 is&lt;br /&gt;
 0xffff * 2**208&lt;br /&gt;
and for difficulty D is&lt;br /&gt;
 (0xffff * 2**208)/D&lt;br /&gt;
&lt;br /&gt;
The expected number of hashes we need to calculate to find a block with difficulty D is therefore&lt;br /&gt;
 D * 2**256 / (0xffff * 2**208)&lt;br /&gt;
or just&lt;br /&gt;
 D * 2**48 / 0xffff&lt;br /&gt;
&lt;br /&gt;
The difficulty is set such that the previous 2016 blocks would have been found at the rate of one every 10 minutes, so we were calculating (D * 2**48 / 0xffff) hashes in 600 seconds.  That means the hash rate of the network was&lt;br /&gt;
 D * 2**48 / 0xffff / 600&lt;br /&gt;
over the previous 2016 blocks.  Can be further simplified to&lt;br /&gt;
 D * 2**32 / 600&lt;br /&gt;
without much loss of accuracy.&lt;br /&gt;
&lt;br /&gt;
At difficulty 1, that is around 7 Mhashes per second.&lt;br /&gt;
&lt;br /&gt;
At the time of writing, the difficulty is 22012.4941572, which means that over the previous set of 2016 blocks found the average network hash rate was&lt;br /&gt;
 22012.4941572 * 2**32 / 600 = around 157 Ghashes per second.&lt;br /&gt;
&lt;br /&gt;
=== How soon might I expect to generate a block? ===&lt;br /&gt;
(The [https://www.bitcointalk.org/index.php?topic=1682.0 eternal question].)&lt;br /&gt;
&lt;br /&gt;
The average time to find a block can be approximated by calculating:&lt;br /&gt;
 time = difficulty * 2**32 / hashrate&lt;br /&gt;
where difficulty is the current difficulty, hashrate is the number of hashes your miner calculates per second, and time is the average in seconds between the blocks you find.&lt;br /&gt;
&lt;br /&gt;
For example, using Python we calculate the average time to generate a block using a 1Ghash/s mining rig when the difficulty is 20000:&lt;br /&gt;
 $ python -c &amp;quot;print 20000 * 2**32 / 10**9 / 60 / 60.0&amp;quot;&lt;br /&gt;
 23.85&lt;br /&gt;
and find that it takes just under 24 hours on average.&lt;br /&gt;
&lt;br /&gt;
* Any one grinding of the hash stands the same chance of &amp;quot;winning&amp;quot; as any other.  The numbers game is how many attempts your hardware can make per second.&lt;br /&gt;
* You need to know the difficulty (above) and your khash/sec rate (reported by the client).&lt;br /&gt;
** [[Mining Hardware Comparison]] has some stats that may help you predict what you could get.&lt;br /&gt;
* Visit a calculator or perform the maths yourself,&lt;br /&gt;
** http://www.alloscomp.com/bitcoin/calculator.php&lt;br /&gt;
** http://www.vnbitcoin.org/bitcoincalculator.php&lt;br /&gt;
** https://bitknock.com/calculator&lt;br /&gt;
**https://99bitcoins.com/bitcoin-mining-calculator&lt;br /&gt;
* Remember it's just probability!  There are no guarantees you will win every N days.&lt;br /&gt;
&lt;br /&gt;
==Related Links==&lt;br /&gt;
&lt;br /&gt;
* [https://docs.google.com/spreadsheet/ccc?key=0AiFMBvXvL2dtdEZkR2J4eU5rS3B4ei1iUmJxSWNlQ0E Bitcoin Difficulty History]&lt;br /&gt;
* [https://www.bitcoinmining.com/what-is-bitcoin-mining-difficulty/ What is Bitcoin Mining Difficulty?]&lt;br /&gt;
* See also: [[Target]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Technical]]&lt;br /&gt;
[[Category:Vocabulary]]&lt;br /&gt;
&lt;br /&gt;
[[pl:Trudność]]&lt;/div&gt;</summary>
		<author><name>Angus Adams</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.bitcoinsv.io/index.php?title=Target&amp;diff=1057</id>
		<title>Target</title>
		<link rel="alternate" type="text/html" href="https://wiki.bitcoinsv.io/index.php?title=Target&amp;diff=1057"/>
		<updated>2020-01-10T14:28:38Z</updated>

		<summary type="html">&lt;p&gt;Angus Adams: /* What is the maximum target? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;''See also: [[Difficulty]]''&lt;br /&gt;
&lt;br /&gt;
The '''target''' is a 256-bit number (extremely large) that all Bitcoin clients share. The SHA-256 [https://wiki.bitcoinsv.io/index.php/Mining#Hashing hash] of a [[Block hashing algorithm|block's header]] must be less than or equal to the current target for the block to be accepted by the network. The lower the target, the more [[difficulty|difficult]] it is to generate a block.&lt;br /&gt;
&lt;br /&gt;
It's important to realize that block generation is not a long, set problem (like doing a million hashes), but more like a lottery. Each hash basically gives you a random number between 0 and the maximum value of a 256-bit number (2^256-1). If your hash is below the target, then you win. If not, you increment the nonce (completely changing the hash) and try again. &lt;br /&gt;
&lt;br /&gt;
The bitcoin network tries to produce one block every ten minutes on average. As mining hash power changes over time, it achieves this through changing the target value.&lt;br /&gt;
&lt;br /&gt;
Historically (prior to forking from BTC in August 2017), bitcoin changed its target every 2016 blocks (exactly two weeks if a block time of 10 minutes was kept perfectly). This change in the target is known as a 'difficulty adjustment'. Under the original difficulty adjustment paradigm, when adjusting the target, every bitcoin client compared the actual time it took to generate 2016 blocks with the two week goal, and modified the target by the percentage difference. A single retarget never changes the target by more than a factor of 4 either way to prevent large changes in difficulty.&lt;br /&gt;
&lt;br /&gt;
Post forking from BTC in August 2017, bitcoin changed the original difficulty adjustment algorithm to what was named the Emergency Difficulty Adjustment (EDA) algorithm. The EDA had the capacity to update the target value every time a new block was found (as opposed to every 2016 blocks), while still targeting a ten minute block time average. The EDA was changed to the Difficulty Adjustment Algorithm (DAA) on 17 November 2017 to address instabilities associated with the EDA. The DAA uses a moving average of the last 144 blocks to determine changes to the target and like the EDA, the target can change every block. &lt;br /&gt;
&lt;br /&gt;
The reason the EDA (and later, it's improvement, the DAA) needed to be implemented was because of the fork from BTC (creating BCH) in August 2017. Because it was expected that BCH would garner significantly less hash power than BTC, measures were put in place so that block production on BCH would not slow to a crawl due to inheriting BTC's target difficulty and a small number of miners. &lt;br /&gt;
&lt;br /&gt;
It is proposed that bitcoin will move back to the original difficulty adjustment algorithm (still used by BTC) in the future.&lt;br /&gt;
&lt;br /&gt;
===How is the target stored in blocks?===&lt;br /&gt;
Each block stores a packed representation in its block header (called [[Block hashing algorithm|Bits]]) for its actual hexadecimal target. The target can be derived from Bits via a predefined formula. For example, if the packed target in the block is 0x1b0404cb, the hexadecimal target is:&lt;br /&gt;
 0x0404cb * 2**(8*(0x1b - 3)) = 0x00000000000404CB000000000000000000000000000000000000000000000000&lt;br /&gt;
&lt;br /&gt;
Note that the 0x0404cb value is a signed value in this format. The largest legal value for this field is 0x7fffff. To make a larger value you must shift it down one full byte. Also 0x008000 is the smallest positive valid value.&lt;br /&gt;
&lt;br /&gt;
=== What is the maximum target? ===&lt;br /&gt;
The maximum target used by SHA256 mining devices is:&lt;br /&gt;
 0x00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF&lt;br /&gt;
Because Bitcoin stores the target as a floating-point type, this is truncated:&lt;br /&gt;
 0x00000000FFFF0000000000000000000000000000000000000000000000000000&lt;br /&gt;
&lt;br /&gt;
The maximum target is the target used in the [[Genesis block|Genesis Block]] and represents a [[difficulty]] of 1. Its packed representation as [[Block hashing algorithm|Bits]] is 0x1d00ffff.&lt;br /&gt;
&lt;br /&gt;
Since a lower target makes Bitcoin generation more difficult, the maximum target is the ''lowest'' possible [[difficulty]].&lt;br /&gt;
&lt;br /&gt;
==Related Links==&lt;br /&gt;
See also [[Difficulty]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Technical]]&lt;br /&gt;
[[Category:Vocabulary]]&lt;/div&gt;</summary>
		<author><name>Angus Adams</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.bitcoinsv.io/index.php?title=Target&amp;diff=1056</id>
		<title>Target</title>
		<link rel="alternate" type="text/html" href="https://wiki.bitcoinsv.io/index.php?title=Target&amp;diff=1056"/>
		<updated>2020-01-10T14:28:04Z</updated>

		<summary type="html">&lt;p&gt;Angus Adams: /* What is the maximum target? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;''See also: [[Difficulty]]''&lt;br /&gt;
&lt;br /&gt;
The '''target''' is a 256-bit number (extremely large) that all Bitcoin clients share. The SHA-256 [https://wiki.bitcoinsv.io/index.php/Mining#Hashing hash] of a [[Block hashing algorithm|block's header]] must be less than or equal to the current target for the block to be accepted by the network. The lower the target, the more [[difficulty|difficult]] it is to generate a block.&lt;br /&gt;
&lt;br /&gt;
It's important to realize that block generation is not a long, set problem (like doing a million hashes), but more like a lottery. Each hash basically gives you a random number between 0 and the maximum value of a 256-bit number (2^256-1). If your hash is below the target, then you win. If not, you increment the nonce (completely changing the hash) and try again. &lt;br /&gt;
&lt;br /&gt;
The bitcoin network tries to produce one block every ten minutes on average. As mining hash power changes over time, it achieves this through changing the target value.&lt;br /&gt;
&lt;br /&gt;
Historically (prior to forking from BTC in August 2017), bitcoin changed its target every 2016 blocks (exactly two weeks if a block time of 10 minutes was kept perfectly). This change in the target is known as a 'difficulty adjustment'. Under the original difficulty adjustment paradigm, when adjusting the target, every bitcoin client compared the actual time it took to generate 2016 blocks with the two week goal, and modified the target by the percentage difference. A single retarget never changes the target by more than a factor of 4 either way to prevent large changes in difficulty.&lt;br /&gt;
&lt;br /&gt;
Post forking from BTC in August 2017, bitcoin changed the original difficulty adjustment algorithm to what was named the Emergency Difficulty Adjustment (EDA) algorithm. The EDA had the capacity to update the target value every time a new block was found (as opposed to every 2016 blocks), while still targeting a ten minute block time average. The EDA was changed to the Difficulty Adjustment Algorithm (DAA) on 17 November 2017 to address instabilities associated with the EDA. The DAA uses a moving average of the last 144 blocks to determine changes to the target and like the EDA, the target can change every block. &lt;br /&gt;
&lt;br /&gt;
The reason the EDA (and later, it's improvement, the DAA) needed to be implemented was because of the fork from BTC (creating BCH) in August 2017. Because it was expected that BCH would garner significantly less hash power than BTC, measures were put in place so that block production on BCH would not slow to a crawl due to inheriting BTC's target difficulty and a small number of miners. &lt;br /&gt;
&lt;br /&gt;
It is proposed that bitcoin will move back to the original difficulty adjustment algorithm (still used by BTC) in the future.&lt;br /&gt;
&lt;br /&gt;
===How is the target stored in blocks?===&lt;br /&gt;
Each block stores a packed representation in its block header (called [[Block hashing algorithm|Bits]]) for its actual hexadecimal target. The target can be derived from Bits via a predefined formula. For example, if the packed target in the block is 0x1b0404cb, the hexadecimal target is:&lt;br /&gt;
 0x0404cb * 2**(8*(0x1b - 3)) = 0x00000000000404CB000000000000000000000000000000000000000000000000&lt;br /&gt;
&lt;br /&gt;
Note that the 0x0404cb value is a signed value in this format. The largest legal value for this field is 0x7fffff. To make a larger value you must shift it down one full byte. Also 0x008000 is the smallest positive valid value.&lt;br /&gt;
&lt;br /&gt;
=== What is the maximum target? ===&lt;br /&gt;
The maximum target used by SHA256 mining devices is:&lt;br /&gt;
 0x00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF&lt;br /&gt;
Because Bitcoin stores the target as a floating-point type, this is truncated:&lt;br /&gt;
 0x00000000FFFF0000000000000000000000000000000000000000000000000000&lt;br /&gt;
&lt;br /&gt;
The maximum target is the target used in the [[Genesis block|Genesis Block]] and represents a [[difficulty]] of 1. Its packed representation as Bits is 0x1d00ffff.&lt;br /&gt;
&lt;br /&gt;
Since a lower target makes Bitcoin generation more difficult, the maximum target is the ''lowest'' possible [[difficulty]].&lt;br /&gt;
&lt;br /&gt;
==Related Links==&lt;br /&gt;
See also [[Difficulty]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Technical]]&lt;br /&gt;
[[Category:Vocabulary]]&lt;/div&gt;</summary>
		<author><name>Angus Adams</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.bitcoinsv.io/index.php?title=Target&amp;diff=1055</id>
		<title>Target</title>
		<link rel="alternate" type="text/html" href="https://wiki.bitcoinsv.io/index.php?title=Target&amp;diff=1055"/>
		<updated>2020-01-10T14:20:27Z</updated>

		<summary type="html">&lt;p&gt;Angus Adams: /* How is the target stored in blocks? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;''See also: [[Difficulty]]''&lt;br /&gt;
&lt;br /&gt;
The '''target''' is a 256-bit number (extremely large) that all Bitcoin clients share. The SHA-256 [https://wiki.bitcoinsv.io/index.php/Mining#Hashing hash] of a [[Block hashing algorithm|block's header]] must be less than or equal to the current target for the block to be accepted by the network. The lower the target, the more [[difficulty|difficult]] it is to generate a block.&lt;br /&gt;
&lt;br /&gt;
It's important to realize that block generation is not a long, set problem (like doing a million hashes), but more like a lottery. Each hash basically gives you a random number between 0 and the maximum value of a 256-bit number (2^256-1). If your hash is below the target, then you win. If not, you increment the nonce (completely changing the hash) and try again. &lt;br /&gt;
&lt;br /&gt;
The bitcoin network tries to produce one block every ten minutes on average. As mining hash power changes over time, it achieves this through changing the target value.&lt;br /&gt;
&lt;br /&gt;
Historically (prior to forking from BTC in August 2017), bitcoin changed its target every 2016 blocks (exactly two weeks if a block time of 10 minutes was kept perfectly). This change in the target is known as a 'difficulty adjustment'. Under the original difficulty adjustment paradigm, when adjusting the target, every bitcoin client compared the actual time it took to generate 2016 blocks with the two week goal, and modified the target by the percentage difference. A single retarget never changes the target by more than a factor of 4 either way to prevent large changes in difficulty.&lt;br /&gt;
&lt;br /&gt;
Post forking from BTC in August 2017, bitcoin changed the original difficulty adjustment algorithm to what was named the Emergency Difficulty Adjustment (EDA) algorithm. The EDA had the capacity to update the target value every time a new block was found (as opposed to every 2016 blocks), while still targeting a ten minute block time average. The EDA was changed to the Difficulty Adjustment Algorithm (DAA) on 17 November 2017 to address instabilities associated with the EDA. The DAA uses a moving average of the last 144 blocks to determine changes to the target and like the EDA, the target can change every block. &lt;br /&gt;
&lt;br /&gt;
The reason the EDA (and later, it's improvement, the DAA) needed to be implemented was because of the fork from BTC (creating BCH) in August 2017. Because it was expected that BCH would garner significantly less hash power than BTC, measures were put in place so that block production on BCH would not slow to a crawl due to inheriting BTC's target difficulty and a small number of miners. &lt;br /&gt;
&lt;br /&gt;
It is proposed that bitcoin will move back to the original difficulty adjustment algorithm (still used by BTC) in the future.&lt;br /&gt;
&lt;br /&gt;
===How is the target stored in blocks?===&lt;br /&gt;
Each block stores a packed representation in its block header (called [[Block hashing algorithm|Bits]]) for its actual hexadecimal target. The target can be derived from Bits via a predefined formula. For example, if the packed target in the block is 0x1b0404cb, the hexadecimal target is:&lt;br /&gt;
 0x0404cb * 2**(8*(0x1b - 3)) = 0x00000000000404CB000000000000000000000000000000000000000000000000&lt;br /&gt;
&lt;br /&gt;
Note that the 0x0404cb value is a signed value in this format. The largest legal value for this field is 0x7fffff. To make a larger value you must shift it down one full byte. Also 0x008000 is the smallest positive valid value.&lt;br /&gt;
&lt;br /&gt;
=== What is the maximum target? ===&lt;br /&gt;
The maximum target used by SHA256 mining devices is:&lt;br /&gt;
 0x00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF&lt;br /&gt;
Because Bitcoin stores the target as a floating-point type, this is truncated:&lt;br /&gt;
 0x00000000FFFF0000000000000000000000000000000000000000000000000000&lt;br /&gt;
&lt;br /&gt;
The maximum target is the target used in the [[Genesis block|Genesis Block]] and represents a [[difficulty]] of 1.&lt;br /&gt;
&lt;br /&gt;
Since a lower target makes Bitcoin generation more difficult, the maximum target is the ''lowest'' possible [[difficulty]].&lt;br /&gt;
&lt;br /&gt;
==Related Links==&lt;br /&gt;
See also [[Difficulty]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Technical]]&lt;br /&gt;
[[Category:Vocabulary]]&lt;/div&gt;</summary>
		<author><name>Angus Adams</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.bitcoinsv.io/index.php?title=Target&amp;diff=1054</id>
		<title>Target</title>
		<link rel="alternate" type="text/html" href="https://wiki.bitcoinsv.io/index.php?title=Target&amp;diff=1054"/>
		<updated>2020-01-10T14:19:33Z</updated>

		<summary type="html">&lt;p&gt;Angus Adams: /* How is the target stored in blocks? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;''See also: [[Difficulty]]''&lt;br /&gt;
&lt;br /&gt;
The '''target''' is a 256-bit number (extremely large) that all Bitcoin clients share. The SHA-256 [https://wiki.bitcoinsv.io/index.php/Mining#Hashing hash] of a [[Block hashing algorithm|block's header]] must be less than or equal to the current target for the block to be accepted by the network. The lower the target, the more [[difficulty|difficult]] it is to generate a block.&lt;br /&gt;
&lt;br /&gt;
It's important to realize that block generation is not a long, set problem (like doing a million hashes), but more like a lottery. Each hash basically gives you a random number between 0 and the maximum value of a 256-bit number (2^256-1). If your hash is below the target, then you win. If not, you increment the nonce (completely changing the hash) and try again. &lt;br /&gt;
&lt;br /&gt;
The bitcoin network tries to produce one block every ten minutes on average. As mining hash power changes over time, it achieves this through changing the target value.&lt;br /&gt;
&lt;br /&gt;
Historically (prior to forking from BTC in August 2017), bitcoin changed its target every 2016 blocks (exactly two weeks if a block time of 10 minutes was kept perfectly). This change in the target is known as a 'difficulty adjustment'. Under the original difficulty adjustment paradigm, when adjusting the target, every bitcoin client compared the actual time it took to generate 2016 blocks with the two week goal, and modified the target by the percentage difference. A single retarget never changes the target by more than a factor of 4 either way to prevent large changes in difficulty.&lt;br /&gt;
&lt;br /&gt;
Post forking from BTC in August 2017, bitcoin changed the original difficulty adjustment algorithm to what was named the Emergency Difficulty Adjustment (EDA) algorithm. The EDA had the capacity to update the target value every time a new block was found (as opposed to every 2016 blocks), while still targeting a ten minute block time average. The EDA was changed to the Difficulty Adjustment Algorithm (DAA) on 17 November 2017 to address instabilities associated with the EDA. The DAA uses a moving average of the last 144 blocks to determine changes to the target and like the EDA, the target can change every block. &lt;br /&gt;
&lt;br /&gt;
The reason the EDA (and later, it's improvement, the DAA) needed to be implemented was because of the fork from BTC (creating BCH) in August 2017. Because it was expected that BCH would garner significantly less hash power than BTC, measures were put in place so that block production on BCH would not slow to a crawl due to inheriting BTC's target difficulty and a small number of miners. &lt;br /&gt;
&lt;br /&gt;
It is proposed that bitcoin will move back to the original difficulty adjustment algorithm (still used by BTC) in the future.&lt;br /&gt;
&lt;br /&gt;
===How is the target stored in blocks?===&lt;br /&gt;
Each block stores a packed representation in its block header (called [[Block hashing algorithm|bits]]) for its actual hexadecimal target. The target can be derived from Bits via a predefined formula. For example, if the packed target in the block is 0x1b0404cb, the hexadecimal target is:&lt;br /&gt;
 0x0404cb * 2**(8*(0x1b - 3)) = 0x00000000000404CB000000000000000000000000000000000000000000000000&lt;br /&gt;
&lt;br /&gt;
Note that the 0x0404cb value is a signed value in this format. The largest legal value for this field is 0x7fffff. To make a larger value you must shift it down one full byte. Also 0x008000 is the smallest positive valid value.&lt;br /&gt;
&lt;br /&gt;
=== What is the maximum target? ===&lt;br /&gt;
The maximum target used by SHA256 mining devices is:&lt;br /&gt;
 0x00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF&lt;br /&gt;
Because Bitcoin stores the target as a floating-point type, this is truncated:&lt;br /&gt;
 0x00000000FFFF0000000000000000000000000000000000000000000000000000&lt;br /&gt;
&lt;br /&gt;
The maximum target is the target used in the [[Genesis block|Genesis Block]] and represents a [[difficulty]] of 1.&lt;br /&gt;
&lt;br /&gt;
Since a lower target makes Bitcoin generation more difficult, the maximum target is the ''lowest'' possible [[difficulty]].&lt;br /&gt;
&lt;br /&gt;
==Related Links==&lt;br /&gt;
See also [[Difficulty]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Technical]]&lt;br /&gt;
[[Category:Vocabulary]]&lt;/div&gt;</summary>
		<author><name>Angus Adams</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.bitcoinsv.io/index.php?title=Target&amp;diff=1053</id>
		<title>Target</title>
		<link rel="alternate" type="text/html" href="https://wiki.bitcoinsv.io/index.php?title=Target&amp;diff=1053"/>
		<updated>2020-01-10T14:19:05Z</updated>

		<summary type="html">&lt;p&gt;Angus Adams: /* How is the target stored in blocks? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;''See also: [[Difficulty]]''&lt;br /&gt;
&lt;br /&gt;
The '''target''' is a 256-bit number (extremely large) that all Bitcoin clients share. The SHA-256 [https://wiki.bitcoinsv.io/index.php/Mining#Hashing hash] of a [[Block hashing algorithm|block's header]] must be less than or equal to the current target for the block to be accepted by the network. The lower the target, the more [[difficulty|difficult]] it is to generate a block.&lt;br /&gt;
&lt;br /&gt;
It's important to realize that block generation is not a long, set problem (like doing a million hashes), but more like a lottery. Each hash basically gives you a random number between 0 and the maximum value of a 256-bit number (2^256-1). If your hash is below the target, then you win. If not, you increment the nonce (completely changing the hash) and try again. &lt;br /&gt;
&lt;br /&gt;
The bitcoin network tries to produce one block every ten minutes on average. As mining hash power changes over time, it achieves this through changing the target value.&lt;br /&gt;
&lt;br /&gt;
Historically (prior to forking from BTC in August 2017), bitcoin changed its target every 2016 blocks (exactly two weeks if a block time of 10 minutes was kept perfectly). This change in the target is known as a 'difficulty adjustment'. Under the original difficulty adjustment paradigm, when adjusting the target, every bitcoin client compared the actual time it took to generate 2016 blocks with the two week goal, and modified the target by the percentage difference. A single retarget never changes the target by more than a factor of 4 either way to prevent large changes in difficulty.&lt;br /&gt;
&lt;br /&gt;
Post forking from BTC in August 2017, bitcoin changed the original difficulty adjustment algorithm to what was named the Emergency Difficulty Adjustment (EDA) algorithm. The EDA had the capacity to update the target value every time a new block was found (as opposed to every 2016 blocks), while still targeting a ten minute block time average. The EDA was changed to the Difficulty Adjustment Algorithm (DAA) on 17 November 2017 to address instabilities associated with the EDA. The DAA uses a moving average of the last 144 blocks to determine changes to the target and like the EDA, the target can change every block. &lt;br /&gt;
&lt;br /&gt;
The reason the EDA (and later, it's improvement, the DAA) needed to be implemented was because of the fork from BTC (creating BCH) in August 2017. Because it was expected that BCH would garner significantly less hash power than BTC, measures were put in place so that block production on BCH would not slow to a crawl due to inheriting BTC's target difficulty and a small number of miners. &lt;br /&gt;
&lt;br /&gt;
It is proposed that bitcoin will move back to the original difficulty adjustment algorithm (still used by BTC) in the future.&lt;br /&gt;
&lt;br /&gt;
===How is the target stored in blocks?===&lt;br /&gt;
Each block stores a packed representation in its block header (called hello) for its actual hexadecimal target. The target can be derived from Bits via a predefined formula. For example, if the packed target in the block is 0x1b0404cb, the hexadecimal target is:&lt;br /&gt;
 0x0404cb * 2**(8*(0x1b - 3)) = 0x00000000000404CB000000000000000000000000000000000000000000000000&lt;br /&gt;
&lt;br /&gt;
Note that the 0x0404cb value is a signed value in this format. The largest legal value for this field is 0x7fffff. To make a larger value you must shift it down one full byte. Also 0x008000 is the smallest positive valid value.&lt;br /&gt;
&lt;br /&gt;
=== What is the maximum target? ===&lt;br /&gt;
The maximum target used by SHA256 mining devices is:&lt;br /&gt;
 0x00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF&lt;br /&gt;
Because Bitcoin stores the target as a floating-point type, this is truncated:&lt;br /&gt;
 0x00000000FFFF0000000000000000000000000000000000000000000000000000&lt;br /&gt;
&lt;br /&gt;
The maximum target is the target used in the [[Genesis block|Genesis Block]] and represents a [[difficulty]] of 1.&lt;br /&gt;
&lt;br /&gt;
Since a lower target makes Bitcoin generation more difficult, the maximum target is the ''lowest'' possible [[difficulty]].&lt;br /&gt;
&lt;br /&gt;
==Related Links==&lt;br /&gt;
See also [[Difficulty]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Technical]]&lt;br /&gt;
[[Category:Vocabulary]]&lt;/div&gt;</summary>
		<author><name>Angus Adams</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.bitcoinsv.io/index.php?title=Target&amp;diff=1052</id>
		<title>Target</title>
		<link rel="alternate" type="text/html" href="https://wiki.bitcoinsv.io/index.php?title=Target&amp;diff=1052"/>
		<updated>2020-01-10T14:18:07Z</updated>

		<summary type="html">&lt;p&gt;Angus Adams: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;''See also: [[Difficulty]]''&lt;br /&gt;
&lt;br /&gt;
The '''target''' is a 256-bit number (extremely large) that all Bitcoin clients share. The SHA-256 [https://wiki.bitcoinsv.io/index.php/Mining#Hashing hash] of a [[Block hashing algorithm|block's header]] must be less than or equal to the current target for the block to be accepted by the network. The lower the target, the more [[difficulty|difficult]] it is to generate a block.&lt;br /&gt;
&lt;br /&gt;
It's important to realize that block generation is not a long, set problem (like doing a million hashes), but more like a lottery. Each hash basically gives you a random number between 0 and the maximum value of a 256-bit number (2^256-1). If your hash is below the target, then you win. If not, you increment the nonce (completely changing the hash) and try again. &lt;br /&gt;
&lt;br /&gt;
The bitcoin network tries to produce one block every ten minutes on average. As mining hash power changes over time, it achieves this through changing the target value.&lt;br /&gt;
&lt;br /&gt;
Historically (prior to forking from BTC in August 2017), bitcoin changed its target every 2016 blocks (exactly two weeks if a block time of 10 minutes was kept perfectly). This change in the target is known as a 'difficulty adjustment'. Under the original difficulty adjustment paradigm, when adjusting the target, every bitcoin client compared the actual time it took to generate 2016 blocks with the two week goal, and modified the target by the percentage difference. A single retarget never changes the target by more than a factor of 4 either way to prevent large changes in difficulty.&lt;br /&gt;
&lt;br /&gt;
Post forking from BTC in August 2017, bitcoin changed the original difficulty adjustment algorithm to what was named the Emergency Difficulty Adjustment (EDA) algorithm. The EDA had the capacity to update the target value every time a new block was found (as opposed to every 2016 blocks), while still targeting a ten minute block time average. The EDA was changed to the Difficulty Adjustment Algorithm (DAA) on 17 November 2017 to address instabilities associated with the EDA. The DAA uses a moving average of the last 144 blocks to determine changes to the target and like the EDA, the target can change every block. &lt;br /&gt;
&lt;br /&gt;
The reason the EDA (and later, it's improvement, the DAA) needed to be implemented was because of the fork from BTC (creating BCH) in August 2017. Because it was expected that BCH would garner significantly less hash power than BTC, measures were put in place so that block production on BCH would not slow to a crawl due to inheriting BTC's target difficulty and a small number of miners. &lt;br /&gt;
&lt;br /&gt;
It is proposed that bitcoin will move back to the original difficulty adjustment algorithm (still used by BTC) in the future.&lt;br /&gt;
&lt;br /&gt;
===How is the target stored in blocks?===&lt;br /&gt;
Each block stores a packed representation in its block header (called [[Block hashing algorithm|Bits]]) for its actual hexadecimal [[target]]. The target can be derived from Bits via a predefined formula. For example, if the packed target in the block is 0x1b0404cb, the hexadecimal target is:&lt;br /&gt;
 0x0404cb * 2**(8*(0x1b - 3)) = 0x00000000000404CB000000000000000000000000000000000000000000000000&lt;br /&gt;
&lt;br /&gt;
Note that the 0x0404cb value is a signed value in this format. The largest legal value for this field is 0x7fffff. To make a larger value you must shift it down one full byte. Also 0x008000 is the smallest positive valid value.&lt;br /&gt;
&lt;br /&gt;
=== What is the maximum target? ===&lt;br /&gt;
The maximum target used by SHA256 mining devices is:&lt;br /&gt;
 0x00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF&lt;br /&gt;
Because Bitcoin stores the target as a floating-point type, this is truncated:&lt;br /&gt;
 0x00000000FFFF0000000000000000000000000000000000000000000000000000&lt;br /&gt;
&lt;br /&gt;
The maximum target is the target used in the [[Genesis block|Genesis Block]] and represents a [[difficulty]] of 1.&lt;br /&gt;
&lt;br /&gt;
Since a lower target makes Bitcoin generation more difficult, the maximum target is the ''lowest'' possible [[difficulty]].&lt;br /&gt;
&lt;br /&gt;
==Related Links==&lt;br /&gt;
See also [[Difficulty]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Technical]]&lt;br /&gt;
[[Category:Vocabulary]]&lt;/div&gt;</summary>
		<author><name>Angus Adams</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.bitcoinsv.io/index.php?title=Target&amp;diff=1051</id>
		<title>Target</title>
		<link rel="alternate" type="text/html" href="https://wiki.bitcoinsv.io/index.php?title=Target&amp;diff=1051"/>
		<updated>2020-01-10T14:17:40Z</updated>

		<summary type="html">&lt;p&gt;Angus Adams: /* How is difficulty stored in blocks? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;''See also: [[Difficulty]]''&lt;br /&gt;
&lt;br /&gt;
The '''target''' is a 256-bit number (extremely large) that all Bitcoin clients share. The SHA-256 [https://wiki.bitcoinsv.io/index.php/Mining#Hashing hash] of a [[Block hashing algorithm|block's header]] must be less than or equal to the current target for the block to be accepted by the network. The lower the target, the more [[difficulty|difficult]] it is to generate a block.&lt;br /&gt;
&lt;br /&gt;
It's important to realize that block generation is not a long, set problem (like doing a million hashes), but more like a lottery. Each hash basically gives you a random number between 0 and the maximum value of a 256-bit number (2^256-1). If your hash is below the target, then you win. If not, you increment the nonce (completely changing the hash) and try again. &lt;br /&gt;
&lt;br /&gt;
The bitcoin network tries to produce one block every ten minutes on average. As mining hash power changes over time, it achieves this through changing the target value.&lt;br /&gt;
&lt;br /&gt;
Historically (prior to forking from BTC in August 2017), bitcoin changed its target every 2016 blocks (exactly two weeks if a block time of 10 minutes was kept perfectly). This change in the target is known as a 'difficulty adjustment'. Under the original difficulty adjustment paradigm, when adjusting the target, every bitcoin client compared the actual time it took to generate 2016 blocks with the two week goal, and modified the target by the percentage difference. A single retarget never changes the target by more than a factor of 4 either way to prevent large changes in difficulty.&lt;br /&gt;
&lt;br /&gt;
Post forking from BTC in August 2017, bitcoin changed the original difficulty adjustment algorithm to what was named the Emergency Difficulty Adjustment (EDA) algorithm. The EDA had the capacity to update the target value every time a new block was found (as opposed to every 2016 blocks), while still targeting a ten minute block time average. The EDA was changed to the Difficulty Adjustment Algorithm (DAA) on 17 November 2017 to address instabilities associated with the EDA. The DAA uses a moving average of the last 144 blocks to determine changes to the target and like the EDA, the target can change every block. &lt;br /&gt;
&lt;br /&gt;
The reason the EDA (and later, it's improvement, the DAA) needed to be implemented was because of the fork from BTC (creating BCH) in August 2017. Because it was expected that BCH would garner significantly less hash power than BTC, measures were put in place so that block production on BCH would not slow to a crawl due to inheriting BTC's target difficulty and a small number of miners. &lt;br /&gt;
&lt;br /&gt;
It is proposed that bitcoin will move back to the original difficulty adjustment algorithm (still used by BTC) in the future.&lt;br /&gt;
&lt;br /&gt;
=== What is the maximum target? ===&lt;br /&gt;
The maximum target used by SHA256 mining devices is:&lt;br /&gt;
 0x00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF&lt;br /&gt;
Because Bitcoin stores the target as a floating-point type, this is truncated:&lt;br /&gt;
 0x00000000FFFF0000000000000000000000000000000000000000000000000000&lt;br /&gt;
&lt;br /&gt;
The maximum target is the target used in the [[Genesis block|Genesis Block]] and represents a [[difficulty]] of 1.&lt;br /&gt;
&lt;br /&gt;
Since a lower target makes Bitcoin generation more difficult, the maximum target is the ''lowest'' possible [[difficulty]].&lt;br /&gt;
&lt;br /&gt;
===How is the target stored in blocks?===&lt;br /&gt;
Each block stores a packed representation in its block header (called [[Block hashing algorithm|Bits]]) for its actual hexadecimal [[target]]. The target can be derived from Bits via a predefined formula. For example, if the packed target in the block is 0x1b0404cb, the hexadecimal target is:&lt;br /&gt;
 0x0404cb * 2**(8*(0x1b - 3)) = 0x00000000000404CB000000000000000000000000000000000000000000000000&lt;br /&gt;
&lt;br /&gt;
Note that the 0x0404cb value is a signed value in this format. The largest legal value for this field is 0x7fffff. To make a larger value you must shift it down one full byte. Also 0x008000 is the smallest positive valid value.&lt;br /&gt;
&lt;br /&gt;
==Related Links==&lt;br /&gt;
See also [[Difficulty]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Technical]]&lt;br /&gt;
[[Category:Vocabulary]]&lt;/div&gt;</summary>
		<author><name>Angus Adams</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.bitcoinsv.io/index.php?title=Target&amp;diff=1050</id>
		<title>Target</title>
		<link rel="alternate" type="text/html" href="https://wiki.bitcoinsv.io/index.php?title=Target&amp;diff=1050"/>
		<updated>2020-01-10T14:17:28Z</updated>

		<summary type="html">&lt;p&gt;Angus Adams: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;''See also: [[Difficulty]]''&lt;br /&gt;
&lt;br /&gt;
The '''target''' is a 256-bit number (extremely large) that all Bitcoin clients share. The SHA-256 [https://wiki.bitcoinsv.io/index.php/Mining#Hashing hash] of a [[Block hashing algorithm|block's header]] must be less than or equal to the current target for the block to be accepted by the network. The lower the target, the more [[difficulty|difficult]] it is to generate a block.&lt;br /&gt;
&lt;br /&gt;
It's important to realize that block generation is not a long, set problem (like doing a million hashes), but more like a lottery. Each hash basically gives you a random number between 0 and the maximum value of a 256-bit number (2^256-1). If your hash is below the target, then you win. If not, you increment the nonce (completely changing the hash) and try again. &lt;br /&gt;
&lt;br /&gt;
The bitcoin network tries to produce one block every ten minutes on average. As mining hash power changes over time, it achieves this through changing the target value.&lt;br /&gt;
&lt;br /&gt;
Historically (prior to forking from BTC in August 2017), bitcoin changed its target every 2016 blocks (exactly two weeks if a block time of 10 minutes was kept perfectly). This change in the target is known as a 'difficulty adjustment'. Under the original difficulty adjustment paradigm, when adjusting the target, every bitcoin client compared the actual time it took to generate 2016 blocks with the two week goal, and modified the target by the percentage difference. A single retarget never changes the target by more than a factor of 4 either way to prevent large changes in difficulty.&lt;br /&gt;
&lt;br /&gt;
Post forking from BTC in August 2017, bitcoin changed the original difficulty adjustment algorithm to what was named the Emergency Difficulty Adjustment (EDA) algorithm. The EDA had the capacity to update the target value every time a new block was found (as opposed to every 2016 blocks), while still targeting a ten minute block time average. The EDA was changed to the Difficulty Adjustment Algorithm (DAA) on 17 November 2017 to address instabilities associated with the EDA. The DAA uses a moving average of the last 144 blocks to determine changes to the target and like the EDA, the target can change every block. &lt;br /&gt;
&lt;br /&gt;
The reason the EDA (and later, it's improvement, the DAA) needed to be implemented was because of the fork from BTC (creating BCH) in August 2017. Because it was expected that BCH would garner significantly less hash power than BTC, measures were put in place so that block production on BCH would not slow to a crawl due to inheriting BTC's target difficulty and a small number of miners. &lt;br /&gt;
&lt;br /&gt;
It is proposed that bitcoin will move back to the original difficulty adjustment algorithm (still used by BTC) in the future.&lt;br /&gt;
&lt;br /&gt;
=== What is the maximum target? ===&lt;br /&gt;
The maximum target used by SHA256 mining devices is:&lt;br /&gt;
 0x00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF&lt;br /&gt;
Because Bitcoin stores the target as a floating-point type, this is truncated:&lt;br /&gt;
 0x00000000FFFF0000000000000000000000000000000000000000000000000000&lt;br /&gt;
&lt;br /&gt;
The maximum target is the target used in the [[Genesis block|Genesis Block]] and represents a [[difficulty]] of 1.&lt;br /&gt;
&lt;br /&gt;
Since a lower target makes Bitcoin generation more difficult, the maximum target is the ''lowest'' possible [[difficulty]].&lt;br /&gt;
&lt;br /&gt;
===How is difficulty stored in blocks?===&lt;br /&gt;
Each block stores a packed representation in its block header (called [[Block hashing algorithm|Bits]]) for its actual hexadecimal [[target]]. The target can be derived from Bits via a predefined formula. For example, if the packed target in the block is 0x1b0404cb, the hexadecimal target is:&lt;br /&gt;
 0x0404cb * 2**(8*(0x1b - 3)) = 0x00000000000404CB000000000000000000000000000000000000000000000000&lt;br /&gt;
&lt;br /&gt;
Note that the 0x0404cb value is a signed value in this format. The largest legal value for this field is 0x7fffff. To make a larger value you must shift it down one full byte. Also 0x008000 is the smallest positive valid value.&lt;br /&gt;
&lt;br /&gt;
==Related Links==&lt;br /&gt;
See also [[Difficulty]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Technical]]&lt;br /&gt;
[[Category:Vocabulary]]&lt;/div&gt;</summary>
		<author><name>Angus Adams</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.bitcoinsv.io/index.php?title=Target&amp;diff=1034</id>
		<title>Target</title>
		<link rel="alternate" type="text/html" href="https://wiki.bitcoinsv.io/index.php?title=Target&amp;diff=1034"/>
		<updated>2020-01-09T16:53:36Z</updated>

		<summary type="html">&lt;p&gt;Angus Adams: /* What is the maximum target? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;''See also: [[Difficulty]]''&lt;br /&gt;
&lt;br /&gt;
The '''target''' is a 256-bit number (extremely large) that all Bitcoin clients share. The SHA-256 [https://wiki.bitcoinsv.io/index.php/Mining#Hashing hash] of a [[Block hashing algorithm|block's header]] must be less than or equal to the current target for the block to be accepted by the network. The lower the target, the more [[difficulty|difficult]] it is to generate a block.&lt;br /&gt;
&lt;br /&gt;
It's important to realize that block generation is not a long, set problem (like doing a million hashes), but more like a lottery. Each hash basically gives you a random number between 0 and the maximum value of a 256-bit number (2^256-1). If your hash is below the target, then you win. If not, you increment the nonce (completely changing the hash) and try again. &lt;br /&gt;
&lt;br /&gt;
The bitcoin network tries to produce one block every ten minutes on average. As mining hash power changes over time, it achieves this through changing the target value.&lt;br /&gt;
&lt;br /&gt;
Historically (prior to forking from BTC in August 2017), bitcoin changed its target every 2016 blocks (exactly two weeks if a block time of 10 minutes was kept perfectly). This change in the target is known as a 'difficulty adjustment'. Under the original difficulty adjustment paradigm, when adjusting the target, every bitcoin client compared the actual time it took to generate 2016 blocks with the two week goal, and modified the target by the percentage difference. A single retarget never changes the target by more than a factor of 4 either way to prevent large changes in difficulty.&lt;br /&gt;
&lt;br /&gt;
Post forking from BTC in August 2017, bitcoin changed the original difficulty adjustment algorithm to what was named the Emergency Difficulty Adjustment (EDA) algorithm. The EDA had the capacity to update the target value every time a new block was found (as opposed to every 2016 blocks), while still targeting a ten minute block time average. The EDA was changed to the Difficulty Adjustment Algorithm (DAA) on 17 November 2017 to address instabilities associated with the EDA. The DAA uses a moving average of the last 144 blocks to determine changes to the target and like the EDA, the target can change every block. &lt;br /&gt;
&lt;br /&gt;
The reason the EDA (and later, it's improvement, the DAA) needed to be implemented was because of the fork from BTC (creating BCH) in August 2017. Because it was expected that BCH would garner significantly less hash power than BTC, measures were put in place so that block production on BCH would not slow to a crawl due to inheriting BTC's target difficulty and a small number of miners. &lt;br /&gt;
&lt;br /&gt;
It is proposed that bitcoin will move back to the original difficulty adjustment algorithm (still used by BTC) in the future.&lt;br /&gt;
&lt;br /&gt;
=== What is the maximum target? ===&lt;br /&gt;
The maximum target used by SHA256 mining devices is:&lt;br /&gt;
 0x00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF&lt;br /&gt;
Because Bitcoin stores the target as a floating-point type, this is truncated:&lt;br /&gt;
 0x00000000FFFF0000000000000000000000000000000000000000000000000000&lt;br /&gt;
&lt;br /&gt;
The maximum target is the target used in the [[Genesis block|Genesis Block]] and represents a [[difficulty]] of 1.&lt;br /&gt;
&lt;br /&gt;
Since a lower target makes Bitcoin generation more difficult, the maximum target is the ''lowest'' possible [[difficulty]].&lt;br /&gt;
&lt;br /&gt;
==Related Links==&lt;br /&gt;
See also [[Difficulty]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Technical]]&lt;br /&gt;
[[Category:Vocabulary]]&lt;/div&gt;</summary>
		<author><name>Angus Adams</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.bitcoinsv.io/index.php?title=Difficulty&amp;diff=1033</id>
		<title>Difficulty</title>
		<link rel="alternate" type="text/html" href="https://wiki.bitcoinsv.io/index.php?title=Difficulty&amp;diff=1033"/>
		<updated>2020-01-09T16:49:39Z</updated>

		<summary type="html">&lt;p&gt;Angus Adams: /* How is difficulty stored in blocks? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;''See also: [[Target]]''&lt;br /&gt;
&lt;br /&gt;
=== What is difficulty? ===&lt;br /&gt;
&lt;br /&gt;
Difficulty is a measure of how difficult it is to find a hash below a given [[target]]. Difficulty answers the question: &amp;quot;how many times more difficult is it to mine a block now, compared with how difficult it was to mine the [[Genesis block|Genesis Block]]?&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The Bitcoin network has a global block difficulty. Valid blocks must have a hash below this target.&lt;br /&gt;
Mining pools also have a pool-specific share difficulty setting a lower limit for shares.&lt;br /&gt;
&lt;br /&gt;
=== How often does the network difficulty change? ===&lt;br /&gt;
&lt;br /&gt;
See [[Target|target]].&lt;br /&gt;
&lt;br /&gt;
=== What is the formula for difficulty? ===&lt;br /&gt;
difficulty = difficulty_1_target / current_target &lt;br /&gt;
&lt;br /&gt;
''target is a 256 bit number''&lt;br /&gt;
&lt;br /&gt;
''difficulty_1_target is the target used in the Genesis Block and represents a difficulty of 1.''&lt;br /&gt;
&lt;br /&gt;
difficulty_1_target can be different for various ways to measure difficulty.&lt;br /&gt;
Traditionally, it represents a hash where the leading 32 bits are zero and the rest are one (this is known as &amp;quot;pool difficulty&amp;quot; or &amp;quot;pdiff&amp;quot;).&lt;br /&gt;
The Bitcoin protocol represents targets as a custom floating point type with limited precision; as a result, Bitcoin clients often approximate difficulty based on this (this is known as &amp;quot;bdiff&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
===How is difficulty stored in blocks?===&lt;br /&gt;
&lt;br /&gt;
Each block stores a packed representation in its block header (called [[Block hashing algorithm|Bits]]) for its actual hexadecimal [[target]]. The target can be derived from Bits via a predefined formula. For example, if the packed target in the block is 0x1b0404cb, the hexadecimal target is:&lt;br /&gt;
 0x0404cb * 2**(8*(0x1b - 3)) = 0x00000000000404CB000000000000000000000000000000000000000000000000&lt;br /&gt;
&lt;br /&gt;
Note that the 0x0404cb value is a signed value in this format. The largest legal value for this field is 0x7fffff. To make a larger value you must shift it down one full byte. Also 0x008000 is the smallest positive valid value.&lt;br /&gt;
&lt;br /&gt;
===How is difficulty calculated? What is the difference between bdiff and pdiff?===&lt;br /&gt;
&lt;br /&gt;
The highest possible target (difficulty 1) is defined as 0x1d00ffff, which gives us a hex target of&lt;br /&gt;
 0x00ffff * 2**(8*(0x1d - 3)) = 0x00000000FFFF0000000000000000000000000000000000000000000000000000&lt;br /&gt;
&lt;br /&gt;
It should be noted that pooled mining often uses non-truncated targets, which puts &amp;quot;pool difficulty 1&amp;quot; at&lt;br /&gt;
 0x00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF&lt;br /&gt;
&lt;br /&gt;
So the difficulty at 0x1b0404cb is therefore:&lt;br /&gt;
 0x00000000FFFF0000000000000000000000000000000000000000000000000000 /&lt;br /&gt;
 0x00000000000404CB000000000000000000000000000000000000000000000000 &lt;br /&gt;
 = 16307.420938523983 (bdiff)&lt;br /&gt;
And:&lt;br /&gt;
 0x00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF /&lt;br /&gt;
 0x00000000000404CB000000000000000000000000000000000000000000000000 &lt;br /&gt;
 = 16307.669773817162 (pdiff)&lt;br /&gt;
&lt;br /&gt;
Here's a fast way to calculate bitcoin difficulty. It uses a modified Taylor series for the logarithm (you can see tutorials on flipcode and wikipedia) and relies on logs to transform the difficulty calculation:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;cmath&amp;gt;&lt;br /&gt;
&lt;br /&gt;
inline float fast_log(float val)&lt;br /&gt;
{&lt;br /&gt;
   int * const exp_ptr = reinterpret_cast &amp;lt;int *&amp;gt;(&amp;amp;val);&lt;br /&gt;
   int x = *exp_ptr;&lt;br /&gt;
   const int log_2 = ((x &amp;gt;&amp;gt; 23) &amp;amp; 255) - 128;&lt;br /&gt;
   x &amp;amp;= ~(255 &amp;lt;&amp;lt; 23);&lt;br /&gt;
   x += 127 &amp;lt;&amp;lt; 23;&lt;br /&gt;
   *exp_ptr = x;&lt;br /&gt;
&lt;br /&gt;
   val = ((-1.0f/3) * val + 2) * val - 2.0f/3;&lt;br /&gt;
   return ((val + log_2) * 0.69314718f);&lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
float difficulty(unsigned int bits)&lt;br /&gt;
{&lt;br /&gt;
    static double max_body = fast_log(0x00ffff), scaland = fast_log(256);&lt;br /&gt;
    return exp(max_body - fast_log(bits &amp;amp; 0x00ffffff) + scaland * (0x1d - ((bits &amp;amp; 0xff000000) &amp;gt;&amp;gt; 24)));&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
    std::cout &amp;lt;&amp;lt; difficulty(0x1b0404cb) &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To see the math to go from the normal difficulty calculations (which require large big ints bigger than the space in any normal integer) to the calculation above, here's some python:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import decimal, math&lt;br /&gt;
l = math.log&lt;br /&gt;
e = math.e&lt;br /&gt;
&lt;br /&gt;
print 0x00ffff * 2**(8*(0x1d - 3)) / float(0x0404cb * 2**(8*(0x1b - 3)))&lt;br /&gt;
print l(0x00ffff * 2**(8*(0x1d - 3)) / float(0x0404cb * 2**(8*(0x1b - 3))))&lt;br /&gt;
print l(0x00ffff * 2**(8*(0x1d - 3))) - l(0x0404cb * 2**(8*(0x1b - 3)))&lt;br /&gt;
print l(0x00ffff) + l(2**(8*(0x1d - 3))) - l(0x0404cb) - l(2**(8*(0x1b - 3)))&lt;br /&gt;
print l(0x00ffff) + (8*(0x1d - 3))*l(2) - l(0x0404cb) - (8*(0x1b - 3))*l(2)&lt;br /&gt;
print l(0x00ffff / float(0x0404cb)) + (8*(0x1d - 3))*l(2) - (8*(0x1b - 3))*l(2)&lt;br /&gt;
print l(0x00ffff / float(0x0404cb)) + (0x1d - 0x1b)*l(2**8)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== What is the current difficulty? ===&lt;br /&gt;
[http://blockexplorer.com/q/getdifficulty Current difficulty], as output by Bitcoin's getDifficulty.&lt;br /&gt;
&lt;br /&gt;
[http://bitcoin.sipa.be Graphs]&lt;br /&gt;
&lt;br /&gt;
=== What is the maximum difficulty? ===&lt;br /&gt;
&lt;br /&gt;
There is no minimum target. The maximum difficulty is roughly: maximum_target / 1 (since 0 would result in infinity), which is a ridiculously huge number (about 2^224).&lt;br /&gt;
&lt;br /&gt;
The actual maximum difficulty is when current_target=0, but we would not be able to calculate the difficulty if that happened. (fortunately it never will, so we're ok.)&lt;br /&gt;
&lt;br /&gt;
=== Can the network difficulty go down? ===&lt;br /&gt;
Yes it can. See discussion in [[target]].&lt;br /&gt;
&lt;br /&gt;
=== What is the minimum difficulty? ===&lt;br /&gt;
The minimum difficulty, when the target is at the maximum allowed value, is 1.&lt;br /&gt;
&lt;br /&gt;
=== What network hash rate results in a given difficulty? ===&lt;br /&gt;
The difficulty is adjusted every 2016 blocks based on the [[Block_timestamp|time]] it took to find the previous 2016 blocks.  At the desired rate of one block each 10 minutes, 2016 blocks would take exactly two weeks to find.  If the previous 2016 blocks took more than two weeks to find, the difficulty is reduced.  If they took less than two weeks, the difficulty is increased.  The change in difficulty is in proportion to the amount of time over or under two weeks the previous 2016 blocks took to find.&lt;br /&gt;
&lt;br /&gt;
To find a block, the hash must be less than the target.  The hash is effectively a random number between 0 and 2**256-1.  The offset for difficulty 1 is&lt;br /&gt;
 0xffff * 2**208&lt;br /&gt;
and for difficulty D is&lt;br /&gt;
 (0xffff * 2**208)/D&lt;br /&gt;
&lt;br /&gt;
The expected number of hashes we need to calculate to find a block with difficulty D is therefore&lt;br /&gt;
 D * 2**256 / (0xffff * 2**208)&lt;br /&gt;
or just&lt;br /&gt;
 D * 2**48 / 0xffff&lt;br /&gt;
&lt;br /&gt;
The difficulty is set such that the previous 2016 blocks would have been found at the rate of one every 10 minutes, so we were calculating (D * 2**48 / 0xffff) hashes in 600 seconds.  That means the hash rate of the network was&lt;br /&gt;
 D * 2**48 / 0xffff / 600&lt;br /&gt;
over the previous 2016 blocks.  Can be further simplified to&lt;br /&gt;
 D * 2**32 / 600&lt;br /&gt;
without much loss of accuracy.&lt;br /&gt;
&lt;br /&gt;
At difficulty 1, that is around 7 Mhashes per second.&lt;br /&gt;
&lt;br /&gt;
At the time of writing, the difficulty is 22012.4941572, which means that over the previous set of 2016 blocks found the average network hash rate was&lt;br /&gt;
 22012.4941572 * 2**32 / 600 = around 157 Ghashes per second.&lt;br /&gt;
&lt;br /&gt;
=== How soon might I expect to generate a block? ===&lt;br /&gt;
(The [https://www.bitcointalk.org/index.php?topic=1682.0 eternal question].)&lt;br /&gt;
&lt;br /&gt;
The average time to find a block can be approximated by calculating:&lt;br /&gt;
 time = difficulty * 2**32 / hashrate&lt;br /&gt;
where difficulty is the current difficulty, hashrate is the number of hashes your miner calculates per second, and time is the average in seconds between the blocks you find.&lt;br /&gt;
&lt;br /&gt;
For example, using Python we calculate the average time to generate a block using a 1Ghash/s mining rig when the difficulty is 20000:&lt;br /&gt;
 $ python -c &amp;quot;print 20000 * 2**32 / 10**9 / 60 / 60.0&amp;quot;&lt;br /&gt;
 23.85&lt;br /&gt;
and find that it takes just under 24 hours on average.&lt;br /&gt;
&lt;br /&gt;
* Any one grinding of the hash stands the same chance of &amp;quot;winning&amp;quot; as any other.  The numbers game is how many attempts your hardware can make per second.&lt;br /&gt;
* You need to know the difficulty (above) and your khash/sec rate (reported by the client).&lt;br /&gt;
** [[Mining Hardware Comparison]] has some stats that may help you predict what you could get.&lt;br /&gt;
* Visit a calculator or perform the maths yourself,&lt;br /&gt;
** http://www.alloscomp.com/bitcoin/calculator.php&lt;br /&gt;
** http://www.vnbitcoin.org/bitcoincalculator.php&lt;br /&gt;
** https://bitknock.com/calculator&lt;br /&gt;
**https://99bitcoins.com/bitcoin-mining-calculator&lt;br /&gt;
* Remember it's just probability!  There are no guarantees you will win every N days.&lt;br /&gt;
&lt;br /&gt;
==Related Links==&lt;br /&gt;
&lt;br /&gt;
* [https://docs.google.com/spreadsheet/ccc?key=0AiFMBvXvL2dtdEZkR2J4eU5rS3B4ei1iUmJxSWNlQ0E Bitcoin Difficulty History]&lt;br /&gt;
* [https://www.bitcoinmining.com/what-is-bitcoin-mining-difficulty/ What is Bitcoin Mining Difficulty?]&lt;br /&gt;
* See also: [[Target]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Technical]]&lt;br /&gt;
[[Category:Vocabulary]]&lt;br /&gt;
&lt;br /&gt;
[[pl:Trudność]]&lt;/div&gt;</summary>
		<author><name>Angus Adams</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.bitcoinsv.io/index.php?title=Difficulty&amp;diff=1032</id>
		<title>Difficulty</title>
		<link rel="alternate" type="text/html" href="https://wiki.bitcoinsv.io/index.php?title=Difficulty&amp;diff=1032"/>
		<updated>2020-01-09T16:47:54Z</updated>

		<summary type="html">&lt;p&gt;Angus Adams: /* How is difficulty stored in blocks? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;''See also: [[Target]]''&lt;br /&gt;
&lt;br /&gt;
=== What is difficulty? ===&lt;br /&gt;
&lt;br /&gt;
Difficulty is a measure of how difficult it is to find a hash below a given [[target]]. Difficulty answers the question: &amp;quot;how many times more difficult is it to mine a block now, compared with how difficult it was to mine the [[Genesis block|Genesis Block]]?&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The Bitcoin network has a global block difficulty. Valid blocks must have a hash below this target.&lt;br /&gt;
Mining pools also have a pool-specific share difficulty setting a lower limit for shares.&lt;br /&gt;
&lt;br /&gt;
=== How often does the network difficulty change? ===&lt;br /&gt;
&lt;br /&gt;
See [[Target|target]].&lt;br /&gt;
&lt;br /&gt;
=== What is the formula for difficulty? ===&lt;br /&gt;
difficulty = difficulty_1_target / current_target &lt;br /&gt;
&lt;br /&gt;
''target is a 256 bit number''&lt;br /&gt;
&lt;br /&gt;
''difficulty_1_target is the target used in the Genesis Block and represents a difficulty of 1.''&lt;br /&gt;
&lt;br /&gt;
difficulty_1_target can be different for various ways to measure difficulty.&lt;br /&gt;
Traditionally, it represents a hash where the leading 32 bits are zero and the rest are one (this is known as &amp;quot;pool difficulty&amp;quot; or &amp;quot;pdiff&amp;quot;).&lt;br /&gt;
The Bitcoin protocol represents targets as a custom floating point type with limited precision; as a result, Bitcoin clients often approximate difficulty based on this (this is known as &amp;quot;bdiff&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
===How is difficulty stored in blocks?===&lt;br /&gt;
&lt;br /&gt;
Each block stores a packed representation (called [[Block hashing algorithm|bits]]) for its actual hexadecimal [[target]]. The target can be derived from it via a predefined formula. For example, if the packed target in the block is 0x1b0404cb, the hexadecimal target is&lt;br /&gt;
 0x0404cb * 2**(8*(0x1b - 3)) = 0x00000000000404CB000000000000000000000000000000000000000000000000&lt;br /&gt;
&lt;br /&gt;
Note that the 0x0404cb value is a signed value in this format. The largest legal value for this field is 0x7fffff. To make a larger value you must shift it down one full byte. Also 0x008000 is the smallest positive valid value.&lt;br /&gt;
&lt;br /&gt;
===How is difficulty calculated? What is the difference between bdiff and pdiff?===&lt;br /&gt;
&lt;br /&gt;
The highest possible target (difficulty 1) is defined as 0x1d00ffff, which gives us a hex target of&lt;br /&gt;
 0x00ffff * 2**(8*(0x1d - 3)) = 0x00000000FFFF0000000000000000000000000000000000000000000000000000&lt;br /&gt;
&lt;br /&gt;
It should be noted that pooled mining often uses non-truncated targets, which puts &amp;quot;pool difficulty 1&amp;quot; at&lt;br /&gt;
 0x00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF&lt;br /&gt;
&lt;br /&gt;
So the difficulty at 0x1b0404cb is therefore:&lt;br /&gt;
 0x00000000FFFF0000000000000000000000000000000000000000000000000000 /&lt;br /&gt;
 0x00000000000404CB000000000000000000000000000000000000000000000000 &lt;br /&gt;
 = 16307.420938523983 (bdiff)&lt;br /&gt;
And:&lt;br /&gt;
 0x00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF /&lt;br /&gt;
 0x00000000000404CB000000000000000000000000000000000000000000000000 &lt;br /&gt;
 = 16307.669773817162 (pdiff)&lt;br /&gt;
&lt;br /&gt;
Here's a fast way to calculate bitcoin difficulty. It uses a modified Taylor series for the logarithm (you can see tutorials on flipcode and wikipedia) and relies on logs to transform the difficulty calculation:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;cmath&amp;gt;&lt;br /&gt;
&lt;br /&gt;
inline float fast_log(float val)&lt;br /&gt;
{&lt;br /&gt;
   int * const exp_ptr = reinterpret_cast &amp;lt;int *&amp;gt;(&amp;amp;val);&lt;br /&gt;
   int x = *exp_ptr;&lt;br /&gt;
   const int log_2 = ((x &amp;gt;&amp;gt; 23) &amp;amp; 255) - 128;&lt;br /&gt;
   x &amp;amp;= ~(255 &amp;lt;&amp;lt; 23);&lt;br /&gt;
   x += 127 &amp;lt;&amp;lt; 23;&lt;br /&gt;
   *exp_ptr = x;&lt;br /&gt;
&lt;br /&gt;
   val = ((-1.0f/3) * val + 2) * val - 2.0f/3;&lt;br /&gt;
   return ((val + log_2) * 0.69314718f);&lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
float difficulty(unsigned int bits)&lt;br /&gt;
{&lt;br /&gt;
    static double max_body = fast_log(0x00ffff), scaland = fast_log(256);&lt;br /&gt;
    return exp(max_body - fast_log(bits &amp;amp; 0x00ffffff) + scaland * (0x1d - ((bits &amp;amp; 0xff000000) &amp;gt;&amp;gt; 24)));&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
    std::cout &amp;lt;&amp;lt; difficulty(0x1b0404cb) &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To see the math to go from the normal difficulty calculations (which require large big ints bigger than the space in any normal integer) to the calculation above, here's some python:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import decimal, math&lt;br /&gt;
l = math.log&lt;br /&gt;
e = math.e&lt;br /&gt;
&lt;br /&gt;
print 0x00ffff * 2**(8*(0x1d - 3)) / float(0x0404cb * 2**(8*(0x1b - 3)))&lt;br /&gt;
print l(0x00ffff * 2**(8*(0x1d - 3)) / float(0x0404cb * 2**(8*(0x1b - 3))))&lt;br /&gt;
print l(0x00ffff * 2**(8*(0x1d - 3))) - l(0x0404cb * 2**(8*(0x1b - 3)))&lt;br /&gt;
print l(0x00ffff) + l(2**(8*(0x1d - 3))) - l(0x0404cb) - l(2**(8*(0x1b - 3)))&lt;br /&gt;
print l(0x00ffff) + (8*(0x1d - 3))*l(2) - l(0x0404cb) - (8*(0x1b - 3))*l(2)&lt;br /&gt;
print l(0x00ffff / float(0x0404cb)) + (8*(0x1d - 3))*l(2) - (8*(0x1b - 3))*l(2)&lt;br /&gt;
print l(0x00ffff / float(0x0404cb)) + (0x1d - 0x1b)*l(2**8)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== What is the current difficulty? ===&lt;br /&gt;
[http://blockexplorer.com/q/getdifficulty Current difficulty], as output by Bitcoin's getDifficulty.&lt;br /&gt;
&lt;br /&gt;
[http://bitcoin.sipa.be Graphs]&lt;br /&gt;
&lt;br /&gt;
=== What is the maximum difficulty? ===&lt;br /&gt;
&lt;br /&gt;
There is no minimum target. The maximum difficulty is roughly: maximum_target / 1 (since 0 would result in infinity), which is a ridiculously huge number (about 2^224).&lt;br /&gt;
&lt;br /&gt;
The actual maximum difficulty is when current_target=0, but we would not be able to calculate the difficulty if that happened. (fortunately it never will, so we're ok.)&lt;br /&gt;
&lt;br /&gt;
=== Can the network difficulty go down? ===&lt;br /&gt;
Yes it can. See discussion in [[target]].&lt;br /&gt;
&lt;br /&gt;
=== What is the minimum difficulty? ===&lt;br /&gt;
The minimum difficulty, when the target is at the maximum allowed value, is 1.&lt;br /&gt;
&lt;br /&gt;
=== What network hash rate results in a given difficulty? ===&lt;br /&gt;
The difficulty is adjusted every 2016 blocks based on the [[Block_timestamp|time]] it took to find the previous 2016 blocks.  At the desired rate of one block each 10 minutes, 2016 blocks would take exactly two weeks to find.  If the previous 2016 blocks took more than two weeks to find, the difficulty is reduced.  If they took less than two weeks, the difficulty is increased.  The change in difficulty is in proportion to the amount of time over or under two weeks the previous 2016 blocks took to find.&lt;br /&gt;
&lt;br /&gt;
To find a block, the hash must be less than the target.  The hash is effectively a random number between 0 and 2**256-1.  The offset for difficulty 1 is&lt;br /&gt;
 0xffff * 2**208&lt;br /&gt;
and for difficulty D is&lt;br /&gt;
 (0xffff * 2**208)/D&lt;br /&gt;
&lt;br /&gt;
The expected number of hashes we need to calculate to find a block with difficulty D is therefore&lt;br /&gt;
 D * 2**256 / (0xffff * 2**208)&lt;br /&gt;
or just&lt;br /&gt;
 D * 2**48 / 0xffff&lt;br /&gt;
&lt;br /&gt;
The difficulty is set such that the previous 2016 blocks would have been found at the rate of one every 10 minutes, so we were calculating (D * 2**48 / 0xffff) hashes in 600 seconds.  That means the hash rate of the network was&lt;br /&gt;
 D * 2**48 / 0xffff / 600&lt;br /&gt;
over the previous 2016 blocks.  Can be further simplified to&lt;br /&gt;
 D * 2**32 / 600&lt;br /&gt;
without much loss of accuracy.&lt;br /&gt;
&lt;br /&gt;
At difficulty 1, that is around 7 Mhashes per second.&lt;br /&gt;
&lt;br /&gt;
At the time of writing, the difficulty is 22012.4941572, which means that over the previous set of 2016 blocks found the average network hash rate was&lt;br /&gt;
 22012.4941572 * 2**32 / 600 = around 157 Ghashes per second.&lt;br /&gt;
&lt;br /&gt;
=== How soon might I expect to generate a block? ===&lt;br /&gt;
(The [https://www.bitcointalk.org/index.php?topic=1682.0 eternal question].)&lt;br /&gt;
&lt;br /&gt;
The average time to find a block can be approximated by calculating:&lt;br /&gt;
 time = difficulty * 2**32 / hashrate&lt;br /&gt;
where difficulty is the current difficulty, hashrate is the number of hashes your miner calculates per second, and time is the average in seconds between the blocks you find.&lt;br /&gt;
&lt;br /&gt;
For example, using Python we calculate the average time to generate a block using a 1Ghash/s mining rig when the difficulty is 20000:&lt;br /&gt;
 $ python -c &amp;quot;print 20000 * 2**32 / 10**9 / 60 / 60.0&amp;quot;&lt;br /&gt;
 23.85&lt;br /&gt;
and find that it takes just under 24 hours on average.&lt;br /&gt;
&lt;br /&gt;
* Any one grinding of the hash stands the same chance of &amp;quot;winning&amp;quot; as any other.  The numbers game is how many attempts your hardware can make per second.&lt;br /&gt;
* You need to know the difficulty (above) and your khash/sec rate (reported by the client).&lt;br /&gt;
** [[Mining Hardware Comparison]] has some stats that may help you predict what you could get.&lt;br /&gt;
* Visit a calculator or perform the maths yourself,&lt;br /&gt;
** http://www.alloscomp.com/bitcoin/calculator.php&lt;br /&gt;
** http://www.vnbitcoin.org/bitcoincalculator.php&lt;br /&gt;
** https://bitknock.com/calculator&lt;br /&gt;
**https://99bitcoins.com/bitcoin-mining-calculator&lt;br /&gt;
* Remember it's just probability!  There are no guarantees you will win every N days.&lt;br /&gt;
&lt;br /&gt;
==Related Links==&lt;br /&gt;
&lt;br /&gt;
* [https://docs.google.com/spreadsheet/ccc?key=0AiFMBvXvL2dtdEZkR2J4eU5rS3B4ei1iUmJxSWNlQ0E Bitcoin Difficulty History]&lt;br /&gt;
* [https://www.bitcoinmining.com/what-is-bitcoin-mining-difficulty/ What is Bitcoin Mining Difficulty?]&lt;br /&gt;
* See also: [[Target]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Technical]]&lt;br /&gt;
[[Category:Vocabulary]]&lt;br /&gt;
&lt;br /&gt;
[[pl:Trudność]]&lt;/div&gt;</summary>
		<author><name>Angus Adams</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.bitcoinsv.io/index.php?title=Difficulty&amp;diff=1031</id>
		<title>Difficulty</title>
		<link rel="alternate" type="text/html" href="https://wiki.bitcoinsv.io/index.php?title=Difficulty&amp;diff=1031"/>
		<updated>2020-01-09T16:46:39Z</updated>

		<summary type="html">&lt;p&gt;Angus Adams: /* What is the formula for difficulty? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;''See also: [[Target]]''&lt;br /&gt;
&lt;br /&gt;
=== What is difficulty? ===&lt;br /&gt;
&lt;br /&gt;
Difficulty is a measure of how difficult it is to find a hash below a given [[target]]. Difficulty answers the question: &amp;quot;how many times more difficult is it to mine a block now, compared with how difficult it was to mine the [[Genesis block|Genesis Block]]?&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The Bitcoin network has a global block difficulty. Valid blocks must have a hash below this target.&lt;br /&gt;
Mining pools also have a pool-specific share difficulty setting a lower limit for shares.&lt;br /&gt;
&lt;br /&gt;
=== How often does the network difficulty change? ===&lt;br /&gt;
&lt;br /&gt;
See [[Target|target]].&lt;br /&gt;
&lt;br /&gt;
=== What is the formula for difficulty? ===&lt;br /&gt;
difficulty = difficulty_1_target / current_target &lt;br /&gt;
&lt;br /&gt;
''target is a 256 bit number''&lt;br /&gt;
&lt;br /&gt;
''difficulty_1_target is the target used in the Genesis Block and represents a difficulty of 1.''&lt;br /&gt;
&lt;br /&gt;
difficulty_1_target can be different for various ways to measure difficulty.&lt;br /&gt;
Traditionally, it represents a hash where the leading 32 bits are zero and the rest are one (this is known as &amp;quot;pool difficulty&amp;quot; or &amp;quot;pdiff&amp;quot;).&lt;br /&gt;
The Bitcoin protocol represents targets as a custom floating point type with limited precision; as a result, Bitcoin clients often approximate difficulty based on this (this is known as &amp;quot;bdiff&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
===How is difficulty stored in blocks?===&lt;br /&gt;
&lt;br /&gt;
Each block stores a packed representation (called &amp;quot;Bits&amp;quot;) for its actual hexadecimal [[target]]. The target can be derived from it via a predefined formula. For example, if the packed target in the block is 0x1b0404cb, the hexadecimal target is&lt;br /&gt;
 0x0404cb * 2**(8*(0x1b - 3)) = 0x00000000000404CB000000000000000000000000000000000000000000000000&lt;br /&gt;
&lt;br /&gt;
Note that the 0x0404cb value is a signed value in this format. The largest legal value for this field is 0x7fffff. To make a larger value you must shift it down one full byte. Also 0x008000 is the smallest positive valid value.&lt;br /&gt;
&lt;br /&gt;
===How is difficulty calculated? What is the difference between bdiff and pdiff?===&lt;br /&gt;
&lt;br /&gt;
The highest possible target (difficulty 1) is defined as 0x1d00ffff, which gives us a hex target of&lt;br /&gt;
 0x00ffff * 2**(8*(0x1d - 3)) = 0x00000000FFFF0000000000000000000000000000000000000000000000000000&lt;br /&gt;
&lt;br /&gt;
It should be noted that pooled mining often uses non-truncated targets, which puts &amp;quot;pool difficulty 1&amp;quot; at&lt;br /&gt;
 0x00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF&lt;br /&gt;
&lt;br /&gt;
So the difficulty at 0x1b0404cb is therefore:&lt;br /&gt;
 0x00000000FFFF0000000000000000000000000000000000000000000000000000 /&lt;br /&gt;
 0x00000000000404CB000000000000000000000000000000000000000000000000 &lt;br /&gt;
 = 16307.420938523983 (bdiff)&lt;br /&gt;
And:&lt;br /&gt;
 0x00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF /&lt;br /&gt;
 0x00000000000404CB000000000000000000000000000000000000000000000000 &lt;br /&gt;
 = 16307.669773817162 (pdiff)&lt;br /&gt;
&lt;br /&gt;
Here's a fast way to calculate bitcoin difficulty. It uses a modified Taylor series for the logarithm (you can see tutorials on flipcode and wikipedia) and relies on logs to transform the difficulty calculation:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;cmath&amp;gt;&lt;br /&gt;
&lt;br /&gt;
inline float fast_log(float val)&lt;br /&gt;
{&lt;br /&gt;
   int * const exp_ptr = reinterpret_cast &amp;lt;int *&amp;gt;(&amp;amp;val);&lt;br /&gt;
   int x = *exp_ptr;&lt;br /&gt;
   const int log_2 = ((x &amp;gt;&amp;gt; 23) &amp;amp; 255) - 128;&lt;br /&gt;
   x &amp;amp;= ~(255 &amp;lt;&amp;lt; 23);&lt;br /&gt;
   x += 127 &amp;lt;&amp;lt; 23;&lt;br /&gt;
   *exp_ptr = x;&lt;br /&gt;
&lt;br /&gt;
   val = ((-1.0f/3) * val + 2) * val - 2.0f/3;&lt;br /&gt;
   return ((val + log_2) * 0.69314718f);&lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
float difficulty(unsigned int bits)&lt;br /&gt;
{&lt;br /&gt;
    static double max_body = fast_log(0x00ffff), scaland = fast_log(256);&lt;br /&gt;
    return exp(max_body - fast_log(bits &amp;amp; 0x00ffffff) + scaland * (0x1d - ((bits &amp;amp; 0xff000000) &amp;gt;&amp;gt; 24)));&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
    std::cout &amp;lt;&amp;lt; difficulty(0x1b0404cb) &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To see the math to go from the normal difficulty calculations (which require large big ints bigger than the space in any normal integer) to the calculation above, here's some python:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import decimal, math&lt;br /&gt;
l = math.log&lt;br /&gt;
e = math.e&lt;br /&gt;
&lt;br /&gt;
print 0x00ffff * 2**(8*(0x1d - 3)) / float(0x0404cb * 2**(8*(0x1b - 3)))&lt;br /&gt;
print l(0x00ffff * 2**(8*(0x1d - 3)) / float(0x0404cb * 2**(8*(0x1b - 3))))&lt;br /&gt;
print l(0x00ffff * 2**(8*(0x1d - 3))) - l(0x0404cb * 2**(8*(0x1b - 3)))&lt;br /&gt;
print l(0x00ffff) + l(2**(8*(0x1d - 3))) - l(0x0404cb) - l(2**(8*(0x1b - 3)))&lt;br /&gt;
print l(0x00ffff) + (8*(0x1d - 3))*l(2) - l(0x0404cb) - (8*(0x1b - 3))*l(2)&lt;br /&gt;
print l(0x00ffff / float(0x0404cb)) + (8*(0x1d - 3))*l(2) - (8*(0x1b - 3))*l(2)&lt;br /&gt;
print l(0x00ffff / float(0x0404cb)) + (0x1d - 0x1b)*l(2**8)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== What is the current difficulty? ===&lt;br /&gt;
[http://blockexplorer.com/q/getdifficulty Current difficulty], as output by Bitcoin's getDifficulty.&lt;br /&gt;
&lt;br /&gt;
[http://bitcoin.sipa.be Graphs]&lt;br /&gt;
&lt;br /&gt;
=== What is the maximum difficulty? ===&lt;br /&gt;
&lt;br /&gt;
There is no minimum target. The maximum difficulty is roughly: maximum_target / 1 (since 0 would result in infinity), which is a ridiculously huge number (about 2^224).&lt;br /&gt;
&lt;br /&gt;
The actual maximum difficulty is when current_target=0, but we would not be able to calculate the difficulty if that happened. (fortunately it never will, so we're ok.)&lt;br /&gt;
&lt;br /&gt;
=== Can the network difficulty go down? ===&lt;br /&gt;
Yes it can. See discussion in [[target]].&lt;br /&gt;
&lt;br /&gt;
=== What is the minimum difficulty? ===&lt;br /&gt;
The minimum difficulty, when the target is at the maximum allowed value, is 1.&lt;br /&gt;
&lt;br /&gt;
=== What network hash rate results in a given difficulty? ===&lt;br /&gt;
The difficulty is adjusted every 2016 blocks based on the [[Block_timestamp|time]] it took to find the previous 2016 blocks.  At the desired rate of one block each 10 minutes, 2016 blocks would take exactly two weeks to find.  If the previous 2016 blocks took more than two weeks to find, the difficulty is reduced.  If they took less than two weeks, the difficulty is increased.  The change in difficulty is in proportion to the amount of time over or under two weeks the previous 2016 blocks took to find.&lt;br /&gt;
&lt;br /&gt;
To find a block, the hash must be less than the target.  The hash is effectively a random number between 0 and 2**256-1.  The offset for difficulty 1 is&lt;br /&gt;
 0xffff * 2**208&lt;br /&gt;
and for difficulty D is&lt;br /&gt;
 (0xffff * 2**208)/D&lt;br /&gt;
&lt;br /&gt;
The expected number of hashes we need to calculate to find a block with difficulty D is therefore&lt;br /&gt;
 D * 2**256 / (0xffff * 2**208)&lt;br /&gt;
or just&lt;br /&gt;
 D * 2**48 / 0xffff&lt;br /&gt;
&lt;br /&gt;
The difficulty is set such that the previous 2016 blocks would have been found at the rate of one every 10 minutes, so we were calculating (D * 2**48 / 0xffff) hashes in 600 seconds.  That means the hash rate of the network was&lt;br /&gt;
 D * 2**48 / 0xffff / 600&lt;br /&gt;
over the previous 2016 blocks.  Can be further simplified to&lt;br /&gt;
 D * 2**32 / 600&lt;br /&gt;
without much loss of accuracy.&lt;br /&gt;
&lt;br /&gt;
At difficulty 1, that is around 7 Mhashes per second.&lt;br /&gt;
&lt;br /&gt;
At the time of writing, the difficulty is 22012.4941572, which means that over the previous set of 2016 blocks found the average network hash rate was&lt;br /&gt;
 22012.4941572 * 2**32 / 600 = around 157 Ghashes per second.&lt;br /&gt;
&lt;br /&gt;
=== How soon might I expect to generate a block? ===&lt;br /&gt;
(The [https://www.bitcointalk.org/index.php?topic=1682.0 eternal question].)&lt;br /&gt;
&lt;br /&gt;
The average time to find a block can be approximated by calculating:&lt;br /&gt;
 time = difficulty * 2**32 / hashrate&lt;br /&gt;
where difficulty is the current difficulty, hashrate is the number of hashes your miner calculates per second, and time is the average in seconds between the blocks you find.&lt;br /&gt;
&lt;br /&gt;
For example, using Python we calculate the average time to generate a block using a 1Ghash/s mining rig when the difficulty is 20000:&lt;br /&gt;
 $ python -c &amp;quot;print 20000 * 2**32 / 10**9 / 60 / 60.0&amp;quot;&lt;br /&gt;
 23.85&lt;br /&gt;
and find that it takes just under 24 hours on average.&lt;br /&gt;
&lt;br /&gt;
* Any one grinding of the hash stands the same chance of &amp;quot;winning&amp;quot; as any other.  The numbers game is how many attempts your hardware can make per second.&lt;br /&gt;
* You need to know the difficulty (above) and your khash/sec rate (reported by the client).&lt;br /&gt;
** [[Mining Hardware Comparison]] has some stats that may help you predict what you could get.&lt;br /&gt;
* Visit a calculator or perform the maths yourself,&lt;br /&gt;
** http://www.alloscomp.com/bitcoin/calculator.php&lt;br /&gt;
** http://www.vnbitcoin.org/bitcoincalculator.php&lt;br /&gt;
** https://bitknock.com/calculator&lt;br /&gt;
**https://99bitcoins.com/bitcoin-mining-calculator&lt;br /&gt;
* Remember it's just probability!  There are no guarantees you will win every N days.&lt;br /&gt;
&lt;br /&gt;
==Related Links==&lt;br /&gt;
&lt;br /&gt;
* [https://docs.google.com/spreadsheet/ccc?key=0AiFMBvXvL2dtdEZkR2J4eU5rS3B4ei1iUmJxSWNlQ0E Bitcoin Difficulty History]&lt;br /&gt;
* [https://www.bitcoinmining.com/what-is-bitcoin-mining-difficulty/ What is Bitcoin Mining Difficulty?]&lt;br /&gt;
* See also: [[Target]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Technical]]&lt;br /&gt;
[[Category:Vocabulary]]&lt;br /&gt;
&lt;br /&gt;
[[pl:Trudność]]&lt;/div&gt;</summary>
		<author><name>Angus Adams</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.bitcoinsv.io/index.php?title=Difficulty&amp;diff=1030</id>
		<title>Difficulty</title>
		<link rel="alternate" type="text/html" href="https://wiki.bitcoinsv.io/index.php?title=Difficulty&amp;diff=1030"/>
		<updated>2020-01-09T16:45:58Z</updated>

		<summary type="html">&lt;p&gt;Angus Adams: /* What is the formula for difficulty? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;''See also: [[Target]]''&lt;br /&gt;
&lt;br /&gt;
=== What is difficulty? ===&lt;br /&gt;
&lt;br /&gt;
Difficulty is a measure of how difficult it is to find a hash below a given [[target]]. Difficulty answers the question: &amp;quot;how many times more difficult is it to mine a block now, compared with how difficult it was to mine the [[Genesis block|Genesis Block]]?&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The Bitcoin network has a global block difficulty. Valid blocks must have a hash below this target.&lt;br /&gt;
Mining pools also have a pool-specific share difficulty setting a lower limit for shares.&lt;br /&gt;
&lt;br /&gt;
=== How often does the network difficulty change? ===&lt;br /&gt;
&lt;br /&gt;
See [[Target|target]].&lt;br /&gt;
&lt;br /&gt;
=== What is the formula for difficulty? ===&lt;br /&gt;
difficulty = difficulty_1_target / current_target &lt;br /&gt;
&lt;br /&gt;
''target is a 256 bit number''&lt;br /&gt;
&lt;br /&gt;
''Difficulty_1_target is the target used in the Genesis Block and represents a difficulty of 1.''&lt;br /&gt;
&lt;br /&gt;
difficulty_1_target can be different for various ways to measure difficulty.&lt;br /&gt;
Traditionally, it represents a hash where the leading 32 bits are zero and the rest are one (this is known as &amp;quot;pool difficulty&amp;quot; or &amp;quot;pdiff&amp;quot;).&lt;br /&gt;
The Bitcoin protocol represents targets as a custom floating point type with limited precision; as a result, Bitcoin clients often approximate difficulty based on this (this is known as &amp;quot;bdiff&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
===How is difficulty stored in blocks?===&lt;br /&gt;
&lt;br /&gt;
Each block stores a packed representation (called &amp;quot;Bits&amp;quot;) for its actual hexadecimal [[target]]. The target can be derived from it via a predefined formula. For example, if the packed target in the block is 0x1b0404cb, the hexadecimal target is&lt;br /&gt;
 0x0404cb * 2**(8*(0x1b - 3)) = 0x00000000000404CB000000000000000000000000000000000000000000000000&lt;br /&gt;
&lt;br /&gt;
Note that the 0x0404cb value is a signed value in this format. The largest legal value for this field is 0x7fffff. To make a larger value you must shift it down one full byte. Also 0x008000 is the smallest positive valid value.&lt;br /&gt;
&lt;br /&gt;
===How is difficulty calculated? What is the difference between bdiff and pdiff?===&lt;br /&gt;
&lt;br /&gt;
The highest possible target (difficulty 1) is defined as 0x1d00ffff, which gives us a hex target of&lt;br /&gt;
 0x00ffff * 2**(8*(0x1d - 3)) = 0x00000000FFFF0000000000000000000000000000000000000000000000000000&lt;br /&gt;
&lt;br /&gt;
It should be noted that pooled mining often uses non-truncated targets, which puts &amp;quot;pool difficulty 1&amp;quot; at&lt;br /&gt;
 0x00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF&lt;br /&gt;
&lt;br /&gt;
So the difficulty at 0x1b0404cb is therefore:&lt;br /&gt;
 0x00000000FFFF0000000000000000000000000000000000000000000000000000 /&lt;br /&gt;
 0x00000000000404CB000000000000000000000000000000000000000000000000 &lt;br /&gt;
 = 16307.420938523983 (bdiff)&lt;br /&gt;
And:&lt;br /&gt;
 0x00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF /&lt;br /&gt;
 0x00000000000404CB000000000000000000000000000000000000000000000000 &lt;br /&gt;
 = 16307.669773817162 (pdiff)&lt;br /&gt;
&lt;br /&gt;
Here's a fast way to calculate bitcoin difficulty. It uses a modified Taylor series for the logarithm (you can see tutorials on flipcode and wikipedia) and relies on logs to transform the difficulty calculation:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;cmath&amp;gt;&lt;br /&gt;
&lt;br /&gt;
inline float fast_log(float val)&lt;br /&gt;
{&lt;br /&gt;
   int * const exp_ptr = reinterpret_cast &amp;lt;int *&amp;gt;(&amp;amp;val);&lt;br /&gt;
   int x = *exp_ptr;&lt;br /&gt;
   const int log_2 = ((x &amp;gt;&amp;gt; 23) &amp;amp; 255) - 128;&lt;br /&gt;
   x &amp;amp;= ~(255 &amp;lt;&amp;lt; 23);&lt;br /&gt;
   x += 127 &amp;lt;&amp;lt; 23;&lt;br /&gt;
   *exp_ptr = x;&lt;br /&gt;
&lt;br /&gt;
   val = ((-1.0f/3) * val + 2) * val - 2.0f/3;&lt;br /&gt;
   return ((val + log_2) * 0.69314718f);&lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
float difficulty(unsigned int bits)&lt;br /&gt;
{&lt;br /&gt;
    static double max_body = fast_log(0x00ffff), scaland = fast_log(256);&lt;br /&gt;
    return exp(max_body - fast_log(bits &amp;amp; 0x00ffffff) + scaland * (0x1d - ((bits &amp;amp; 0xff000000) &amp;gt;&amp;gt; 24)));&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
    std::cout &amp;lt;&amp;lt; difficulty(0x1b0404cb) &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To see the math to go from the normal difficulty calculations (which require large big ints bigger than the space in any normal integer) to the calculation above, here's some python:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import decimal, math&lt;br /&gt;
l = math.log&lt;br /&gt;
e = math.e&lt;br /&gt;
&lt;br /&gt;
print 0x00ffff * 2**(8*(0x1d - 3)) / float(0x0404cb * 2**(8*(0x1b - 3)))&lt;br /&gt;
print l(0x00ffff * 2**(8*(0x1d - 3)) / float(0x0404cb * 2**(8*(0x1b - 3))))&lt;br /&gt;
print l(0x00ffff * 2**(8*(0x1d - 3))) - l(0x0404cb * 2**(8*(0x1b - 3)))&lt;br /&gt;
print l(0x00ffff) + l(2**(8*(0x1d - 3))) - l(0x0404cb) - l(2**(8*(0x1b - 3)))&lt;br /&gt;
print l(0x00ffff) + (8*(0x1d - 3))*l(2) - l(0x0404cb) - (8*(0x1b - 3))*l(2)&lt;br /&gt;
print l(0x00ffff / float(0x0404cb)) + (8*(0x1d - 3))*l(2) - (8*(0x1b - 3))*l(2)&lt;br /&gt;
print l(0x00ffff / float(0x0404cb)) + (0x1d - 0x1b)*l(2**8)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== What is the current difficulty? ===&lt;br /&gt;
[http://blockexplorer.com/q/getdifficulty Current difficulty], as output by Bitcoin's getDifficulty.&lt;br /&gt;
&lt;br /&gt;
[http://bitcoin.sipa.be Graphs]&lt;br /&gt;
&lt;br /&gt;
=== What is the maximum difficulty? ===&lt;br /&gt;
&lt;br /&gt;
There is no minimum target. The maximum difficulty is roughly: maximum_target / 1 (since 0 would result in infinity), which is a ridiculously huge number (about 2^224).&lt;br /&gt;
&lt;br /&gt;
The actual maximum difficulty is when current_target=0, but we would not be able to calculate the difficulty if that happened. (fortunately it never will, so we're ok.)&lt;br /&gt;
&lt;br /&gt;
=== Can the network difficulty go down? ===&lt;br /&gt;
Yes it can. See discussion in [[target]].&lt;br /&gt;
&lt;br /&gt;
=== What is the minimum difficulty? ===&lt;br /&gt;
The minimum difficulty, when the target is at the maximum allowed value, is 1.&lt;br /&gt;
&lt;br /&gt;
=== What network hash rate results in a given difficulty? ===&lt;br /&gt;
The difficulty is adjusted every 2016 blocks based on the [[Block_timestamp|time]] it took to find the previous 2016 blocks.  At the desired rate of one block each 10 minutes, 2016 blocks would take exactly two weeks to find.  If the previous 2016 blocks took more than two weeks to find, the difficulty is reduced.  If they took less than two weeks, the difficulty is increased.  The change in difficulty is in proportion to the amount of time over or under two weeks the previous 2016 blocks took to find.&lt;br /&gt;
&lt;br /&gt;
To find a block, the hash must be less than the target.  The hash is effectively a random number between 0 and 2**256-1.  The offset for difficulty 1 is&lt;br /&gt;
 0xffff * 2**208&lt;br /&gt;
and for difficulty D is&lt;br /&gt;
 (0xffff * 2**208)/D&lt;br /&gt;
&lt;br /&gt;
The expected number of hashes we need to calculate to find a block with difficulty D is therefore&lt;br /&gt;
 D * 2**256 / (0xffff * 2**208)&lt;br /&gt;
or just&lt;br /&gt;
 D * 2**48 / 0xffff&lt;br /&gt;
&lt;br /&gt;
The difficulty is set such that the previous 2016 blocks would have been found at the rate of one every 10 minutes, so we were calculating (D * 2**48 / 0xffff) hashes in 600 seconds.  That means the hash rate of the network was&lt;br /&gt;
 D * 2**48 / 0xffff / 600&lt;br /&gt;
over the previous 2016 blocks.  Can be further simplified to&lt;br /&gt;
 D * 2**32 / 600&lt;br /&gt;
without much loss of accuracy.&lt;br /&gt;
&lt;br /&gt;
At difficulty 1, that is around 7 Mhashes per second.&lt;br /&gt;
&lt;br /&gt;
At the time of writing, the difficulty is 22012.4941572, which means that over the previous set of 2016 blocks found the average network hash rate was&lt;br /&gt;
 22012.4941572 * 2**32 / 600 = around 157 Ghashes per second.&lt;br /&gt;
&lt;br /&gt;
=== How soon might I expect to generate a block? ===&lt;br /&gt;
(The [https://www.bitcointalk.org/index.php?topic=1682.0 eternal question].)&lt;br /&gt;
&lt;br /&gt;
The average time to find a block can be approximated by calculating:&lt;br /&gt;
 time = difficulty * 2**32 / hashrate&lt;br /&gt;
where difficulty is the current difficulty, hashrate is the number of hashes your miner calculates per second, and time is the average in seconds between the blocks you find.&lt;br /&gt;
&lt;br /&gt;
For example, using Python we calculate the average time to generate a block using a 1Ghash/s mining rig when the difficulty is 20000:&lt;br /&gt;
 $ python -c &amp;quot;print 20000 * 2**32 / 10**9 / 60 / 60.0&amp;quot;&lt;br /&gt;
 23.85&lt;br /&gt;
and find that it takes just under 24 hours on average.&lt;br /&gt;
&lt;br /&gt;
* Any one grinding of the hash stands the same chance of &amp;quot;winning&amp;quot; as any other.  The numbers game is how many attempts your hardware can make per second.&lt;br /&gt;
* You need to know the difficulty (above) and your khash/sec rate (reported by the client).&lt;br /&gt;
** [[Mining Hardware Comparison]] has some stats that may help you predict what you could get.&lt;br /&gt;
* Visit a calculator or perform the maths yourself,&lt;br /&gt;
** http://www.alloscomp.com/bitcoin/calculator.php&lt;br /&gt;
** http://www.vnbitcoin.org/bitcoincalculator.php&lt;br /&gt;
** https://bitknock.com/calculator&lt;br /&gt;
**https://99bitcoins.com/bitcoin-mining-calculator&lt;br /&gt;
* Remember it's just probability!  There are no guarantees you will win every N days.&lt;br /&gt;
&lt;br /&gt;
==Related Links==&lt;br /&gt;
&lt;br /&gt;
* [https://docs.google.com/spreadsheet/ccc?key=0AiFMBvXvL2dtdEZkR2J4eU5rS3B4ei1iUmJxSWNlQ0E Bitcoin Difficulty History]&lt;br /&gt;
* [https://www.bitcoinmining.com/what-is-bitcoin-mining-difficulty/ What is Bitcoin Mining Difficulty?]&lt;br /&gt;
* See also: [[Target]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Technical]]&lt;br /&gt;
[[Category:Vocabulary]]&lt;br /&gt;
&lt;br /&gt;
[[pl:Trudność]]&lt;/div&gt;</summary>
		<author><name>Angus Adams</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.bitcoinsv.io/index.php?title=Difficulty&amp;diff=1029</id>
		<title>Difficulty</title>
		<link rel="alternate" type="text/html" href="https://wiki.bitcoinsv.io/index.php?title=Difficulty&amp;diff=1029"/>
		<updated>2020-01-09T16:45:48Z</updated>

		<summary type="html">&lt;p&gt;Angus Adams: /* What is the formula for difficulty? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;''See also: [[Target]]''&lt;br /&gt;
&lt;br /&gt;
=== What is difficulty? ===&lt;br /&gt;
&lt;br /&gt;
Difficulty is a measure of how difficult it is to find a hash below a given [[target]]. Difficulty answers the question: &amp;quot;how many times more difficult is it to mine a block now, compared with how difficult it was to mine the [[Genesis block|Genesis Block]]?&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The Bitcoin network has a global block difficulty. Valid blocks must have a hash below this target.&lt;br /&gt;
Mining pools also have a pool-specific share difficulty setting a lower limit for shares.&lt;br /&gt;
&lt;br /&gt;
=== How often does the network difficulty change? ===&lt;br /&gt;
&lt;br /&gt;
See [[Target|target]].&lt;br /&gt;
&lt;br /&gt;
=== What is the formula for difficulty? ===&lt;br /&gt;
difficulty = difficulty_1_target / current_target &lt;br /&gt;
&lt;br /&gt;
''target is a 256 bit number''&lt;br /&gt;
''Difficulty_1_target is the target used in the Genesis Block and represents a difficulty of 1.''&lt;br /&gt;
&lt;br /&gt;
difficulty_1_target can be different for various ways to measure difficulty.&lt;br /&gt;
Traditionally, it represents a hash where the leading 32 bits are zero and the rest are one (this is known as &amp;quot;pool difficulty&amp;quot; or &amp;quot;pdiff&amp;quot;).&lt;br /&gt;
The Bitcoin protocol represents targets as a custom floating point type with limited precision; as a result, Bitcoin clients often approximate difficulty based on this (this is known as &amp;quot;bdiff&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
===How is difficulty stored in blocks?===&lt;br /&gt;
&lt;br /&gt;
Each block stores a packed representation (called &amp;quot;Bits&amp;quot;) for its actual hexadecimal [[target]]. The target can be derived from it via a predefined formula. For example, if the packed target in the block is 0x1b0404cb, the hexadecimal target is&lt;br /&gt;
 0x0404cb * 2**(8*(0x1b - 3)) = 0x00000000000404CB000000000000000000000000000000000000000000000000&lt;br /&gt;
&lt;br /&gt;
Note that the 0x0404cb value is a signed value in this format. The largest legal value for this field is 0x7fffff. To make a larger value you must shift it down one full byte. Also 0x008000 is the smallest positive valid value.&lt;br /&gt;
&lt;br /&gt;
===How is difficulty calculated? What is the difference between bdiff and pdiff?===&lt;br /&gt;
&lt;br /&gt;
The highest possible target (difficulty 1) is defined as 0x1d00ffff, which gives us a hex target of&lt;br /&gt;
 0x00ffff * 2**(8*(0x1d - 3)) = 0x00000000FFFF0000000000000000000000000000000000000000000000000000&lt;br /&gt;
&lt;br /&gt;
It should be noted that pooled mining often uses non-truncated targets, which puts &amp;quot;pool difficulty 1&amp;quot; at&lt;br /&gt;
 0x00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF&lt;br /&gt;
&lt;br /&gt;
So the difficulty at 0x1b0404cb is therefore:&lt;br /&gt;
 0x00000000FFFF0000000000000000000000000000000000000000000000000000 /&lt;br /&gt;
 0x00000000000404CB000000000000000000000000000000000000000000000000 &lt;br /&gt;
 = 16307.420938523983 (bdiff)&lt;br /&gt;
And:&lt;br /&gt;
 0x00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF /&lt;br /&gt;
 0x00000000000404CB000000000000000000000000000000000000000000000000 &lt;br /&gt;
 = 16307.669773817162 (pdiff)&lt;br /&gt;
&lt;br /&gt;
Here's a fast way to calculate bitcoin difficulty. It uses a modified Taylor series for the logarithm (you can see tutorials on flipcode and wikipedia) and relies on logs to transform the difficulty calculation:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;cmath&amp;gt;&lt;br /&gt;
&lt;br /&gt;
inline float fast_log(float val)&lt;br /&gt;
{&lt;br /&gt;
   int * const exp_ptr = reinterpret_cast &amp;lt;int *&amp;gt;(&amp;amp;val);&lt;br /&gt;
   int x = *exp_ptr;&lt;br /&gt;
   const int log_2 = ((x &amp;gt;&amp;gt; 23) &amp;amp; 255) - 128;&lt;br /&gt;
   x &amp;amp;= ~(255 &amp;lt;&amp;lt; 23);&lt;br /&gt;
   x += 127 &amp;lt;&amp;lt; 23;&lt;br /&gt;
   *exp_ptr = x;&lt;br /&gt;
&lt;br /&gt;
   val = ((-1.0f/3) * val + 2) * val - 2.0f/3;&lt;br /&gt;
   return ((val + log_2) * 0.69314718f);&lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
float difficulty(unsigned int bits)&lt;br /&gt;
{&lt;br /&gt;
    static double max_body = fast_log(0x00ffff), scaland = fast_log(256);&lt;br /&gt;
    return exp(max_body - fast_log(bits &amp;amp; 0x00ffffff) + scaland * (0x1d - ((bits &amp;amp; 0xff000000) &amp;gt;&amp;gt; 24)));&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
    std::cout &amp;lt;&amp;lt; difficulty(0x1b0404cb) &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To see the math to go from the normal difficulty calculations (which require large big ints bigger than the space in any normal integer) to the calculation above, here's some python:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import decimal, math&lt;br /&gt;
l = math.log&lt;br /&gt;
e = math.e&lt;br /&gt;
&lt;br /&gt;
print 0x00ffff * 2**(8*(0x1d - 3)) / float(0x0404cb * 2**(8*(0x1b - 3)))&lt;br /&gt;
print l(0x00ffff * 2**(8*(0x1d - 3)) / float(0x0404cb * 2**(8*(0x1b - 3))))&lt;br /&gt;
print l(0x00ffff * 2**(8*(0x1d - 3))) - l(0x0404cb * 2**(8*(0x1b - 3)))&lt;br /&gt;
print l(0x00ffff) + l(2**(8*(0x1d - 3))) - l(0x0404cb) - l(2**(8*(0x1b - 3)))&lt;br /&gt;
print l(0x00ffff) + (8*(0x1d - 3))*l(2) - l(0x0404cb) - (8*(0x1b - 3))*l(2)&lt;br /&gt;
print l(0x00ffff / float(0x0404cb)) + (8*(0x1d - 3))*l(2) - (8*(0x1b - 3))*l(2)&lt;br /&gt;
print l(0x00ffff / float(0x0404cb)) + (0x1d - 0x1b)*l(2**8)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== What is the current difficulty? ===&lt;br /&gt;
[http://blockexplorer.com/q/getdifficulty Current difficulty], as output by Bitcoin's getDifficulty.&lt;br /&gt;
&lt;br /&gt;
[http://bitcoin.sipa.be Graphs]&lt;br /&gt;
&lt;br /&gt;
=== What is the maximum difficulty? ===&lt;br /&gt;
&lt;br /&gt;
There is no minimum target. The maximum difficulty is roughly: maximum_target / 1 (since 0 would result in infinity), which is a ridiculously huge number (about 2^224).&lt;br /&gt;
&lt;br /&gt;
The actual maximum difficulty is when current_target=0, but we would not be able to calculate the difficulty if that happened. (fortunately it never will, so we're ok.)&lt;br /&gt;
&lt;br /&gt;
=== Can the network difficulty go down? ===&lt;br /&gt;
Yes it can. See discussion in [[target]].&lt;br /&gt;
&lt;br /&gt;
=== What is the minimum difficulty? ===&lt;br /&gt;
The minimum difficulty, when the target is at the maximum allowed value, is 1.&lt;br /&gt;
&lt;br /&gt;
=== What network hash rate results in a given difficulty? ===&lt;br /&gt;
The difficulty is adjusted every 2016 blocks based on the [[Block_timestamp|time]] it took to find the previous 2016 blocks.  At the desired rate of one block each 10 minutes, 2016 blocks would take exactly two weeks to find.  If the previous 2016 blocks took more than two weeks to find, the difficulty is reduced.  If they took less than two weeks, the difficulty is increased.  The change in difficulty is in proportion to the amount of time over or under two weeks the previous 2016 blocks took to find.&lt;br /&gt;
&lt;br /&gt;
To find a block, the hash must be less than the target.  The hash is effectively a random number between 0 and 2**256-1.  The offset for difficulty 1 is&lt;br /&gt;
 0xffff * 2**208&lt;br /&gt;
and for difficulty D is&lt;br /&gt;
 (0xffff * 2**208)/D&lt;br /&gt;
&lt;br /&gt;
The expected number of hashes we need to calculate to find a block with difficulty D is therefore&lt;br /&gt;
 D * 2**256 / (0xffff * 2**208)&lt;br /&gt;
or just&lt;br /&gt;
 D * 2**48 / 0xffff&lt;br /&gt;
&lt;br /&gt;
The difficulty is set such that the previous 2016 blocks would have been found at the rate of one every 10 minutes, so we were calculating (D * 2**48 / 0xffff) hashes in 600 seconds.  That means the hash rate of the network was&lt;br /&gt;
 D * 2**48 / 0xffff / 600&lt;br /&gt;
over the previous 2016 blocks.  Can be further simplified to&lt;br /&gt;
 D * 2**32 / 600&lt;br /&gt;
without much loss of accuracy.&lt;br /&gt;
&lt;br /&gt;
At difficulty 1, that is around 7 Mhashes per second.&lt;br /&gt;
&lt;br /&gt;
At the time of writing, the difficulty is 22012.4941572, which means that over the previous set of 2016 blocks found the average network hash rate was&lt;br /&gt;
 22012.4941572 * 2**32 / 600 = around 157 Ghashes per second.&lt;br /&gt;
&lt;br /&gt;
=== How soon might I expect to generate a block? ===&lt;br /&gt;
(The [https://www.bitcointalk.org/index.php?topic=1682.0 eternal question].)&lt;br /&gt;
&lt;br /&gt;
The average time to find a block can be approximated by calculating:&lt;br /&gt;
 time = difficulty * 2**32 / hashrate&lt;br /&gt;
where difficulty is the current difficulty, hashrate is the number of hashes your miner calculates per second, and time is the average in seconds between the blocks you find.&lt;br /&gt;
&lt;br /&gt;
For example, using Python we calculate the average time to generate a block using a 1Ghash/s mining rig when the difficulty is 20000:&lt;br /&gt;
 $ python -c &amp;quot;print 20000 * 2**32 / 10**9 / 60 / 60.0&amp;quot;&lt;br /&gt;
 23.85&lt;br /&gt;
and find that it takes just under 24 hours on average.&lt;br /&gt;
&lt;br /&gt;
* Any one grinding of the hash stands the same chance of &amp;quot;winning&amp;quot; as any other.  The numbers game is how many attempts your hardware can make per second.&lt;br /&gt;
* You need to know the difficulty (above) and your khash/sec rate (reported by the client).&lt;br /&gt;
** [[Mining Hardware Comparison]] has some stats that may help you predict what you could get.&lt;br /&gt;
* Visit a calculator or perform the maths yourself,&lt;br /&gt;
** http://www.alloscomp.com/bitcoin/calculator.php&lt;br /&gt;
** http://www.vnbitcoin.org/bitcoincalculator.php&lt;br /&gt;
** https://bitknock.com/calculator&lt;br /&gt;
**https://99bitcoins.com/bitcoin-mining-calculator&lt;br /&gt;
* Remember it's just probability!  There are no guarantees you will win every N days.&lt;br /&gt;
&lt;br /&gt;
==Related Links==&lt;br /&gt;
&lt;br /&gt;
* [https://docs.google.com/spreadsheet/ccc?key=0AiFMBvXvL2dtdEZkR2J4eU5rS3B4ei1iUmJxSWNlQ0E Bitcoin Difficulty History]&lt;br /&gt;
* [https://www.bitcoinmining.com/what-is-bitcoin-mining-difficulty/ What is Bitcoin Mining Difficulty?]&lt;br /&gt;
* See also: [[Target]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Technical]]&lt;br /&gt;
[[Category:Vocabulary]]&lt;br /&gt;
&lt;br /&gt;
[[pl:Trudność]]&lt;/div&gt;</summary>
		<author><name>Angus Adams</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.bitcoinsv.io/index.php?title=Difficulty&amp;diff=1028</id>
		<title>Difficulty</title>
		<link rel="alternate" type="text/html" href="https://wiki.bitcoinsv.io/index.php?title=Difficulty&amp;diff=1028"/>
		<updated>2020-01-09T16:44:38Z</updated>

		<summary type="html">&lt;p&gt;Angus Adams: /* What is the formula for difficulty? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;''See also: [[Target]]''&lt;br /&gt;
&lt;br /&gt;
=== What is difficulty? ===&lt;br /&gt;
&lt;br /&gt;
Difficulty is a measure of how difficult it is to find a hash below a given [[target]]. Difficulty answers the question: &amp;quot;how many times more difficult is it to mine a block now, compared with how difficult it was to mine the [[Genesis block|Genesis Block]]?&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The Bitcoin network has a global block difficulty. Valid blocks must have a hash below this target.&lt;br /&gt;
Mining pools also have a pool-specific share difficulty setting a lower limit for shares.&lt;br /&gt;
&lt;br /&gt;
=== How often does the network difficulty change? ===&lt;br /&gt;
&lt;br /&gt;
See [[Target|target]].&lt;br /&gt;
&lt;br /&gt;
=== What is the formula for difficulty? ===&lt;br /&gt;
difficulty = difficulty_1_target / current_target &lt;br /&gt;
&lt;br /&gt;
(target is a 256 bit number)&lt;br /&gt;
&lt;br /&gt;
''Difficulty_1_target is the target used in the Genesis Block and represents a difficulty of 1.''&lt;br /&gt;
&lt;br /&gt;
difficulty_1_target can be different for various ways to measure difficulty.&lt;br /&gt;
Traditionally, it represents a hash where the leading 32 bits are zero and the rest are one (this is known as &amp;quot;pool difficulty&amp;quot; or &amp;quot;pdiff&amp;quot;).&lt;br /&gt;
The Bitcoin protocol represents targets as a custom floating point type with limited precision; as a result, Bitcoin clients often approximate difficulty based on this (this is known as &amp;quot;bdiff&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
===How is difficulty stored in blocks?===&lt;br /&gt;
&lt;br /&gt;
Each block stores a packed representation (called &amp;quot;Bits&amp;quot;) for its actual hexadecimal [[target]]. The target can be derived from it via a predefined formula. For example, if the packed target in the block is 0x1b0404cb, the hexadecimal target is&lt;br /&gt;
 0x0404cb * 2**(8*(0x1b - 3)) = 0x00000000000404CB000000000000000000000000000000000000000000000000&lt;br /&gt;
&lt;br /&gt;
Note that the 0x0404cb value is a signed value in this format. The largest legal value for this field is 0x7fffff. To make a larger value you must shift it down one full byte. Also 0x008000 is the smallest positive valid value.&lt;br /&gt;
&lt;br /&gt;
===How is difficulty calculated? What is the difference between bdiff and pdiff?===&lt;br /&gt;
&lt;br /&gt;
The highest possible target (difficulty 1) is defined as 0x1d00ffff, which gives us a hex target of&lt;br /&gt;
 0x00ffff * 2**(8*(0x1d - 3)) = 0x00000000FFFF0000000000000000000000000000000000000000000000000000&lt;br /&gt;
&lt;br /&gt;
It should be noted that pooled mining often uses non-truncated targets, which puts &amp;quot;pool difficulty 1&amp;quot; at&lt;br /&gt;
 0x00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF&lt;br /&gt;
&lt;br /&gt;
So the difficulty at 0x1b0404cb is therefore:&lt;br /&gt;
 0x00000000FFFF0000000000000000000000000000000000000000000000000000 /&lt;br /&gt;
 0x00000000000404CB000000000000000000000000000000000000000000000000 &lt;br /&gt;
 = 16307.420938523983 (bdiff)&lt;br /&gt;
And:&lt;br /&gt;
 0x00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF /&lt;br /&gt;
 0x00000000000404CB000000000000000000000000000000000000000000000000 &lt;br /&gt;
 = 16307.669773817162 (pdiff)&lt;br /&gt;
&lt;br /&gt;
Here's a fast way to calculate bitcoin difficulty. It uses a modified Taylor series for the logarithm (you can see tutorials on flipcode and wikipedia) and relies on logs to transform the difficulty calculation:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;cmath&amp;gt;&lt;br /&gt;
&lt;br /&gt;
inline float fast_log(float val)&lt;br /&gt;
{&lt;br /&gt;
   int * const exp_ptr = reinterpret_cast &amp;lt;int *&amp;gt;(&amp;amp;val);&lt;br /&gt;
   int x = *exp_ptr;&lt;br /&gt;
   const int log_2 = ((x &amp;gt;&amp;gt; 23) &amp;amp; 255) - 128;&lt;br /&gt;
   x &amp;amp;= ~(255 &amp;lt;&amp;lt; 23);&lt;br /&gt;
   x += 127 &amp;lt;&amp;lt; 23;&lt;br /&gt;
   *exp_ptr = x;&lt;br /&gt;
&lt;br /&gt;
   val = ((-1.0f/3) * val + 2) * val - 2.0f/3;&lt;br /&gt;
   return ((val + log_2) * 0.69314718f);&lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
float difficulty(unsigned int bits)&lt;br /&gt;
{&lt;br /&gt;
    static double max_body = fast_log(0x00ffff), scaland = fast_log(256);&lt;br /&gt;
    return exp(max_body - fast_log(bits &amp;amp; 0x00ffffff) + scaland * (0x1d - ((bits &amp;amp; 0xff000000) &amp;gt;&amp;gt; 24)));&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
    std::cout &amp;lt;&amp;lt; difficulty(0x1b0404cb) &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To see the math to go from the normal difficulty calculations (which require large big ints bigger than the space in any normal integer) to the calculation above, here's some python:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import decimal, math&lt;br /&gt;
l = math.log&lt;br /&gt;
e = math.e&lt;br /&gt;
&lt;br /&gt;
print 0x00ffff * 2**(8*(0x1d - 3)) / float(0x0404cb * 2**(8*(0x1b - 3)))&lt;br /&gt;
print l(0x00ffff * 2**(8*(0x1d - 3)) / float(0x0404cb * 2**(8*(0x1b - 3))))&lt;br /&gt;
print l(0x00ffff * 2**(8*(0x1d - 3))) - l(0x0404cb * 2**(8*(0x1b - 3)))&lt;br /&gt;
print l(0x00ffff) + l(2**(8*(0x1d - 3))) - l(0x0404cb) - l(2**(8*(0x1b - 3)))&lt;br /&gt;
print l(0x00ffff) + (8*(0x1d - 3))*l(2) - l(0x0404cb) - (8*(0x1b - 3))*l(2)&lt;br /&gt;
print l(0x00ffff / float(0x0404cb)) + (8*(0x1d - 3))*l(2) - (8*(0x1b - 3))*l(2)&lt;br /&gt;
print l(0x00ffff / float(0x0404cb)) + (0x1d - 0x1b)*l(2**8)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== What is the current difficulty? ===&lt;br /&gt;
[http://blockexplorer.com/q/getdifficulty Current difficulty], as output by Bitcoin's getDifficulty.&lt;br /&gt;
&lt;br /&gt;
[http://bitcoin.sipa.be Graphs]&lt;br /&gt;
&lt;br /&gt;
=== What is the maximum difficulty? ===&lt;br /&gt;
&lt;br /&gt;
There is no minimum target. The maximum difficulty is roughly: maximum_target / 1 (since 0 would result in infinity), which is a ridiculously huge number (about 2^224).&lt;br /&gt;
&lt;br /&gt;
The actual maximum difficulty is when current_target=0, but we would not be able to calculate the difficulty if that happened. (fortunately it never will, so we're ok.)&lt;br /&gt;
&lt;br /&gt;
=== Can the network difficulty go down? ===&lt;br /&gt;
Yes it can. See discussion in [[target]].&lt;br /&gt;
&lt;br /&gt;
=== What is the minimum difficulty? ===&lt;br /&gt;
The minimum difficulty, when the target is at the maximum allowed value, is 1.&lt;br /&gt;
&lt;br /&gt;
=== What network hash rate results in a given difficulty? ===&lt;br /&gt;
The difficulty is adjusted every 2016 blocks based on the [[Block_timestamp|time]] it took to find the previous 2016 blocks.  At the desired rate of one block each 10 minutes, 2016 blocks would take exactly two weeks to find.  If the previous 2016 blocks took more than two weeks to find, the difficulty is reduced.  If they took less than two weeks, the difficulty is increased.  The change in difficulty is in proportion to the amount of time over or under two weeks the previous 2016 blocks took to find.&lt;br /&gt;
&lt;br /&gt;
To find a block, the hash must be less than the target.  The hash is effectively a random number between 0 and 2**256-1.  The offset for difficulty 1 is&lt;br /&gt;
 0xffff * 2**208&lt;br /&gt;
and for difficulty D is&lt;br /&gt;
 (0xffff * 2**208)/D&lt;br /&gt;
&lt;br /&gt;
The expected number of hashes we need to calculate to find a block with difficulty D is therefore&lt;br /&gt;
 D * 2**256 / (0xffff * 2**208)&lt;br /&gt;
or just&lt;br /&gt;
 D * 2**48 / 0xffff&lt;br /&gt;
&lt;br /&gt;
The difficulty is set such that the previous 2016 blocks would have been found at the rate of one every 10 minutes, so we were calculating (D * 2**48 / 0xffff) hashes in 600 seconds.  That means the hash rate of the network was&lt;br /&gt;
 D * 2**48 / 0xffff / 600&lt;br /&gt;
over the previous 2016 blocks.  Can be further simplified to&lt;br /&gt;
 D * 2**32 / 600&lt;br /&gt;
without much loss of accuracy.&lt;br /&gt;
&lt;br /&gt;
At difficulty 1, that is around 7 Mhashes per second.&lt;br /&gt;
&lt;br /&gt;
At the time of writing, the difficulty is 22012.4941572, which means that over the previous set of 2016 blocks found the average network hash rate was&lt;br /&gt;
 22012.4941572 * 2**32 / 600 = around 157 Ghashes per second.&lt;br /&gt;
&lt;br /&gt;
=== How soon might I expect to generate a block? ===&lt;br /&gt;
(The [https://www.bitcointalk.org/index.php?topic=1682.0 eternal question].)&lt;br /&gt;
&lt;br /&gt;
The average time to find a block can be approximated by calculating:&lt;br /&gt;
 time = difficulty * 2**32 / hashrate&lt;br /&gt;
where difficulty is the current difficulty, hashrate is the number of hashes your miner calculates per second, and time is the average in seconds between the blocks you find.&lt;br /&gt;
&lt;br /&gt;
For example, using Python we calculate the average time to generate a block using a 1Ghash/s mining rig when the difficulty is 20000:&lt;br /&gt;
 $ python -c &amp;quot;print 20000 * 2**32 / 10**9 / 60 / 60.0&amp;quot;&lt;br /&gt;
 23.85&lt;br /&gt;
and find that it takes just under 24 hours on average.&lt;br /&gt;
&lt;br /&gt;
* Any one grinding of the hash stands the same chance of &amp;quot;winning&amp;quot; as any other.  The numbers game is how many attempts your hardware can make per second.&lt;br /&gt;
* You need to know the difficulty (above) and your khash/sec rate (reported by the client).&lt;br /&gt;
** [[Mining Hardware Comparison]] has some stats that may help you predict what you could get.&lt;br /&gt;
* Visit a calculator or perform the maths yourself,&lt;br /&gt;
** http://www.alloscomp.com/bitcoin/calculator.php&lt;br /&gt;
** http://www.vnbitcoin.org/bitcoincalculator.php&lt;br /&gt;
** https://bitknock.com/calculator&lt;br /&gt;
**https://99bitcoins.com/bitcoin-mining-calculator&lt;br /&gt;
* Remember it's just probability!  There are no guarantees you will win every N days.&lt;br /&gt;
&lt;br /&gt;
==Related Links==&lt;br /&gt;
&lt;br /&gt;
* [https://docs.google.com/spreadsheet/ccc?key=0AiFMBvXvL2dtdEZkR2J4eU5rS3B4ei1iUmJxSWNlQ0E Bitcoin Difficulty History]&lt;br /&gt;
* [https://www.bitcoinmining.com/what-is-bitcoin-mining-difficulty/ What is Bitcoin Mining Difficulty?]&lt;br /&gt;
* See also: [[Target]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Technical]]&lt;br /&gt;
[[Category:Vocabulary]]&lt;br /&gt;
&lt;br /&gt;
[[pl:Trudność]]&lt;/div&gt;</summary>
		<author><name>Angus Adams</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.bitcoinsv.io/index.php?title=Difficulty&amp;diff=1027</id>
		<title>Difficulty</title>
		<link rel="alternate" type="text/html" href="https://wiki.bitcoinsv.io/index.php?title=Difficulty&amp;diff=1027"/>
		<updated>2020-01-09T16:44:25Z</updated>

		<summary type="html">&lt;p&gt;Angus Adams: /* What is the formula for difficulty? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;''See also: [[Target]]''&lt;br /&gt;
&lt;br /&gt;
=== What is difficulty? ===&lt;br /&gt;
&lt;br /&gt;
Difficulty is a measure of how difficult it is to find a hash below a given [[target]]. Difficulty answers the question: &amp;quot;how many times more difficult is it to mine a block now, compared with how difficult it was to mine the [[Genesis block|Genesis Block]]?&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The Bitcoin network has a global block difficulty. Valid blocks must have a hash below this target.&lt;br /&gt;
Mining pools also have a pool-specific share difficulty setting a lower limit for shares.&lt;br /&gt;
&lt;br /&gt;
=== How often does the network difficulty change? ===&lt;br /&gt;
&lt;br /&gt;
See [[Target|target]].&lt;br /&gt;
&lt;br /&gt;
=== What is the formula for difficulty? ===&lt;br /&gt;
difficulty = difficulty_1_target / current_target &lt;br /&gt;
&lt;br /&gt;
(target is a 256 bit number)&lt;br /&gt;
''Difficulty_1_target is the target used in the Genesis Block and represents a difficulty of 1.''&lt;br /&gt;
&lt;br /&gt;
difficulty_1_target can be different for various ways to measure difficulty.&lt;br /&gt;
Traditionally, it represents a hash where the leading 32 bits are zero and the rest are one (this is known as &amp;quot;pool difficulty&amp;quot; or &amp;quot;pdiff&amp;quot;).&lt;br /&gt;
The Bitcoin protocol represents targets as a custom floating point type with limited precision; as a result, Bitcoin clients often approximate difficulty based on this (this is known as &amp;quot;bdiff&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
===How is difficulty stored in blocks?===&lt;br /&gt;
&lt;br /&gt;
Each block stores a packed representation (called &amp;quot;Bits&amp;quot;) for its actual hexadecimal [[target]]. The target can be derived from it via a predefined formula. For example, if the packed target in the block is 0x1b0404cb, the hexadecimal target is&lt;br /&gt;
 0x0404cb * 2**(8*(0x1b - 3)) = 0x00000000000404CB000000000000000000000000000000000000000000000000&lt;br /&gt;
&lt;br /&gt;
Note that the 0x0404cb value is a signed value in this format. The largest legal value for this field is 0x7fffff. To make a larger value you must shift it down one full byte. Also 0x008000 is the smallest positive valid value.&lt;br /&gt;
&lt;br /&gt;
===How is difficulty calculated? What is the difference between bdiff and pdiff?===&lt;br /&gt;
&lt;br /&gt;
The highest possible target (difficulty 1) is defined as 0x1d00ffff, which gives us a hex target of&lt;br /&gt;
 0x00ffff * 2**(8*(0x1d - 3)) = 0x00000000FFFF0000000000000000000000000000000000000000000000000000&lt;br /&gt;
&lt;br /&gt;
It should be noted that pooled mining often uses non-truncated targets, which puts &amp;quot;pool difficulty 1&amp;quot; at&lt;br /&gt;
 0x00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF&lt;br /&gt;
&lt;br /&gt;
So the difficulty at 0x1b0404cb is therefore:&lt;br /&gt;
 0x00000000FFFF0000000000000000000000000000000000000000000000000000 /&lt;br /&gt;
 0x00000000000404CB000000000000000000000000000000000000000000000000 &lt;br /&gt;
 = 16307.420938523983 (bdiff)&lt;br /&gt;
And:&lt;br /&gt;
 0x00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF /&lt;br /&gt;
 0x00000000000404CB000000000000000000000000000000000000000000000000 &lt;br /&gt;
 = 16307.669773817162 (pdiff)&lt;br /&gt;
&lt;br /&gt;
Here's a fast way to calculate bitcoin difficulty. It uses a modified Taylor series for the logarithm (you can see tutorials on flipcode and wikipedia) and relies on logs to transform the difficulty calculation:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;cmath&amp;gt;&lt;br /&gt;
&lt;br /&gt;
inline float fast_log(float val)&lt;br /&gt;
{&lt;br /&gt;
   int * const exp_ptr = reinterpret_cast &amp;lt;int *&amp;gt;(&amp;amp;val);&lt;br /&gt;
   int x = *exp_ptr;&lt;br /&gt;
   const int log_2 = ((x &amp;gt;&amp;gt; 23) &amp;amp; 255) - 128;&lt;br /&gt;
   x &amp;amp;= ~(255 &amp;lt;&amp;lt; 23);&lt;br /&gt;
   x += 127 &amp;lt;&amp;lt; 23;&lt;br /&gt;
   *exp_ptr = x;&lt;br /&gt;
&lt;br /&gt;
   val = ((-1.0f/3) * val + 2) * val - 2.0f/3;&lt;br /&gt;
   return ((val + log_2) * 0.69314718f);&lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
float difficulty(unsigned int bits)&lt;br /&gt;
{&lt;br /&gt;
    static double max_body = fast_log(0x00ffff), scaland = fast_log(256);&lt;br /&gt;
    return exp(max_body - fast_log(bits &amp;amp; 0x00ffffff) + scaland * (0x1d - ((bits &amp;amp; 0xff000000) &amp;gt;&amp;gt; 24)));&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
    std::cout &amp;lt;&amp;lt; difficulty(0x1b0404cb) &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To see the math to go from the normal difficulty calculations (which require large big ints bigger than the space in any normal integer) to the calculation above, here's some python:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import decimal, math&lt;br /&gt;
l = math.log&lt;br /&gt;
e = math.e&lt;br /&gt;
&lt;br /&gt;
print 0x00ffff * 2**(8*(0x1d - 3)) / float(0x0404cb * 2**(8*(0x1b - 3)))&lt;br /&gt;
print l(0x00ffff * 2**(8*(0x1d - 3)) / float(0x0404cb * 2**(8*(0x1b - 3))))&lt;br /&gt;
print l(0x00ffff * 2**(8*(0x1d - 3))) - l(0x0404cb * 2**(8*(0x1b - 3)))&lt;br /&gt;
print l(0x00ffff) + l(2**(8*(0x1d - 3))) - l(0x0404cb) - l(2**(8*(0x1b - 3)))&lt;br /&gt;
print l(0x00ffff) + (8*(0x1d - 3))*l(2) - l(0x0404cb) - (8*(0x1b - 3))*l(2)&lt;br /&gt;
print l(0x00ffff / float(0x0404cb)) + (8*(0x1d - 3))*l(2) - (8*(0x1b - 3))*l(2)&lt;br /&gt;
print l(0x00ffff / float(0x0404cb)) + (0x1d - 0x1b)*l(2**8)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== What is the current difficulty? ===&lt;br /&gt;
[http://blockexplorer.com/q/getdifficulty Current difficulty], as output by Bitcoin's getDifficulty.&lt;br /&gt;
&lt;br /&gt;
[http://bitcoin.sipa.be Graphs]&lt;br /&gt;
&lt;br /&gt;
=== What is the maximum difficulty? ===&lt;br /&gt;
&lt;br /&gt;
There is no minimum target. The maximum difficulty is roughly: maximum_target / 1 (since 0 would result in infinity), which is a ridiculously huge number (about 2^224).&lt;br /&gt;
&lt;br /&gt;
The actual maximum difficulty is when current_target=0, but we would not be able to calculate the difficulty if that happened. (fortunately it never will, so we're ok.)&lt;br /&gt;
&lt;br /&gt;
=== Can the network difficulty go down? ===&lt;br /&gt;
Yes it can. See discussion in [[target]].&lt;br /&gt;
&lt;br /&gt;
=== What is the minimum difficulty? ===&lt;br /&gt;
The minimum difficulty, when the target is at the maximum allowed value, is 1.&lt;br /&gt;
&lt;br /&gt;
=== What network hash rate results in a given difficulty? ===&lt;br /&gt;
The difficulty is adjusted every 2016 blocks based on the [[Block_timestamp|time]] it took to find the previous 2016 blocks.  At the desired rate of one block each 10 minutes, 2016 blocks would take exactly two weeks to find.  If the previous 2016 blocks took more than two weeks to find, the difficulty is reduced.  If they took less than two weeks, the difficulty is increased.  The change in difficulty is in proportion to the amount of time over or under two weeks the previous 2016 blocks took to find.&lt;br /&gt;
&lt;br /&gt;
To find a block, the hash must be less than the target.  The hash is effectively a random number between 0 and 2**256-1.  The offset for difficulty 1 is&lt;br /&gt;
 0xffff * 2**208&lt;br /&gt;
and for difficulty D is&lt;br /&gt;
 (0xffff * 2**208)/D&lt;br /&gt;
&lt;br /&gt;
The expected number of hashes we need to calculate to find a block with difficulty D is therefore&lt;br /&gt;
 D * 2**256 / (0xffff * 2**208)&lt;br /&gt;
or just&lt;br /&gt;
 D * 2**48 / 0xffff&lt;br /&gt;
&lt;br /&gt;
The difficulty is set such that the previous 2016 blocks would have been found at the rate of one every 10 minutes, so we were calculating (D * 2**48 / 0xffff) hashes in 600 seconds.  That means the hash rate of the network was&lt;br /&gt;
 D * 2**48 / 0xffff / 600&lt;br /&gt;
over the previous 2016 blocks.  Can be further simplified to&lt;br /&gt;
 D * 2**32 / 600&lt;br /&gt;
without much loss of accuracy.&lt;br /&gt;
&lt;br /&gt;
At difficulty 1, that is around 7 Mhashes per second.&lt;br /&gt;
&lt;br /&gt;
At the time of writing, the difficulty is 22012.4941572, which means that over the previous set of 2016 blocks found the average network hash rate was&lt;br /&gt;
 22012.4941572 * 2**32 / 600 = around 157 Ghashes per second.&lt;br /&gt;
&lt;br /&gt;
=== How soon might I expect to generate a block? ===&lt;br /&gt;
(The [https://www.bitcointalk.org/index.php?topic=1682.0 eternal question].)&lt;br /&gt;
&lt;br /&gt;
The average time to find a block can be approximated by calculating:&lt;br /&gt;
 time = difficulty * 2**32 / hashrate&lt;br /&gt;
where difficulty is the current difficulty, hashrate is the number of hashes your miner calculates per second, and time is the average in seconds between the blocks you find.&lt;br /&gt;
&lt;br /&gt;
For example, using Python we calculate the average time to generate a block using a 1Ghash/s mining rig when the difficulty is 20000:&lt;br /&gt;
 $ python -c &amp;quot;print 20000 * 2**32 / 10**9 / 60 / 60.0&amp;quot;&lt;br /&gt;
 23.85&lt;br /&gt;
and find that it takes just under 24 hours on average.&lt;br /&gt;
&lt;br /&gt;
* Any one grinding of the hash stands the same chance of &amp;quot;winning&amp;quot; as any other.  The numbers game is how many attempts your hardware can make per second.&lt;br /&gt;
* You need to know the difficulty (above) and your khash/sec rate (reported by the client).&lt;br /&gt;
** [[Mining Hardware Comparison]] has some stats that may help you predict what you could get.&lt;br /&gt;
* Visit a calculator or perform the maths yourself,&lt;br /&gt;
** http://www.alloscomp.com/bitcoin/calculator.php&lt;br /&gt;
** http://www.vnbitcoin.org/bitcoincalculator.php&lt;br /&gt;
** https://bitknock.com/calculator&lt;br /&gt;
**https://99bitcoins.com/bitcoin-mining-calculator&lt;br /&gt;
* Remember it's just probability!  There are no guarantees you will win every N days.&lt;br /&gt;
&lt;br /&gt;
==Related Links==&lt;br /&gt;
&lt;br /&gt;
* [https://docs.google.com/spreadsheet/ccc?key=0AiFMBvXvL2dtdEZkR2J4eU5rS3B4ei1iUmJxSWNlQ0E Bitcoin Difficulty History]&lt;br /&gt;
* [https://www.bitcoinmining.com/what-is-bitcoin-mining-difficulty/ What is Bitcoin Mining Difficulty?]&lt;br /&gt;
* See also: [[Target]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Technical]]&lt;br /&gt;
[[Category:Vocabulary]]&lt;br /&gt;
&lt;br /&gt;
[[pl:Trudność]]&lt;/div&gt;</summary>
		<author><name>Angus Adams</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.bitcoinsv.io/index.php?title=Difficulty&amp;diff=1026</id>
		<title>Difficulty</title>
		<link rel="alternate" type="text/html" href="https://wiki.bitcoinsv.io/index.php?title=Difficulty&amp;diff=1026"/>
		<updated>2020-01-09T16:43:55Z</updated>

		<summary type="html">&lt;p&gt;Angus Adams: /* What is the formula for difficulty? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;''See also: [[Target]]''&lt;br /&gt;
&lt;br /&gt;
=== What is difficulty? ===&lt;br /&gt;
&lt;br /&gt;
Difficulty is a measure of how difficult it is to find a hash below a given [[target]]. Difficulty answers the question: &amp;quot;how many times more difficult is it to mine a block now, compared with how difficult it was to mine the [[Genesis block|Genesis Block]]?&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The Bitcoin network has a global block difficulty. Valid blocks must have a hash below this target.&lt;br /&gt;
Mining pools also have a pool-specific share difficulty setting a lower limit for shares.&lt;br /&gt;
&lt;br /&gt;
=== How often does the network difficulty change? ===&lt;br /&gt;
&lt;br /&gt;
See [[Target|target]].&lt;br /&gt;
&lt;br /&gt;
=== What is the formula for difficulty? ===&lt;br /&gt;
''Difficulty_1_target is the target used in the Genesis Block and represents a difficulty of 1.''&lt;br /&gt;
&lt;br /&gt;
difficulty = difficulty_1_target / current_target &lt;br /&gt;
&lt;br /&gt;
(target is a 256 bit number)&lt;br /&gt;
&lt;br /&gt;
difficulty_1_target can be different for various ways to measure difficulty.&lt;br /&gt;
Traditionally, it represents a hash where the leading 32 bits are zero and the rest are one (this is known as &amp;quot;pool difficulty&amp;quot; or &amp;quot;pdiff&amp;quot;).&lt;br /&gt;
The Bitcoin protocol represents targets as a custom floating point type with limited precision; as a result, Bitcoin clients often approximate difficulty based on this (this is known as &amp;quot;bdiff&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
===How is difficulty stored in blocks?===&lt;br /&gt;
&lt;br /&gt;
Each block stores a packed representation (called &amp;quot;Bits&amp;quot;) for its actual hexadecimal [[target]]. The target can be derived from it via a predefined formula. For example, if the packed target in the block is 0x1b0404cb, the hexadecimal target is&lt;br /&gt;
 0x0404cb * 2**(8*(0x1b - 3)) = 0x00000000000404CB000000000000000000000000000000000000000000000000&lt;br /&gt;
&lt;br /&gt;
Note that the 0x0404cb value is a signed value in this format. The largest legal value for this field is 0x7fffff. To make a larger value you must shift it down one full byte. Also 0x008000 is the smallest positive valid value.&lt;br /&gt;
&lt;br /&gt;
===How is difficulty calculated? What is the difference between bdiff and pdiff?===&lt;br /&gt;
&lt;br /&gt;
The highest possible target (difficulty 1) is defined as 0x1d00ffff, which gives us a hex target of&lt;br /&gt;
 0x00ffff * 2**(8*(0x1d - 3)) = 0x00000000FFFF0000000000000000000000000000000000000000000000000000&lt;br /&gt;
&lt;br /&gt;
It should be noted that pooled mining often uses non-truncated targets, which puts &amp;quot;pool difficulty 1&amp;quot; at&lt;br /&gt;
 0x00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF&lt;br /&gt;
&lt;br /&gt;
So the difficulty at 0x1b0404cb is therefore:&lt;br /&gt;
 0x00000000FFFF0000000000000000000000000000000000000000000000000000 /&lt;br /&gt;
 0x00000000000404CB000000000000000000000000000000000000000000000000 &lt;br /&gt;
 = 16307.420938523983 (bdiff)&lt;br /&gt;
And:&lt;br /&gt;
 0x00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF /&lt;br /&gt;
 0x00000000000404CB000000000000000000000000000000000000000000000000 &lt;br /&gt;
 = 16307.669773817162 (pdiff)&lt;br /&gt;
&lt;br /&gt;
Here's a fast way to calculate bitcoin difficulty. It uses a modified Taylor series for the logarithm (you can see tutorials on flipcode and wikipedia) and relies on logs to transform the difficulty calculation:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;cmath&amp;gt;&lt;br /&gt;
&lt;br /&gt;
inline float fast_log(float val)&lt;br /&gt;
{&lt;br /&gt;
   int * const exp_ptr = reinterpret_cast &amp;lt;int *&amp;gt;(&amp;amp;val);&lt;br /&gt;
   int x = *exp_ptr;&lt;br /&gt;
   const int log_2 = ((x &amp;gt;&amp;gt; 23) &amp;amp; 255) - 128;&lt;br /&gt;
   x &amp;amp;= ~(255 &amp;lt;&amp;lt; 23);&lt;br /&gt;
   x += 127 &amp;lt;&amp;lt; 23;&lt;br /&gt;
   *exp_ptr = x;&lt;br /&gt;
&lt;br /&gt;
   val = ((-1.0f/3) * val + 2) * val - 2.0f/3;&lt;br /&gt;
   return ((val + log_2) * 0.69314718f);&lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
float difficulty(unsigned int bits)&lt;br /&gt;
{&lt;br /&gt;
    static double max_body = fast_log(0x00ffff), scaland = fast_log(256);&lt;br /&gt;
    return exp(max_body - fast_log(bits &amp;amp; 0x00ffffff) + scaland * (0x1d - ((bits &amp;amp; 0xff000000) &amp;gt;&amp;gt; 24)));&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
    std::cout &amp;lt;&amp;lt; difficulty(0x1b0404cb) &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To see the math to go from the normal difficulty calculations (which require large big ints bigger than the space in any normal integer) to the calculation above, here's some python:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import decimal, math&lt;br /&gt;
l = math.log&lt;br /&gt;
e = math.e&lt;br /&gt;
&lt;br /&gt;
print 0x00ffff * 2**(8*(0x1d - 3)) / float(0x0404cb * 2**(8*(0x1b - 3)))&lt;br /&gt;
print l(0x00ffff * 2**(8*(0x1d - 3)) / float(0x0404cb * 2**(8*(0x1b - 3))))&lt;br /&gt;
print l(0x00ffff * 2**(8*(0x1d - 3))) - l(0x0404cb * 2**(8*(0x1b - 3)))&lt;br /&gt;
print l(0x00ffff) + l(2**(8*(0x1d - 3))) - l(0x0404cb) - l(2**(8*(0x1b - 3)))&lt;br /&gt;
print l(0x00ffff) + (8*(0x1d - 3))*l(2) - l(0x0404cb) - (8*(0x1b - 3))*l(2)&lt;br /&gt;
print l(0x00ffff / float(0x0404cb)) + (8*(0x1d - 3))*l(2) - (8*(0x1b - 3))*l(2)&lt;br /&gt;
print l(0x00ffff / float(0x0404cb)) + (0x1d - 0x1b)*l(2**8)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== What is the current difficulty? ===&lt;br /&gt;
[http://blockexplorer.com/q/getdifficulty Current difficulty], as output by Bitcoin's getDifficulty.&lt;br /&gt;
&lt;br /&gt;
[http://bitcoin.sipa.be Graphs]&lt;br /&gt;
&lt;br /&gt;
=== What is the maximum difficulty? ===&lt;br /&gt;
&lt;br /&gt;
There is no minimum target. The maximum difficulty is roughly: maximum_target / 1 (since 0 would result in infinity), which is a ridiculously huge number (about 2^224).&lt;br /&gt;
&lt;br /&gt;
The actual maximum difficulty is when current_target=0, but we would not be able to calculate the difficulty if that happened. (fortunately it never will, so we're ok.)&lt;br /&gt;
&lt;br /&gt;
=== Can the network difficulty go down? ===&lt;br /&gt;
Yes it can. See discussion in [[target]].&lt;br /&gt;
&lt;br /&gt;
=== What is the minimum difficulty? ===&lt;br /&gt;
The minimum difficulty, when the target is at the maximum allowed value, is 1.&lt;br /&gt;
&lt;br /&gt;
=== What network hash rate results in a given difficulty? ===&lt;br /&gt;
The difficulty is adjusted every 2016 blocks based on the [[Block_timestamp|time]] it took to find the previous 2016 blocks.  At the desired rate of one block each 10 minutes, 2016 blocks would take exactly two weeks to find.  If the previous 2016 blocks took more than two weeks to find, the difficulty is reduced.  If they took less than two weeks, the difficulty is increased.  The change in difficulty is in proportion to the amount of time over or under two weeks the previous 2016 blocks took to find.&lt;br /&gt;
&lt;br /&gt;
To find a block, the hash must be less than the target.  The hash is effectively a random number between 0 and 2**256-1.  The offset for difficulty 1 is&lt;br /&gt;
 0xffff * 2**208&lt;br /&gt;
and for difficulty D is&lt;br /&gt;
 (0xffff * 2**208)/D&lt;br /&gt;
&lt;br /&gt;
The expected number of hashes we need to calculate to find a block with difficulty D is therefore&lt;br /&gt;
 D * 2**256 / (0xffff * 2**208)&lt;br /&gt;
or just&lt;br /&gt;
 D * 2**48 / 0xffff&lt;br /&gt;
&lt;br /&gt;
The difficulty is set such that the previous 2016 blocks would have been found at the rate of one every 10 minutes, so we were calculating (D * 2**48 / 0xffff) hashes in 600 seconds.  That means the hash rate of the network was&lt;br /&gt;
 D * 2**48 / 0xffff / 600&lt;br /&gt;
over the previous 2016 blocks.  Can be further simplified to&lt;br /&gt;
 D * 2**32 / 600&lt;br /&gt;
without much loss of accuracy.&lt;br /&gt;
&lt;br /&gt;
At difficulty 1, that is around 7 Mhashes per second.&lt;br /&gt;
&lt;br /&gt;
At the time of writing, the difficulty is 22012.4941572, which means that over the previous set of 2016 blocks found the average network hash rate was&lt;br /&gt;
 22012.4941572 * 2**32 / 600 = around 157 Ghashes per second.&lt;br /&gt;
&lt;br /&gt;
=== How soon might I expect to generate a block? ===&lt;br /&gt;
(The [https://www.bitcointalk.org/index.php?topic=1682.0 eternal question].)&lt;br /&gt;
&lt;br /&gt;
The average time to find a block can be approximated by calculating:&lt;br /&gt;
 time = difficulty * 2**32 / hashrate&lt;br /&gt;
where difficulty is the current difficulty, hashrate is the number of hashes your miner calculates per second, and time is the average in seconds between the blocks you find.&lt;br /&gt;
&lt;br /&gt;
For example, using Python we calculate the average time to generate a block using a 1Ghash/s mining rig when the difficulty is 20000:&lt;br /&gt;
 $ python -c &amp;quot;print 20000 * 2**32 / 10**9 / 60 / 60.0&amp;quot;&lt;br /&gt;
 23.85&lt;br /&gt;
and find that it takes just under 24 hours on average.&lt;br /&gt;
&lt;br /&gt;
* Any one grinding of the hash stands the same chance of &amp;quot;winning&amp;quot; as any other.  The numbers game is how many attempts your hardware can make per second.&lt;br /&gt;
* You need to know the difficulty (above) and your khash/sec rate (reported by the client).&lt;br /&gt;
** [[Mining Hardware Comparison]] has some stats that may help you predict what you could get.&lt;br /&gt;
* Visit a calculator or perform the maths yourself,&lt;br /&gt;
** http://www.alloscomp.com/bitcoin/calculator.php&lt;br /&gt;
** http://www.vnbitcoin.org/bitcoincalculator.php&lt;br /&gt;
** https://bitknock.com/calculator&lt;br /&gt;
**https://99bitcoins.com/bitcoin-mining-calculator&lt;br /&gt;
* Remember it's just probability!  There are no guarantees you will win every N days.&lt;br /&gt;
&lt;br /&gt;
==Related Links==&lt;br /&gt;
&lt;br /&gt;
* [https://docs.google.com/spreadsheet/ccc?key=0AiFMBvXvL2dtdEZkR2J4eU5rS3B4ei1iUmJxSWNlQ0E Bitcoin Difficulty History]&lt;br /&gt;
* [https://www.bitcoinmining.com/what-is-bitcoin-mining-difficulty/ What is Bitcoin Mining Difficulty?]&lt;br /&gt;
* See also: [[Target]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Technical]]&lt;br /&gt;
[[Category:Vocabulary]]&lt;br /&gt;
&lt;br /&gt;
[[pl:Trudność]]&lt;/div&gt;</summary>
		<author><name>Angus Adams</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.bitcoinsv.io/index.php?title=Target&amp;diff=1025</id>
		<title>Target</title>
		<link rel="alternate" type="text/html" href="https://wiki.bitcoinsv.io/index.php?title=Target&amp;diff=1025"/>
		<updated>2020-01-09T16:42:16Z</updated>

		<summary type="html">&lt;p&gt;Angus Adams: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;''See also: [[Difficulty]]''&lt;br /&gt;
&lt;br /&gt;
The '''target''' is a 256-bit number (extremely large) that all Bitcoin clients share. The SHA-256 [https://wiki.bitcoinsv.io/index.php/Mining#Hashing hash] of a [[Block hashing algorithm|block's header]] must be less than or equal to the current target for the block to be accepted by the network. The lower the target, the more [[difficulty|difficult]] it is to generate a block.&lt;br /&gt;
&lt;br /&gt;
It's important to realize that block generation is not a long, set problem (like doing a million hashes), but more like a lottery. Each hash basically gives you a random number between 0 and the maximum value of a 256-bit number (2^256-1). If your hash is below the target, then you win. If not, you increment the nonce (completely changing the hash) and try again. &lt;br /&gt;
&lt;br /&gt;
The bitcoin network tries to produce one block every ten minutes on average. As mining hash power changes over time, it achieves this through changing the target value.&lt;br /&gt;
&lt;br /&gt;
Historically (prior to forking from BTC in August 2017), bitcoin changed its target every 2016 blocks (exactly two weeks if a block time of 10 minutes was kept perfectly). This change in the target is known as a 'difficulty adjustment'. Under the original difficulty adjustment paradigm, when adjusting the target, every bitcoin client compared the actual time it took to generate 2016 blocks with the two week goal, and modified the target by the percentage difference. A single retarget never changes the target by more than a factor of 4 either way to prevent large changes in difficulty.&lt;br /&gt;
&lt;br /&gt;
Post forking from BTC in August 2017, bitcoin changed the original difficulty adjustment algorithm to what was named the Emergency Difficulty Adjustment (EDA) algorithm. The EDA had the capacity to update the target value every time a new block was found (as opposed to every 2016 blocks), while still targeting a ten minute block time average. The EDA was changed to the Difficulty Adjustment Algorithm (DAA) on 17 November 2017 to address instabilities associated with the EDA. The DAA uses a moving average of the last 144 blocks to determine changes to the target and like the EDA, the target can change every block. &lt;br /&gt;
&lt;br /&gt;
The reason the EDA (and later, it's improvement, the DAA) needed to be implemented was because of the fork from BTC (creating BCH) in August 2017. Because it was expected that BCH would garner significantly less hash power than BTC, measures were put in place so that block production on BCH would not slow to a crawl due to inheriting BTC's target difficulty and a small number of miners. &lt;br /&gt;
&lt;br /&gt;
It is proposed that bitcoin will move back to the original difficulty adjustment algorithm (still used by BTC) in the future.&lt;br /&gt;
&lt;br /&gt;
=== What is the maximum target? ===&lt;br /&gt;
The maximum target used by SHA256 mining devices is:&lt;br /&gt;
 0x00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF&lt;br /&gt;
Because Bitcoin stores the target as a floating-point type, this is truncated:&lt;br /&gt;
 0x00000000FFFF0000000000000000000000000000000000000000000000000000&lt;br /&gt;
&lt;br /&gt;
This is the target used in the [[Genesis block|Genesis Block]] and represents a [[difficulty]] of 1.&lt;br /&gt;
&lt;br /&gt;
Since a lower target makes Bitcoin generation more difficult, the maximum target is the ''lowest'' possible [[difficulty]].&lt;br /&gt;
&lt;br /&gt;
==Related Links==&lt;br /&gt;
See also [[Difficulty]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Technical]]&lt;br /&gt;
[[Category:Vocabulary]]&lt;/div&gt;</summary>
		<author><name>Angus Adams</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.bitcoinsv.io/index.php?title=Target&amp;diff=1024</id>
		<title>Target</title>
		<link rel="alternate" type="text/html" href="https://wiki.bitcoinsv.io/index.php?title=Target&amp;diff=1024"/>
		<updated>2020-01-09T16:41:27Z</updated>

		<summary type="html">&lt;p&gt;Angus Adams: /* What is the maximum target? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;''See also: [[Difficulty]]''&lt;br /&gt;
&lt;br /&gt;
The '''target''' is a 256-bit number (extremely large) that all Bitcoin clients share. The SHA-256 [https://wiki.bitcoinsv.io/index.php/Mining#Hashing hash] of a [[Block hashing algorithm|block's header]] must be less than or equal to the current target for the block to be accepted by the network. The lower the target, the more [[difficulty|difficult]] it is to generate a block.&lt;br /&gt;
&lt;br /&gt;
It's important to realize that block generation is not a long, set problem (like doing a million hashes), but more like a lottery. Each hash basically gives you a random number between 0 and the maximum value of a 256-bit number (2^256-1). If your hash is below the target, then you win. If not, you increment the nonce (completely changing the hash) and try again. &lt;br /&gt;
&lt;br /&gt;
The bitcoin network tries to produce one block every ten minutes on average. As mining hash power changes over time, it achieves this through changing the target value.&lt;br /&gt;
&lt;br /&gt;
Historically (prior to forking from BTC in August 2017), bitcoin changed its target every 2016 blocks (exactly two weeks if a block time of 10 minutes was kept perfectly). This change in the target is known as a 'difficulty adjustment'. Under the original difficulty adjustment paradigm, when adjusting the target, every bitcoin client compared the actual time it took to generate 2016 blocks with the two week goal, and modified the target by the percentage difference. A single retarget never changes the target by more than a factor of 4 either way to prevent large changes in difficulty.&lt;br /&gt;
&lt;br /&gt;
Post forking from BTC in August 2017, bitcoin changed the original difficulty adjustment algorithm to what was named the Emergency Difficulty Adjustment (EDA) algorithm. The EDA had the capacity to update the target value every time a new block was found (as opposed to every 2016 blocks), while still targeting a ten minute block time average. The EDA was changed to the Difficulty Adjustment Algorithm (DAA) on 17 November 2017 to address instabilities associated with the EDA. The DAA uses a moving average of the last 144 blocks to determine changes to the target and like the EDA, the target can change every block. &lt;br /&gt;
&lt;br /&gt;
The reason the EDA (and later, it's improvement, the DAA) needed to be implemented was because of the fork from BTC (creating BCH) in August 2017. Because it was expected that BCH would garner significantly less hash power than BTC, measures were put in place so that block production on BCH would not slow to a crawl due to inheriting BTC's target difficulty and a small number of miners. &lt;br /&gt;
&lt;br /&gt;
It is proposed that bitcoin will move back to the original difficulty adjustment algorithm (still used by BTC) in the future.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== What is the target now? === &lt;br /&gt;
* [http://blockexplorer.com/q/getdifficulty Current difficulty], as output by Bitcoin's getDifficulty&lt;br /&gt;
&lt;br /&gt;
=== When does the target change next? ===&lt;br /&gt;
&lt;br /&gt;
* [http://blockexplorer.com/q/nextretarget Next retarget]&lt;br /&gt;
&lt;br /&gt;
=== What has the target been in the past? ===&lt;br /&gt;
&lt;br /&gt;
* [http://blockexplorer.com/q/nethash Difficulty history, (at column 5)]&lt;br /&gt;
* [http://www.bitcointalk.org/index.php?topic=2345.msg31405#msg31405 Re: difficulty over time data?]&lt;br /&gt;
* [http://bitcoin.sipa.be/ Bitcoin network graphs] &lt;br /&gt;
&lt;br /&gt;
=== What is the maximum target? ===&lt;br /&gt;
The maximum target used by SHA256 mining devices is:&lt;br /&gt;
 0x00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF&lt;br /&gt;
Because Bitcoin stores the target as a floating-point type, this is truncated:&lt;br /&gt;
 0x00000000FFFF0000000000000000000000000000000000000000000000000000&lt;br /&gt;
&lt;br /&gt;
This is the target used in the [[Genesis block|Genesis Block]] and represents a [[difficulty]] of 1.&lt;br /&gt;
&lt;br /&gt;
Since a lower target makes Bitcoin generation more difficult, the maximum target is the ''lowest'' possible [[difficulty]].&lt;br /&gt;
&lt;br /&gt;
==Related Links==&lt;br /&gt;
See also [[Difficulty]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Technical]]&lt;br /&gt;
[[Category:Vocabulary]]&lt;/div&gt;</summary>
		<author><name>Angus Adams</name></author>
		
	</entry>
</feed>