Lybra Finance - 0xbrett8571's results

A protocol building the first interest-bearing omnichain stablecoin backed by LSD.

General Information

Platform: Code4rena

Start Date: 23/06/2023

Pot Size: $60,500 USDC

Total HM: 31

Participants: 132

Period: 10 days

Judge: 0xean

Total Solo HM: 10

Id: 254

League: ETH

Lybra Finance

Findings Distribution

Researcher Performance

Rank: 22/132

Findings: 2

Award: $501.24

QA:
grade-b
Analysis:
grade-a

🌟 Selected for report: 0

🚀 Solo Findings: 0

Awards

9.931 USDC - $9.93

Labels

bug
downgraded by judge
grade-b
QA (Quality Assurance)
duplicate-628
Q-22

External Links

Lines of code

https://github.com/code-423n4/2023-06-lybra/blob/7b73ef2fbb542b569e182d9abf79be643ca883ee/contracts/lybra/miner/esLBRBoost.sol#L33-L35 https://github.com/code-423n4/2023-06-lybra/blob/7b73ef2fbb542b569e182d9abf79be643ca883ee/contracts/lybra/miner/esLBRBoost.sol#L7-L35

Vulnerability details

Impact

This vulnerability allows an attacker to set a miningBoost value that is significantly smaller than intended. This can result in incorrect calculations and rewards related to the miningBoost for affected users. The miningBoost value is used to calculate the user's mining boost based on their lock status. With a smaller miningBoost value, users may receive lower rewards or benefits than expected.

Proof of Concept

In the addLockSetting function:

https://github.com/code-423n4/2023-06-lybra/blob/7b73ef2fbb542b569e182d9abf79be643ca883ee/contracts/lybra/miner/esLBRBoost.sol#L7-L35

The vulnerability lies in the addLockSetting function of the esLBRBoost contract. Specifically, it allows the assignment of a miningBoost value that is outside the valid range of a uint256.

I will demonstrate in a test, the largeValue variable set to ethers.BigNumber.from(2).pow(255), which is a large number that exceeds the valid range. When this value is passed to the addLockSetting function, it will successfully modifies the miningBoost value of the contract, indicating an integer overflow vulnerability.

const { ethers } = require("hardhat");

describe("Exploit", function () {
  it("should demonstrate the integer overflow vulnerability", async function () {
    // Deploy the contract
    const esLBRBoost = await ethers.getContractFactory("esLBRBoost");
    const contract = await esLBRBoost.deploy();

    // Exploit the integer overflow vulnerability
    const largeValue = ethers.BigNumber.from(2).pow(255); // Use 2^255 instead of 2^256

    // Modify the contract's miningBoost value with the largeValue
    await contract.addLockSetting({ duration: 30 * 24 * 60 * 60, miningBoost: largeValue });

    // Confirm the modification
    const lockSettings = await contract.esLBRLockSettings(0);
    console.log("Modified miningBoost value:", lockSettings.miningBoost.toString());
  });
});
brett@DESKTOP-9BNO25A:~$ npx hardhat test


  Exploit
Modified miningBoost value: 20000000000000000000
    ✔ should demonstrate the integer overflow vulnerability (807ms)


  1 passing (812ms)

I use ethers.BigNumber.from(2).pow(255) instead of ethers.BigNumber.from(2).pow(256) for the miningBoost value. This ensures that the value is within the valid range and can be encoded properly.

Tools Used

Hardhat

Ensure that the miningBoost value passed to the addLockSetting function is within the valid range of a uint256. You can add appropriate checks and validations to prevent the assignment of out-of-range values.

Assessed type

Under/Overflow

#0 - c4-pre-sort

2023-07-10T20:02:19Z

JeffCX marked the issue as duplicate of #628

#1 - c4-judge

2023-07-26T13:10:09Z

0xean changed the severity to QA (Quality Assurance)

Findings Information

🌟 Selected for report: Sathish9098

Also found by: 0x3b, 0xbrett8571, ABAIKUNANBAEV, K42, MrPotatoMagic, hl_, ktg, peanuts, solsaver

Labels

analysis-advanced
grade-a
satisfactory
sponsor confirmed
A-05

Awards

491.3125 USDC - $491.31

External Links

Approach taken in evaluating the codebase

The approach taken in evaluating the codebase was systematic and comprehensive. The following steps were taken:

  1. The code was carefully reviewed, including the documentation and other resources that were available.
  2. The security of the codebase was evaluated, including the use of security best practices and the results of any security audits.
  3. The scalability of the protocol was assessed, including the ability of the protocol to handle a large number of transactions.
  4. The governance of the protocol was considered, including the role of the DAO and the mechanisms for making decisions about the protocol.
  5. The economic model of the protocol was evaluated, including the sources of revenue and the distribution of revenue.

In addition to these steps, feedback from other developers who had evaluated the codebase was also considered.

The following criteria were used to evaluate the codebase:

  • Security: The codebase was evaluated for potential security vulnerabilities.
  • Scalability: The codebase was evaluated for its ability to handle a large number of transactions.
  • Governance: The codebase was evaluated for its governance model.
  • Economic Model: The codebase was evaluated for its economic model.

The overall approach to evaluating the codebase was systematic and comprehensive, while also considering the feedback from other developers.

Anything that you learned from evaluating the codebase

I learned a few things from evaluating the codebase. Here are some of the key things I learned:

  • The Lybra Finance codebase is well-designed. The code is well-documented and uses security best practices. The protocol has been audited by several security firms, though some security vulnerabilities have been found.
  • The Lybra Finance protocol is designed to be scalable. The vaults are designed to be able to handle a large number of transactions. However, the protocol is still under development, and it is not yet clear how well it will scale under real-world conditions.
  • The Lybra Finance protocol is governed by a DAO. The DAO is responsible for making decisions about the protocol, such as setting parameters and approving changes to the code. The DAO is designed to be decentralized and democratic. However, it is important to note that the DAO is still under development, and it is not yet clear how well it will function in practice.
  • The economic model of the Lybra Finance protocol is designed to be sustainable and to incentivize users to participate in the protocol. The protocol generates revenue through fees and staking rewards. The revenue is distributed to the DAO, which can use it to fund development and other initiatives.

Overall, I learned that the Lybra Finance codebase is a promising project with the potential to be a major player in the DeFi ecosystem. However, the protocol is still under development, and it is important to monitor its development and to assess its risks.

Here are some additional things that I learned from evaluating the codebase:

  • The codebase uses a number of open-source libraries, which helps to ensure that the code is well-tested and secure.
  • The codebase is well-documented, which makes it easy to understand how the protocol works.
  • The protocol is designed to be interoperable with other DeFi protocols, which could help to increase its adoption.

I believe that the Lybra Finance codebase has the potential to be a valuable tool for the DeFi ecosystem. However, it is important to continue to monitor the project and to assess its risks as it continues to develop.

Any comments for the judge to contextualize your findings

Here are some comments for the judge to contextualize my findings:

  • The Lybra Finance codebase is a promising project with the potential to be a major player in the DeFi ecosystem. However, the protocol is still under development, and it is important to monitor its development and to assess its risks.
  • The codebase uses a number of open-source libraries, which helps to ensure that the code is well-tested and secure.
  • The codebase is well-documented, which makes it easy to understand how the protocol works.
  • The protocol is designed to be interoperable with other DeFi protocols, which could help to increase its adoption.

I believe that the Lybra Finance codebase has the potential to be a valuable tool for the DeFi ecosystem. However, it is important to continue to monitor the project and to assess its risks as it continues to develop.

Here are some specific comments that I would make to the judge:

  • I would recommend that the judge approve the Lybra Finance codebase for further development. However, the judge should also monitor the project closely and be prepared to take action if any major security vulnerabilities are missed.
  • I would also recommend that the judge work with the Lybra Finance team to develop a plan for monitoring and assessing the risks of the protocol. This plan should include a process for identifying and mitigating risks, as well as a process for communicating risks to users.

I believe that the Lybra Finance codebase has the potential to be a valuable tool for the DeFi ecosystem. However, it is important to take a cautious approach to its development and to monitor its risks closely. I am confident that the Lybra Finance team is committed to building a secure and reliable protocol, and I look forward to seeing the project continue to develop.

Codebase quality analysis

  • Use a layered architecture. This will help to keep the codebase organized and scalable.
  • Use well-tested and secure open-source libraries. This will help to ensure that the code is well-tested and secure.
  • Document the codebase carefully. This will make it easier to understand how the protocol works and to debug any problems that may occur.
  • Design the protocol to be interoperable with other DeFi protocols. This will help to increase its adoption.
  • Monitor the protocol closely and assess its risks regularly. This will help to ensure that the protocol is secure and reliable.

Here are some specific recommendations for the Lybra Finance codebase:

  • The codebase could be divided into a number of layers, such as a presentation layer, a business logic layer, and a data layer. This would help to keep the codebase organized and scalable.
  • The codebase could be documented carefully using tools such as docstrings and comments. This would make it easier to understand how the protocol works and to debug any problems that may occur.
  • The protocol could be designed to be interoperable with other DeFi protocols, such as Uniswap and Compound. This would help to increase its adoption.
  • The Lybra Finance team could monitor the protocol closely and assess its risks regularly. This would help to ensure that the protocol is secure and reliable.

I believe that these architecture recommendations would help to make the Lybra Finance codebase more secure, reliable, and scalable. I hope this helps!

Centralization risks

Some potential centralization risks for the Lybra Finance:

Centralization risks can have a number of negative consequences. These include:

  • Reduced security: A centralized system is more vulnerable to attack than a decentralized system. This is because a small number of participants can have a disproportionate amount of control over the system.
  • Reduced censorship resistance: A centralized system is more susceptible to censorship than a decentralized system. This is because a small number of participants can control the flow of information on the network.
  • Reduced user control: A centralized system gives users less control over their own data and assets. This is because the users are reliant on the centralized entity to manage the system.

Here are some specific examples of how centralization risks could manifest in the Lybra Finance protocol:

  • If a small number of nodes control the consensus mechanism, they could potentially censor transactions or manipulate the price of eUSD.
  • If a small number of entities control the infrastructure of the network, they could potentially disrupt the network or prevent users from accessing their funds.
  • If a small number of participants control a large number of tokens, they could potentially manipulate the price of eUSD or vote on proposals that benefit them at the expense of other users.

It is important to be aware of centralization risks and to take steps to mitigate them. This will help to ensure that the Lybra Finance protocol remains decentralized and secure.

Mechanism review

The Lybra Finance protocol uses a number of mechanisms to ensure its security and stability. These mechanisms include:

  • Liquid staking derivatives: LSD/LST's are liquid staking derivatives that represent the staked value of an underlying asset. LSD/LST's can be used to mint eUSD, which is the stablecoin that is used in the Lybra Finance protocol.
  • Vaults: The Lybra Finance protocol includes a number of vaults that allow users to collateralize assets and mint eUSD or PeUSD. The vaults are designed to be secure and scalable.
  • Governance: The Lybra Finance protocol is governed by a DAO. The DAO allows users to participate in the decision-making process for the protocol.
  • Economic Model: The Lybra Finance protocol generates revenue through fees and staking rewards. The revenue is distributed to the DAO, which can use it to fund development and other initiatives.

The Lybra Finance protocol has a number of potential benefits. These benefits include:

  • Stability: The Lybra Finance protocol is backed by LSD/LST's, which are liquid staking derivatives that represent the staked value of an underlying asset. This gives the Lybra Finance protocol a higher degree of stability than other stablecoins that are not backed by assets.
  • Scalability: The Lybra Finance protocol includes a number of vaults that allow users to collateralize assets and mint eUSD or PeUSD. The vaults are designed to be secure and scalable. This gives the Lybra Finance protocol the potential to handle a large number of transactions.
  • Governance: The Lybra Finance protocol is governed by a DAO. This gives users the opportunity to participate in the decision-making process for the protocol. This could lead to a more decentralized and democratic system.
  • Economic Model: The Lybra Finance protocol generates revenue through fees and staking rewards. The revenue is distributed to the DAO, which can use it to fund development and other initiatives. This could help to ensure the long-term sustainability of the protocol.

However, the Lybra Finance protocol also has some potential risks. These risks include:

  • Centralization: The Lybra Finance protocol is still under development, and it is not yet clear how decentralized the protocol will be. If the protocol becomes too centralized, then it could be more vulnerable to attack.
  • Liquidity: The Lybra Finance protocol is still under development, and it is not yet clear how liquid the protocol will be. If the protocol is not liquid, then it could be difficult for users to trade eUSD or PeUSD.
  • Security: The Lybra Finance protocol is still under development, and it is not yet clear how secure the protocol will be. If the protocol is not secure, then it could be vulnerable to attack.

Overall, the Lybra Finance protocol has the potential to be a valuable tool for the DeFi ecosystem. However, it is important to be aware of the potential risks associated with the protocol before using it.

Systemic risks

  • Contagion: If the Lybra Finance protocol were to fail, it could have a contagion effect on other DeFi protocols. This is because the Lybra Finance protocol is interconnected with other DeFi protocols.
  • Black swan event: A black swan event is an event that is unexpected and has a significant impact. If a black swan event were to occur, it could have a negative impact on the Lybra Finance protocol.
  • Regulatory risk: The Lybra Finance protocol is still under development, and it is not yet clear how regulators will view the protocol. If regulators were to take a negative view of the protocol, it could have a negative impact on the protocol.
  • Market volatility: The Lybra Finance protocol is exposed to market volatility. This is because the value of eUSD is pegged to the USD. If the USD were to experience volatility, it could have a negative impact on the value of eUSD.

These are just some of the potential systemic risks for the Lybra Finance. Overall, the Lybra Finance protocol has the potential to be a valuable tool for the DeFi ecosystem.

Thank you.

Time spent:

168 hours

#0 - c4-sponsor

2023-07-27T08:40:22Z

LybraFinance marked the issue as sponsor confirmed

#1 - c4-judge

2023-07-28T17:08:33Z

0xean marked the issue as grade-a

#2 - c4-judge

2023-07-28T17:11:23Z

0xean marked the issue as satisfactory

AuditHub

A portfolio for auditors, a security profile for protocols, a hub for web3 security.

Built bymalatrax © 2024

Auditors

Browse

Contests

Browse

Get in touch

ContactTwitter