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

YieldManager's distributeYield can be subject to sandwich attacks #87

Closed
code423n4 opened this issue May 15, 2022 · 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 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

Comments

@code423n4
Copy link
Contributor

Lines of code

https://github.com/code-423n4/2022-05-sturdy/blob/78f51a7a74ebe8adfd055bdbaedfddc05632566f/smart-contracts/YieldManager.sol#L178-L187

Vulnerability details

distributeYield uses Uniswap swaps via _convertAssetToExchangeToken and Curve swaps via _convertToStableCoin. UniswapAdapter and CurveswapAdapter do use Oracle for price estimation, but distributeYield calls use hard coded 5% SLIPPAGE, which is wide enough to make sandwich attacks economically viable, specifically for Uniswap case, where price manipulation can be less costly.

As a result trades converting assets to _exchangeToken can happen at a manipulated price and end up receiving fewer _exchangeTokens than current market price dictates.

Placing severity to medium as impact here is a partial fund loss conditional only on big enough asset amount to be swapped: sandwich attacks are common and can be counted to happen almost always as long as economic viability is present.

Proof of Concept

_convertAssetToExchangeToken and _convertToStableCoin use SLIPPAGE for DEX output control:

https://github.com/code-423n4/2022-05-sturdy/blob/78f51a7a74ebe8adfd055bdbaedfddc05632566f/smart-contracts/YieldManager.sol#L178-L187

  function _convertAssetToExchangeToken(address asset, uint256 amount) internal {
    UniswapAdapter.swapExactTokensForTokens(
      _addressesProvider,
      asset,
      _exchangeToken,
      amount,
      UNISWAP_FEE,
      SLIPPAGE
    );
  }

https://github.com/code-423n4/2022-05-sturdy/blob/78f51a7a74ebe8adfd055bdbaedfddc05632566f/smart-contracts/YieldManager.sol#L204-L211

    receivedAmount = CurveswapAdapter.swapExactTokensForTokens(
      _addressesProvider,
      _pool,
      _exchangeToken,
      _tokenOut,
      _amount,
      SLIPPAGE
    );

SLIPPAGE is hard coded to be 5%, which is excessively wide and can be exploited whenever the asset amount is big enough:

https://github.com/code-423n4/2022-05-sturdy/blob/78f51a7a74ebe8adfd055bdbaedfddc05632566f/smart-contracts/YieldManager.sol#L49

  uint256 public constant SLIPPAGE = 500; // 5%

Recommended Mitigation Steps

Consider adding slippage argument to the distributeYield, so it can be tuned each time accordingly to the current market conditions.

@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 May 15, 2022
code423n4 added a commit that referenced this issue May 15, 2022
@sforman2000
Copy link
Collaborator

Duplicate of #133 (high risk)

@sforman2000 sforman2000 added the disagree with severity Sponsor confirms validity, but disagrees with warden’s risk assessment (sponsor explain in comments) label May 18, 2022
@itsmetechjay itsmetechjay added the duplicate This issue or pull request already exists label May 18, 2022
@HickupHH3
Copy link
Collaborator

Wrong duplicate identifier. It's a duplicate of #61

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 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
Projects
None yet
Development

No branches or pull requests

4 participants