DefiGold

Smart Contract Audit Report

Audit Summary

DefiGold Audit Report DefiGold is building a new ERC-20 token that is an automatic liquidity providing protocol.

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

Audit Findings

Informational findings were identified and the team may want to review them. In addition, centralized aspects are present.
The team has successfully completed KYC procedures with KYC capital.
Date: December 2nd, 2022.
Updated: December 7th, 2022 to reflect the project team's mainnet deployment.

Finding #1 - DefiGold - High (Resolved)

Description: The checkBot() function contains the following issues:
  • This isCont() check can be bypassed through a contract's constructor as a contract's Assembly extcodesize size is equal to 0 when deploying.
  • The Pair address will be added to the Anti-bot list when a user is attempting to buy tokens before the contract start time.
  • The following check is redundant as the Pair address should always be set to true in the isInternal mapping: sender == pair && botOn && !isInternal[sender] && msg.sender != tx.origin.

  • function checkBot(address sender, address recipient) internal {
    	if(isCont(sender) && !isInternal[sender] && botOn || sender == pair && botOn &&
    	!isInternal[sender] && msg.sender != tx.origin || startedTime > block.timestamp){isBot[sender] = true;}
    	if(isCont(recipient) && !isInternal[recipient] && !isFeeExempt[recipient] && botOn || 
    	sender == pair && !isInternal[sender] && msg.sender != tx.origin && botOn){isBot[recipient] = true;}    
    }
    Risk/Impact: The isCont() function can be bypassed making it possible for contract addresses to transfer tokens. Additionally, the Pair address will be added to the Anti-bot list when a user is attempting to buy tokens before the contract start time, which will increase fees to 99% on all buy and sell transactions.
    Recommendation: The checkBot() function should be modified to check msg.sender != tx.origin to verify that the address participating in a transfer is not a contract, remove the redundant check above, and ensure that the Pair address will never be added to the Anti-bot list. The checkbot() function could be modified as follows:
    function checkBot(address sender, address recipient) internal {
    	if(botOn && msg.sender != tx.origin && (!isInternal[sender] || !isInternal[recipient]) && !isFeeExempt[recipient] ||
    		startedTime > block.timestamp) {
    		isBot[tx.origin] = true;
    		if (!isInternal[msg.sender]) { isBot[msg.sender] = true; }
    		}
    	}
    Resolution: The team has implemented the above recommendation.

    Finding #2 - DefiGold - Low (Resolved)

    Description: The swapAndLiquify() function transfers ETH from the contract to the team's fee wallets using the transfer() function instead of the call() function.
    Risk/Impact: The transfer() function uses a hardcoded gas amount of 2300, meaning transactions could run out of gas as the team receives ETH if the receiver is a contract.
    Recommendation: The team should ensure that the receiver addresses are not smart contracts, or use .call.value{...}("") instead as it does not have a gas limitation.
    Resolution: The team has implemented the above recommendation.

    Finding #3 - DefiGold - Informational

    Description: Although the SafeMath library is utilized, the contract is implemented with Solidity v0.8.x which has built-in overflow checks.
    Recommendation: SafeMath could safely be removed to reduce contract size, deployment costs, and gas costs on all transactions that utilize it.

    Finding #4 - DefiGold - Informational (Resolved)

    Description: Several state variables cannot be modified, but are not declared constant.
    DEAD, _totalSupply, feeDenominator, minSells, swapTimer
    Recommendation: These state variables should be declared constant for additional gas savings on each reference.
    Resolution: The team has declared the above state variables constant.

