Array Capital Staking
Smart Contract Audit Report
Audit Summary
Array Capital is building a new ERC-20 token and a new platform where users can stake tokens and earn rewards.
For this audit, we reviewed the Array and ArrayStaking contract provided to us by the project team.
Audit Findings
High findings were identified and the team must resolve these issues. In addition, some centralized aspects are present.
Date: April 19th, 2023.Finding #1 - ArrayStaking - High
Description: The safeRewardTransfer() function checks the contract's Staking token balance and transfers the Staking token from the Treasury contract to the user rather than the Reward token.
Risk/Impact: If the Staking token and Reward token are not set to the same address, deposits and withdrawals will revert if the user is due rewards and the Treasury contract doesn't hold any Staking tokens. If the Treasury contract currently holds any Staking tokens, the Staking token will be used to fund rewards rather than the Reward token.function safeRewardTransfer(address to, uint256 amount) internal returns (uint256) { uint256 balance = poolInfo.stakingToken.balanceOf(address(treasury)); ... if (amount > balance) { poolInfo.stakingToken.safeTransferFrom( address(treasury), to, balance ); return balance; } poolInfo.stakingToken.safeTransferFrom(address(treasury), to, amount);
Recommendation: The team should modify the safeRewardTransfer() function to check the contract's Reward token balance and transfer the Reward token rather than the Staking token.
Resolution: The team has not yet addressed this issue.
Finding #2 - ArrayStaking - 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 be safely removed to reduce contract size, deployment costs, and gas costs on all transactions that utilize it.
Contracts Overview
Array Contract:
- As the contracts are implemented with Solidity v0.8.x, they are protected from any possible overflows/underflows.
ArrayStaking Contract:
- The initial supply of the token is set to 20 million $Array [20,000,000] and is minted to the deployer.
- The maximum supply of the token is set to 100 million.
- The Minter role can mint any number of tokens to any address up to the maximum supply at any time.
- Any user can burn their own tokens to decrease the total supply at any time.
- Any user can burn tokens on another user's behalf if an allowance has been granted.
- The Default admin can pause/unpause the contract at any time which disables all transfers, minting, and burning.
- The contract complies with the ERC-20 token standard.
- Any user can use this contract to stake tokens and earn rewards.
- The owner can set the contract's staking pool one time by specifying the staking token, reward token, and reward per block value.
- The owner will set the Founder, Developer, Marketing, and Advisor addresses upon deployment and a new Treasury contract will be created.
- Any user can specify a number of tokens to deposit into the contract at any time.
- The user must grant the contract a sufficient allowance in order for the deposit to successfully occur.
- A deposit fee is charged on all deposits and is allocated to the Collector address set by the team.
- The user's lock start time is set to the time of the transaction on all first deposits.
- The owner or Admin can add a new tier to the contract by specifying the tier's ID, weight, and minimum amount value.
- On deposits, a user's tier number is returned based on their total number of staked tokens.
- The user's lock start time is updated on all subsequent deposits if their current stake is unlocked or the user's updated total stake amount advances their stake to a new tier.
- Users that have staked tokens can specify a number of tokens to withdraw as long as the lock period has passed since the user's lock start time.
- A withdraw fee is charged on all withdrawals and is allocated to the Collector address set by the team.
- Any pending rewards are calculated and transferred from the Treasury contract to the user on all deposits and withdrawals.
- Reward tokens are minted to the Founder, Developer, Marketing, Advisor, and Treasury addresses on all deposits and withdrawals based on their share percentages set by the team.
- If the Staking token and Reward token are set to the same address, users can execute a redeposit which will calculate any pending rewards and initiate a new deposit for the calculated amount.
- Any user that has deposited tokens can trigger an emergency withdrawal at any time which will withdraw their staked tokens and forfeit all rewards.
- The owner or Admin can update an existing tier's weight and minimum amount value at any time.
- The owner or Admin can remove an existing tier at any time.
- The owner can update the reward per block to any value at any time.
- The owner can set the lock period to any value at any time.
- The owner can set both the Deposit fee and Withdraw fee to any percentages up to 70% at any time.
- The owner can update the Collector address at any time.
- The owner can update the Founder, Developer, Marketing, and Advisor addresses and their share percentages at any time.
- The owner can pause/unpause all deposits at any time.
- The owner can withdraw the Treasury contract's full Reward token balance at any time. The team must ensure the Treasury contract has a sufficient reward token balance to support rewards for all users.
- The team must exercise caution when assigning the staking token to avoid using a fee-on-transfer token. If a fee-on-transfer token is added, the contract must be excluded from the token's fee mechanism.
- The team must exercise caution when assigning the staking token to avoid using an ERC-777 compliant token as this could introduce reentrancy to the platform.
Audit Results
Vulnerability Category | Notes | Result |
---|---|---|
Arbitrary Jump/Storage Write | N/A | PASS |
Centralization of Control |
|
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 | N/A | PASS |
Improper Events | N/A | PASS |
Improper Authorization Scheme | N/A | PASS |
Integer Over/Underflow | N/A | PASS |
Logical Issues | The safeRewardTransfer() function checks the contract's Staking token balance and transfers the Staking token from the Treasury contract to the user rather than the Reward token. | FAIL |
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 | FAIL |
Inheritance Chart
Function 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 #
+ [Lib] Address
- [Int] isContract
- [Int] sendValue #
- [Int] functionCall #
- [Int] functionCall #
- [Int] functionCallWithValue #
- [Int] functionCallWithValue #
- [Int] functionStaticCall
- [Int] functionStaticCall
- [Int] functionDelegateCall #
- [Int] functionDelegateCall #
- [Int] verifyCallResult
+ [Lib] SafeERC20
- [Int] safeTransfer #
- [Int] safeTransferFrom #
- [Int] safeApprove #
- [Int] safeIncreaseAllowance #
- [Int] safeDecreaseAllowance #
- [Prv] _callOptionalReturn #
+ Context
- [Int] _msgSender
- [Int] _msgData
+ Ownable (Context)
- [Pub] #
- [Pub] owner
- [Pub] renounceOwnership #
- modifiers: onlyOwner
- [Pub] transferOwnership #
- modifiers: onlyOwner
- [Int] _transferOwnership #
+ [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
+ StakingTreasury (Ownable)
- [Ext] allowClaiming #
- modifiers: onlyOwner
- [Ext] withdrawRewards #
- modifiers: onlyOwner
+ Pausable (Context)
- [Pub] #
- [Pub] paused
- [Int] _pause #
- modifiers: whenNotPaused
- [Int] _unpause #
- modifiers: whenPaused
+ [Int] IAccessControl
- [Ext] hasRole
- [Ext] getRoleAdmin
- [Ext] grantRole #
- [Ext] revokeRole #
- [Ext] renounceRole #
+ [Lib] Strings
- [Int] toString
- [Int] toHexString
- [Int] toHexString
+ [Int] IERC165
- [Ext] supportsInterface
+ ERC165 (IERC165)
- [Pub] supportsInterface
+ AccessControl (Context, IAccessControl, ERC165)
- [Pub] supportsInterface
- [Pub] hasRole
- [Int] _checkRole
- [Pub] getRoleAdmin
- [Pub] grantRole #
- modifiers: onlyRole
- [Pub] revokeRole #
- modifiers: onlyRole
- [Pub] renounceRole #
- [Int] _setupRole #
- [Int] _setRoleAdmin #
- [Int] _grantRole #
- [Int] _revokeRole #
+ [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 #
+ ERC20Capped (ERC20, ERC20Burnable)
- [Pub] #
- [Pub] cap
- [Int] _mint #
+ Array (ERC20Capped, Pausable, AccessControl)
- [Pub] #
- modifiers: ERC20,ERC20Capped
- [Pub] mint #
- modifiers: onlyRole
- [Pub] pause #
- modifiers: onlyRole
- [Pub] unpause #
- modifiers: onlyRole
- [Int] _beforeTokenTransfer #
- modifiers: whenNotPaused
+ [Int] IArrayStaking
- [Ext] isLocked
- [Ext] getTierById
- [Ext] getLockedAmount
- [Ext] getUserUnlockTime
- [Ext] getUserTier
- [Ext] getTierIds
+ Adminable (Ownable, AccessControl)
- [Pub] #
+ WithLevels (Adminable, IArrayStaking)
- [Pub] #
- [Ext] getTierIds
- [Pub] getTierById
- [Int] getTierForAmount
- [Int] getTierIdxForAmount
- [Ext] setTier #
- modifiers: onlyOwnerOrAdmin
- [Ext] deleteTier #
- modifiers: onlyOwnerOrAdmin
- [Int] stringsEqual
+ [Lib] EnumerableSet
- [Prv] _add #
- [Prv] _remove #
- [Prv] _contains
- [Prv] _length
- [Prv] _at
- [Prv] _values
- [Int] add #
- [Int] remove #
- [Int] contains
- [Int] length
- [Int] at
- [Int] values
- [Int] add #
- [Int] remove #
- [Int] contains
- [Int] length
- [Int] at
- [Int] values
- [Int] add #
- [Int] remove #
- [Int] contains
- [Int] length
- [Int] at
- [Int] values
+ Stakeable (Ownable, IArrayStaking, WithLevels)
- [Pub] #
- [Pub] setPool #
- modifiers: onlyOwner
- [Pub] getMultiplier
- [Pub] updatePool #
- [Pub] isLocked
- [Pub] reDeposit #
- [Pub] deposit #
- [Ext] pendingArray
- [Pub] withdraw #
- [Int] takeFee #
- [Pub] emergencyWithdraw #
- [Int] safeRewardTransfer #
- [Ext] updateRewardPerBlock #
- modifiers: onlyOwner
- [Ext] updateLockPeriod #
- modifiers: onlyOwner
- [Pub] setFees #
- modifiers: onlyOwner
- [Pub] setDeveloper #
- modifiers: validShare,onlyOwner
- [Pub] setMarketing #
- modifiers: validShare,onlyOwner
- [Pub] setAdvisor #
- modifiers: validShare,onlyOwner
- [Pub] setFounder #
- modifiers: validShare,onlyOwner
- [Ext] getLockedAmount
- [Pub] getUserUnlockTime
- [Ext] getUserTier
- [Pub] getAllPoolUserInfos
+ ArrayStaking (Ownable, Stakeable)
- [Pub] #
- modifiers: Stakeable
- [Ext] halt #
- modifiers: onlyOwner
- [Pub] deposit #
- modifiers: notHalted
- [Pub] reDeposit #
- modifiers: notHalted
- [Pub] withdraw #
- modifiers: lockable
- [Ext] withdrawRewards #
- 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.