CollarSwap

Smart Contract Audit Report

Audit Summary

CollarSwap Audit Report CollarSwap is building a new Decentralized Exchange and a platform where users can stake tokens and earn rewards.

For this audit, we reviewed the following contracts on the Ethereum Mainnet:

Audit Findings

All findings have been resolved.
Date: October 7th, 2022.
Updated: November 29th, 2022 to include the project team's CollarFlexStake contract.
Updated: February 3rd, 2023 to reflect the CollarFlexStake contract's Mainnet address.

Finding #1 - CollarStake - High (Resolved)

Description: The owner can call the emergenecy() function and withdraw any staked tokens from the contract.
function emergenecy(address token, address to, uint256 amount)external onlyOwner{
   if(token == address(0x0)){
         require(payable(to).send(amount),"transaction failed");
   } else  {
         IERC20(token).transfer(to, amount);
   }
   emit emergencySafe(to, token, amount);
}
Risk/Impact: The team can withdraw any user's staked tokens at any time.
Recommendation: The contract should include logic that disallows the owner from being able to withdraw tokens that have been assigned as staking tokens.
Resolution: The team has removed the above function from the contract.

Finding #2 - CollarStake - Medium (Resolved)

Description: Although the stake(), unstake(), updateMaxTokenStake(), updatePoolAPYpercentage(), updateCoolDownTime(), updateCollarToken(), poolCreation(), and poolStatus() functions use the whenNotPaused modifier, a function does not exist to pause/unpause the contract.
Risk/Impact: The contract can never be paused by the team.
Recommendation: The team should add a function that allows them to pause/unpause the contract or should remove the modifier from the above functions for additional gas savings on each call.
Resolution: The team has added a pause() and unPause() function to the contract.

Contracts Overview

CollarSwapERC20 Contract:
  • This contract contains the core functionality of the CollarSwap LP token ($Collar-LP) maintained by the CollarSwapPair contract.
  • The contract supports ERC-712 signed messages which users can use to grant allowances via a signed message, allowing for gasless approvals.
  • The contract complies with the ERC-20 standard.
CollarSwapPair 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.
  • Anyone 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.
  • Anyone can use the burn function to burn any LP tokens in the contract and receive an amount of asset tokens proportional to the represented value of the LP tokens.
  • Anyone 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 anyone 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.
  • There is a fee taken on all swaps; the fee remains in the liquidity pool and is proportionally allocated among all LP token holders.
  • Anyone can use the skim function to transfer out any excess tokens that are not accounted for in the reserve amounts.
  • Alternatively, anyone can use the sync function to include any excess tokens in the reserve amounts so that they cannot be removed.
CollarSwapFactory Contract:
  • This contract is used to deploy new CollarSwapPair contracts specifying two underlying token assets.
  • Anyone can create any pair at any time, as long as the pair has not been created yet.
  • Only one CollarSwapPair contract can exist for any combination of two token assets.
  • The "FeeTo Setter" address can set the "FeeTo" and the "FeeTo Setter" addresses to any address at any time.
CollarSwapRouter Contract:
  • This contract is used to interact with any CollarSwapPair liquidity pool contract created by the CollarSwapFactory 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 CollarSwapPair 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.
  • Liquidity adds and removals support fee-on-transfer tokens.
  • Anyone can use this contract to swap one token asset for any other supported asset along a user-specified path of token assets.
CollarStake Contract:
  • Users can stake tokens into various pools set by the team by specifying a number of tokens and a number of staking days.
  • The specified number of tokens must not exceed the stake limit set by the team.
  • The reward end time for each stake will be set to the number of specified days.
  • Users can claim rewards after staking at any time. The number of tokens sent to the user is calculated based on the user's total number of staked tokens, the difference between the reward end time and the user's last claim, and the APY percentage assigned to the pool.
  • Users can unstake from each pool once the reward end time assigned to the stake has passed. Rewards are automatically claimed upon unstaking.
  • After a user successfully unstakes, they can withdraw their staked amount once the cool-down period of the contract has passed.
  • The team must exercise caution when assigning the staking token to avoid using fee-on-transfer tokens. If a fee-on-transfer token is assigned, the team must ensure that the proper addresses are excluded from fees.
  • The team must also exercise caution when assigning the staking token and the reward token to avoid using ERC-777 compliant tokens.
  • The owner can use this contract to transfer reward tokens from their wallet to the contract at any time.
  • The owner can pause/unpause the contract at any time which disables all staking, unstaking, withdrawing, and claiming.
  • The owner can activate/deactivate any created pool at any time.
  • The owner can update the reward token address at any time.
  • The owner can update the cool-down period to any value at any time.
  • The owner can update the APY percentage assigned to each pool to any value at any time.
  • The owner can set the maximum stake limit to any value at any time.
CollarFlexStake contract:
  • Users can stake tokens into various pools set by the team by specifying a number of tokens.
  • The specified number of tokens must not exceed the stake limit set by the team.
  • The reward end time for each stake will automatically be set to 1 year.
  • Users can claim rewards after staking at any time. The number of tokens sent to the user is calculated based on the user's total number of staked tokens, the difference between the reward end time and the user's last claim, and the APY percentage assigned to the pool.
  • Users can withdraw their staked tokens at any time. Rewards are automatically claimed on withdrawals.
  • The team must exercise caution when assigning the staking token to avoid using fee-on-transfer tokens. If a fee-on-transfer token is assigned, the team must ensure that the proper addresses are excluded from fees.
  • The team must also exercise caution when assigning the staking token and the reward token to avoid using ERC-777 compliant tokens.
  • The owner can use this contract to transfer reward tokens from their wallet to the contract at any time.
  • The owner can pause/unpause the contract at any time which disables all staking, withdrawing, and claiming.
  • The owner can activate/deactivate any created pool at any time.
  • The owner can update the reward token address at any time.
  • The owner can update the cool-down period to any value at any time.
  • The owner can update the APY percentage assigned to each pool to any value at any time.
  • The owner can set the maximum stake limit to any value 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
Unbounded Loops N/A PASS
Unused Code N/A PASS
Overall Contract Safety   PASS

CollarSwapERC20, CollarSwapPair, and CollarSwapFactory Contracts

Smart Contract Audit - Inheritance

