Off by One issue in the _forceRepay() function causes protocol to lose funds in the form of protocol fee.
Vulnerability Details
In the _forceRepay() function, protocolFeeTotal is paid when account.collateralBalance > protocolFeeTotal.
function_forceRepay(uint256accountId,uint256amount)internalreturns(uint256){...if(account.collateralBalance > protocolFeeTotal){ account.collateralBalance -= protocolFeeTotal;// Transfer the protocol fee to the protocol fee receiver TokenUtils.safeTransfer(myt, protocolFeeReceiver, protocolFeeTotal);}...
But what if whenaccount.collateralBalance = protocolFeeTotal.
The check should be account.collateralBalance >= protocolFeeTotal where >= should be used instead of =.
Impact Details
Loss of funds for the protocol when account.collateralBalance = protocolFeeTotal.
References
The above code snippets can be verified here: https://github.com/alchemix-finance/v3-poc/blob/a192ab313c81ba3ab621d9ca1ee000110fbdd1e9/src/AlchemistV3.sol#L771-L775
Proof of Concept
Proof of Concept
Paste the above test in the AlchemistV3.t.sol contract, set up $MAINNET_RPC_URL and run it using: