Cairo Finance

Smart Contract Audit Report

Audit Summary

Cairo Finance Audit Report Cairo Finance is building a new referral platform where users can earn daily $CAF rewards.

For this audit, we reviewed the project team's PharaohFarmPoT contract at 0xdbcb34d17346e4e96469092bded68b131c497633 on the Binance Smart Chain Mainnet.

Audit Findings

An Informational finding was identified and the team may want to review it.
Date: February 9th, 2023.
Updated: February 10th, 2023 to reflect updates made to the contract that resolve Findings #1, #2, #3, and #5.
Updated: February 16th, 2023 to reflect the contract's Mainnet address.
Updated: February 21st, 2023 to reflect the contract's newly deployed Mainnet address.

Finding #1 - PharaohFarmPoT - High (Resolved)

Description: In the claimRewards() function, the following check to ensure that users can only claim rewards once every 24 hours is calculated incorrectly:
require(block.timestamp - lastClaim / 1 days >= 1 days, "Can't claim twice in 24hrs");
Risk/Impact: Users will be able to repeatedly call the claim function in an effort to claim rewards more than once per 24 hours. Daily rewards for the user will potentially be forfeited as the user's last claim time will be updated to the time of the transaction.
Recommendation: The above calculation should be modified as follows to enforce that users can only call the claimRewards() function once every 24 hours:
require((block.timestamp - lastClaim) >= 1 days, "Can't claim twice in 24hrs");
Resolution: The team has implemented the above recommendation.

Finding #2 - PharaohFarmPoT - Low (Resolved)

Description: The claimRewards() function contains a tautology as the following require statement will always be true:
require(interest >= 0, "Can't claim if nothing is available");
Risk/Impact: The claimRewards() function will execute even if the user is not currently due any rewards. Daily rewards for the user will potentially be forfeited as the user's last claim time will be updated to the time of the transaction.
Recommendation: The team should modify the above require statement to enforce that the interest value is greater than zero as follows:
require(interest > 0, "Can't claim if nothing is available");
Resolution: The team has implemented the above recommendation.

Finding #3 - PharaohFarmPoT - Informational (Resolved)

Description: The following state variables cannot be modified but are not declared constant.
BASE_WITHDRAW_FEE, DEPOSITE_TAX_RATE, MIN_DEPOSIT_AMOUNT, maxPayout
Recommendation: The team should declare the above state variables constant for additional gas savings on each reference.
Resolution: The team has declared the above state variables constant.

Finding #4 - PharaohFarmPoT - Informational

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

Finding #5 - PharaohFarmPoT - Informational (Resolved)

Description: The firstAddress state variable is set twice in the constructor.
Recommendation: The constructor could be modified to set firstAddress to the deployer one time to reduce deployment costs.
Resolution: The team has implemented the above recommendation.

Contract Overview

  • Any user can initiate a deposit one time by specifying an amount of $CAF tokens that will be sent to the contract.
  • The user must grant the contract a sufficient allowance in order for the transaction to successfully occur.
  • Tokens that are deposited cannot be directly withdrawn by users.
  • A minimum deposit amount of 100 tokens is enforced on all deposits.
  • A 15% deposit tax is calculated on all deposits and remains in the contract.
  • A maximum reward amount is set to 365% of the user's deposit amount minus the deposit tax. The maximum reward amount does not apply to the deployer's address.
  • The user must provide a referral address that has previously made a deposit into the contract.
  • The referral address is automatically allocated 10% of the deposit value if the current amount of rewards due to them will not cause their total claimed rewards to exceed their maximum reward amount.
  • Rewards are automatically calculated for all subsequent upline addresses of the specified referral address on deposits. Each upline address is moved into the next tier when calculating rewards.
  • Any user can claim any rewards due to them once every 24 hours.
  • A 10% withdraw tax is charged when the user's deposit amount does not exceed 1% of the contract's current $CAF token balance.
  • For each percentage (up to 10%) of the current contract balance the user's deposit exceeds, the withdrawal tax is increased by 5%.
  • The tokens collected through the withdraw tax remain in the contract.
  • Any pending rewards are transferred from the contract to the user's wallet address.
  • Users should be aware that the funding for rewards comes from other users' deposits and there is no guarantee that these deposits will be sufficient to cover payouts.
  • Any user that has previously deposited tokens into the contract can elect to "double up" their deposit in order to increase their maximum reward amount.
  • The sum of the user's claimed amount and pending rewards must exceed their maximum reward amount value in order to successfully double up.
  • The user will transfer the difference between their current pending rewards (if any) and double their original deposit into the contract.
  • The user must grant the contract a sufficient allowance in order for the transaction to successfully occur.
  • The contract utilizes ReentrancyGuard to prevent reentrancy attacks in applicable functions.
  • As the contract is implemented with Solidity v0.8.x, it is safe from any possible overflows/underflows.

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 Rewards are funded from other users' deposits. As a result, there is no guarantee that these deposits will be sufficient to cover payouts. WARNING
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   WARNING

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

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

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

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

 + [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] safePermit #
    - [Prv] _callOptionalReturn #

 + [Lib] SafeMath 
    - [Int] tryAdd
    - [Int] trySub
    - [Int] tryMul
    - [Int] tryDiv
    - [Int] tryMod
    - [Int] add
    - [Int] sub
    - [Int] mul
    - [Int] div
    - [Int] mod
    - [Int] sub
    - [Int] div
    - [Int] mod

 +  ReentrancyGuard 
    - [Pub]  #
    - [Prv] _nonReentrantBefore #
    - [Prv] _nonReentrantAfter #

 +  PharaohFarmPoT (Ownable, ReentrancyGuard)
    - [Pub]  #
    - [Pub] deposit #
       - modifiers: nonReentrant
    - [Int] refer #
    - [Int] reinvestRefer #
    - [Pub] getUplineAddress
    - [Pub] depositAfterTax
    - [Pub] getMaxPayout
    - [Pub] availableRewards
    - [Pub] getWithdrawalTax
    - [Pub] getDay
    - [Pub] claimRewards #
       - modifiers: nonReentrant
    - [Pub] doubleUp #
       - modifiers: nonReentrant
    - [Int] setLvl1Setter #
    - [Int] setLvl2Setter #
    - [Int] setLvl3Setter #
    - [Int] setLvl4Setter #
    - [Int] setLvl5Setter #
    - [Int] setLvl6Setter #
    - [Int] setLvl7Setter #
    - [Ext] getLevel1Reffers
    - [Ext] getLevel2Reffers
    - [Ext] getLevel3Reffers
    - [Ext] getLevel4Reffers
    - [Ext] getLevel5Reffers
    - [Ext] getLevel6Reffers
    - [Ext] getLevel7Reffers
    - [Pub] calculatePayout
    - [Pub] getContractBalance

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.