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

SuperVault depositToVault use unchecked transferFrom with an arbitrary ERC20 asset #147

Closed
code423n4 opened this issue May 2, 2022 · 3 comments
Labels
bug Something isn't working duplicate This issue or pull request already exists QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax

Comments

@code423n4
Copy link
Contributor

Lines of code

https://github.com/code-423n4/2022-04-mimo/blob/b18670f44d595483df2c0f76d1c57a7bfbfbc083/supervaults/contracts/SuperVault.sol#L274-L274

Vulnerability details

Whenever an asset ERC20 do not revert on transfer failure, the such transfer failure will produce an accounting discrepancy as the system will go on with operations as if transfer was successful.

The end result depends on the current state of the contract.

As funds are to be pulled in and such a failure without revert happened, if the contract balance has enough funds the user will be credited with someone else's funds, i.e. double counting happens.

This can end up with contract insolvency for the users who had properly deposited the funds.

Placing severity to be high as once such an asset is supported by the core, the depositToVault can be run by a malicious user repeatedly to bloat his balance and then empty contract holdings with a subsequent withdraw.

Proof of Concept

depositToVault has no access controls and use unchecked transferFrom for an arbitrary token:

https://github.com/code-423n4/2022-04-mimo/blob/b18670f44d595483df2c0f76d1c57a7bfbfbc083/supervaults/contracts/SuperVault.sol#L274-L274

token.transferFrom(msg.sender, address(this), amount);

Some ERC20 do not revert on transfer failure:

https://github.com/d-xo/weird-erc20#no-revert-on-failure

This gives an attacker a way to credit himself without actual fund transfer.

Recommended Mitigation Steps

Require transfer success as it is done elsewhere in the contract or employ OpenZeppelin's SafeERC20

@code423n4 code423n4 added 3 (High Risk) Assets can be stolen/lost/compromised directly bug Something isn't working labels May 2, 2022
code423n4 added a commit that referenced this issue May 2, 2022
@m19 m19 marked this as a duplicate of #41 May 5, 2022
@m19 m19 added the duplicate This issue or pull request already exists label May 6, 2022
@m19
Copy link
Collaborator

m19 commented May 10, 2022

Duplicate of #124

@m19 m19 marked this as a duplicate of #124 May 10, 2022
@m19 m19 closed this as completed May 10, 2022
@gzeoneth gzeoneth reopened this Jun 5, 2022
@gzeoneth gzeoneth added 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value and removed 3 (High Risk) Assets can be stolen/lost/compromised directly duplicate This issue or pull request already exists labels Jun 5, 2022
@gzeoneth
Copy link
Member

gzeoneth commented Jun 5, 2022

Since the transfer should be one that accepted by the core protocol and according to https://github.com/code-423n4/2022-04-mimo/blob/b18670f44d595483df2c0f76d1c57a7bfbfbc083/core/config/deployment.ts#L65 it seems that all asset will revert upon failed transfer, this listing of new asset can be guarded by owner, downgrading to Low / QA.

@gzeoneth gzeoneth closed this as completed Jun 5, 2022
@gzeoneth gzeoneth added QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax and removed 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value labels Jun 5, 2022
@gzeoneth
Copy link
Member

gzeoneth commented Jun 5, 2022

Considered with #165

@gzeoneth gzeoneth added the duplicate This issue or pull request already exists label Jun 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working duplicate This issue or pull request already exists QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax
Projects
None yet
Development

No branches or pull requests

3 participants