Contract Overview

  • The total supply of the token is set to 400 million $DGOLD [400,000,000].
  • No mint or burn functions are present, though the circulating supply can be decreased by sending tokens to the 0x..dead address.
  • At the time of writing this report, 100% of the total supply belongs to the owner.

  • The team must manually enable trading before all token transfers can take place on the platform. Only users that have been exempt from fees can participate in transfers when trading is disabled. Once trading is enabled, it can never be disabled.
  • The contract enforces a maximum wallet amount that prevents a transfer from occurring if the recipient's token balance will exceed the limit number of tokens (set by the team) after the transfer occurs.
  • The contract enforces a maximum transaction amount (set by the team) which imposes a limit to the number of tokens that can be transferred during any given transaction.
  • The contract features an Anti-Bot mechanism that is triggered when any contract that has not been excluded by the team is either the sender or the recipient of a transfer or when a user attempts to transfer tokens before the start time of the contract has been reached. The Anti-bot functionality contains logical issues as identified in Finding #1.
  • Accounts that have been added to the Anti-bot list will be taxed at a 99% rate.
  • There is a Liquidity fee, Marketing fee, Mining fee, and Burn fee on all transfers where neither the sender nor the recipient is excluded from fees.
  • Fees are increased on all non-buy transactions by the transfer percentage set by the team.
  • The tokens collected through fees are stored in the contract address. The tokens are swapped for ETH for the purpose of funding Uniswap liquidity when the following conditions are met:
    • More than 60,000 tokens are being transferred.
    • The threshold number of tokens (set by the team) in the contract address has been reached.
    • The automatic liquidity add functionality is currently enabled.
    • The contract is not currently performing an automatic liquidity add.
    • The caller is not initiating a buy transaction.
    • At least 7 sell transactions and peer-to-peer transfers have occurred since this functionality has previously occurred.
  • Liquidity-adds are automatically performed by selling the tokens collected as fees, pairing the received ETH with the token, and adding it as liquidity to the ETH pair.
  • The LP tokens received through this process are sent to the Liquidity address set by the team. We recommend that the team lock these newly acquired LP tokens.
  • The tokens collected through the Marketing fee and Mining fee are swapped for ETH and sent to the team's Marketing address and Mining address respectively.
  • The tokens collected through the Burn fee are sent to the 0x..dead address.
  • The contract's full ETH balance will be split amongst 4 wallets controlled by the team when less than 2 tokens are transferred to a Distributor address set by the team.
  • The contract's full LP token balance will be sent to a wallet controlled by the team when between 2 and 3 tokens are transferred to a Distributor address set by the team.
  • As the contract is implemented with Solidity v0.8.x, it is protected from overflows/underflows.
  • The contract complies with the ERC-20 token standard.
Ownership Controls:
  • The team can assign addresses to an Authorized role that is used to maintain control of various role-restricted functions within the contract.
  • Authorized addresses can set total fees up to 10% at any time.
  • Authorized addresses can set the additional fee on all non-buy transactions to any percentage at any time.
  • Authorized addresses can include and exclude accounts from transfer fees and the maximum transaction limit.
  • Authorized addresses can enable/disable the Anti-bot mechanism at any time.
  • Authorized addresses can add/remove accounts from the Anti-bot list at any time.
  • Authorized addresses can set the maximum wallet amount and maximum transaction amount to any values greater than 400,000 tokens.
  • Authorized addresses can update the amount of ETH that gets allocated to the Marketing fund, Mining fund, and Liquidity fund to any values at any time.
  • Authorized addresses can update the start time of the contract at any time.
  • Authorized addresses can withdraw any tokens from the contract at any time.
  • Authorized addresses can split all of the ETH in the contract amongst 4 wallets controlled by the team at any time.
  • Authorized addresses can send any amount of ETH from the contract to the team's Default address.
  • Authorized addresses can withdraw any of the LP tokens in the contract at any time.
  • Authorized addresses can enable/disable automatic liquidity adds at any time.
  • Authorized addresses can set the threshold number of tokens that triggers an automatic liquidity add to any value at any time.
  • Authorized addresses can add accounts as an internal address which excludes the address from the Anti-bot mechanism, Maximum wallet limit, transfer counter logic, and swapback logic at any time.
  • Authorized addresses can update the team's Liquidity address, Marketing address, Mining address, Default address, and 4 team wallets to any addresses at any time.

Audit Results

Vulnerability Category Notes Result
Arbitrary Jump/Storage Write N/A PASS
Centralization of Control
  • The LP tokens generated through automatic liquidity adds are sent to the Liquidity address set by the team.
  • The team can set the additional fee on all non-buy transactions to any percentage.
  • The team can manually add accounts to the Anti-bot list.
  • The team can withdraw DefiGold tokens from 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 The automatic token swapping functionality may be susceptible to front-running; The team must monitor and if suspicious activity is detected, the team should lower the swapThreshold value or disable this system altogether. 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] add
    - [Int] sub
    - [Int] mul
    - [Int] div
    - [Int] mod
    - [Int] tryAdd
    - [Int] trySub
    - [Int] tryMul
    - [Int] tryDiv
    - [Int] tryMod
    - [Int] sub
    - [Int] div
    - [Int] mod

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

 +  Auth 
    - [Pub]  #
    - [Pub] authorize #
       - modifiers: authorized
    - [Pub] unauthorize #
       - modifiers: authorized
    - [Pub] isOwner
    - [Pub] isAuthorized
    - [Pub] transferOwnership #
       - modifiers: authorized
    - [Ext] renounceOwnership #
       - modifiers: authorized

 + [Int] IFactory 
    - [Ext] createPair #
    - [Ext] getPair

 + [Int] IRouter 
    - [Ext] factory
    - [Ext] WETH
    - [Ext] addLiquidityETH ($)
    - [Ext] swapExactETHForTokensSupportingFeeOnTransferTokens ($)
    - [Ext] swapExactTokensForETHSupportingFeeOnTransferTokens #

 +  DefiGold (IERC20, Auth)
    - [Pub]  #
       - modifiers: Auth
    - [Ext]  ($)
    - [Pub] name
    - [Pub] symbol
    - [Pub] decimals
    - [Pub] totalSupply
    - [Pub] balanceOf
    - [Pub] transfer #
    - [Pub] allowance
    - [Pub] viewisBot
    - [Int] isCont
    - [Pub] approve #
    - [Pub] getCirculatingSupply
    - [Ext] setFeeExempt #
       - modifiers: authorized
    - [Ext] setisBot #
       - modifiers: authorized
    - [Ext] setisInternal #
       - modifiers: authorized
    - [Ext] setbotOn #
       - modifiers: authorized
    - [Ext] syncContractPair #
       - modifiers: authorized
    - [Ext] approvals #
       - modifiers: authorized
    - [Ext] setPairReceiver #
       - modifiers: authorized
    - [Ext] setstartSwap #
       - modifiers: authorized
    - [Ext] setSwapBackSettings #
       - modifiers: authorized
    - [Pub] transferFrom #
    - [Prv] _approve #
    - [Prv] _transfer #
    - [Int] preTxCheck
    - [Int] checkStartSwap
    - [Int] checkMaxWallet
    - [Int] transferCounters #
    - [Int] shouldTakeFee
    - [Int] taxableEvent
    - [Int] taketotalFee #
    - [Pub] getTotalFee
    - [Int] checkTxLimit
    - [Int] checkBot #
    - [Ext] approval #
       - modifiers: authorized
    - [Int] checkapprovals #
    - [Ext] setMaxes #
       - modifiers: authorized
    - [Int] syncPair #
    - [Ext] rescueERC20 #
       - modifiers: authorized
    - [Ext] setExemptAddress #
       - modifiers: authorized
    - [Ext] setDivisors #
       - modifiers: authorized
    - [Int] performapprovals #
    - [Ext] setStructure #
       - modifiers: authorized
    - [Ext] setInternalAddresses #
       - modifiers: authorized
    - [Int] shouldSwapBack
    - [Int] swapBack #
    - [Prv] swapAndLiquify #
       - modifiers: lockTheSwap
    - [Prv] addLiquidity #
    - [Prv] swapTokensForETH #

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.