Submitted by MiloTruck, also found by d3e4 (1, 2), adriro, and rvierdiiev
In AfEth.sol, the price() function returns the current price of afEth:
AfEth.sol#L133-L141
As seen from above, the price of afEth is calculated by the TVL of both safEth and vAfEth divided by totalSupply(). However, this calculation does not take into account afEth that is transferred to the contract when requestWithdraw() is called:
AfEth.sol#L183-L187
When a user calls requestWithdraw() to initiate a withdrawal, his afEth is transferred to the AfEth contract as shown above. Afterwards, an amount of vAfEth proportional to his withdrawal amount is burned, and pendingSafEthWithdraws is increased.
When price() is called afterwards, safEthBalanceMinusPending() and vEthStrategy.balanceOf(address(this)) will be decreased. However, since the users afEth is only transferred and not burnt, totalSupply() remains the same. This causes the value returned by price() to be lower than what it should be, since totalSupply() is larger than the actual circulating supply of afEth.
This is an issue as deposit() relies on price() to determine how much afEth to mint to a depositor:
AfEth.sol#L166-L168
Where:
If anyone has initiated a withdrawal using requestWithdraw() but hasnt called withdraw() to withdraw his funds, price() will be lower than what it should be. Subsequently, when deposit() is called, the depositor will receive more afEth than he should since priceBeforeDeposit is smaller.
Furthermore, a first depositor can call requestWithdraw() with all his afEth immediately after staking to make price() return 0, thereby permanently DOSing all future deposits as deposit() will always revert with a division by zero error.
When there are pending withdrawals, price() will return a value smaller than its actual value. This causes depositors to receive more afEth than intended when calling deposit(), resulting in a loss of funds for previous depositors.
Additionally, a first depositor can abuse this to force deposit() to always revert, permanently bricking the protocol forever.
Assume that the protocol is newly deployed and Alice is the only depositor.
Alice calls requestWithdraw() with _amount as all her afEth:
Bob calls deposit() to deposit some ETH into the protocol:
As demonstrated above, deposit() will always revert as long as Alice does not call withdraw() to burn her afEth, thereby bricking the protocols core functionality.
In price(), consider subtracting the amount of afEth held in the contract from totalSupply():
AfEth.sol#L133-L141
elmutt (Asymmetry) confirmed and commented:
Asymmetry mitigated:
Status: Mitigation confirmed. Full details in reports from m_Rassska, d3e4, and adriro.
