DeFiFoundrySolidity
16,653 OP
View results
Submission Details
Severity: medium
Invalid

Inadequate Price Validation in Swaps

Summary

The StrategyArb lacks proper validation of exchange rates during token swaps in the _swapUnderlyingToAsset function. The only check ensures that minOut is greater than _amount, which is insufficient. A malicious or negligent keeper can exploit this by setting a minOut that results in swaps at unfavorable rates, causing financial loss to the strategy.

Vulnerability Details

  • Insufficient Validation:

    • The function checks if minOut > _amount but does not verify if the exchange rate is favorable.

function _swapUnderlyingToAsset(uint256 _amount, uint256 minOut, IRamsesRouter.route[] calldata _path) internal {
require(minOut > _amount, "minOut too low");
// Proceed with swap
}
  • Dependence on Keeper:

    • The keeper provides the minOut parameter without any upper or lower bounds enforced by the contract.

    • There is no use of an oracle or other mechanism to verify market rates.

  • Potential Exploit:

    • A keeper can set minOut to a value just above _amount, accepting a poor exchange rate.

    • The strategy ends up receiving fewer asset tokens than expected, resulting in a loss.

Impact

  • Financial Loss:

    • The strategy may lose value due to unfavorable exchange rates during swaps.

  • Keeper Manipulation:

    • Malicious keepers can intentionally cause the strategy to engage in bad trades.

  • Performance Degradation:

    • The overall returns of the strategy are negatively affected.

Proof of Concept (POC)

  1. Keeper's Action:

    • The keeper sets minOut to a value marginally greater than _amount, disregarding the actual market rate.

    • For example, _amount = 100, minOut = 101, even though the market rate should yield minOut = 150.

  2. Swap Execution:

    • The swap is executed based on the low minOut.

    • The require check passes since 101 > 100.

  3. Result:

    • The strategy swaps 100 units of underlying but receives only 101 units of asset instead of the fair market value.

    • The strategy incurs a significant loss.

Recommendations

  • Implement Oracle-based Price Checks:

    • Use a trusted price oracle (e.g., Chainlink) to get the current exchange rate between underlying and asset.

function _swapUnderlyingToAsset(uint256 _amount, uint256 minOut, IRamsesRouter.route[] calldata _path) internal {
uint256 currentRate = getOraclePrice(); // Implement this function
uint256 expectedMinOut = (_amount * currentRate * (100 - acceptableSlippage)) / 100;
require(minOut >= expectedMinOut, "Slippage too high");
// Proceed with swap
}
Updates

Appeal created

inallhonesty Lead Judge 8 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.