Submitted by hyh, also found by defsec
Having no reentrancy control and updating the records after external interactions allows for funds draining by reentrancy.
Setting the severity to medium as this is conditional to transfer flow control introduction on future upgrades, but the impact is up to the full loss of the available funds by unrestricted borrowing.
CNote runs doTransferOut before borrowing accounts are updated:
https://github.com/Plex-Engineer/lending-market/blob/2d423c7c3f62d65182d802deb99cc7bba4e057fd/contracts/CNote.sol#L70-L87
Call sequence here is borrow() -> borrowInternal() -> borrowFresh() -> doTransferOut(), which transfers the token to an external recipient:
https://github.com/Plex-Engineer/lending-market/blob/2d423c7c3f62d65182d802deb99cc7bba4e057fd/contracts/CErc20.sol#L189-L200
There an attacker can call exitMarket() that have no reentrancy control to remove the account of the debt:
https://github.com/Plex-Engineer/lending-market/blob/2d423c7c3f62d65182d802deb99cc7bba4e057fd/contracts/Comptroller.sol#L167-L174
https://github.com/Plex-Engineer/lending-market/blob/2d423c7c3f62d65182d802deb99cc7bba4e057fd/contracts/ComptrollerG7.sol#L157-L164
This attack was carried out several times:
https://certik.medium.com/fei-protocol-incident-analysis-8527440696cc
Consider moving accounting update before funds were sent out, for example as it is done in CTokens borrowFresh():
nivasan1 (Canto) confirmed
Alex the Entreprenerd (judge) commented:
