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

Deposit transfers shares not assets #471

Closed
code423n4 opened this issue Sep 19, 2022 · 4 comments
Closed

Deposit transfers shares not assets #471

code423n4 opened this issue Sep 19, 2022 · 4 comments
Labels
bug Something isn't working disagree with severity Sponsor confirms validity, but disagrees with warden’s risk assessment (sponsor explain in comments) duplicate This issue or pull request already exists old-submission-method 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-09-y2k-finance/blob/main/src/Vault.sol#L167

Vulnerability details

Impact

When depositing to the Vault, it transfers the wrong amount of tokens from the user. Deposit mistakenly transfers calculated shares, not assets:

    function deposit(
        uint256 id,
        uint256 assets,
        address receiver
    )
        ...
        require((shares = previewDeposit(id, assets)) != 0, "ZeroValue");
        asset.transferFrom(msg.sender, address(this), shares);

Users will actually deposit less than intended this way because as far as I understand shares are supposed to include accrued interest.

It overrides the deposit function from SemiFungibleVault, there it works as expected:

  asset.safeTransferFrom(msg.sender, address(this), assets);

Recommended Mitigation Steps

It should transfer from the user assets, not shares.

@code423n4 code423n4 added 3 (High Risk) Assets can be stolen/lost/compromised directly bug Something isn't working old-submission-method labels Sep 19, 2022
code423n4 added a commit that referenced this issue Sep 19, 2022
@3xHarry
Copy link
Collaborator

3xHarry commented Sep 21, 2022

@MiguelBits this seems valid, users should transfer as much as they specified in WETH and the contract should mint the calculated shares?

@3xHarry 3xHarry added the disagree with severity Sponsor confirms validity, but disagrees with warden’s risk assessment (sponsor explain in comments) label Sep 21, 2022
@3xHarry
Copy link
Collaborator

3xHarry commented Sep 21, 2022

however this will not cause any harm and no funds will be lost as, assets are the same as shares downgrade to low

@3xHarry 3xHarry added QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax and removed 3 (High Risk) Assets can be stolen/lost/compromised directly labels Sep 21, 2022
@HickupHH3
Copy link
Collaborator

HickupHH3 commented Oct 15, 2022

Honestly, the severity rating depends on which statement is true:

as I understand shares are supposed to include accrued interest.
vs
assets are the same as shares

Looking at the code, it seems like the latter is true.

shares
= previewDeposit(id, assets)
= convertToShares(id, assets)
= totalSupply(id) == 0 ? assets : assets.mulDivDown(totalSupply(id), totalAssets(id));
// for the latter case
= assets.mulDivDown(totalAssets(id), totalAssets(id))
= assets

Hence, I agree that the severity should be downgraded to QA.

@HickupHH3
Copy link
Collaborator

part of warden's QA: #486

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working disagree with severity Sponsor confirms validity, but disagrees with warden’s risk assessment (sponsor explain in comments) duplicate This issue or pull request already exists old-submission-method 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

6 participants