AI-generated analysisPublished automatically and not human-verified. Validated context appears in community notes below.
← Watch feed
Low 45 Bitcoin

Merge rust-bitcoin/rust-bitcoin#7051: pow: Fix overflow in min difficulty time check

Public commit record

What the developer wrote

Authored by Andrew Poelstra

96/100 · Strong
Merge rust-bitcoin/rust-bitcoin#7051: pow: Fix overflow in min difficulty time check

7559880f2c3f98c9ebc4ab2e065fdd598300b4ad pow: Add test for min difficulty time near u32::MAX (Nuem.dev)
b2547a3221d39d9ab33660d630db7e556765f43f pow: Fix overflow in min difficulty time check (Nuem.dev)

Pull request description:

In `next_target_after` the testnet min difficulty check adds twice the target spacing to the current header's time using `u32`. If the time is within 1200 seconds of `u32::MAX` this panics in debug builds and wraps in release builds, returning the wrong target.

Bitcoin Core does this comparison using `int64_t`. Do the same by converting to `i64` first, and add a regression test.


ACKs for top commit:
apoelstra:
ACK 7559880f2c3f98c9ebc4ab2e065fdd598300b4ad; successfully ran local tests
tcharding:
ACK 7559880f2c3f98c9ebc4ab2e065fdd598300b4ad


Tree-SHA512: 049772504cbb9866ced028ccdd5aa7db3a2c22c422787f6c008441a5537aaeb37f46c2462f53498c738a16f4ca276fe72de45e261aef82b99427ba86b75d7b43
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context✓ Mentions testing or verification✓ Links an issue, advisory, or supporting reference✓ Names security-relevant behavior explicitly
The short version

What changed, and why it matters

This commit fixes an arithmetic overflow bug in the code that calculates the next mining difficulty target for Bitcoin's testnet. When a block's timestamp was very close to the maximum value a 32-bit unsigned integer can hold, adding 20 minutes to it would either crash the program in debug builds or silently wrap around to a small number in release builds, causing the wrong difficulty target to be returned. The fix converts the values to 64-bit integers before adding them, matching how Bitcoin Core handles the same calculation.

Recommended action

Review and merge the fix; ensure downstream users update to a release containing this commit. The bug is primarily relevant to testnet, but any code relying on `next_target_after` with crafted or boundary timestamps should be considered. No immediate emergency response is warranted for mainnet consensus.

Security signals we found

01

Integer overflow in difficulty-target calculation

02

Debug-build panic / release-build silent wraparound

03

Consensus-relevant code path (testnet minimum-difficulty rule)

04

Fix aligns implementation with Bitcoin Core behavior

05

Regression test added for boundary condition

Risk score

Why this scored 45/100

Our methodology →
Potential impact 12/30
Exploitability 8/25
Stealth signal 6/15
Affected reach 7/15
Confidence 8/10
Evidence quality 4/5
Human-validated context

Community notes

Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.

No validated notes yet.

The AI analysis stands alone for now. Submit a note if you can add evidence or important context.