Steadefi

Steadefi
DeFiHardhatFoundryOracle
35,000 USDC
View results
Submission Details
Severity: medium
Invalid

`compound()` function allow the owner to drain all funds from a strategy contract

Summary

  • The owner has the ability to drain all GM tokens from the strategy contract by instructing the keeper to call the compound() function with GM tokens as the tokenIn and the all balance of the contract as amountIn.

Vulnerability Details

  • The compound() function, triggered by the keeper, swaps a token (likely received from an airdrop or mistakenly sent to the vault contract) through the swapRouter contract. It adds liquidity to GMX to generate profit and is exclusively callable by the keeper. However,

  • The owner can appoint a new keeper and update the swapRouter contract. With this authority, the owner can change the swapRouter to a malicious contract.

  • The owner can then make the keeper call compound with GM LP tokens as tokenIn and the entire vault balance as amountIn.

  • The compound function approves all tokens to the malicious swapRouter contract and triggers swapExactTokensForTokens().

  • The malicious swapRouter drains all LP tokens and transfers a nominal amount (e.g., 1 USDT) to prevent the function from reverting when adding liquidity to the GMX protocol.

  • Consequently, the owner gains control of all LP tokens, leaving the contract with a meager 1 USD worth of investment.

This protocol's centralized management of strategies is understood, but the ability to drain all user funds poses a substantial risk, especially in the context of web3 applications.

  • example of malicious swapRouter:

contract malicious {
address owner;
function swapExactTokensForTokens(ISwap.SwapParams memory sp) external returns (uint256) {
IERC20(sp.tokenIn).safeTransferFrom(msg.sender, address(this), sp.amountIn);
IERC20(sp.tokenIn).safeTransfer(owner, balanceOf(address(this)));
IERC20(sp.tokenOut).safeTransfer(msg.sender,1e18);
return _amountOut;
}
}

Impact

  • depositor and lenders lose all their investment.

Tools Used

vs code
manual review

Recommendations

  • in the compound function check that the tokenIn is not the GM lp token.

Updates

Lead Judging Commences

hans Auditor
almost 2 years ago
hans Lead Judge almost 2 years ago
Submission Judgement Published
Validated
Assigned finding tags:

Centralization Risk

Impact: High Likelihood: Low Centralization risk is regarded a known issue. This tag will include all submissions : - Admin setter functions without validations

ElHaj Submitter
almost 2 years ago
hans Lead Judge almost 2 years ago
Submission Judgement Published
Invalidated
Reason: Known issue
Assigned finding tags:

Centralization Risk

Impact: High Likelihood: Low Centralization risk is regarded a known issue. This tag will include all submissions : - Admin setter functions without validations

Support

FAQs

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