Open code423n4 opened 1 year ago
Low severity as the impact isn't significant compared to just withdrawing.
Picodes changed the severity to QA (Quality Assurance)
Picodes marked the issue as grade-b
This is fine, reserve is intended to prevent manager from withdrawing beyond the reserve, it is not necessarily a undesirable situation that a user withdraws when Collateral
is below reserve requirement.
ramenforbreakfast marked the issue as sponsor disputed
Lines of code
https://github.com/prepo-io/prepo-monorepo/blob/feat/2022-12-prepo/apps/smart-contracts/core/contracts/Collateral.sol#L80-L83 https://github.com/prepo-io/prepo-monorepo/blob/feat/2022-12-prepo/apps/smart-contracts/core/contracts/ManagerWithdrawHook.sol#L17 https://github.com/prepo-io/prepo-monorepo/blob/feat/2022-12-prepo/apps/smart-contracts/core/contracts/ManagerWithdrawHook.sol#L41
Vulnerability details
Impact
hook
function inManagerWithdrawHook
is used for ensuring that the amount remaining after withdrawn by manager is above certain threshold(returned bygetMinReserve
). However,manager
can take advantage of this when seeing large withdrawal by user and frontrunning transaction by withdrawing more tokens. Ifmanager
would have withdrawn after thewithdraw
by user, it would receive less tokens.Proof of Concept
assume
minReservePercentage = 50%
. There are 100 tokens in the reserve. And some user sends the transaction to withdraw 20 tokens. After withdrawal by user, manager will only be able to withdraw (100 - 20) 0.5 = 40 tokens but if manager withdraws first, then it will be able to withdraw (100 0.5) = 50 tokens and after withdrawal by user, the reserve will fall below minimum reserve.Tools Used
Manual review
Recommended Mitigation Steps
Use timelock for withdrawal by manager so that it can't frontrun other users.