[The Butterfly Effect] The Compound Security Incident Caused by a Bugfix


The Compound protocol is based on the Compound Whitepaper. Through the cToken contracts, accounts on the blockchain supply capital (Ether or ERC-20 tokens) to receive cTokens or borrow assets from the protocol (holding other assets as collateral). The Compound cToken contracts track these balances and algorithmically set interest rates for borrowers.

Bug 1

On September 31, 2021, there was a new proposal (Proposals 62) in the Compound DAO, which aims to fix a bug in the Comptroller.

The flow of the mint function

In the following, we will use the mint function to describe the cause of this bug. The invocation chain of the mint function is: mintmintInternalmintFresh.



The another function distributeSupplierComp is responsible for recording the number of COMP tokens that should be distributed to the user (supplier) in compAccrued[supplier]

the cause of the Bug 1

There is another function setCompSpeed to adjust the supplySpeed of the market (compSpeeds[address[cToken]]).

  • Step I: set the CompSpeed[cToken] as zero to disable the distribution of COMP tokens
  • Step II: invoke the setCompSpeed function to set CompSpeed[cToken] as a non-zero value

the impact of the bug 1

We further dig into the ``distributeSupplierComp` function that’s responsible for distributing the COMP tokens.

Bug 2: Introduced by the fix to the bug 1

To fix the bug, the project owner changes the code logic. Specifically, it immediately initializes the index to compInitialIndex when initializing a new market.

Real World

We show the affected markets in the following:

0xF5DCe57282A584D2746FaF1593d3121Fcac444dC: cSAI
0x12392F67bdf24faE0AF363c24aC620a2f67DAd86: cTUSD
0x95b4eF2869eBD94BEb4eEE400a99824BF5DC325b: cMKR
0x4B0181102A0112A2ef11AbEE5563bb4a3176c9d7: cSUSHI
0xe65cdB6479BaC1e22340E4E755fAE7E509EcD06c: cAAVE
0x80a2AE356fc9ef4305676f7a3E2Ed04e12C33946: cYFI

the fix to the bug 2

The fix to the bug 2 is simple. It changes the if condition in the distributeSupplierComp function.


  • This is a bug caused by the fix of another bug. How to thoroughly review the code changes for high-profile projects is still an open question.
  • The DAO can eliminate the risk of centralization. However, it also makes the response to security incidents a slow process.
  • The high profile DeFi projects can take good security practices in traditional programs, e.g., deploying an efficient fuzzing system with a continuous testing process.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store



The BlockSec Team focuses on the security of the blockchain ecosystem and the research of crypto hack monitoring and blocking, smart contract auditing.