Energyfi

Smart Contract Audit Report

Audit Summary

Energyfi Audit Report Energyfi is building a yield farming platform and a decentralized exchange.

For this audit, we reviewed the following contracts:

Audit Findings

Please ensure trust in the team prior to investing as they have substantial control in the ecosystem.
Date: June 1st, 2022
Updated: July 7th, 2022 to reflect the MiniChefV2 contract's Mainnet address.
Updated: July 11th, 2022 to include the Migrator contract and resolve findings.

Finding #1 - MiniChefV2 - High (Resolved)

Description: The migrate() function can swap all LP tokens from any staking pool for an equivalent amount of tokens from the Migrator contract.
Risk/Impact: The owner can transfer all LP tokens from all pools to the Migrator contract using the migrate() function at any time.
Recommendation: The project team should properly set the Migrator address to their Migrator contract.
Resolution: The team has set the address of the Migrator contract; once set it cannot be changed.

Contracts Overview

MiniChefV2 Contract:
  • Users can stake various LP tokens into the MiniChefV2 contract in order to earn rewards.
  • The reward per share amount is calculated using the contract's reward per second rate (set by the owner) and the pool's allocation point percentage.
  • Staking rewards can be calculated and claimed by the user at any time.
  • There are no fees associated with making a deposit or withdraw from the contract.
  • Any user can trigger an emergency withdrawal, which will transfer all the user's deposited tokens to their wallet address, forfeiting any rewards.
  • The contract makes a call into the Energyfi Rewarder contract on all deposits, withdrawals, and reward claims. This contract was not provided in the scope of this audit, so we are unable to provide an assessment of the contract with regards to security.
  • A Migrator function is present, allowing the team to migrate all of users' staked funds to a new contract without restriction.

  • The owner can add new staking pools for LP tokens at any time. The team must exercise caution when adding tokens to avoid fee-on-transfer and ERC777-compliant tokens.
  • The owner can set the allocation points and Rewarder address for any existing pool at any time.
  • The owner can update the reward per second rate to any value at any time.
UniswapV2ERC20 Contract:
  • This contract contains the core functionality of the Energyfi LP token ($ELP-LP) maintained by the UniswapV2Pair contract.
  • The contract supports ERC-712 signed messages which users can use to grant an allowance via a signed message, allowing for gasless approvals.
  • The contract complies with the ERC-20 token standard.
UniswapV2Pair Contract:
  • This contract supports the core functionality of the Liquidity Pool token, which contains the logic behind LP minting, burning, and swapping between the assets in the liquidity pool.
  • Any user can use the mint function to mint an amount of LP tokens proportional to the number of tokens in the contract that are not accounted for in the reserves.
  • If the "Migrator" contract address from the UniswapV2Factory contract is the caller of the initial liquidity add, then the liquidity amount is set by the Migrator contract's desiredLiquidity() function. The Migrator contract was not provided in the scope of this audit, so we are unable to provide an assessment of the contract with regards to security.
  • Any user can use the swap function to transfer out an amount of the assets from the pool such that the new K value is at least as much as the current K value.
  • The swap function supports flash swaps which allows any user to use a contract to borrow any amount of any asset, as long as the borrowed amount of each asset is returned within the call.
  • A 0.3% fee is taken on an exchange between tokens and given as rewards to LP providers.
  • Any user can use the skim function to transfer out any excess tokens that are not accounted for in the reserve amounts.
  • Alternatively, any user can use the sync function to include any excess tokens in the reserve amounts so that they cannot be removed.
UniswapV2Factory Contract:
  • This contract is used to deploy new UniswapV2Pair contracts specifying two underlying token assets.
  • Any user can create a new pair at any time, as long as the pair has not been created yet.
  • Only one UniswapV2Pair contract can exist for any combination of two token assets.
  • The "FeeToSetter" address can set the FeeTo address, Migrator address, and FeeToSetter address to any addresses at any time.
UniswapV2Router02 Contract:
  • This contract is used to interact with any UniswapV2Pair liquidity pool contract created by the UniswapV2Factory contract.
  • Upon adding liquidity, the user specifies the desired minimum amount of each token in the pair to add to the liquidity pool; the user is minted UniswapV2Pair LP tokens representing their share of ownership of the liquidity pool.
  • Upon removing liquidity, the user specifies the desired minimum amount of each token asset to receive from the liquidity pool; the user's LP tokens are burnt in the process.
  • Liquidity removals support ERC-712 permits which allow the user to approve the Router to spend the user's LP tokens in a gasless manner.
  • Any user can use this contract to swap one token asset for any other supported asset along a user-specified path of token assets.

