Bitcoin Forum
May 08, 2024, 08:58:28 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: nBits  (Read 868 times)
manuelra (OP)
Newbie
*
Offline Offline

Activity: 6
Merit: 3


View Profile
December 01, 2016, 01:47:24 PM
Last edit: December 01, 2016, 02:14:08 PM by manuelra
Merited by ABCbits (1)
 #1

Suppose that a bad miner (who intends to attack the network) sucessfully mines a block for which the found hash has several zeros more than the current required POW effort. If this miner sets the nBits field on the mined block header to a value much higher than the current POW target, but compatible with hash it has found for that block AND that block is the 2016th at a given target level, what will the other nodes do?

a) reject that block because its header contains an incorrect difficulty level value
b) accept that block and choose a very hard difficulty level - which will decay only after having a hard time minning the next 2016 blocks, a process that will likely take substancially more than 2 weeks

Notes:
  • GetNextWorkRequired uses nBits from the latest block to compute the new difficulty level;
  • Apparently CheckProofOfWork checks the hash against the nBits field within the block itself, not against a locally computed dificulty target at a given height - which would be independent of the node which published the block;
  • I did not check whether the code checks that nBits is checked against such a locally computed difficulty target

See https://github.com/bitcoin/bitcoin/blob/57b34599b2deb179ff1bd97ffeab91ec9f904d85/src/pow.cpp for details.

Edit: the target effort will not increase by more that 4x, as coded within GetNextWorkRequired
1715158708
Hero Member
*
Offline Offline

Posts: 1715158708

View Profile Personal Message (Offline)

Ignore
1715158708
Reply with quote  #2

1715158708
Report to moderator
The network tries to produce one block per 10 minutes. It does this by automatically adjusting how difficult it is to produce blocks.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1715158708
Hero Member
*
Offline Offline

Posts: 1715158708

View Profile Personal Message (Offline)

Ignore
1715158708
Reply with quote  #2

1715158708
Report to moderator
piotr_n
Legendary
*
Offline Offline

Activity: 2053
Merit: 1354


aka tonikt


View Profile WWW
December 01, 2016, 02:00:27 PM
Merited by ABCbits (2)
 #2

Suppose that a bad miner (who intends to attack the network) sucessfully mines a block for which the found hash has several zeros more than the current required POW effort. If this miner sets the nBits field on the mined block header to a value much higher than the current POW target, but compatible with hash it has found for that block AND that block is the 2016th at a given target level, what will the other nodes do?
The bits field must have the exact expected value, otherwise the block gets rejected (ignored) by the nodes.
Harder or lighter - doesn't matter, it would be still invalid.

Check out gocoin - my original project of full bitcoin node & cold wallet written in Go.
PGP fingerprint: AB9E A551 E262 A87A 13BB  9059 1BE7 B545 CDF3 FD0E
ArcCsch
Full Member
***
Offline Offline

Activity: 224
Merit: 117


▲ Portable backup power source for mining.


View Profile
December 02, 2016, 09:17:13 PM
Merited by ABCbits (1)
 #3

The difficulty is hashed with the block, so if the attacker changes the difficulty, the hash would change (avalanche effect) and it would be back to square one.
The PoW is invalidated by changing any of the confirmed data, and this includes nBits.
This feature was included intentionally to prevent this.

If you don't have sole and complete control over the private keys, you don't have any bitcoin!  Signature campaigns are OK, zero tolorance for spam!
1JGYXhfhPrkiHcpYkiuCoKpdycPhGCuswa
dreamhouse
Hero Member
*****
Offline Offline

Activity: 1073
Merit: 666



View Profile
December 04, 2016, 07:51:38 AM
 #4

The current block hash depends on the previous block hash, so even you solve one with higher diff you won't be able to "save" it for the next block, as your hash will be rejected.
DannyHamilton
Legendary
*
Offline Offline

Activity: 3388
Merit: 4653



View Profile
December 04, 2016, 05:22:13 PM
 #5

- snip -
The bits field must have the exact expected value, otherwise the block gets rejected (ignored) by the nodes.
Harder or lighter - doesn't matter, it would be still invalid.

That's what I assumed, but I hadn't taken the time to go find the lines of code in Core that make that comparison.  Since you seem to have found it, can you link to it here please, and save me the time of searching for it?
piotr_n
Legendary
*
Offline Offline

Activity: 2053
Merit: 1354


aka tonikt


View Profile WWW
December 04, 2016, 05:36:45 PM
Merited by ABCbits (1)
 #6

- snip -
The bits field must have the exact expected value, otherwise the block gets rejected (ignored) by the nodes.
Harder or lighter - doesn't matter, it would be still invalid.

That's what I assumed, but I hadn't taken the time to go find the lines of code in Core that make that comparison.  Since you seem to have found it, can you link to it here please, and save me the time of searching for it?

I saw it long ago, needing to know how to implement it inside my shit.

It's moved all around the code base ever since, but look for the place where GetNextWorkRequired() is called from.

ATM it's in file validation.cpp:
Code:
bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& state, const Consensus::Params& consensusParams, const CBlockIndex* pindexPrev, int64_t nAdjustedTime)
{
    const int nHeight = pindexPrev == NULL ? 0 : pindexPrev->nHeight + 1;
    // Check proof of work
    if (block.nBits != GetNextWorkRequired(pindexPrev, &block, consensusParams))
        return state.DoS(100, false, REJECT_INVALID, "bad-diffbits", false, "incorrect proof of work");

Check out gocoin - my original project of full bitcoin node & cold wallet written in Go.
PGP fingerprint: AB9E A551 E262 A87A 13BB  9059 1BE7 B545 CDF3 FD0E
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!