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

DOESN'T CHECK FOR RETURN VALUE OF TRANSFERFROM() #255

Closed
code423n4 opened this issue Sep 19, 2022 · 1 comment
Closed

DOESN'T CHECK FOR RETURN VALUE OF TRANSFERFROM() #255

code423n4 opened this issue Sep 19, 2022 · 1 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 invalid This doesn't seem right sponsor disputed Sponsor cannot duplicate the issue, or otherwise disagrees this is an issue unsatisfactory does not satisfy C4 submission criteria; not eligible for awards

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

In function deposit(), it doesnot check the return value of transferFrom() that helps in transfer of share(assets share) from user to Vault contract,
and furthere this deposit() mints share to user in return

Proof of Concept

For example :

. let a User call deposit() of Vault contract
. now assume if transfer of asset from user to vault fails, so transferFrom() returns false
. then as no check present
. deposit() mints some share to user considering that user sent some assets to vault, where actually transfer call was failed
. User can take advantage of this and mint share repeated for him

    function deposit( uint256 id, uint256 assets, address receiver )
    public
    override
    marketExists(id)
    epochHasNotStarted(id)
    nonReentrant
    returns (uint256 shares)
{
    // Check for rounding error since we round down in previewDeposit.
    require((shares = previewDeposit(id, assets)) != 0, "ZeroValue");

    asset.transferFrom(msg.sender, address(this), shares);  // @audit -- bool return check absent

    _mint(receiver, id, shares, EMPTY);   

    emit Deposit(msg.sender, receiver, id, shares, shares);

    return shares;
} 

Tools Used

Manual Review

Recommended Mitigation Steps

There should be a check for return value of transferFrom(), if it fails then whole function should revert.

    function deposit( uint256 id, uint256 assets, address receiver )
    public
    override
    marketExists(id)
    epochHasNotStarted(id)
    nonReentrant
    returns (uint256 shares)
{
    // Check for rounding error since we round down in previewDeposit.
    require((shares = previewDeposit(id, assets)) != 0, "ZeroValue");

    bool succ = asset.transferFrom(msg.sender, address(this), shares); 
    require(succ, "Asset tranfer failed");

    _mint(receiver, id, shares, EMPTY);   // @audit -- safeMint should use

    emit Deposit(msg.sender, receiver, id, shares, shares);

    return shares;
}
@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 Sep 19, 2022
code423n4 added a commit that referenced this issue Sep 19, 2022
@MiguelBits MiguelBits added the invalid This doesn't seem right label Sep 30, 2022
@liveactionllama liveactionllama added sponsor disputed Sponsor cannot duplicate the issue, or otherwise disagrees this is an issue and removed invalid This doesn't seem right labels Oct 3, 2022
@HickupHH3
Copy link
Collaborator

dup #499

@HickupHH3 HickupHH3 added the unsatisfactory does not satisfy C4 submission criteria; not eligible for awards label Nov 10, 2022
@JeeberC4 JeeberC4 added the invalid This doesn't seem right label Nov 10, 2022
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 invalid This doesn't seem right sponsor disputed Sponsor cannot duplicate the issue, or otherwise disagrees this is an issue unsatisfactory does not satisfy C4 submission criteria; not eligible for awards
Projects
None yet
Development

No branches or pull requests

5 participants