Audit Results

Vulnerability Category Notes Result
Arbitrary Jump/Storage Write N/A PASS
Centralization of Control
  • The team can utilize the migrate() function and swap all LP tokens in the staking pool from one DEX's liquidity pool to another.
  • The owner can update the reward per second rate in the MiniChefV2 contract to any value at any time.
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
Unbounded Loops N/A PASS
Unused Code N/A PASS
Overall Contract Safety   PASS

MiniChefV2 Contract

Smart Contract Audit - Inheritance

Smart Contract Audit - Graph


 ($) = payable function
 # = non-constant function
 
 Int = Internal
 Ext = External
 Pub = Public
 
 + [Int] IERC20 
    - [Ext] totalSupply
    - [Ext] balanceOf
    - [Ext] allowance
    - [Ext] approve #
    - [Ext] permit #

 + [Lib] BoringERC20 
    - [Int] safeSymbol
    - [Int] safeName
    - [Int] safeDecimals
    - [Int] safeTransfer #
    - [Int] safeTransferFrom #


 + [Int] IMasterChef 
    - [Ext] poolInfo
    - [Ext] totalAllocPoint
    - [Ext] deposit #

 + [Int] IRewarder 
    - [Ext] onEnergyFiReward #
    - [Ext] pendingTokens

 + [Lib] SignedSafeMath 
    - [Int] mul
    - [Int] div
    - [Int] sub
    - [Int] add
    - [Int] toUInt256

 + [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

 +  BoringOwnableData 

 +  BoringOwnable (BoringOwnableData)
    - [Pub]  #
    - [Pub] transferOwnership #
       - modifiers: onlyOwner
    - [Pub] claimOwnership #

 +  BaseBoringBatchable 
    - [Int] _getRevertMsg
    - [Ext] batch ($)

 +  BoringBatchable (BaseBoringBatchable)
    - [Pub] permitToken #

 + [Lib] BoringMath 
    - [Int] add
    - [Int] sub
    - [Int] mul
    - [Int] to128
    - [Int] to64
    - [Int] to32

 + [Lib] BoringMath128 
    - [Int] add
    - [Int] sub

 + [Lib] BoringMath64 
    - [Int] add
    - [Int] sub

 + [Lib] BoringMath32 
    - [Int] add
    - [Int] sub

 + [Int] IMigratorChef 
    - [Ext] migrate #

 +  MiniChefV2 (BoringOwnable, BoringBatchable)
    - [Pub]  #
    - [Pub] poolLength
    - [Pub] add #
       - modifiers: onlyOwner
    - [Pub] set #
       - modifiers: onlyOwner
    - [Pub] setEnergyFiPerSecond #
       - modifiers: onlyOwner
    - [Pub] setMigrator #
       - modifiers: onlyOwner
    - [Pub] migrate #
    - [Ext] pendingEnergyFi
    - [Ext] massUpdatePools #
    - [Pub] updatePool #
    - [Pub] deposit #
    - [Pub] withdraw #
    - [Pub] harvest #
    - [Pub] withdrawAndHarvest #
    - [Pub] emergencyWithdraw #

Migrator Contract

Smart Contract Audit - Inheritance

Smart Contract Audit - Graph


 ($) = payable function
 # = non-constant function
 
 Int = Internal
 Ext = External
 Pub = Public
 
 + [Int] IUniswapV2Pair 
    - [Ext] name
    - [Ext] symbol
    - [Ext] decimals
    - [Ext] totalSupply
    - [Ext] balanceOf
    - [Ext] allowance
    - [Ext] approve #
    - [Ext] transfer #
    - [Ext] transferFrom #
    - [Ext] DOMAIN_SEPARATOR
    - [Ext] PERMIT_TYPEHASH
    - [Ext] nonces
    - [Ext] permit #
    - [Ext] MINIMUM_LIQUIDITY
    - [Ext] factory
    - [Ext] token0
    - [Ext] token1
    - [Ext] getReserves
    - [Ext] price0CumulativeLast
    - [Ext] price1CumulativeLast
    - [Ext] kLast
    - [Ext] mint #
    - [Ext] burn #
    - [Ext] swap #
    - [Ext] skim #
    - [Ext] sync #
    - [Ext] initialize #

 + [Int] IUniswapV2Factory 
    - [Ext] feeTo
    - [Ext] feeToSetter
    - [Ext] getPair
    - [Ext] allPairs
    - [Ext] allPairsLength
    - [Ext] createPair #
    - [Ext] setFeeTo #
    - [Ext] setFeeToSetter #

 +  Migrator 
    - [Pub]  #
    - [Pub] migrate #

UniswapV2Factory, UniswapV2Pair, UniswapV2ERC20 Contracts

Smart Contract Audit - Inheritance

Smart Contract Audit - Graph


 ($) = payable function
 # = non-constant function
 
 Int = Internal
 Ext = External
 Pub = Public
 
 + [Int] IUniswapV2Factory 
    - [Ext] feeTo
    - [Ext] feeToSetter
    - [Ext] migrator
    - [Ext] getPair
    - [Ext] allPairs
    - [Ext] allPairsLength
    - [Ext] createPair #
    - [Ext] setFeeTo #
    - [Ext] setFeeToSetter #
    - [Ext] setMigrator #

 + [Lib] SafeMathUniswap 
    - [Int] add
    - [Int] sub
    - [Int] mul

 +  UniswapV2ERC20 
    - [Pub]  #
    - [Int] _mint #
    - [Int] _burn #
    - [Prv] _approve #
    - [Prv] _transfer #
    - [Ext] approve #
    - [Ext] transfer #
    - [Ext] transferFrom #
    - [Ext] permit #

 + [Lib] Math 
    - [Int] min
    - [Int] sqrt

 + [Lib] UQ112x112 
    - [Int] encode
    - [Int] uqdiv

 + [Int] IERC20Uniswap 
    - [Ext] name
    - [Ext] symbol
    - [Ext] decimals
    - [Ext] totalSupply
    - [Ext] balanceOf
    - [Ext] allowance
    - [Ext] approve #
    - [Ext] transfer #
    - [Ext] transferFrom #

 + [Int] IUniswapV2Callee 
    - [Ext] uniswapV2Call #

 + [Int] IMigrator 
    - [Ext] desiredLiquidity

 +  UniswapV2Pair (UniswapV2ERC20)
    - [Pub] getReserves
    - [Prv] _safeTransfer #
    - [Pub]  #
    - [Ext] initialize #
    - [Prv] _update #
    - [Prv] _mintFee #
    - [Ext] mint #
       - modifiers: lock
    - [Ext] burn #
       - modifiers: lock
    - [Ext] swap #
       - modifiers: lock
    - [Ext] skim #
       - modifiers: lock
    - [Ext] sync #
       - modifiers: lock

 +  UniswapV2Factory (IUniswapV2Factory)
    - [Pub]  #
    - [Ext] allPairsLength
    - [Ext] pairCodeHash
    - [Ext] createPair #
    - [Ext] setFeeTo #
    - [Ext] setMigrator #
    - [Ext] setFeeToSetter #

UniswapV2Router02 Contract

Smart Contract Audit - Inheritance

Smart Contract Audit - Graph


 ($) = payable function
 # = non-constant function
 
 Int = Internal
 Ext = External
 Pub = Public
 
 + [Int] IUniswapV2Pair 
    - [Ext] name
    - [Ext] symbol
    - [Ext] decimals
    - [Ext] totalSupply
    - [Ext] balanceOf
    - [Ext] allowance
    - [Ext] approve #
    - [Ext] transfer #
    - [Ext] transferFrom #
    - [Ext] DOMAIN_SEPARATOR
    - [Ext] PERMIT_TYPEHASH
    - [Ext] nonces
    - [Ext] permit #
    - [Ext] MINIMUM_LIQUIDITY
    - [Ext] factory
    - [Ext] token0
    - [Ext] token1
    - [Ext] getReserves
    - [Ext] price0CumulativeLast
    - [Ext] price1CumulativeLast
    - [Ext] kLast
    - [Ext] mint #
    - [Ext] burn #
    - [Ext] swap #
    - [Ext] skim #
    - [Ext] sync #
    - [Ext] initialize #

 + [Lib] SafeMathUniswap 
    - [Int] add
    - [Int] sub
    - [Int] mul

 + [Lib] UniswapV2Library 
    - [Int] sortTokens
    - [Int] pairFor
    - [Int] getReserves
    - [Int] quote
    - [Int] getAmountOut
    - [Int] getAmountIn
    - [Int] getAmountsOut
    - [Int] getAmountsIn

 + [Lib] TransferHelper 
    - [Int] safeApprove #
    - [Int] safeTransfer #
    - [Int] safeTransferFrom #
    - [Int] safeTransferETH #

 + [Int] IUniswapV2Router01 
    - [Ext] factory
    - [Ext] WETH
    - [Ext] addLiquidity #
    - [Ext] addLiquidityETH ($)
    - [Ext] removeLiquidity #
    - [Ext] removeLiquidityETH #
    - [Ext] removeLiquidityWithPermit #
    - [Ext] removeLiquidityETHWithPermit #
    - [Ext] swapExactTokensForTokens #
    - [Ext] swapTokensForExactTokens #
    - [Ext] swapExactETHForTokens ($)
    - [Ext] swapTokensForExactETH #
    - [Ext] swapExactTokensForETH #
    - [Ext] swapETHForExactTokens ($)
    - [Ext] quote
    - [Ext] getAmountOut
    - [Ext] getAmountIn
    - [Ext] getAmountsOut
    - [Ext] getAmountsIn

 + [Int] IUniswapV2Router02 (IUniswapV2Router01)
    - [Ext] removeLiquidityETHSupportingFeeOnTransferTokens #
    - [Ext] removeLiquidityETHWithPermitSupportingFeeOnTransferTokens #
    - [Ext] swapExactTokensForTokensSupportingFeeOnTransferTokens #
    - [Ext] swapExactETHForTokensSupportingFeeOnTransferTokens ($)
    - [Ext] swapExactTokensForETHSupportingFeeOnTransferTokens #

 + [Int] IUniswapV2Factory 
    - [Ext] feeTo
    - [Ext] feeToSetter
    - [Ext] migrator
    - [Ext] getPair
    - [Ext] allPairs
    - [Ext] allPairsLength
    - [Ext] createPair #
    - [Ext] setFeeTo #
    - [Ext] setFeeToSetter #
    - [Ext] setMigrator #

 + [Int] IERC20Uniswap 
    - [Ext] name
    - [Ext] symbol
    - [Ext] decimals
    - [Ext] totalSupply
    - [Ext] balanceOf
    - [Ext] allowance
    - [Ext] approve #
    - [Ext] transfer #
    - [Ext] transferFrom #

 + [Int] IWETH 
    - [Ext] deposit ($)
    - [Ext] transfer #
    - [Ext] withdraw #

 +  UniswapV2Router02 (IUniswapV2Router02)
    - [Pub]  #
    - [Ext]  ($)
    - [Int] _addLiquidity #
    - [Ext] addLiquidity #
       - modifiers: ensure
    - [Ext] addLiquidityETH ($)
       - modifiers: ensure
    - [Pub] removeLiquidity #
       - modifiers: ensure
    - [Pub] removeLiquidityETH #
       - modifiers: ensure
    - [Ext] removeLiquidityWithPermit #
    - [Ext] removeLiquidityETHWithPermit #
    - [Pub] removeLiquidityETHSupportingFeeOnTransferTokens #
       - modifiers: ensure
    - [Ext] removeLiquidityETHWithPermitSupportingFeeOnTransferTokens #
    - [Int] _swap #
    - [Ext] swapExactTokensForTokens #
       - modifiers: ensure
    - [Ext] swapTokensForExactTokens #
       - modifiers: ensure
    - [Ext] swapExactETHForTokens ($)
       - modifiers: ensure
    - [Ext] swapTokensForExactETH #
       - modifiers: ensure
    - [Ext] swapExactTokensForETH #
       - modifiers: ensure
    - [Ext] swapETHForExactTokens ($)
       - modifiers: ensure
    - [Int] _swapSupportingFeeOnTransferTokens #
    - [Ext] swapExactTokensForTokensSupportingFeeOnTransferTokens #
       - modifiers: ensure
    - [Ext] swapExactETHForTokensSupportingFeeOnTransferTokens ($)
       - modifiers: ensure
    - [Ext] swapExactTokensForETHSupportingFeeOnTransferTokens #
       - modifiers: ensure
    - [Pub] quote
    - [Pub] getAmountOut
    - [Pub] getAmountIn
    - [Pub] getAmountsOut
    - [Pub] getAmountsIn

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.