Cream Finance Reentrancy Bug

From Quadriga Initiative Cryptocurrency Hacks, Scams, and Frauds Repository
Revision as of 15:23, 27 January 2023 by Azoundria (talk | contribs) (Created page with "{{Imported Case Study|source=https://www.quadrigainitiative.com/casestudy/creamfinancereentrancybug.php}} thumb|Cream FinanceCream Finance is a decentralized lending program. There was a reentrancy exploit in the smart contract hot wallet where AMP and ETH were stored. This enabled a hacker to remove 462,079,976 in AMP and 2,804.96 ETH. It appears that Cream Finance has committed to making this right, and that the hacker ultimately returned the...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Notice: This page is a freshly imported case study from the original repository. The original content was in a different format, and may not have relevant information for all sections. Please help restructure the content by moving information from the 'About' section to other sections, and add any missing information or sources you can find. If you are new here, please read General Tutorial on Wikis or Anatomy of a Case Study for help getting started.

Cream Finance

Cream Finance is a decentralized lending program. There was a reentrancy exploit in the smart contract hot wallet where AMP and ETH were stored. This enabled a hacker to remove 462,079,976 in AMP and 2,804.96 ETH. It appears that Cream Finance has committed to making this right, and that the hacker ultimately returned the funds. A 10% bounty was offered.

This is a global/international case not involving a specific country.

About Cream Finance

"C.R.E.A.M. Finance is a decentralized lending protocol for individuals, institutions and protocols to access financial services. Part of the yearn finance ecosystem, it is a permissionless, open source and blockchain agnostic protocol serving users on Ethereum, Binance Smart Chain and Fantom. Users who are passively holding Ethereum or Bitcoin can deposit their assets on C.R.E.A.M. to earn yield, similar to a traditional savings account."

"At approximately 12pm on 31st August (UTC +8), C.R.E.A.M. Finance was exploited for 462,079,976 in AMP tokens and 2,804.96 ETH tokens."

"There was a main exploit along with a smaller copy-cat. The copy-cat exploit address has withdrawal history from Binance. We are working with Binance to identify the second perpetrator. We will forward all relevant information to law enforcement authorities and prosecute to the fullest extent of the law."

"The hack is made possible due to a reentrancy bug introduced by $AMP, which is an ERC777-like token and exploited to re-borrow assets during its transfer before updating the first borrow." "The AMP token contract implements ERC777, which has the _callPostTransferHooks hook that triggers tokensReceived() function that was implemented by the recipient. The reentrancy opportunity related to ERC-777-style transfer hooks allowed the exploiter to nest a second borrow() function inside the token transfer() before the initial borrow() was updated. This was used over 17 transactions."

"With the assistance of PeckShield, we have determined that the root cause of the exploit was an error in the way C.R.E.A.M. Finance integrated AMP into our protocol. While unfortunate and disappointing, we take ownership of the error."

"Since the execution of this attack vector would result in the protocol holding bad debts against the attacking contract address, each attacking contract could only be used once. The attacker repeated the attack 7 times with deployments of duplicated attacking contracts before 10 revised version of the attack were launched."

"In the first wave of the attacks, the attacker started with supplying ETH as collateral in crETH market, and then borrowed AMP from crAMP market. Within the execution of transferring AMP to the attacking contract, _callPostTransferHooks was called, which in turn executed an external contract call that then re-entered crETH market to borrow ETH against the very same collateral that was supposed to be posted for borrowing AMP."

"To be more specific, the vulnerability is present within our borrow function when executed in combination with $AMP token’s ERC777 implementation, which calls the tokenReceived hook. In our crToken contract, we transfer the loan before updating the storage. Since $AMP is an ERC777-like token, tokenReceived hook is called. This allowed the attacker to nest a second borrow() function before the initial borrow() completed its execution, the effect of which allowed the attacker to borrow more than normally they would have been allowed."

"[I]n the example tx, the hacker makes a flashloan of 500 ETH and deposit the funds as collateral. Then the hacker borrows 19M $AMP and makes use of the reentrancy bug to re-borrow 355 ETH inside $AMP token transfer(). Then the hacker self-liquidates the borrow." "The hacker repeats the above process in 17 different txs and gains in total 5.98K ETHs (with ~$18.8M)."

"We paused the AMP supply and borrow functions. We will re-enable the AMP market when a patch can be safely deployed. We are working with auditors and technical advisors to ensure that we can safely protect against similar attacks in the future."

"We will be replacing the stolen ETH and stolen AMP so that there’s no liquidity issues for users. We will commit to allocating 20% of all protocol fees toward repayment until this debt is fully paid. In the meantime, we will post a CREAM collateral with the Flexa/AMP team to secure this debt."

"We are committed to making this right for those negatively impacted by the exploiter. We are committed to this industry and building innovative DeFi products. We appreciate the support of our partners and community and will move forward together."

"We have long term goals, and C.R.E.A.M. Finance will continue to build and innovate. We will learn from this exploit and use it as an opportunity to further strengthen the C.R.E.A.M. protocol. While certainly a setback, we remain driven in our mission to bring capital efficiency decentralized lending markets, fulfilling the financial needs of individuals, institutions and protocols."

"@CreamdotFinance hacker just returned 5,152.6 ETH"

This is a global/international case not involving a specific country.

The background of the exchange platform, service, or individuals involved, as it would have been seen or understood at the time of the events.

Include:

  • Known history of when and how the service was started.
  • What problems does the company or service claim to solve?
  • What marketing materials were used by the firm or business?
  • Audits performed, and excerpts that may have been included.
  • Business registration documents shown (fake or legitimate).
  • How were people recruited to participate?
  • Public warnings and announcements prior to the event.

Don't Include:

  • Any wording which directly states or implies that the business is/was illegitimate, or that a vulnerability existed.
  • Anything that wasn't reasonably knowable at the time of the event.

There could be more than one section here. If the same platform is involved with multiple incidents, then it can be linked to a main article page.

The Reality

This sections is included if a case involved deception or information that was unknown at the time. Examples include:

  • When the service was actually started (if different than the "official story").
  • Who actually ran a service and their own personal history.
  • How the service was structured behind the scenes. (For example, there was no "trading bot".)
  • Details of what audits reported and how vulnerabilities were missed during auditing.

What Happened

The specific events of the loss and how it came about. What actually happened to cause the loss and some of the events leading up to it.

Key Event Timeline - Cream Finance Reentrancy Bug
Date Event Description
August 30th, 2021 12:00:00 AM Main Event Expand this into a brief description of what happened and the impact. If multiple lines are necessary, add them here.

Total Amount Lost

The total amount lost has been estimated at $18,800,000 USD.

How much was lost and how was it calculated? If there are conflicting reports, which are accurate and where does the discrepancy lie?

Immediate Reactions

How did the various parties involved (firm, platform, management, and/or affected individual(s)) deal with the events? Were services shut down? Were announcements made? Were groups formed?

Ultimate Outcome

What was the end result? Was any investigation done? Were any individuals prosecuted? Was there a lawsuit? Was any tracing done?

Total Amount Recovered

There do not appear to have been any funds recovered in this case.

What funds were recovered? What funds were reimbursed for those affected users?

Ongoing Developments

What parts of this case are still remaining to be concluded?

Prevention Policies

Hot wallets should either not store customer funds, or be insured fully through smart contract insurance or our proposed industry insurance fund.

References

blocksec-incidents/2021.md at main · openblocksec/blocksec-incidents · GitHub (Aug 10)

C R E A M Finance Is Coming To Arbitrum (Nov 5)

C R E A M Finance Post Mortem Amp Exploit (Nov 5)

Ethereum Transaction Hash (Txhash) Details | Etherscan (Nov 5)

Ethereum Transaction Hash (Txhash) Details | Etherscan (Nov 5)

@peckshield Twitter (Nov 5)

https://slowmist.medium.com/slowmist-brief-analysis-of-cream-finance-hacked-event-30b18e1db8c (Nov 5)

https://medium.com/@Knownsec_Blockchain_Lab/knowsec-blockchain-lab-cream-finance-reentry-vulnerability-incident-analysis-bb7a540c1816 (Nov 5)

Rekt - Cream Finance - REKT (Nov 5)

@peckshield Twitter (Nov 5)

@CreamdotFinance Twitter (Nov 5)

Cream Finance launches $1.5M bug bounty to improve DeFi security (Feb 8)

Cream Finance Review: What You NEED To Know About CREAM!! (Feb 8)

August 19th Beta Liquidity Mining Distribution (Feb 8)