Skip to content

Commit

Permalink
Merge bitcoin#31376: Miner: never create a template which exploits th…
Browse files Browse the repository at this point in the history
…e timewarp bug

733fa0b miner: never create a template which exploits the timewarp bug (Antoine Poinsot)

Pull request description:

  This check was introduced in bitcoin#30681 but only enabled for testnet4. To avoid potentially creating an invalid block template if a soft fork to fix the timewarp attack were to activate in the future, we should have this check on all networks. It also seems wise for our miner to not support it whether or not a soft fork activates to fix it at the consensus level.

ACKs for top commit:
  Sjors:
    ACK 733fa0b
  fjahr:
    utACK 733fa0b
  TheCharlatan:
    ACK 733fa0b

Tree-SHA512: 9b3bc8b26a57f93425b17dda80bcfac4ecb750a3d26bc3eb8df619135634e369ac15982fac0c9770b1df207bd2e418ffe02a98f37968f024e55262d97715a4f5
  • Loading branch information
fanquake committed Jan 23, 2025
2 parents 449a25b + 733fa0b commit 59876b3
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/node/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,10 @@ int64_t UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParam
int64_t nOldTime = pblock->nTime;
int64_t nNewTime{std::max<int64_t>(pindexPrev->GetMedianTimePast() + 1, TicksSinceEpoch<std::chrono::seconds>(NodeClock::now()))};

if (consensusParams.enforce_BIP94) {
// Height of block to be mined.
const int height{pindexPrev->nHeight + 1};
if (height % consensusParams.DifficultyAdjustmentInterval() == 0) {
nNewTime = std::max<int64_t>(nNewTime, pindexPrev->GetBlockTime() - MAX_TIMEWARP);
}
// Height of block to be mined.
const int height{pindexPrev->nHeight + 1};
if (height % consensusParams.DifficultyAdjustmentInterval() == 0) {
nNewTime = std::max<int64_t>(nNewTime, pindexPrev->GetBlockTime() - MAX_TIMEWARP);
}

if (nOldTime < nNewTime) {
Expand Down

0 comments on commit 59876b3

Please sign in to comment.