ltc: saturate emergency-decay target shift to prevent uint256 wrap - #561
Merged
Conversation
Step 3 of compute_share_target used a bare prev<<halvings on the 256-bit target. With a large prev and a multi-window share gap the shift overflows 256 bits and wraps to a tiny value (a HARDER target), accelerating the very death spiral the emergency decay exists to arrest. The old halvings<256 guard bounded shift width only, never magnitude. Add emergency_decay_shl() saturating helper (clamps to max_target on overflow) and a 5-case conformance KAT enforcing the easing-only invariant (emergency decay never decreases target).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replaces the bare
prev << halvingsin compute_share_target Step 3 with a saturatingemergency_decay_shl()helper that clamps to max_target on 256-bit overflow. A large prev across a multi-window share gap could previously wrap to a tiny (harder) target and accelerate a death spiral; this makes the emergency-decay path easing-only.Scope: src/impl/ltc/ only (single-coin, LTC lane). DOGE rides the same site; BTC carries its own copy of the helper separately in its lane (no cross-coin bundling).
Tests: new 5-case conformance KAT (easing-only invariant) green; full ltc share_test 11/11 green; clean rebuild.
Head: da75622. Held for integrator merge tap (consensus-bearing path).