PYESWAP

Smart Contract Audit Report

Audit Summary

PYESWAP is a new decentralized exchange.

For this audit, we reviewed the project team's PYESwapERC20, PYESwapPair, PYESwapFactory contracts at 0x130F7f261B086204c565c7c45025CAC128a88612 and PYESwapRouter contract at 0xA8B5D59E36E26769925B22B73Cb1E2c568e2F570 on the Binance Smart Chain Mainnet.

Audit Findings

No findings were identified.
Date: July 1st, 2022.

Contracts Overview

  • The contracts utilize ReentrancyGuard to prevent reentrancy attacks in applicable functions.
  • As the contracts are deployed with Solidity v0.8.15, they are safe from any possible overflows/underflows.
PYESwapERC20 Contract:
  • This contract contains the core functionality of the PYESwap LP token ($PYE-LP) maintained by the PYESwapPair 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.
PYESwapPair 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.
  • In the event that the team's platform fee is enabled, 16.6% of the swap fee is minted as LP tokens to an address controlled by the team.
  • 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.
PYESwapFactory Contract:
  • This contract is used to deploy new PYESwapPair contracts specifying two underlying token assets.
  • Anyone can create any pair any any time, as long as the pair has not been created yet.
  • Only one PYESwapPair 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.
PYESwapRouter Contract:
  • This contract is used to interact with any PYESwapPair liquidity pool contract created by the PYESwapFactory 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 PYESwapPair 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.

Audit Results

Vulnerability CategoryNotesResult
Arbitrary Jump/Storage WriteN/APASS
Centralization of ControlN/APASS
Compiler IssuesN/APASS
Delegate Call to Untrusted ContractN/APASS
Dependence on Predictable VariablesN/APASS
Ether/Token TheftN/APASS
Flash LoansN/APASS
Front RunningN/APASS
Improper EventsN/APASS
Improper Authorization SchemeN/APASS
Integer Over/UnderflowN/APASS
Logical IssuesN/APASS
Oracle IssuesN/APASS
Outdated Compiler VersionN/APASS
Race ConditionsN/APASS
ReentrancyN/APASS
Signature IssuesN/APASS
Unbounded LoopsN/APASS
Unused CodeN/APASS
Overall Contract Safety PASS

PYESwapERC20, PYESwapPair, PYESwapFactory Contracts

Smart Contract Audit - Inheritance

Smart Contract Audit - Graph


 ($) = payable function
 # = non-constant function
 
 Int = Internal
 Ext = External
 Pub = Public
 
 + [Int] IPYESwapFactory 
    - [Ext] feeTo
    - [Ext] feeToSetter
    - [Ext] getPair
    - [Ext] allPairs
    - [Ext] allPairsLength
    - [Ext] pairExist
    - [Ext] createPair #
    - [Ext] routerInitialize #
    - [Ext] routerAddress

 + [Int] IPYESwapPair 
    - [Ext] baseToken
    - [Ext] feeTaker
    - [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 #
    - [Ext] setBaseToken #
    - [Ext] setFeeTaker #

 +  ReentrancyGuard 
    - [Pub]  #

 + [Int] IPYESwapRouter 
    - [Ext] pairFeeAddress
    - [Ext] adminFee
    - [Ext] feeAddressGet
    - [Ext] adminFeeAddress
    - [Ext] owner

 + [Int] IPYESwapERC20 
    - [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
    - [Int] div

 + [Lib] ECDSA 
    - [Int] recover
    - [Int] recover
    - [Int] toEthSignedMessageHash

 +  PYESwapERC20 (IPYESwapERC20)
    - [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] IPYESwapCallee 
    - [Ext] pyeSwapCall #

 + [Int] IToken 
    - [Ext] addPair #
    - [Ext] handleFee #

 +  PYESwapPair (IPYESwapPair, PYESwapERC20, ReentrancyGuard)
    - [Pub] getReserves
    - [Prv] _safeTransfer #
       - modifiers: nonReentrant
    - [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
    - [Ext] setBaseToken #
    - [Ext] setFeeTaker #

 +  PYESwapFactory (IPYESwapFactory, ReentrancyGuard)
    - [Pub]  #
    - [Ext] routerInitialize #
    - [Ext] allPairsLength
    - [Ext] createPair #
       - modifiers: nonReentrant
    - [Ext] setFeeTo #
    - [Ext] setFeeToSetter #

PYESwapRouter Contract

Smart Contract Audit - Inheritance

Smart Contract Audit - Graph


 ($) = payable function
 # = non-constant function
 
 Int = Internal
 Ext = External
 Pub = Public
 
 + [Int] IPYESwapRouter01 
    - [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 ($)

 + [Int] IPYESwapRouter (IPYESwapRouter01)
    - [Ext] removeLiquidityETHSupportingFeeOnTransferTokens #
    - [Ext] removeLiquidityETHWithPermitSupportingFeeOnTransferTokens #
    - [Ext] swapExactTokensForTokensSupportingFeeOnTransferTokens #
    - [Ext] swapExactETHForTokensSupportingFeeOnTransferTokens ($)
    - [Ext] swapExactTokensForETHSupportingFeeOnTransferTokens #

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

 + [Int] IPYESwapPair 
    - [Ext] baseToken
    - [Ext] feeTaker
    - [Ext] name
    - [Ext] symbol
    - [Ext] decimals
    - [Ext] totalSupply
    - [Ext] balanceOf
    - [Ext] allowance
    - [Ext] updateTotalFee #
    - [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 #
    - [Ext] setBaseToken #

 + [Int] IPYESwapFactory 
    - [Ext] feeTo
    - [Ext] feeToSetter
    - [Ext] getPair
    - [Ext] allPairs
    - [Ext] allPairsLength
    - [Ext] pairExist
    - [Ext] createPair #
    - [Ext] setFeeTo #
    - [Ext] setFeeToSetter #
    - [Ext] routerInitialize #
    - [Ext] routerAddress

 + [Int] IToken 
    - [Ext] addPair #
    - [Ext] depositLPFee #
    - [Ext] getTotalFee

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

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

 + [Lib] PYESwapLibrary 
    - [Int] sortTokens
    - [Int] pairFor
    - [Int] getReserves
    - [Int] quote
    - [Int] getAmountOut
    - [Int] getAmountIn
    - [Int] amountsOut
    - [Int] amountsIn
    - [Int] getAmountsOut
    - [Int] getAmountsIn
    - [Int] adminFeeCalculation
    - [Int] _calculateFees
    - [Int] _calculateAmounts

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

 +  FeeStore 
    - [Int] initialize #
    - [Ext] setAdminFee #

 +  SupportingSwap (FeeStore, IPYESwapRouter)
    - [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

 +  PYESwapRouter (SupportingSwap)
    - [Pub]  #
    - [Ext]  ($)
    - [Int] _addLiquidity #
    - [Pub] getPair
    - [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 #

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 1300+ 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 across 1500 projects!.
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.