Circuit Protocol
Smart Contract Audit Report
Audit Summary
Circuit Protocol is releasing new Vault and Strategy contracts allowing users to aggregate their tokens for increased yields.
For this audit, we reviewed the project team's CircuitVault and StrategyLendleSupplyOnly contracts at commit f9baf7742fc3ebac46caecd0d0f7d7e9e4ddc8bb on the team's private GitHub repository.
Audit Findings
All findings have been resolved, though some centralized aspects are present.
Date: September 27th, 2023.
Updated: October 2nd, 2023 with changes from commit e4a89d6aa7a02a3610d4cd267e7f227193bfe54e to commit f9baf7742fc3ebac46caecd0d0f7d7e9e4ddc8bb.Finding #1 - StratLendleSupplyOnly - Low (Acknowledged)
Description: The contract performs various swaps with no minimum amount out when harvesting and allows users to trigger a harvest at any time.
Risk/Impact: A malicious user can front run a harvest causing the contract to swap tokens at a manipulated rate.
Recommendation: The team should implement a TWAP Oracle to prevent manipulation or allow users to specify a minimum amount out when harvesting.
Resolution: The team has acknowledged this possibility. They are comfortable with this as it would require a large amount of resources to successfully exploit. Additionally, they intend to enable harvests on deposit to prevent a large amount of pending rewards accruing.
Finding #2 - StratLendleSupplyOnly - Informational (Resolved)
Description: The contract inherits the GasFeeThrottler contract but never uses the contract's functionality.
Recommendation: The team should include the GasFeeThrottler functionality if intended or remove the inherited contract and the setShouldGasThrottle() function to save on contract size and deployment costs.
Resolution: The team has implemented the above recommendation.
Finding #3 - StratLendleSupplyOnly - Informational (Resolved)
Description: The contract includes the rewardToNativeFeeRoutes and nativeToWantFeeRoute mappings that are never used meaningfully in the contract.
Recommendation: The team should include the mappings in functionality if intended or remove them to save on contract size and deployment costs.
Resolution: The team has implemented the above recommendation.
Contracts Overview
CircuitVault Contract:
- The contracts utilize ReentrancyGuard to protect against reentrancy attacks in applicable functions.
- As the contracts are implemented with Solidity v0.8, they are safe from any possible overflows/underflows.
StrategyLendleSupplyOnly Contract:
- This contract allows users to deposit a specified asset in exchange for minted vault shares.
- Upon depositing, the asset is transferred from the user to this contract. Any assets in the contract are then deposited into the associated Strategy contract.
- When withdrawing, shares are burned from the user and the necessary funds are subsequently withdrawn from the Strategy contract.
- The owner may propose a new Strategy at any time.
- Once the contract's "approval delay" has passed, the owner may upgrade the strategy, which invokes the Strategy contract to upgrade itself to the newly proposed implementation.
- The owner may "retire" the current strategy at any time. This will withdraw all deposited assets from the Strategy to this contract.
- The owner may withdraw any non-want tokens at any time.
- This Strategy deposits "want" tokens into a LendingPool contract in order to earn rewards.
- Any address may call this contract's deposit function when the contract is not paused. This will deposit all of the want tokens into the LendingPool contract.
- The Vault contract may withdraw want tokens. If this contract does not have enough funds the needed funds will be withdrawn from the LendingPool.
- A withdrawal fee will be taken if the contract is not paused and the user that initiated the withdraw in the Vault contract is not the owner.
- Any address may trigger a "harvest" when the contract is not paused. They may optionally specify a separate address to harvest on behalf of.
- Harvesting will claim all of the contract's pending rewards from the IncentivesController and MultiFeeDistributor contracts.
- All collected rewards will be swapped to the "native" token where subsequently a fee is collected.
- Fees are determined in the FeeConfig contract. This contract is outside the scope of this audit so we are unable to give an assessment in regard to security.
- A call fee will be transferred to the user who initiated the harvest, unless another address was specified to receive the fee.
- A circuit fee will be taken and transferred to the circuit fee recipient address.
- A strategist fee will be taken and transferred to the Strategist address.
- All remaining native tokens after fees will be swapped for the want token and deposited into the LendingPool.
- A harvest may be performed upon each deposit if the harvest on deposit flag is enabled. This will additionally set the withdrawal fee to 0 when enabled.
- The owner may add and update the path which specified tokens are swapped to native and want tokens at any time.
- The Vault address may retire this contract as its Strategy at any time. This will withdraw all tokens and transfer them to the Vault.
- The owner or Keeper addresses may withdraw any non-want tokens when the contract is retired.
- The owner or Keeper addresses may panic at any time. This will withdraw all tokens from the Lending Pool and then pause the contract.
- The owner or Keeper addresses may pause and unpause the contract at any time.
- The owner or Keeper addresses may set the Strategy's Fee ID in the CircuitFeeConfig address at any time.
- The owner or Keeper addresses may set the withdrawal fee up to the withdrawal fee cap at any time.
- The owner or Keeper addresses may set the Vault address once after deployment.
- The owner or Keeper addresses may toggle harvesting upon deposit at any time.
- The owner or Keeper addresses may toggle whether the contract should gas throttle at any time.
- The owner may set the V2Router, V3Router, and Treasury addresses at any time.
- The owner may set the circuitFeeRecipient and circuitFeeConfig addresses at any time.
- The Keeper address may update its own address at any time.
- The Strategist address may update its own address at any time.
Audit Results
Vulnerability Category | Notes | Result |
---|---|---|
Arbitrary Jump/Storage Write | N/A | PASS |
Centralization of Control | The StrategyLendleSupplyOnly owner may pause the contract. | WARNING |
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 | It is potentially possible to front run StrategyLendleSupplyOnly harvests. | WARNING |
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 |
CircuitVault Contract
($) = payable function
# = non-constant function
Int = Internal
Ext = External
Pub = Public
+ [Int] IERC20
- [Ext] totalSupply
- [Ext] balanceOf
- [Ext] transfer #
- [Ext] allowance
- [Ext] approve #
- [Ext] transferFrom #
+ [Int] IERC20Metadata (IERC20)
- [Ext] name
- [Ext] symbol
- [Ext] decimals
+ Context
- [Int] _msgSender
- [Int] _msgData
+ ERC20 (Context, IERC20, IERC20Metadata)
- [Pub] Constructor #
- [Pub] name
- [Pub] symbol
- [Pub] decimals
- [Pub] totalSupply
- [Pub] balanceOf
- [Pub] transfer #
- [Pub] allowance
- [Pub] approve #
- [Pub] transferFrom #
- [Pub] increaseAllowance #
- [Pub] decreaseAllowance #
- [Int] _transfer #
- [Int] _mint #
- [Int] _burn #
- [Int] _approve #
- [Int] _spendAllowance #
- [Int] _beforeTokenTransfer #
- [Int] _afterTokenTransfer #
+ [Int] IERC20Permit
- [Ext] permit #
- [Ext] nonces
- [Ext] DOMAIN_SEPARATOR
+ [Lib] Address
- [Int] isContract
- [Int] sendValue #
- [Int] functionCall #
- [Int] functionCall #
- [Int] functionCallWithValue #
- [Int] functionCallWithValue #
- [Int] functionStaticCall
- [Int] functionStaticCall
- [Int] functionDelegateCall #
- [Int] functionDelegateCall #
- [Int] verifyCallResultFromTarget
- [Int] verifyCallResult
- [Prv] _revert
+ [Lib] SafeERC20
- [Int] safeTransfer #
- [Int] safeTransferFrom #
- [Int] safeApprove #
- [Int] safeIncreaseAllowance #
- [Int] safeDecreaseAllowance #
- [Int] forceApprove #
- [Int] safePermit #
- [Prv] _callOptionalReturn #
- [Prv] _callOptionalReturnBool #
+ Ownable (Context)
- [Pub] Constructor #
- [Pub] owner
- [Int] _checkOwner
- [Pub] renounceOwnership #
- modifiers: onlyOwner
- [Pub] transferOwnership #
- modifiers: onlyOwner
- [Int] _transferOwnership #
+ ReentrancyGuard
- [Pub] Constructor #
- [Prv] _nonReentrantBefore #
- [Prv] _nonReentrantAfter #
- [Int] _reentrancyGuardEntered
+ [Int] IStrategy
- [Ext] vault
- [Ext] want
- [Ext] beforeDeposit #
- [Ext] deposit #
- [Ext] withdraw #
- [Ext] balanceOf
- [Ext] balanceOfWant
- [Ext] balanceOfPool
- [Ext] harvest #
- [Ext] retireStrat #
- [Ext] panic #
- [Ext] pause #
- [Ext] unpause #
- [Ext] paused
- [Ext] unirouter
+ CircuitVault (ERC20, Ownable, ReentrancyGuard)
- [Pub] Constructor #
- modifiers: ERC20
- [Pub] want
- [Pub] transfer #
- [Pub] balance
- [Pub] available
- [Pub] getPricePerFullShare
- [Ext] depositAll #
- [Pub] deposit #
- modifiers: nonReentrant
- [Int] earn #
- [Ext] withdrawAll #
- [Pub] withdraw #
- [Pub] proposeStrat #
- modifiers: onlyOwner
- [Pub] upgradeStrat #
- modifiers: onlyOwner
- [Pub] retireStrat #
- modifiers: onlyOwner
- [Ext] inCaseTokensGetStuck #
- modifiers: onlyOwner
StrategyLendleSupplyOnly Contract
($) = payable function
# = non-constant function
Int = Internal
Ext = External
Pub = Public
+ [Int] IERC20
- [Ext] totalSupply
- [Ext] balanceOf
- [Ext] transfer #
- [Ext] allowance
- [Ext] approve #
- [Ext] transferFrom #
+ [Int] IERC20Metadata (IERC20)
- [Ext] name
- [Ext] symbol
- [Ext] decimals
+ Context
- [Int] _msgSender
- [Int] _msgData
+ ERC20 (Context, IERC20, IERC20Metadata)
- [Pub] Constructor #
- [Pub] name
- [Pub] symbol
- [Pub] decimals
- [Pub] totalSupply
- [Pub] balanceOf
- [Pub] transfer #
- [Pub] allowance
- [Pub] approve #
- [Pub] transferFrom #
- [Pub] increaseAllowance #
- [Pub] decreaseAllowance #
- [Int] _transfer #
- [Int] _mint #
- [Int] _burn #
- [Int] _approve #
- [Int] _spendAllowance #
- [Int] _beforeTokenTransfer #
- [Int] _afterTokenTransfer #
+ [Int] IERC20Permit
- [Ext] permit #
- [Ext] nonces
- [Ext] DOMAIN_SEPARATOR
+ [Lib] Address
- [Int] isContract
- [Int] sendValue #
- [Int] functionCall #
- [Int] functionCall #
- [Int] functionCallWithValue #
- [Int] functionCallWithValue #
- [Int] functionStaticCall
- [Int] functionStaticCall
- [Int] functionDelegateCall #
- [Int] functionDelegateCall #
- [Int] verifyCallResultFromTarget
- [Int] verifyCallResult
- [Prv] _revert
+ [Lib] SafeERC20
- [Int] safeTransfer #
- [Int] safeTransferFrom #
- [Int] safeApprove #
- [Int] safeIncreaseAllowance #
- [Int] safeDecreaseAllowance #
- [Int] forceApprove #
- [Int] safePermit #
- [Prv] _callOptionalReturn #
- [Prv] _callOptionalReturnBool #
+ [Int] IERC20Extended
- [Ext] symbol
- [Ext] decimals
+ [Int] IUniswapRouterETH
- [Ext] factory
- [Ext] WETH
- [Ext] addLiquidity #
- [Ext] addLiquidityETH ($)
- [Ext] removeLiquidity #
- [Ext] removeLiquidityETH #
- [Ext] removeLiquidityWithPermit #
- [Ext] removeLiquidityETHWithPermit #
- [Ext] removeLiquidityETHSupportingFeeOnTransferTokens #
- [Ext] removeLiquidityETHWithPermitSupportingFeeOnTransferTokens #
- [Ext] swapExactTokensForTokensSupportingFeeOnTransferTokens #
- [Ext] swapExactETHForTokensSupportingFeeOnTransferTokens ($)
- [Ext] swapExactTokensForETHSupportingFeeOnTransferTokens #
- [Ext] swapExactTokensForTokens #
- [Ext] swapExactETHForTokens ($)
- [Ext] swapTokensForExactETH #
- [Ext] swapExactTokensForETH #
- [Ext] swapETHForExactTokens ($)
- [Ext] quote
- [Ext] getAmountOut
- [Ext] getAmountIn
- [Ext] getAmountsOut
- [Ext] getAmountsIn
+ [Int] IMultiFeeDistributer
- [Ext] claimableRewards
- [Ext] exit #
+ [Int] ILendingPool
- [Ext] deposit #
- [Ext] borrow #
- [Ext] repay #
- [Ext] withdraw #
- [Ext] getUserAccountData
- [Ext] setUserEMode #
- [Ext] getUserEMode
- [Ext] getEModeCategoryData
+ [Int] IDataProvider
- [Ext] getReserveTokensAddresses
- [Ext] getUserReserveData
+ [Int] IChefIncentivesController
- [Ext] claimableReward
- [Ext] claim #
+ [Lib] BytesLib
- [Int] concat
- [Int] concatStorage #
- [Int] slice
- [Int] toAddress
- [Int] toUint8
- [Int] toUint16
- [Int] toUint24
- [Int] toUint32
- [Int] toUint64
- [Int] toUint96
- [Int] toUint128
- [Int] toUint256
- [Int] toBytes32
- [Int] equal
- [Int] equalStorage
+ [Lib] PancakeV3Path
- [Int] hasMultiplePools
- [Int] numPools
- [Int] decodeFirstPool
- [Int] getFirstPool
- [Int] skipToken
+ [Int] IV3SwapRouter
- [Ext] exactInputSingle ($)
- [Ext] exactInput ($)
- [Ext] exactOutputSingle ($)
- [Ext] exactOutput ($)
+ [Lib] PancakeV3Utils
- [Int] swap #
- [Int] pathToRoute
- [Int] routeToPath
+ [Int] IGasPrice
- [Ext] maxGasPrice #
+ GasFeeThrottler
+ [Lib] StringUtils
- [Int] concat
+ Ownable (Context)
- [Pub] Constructor #
- [Pub] owner
- [Int] _checkOwner
- [Pub] renounceOwnership #
- modifiers: onlyOwner
- [Pub] transferOwnership #
- modifiers: onlyOwner
- [Int] _transferOwnership #
+ Pausable (Context)
- [Pub] Constructor #
- [Pub] paused
- [Int] _requireNotPaused
- [Int] _requirePaused
- [Int] _pause #
- modifiers: whenNotPaused
- [Int] _unpause #
- modifiers: whenPaused
+ [Int] IFeeConfig
- [Ext] getFees
- [Ext] stratFeeId
- [Ext] setStratFeeId #
+ StratFeeManager (Ownable, Pausable)
- [Pub] Constructor #
- [Int] getFees
- [Ext] getAllFees
- [Ext] getStratFeeId
- [Ext] setStratFeeId #
- modifiers: onlyManager
- [Pub] setWithdrawalFee #
- modifiers: onlyManager
- [Ext] setVault #
- modifiers: onlyManager
- [Ext] setV2Router #
- modifiers: onlyOwner
- [Ext] setV3Router #
- modifiers: onlyOwner
- [Ext] setKeeper #
- [Ext] setTreasury #
- modifiers: onlyOwner
- [Ext] setStrategist #
- [Ext] setCircuitFeeRecipient #
- modifiers: onlyOwner
- [Ext] setCircuitFeeConfig #
- modifiers: onlyOwner
- [Pub] depositFee
- [Pub] withdrawFee
- [Ext] beforeDeposit #
+ StrategyLendleSupplyOnly (StratFeeManager, GasFeeThrottler)
- [Pub] Constructor #
- modifiers: StratFeeManager
- [Pub] deposit #
- modifiers: whenNotPaused
- [Ext] withdraw #
- [Ext] beforeDeposit #
- [Ext] harvest #
- [Ext] harvest #
- [Ext] managerHarvest #
- modifiers: onlyManager
- [Int] _harvest #
- modifiers: whenNotPaused
- [Int] swapOutputToNative #
- [Int] swapRewardsToNative #
- [Int] chargeFees #
- [Int] swapNativeToWant #
- [Pub] userReserves
- [Pub] userAccountData
- [Pub] balanceOf
- [Pub] balanceOfWant
- [Pub] balanceOfPool
- [Pub] pendingRewards
- [Pub] callReward
- [Ext] setHarvestOnDeposit #
- modifiers: onlyManager
- [Ext] setShouldGasThrottle #
- modifiers: onlyManager
- [Ext] retireStrat #
- [Ext] removeERC20 #
- modifiers: onlyManager
- [Pub] panic #
- modifiers: onlyManager
- [Pub] pause #
- modifiers: onlyManager
- [Ext] unpause #
- modifiers: onlyManager
- [Int] _giveAllowances #
- [Int] _removeAllowances #
- [Ext] addRewardToNativePath #
- modifiers: onlyOwner
- [Ext] removeRewardToNativePath #
- modifiers: onlyOwner
- [Pub] outputToNative
- [Pub] setNativeToWantPath #
- modifiers: onlyOwner
- [Pub] nativeToWant
- [Pub] setRewardToNativePaths #
- modifiers: onlyOwner
- [Pub] rewardToNativeRoutes
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.