question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ReEntrancy with multiple coordinating malicious cTokens

See original GitHub issue

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:open
  • Created 2 years ago
  • Reactions:1
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
coburncoburncommented, Aug 30, 2021

https://twitter.com/CreamdotFinance/status/1432249771750686721 this flaw has been exploited in a second Compound fork

1reaction
coburncoburncommented, Aug 17, 2021

@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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

No results found

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found