How is a block header hash compared to the target (bits)?

1

How to calculate the target from bits

Let's start with a block-header, always 80-bytes that looks like this:

04000000b9e2784a84e5d2468cee60ad14e08d0fee5dda49a37148040000000000000000e9dd2b13157508891880ef68729a1e5ecdde58062ebfa214a89f0141e5a4717faefd2b577627061880564bec

From the 80-bytes, the bits are actually the 72nd to 76th byte:

04000000b9e2784a84e5d2468cee60ad14e08d0fee5dda49a37148040000000000000000e9dd2b13157508891880ef68729a1e5ecdde58062ebfa214a89f0141e5a4717faefd2b57**76270618**80564bec

or

76270618

This number, however, is in little-endian, so we have to reverse the bytes:

18062776

The first byte is the "exponent"

e = 0x18

The next 3 bytes are the "coefficient"

c = 0x062776

You plug this into a formula:

target = c * 2**(8*(e - 3))

In our case, that is:

target = 0x062776 * 2**(8*(0x18 - 3))

Which turns out to...

0 0
2
https://en.bitcoin.it/wiki/Target

The target is a 256-bit number (extremely large) that all Bitcoin clients share. The SHA-256 hash of a block's header must be lower than or equal to the current target for the block to be accepted by the network. The lower the target, the more difficult it is to generate a block.

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

... A block is "solved" (published and considered valid by peers) when the SHA-256 hash of the entire block is below the current target.

Does both things mean the same?

I'm trying to understand the system better, thank you.

EDIT:
Also I think the Target and Difficulty articles confuses both terms. It should be clearer, IMHO. Guess I'll take it to wiki...

0 0
3

The block header is the hash returned from generating a Merlkle tree that is below the current difficulty target for the blocks data.

Whats a hash?

In order to understand what the block header is you need to understand what a hashing function is. A hashing function is a one way(non invertable function) that maps a set of inputs to a set of outputs hash(s) -> p, where for our purposes s and p are both strings. For any string s we can find the hash by applying our hashing function, which will return a new string. This is a deterministic procedure in that given an s, the same hash() will produce the same p. There is no inverse of the hash operation, so you cannot go from output to input hash^-1(p) -> s. A hash function will ideally map the domain uniformly over the range such that any input that is in the domain will have a pretty even probability of being anywhere in the range vs more likely to be in a certain section.

You use hashing operations for many...

0 0
4

Over the course of the inception of Bitcoin to the current state. There are wikis, forums, StackExchange questions, Github repos, etc. and each one of these has a different way of hashing the block.

Why the difference? Because everyone does optimization differently (some people don't change the nonce, some don't use the nonce, etc). This allows people to claim their miner is better, because they are faster. Are they doing correct bitcoin hashing? Who really knows.

This page is to give you the basic understanding of how hashing works. Why? Because there is no real central location for how everything works like in Open Source.

The Block Header

