Assets may be lost when calling unprotected AutoPxGlp::compound function
The AutoPxGlp::compound function is callable by anyone and accepts caller-controlled minimum amounts for GLP and USDG, which can be set to near-zero. An attacker could exploit this to cause the vault to lose assets during compounding, especially when market prices are volatile or manipulated.
Submitted by deliriusz, also found by keccak123, wagmi, pashov, 0xbepresent, rbserver, unforgiven, simon135, xiaoming90, gzeon, R2, ladboy233, 0xLad, 0x52, pedroais, Ruhum, cccz, hihen, rvierdiiev, perseverancesuccess, and Englave
https://github.com/code-423n4/2022-11-redactedcartel/blob/main/src/vaults/AutoPxGlp.sol#L210
https://github.com/code-423n4/2022-11-redactedcartel/blob/main/src/PirexGmx.sol#L497-L516
Impact
Compounded assets may be lost because AutoPxGlp::compound can be called by anyone and minimum amount of Glp and USDG are under caller’s control. The only check concerning minValues is that they are not zero (1 will work, however from the perspective of real tokens e.g. 1e6, or 1e18 it’s virtually zero). Additionally, internal smart contract functions use it as well with minimal possible value (e.g. beforeDeposit function).
Proof of Concept
compound function calls PirexGmx::depositGlp, that uses external GMX reward router to mint and stake GLP.
https://snowtrace.io/address/0x82147c5a7e850ea4e28155df107f2590fd4ba327#code
141: function mintAndStakeGlpETH(uint256 _minUsdg, uint256 _minGlp) external payable nonReentrant returns (uint256) {
...
148: uint256 glpAmount = IGlpManager(glpManager).addLiquidityForAccount(address(this), account, weth, msg.value, _minUsdg, _minGlp);
Next GlpManager::addLiquidityForAccount is called https://github.com/gmx-io/gmx-contracts/blob/master/contracts/core/GlpManager.sol#L103
function addLiquidityForAccount(address _fundingAccount, address _account, address _token, uint256 _amount, uint256 _minUsdg, uint256 _minGlp) external override nonReentrant returns (uint256) {
_validateHandler();
return _addLiquidity(_fundingAccount, _account, _token, _amount, _minUsdg, _minGlp);
}
which in turn uses vault to swap token for specific amount of USDG before adding liquidity: https://github.com/gmx-io/gmx-contracts/blob/master/contracts/core/GlpManager.sol#L217
The amount of USGD to mint is calcualted by GMX own price feed: https://github.com/gmx-io/gmx-contracts/blob/master/contracts/core/Vault.sol#L765-L767
In times of market turbulence, or price oracle manipulation, all compound value may be lost
Tools Used
VS Code, arbiscan.io
Recommended Mitigation Steps
Don’t depend on user passing minimum amounts of usdg and glp tokens. Use GMX oracle to get current price, and additionally check it against some other price feed (e.g. ChainLink).
kphed (Redacted Cartel) commented:
We’re using the following combination of mechanics in order to make front-running
compoundcalls economically unattractive (or, at the very least, minimally impactful) for would-be attackers:
- Compound incentives
- Execution as a side effect of vault functions
Both will result in a higher frequency of the vault compounding its rewards and less resources available for potential attackers.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The compound function relies on caller-supplied minimum amounts that can be set to near-zero, and it does not independently verify the output against a reliable price feed.
Impact
All compounded value could be lost during market turbulence or price oracle manipulation, though the protocol argues that incentives and frequent compounding reduce the economic attractiveness of such an attack.
What the attacker needed
Compound function is publicly callable; attacker can set minUsdg and minGlp to near-zero; market turbulence or oracle manipulation
The fix
The compound function should not rely on user-supplied minimum amounts; instead it should use a reliable price oracle (such as GMX's oracle cross-checked with Chainlink) to enforce sensible minimums.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A vault lets people deposit funds and earn rewards. The function that reinvests those rewards can be called by anyone, and the caller decides the minimum acceptable amounts of tokens received. If those minimums are set very low, the vault might accept a bad trade and lose money.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.