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

Inadequate Validation of Swap Paths in `claimAndSwap`

Summary

The claimAndSwap function accepts an array of swap paths (_path) without validating their integrity. This oversight increases the risk of malicious or improperly configured swap paths, which could lead to token theft, slippage exploitation, or interactions with malicious contracts. Implementing robust path validation and restrictions can mitigate these risks effectively.

Root Cause

The _path parameter, an array of IVeloRouter.route structures, is passed directly to the IVeloRouter.swapExactTokensForTokens function without validation. This allows arbitrary paths to be supplied, potentially exposing the protocol to malicious or inefficient routes.

Vulnerable Code

function claimAndSwap(
uint256 _amountClaim,
uint256 _minOut,
IVeloRouter.route[] calldata _path
) external onlyKeepers {
transmuter.claim(_amountClaim, address(this));
uint256 balBefore = asset.balanceOf(address(this));
_swapUnderlyingToAsset(_amountClaim, _minOut, _path);
uint256 balAfter = asset.balanceOf(address(this));
require((balAfter - balBefore) >= _minOut, "Slippage too high");
transmuter.deposit(asset.balanceOf(address(this)), address(this));
}
function _swapUnderlyingToAsset(
uint256 _amount,
uint256 minOut,
IVeloRouter.route[] calldata _path
) internal {
require(minOut > _amount, "minOut too low");
uint256 underlyingBalance = underlying.balanceOf(address(this));
require(underlyingBalance >= _amount, "not enough underlying balance");
IVeloRouter(router).swapExactTokensForTokens(_amount, minOut, _path, address(this), block.timestamp);
}

Why This Matters

  • Malicious Routes: Unverified _path inputs can redirect swaps to malicious contracts that steal tokens.

  • Excessive Complexity: Overly complex paths can cause gas exhaustion, failed transactions, or unfavorable swap outcomes.

  • Protocol Integrity: Allowing unrestricted paths undermines the trust and stability of the protocol’s swap operations.

Attack Scenarios Common to happen

Scenario 1: Malicious Swap Path

  1. Setup: A Keeper provides a _path that routes WETH through a malicious contract.

  2. Execution: The malicious contract intercepts WETH and transfers it to an attacker’s address.

  3. **Impact **The strategy loses WETH, and funds are drained from the protocol.

Scenario 2: Slippage Exploitation

  1. Setup: A Keeper designs a _path with multiple intermediary tokens that increase the complexity of the swap.

  2. Execution: The swap fails to meet the minOut condition due to manipulated slippage, causing transaction failures or economic loss.

  3. **Impact **Users experience reduced yields or financial losses due to unfavorable trades.

Scenario 3: Gas Exhaustion

  1. Setup: A malicious Keeper provides a _path with unnecessary steps, increasing gas consumption.

  2. Execution: The transaction consumes excessive gas, leading to failed swaps or operational delays.

  3. **Impact **The strategy becomes less efficient, harming depositors and the protocol's reputation.

Impact

  1. Financial Risk: Loss of funds through malicious swaps or slippage manipulation.

  2. Operational Risk: Increased gas costs and failed transactions.

  3. Reputational Risk: Undermined trust in the protocol due to exploitability.

Mitigation Recommendations

1. Validate Swap Paths

  • Check Token Sequences: Verify that each token in the _path array adheres to expected token pairs and is compatible with the protocol’s assets.

  • Verify Contract Addresses: Ensure each contract in the swap path is legitimate and aligns with known protocols (e.g., VeloRouter, Uniswap).

2. Whitelist Swap Contracts

  • Restrict swap paths to use only contracts on an approved whitelist:

    require(isWhitelistedContract(_path[i].pool), "Untrusted swap contract");

3. Limit Swap Path Complexity

  • Set a maximum length for _path to reduce gas consumption and prevent unnecessary complexity:

    require(_path.length <= MAX_PATH_LENGTH, "Path too complex");

4. Emit Events for Monitoring

  • Log details of each swap to facilitate auditing and real-time monitoring:

    emit SwapExecuted(_amount, minOut, _path);

Proof of Concept (PoC)

Steps to Reproduce:

  1. Deploy the StrategyOp contract with mock implementations of IVeloRouter and transmuter.

  2. Call claimAndSwap with a _path that includes a malicious contract.

  3. Observe token transfers to the malicious contract instead of legitimate pools.

Expected Fix Behavior:

  1. Implement path validation as recommended.

  2. Retry the exploit with the same malicious _path.

  3. Observe the transaction revert with an error message indicating invalid paths.

Updates

Appeal created

inallhonesty Lead Judge 7 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.