Open code423n4 opened 1 year ago
chechu marked the issue as disagree with severity
No funds at risk here
@chechu - the severity of M doesn't require that funds are at risk. Here is the quick reference for M severity per c4 docs
2 — Med: Assets not at direct risk, but the function of the protocol or its availability could be impacted, or leak value with a hypothetical attack path with stated assumptions, but external requirements.
chechu marked the issue as sponsor confirmed
0xean changed the severity to QA (Quality Assurance)
Lines of code
https://github.com/code-423n4/2023-05-venus/blob/main/contracts/Comptroller.sol#L885-L902 https://github.com/code-423n4/2023-05-venus/blob/main/contracts/MaxLoopsLimitHelper.sol#L25-L32 https://github.com/code-423n4/2023-05-venus/blob/main/contracts/MaxLoopsLimitHelper.sol#L39-L43
Vulnerability details
Proof of Concept
The protocol is using
MaxLoopLimitHelper._ensureMaxLoop()
throughout various functions to prevent DOS. However,Comptroller.setActionsPaused()
contains a nested loop with a time complexity ofmarketsList.length * actionsList.length
, while_ensureMaxLoop()
is only validatingmarketsList.length
.https://github.com/code-423n4/2023-05-venus/blob/main/contracts/Comptroller.sol#L885-L902
If
x
is the number of tokens andy
is the number of actions,_ensureMaxLoop()
should validatex * y
and not onlyx
..MaxLoopLimitHelper_ensureMaxLoop()
contains a limit of 200.Comptroller.setActionsPaused()
MaxLoopLimitHelper._ensureMaxLoop()
will incorrectly pass assuming100 (iterations) < 200 (limit)
, however it should revert since500 (iterations) > 200 (limit)
https://github.com/code-423n4/2023-05-venus/blob/main/contracts/MaxLoopsLimitHelper.sol#L25-L32
https://github.com/code-423n4/2023-05-venus/blob/main/contracts/MaxLoopsLimitHelper.sol#L39-L43
https://github.com/code-423n4/2023-05-venus/blob/main/contracts/ComptrollerStorage.sol#L44-L54
Impact
Letting
Comptroller.setActionsPaused()
consume all gas and revert will be more costly than failing early. Also, failing with the custom errorMaxLoopsLimitExceeded(maxLoopsLimit, len)
is the expected behavior. Is is possible that failing directly instead of throughMaxLoopLimitHelper._ensureMaxLoop()
will damage monitoring/frontend tooling, sinceMaxLoopLimitHelper._ensureMaxLoop()
will incorrectly pass the input data and it won't trigger the custom error.The usage of
MaxLoopLimitHelper._ensureMaxLoop()
indicates failing early against DOS is important for the project. Loop validation will have undefined behavior inComptroller.setActionsPaused()
. Pausing actions will likely be done in times of market instability, therefore the functions used for pausing should have a stable and pre-defined behavior.Tools Used
Manual review.
Recommended Mitigation Steps
Replace
marketsCount
withmarketsCount * actionsCount
inComptroller.setActionsPaused()
when callingMaxLoopLimitHelper._ensureMaxLoops()
, e.g.Assessed type
Invalid Validation