Closed code423n4 closed 1 year ago
Picodes changed the severity to 2 (Med Risk)
Picodes marked the issue as primary issue
Picodes marked the issue as duplicate of #183
Picodes marked the issue as duplicate of #185
Picodes marked the issue as satisfactory
JeeberC4 marked the issue as duplicate of #137
Lines of code
https://github.com/code-423n4/2022-11-redactedcartel/blob/03b71a8d395c02324cb9fdaf92401357da5b19d1/src/vaults/AutoPxGlp.sol#L197-L296 https://github.com/code-423n4/2022-11-redactedcartel/blob/03b71a8d395c02324cb9fdaf92401357da5b19d1/src/vaults/AutoPxGmx.sol#L230-L313
Vulnerability details
Impact
Function
compound()
in theAutoPxGlp
andAutoPxGmx
contracts is claiming all the rewards of the pool then swaps them if required and then deposits them in thePirexGmx
again to compound the reward. when swapping called, code uses the slippage tolerance values that user specified This creates an issue where a single user specify slippage for all the pool contract rewards which belongs to all of the users. attacker can use this to steal contract rewards by creating a smart contract that first manipulate the pool in Uniswap (or any pool that GMX or Pirex protocol uses in depositing) then callcompound()
with very high slippage allowance (setamountOutMinimum
very low) and code would swap rewards token with very bad price and then attacker contract would perform the reverse transaction in Uniswap.Proof of Concept
This is
compound()
code inAutoPxGmx
contract:As you can see contract swaps the
gmxBaseReward
balance of contract forgmx
token by callingIV3SwapRouter
and the slippage parameters for swapsamountOutMinimum
andsqrtPriceLimitX96
are set by the values user provided. This would give attacker to perform on-chain sandwich attack against the pool. to perform this attack, attacker would create a smart contract would perform this steps:compound()
function inAutoPxGmx
with high slippage allowance and the code would tries to swap gmxBaseReward token for gmx token but because the liquidity pool has been manipulatedAutoPxGmx
would receive smaller amount of gmx token that it was supposed to.AutoPxGmx
.By performing this attacker was abled to steal
AutoPxGmx
rewards with on-chain sandwich-attack in one transaction. The situation forAutoPxGlp
is similar to this. the problem is that contract allows a user to chose slippage allowance for all the rewards of contract which belongs to all the users.Tools Used
VIM
Recommended Mitigation Steps
add some slippage allowance for contract which is controllable by DAO