Closed c4-bot-10 closed 3 months ago
Seen issues of this kind in many protocols. Has always been intended business logic / accepted side-effect of compounding so far.
Invalidating for now but open for further input from @thorseldon and Warden.
MarioPoneder marked the issue as unsatisfactory: Invalid
Lines of code
https://github.com/code-423n4/2024-07-benddao/blob/117ef61967d4b318fc65170061c9577e674fffa1/src/libraries/logic/InterestLogic.sol#L267 https://github.com/code-423n4/2024-07-benddao/blob/117ef61967d4b318fc65170061c9577e674fffa1/src/libraries/math/MathUtils.sol#L33
Vulnerability details
Impact
supplyIndex
will be arbitrarily inflated due to vulnerable implementation incalculateLinearInterest()
and_updateSupplyIndex()
.Proof of Concept
Unlike borrowIndex, supplyIndex uses a linear increase formula (rate * deltaT).
The issue is implementation in
calculateLinearInterest()
and_updateSupplyIndex()
is incorrect, and will arbitrarily compoundsupplyIndex
depending on how often_updateSupplyIndex()
is invoked in borrow, repay, liquidation flows.calculateLinearInterest()
adds WadRayMath.RAY to the calculated result, effectively turning it into a multiplier that compounds the interest whenever rayMul is used in_updateSupplyIndex()
.(https://github.com/code-423n4/2024-07-benddao/blob/117ef61967d4b318fc65170061c9577e674fffa1/src/libraries/math/MathUtils.sol#L33)
Each time
_updateSupplyIndex()
is invoked, the interest is compounded rather than linearly increased.(https://github.com/code-423n4/2024-07-benddao/blob/117ef61967d4b318fc65170061c9577e674fffa1/src/libraries/logic/InterestLogic.sol#L267)
POC: suppose during the same time delta, a total of 6% linear distribution (
calculateLinearInterest()
returns (1 + 6%) ). supplyIndex starts from 1 (leaving out precision scaling for simplicity):Case A: _updateSupplyIndex() is invoked three times during this time delta with each step linear increase 2% ( at each time
calculateLinearInterest()
returns (1 + 2%) ).supplyIndex after = 1 x (1 + 0.02)^3 -> 1.061208
Case B: _updateSupplyIndex() is invoked once at the end of this time delta with total linear increase of 6%.
supplyIndex after = 1 x (1 + 0.06) -> 1.06
Current implementation inadvertently compounds the supply interest when it should only be applying a linear increase. This results in an arbitrarily inflated supplyIndex value depending on the frequency of atomic
_updateSupplyIndex()
calls.Tools Used
Manual
Recommended Mitigation Steps
(1) In
calculateLinearInterest
, Consider simply returningresult
without adding RAY; (2) In_updateSupplyIndex
,supplyIndex
should be updated by adding cumulatedSupplyInterest directly, scaled appropriately, ensuring a linear increase rather than compounding;Assessed type
Other