Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collateral can become insolvent #180

Closed
code423n4 opened this issue Dec 12, 2022 · 3 comments
Closed

Collateral can become insolvent #180

code423n4 opened this issue Dec 12, 2022 · 3 comments
Labels
2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value bug Something isn't working duplicate-254 satisfactory satisfies C4 submission criteria; eligible for awards

Comments

@code423n4
Copy link
Contributor

Lines of code

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#L29-L33
https://github.com/prepo-io/prepo-monorepo/blob/feat/2022-12-prepo/apps/smart-contracts/core/contracts/Collateral.sol#L82

Vulnerability details

Impact

Collateral can become insolvent because of managerWithdraw function.

Proof of Concept

Collateral.managerWithdraw allows to withdraw base tokens to manager.
https://github.com/prepo-io/prepo-monorepo/blob/feat/2022-12-prepo/apps/smart-contracts/core/contracts/Collateral.sol#L80-L83

  function managerWithdraw(uint256 _amount) external override onlyRole(MANAGER_WITHDRAW_ROLE) nonReentrant {
    if (address(managerWithdrawHook) != address(0)) managerWithdrawHook.hook(msg.sender, _amount, _amount);
    baseToken.transfer(manager, _amount);
  }

In case if managerWithdrawHook is 0 then there is no any checks and _amount is sent to manager. This can make Collateral insolvent.
Scenario.
1.User deposit 1 million tokens to Collateral.
2.managerWithdraw is called and all tokens were sent to manager.
3.Collateral is insolvent, users can't withdraw.

In case if managerWithdrawHook is not 0 then managerWithdrawHook.hook is called.
https://github.com/prepo-io/prepo-monorepo/blob/feat/2022-12-prepo/apps/smart-contracts/core/contracts/ManagerWithdrawHook.sol#L17

  function hook(address, uint256, uint256 _amountAfterFee) external view override { require(collateral.getReserve() - _amountAfterFee >= getMinReserve(), "reserve would fall below minimum"); }

The check that is done here is that balance of base token of Collateral will stay above some provided percentage(minReservePercentage) multiplied by all amount recorded in depositRecord after withdraw.
https://github.com/prepo-io/prepo-monorepo/blob/feat/2022-12-prepo/apps/smart-contracts/core/contracts/ManagerWithdrawHook.sol#L41

  function getMinReserve() public view override returns (uint256) { return (depositRecord.getGlobalNetDepositAmount() * minReservePercentage) / PERCENT_DENOMINATOR; }

Even if this percentage is small, it's enough to make Collateral insolvent as well and Collateral will not hold enough funds to cover users withdraws.

Tools Used

VsCode

Recommended Mitigation Steps

I believe that manager should not be able to withdraw users funds. He should not be able to withdraw any amount that will make Collateral balance less than depositRecord.getGlobalNetDepositAmount().

@code423n4 code423n4 added 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value bug Something isn't working labels Dec 12, 2022
code423n4 added a commit that referenced this issue Dec 12, 2022
@hansfriese
Copy link

duplicate of #254

@c4-judge
Copy link
Contributor

Picodes marked the issue as duplicate of #254

@c4-judge
Copy link
Contributor

c4-judge commented Jan 1, 2023

Picodes marked the issue as satisfactory

@c4-judge c4-judge added the satisfactory satisfies C4 submission criteria; eligible for awards label Jan 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value bug Something isn't working duplicate-254 satisfactory satisfies C4 submission criteria; eligible for awards
Projects
None yet
Development

No branches or pull requests

3 participants