Preventing other users from depositing GMX
into AutoPxGmx
contract Or from depositing GLP
into AutoPxGlp
contract
#67
Labels
3 (High Risk)
Assets can be stolen/lost/compromised directly
bug
Something isn't working
duplicate-275
edited-by-warden
satisfactory
satisfies C4 submission criteria; eligible for awards
Lines of code
https://github.com/code-423n4/2022-11-redactedcartel/blob/03b71a8d395c02324cb9fdaf92401357da5b19d1/src/vaults/AutoPxGmx.sol#L397
Vulnerability details
Impact
An attacker can prevent any user from depositing into
PirexGmx
contract, as a result this contract will have no use.Proof of Concept
Suppose the
AutoPxGmx.sol
has just deployed, so it will have the following initial conditions:totalAssets() = 0
: this shows the balance ofpxGMX
custodied by theAutoPxGmx
contracttotalSupply = 0
: this tracks the number of share tokens mintedapxGMX
Then, Bob (malicious user) deposits 1 token
GMX
as the first user by callingdepositGmx
inAutoPxGmx.sol
:https://github.com/code-423n4/2022-11-redactedcartel/blob/03b71a8d395c02324cb9fdaf92401357da5b19d1/src/vaults/AutoPxGmx.sol#L370
As a result, this 1 token
GMX
will be converted topxGMX
, and 1 share token will be minted to Bob, so we will have:totalAssets() = 1
totalSupply = 1
Now, suppose Alice (honest user) would like to deposit 100 token
GMX
inAutoPxGmx
contract by callingdepositGmx
. Bob notices Alice's transaction, and front-runs her by transferring 100 tokenpxGMX
directly toAutoPxGmx
contract not throughdepositGmx
function. Since Bob's transfer is not through the functiondepositGmx
, no share token will be minted to Bob. So we will have:totalAssets() = 1 + 100 = 101
totalSupply = 1
Now Alice's transaction will be executed. During the calculation for amount of share tokens to be minted to Alice,
supply
is equal to 1, so the second statement of if block will be executed:assets.mulDivDown(supply, totalAssets() - assets)
. This statement will be equal to 0, because100 * 1 / (201 - 100) = 100 / 101 = 0
. So, value ofshares
will be equal to zero, and Alice's transaction will be revertedZeroShares()
.So we will have still the same state as before:
totalAssets() = 101
totalSupply = 1
Now, Bob can call the function
redeem(1, Bob, Bob)
:https://github.com/code-423n4/2022-11-redactedcartel/blob/03b71a8d395c02324cb9fdaf92401357da5b19d1/src/vaults/AutoPxGmx.sol#L339
This function will call the function
previewRedeem(shares)
. In this function the amount of assetspxGMX
which is 101 will be transferred to Bob, and 1 share tokenapxGMX
will be burned. Moreover, Bob will not pay any withdrawal penalty, because_totalSupply - shares = 0
.https://github.com/code-423n4/2022-11-redactedcartel/blob/03b71a8d395c02324cb9fdaf92401357da5b19d1/src/vaults/AutoPxGmx.sol#L173
As a summary, Bob can prevent any user from depositing into
AutoPxGmx
contract by depositing just 1 tokenGMX
to have nonzerototalSupply
and then front-running any user by depositing the same amount of the user's deposit. As a result, the contractAutoPxGmx
will be useless.Please note that Bob can prepare token
pxGMX
by depositingGMX
in the contractPirexGmx.sol
by callingdepositGmx
.The same vulnerability also exists is in the contract
AutoPxGlp
during depositingGlp
/FsGlp
/GlpETH
, so maybe it is not reasonable to repeat the same scenario explanation for that contract as well, or make another report.https://github.com/code-423n4/2022-11-redactedcartel/blob/03b71a8d395c02324cb9fdaf92401357da5b19d1/src/vaults/AutoPxGlp.sol#L314
Tools Used
Recommended Mitigation Steps
The solution is to mint a large amount of
apxGMX
intoAutoPxGmx
at the time of deploy. For example, if 100000apxGMX
is minted to this contract, thetotalSupply
will be qual to 100000. So, Bob to apply the same attack in the previous scenario, he should front-runs Alice and transfers directly 100000pxGMX
, so makes the attack almost impossible for Bob.The text was updated successfully, but these errors were encountered: