Lybra

Smart Contract Audit Report

Audit Summary

Lybra Audit Report Lybra is building a new lending platform allowing users to deposit ETH/stETH collateral in order to receive eUSD.

For this audit, we reviewed the project team's Lybra contract at 0x97de57ec338ab5d51557da3434828c5dbfada371 on the Ethereum Mainnet.

Audit Findings

Low findings were identified and the team should consider resolving these issues.
Date: May 1st, 2023.

Finding #1 - Lybra - Low

Description: Although the setRedemptionFee() function intends to allow the team to set the Redemption fee up to 500 (5%), the newFee parameter is of data type uint8 which is capped at a maximum value of 255.
function setRedemptionFee(uint8 newFee) external onlyGov {
	require(newFee <= 500, "Max Redemption Fee is 5%");
	redemptionFee = newFee;
	emit RedemptionFeeChanged(newFee);
}
Risk/Impact: The team can only set Redemption fee up to 2.55%.
Recommendation: The team should modify the newFee parameter to be of data type uint256.
Resolution: The team has not yet addressed this issue.

Finding #2 - Lybra - Informational

Description: The badCollateralRate and year state variables cannot be modified but are not declared constant.
Recommendation: The above state variables should be declared constant for additional gas savings on each reference.

Contract Overview

  • Any address may initiate an ETH deposit with the option of depositing on behalf of another address.
  • The caller must provide at least 1 ETH and may specify a number of eUSD tokens to mint.
  • The provided ETH is converted to stETH and a number of shares are calculated in the Lido contract based on the amount of provided ETH. The returned number of shares must be greater than zero. The Lido contract was not included in the scope of this audit, so we are unable to provide an assessment with regards to its security or functionality.
  • A number of shares are minted to the user based on the desired eUSD mint amount and total shares for all users in proportion to the total minted eUSD.
  • The user's borrowed eUSD amount is increased by the specified mint amount.
  • Any address may initiate a stETH deposit with the option of depositing on behalf of another address.
  • The caller must provide at least 1 stETH and may specify a number of eUSD tokens to mint.
  • The provided stETH is transferred from the caller to the contract. The caller must grant this contract a sufficient stETH allowance in order for the deposit to successfully occur.
  • A number of shares are calculated based on the desired eUSD mint amount and are minted to the user.
  • The user's borrowed eUSD amount is increased by the specified mint amount.
  • Any user can initiate a stETH withdrawal with the option of withdrawing on behalf of another address.
  • The caller cannot withdraw more stETH than their total ETH/stETH deposit amount.
  • The withdrawn stETH is transferred from the contract to the specified destination address.
  • Any user can specify an amount of eUSD to mint with the option of minting on behalf of another address at any time.
  • The calculated number of shares are allocated to the destination address and the total amount borrowed is increased for the caller by the number of minted tokens.
  • The caller's full borrowed amount in proportion to the eUSD total supply cannot exceed 10% if the total supply is currently above 10 million tokens.
  • The user's deposited stETH to borrowed eUSD collateral rate must remain above the contract's 160% safe collateral rate after all deposits, withdrawals, and mints.
  • Any user can specify an amount of eUSD to repay with the option of repaying on behalf of another address at any time.
  • The specified address's total borrowed amount is decreased by the specified amount and the calculated number of shares are burned on behalf of the caller.
  • Any user can toggle whether or not they are a redemption provider. The user's rewards are "refreshed" in the eslbrMinter contract during this process. The eslbrMinter contract was not included in the scope of this audit, so we are unable to provide an assessment with regards to its security or functionality.
  • Any user can initiate a "rigid redemption" by specifying an amount of eUSD to exchange for stETH and specifying a provider address.
  • The provider address must be a redemption provider and the specified amount of eUSD must not exceed their total borrowed amount.
  • The provider's current collateral rate must be at least 100%.
  • The provider's total borrowed amount is decreased by the specified eUSD amount and the caller's calculated number of shares are burned.
  • The caller is sent a stETH from the contract equivalent to the provided eUSD amount.
  • A redemption fee (set by the team) is deducted from the withdrawn amount and remains in the contract.
  • Any user can initiate a liquidation by specifying a provider address, a borrower address, and an ETH amount to be liquidated.
  • The collateral rate for the borrower cannot currently exceed 150%.
  • The amount of ETH to be liquidated must not exceed 50% of the borrower's total deposited ETH.
  • The provider must have granted this contract a sufficient eUSD allowance in order for the transaction to successfully occur.
  • The borrower address's total borrow amount is decreased by the equivalent eUSD amount of liquidated ETH and the provider's calculated number of shares are burned.
  • The borrower's total deposited ETH is decreased by 110% of the liquidated ETH amount.
  • The full liquidated amount of stETH is transferred to the caller if the provider and caller are the same address.
  • If the provider and caller are not the same address, a percentage of stETH is sent to the caller as a reward based on the keeper rate set by the team. The remaining stETH is sent to the provider address.
  • Any user can initiate a super-liquidation by specifying a provider address, a borrower address, and an ETH amount to be liquidated.
  • The overall collateral rate of the contract must currently be below 150%.
  • The current collateral rate of the borrower must currently be below 125%.
  • The amount of ETH to be liquidated must not exceed the borrower's total ETH deposited.
  • The borrower's total borrow amount is decreased by the equivalent eUSD amount of liquidated ETH and the caller's calculated number of shares are burned.
  • The provider must have granted this contract a sufficient eUSD allowance in order for the transaction to successfully occur.
  • The borrower's total deposited ETH is decreased by the liquidated ETH amount.
  • The full liquidated amount of stETH is transferred to the caller if the provider and caller are the same address.
  • If the provider and caller are not the same address and the borrower's collateral rate is above the contract's threshold, a percentage of stETH is sent to the caller as a reward based on the keeper rate set by the team.
  • The remaining stETH is transferred to the provider address.
  • Any user can trigger an excess income distribution transaction by specifying an amount of eUSD to be paid out.
  • The ETH equivalent of the specified eUSD amount must not exceed the difference between the contract's stETH balance and the total amount of deposited ETH/stETH.
  • The contract's total income is calculated by adding the contract's stored fees with any new fees generated since the last report.
  • If the specified eUSD amount exceeds the total income, the total income amount is transferred to the Service fee pool address, and the corresponding shares are burned on behalf of the caller.
  • If the specified eUSD amount does not exceed the total income, the specified eUSD amount is transferred to the Service fee pool address.
  • The ETH equivalent of the specified eUSD amount is transferred from the contract to the caller.
  • A "notify reward amount" transaction is executed in the Service fee pool contract. The Service fee pool contract was not included in the scope of this audit, so we are unable to provide an assessment with regards to its security or functionality.
  • The Gov address can set the mint fee APY to any percentage up to 1.5% at any time.
  • The Gov address can set the safe collateral rate to 160% or greater at any time.
  • The Gov address can set the keeper rate to any percentage up to 5% at any time.
  • The Gov address can set the redemption fee to any percentage up to 2.55% at any time.
  • The Gov address can update the Service fee pool and Eslbr-Minter addresses at any time.

Audit Results

Vulnerability Category Notes Result
Arbitrary Jump/Storage Write N/A PASS
Centralization of Control N/A PASS
Compiler Issues N/A PASS
Delegate Call to Untrusted Contract N/A PASS
Dependence on Predictable Variables N/A PASS
Ether/Token Theft N/A PASS
Flash Loans N/A PASS
Front Running N/A PASS
Improper Events N/A PASS
Improper Authorization Scheme N/A PASS
Integer Over/Underflow N/A PASS
Logical Issues N/A PASS
Oracle Issues N/A PASS
Outdated Compiler Version N/A PASS
Race Conditions N/A PASS
Reentrancy N/A PASS
Signature Issues N/A PASS
Sybil Attack N/A PASS
Unbounded Loops N/A PASS
Unused Code N/A PASS
Overall Contract Safety   PASS

Inheritance Chart

Smart Contract Audit - Inheritance

Function Graph

Smart Contract Audit - Graph

Functions Overview


 ($) = payable function
 # = non-constant function
 
 Int = Internal
 Ext = External
 Pub = Public

 + [Lib] SafeMath 
    - [Int] tryAdd
    - [Int] trySub
    - [Int] tryMul
    - [Int] tryDiv
    - [Int] tryMod
    - [Int] add
    - [Int] sub
    - [Int] mul
    - [Int] div
    - [Int] mod
    - [Int] sub
    - [Int] div
    - [Int] mod

 + [Int] IERC20 
    - [Ext] totalSupply
    - [Ext] balanceOf
    - [Ext] transfer #
    - [Ext] allowance
    - [Ext] approve #
    - [Ext] transferFrom #

 +  EUSD (IERC20)
    - [Pub] name
    - [Pub] symbol
    - [Pub] decimals
    - [Pub] totalSupply
    - [Pub] balanceOf
    - [Pub] transfer #
    - [Pub] allowance
    - [Pub] approve #
    - [Pub] transferFrom #
    - [Pub] increaseAllowance #
    - [Pub] decreaseAllowance #
    - [Pub] getTotalShares
    - [Pub] sharesOf
    - [Pub] getSharesByMintedEUSD
    - [Pub] getMintedEUSDByShares
    - [Pub] transferShares #
    - [Int] _getTotalMintedEUSD
    - [Int] _transfer #
    - [Int] _approve #
    - [Int] _getTotalShares
    - [Int] _sharesOf
    - [Int] _transferShares #
    - [Int] _mintShares #
    - [Int] _burnShares #

 +  Governable 
    - [Ext] setGov #
       - modifiers: onlyGov

 + [Int] Ilido 
    - [Ext] submit ($)
    - [Ext] withdraw #
    - [Ext] balanceOf
    - [Ext] transfer #
    - [Ext] transferFrom #

 + [Int] LbrStakingPool 
    - [Ext] notifyRewardAmount #

 + [Int] esLBRMinter 
    - [Ext] refreshReward #

 + [Int] IPriceFeed 
    - [Ext] fetchPrice #

 +  Lybra (EUSD, Governable)
    - [Pub]  #
    - [Ext] setBorrowApy #
       - modifiers: onlyGov
    - [Ext] setSafeCollateralRate #
       - modifiers: onlyGov
    - [Ext] setKeeperRate #
       - modifiers: onlyGov
    - [Ext] setRedemptionFee #
       - modifiers: onlyGov
    - [Ext] setLbrStakingPool #
       - modifiers: onlyGov
    - [Ext] setESLBRMinter #
       - modifiers: onlyGov
    - [Ext] becomeRedemptionProvider #
    - [Ext] depositEtherToMint ($)
    - [Ext] depositStETHToMint #
    - [Ext] withdraw #
    - [Pub] mint #
    - [Ext] burn #
    - [Ext] liquidation #
    - [Ext] superLiquidation #
    - [Ext] excessIncomeDistribution #
    - [Ext] rigidRedemption #
    - [Int] _mintEUSD #
    - [Int] _repay #
    - [Int] _saveReport #
    - [Int] _checkHealth #
    - [Int] _etherPrice #
    - [Int] _newFee
    - [Int] _getTotalMintedEUSD
    - [Ext] getBorrowedOf
    - [Ext] isRedemptionProvider

About SourceHat

SourceHat has quickly grown to have one of the most experienced and well-equipped smart contract auditing teams in the industry. Our team has conducted 1800+ solidity smart contract audits covering all major project types and protocols, securing a total of over $50 billion U.S. dollars in on-chain value!
Our firm is well-reputed in the community and is trusted as a top smart contract auditing company for the review of solidity code, no matter how complex. Our team of experienced solidity smart contract auditors performs audits for tokens, NFTs, crowdsales, marketplaces, gambling games, financial protocols, and more!

Contact us today to get a free quote for a smart contract audit of your project!

What is a SourceHat Audit?

Typically, a smart contract audit is a comprehensive review process designed to discover logical errors, security vulnerabilities, and optimization opportunities within code. A SourceHat Audit takes this a step further by verifying economic logic to ensure the stability of smart contracts and highlighting privileged functionality to create a report that is easy to understand for developers and community members alike.

How Do I Interpret the Findings?

Each of our Findings will be labeled with a Severity level. We always recommend the team resolve High, Medium, and Low severity findings prior to deploying the code to the mainnet. Here is a breakdown on what each Severity level means for the project:

  • High severity indicates that the issue puts a large number of users' funds at risk and has a high probability of exploitation, or the smart contract contains serious logical issues which can prevent the code from operating as intended.
  • Medium severity issues are those which place at least some users' funds at risk and has a medium to high probability of exploitation.
  • Low severity issues have a relatively minor risk association; these issues have a low probability of occurring or may have a minimal impact.
  • Informational issues pose no immediate risk, but inform the project team of opportunities for gas optimizations and following smart contract security best practices.