Open code423n4 opened 2 years ago
Sponsor acknowledged
Given that the gALCX deployment has 412 unique tokenholders on mainnet, this series of events is extraordinarily unlikely to occur. But we will keep it in mind for future deployments.
Nice find! Early stakers can DoS new contract deployments, making it impossible for other users to participate in the protocol. As this does not lead to lost funds and is recoverable through redeployment, I believe medium severity to be justified by the warden.
Lines of code
https://github.com/code-423n4/2022-05-alchemix/blob/main/contracts-hardhat/gALCX.sol#L73-L76
Vulnerability details
Impact
An attacker can make the contract unusable when totalSupply is 0. Specifically,
bumpExchangeRate
function does not work correctly which results in makingstake
,unstake
andmigrateSource
functions that do not work as expected.Proof of Concept
Here are steps on how the
gALCX
contract can be unusable.gALCX
contract is deployedThe attacker sends the
ALCX
token to the deployedgALCX
contract directly instead of usingstake
function so that the followingbalance
variable has value.https://github.com/code-423n4/2022-05-alchemix/blob/main/contracts-hardhat/gALCX.sol#L73-L75
ALCX
token is given to thegALCX
contract directly,totalSupply == 0
andalcx.balanceOf(address(this)) > 0
becomes true.https://github.com/code-423n4/2022-05-alchemix/blob/main/contracts-hardhat/gALCX.sol#L76
Non attackers try to call
stake
function, butbumpExchangeRate
function fails because of(balance * exchangeRatePrecision) / totalSupply
when totalSupply is 0.Owner cannot call
migrateSource
function sincebumpExchangeRate
will be in the same situation mentioned in the step4 aboveTools Used
Static code analysis
Recommended Mitigation Steps
Add handling when
totalSupply
is 0 butalcx.balanceOf(address(this))
is more than 0.