fix: prevent near-zero division DoS in SpreadCloseSwapService#766
Open
ffulb wants to merge 1 commit intoIPOR-Labs:mainfrom
Open
fix: prevent near-zero division DoS in SpreadCloseSwapService#766ffulb wants to merge 1 commit intoIPOR-Labs:mainfrom
ffulb wants to merge 1 commit intoIPOR-Labs:mainfrom
Conversation
When closing the last swap in a linked list (nextSwapId == 0), the time-weighted notional is recalculated with division by (tenorInSeconds - swapTimePast). If swapTimePast approaches tenorInSeconds, the denominator approaches 1, causing the result to overflow uint96 in SpreadStorageLibs.saveTimeWeightedNotionalForAssetAndTenor(). This permanently bricks the spread storage for the affected asset/tenor pair, blocking all subsequent swap operations. Fix: enforce a minimum denominator of 1% of the tenor length.
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.
Security Fix — Critical DoS Vulnerability
Vulnerability
In
SpreadCloseSwapService.updateTimeWeightedNotionalOnClose(), when closing the last swap (nextSwapId == 0), the time-weighted notional is recalculated with:If
swapTimePastapproachestenorInSeconds(e.g., a swap opened near tenor expiry), the denominator approaches 1. This causes the result to overflowuint96when packed bySafeCast.toUint96()inSpreadStorageLibs.saveTimeWeightedNotionalForAssetAndTenor().Impact
Attack Scenario
block.timestamp - T ≈ tenorInSeconds - 1nextSwapId == 0swapTimePast ≈ tenorInSeconds - 1, denominator = 17.9e46 * 2419200 / 1 = 1.9e53→ after/1e18=1.9e35→ exceeds uint96 max (7.9e28)SafeCast.toUint96()reverts permanentlyFix
Enforce minimum denominator of 1% of tenor length, preventing the amplification factor from exceeding 100x.
Additional Findings
I have 5 additional findings (2 High, 2 Medium, 1 Low) in the spread calculation subsystem:
timeOfLastUpdate > closedSwap.openSwapTimestampcauses underflowHappy to share details. Contact via GitHub.
Wallet for bounty:
0xd67c6444cD3617Bd6D0A52aCE0E4aA29127cEA68