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

Hacked admin or malicious admin can immediately steal all baseToken in Collateral #117

Closed
code423n4 opened this issue Dec 11, 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/3541bc704ab185a969f300e96e2f744a572a3640/apps/smart-contracts/core/contracts/Collateral.sol#L80-L83
https://github.com/prepo-io/prepo-monorepo/blob/3541bc704ab185a969f300e96e2f744a572a3640/apps/smart-contracts/core/contracts/Collateral.sol#L85-L88
https://github.com/prepo-io/prepo-monorepo/blob/3541bc704ab185a969f300e96e2f744a572a3640/apps/smart-contracts/core/contracts/Collateral.sol#L112-L115

Vulnerability details

Impact

Hacked admin or malicious admin can immediately steal all baseToken that users deposit in Collateral.

If Collateral is deployed as a upgradable proxy, the collateral contract admin could also steal all assets approved to this contract address.

Proof of Concept

Hacked admin or malicious admin can steal the assets by following these steps:

  1. Use the DEFAULT_ADMIN_ROLE: grant his own account X roles(MANAGER_WITHDRAW_ROLE, SET_MANAGER_ROLE, SET_MANAGER_WITHDRAW_HOOK_ROLE), and accept them.
  2. Use account X: call Collateral.setManagerWithdrawHook() with _newManagerWithdrawHook = 0 to disable ManagerWithdrawHook.
  3. Use account X: call Collateral.setManager() with _newManager = X.
  4. Use account X: call Collateral.managerWithdraw() to transfer all baseToken to X. (becase managerWithdrawHook is 0 and manager is X now)

If Collateral is deployed as a proxy(like uups, 1967), the proxy admin could steal all baseToken in this contract and all assets approved to this contract by upgrading Collateral to a new malicious contract.

Tools Used

VS Code

Recommended Mitigation Steps

For the Collateral contract, the following change is recommended:

  • managerWithdrawHook should be set to a valid contract at initialize()
  • Add a timelock to disable Collateral.managerWithdraw() for some time when either managerWithdrawHook or manager changes.

For proxy contract, two options are recommended:

  1. Deploy Collateral behind a non-upgradable proxy.
  2. The upgradable proxy should have a timelock when upgrade, give users enough time to withdraw and cancel their approvals before some malicious action becomes possible.
@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 11, 2022
code423n4 added a commit that referenced this issue Dec 11, 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