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

Fee-on-transfer underlying deposit asset token conflict with ERC4626 #120

Closed
code423n4 opened this issue Jan 11, 2023 · 2 comments
Closed
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-51 edited-by-warden satisfactory satisfies C4 submission criteria; eligible for awards

Comments

@code423n4
Copy link
Contributor

code423n4 commented Jan 11, 2023

Lines of code

https://github.com/code-423n4/2023-01-astaria/blob/main/src/AstariaRouter.sol#L123-L153
https://github.com/code-423n4/2023-01-astaria/blob/main/src/PublicVault.sol#L233-L265
https://github.com/AstariaXYZ/astaria-gpl/blob/4b49fe993d9b807fe68b3421ee7f2fe91267c9ef/src/ERC4626-Cloned.sol#L19-L52

Vulnerability details

Impact

When depositing capital to selected PublicVault.sol via deposit() or mint(), the underlying ERC20 token amount transferred to the contract proportionately determines the minted amount of ERC-4626 VaultTokens that represent the liquidity provider's share in the vault. However, if the ERC20 token entailed is deflationary, it could lead to accounting errors resulting in the last batch of liquidity providers unable to withdraw their funds due to insufficient contract balance.

Proof of Concept

File: ERC4626-Cloned.sol#L19-L52

  function deposit(uint256 assets, address receiver)
    public
    virtual
    returns (uint256 shares)
  {
    // Check for rounding error since we round down in previewDeposit.
    require((shares = previewDeposit(assets)) != 0, "ZERO_SHARES");

    require(shares > minDepositAmount(), "VALUE_TOO_SMALL");
    // Need to transfer before minting or ERC777s could reenter.
    ERC20(asset()).safeTransferFrom(msg.sender, address(this), assets);

    _mint(receiver, shares);

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

    afterDeposit(assets, shares);
  }

  function mint(
    uint256 shares,
    address receiver
  ) public virtual returns (uint256 assets) {
    assets = previewMint(shares); // No need to check for rounding error, previewMint rounds up.
    require(assets > minDepositAmount(), "VALUE_TOO_SMALL");
    // Need to transfer before minting or ERC777s could reenter.
    ERC20(asset()).safeTransferFrom(msg.sender, address(this), assets);

    _mint(receiver, shares);

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

    afterDeposit(assets, shares);
  }

super.deposit() and super.mint() are unanimously used by deposit() and mint() in AstariaRouter.sol and PublicVault.sol to correspondingly invoke the above parental functions.

As can be seen in the code block, no measure has been made to either stem or cater for fee-on-transfer tokens.

Tools Used

Manual inspection

Recommended Mitigation Steps

Consider:

  1. whitelisting the underlying deposit asset ensuring no fee-on-transfer token is allowed when deploying a new PublicVault from AstariaRouter.sol, or
  2. calculating the balance before and after the transfer, and use the difference between those two balances as the amount rather than using the input amount if deflationary token is going to be allowed in the protocol.
@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 Jan 11, 2023
code423n4 added a commit that referenced this issue Jan 11, 2023
@code423n4 code423n4 changed the title Inadequate VIData and its associated function logic in Vault.sol Fee-on-transfer underlying deposit asset token conflict with ERC4626 Jan 13, 2023
@c4-judge
Copy link
Contributor

Picodes marked the issue as duplicate of #51

@c4-judge
Copy link
Contributor

Picodes marked the issue as satisfactory

@c4-judge c4-judge added the satisfactory satisfies C4 submission criteria; eligible for awards label Feb 23, 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-51 edited-by-warden satisfactory satisfies C4 submission criteria; eligible for awards
Projects
None yet
Development

No branches or pull requests

2 participants