Open code423n4 opened 1 year ago
bytes032 marked the issue as duplicate of #237
bytes032 marked the issue as sufficient quality report
bytes032 marked the issue as duplicate of #761
GalloDaSballo marked the issue as not a duplicate
GalloDaSballo changed the severity to QA (Quality Assurance)
Cost is not negligible, rounding is
Lines of code
https://github.com/code-423n4/2023-08-dopex/blob/eb4d4a201b3a75dd4bddc74a34e9c42c71d0d12f/contracts/perp-vault/PerpetualAtlanticVault.sol#L502-L517
Vulnerability details
Impact
An attacker can frequently invoke the
updateFunding
function, aiming to exploit the calculation(currentFundingRate * (block.timestamp - startTime)) / 1e18
. By calling this function every block, the attacker can ensure that the value ofblock.timestamp - startTime
is minimized. If thecurrentFundingRate
is sufficiently low, especially at the beginning of an epoch, the result of the calculation can round down to zero due to integer division. This can lead to liquidity providers (LPs) receiving zero premiums, effectively griefing them and depriving them of expected rewards.Proof of Concept
The
updateFunding
function calculates the amount to transfer based on the elapsed time since the last update:An attacker can call this function every block, ensuring that the difference between
block.timestamp
andstartTime
(i.e., the elapsed time) is minimal. If thecurrentFundingRate
is low, the multiplication can result in a value that, when divided by 1e18, rounds down to zero.POC:
Note: The PoC is using the setup of
perp-vault
.Tools Used
Manual Review + Foundry
Recommended Mitigation Steps
Consider using a more precise arithmetic library or mechanism to handle calculations, minimizing the impact of rounding errors.
Assessed type
Math