apxGMX
price can be inflated by first depositor
#252
Labels
3 (High Risk)
Assets can be stolen/lost/compromised directly
bug
Something isn't working
duplicate-275
satisfactory
satisfies C4 submission criteria; eligible for awards
upgraded by judge
Original issue severity upgraded from QA/Gas by judge
Lines of code
https://github.com/code-423n4/2022-11-redactedcartel/blob/03b71a8d395c02324cb9fdaf92401357da5b19d1/src/vaults/AutoPxGmx.sol#L397
Vulnerability details
An early minter can break the
AutoPxGmx
apxGMX
price, resulting in future depositors losingGMX
upon withdrawal.Impact
Medium
Proof Of Concept
AutoPxGmx
is apxGMX
auto-compounding vault, allowing users to depositGMX
andpxGMX
to compoundpxGMX
rewards into morepxGMX
.Users can deposit
GMX
by callingdepositGmx()
. The function computes the amount ofapxGMX
to be minted, and converts theGMX
intopxGMX
The issue is that because of how the
apxGMX
amount is computed, an early minter can inflate the share price and stealpxGMX
from future depositors:autoPxGmx.depositGmx(1, Alice)
, depositing 1 unit ofGMX
. She receives 1apxGMX
.1e18 - 1
pxGMX
to the vault using theERC20.transfer()
method.autoPxGmx.depositGmx(1.99999999e18, Bob)
.pxGMX.balanceOf(autoPxGmx) = 1e18
. Soshares = 1 * 1.9999 e18 / 1e18
rounds to 1: Bob receives 1apxGMX
: the same amount as Alice.autoPxGmx.redeem(1, Alice, Alice);
to redeem herapxGMX
: because she owns half of theapxGMX
, she will receive ~1.5 * 1e18 pxGMX
, effectively stealing approximately 0.5 * 1e18pxGMX
from Bob.Add this test to
AutoPxGmx.t.sol
, recreating the steps described above:Tools Used
Manual Analysis, Foundry
Mitigation
Consider sending the first 1000
apxGMX
to the address 0, a mitigation used in Uniswap V2.The text was updated successfully, but these errors were encountered: