CandyWallet

Smart Contract Audit Report

Audit Summary

CandyWallet Audit Report Sugar Kingdom is creating a contract that allows users to withdraw SugarKingdomTokens given they have required signatures.

For this audit, we reviewed the CandyWallet contract at commit 159822cdaec31cecc82fa0414b245eb6ac05c915 on the team's private GitHub repository.

We previously reviewed the project team's SugarKingdomToken contract here.

Audit Findings

Please ensure trust in the team prior to investing as they have substantial control in the ecosystem.
Date: May 23rd, 2022.
Updated: June 3rd, 2022 to reflect changes from commit 499415b0f041135c5d96ebb10d55e94fe02e23a3 to commit 159822cdaec31cecc82fa0414b245eb6ac05c915.

Finding #1 - CandyWallet - High (Resolved)

Description: The lastAdd variable used to check both the order of passed signatures and repeated signatures is never updated in the verifySignatures() function.
Risk/Impact: A user can input a Signer's signature multiple times in order to falsely satisfy the required Signers per level requirement.
Recommendation: The lastAdd variable should be updated before the recovered signature is added to the result list.
Resolution: The lastAdd variable is now updated each time an address is added to the result list.

Finding #2 - CandyWallet - Informational

Description: Retrieving a Signers level requires unnecessary loops.
Recommendation: A mapping from (Signer => Level) can be created to fetch a Signer's level more efficiently.
Update:The team has acknowledged and elected not to address this finding.

Finding #3 - CandyWallet - Informational (Resolved)

Description: The following line in the verifySignatures() function is unnecessary as an array index's default value already 0:
for(uint j= 0; j< _maxLevel+1; j++) result[j] = 0;
Recommendation: This line can be removed for gas-saving purposes.
Resolution: The team has removed this loop.

Contract Overview

  • This contract allows users to withdraw a specified token given they have received the necessary number of signatures from required Signers.
  • Upon initialization, a token, a list of Signers, and their corresponding "levels" are set.
  • The required number of signatures for each level and the level requirements and lock times for corresponding withdrawal amounts are also set.
  • When withdrawing, users will input a list of signatures, a destination, amount, nonce, create time, and expiry time.
  • These signatures are each verified along with the other passed parameters to retrieve the Signer and the Signer's level.
  • The withdrawal will be assigned a certain level based on its amount.
  • The withdrawal must have the required amount of signatures from Signers of each level up to the withdrawal's level.
  • A withdrawal can only occur after the withdrawal's corresponding lock time has passed since its creation, and before the withdrawal's expiration time.
  • A withdrawal's lock time is determined by the withdrawal's level.
  • The owner of this contract is set to the owner of the associated token contract.
  • The owner can update the token address at any time, which will in turn update this contract's owner.
  • The owner or any Signer can stop the contract at any time, preventing any withdrawals.
  • Only the owner can restart the contract once stopped.
  • The owner or any Signer can add another Signer at any time. If called by a Signer, they must be a higher level than the added Signer.
  • The owner or any Signer can also remove another Signer at any time. If called by a Signer, they must be a higher level than the removed Signer.
  • The owner or any Signer can update a level's lock time, withdraw amount threshold, and required number of signatures at any time. If called by a Signer, they must be a higher level than the specified level.
  • The owner can withdraw any amount of the token to any address at any time.
  • Any Signer can transfer all tokens to the owner's address at any time.
  • As the contract is implemented with Solidity 0.8.x, it is protected from overflows/underflows.

Audit Results

Vulnerability CategoryNotesResult
Arbitrary Jump/Storage WriteN/APASS
Centralization of Control
  • The owner and Signers have the permissions described above.
  • The owner can withdraw all tokens from the contract at any time.
  • Signers can withdraw all tokens to the owner's address at any time.
  • The owner can update the associated token at any time.
  • The owner and Signers can pause withdrawing functionality at any time.
  • WARNING
    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

    Inheritance Chart

    Smart Contract Audit - Inheritance

    Function Graph

    Smart Contract Audit - Graph

    Functions Overview

    
     ($) = payable function
     # = non-constant function
     
     +  Context 
        - [Int] _msgSender
        - [Int] _msgData
    
     +  Ownable (Context)
        - [Pub]  #
        - [Pub] owner
        - [Pub] renounceOwnership #
           - modifiers: onlyOwner
        - [Pub] transferOwnership #
           - modifiers: onlyOwner
        - [Int] _transferOwnership #
    
     + [Int] iCandyWallet 
        - [Ext] setTokenAddress #
        - [Ext] getStringToSign
        - [Ext] getLevel
        - [Ext] getRequiredLevel
        - [Ext] verifySignatures #
        - [Ext] withdrawTokens #
        - [Ext] emergencyStop #
        - [Ext] restart #
        - [Ext] addSignature #
        - [Ext] removeSignature #
        - [Ext] adminWithdraw #
    
     + [Int] IERC20 
        - [Ext] totalSupply
        - [Ext] balanceOf
        - [Ext] transfer #
        - [Ext] allowance
        - [Ext] approve #
        - [Ext] transferFrom #
    
     + [Int] IERC20Metadata (IERC20)
        - [Ext] name
        - [Ext] symbol
        - [Ext] decimals
    
     +  ERC20 (Context, IERC20, IERC20Metadata)
        - [Pub]  #
        - [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 #
    
     +  ERC20Burnable (Context, ERC20)
        - [Pub] burn #
        - [Pub] burnFrom #
    
     +  ReentrancyGuard 
        - [Pub]  #
    
     + [Int] ILiquidityRestrictor 
        - [Ext] assureLiquidityRestrictions #
    
     + [Int] IAntisnipe 
        - [Ext] assureCanTransfer #
    
     +  SugarKingdomToken (ERC20, Ownable, ERC20Burnable, ReentrancyGuard)
        - [Pub]  #
           - modifiers: ERC20
        - [Pub] balanceOf
        - [Pub] totalSupply
        - [Pub] isWhitelisted
        - [Pub] addWhitelisted #
           - modifiers: onlyOwner
        - [Pub] removeWhitelisted #
           - modifiers: onlyOwner
        - [Pub] isPool
        - [Pub] addPool #
           - modifiers: onlyOwner
        - [Pub] removePool #
           - modifiers: onlyOwner
        - [Pub] setTaxAccount #
           - modifiers: onlyOwner
        - [Int] initFees #
        - [Pub] changeFees #
           - modifiers: onlyOwner
        - [Pub] getFees
        - [Int] _mint #
        - [Int] _burn #
        - [Pub] calculateFees
        - [Int] _transfer #
           - modifiers: nonReentrant
        - [Int] _beforeTokenTransfer #
        - [Ext] setAntisnipeDisable #
           - modifiers: onlyOwner
        - [Ext] setLiquidityRestrictorDisable #
           - modifiers: onlyOwner
        - [Ext] setAntisnipeAddress #
           - modifiers: onlyOwner
        - [Ext] setLiquidityRestrictionAddress #
           - modifiers: onlyOwner
    
     +  CandyWallet (iCandyWallet)
        - [Pub] initialize #
        - [Pub] owner
        - [Pub] setTokenAddress #
           - modifiers: onlyOwner
        - [Pub] getStringToSign
        - [Pub] getLevel
        - [Pub] verifySignatures #
        - [Pub] getRequiredLevel
        - [Ext] withdrawTokens #
           - modifiers: notStopped
        - [Pub] emergencyStop #
           - modifiers: onlySigner
        - [Pub] restart #
           - modifiers: onlyOwner
        - [Ext] addSignature #
           - modifiers: requiredLevel
        - [Ext] removeSignature #
           - modifiers: requiredLevel
        - [Ext] set_level_limit #
           - modifiers: requiredLevel
        - [Ext] set_level_locktime #
           - modifiers: requiredLevel
        - [Ext] adminWithdraw #
           - modifiers: onlyOwner
        - [Ext] executiveWithdraw #
           - modifiers: requiredLevel
        - [Ext] isSigner
        - [Ext] getToken
        - [Ext] getLimit
        - [Ext] getLocktime
        - [Ext] getRequiredSignatures
        - [Ext] isStopped
    
    

    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.