Level Finance Gets Leveled
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.
Level Finance is a decentralized perpetual exchange that offers innovative liquidity solutions and risk management for BTC, ETH, BNB, and stablecoins. Recently, the platform suffered an attack where $1.1 million in referral rewards were stolen due to a bug in the LevelReferralControllerV2 contract, allowing for repeated reward claims to be processed. The attacker used flash loans to create referrals and increase their reward tier, draining 214k LVL tokens, which were swapped for 3,345 BNB. Losses were contained to the referral program, with Treasury funds and LP remaining safe. The funds remain in the attacker's address.
About Level Finance
Level is a decentralized perpetual exchange that combines functional risk management and innovative liquidity solutions. The platform allows users to manage their exposure with just 1/50th collateral, and features a virtually zero slippage and low fee perpetual AMM for leveraged trading in BTC, ETH, BNB, and stablecoins. Level also offers user-elected credit exposure frameworks for liquidity providers, complete transparency, and generates revenue from trading and lending natively in cryptocurrency. The platform is designed to be permissionless with fully transparent open-source smart contracts on BNB Chain. The platform has a user-owned decentralized perpetual exchange and two tokens: the LVL utility token, which is earned via participation on the platform and staked for governance, and the LGO governance token, which is used to make major decisions relating to the platform via voting on the Level DAO[1].
"On-Demand Liquidity Meets Bespoke Risk Management. A Decentralized Perpetual Exchange with Functional Risk Management and Innovative Liquidity Solutions."
"Maximize Your Strategy. Manage your exposure with just 1/50th collateral. Best in kind perpetual AMM with virtually zero slippage and low fees."
"Leveraged Trading. Innovative liquidity solution for BTC, ETH, BNB, and stablecoins."
"Programmable Risk. Define your risk. Level offers an innovative user-elected credit exposure framework for liquidity providers."
"Complete Transparency. No custody, no accounts. Level is designed to be permissionless. Fully transparent open source smart contracts on BNB Chain"
"Real Yield. Revenue from trading and lending generates income natively in the cryptocurrency transacted."
"Decentralized Leadership. First of a kind user owned decentralized perpetual exchange."
Smart Contract Audits by Quantstamp and Obelisk Auditing
The project had previously obtained audits by two separate audit firms, Quantstamp[2] and Obelisk Auditing[3]. Both audits included the project's core contracts[4].
Quantstamp performed an audit for the Level Finance project based on the code present in the listed repositories. We also reviewed the on-chain configuration for the deployed contracts around the time of the writing of this report.
[Obelisk] auditors always conducted a manual visual inspection of the code to find security flaws that automatic tests would not find. Comprehensive tests are also conducted in a specific test environment that utilizes exact copies of the published contract. While conducting the audit, the Obelisk security team uses best practices to ensure that the reviewed contracts are thoroughly examined against all angles of attack. This is done by evaluating the codebase and whether it gives rise to significant risks.
The Reality
While auditing can often find common problems with a smart contract, it is not foolproof. Significant additional certainty can occur from seeking additional audits.
Quantstamp describes some limitations of the available documentation on the smart contract interfering with their auditing process[2].
Moreover, although the protocol does come with a documentation website, there is a distinct lack of detailed technical documentation. For a protocol of this size and complexity, it is important for the developers to provide this documentation for an audit. To account for this, we engaged in extensive communication with the Level Finance team to resolve our higher-level questions and concerns. However, this type of communication can never make up for the detailed explanations and guidance commonly provided by thorough technical documentation. The audit was impaired as a result.
Level Finance’s LevelReferralControllerV2 contract contained a bug which allowed for repeated referral reward claims to be processed within the same epoch. This allowed an attack by creating many referrals and using flash loans to make swaps, which could be used to increase the reward tier of an attacker.
What Happened
The Level Finance referral program was exploited and $1.1m USD worth of referral rewards were taken. Treasury funds and liquidty pools remain safe. The stolen LVL was immediately sold for BNB.
Date | Event | Description |
---|---|---|
November 6th, 2022 | Obelisk Auditing is Commissioned | Obelisk Auditing is commissioned to perform an audit[3]. |
November 21st, 2022 | Obelisk Auditing Starts Audit Process | Obelisk Auditing begins the process of conducting their audit[3]. |
January 9th, 2023 4:17:00 PM MST | Obelisk Auditing Reports Successful Audit | Obelisk auditing announces that they have completed their audit of the Level Finance core contracts[5]. This news is shared with the Level Finance community[6]. |
February 1st, 2023 12:00:00 AM MST | Quantstamp Starts Auditing | Quantstamps starts the process of auditing the Level Finance smart contract[2]. |
April 5th, 2023 7:00:00 PM MDT | Quantstamp Reports Successful Audit | Quantstamp announces that they have completed their audit of Level Finance[7]. This news is shared with the Level Finance community[8]. |
April 23rd, 2023 11:11:16 PM MDT | Attacker Withdraws From TornadoCash | The exploiter withdraws 100 ETH from TornadoCash[9]. |
April 24th, 2023 7:40:20 AM MDT | Funds Moved Between Wallets | The exploiter moves their funds from the TornadoCash receive wallet to their attack wallet[10][11]. |
April 24th, 2023 7:43:32 AM MDT | Malicious Smart Contract Created | The attacker creates a smart contract for their initial attack attempt[12]. |
April 24th, 2023 7:52:59 AM MDT | Initial Attack Attempted | The same attacker[11] attempts a similar attack against the Level Finance protocol[4][13], but failed[14]. "[An] attack was initially attempted over a week ago, but it seems nobody noticed." |
April 24th, 2023 8:00:05 AM MDT | Attacker Gives Up | After 3 more failed attempts (4 in total) to use the malicious smart contract he'd created, the attacker appears to give up[15]. |
May 1st, 2023 7:11:15 AM MDT | Guess Who's Back? | The attacker is back active again, with their first transaction upon returning[16]. TBD - Need to understand this transaction better. |
May 1st, 2023 11:47:32 AM MDT | Malicious Smart Contract Creation | The attacker creates a new version of the smart contract to launch the attack with[17]. TBD what's the difference between the first and second smart contract? |
May 1st, 2023 11:50:41 AM MDT | First Malicious Transaction | The first malicious attacker transactions occurred[18]. TBD more details. |
May 1st, 2023 12:53:00 PM MDT | Definalist Tweet About Hack | Twitter user Definalist announces that Level Finance "is currently under attack from hackers" who are "currently withdrawing LVL tokens in increments of 15,000 using the delegate function"[19]. |
May 1st, 2023 1:33:21 PM MDT | Attacker Moves Funds | The attacker moves his funds to a second wallet[20]. TBD Double check this transaction. |
May 1st, 2023 2:54:00 PM MDT | Twitter Announcement | Level Finance first posts about the issue on Twitter. They report an exploit that targeted the Referral Controller Contract. The attacker drained 214k LVL tokens, worth approximately $1.1M, and swapped them for 3,345 BNB. The exploit was isolated from other contracts, and LP's and DAO treasury were unaffected. A fix is expected to be deployed in the next 12 hours, and more details will be provided[21]. |
May 2nd, 2023 12:46:00 PM MDT | Remediation Proposal Announced | The Level Finance team posts a proposed remediation[22]. The team states they have already taken steps to secure the contract, and a fix will be pushed once the timelock expires. The team has proposed three options to minimize the impact on the community, including conducting a special auction to burn LVL tokens, creating a special LVL auction, and committing the DAO's treasury to buy or burn LVL tokens. LGO token holders are eligible to vote on the proposed options. Going forward, the team will place an emphasis on DevOps and OPSEC to minimize future attacks[23]. |
May 2nd, 2023 2:54:00 PM MDT | Rekt News Report | The incident is reported on Rekt.news[24]. The news report states that on May 2, 2023, the Binance Smart Chain-based DeFi platform, Level Finance, suffered a hack that drained $1.1 million in referral rewards from its LevelReferralControllerV2 contract. The attacker used flash loans to increase their reward tier, and their successful attack went unnoticed for a week. The attack resulted from a bug in the contract that allowed repeated claims within the same epoch. The hack initially caused a 65% drop in LVL's price, but it has mostly recovered since. The incident highlights the need for improved on-chain monitoring systems to prevent future attacks on DeFi protocols[4]. |
May 10th, 2023 8:08:00 AM MDT | ImmuneFi Bug Bounty | The Level Finance team added an ImmuneFi bug bounty with rewards of up to $1m USD for exploits discovered[25][26]. |
Technical Details
This section includes specific detailed technical analysis of any security breaches which happened. What specific software vulnerabilities contributed to the problem and how were they exploited?
"Level Finance’s LevelReferralControllerV2 contract contained a bug which allowed for repeated referral reward claims to be processed within the same epoch."
"In total, 214k LVL tokens were drained by the exploiter, who swapped them for 3,345 BNB, worth approximately $1.1M at the time of writing.
"Yesterday, $1.1M in referral rewards were robbed from the BSC-based perps platform."
Total Amount Lost
"In total, 214k LVL tokens were drained by the exploiter, who swapped them for 3,345 BNB, worth approximately $1.1M at the time of writing. The funds currently remain in the attacker’s address."
The total amount lost has been estimated at $1,802,000 USD.
"Luckily, the losses were contained to the project’s referral programme, with Treasury funds and LP both safe." "The hacker dumping LVL tokens for BNB initially crashed the price by 65%, though this has mostly recovered since."
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?
"The alarm was raised by definalist (whilst the attack was still ongoing) and confirmed two hours later by the Level Finance team."
Initial Posts on Twitter By Level Finance
Level Finance announced the exploit on Twitter shortly after it occurred[21].
An exploit targeted our Referral Controller Contract.
- 214k LVL tokens drained to exploiters address.
- Attacker swapped LVL to 3,345 BNB
- Exploit was isolated from other contracts.
- Fix to be deployed in 12 Hrs.
- LP's and DAO treasury UNAFFECTED.
More details to follow.
Remediation Proposal
A remediation proposal was put forward[27].
Referral Controller Contract Remediation
Due to recent updates in Level’s incentive mechanism, a bug was introduced into the Referral Controller Contract within the claimMultiple() function on the following line:
users[epoch][msg.sender].claimed = reward;
It should instead be
users[epoch][msg.sender].claimed += reward;
When
claimMultiple()
callsclaimable()
with the same epoch multiple times, the returned value resulted in an alternating positive sequence, each number being added to the total reward payout.As a result, 214k LVL was siphoned out of the referral contract and converted to 3,345 BNB by the attacker. Steps have already been taken to secure the contract and a fix will be pushed once the timelock expires. We accept full responsibility.
Given that the full extent of the exploit resulted in the introduction of 214k LVL being added to the circulating supply, we would like to introduce the following proposal to minimize impact to Level’s community of users. Please vote on the combination of action steps that you think would generate the most durable value for the community as a whole:
- The team will commit 2 LGO from the team wallet and conduct a special auction(s) in an effort to diminish the amount of LVL introduced by burning it at the end of the auction. Given that no additional LGO will be introduced as the result of this, Treasury value will not be affected as no dilution would result from this auction.
- The majority of the users affected by this exploit were the ones who unstaked their LVL tokens and panic sold in anticipation of the attacker selling. This resulted in the bulk of the price action that ensued, and as the LVL token price recovered, some of the panic dumpers were not able to buy back LVL tokens at the price they sold, which resulted in trading losses. We neither have the desire nor the ability to prevent token holders from selling. But if the community so wishes, we can also create a special LVL auction up to the amount of the exploit (214k), where the price will start at 0$, and the purchased LVL tokens will be vested over 365 days.
- The purpose of the DAO’s Treasury is not purely for-profit capture. It is a vehicle that is meant to facilitate essential functions within the Level ecosystem, and when necessary come to the support of Level’s community of users. If the community so wishes, the Treasury can either commit to buying up to 214k LVL and keeping it within the Treasury’s balance or burning 214k LVL out of the treasury directly. Not unlike the feds, the DAO has incredible holding power. Net net this also has no impact to the Treasury over the long run. (Should this option be chosen, a follow on vote will decide whether to buyback or straight up burn)
Going forward, the Level team will place an even greater emphasis on DevOps and OPSEC. We have engaged the Quantstamp team in a continuous capacity to conduct real time security reviews on all contract upgrades. Given the sheer volume as well as complexity of LEVEL’s code-base along with our speed of development, this has unfortunately been an ongoing challenge. Nevertheless, steps will be taken to minimize future attacks. As with any project pioneering a new field, it comes with inherent risks along with trade-offs. Please bear with us as we learn. Together we will iteratively improve the protocol. In time the Level community will own one of the most significant assets within the industry.
VOTING OPTIONS
a) 1 only b) 2 only c) 3 only d) 1 and 2 only e) 1 and 3 only f) 2 and 3 only g) 1, 2 and 3
ELIGIBILITY
Only LGO token holders are eligible to vote.
Ultimate Outcome
What was the end result? Was any investigation done? Were any individuals prosecuted? Was there a lawsuit? Was any tracing done?
Addition of ImmuneFi Bug Bounty
The Level Finance team launched a $1m smart contract bug bounty with ImmuneFi, which allows hackers to earn up to $1m USD for discovering critical vulnerabilities[25][26].
Total Amount Recovered
There do not appear to have been any funds recovered in this case.
The funds currently remain in the attacker’s address."
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?
Individual Prevention Policies
Avoid the use of smart contracts unless necessary. Minimize the level of exposure by removing or withdrawing assets whenever possible. Aim to choose smart contracts which have obtained third party security audits, preferably having been audited by at least three separate reputable firms. Pay attention to the audit reports, which smart contracts are covered, and whether the smart contract has been upgraded or modified since the report. Ensure that any administrative functions with the ability to remove funds from the smart contract are under the authority of a multi-signature wallet which is controlled by at least three separate and reputable entities.
For the full list of how to protect your funds as an individual, check our Prevention Policies for Individuals guide.
Platform Prevention Policies
All aspects of any platform should undergo a regular validation/inspection by experts. This validation should include a security audit of any smart contracts, reporting any risks to the backing (of any customer assets, ensuring treasuries or minting functions are properly secured under the control of a multi-signature wallet, and finding any inadequacies in the level of training or integrity of the team. The recommended interval is twice prior to launch or significant system upgrade, once after 3 months, and every 6 months thereafter. It is recommended that the third party performing the inspection not be repeated within a 14 month period.
For the full list of how to protect your funds as a financial service, check our Prevention Policies for Platforms guide.
Regulatory Prevention Policies
All platforms should undergo published security and risk assessments by independent third parties. Two assessments are required at founding or major upgrade, one after 3 months, and one every 6 months thereafter. The third parties must not repeat within the past 14 months. A risk assessment needs to include what assets back customer deposits and the risk of default from any third parties being lent to. The security assessment must include ensuring a proper multi-signature wallet, and that all signatories are properly trained. Assessments must be performed on social media, databases, and DNS security.
For the full list of regulatory policies that can prevent loss, check our Prevention Policies for Regulators guide.
References
- ↑ Level - Decentralized Perpetual Exchange (May 3, 2023)
- ↑ 2.0 2.1 2.2 Level Finance Audit - Quantstamp (May 8, 2023)
- ↑ 3.0 3.1 3.2 Auditing Report - Obelisk Auditing (May 8, 2023)
- ↑ 4.0 4.1 4.2 Rekt - Level Finance - REKT (May 3, 2023)
- ↑ Obelisk Auditing - Our team has delivered the audit of @Level__Finance Core contracts." - Twitter (May 8, 2023)
- ↑ Level Finance - "We are happy to announce that @ObeliskOrg has published the audit report of #LEVEL core contracts." - Twitter (May 8, 2023)
- ↑ Quantstamp - We’ve completed the audit of @Level__Finance’s level-trading-contracts repo at commit 28b2dc5 and level-core-contracts repo at commit 55bdced." - Twitter (May 8, 2023)
- ↑ Level Finance - "Quantstamp has completed the auditing of #LEVEL smart contracts." - Twitter (May 8, 2023)
- ↑ TornadoCash Withdrawal of 100 ETH By Attacker - BscScan (May 5, 2023)
- ↑ Attacker Shifting Funds To Attack Wallet - BscScan (May 5, 2023)
- ↑ 11.0 11.1 Level Finance Attacker's Address - BscScan (May 5, 2023)
- ↑ Attempted Malicious Smart Contract Creation - BscScan (May 5, 2023)
- ↑ BlockSecTeam - "@Level__Finance was reported to be hacked due to the lack of checks of repeated items for the array argument of the vulnerable function." - Twitter (May 5, 2023)
- ↑ First Attempt At Exploit - BscScan (May 5, 2023)
- ↑ Attacker's Fourth Failed Attempt - BscScan (May 5, 2023)
- ↑ Attacker Returns With Another Transaction - BscScan (May 5, 2023)
- ↑ Attacker Creates Final Smart Contract - BscScan (May 5, 2023)
- ↑ Binance Transaction Of Exploit - BscScan (May 3, 2023)
- ↑ Definalist - "Looks like @Level__Finance is currently under attack from hackers. Hacker created an unverified contract 7 days ago and are currently withdrawing LVL tokens in increments of 15,000 using the delegate function. The hacker's source of funds came from Tornado Cash." - Twitter (May 5, 2023)
- ↑ Attacker Transferring His Funds From The Attack Wallet - BscScan (May 5, 2023)
- ↑ 21.0 21.1 Level__Finance - "An exploit targeted our Referral Controller Contract. 214k LVL tokens drained to exploiters address." - Twitter (May 3, 2023)
- ↑ Level__Finance - "Remediation for Referral reward exploit DAO proposal." - Twitter (May 3, 2023)
- ↑ Remediation for Referral reward exploit - Level DAO - May 2nd, 2023 (May 3, 2023)
- ↑ RektHQ - "@Level__Finance got levelled. $1.1M in referral rewards were robbed from the BSC-based perps platform yesterday." - Twitter (May 3, 2023)
- ↑ 25.0 25.1 ImmuneFi - "Great news! @Level__Finance has added Smart Contracts to their bug bounty program, so you can now earn up to $1 MILLION for critical SC vulns" - Twitter (May 16, 2023)
- ↑ 26.0 26.1 Level Finance - "We have now added Smart Contracts to our #LEVEL bug bounty program with @immunefi!" - Twitter (May 16, 2023)
- ↑ Remediation for Referral reward exploit - Level Finance DAO (May 16, 2023)