ReEntrancy with multiple coordinating malicious cTokens
See original GitHub issueIssue Description
The borrowFresh and redeemFresh functions transfer tokens out of the protocol before updating internal accounting. This is a reentrancy vulnerability for tokens that define a malicious transfer
function. The cToken contract has a reentrancy guard for this purpose. However, if multiple malicious tokens coordinate, the reentrancy guards on individual tokens are not sufficient to prevent the comptroller from reading stale liquidity data when checking these transfers.
Compound governance has been diligent in not listing malicious tokens, but the contracts should be fixed for the future.
The fix is to simply move the doTransferOut
call to after internal accounting in the affected functions.
https://github.com/compound-finance/compound-protocol/blob/master/contracts/CToken.sol#L786 https://github.com/compound-finance/compound-protocol/blob/master/contracts/CToken.sol#L694
This flaw was discovered by DeFiPie, an independent deployment of the Compound Protocol.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:9 (5 by maintainers)
https://twitter.com/CreamdotFinance/status/1432249771750686721 this flaw has been exploited in a second Compound fork
@llama There is one main subtlety I think you are missing: no individual cToken is ever reentered. cToken A calls into Token B which calls cTokenB which calls token C which calls cToken C which finally calls into a real token with actual value.