The Block Header is what everyone hashes. It is 80 bytes of data that will ultimately be hashed twice (not really, but we'll get into that later).

The header contains this info:

In most bitcoin protocols is a thing called, "Getwork." For your miner to get work to do, you need to request it. When you...

0 0
5

Today is the third time I find an attack to the way Bitcoin uses SHA-256 to perform mining. Two of the attacks belong to a new family of attacks that involve terribly technical details about the inner workings of SHA-256. These are attacks that may impact on Bitcoin probably not before 5 years, and they could even never have a real impact on Bitcoin. I will talk openly about them when I can really tell if they could affect Bitcoin. And if they can, better be prepared. The good news is that many of these attacks (at least the ones I identified) can be prevented by a hard-fork involving changing the block header without breaking compatibility with current mining ASICs. Since changing the block header requires a hard-fork, it’s free to add more nonce bytes, and so help future ASIC manufacturers to reach higher hashing rates. Also the time field could be increased to 8 bytes. The new design requires only 6 more bytes or storage in its compressed format, but mining requires the record...

0 0
6

Recently over dinner, I was asked to explain bitcoin mining, and I struggled as it is entangled with a number of other concepts. Here’s my attempt at breaking it down into bite-sized pieces.

What is bitcoin mining?

Mining is the process of writing pages (blocks) of bitcoin transactions into the bitcoin ledger, called ‘The Bitcoin Blockchain’, and getting rewarded with newly created bitcoins.

To understand this in more detail, the rest of the post describes:

How do bitcoin transactions work? Why is mining needed in bitcoin? Why do miners mine? What is this ‘computationally expensive’ guessing game? Why pay rewards in BTC instead of USD? Who mines? What can and can’t miscreants do?

If you are new to bitcoin, it might be worth having a quick read of “A gentle introduction to bitcoin”.

How do bitcoin transactions work?

The process is:

Make a payment (a bitcoin transaction) Wait for it to be mined in a block (average 10 mins) Wait for more...
0 0
7

This article explains Bitcoin mining in details, right down to the hex data and network traffic. If you've ever wondered what really happens in Bitcoin mining, you've come to the right place. My previous article,

Bitcoins the hard way

described how I manually created a Bitcoin transaction and sent it into the system. In this article, I show what happens next: how a transaction gets mined into a block.

The purpose of mining

Bitcoin mining is often thought of as the way to create new bitcoins. But that's really just a secondary purpose. The primary importance of mining is to ensure that all participants have a consistent view of the Bitcoin data. Because Bitcoin is a distributed peer-to-peer system, there is no central database that keeps track of who owns bitcoins. Instead, the log of all transactions is distributed across the network.

The main problem with a distributed transaction log is how to avoid inconsistencies that could allow someone to spend...

0 0
8

So you’ve Googled bitcoin target, read a whole bunch of stuff but still don’t get it and want to see real examples for comparisons. You’ve come to the right place. I learn best with examples so here goes.

From Bitcoin wikipedia “The target is a 256-bit number (extremely large) that all Bitcoin clients share. The SHA-256 hash of a block’s header must be lower than or equal to the current target for the block to be accepted by the network. The lower the target, the more difficult it is to generate a block.”

If this is hard for you to visualize try this.

The current Bitcoin target, or hash target can be obtained from: http://blockexplorer.com/q/hextarget

You’ll notice it is a 256 bit number (from the quoted wikipedia text above) but represented in hexidecimal meaning it is only 64 characters long. (4 bits for 1 hex character so 256 bits/4 = 64 characters).

Let’s take for example a hash target of:...

0 0
9

See also Difficulty

The target is a 256-bit number (extremely large) that all Bitcoin clients share. The SHA-256 hash of a block's header must be lower than or equal to the current target for the block to be accepted by the network. The lower the target, the more difficult it is to generate a block.

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 (which is huge). If your hash is below the target, then you win. If not, you increment the nonce (completely changing the hash) and try again.

For reasons of stability and low latency in transactions, the network tries to produce one block every 10 minutes. Every 2016 blocks (which should take two weeks if this goal is kept perfectly), every Bitcoin client compares the actual time it took to generate these blocks with the two week goal and...

0 0
10

Over the past several years there has been a lot of talk about cryptocurrencies, such as bitcoin, and the blockchain technology that underpins them. However it can be difficult to understand how the blockchain actually works in practice, and why it is such a clever method for currency exchange. Two of our graduates are currently developing our own cryptocurrency for use within Scott Logic, as an attempt to better understand the practical uses of the blockchain. In this blog post, we aim to explain the inner workings of the blockchain and help people to understand how it manages to keep transactions both secure and anonymous. This post will go into the low level algorithms of blockchain and provide verified examples alongside each algorithm; this post is not for the faint of heart!

Bitcoin is just one implementation of the blockchain. While all cryptocurrencies are based on the blockchain algorithms, there are subtle differences between the implementations. To illustrate the...

0 0
11
...
0 0
12

What is Bitcoin Mining Difficulty?

Visualize and Download High-Resolution Infographic

The Computationally-Difficult Problem

Bitcoin mining a block is difficult because the SHA-256 hash of a block's header must be lower than or equal to the target in order for the block to be accepted by the network.

This problem can be simplified for explanation purposes: The hash of a block must start with a certain number of zeros. The probability of calculating a hash that starts with many zeros is very low, therefore many attempts must be made. In order to generate a new hash each round, a nonce is incremented. This is based on the hashcash function.

The Bitcoin Network Difficulty Metric

The Bitcoin network difficulty is the measure of how difficult it is to find a new block compared to the easiest it can ever be. It is recalculated every 2016 blocks to a value such that the previous 2016 blocks would have been generated in exactly two weeks had everyone...

0 0
13

When generating litecoins, you hash a block header over and over again, changing it slightly every time. Each iteration results in entirely different hashes. A block header contains these fields: Version, hashPrevBlock, hashMerkleRoot, Time, Bits, Nonce.

See Block header

The body of the block contains the transactions; these are hashed only indirectly through the Merkle root. Transactions aren't hashed directly; therefore hashing a block with a single transaction takes the same amount of effort as hashing a block with 10,000 transactions.

The Bits field is a representation of the current target, using a special floating-point encoding. This encoding uses three bytes for the mantissa, and the leading byte as a base-256 exponent. Only the 5 lowest bits are used.

The Nonce starts at 0 and is incremented for each hash. Whenever it overflows, the extraNonce portion of the generation transaction is incremented, which changes the Merkle root.

Given just those...

0 0
14

This page covers how Bitcoin miners "solve" a block of transactions and add it to the blockchain.

535f0119

The Block.

A "block" isn't actually a fixed group of transactions (to start with). In fact, a "block" doesn't really exist until it is added to the blockchain.

Until then, it makes more sense to think of the current "block" as a bunch of unconfirmed transactions in the bitcoin network, along with a few other bits of relevant information combined together to create what we call a "block header".

This is what miners are working with when they are trying to add a block to the blockchain.

Lets look at the information a miner uses in the block header…

The block header.

Here's the block header for Block 125552 (before it got added to the blockchain).

Allow me to explain what each field means…

Version Previous block This the solution for the previous block. We're trying to get one of these for the current block....
0 0
15
0-Confirmation (Zero-Confirmation)

See Unconfirmed Transaction and Confirmation Number.

51% Attack

Also known as >50% attack or a double spend attack. An attacker can make a payment, wait till the merchant accepts some number of confirmations and provides the service, then starts mining a parallel chain of blocks starting with a block before the transaction. This parallel blockchain then includes another transaction that spends the same outputs on some other address. When the parallel chain becomes more difficult, it is considered a main chain by all nodes and the original transaction becomes invalid. Having more than a half of total hashrate guarantees possibility to overtake chain of any length, hence the name of an attack (strictly speaking, it is "more than 50%", not 51%). Also, even 40% of hashrate allows making a double spend, but the chances are less than 100% and are diminishing exponentially with the number of confirmations that the merchant requires. This attack is...

0 0
16

Block

Blocks are found in the Bitcoin block chain. Blocks connect all transactions together. Transactions are combined into single blocks and are verified every ten minutes through mining. Each subsequent block strengthens the verification of the previous blocks, making it impossible to double spend bitcoin transactions (see double spend below).

BIP

Bitcoin Improvement Proposal or BIP, is a technical design document providing information to the bitcoin community, or describing a new feature for bitcoin or its processes or environment which affect the Bitcoin protocol. New features, suggestions, and design changes to the protocol should be submitted as a BIP. The BIP author is responsible for building consensus within the community and documenting dissenting opinions.

Block Chain

The Bitcoin block chain is a public record of all Bitcoin transactions. You might also hear the term used as a “public ledger.” The block chain shows every single record...

0 0
17

Dirk Merkel continues his introduction to Bitcoin with a look at the Bitcoin network as a system. He briefly explains the mechanics of transactions, blocks, and the block chain, as well as the Bitcoin wallet. He also discusses double-spending and Bitcoin mining, two controversial aspects of Bitcoin.

Having seen how Bitcoin is used (in Part 1) we're ready to look at some of its underlying concepts as a technology and network. This article introduces the mechanics of Bitcoin's core components: transactions, blocks, and the block chain. I also demystify controversial aspects of Bitcoin such as encryption (added in v0.4 of the standard client), the problem of double-spending, and how and why Bitcoin mining happens. Finally, I use Bitcoin Block Explorer to extract some data that I then use to gauge the overall health of the Bitcoin economy today.

To get started, consider Figure 1, which illustrates the relationship between the block chain, individual blocks, and...

0 0
18

Bitcoin Miner - I mine for Bitcoin and show others how.

The Block Reward When a block is discovered, the discoverer may award themselves a certain number of bitcoins, which is agreed-upon by everyone in the network. If you have access to large amounts of cheap electricity and the ability to manage a large installation and business, you can mine for a profit. There is nothing to replace ASICs now or even in the immediate future. It must be trivial to check whether data satisfies said requirements. An ASIC is a chip designed specifically to do one thing and one thing only. Mining profitability is also dictated by the exchange rate, but under all circumstances the more power efficient the mining device, the more profitable it is.

Quick Guide on How to Mine Ethereum on Windows - Crypto.

Genesis Mining is the largest Bitcoin and scrypt cloud mining provider. The probability of calculating a hash that starts with many zeros is very low, therefore many attempts...

0 0
19

NTLM Terminology

Before we start digging in any further, we will need to define a few terms used in the various protocols.

NTLM authentication is a challenge-response scheme, consisting of three messages, commonly referred to as Type 1 (negotiation), Type 2 (challenge) and Type 3 (authentication). It basically works like this:

The client sends a Type 1 message to the server. This primarily contains a list of features supported by the client and requested of the server. The server responds with a Type 2 message. This contains a list of features supported and agreed upon by the server. Most importantly, however, it contains a challenge generated by the server. The client replies to the challenge with a Type 3 message. This contains several pieces of information about the client, including the domain and username of the client user. It also contains one or more responses to the Type 2 challenge.

The responses in the Type 3 message are the most critical...

0 0