Smart Contract Audit - Graph


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

 + [Int] ICollarSwapPair 
    - [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] ICollarSwapERC20 
    - [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 #

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

 +  CollarSwapERC20 (ICollarSwapERC20)
    - [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] IERC20 
    - [Ext] name
    - [Ext] symbol
    - [Ext] decimals
    - [Ext] totalSupply
    - [Ext] balanceOf
    - [Ext] allowance
    - [Ext] approve #
    - [Ext] transfer #
    - [Ext] transferFrom #

 + [Int] ICollarSwapCallee 
    - [Ext] CollarSwapCall #

 +  CollarSwapPair (ICollarSwapPair, CollarSwapERC20)
    - [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

 +  CollarSwapFactory (ICollarSwapFactory)
    - [Pub]  #
    - [Ext] allPairsLength
    - [Ext] createPair #
    - [Ext] setFeeTo #
    - [Ext] setFeeToSetter #

CollarSwapRouter Contract

Smart Contract Audit - Inheritance

Smart Contract Audit - Graph


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

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

 + [Int] ICollarSwapRouter01 
    - [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] ICollarSwapRouter02 (ICollarSwapRouter01)
    - [Ext] removeLiquidityETHSupportingFeeOnTransferTokens #
    - [Ext] removeLiquidityETHWithPermitSupportingFeeOnTransferTokens #
    - [Ext] swapExactTokensForTokensSupportingFeeOnTransferTokens #
    - [Ext] swapExactETHForTokensSupportingFeeOnTransferTokens ($)
    - [Ext] swapExactTokensForETHSupportingFeeOnTransferTokens #

 + [Int] ICollarSwapPair 
    - [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] SafeMath 
    - [Int] add
    - [Int] sub
    - [Int] mul

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

 + [Int] IERC20 
    - [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 #

 +  CollarSwapRouter (ICollarSwapRouter02)
    - [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

CollarStake 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] decimals
    - [Ext] symbol
    - [Ext] name
    - [Ext] getOwner
    - [Ext] balanceOf
    - [Ext] transfer #
    - [Ext] allowance
    - [Ext] approve #
    - [Ext] transferFrom #

 +  Context 
    - [Pub]  #
    - [Int] _msgSender
    - [Int] _msgData

 +  Ownable (Context)
    - [Pub]  #
    - [Pub] owner
    - [Pub] transferOwnership #
       - modifiers: onlyOwner
    - [Int] _transferOwnership #

 +  ReentrancyGuard 
    - [Pub]  #

 +  Pausable (Context)
    - [Pub]  #
    - [Pub] paused
    - [Int] _pause #
       - modifiers: whenNotPaused
    - [Int] _unpause #
       - modifiers: whenPaused

 +  CollarStake (Ownable, ReentrancyGuard, Pausable)
    - [Pub]  #
    - [Ext] viewUserDetails
    - [Ext] veiwPools
    - [Ext] userStakeIDs
    - [Ext] updateMaxTokenStake #
       - modifiers: onlyOwner,whenNotPaused
    - [Ext] pause #
       - modifiers: onlyOwner   
    - [Ext] unPause #
       - modifiers: onlyOwner        
    - [Ext] updatePoolAPYpercentage #
       - modifiers: onlyOwner,whenNotPaused
    - [Ext] updateCoolDownTime #
       - modifiers: onlyOwner,whenNotPaused
    - [Ext] updateCollarToken #
       - modifiers: onlyOwner,whenNotPaused
    - [Ext] poolCreation #
       - modifiers: onlyOwner,whenNotPaused
    - [Ext] poolStatus #
       - modifiers: onlyOwner,whenNotPaused
    - [Ext] stake #
       - modifiers: nonReentrant,whenNotPaused
    - [Ext] unstake #
       - modifiers: nonReentrant,whenNotPaused
    - [Ext] withdraw #
    - [Pub] claimReward #
    - [Pub] pendingReward
    - [Ext] adminDeposit #
       - modifiers: onlyOwner

CollarFlexStake 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] decimals
    - [Ext] symbol
    - [Ext] name
    - [Ext] getOwner
    - [Ext] balanceOf
    - [Ext] transfer #
    - [Ext] allowance
    - [Ext] approve #
    - [Ext] transferFrom #

 +  Context 
    - [Pub]  #
    - [Int] _msgSender
    - [Int] _msgData

 +  Ownable (Context)
    - [Pub]  #
    - [Pub] owner
    - [Pub] transferOwnership #
       - modifiers: onlyOwner
    - [Int] _transferOwnership #

 +  ReentrancyGuard 
    - [Pub]  #

 +  Pausable (Context)
    - [Pub]  #
    - [Pub] paused
    - [Int] _pause #
       - modifiers: whenNotPaused
    - [Int] _unpause #
       - modifiers: whenPaused

 +  CollarFlexStake (Ownable, ReentrancyGuard, Pausable)
    - [Pub]  #
    - [Ext] viewUserDetails
    - [Ext] veiwPools
    - [Ext] userStakeIDs
    - [Ext] updateMaxTokenStake #
       - modifiers: onlyOwner
    - [Ext] pause #
       - modifiers: onlyOwner
    - [Ext] unPause #
       - modifiers: onlyOwner
    - [Ext] updatePoolAPYpercentage #
       - modifiers: onlyOwner
    - [Ext] updateCollarToken #
       - modifiers: onlyOwner
    - [Ext] poolCreation #
       - modifiers: onlyOwner
    - [Ext] poolStatus #
       - modifiers: onlyOwner
    - [Ext] stake #
       - modifiers: nonReentrant,whenNotPaused
    - [Ext] withdraw #
       - modifiers: nonReentrant,whenNotPaused
    - [Pub] claimReward #
       - modifiers: whenNotPaused
    - [Pub] pendingReward
    - [Ext] adminDeposit #
       - modifiers: onlyOwner

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.