TORA Governance

Smart Contract Audit Report

Audit Summary

TORA Governance Audit Report TORA is building a new platform where users can create proposals and cast votes.

For this audit, we reviewed the Governance contract provided to us by the project team.

Audit Findings

All findings have been resolved, though some centralized aspects are present.
Date: February 20th, 2023.
Updated: February 23rd, 2023 to reflect updates made to the contract by the project team that resolves all Findings.

Finding #1 - Governance - High (Resolved)

Description: The team can use the emergencyWithdraw() function to withdraw any deposited tokens from the contract at any time.
function emergencyWithdraw() public _onlyOwner {
	Coin coin = Coin(token);
	coin.transfer(msg.sender, poolSize * 10**decimals);
	poolSize = 0;
}
Risk/Impact: The team can withdraw any user's deposited tokens from the contract at any time.
Recommendation: The team should remove the emergencyWithdraw() function from the contract as all deposited tokens are allocated to users.
Resolution: The team has removed the emergencyWithdraw() function from the contract.

Finding #2 - Governance - High (Resolved)

Description: The contract allows the team to specify any token address as the currency used on deposits and withdrawals, including fee-on-transfer tokens. However, the platform does not have fee-on-transfer support.
Risk/Impact: If a fee-on-transfer token is added as the currency and a user calls the deposit() function, the user's deposits[msg.sender].amount value will be set to a value greater than the contract's token balance. As a result, withdrawals will be funded from other users' deposits. If the contract does not have a sufficient token balance to support the withdrawal, the transaction will revert.
Recommendation: The team should implement fee-on-transfer support in the deposit() function by recording the contract's original token balance before initiating a deposit. After the transfer occurs, the user's deposit amount should be set to the difference between the contract's new balance and the originally recorded balance. Alternatively, the team could ensure that the currency used is not a fee-on-transfer token or ensure that the contract is excluded from the token's fee mechanism.
Resolution: The team has removed the changeToken() function from the contract and must exercise caution when setting the token to not use a fee-on-transfer token.

Finding #3 - Governance - High (Resolved)

Description: The deposit function transfers the specified number of tokens to the contract in the form of the contract's current token address. This address can be changed by the team at any time via the changeToken() function.
Risk/Impact: If the user deposits an amount of the current token address and the team changes the currency to a different token, the user will receive their payment in the new token, which may result in a value discrepancy from the originally expected amount.
Recommendation: The team should add the token address used as payment to the Deposit struct and record it in the deposit() function. The recorded address should be used in the withdraw() function to transfer tokens back to the user. Alternatively, the team could remove the changeToken() function from the contract and only set the token address one time in the constructor.
Resolution: The team has removed the changeToken() function from the contract.

Finding #4 - Governance - High (Resolved)

Description: The contract allows users to initiate multiple deposits in a row if a proposal has not yet been created, but does not allow users to withdraw any previous deposits.
Risk/Impact: Users will not be able to withdraw any previous deposits as they will be overridden by the new deposit amount. As a result, the previous deposit(s) will be permanently locked in the contract.
Recommendation: The team should either disallow users from being able to call the deposit() function multiple times in a row or return the previous deposit amount back to the user if a proposal has not yet been created by the user.
Resolution: Users can no longer initiate multiple deposits in a row if their deposit amount is greater than zero.

Finding #5 - Governance - Medium (Resolved)

Description: In the deposit() function, the specified number of tokens is multiplied by 10**decimals which disallows the user from depositing any less than 1 token if the decimals state variable has been set by the team to the actual decimals value of the token.
function deposit(uint256 amount) public payable {
...
coin.transferFrom(msg.sender, address(this), amount * 10**decimals);
Risk/Impact: If a high-priced token is added as the deposit currency users will not be able to deposit any less than 1 token resulting in the minimum deposit being excessively high.
Recommendation: The team should remove the decimals state variable from the contract and allow the user to account for decimals when initiating a deposit.
Resolution: Users must now account for decimals when initiating a deposit.

Finding #6 - Governance - Low (Resolved)

Description: The vote() function uses a for loop to cycle through every created proposal in the contract in order to execute logic for a single proposal.
Risk/Impact: If the total number of proposals grows too large, all vote transactions will not be able to occur due to the execution cost of the transaction exceeding the block's gas limit.
Recommendation: Rather than use a for loop, the team can determine the index of the proposal by subtracting the passed-in ID value by the first index of the allProposals array in the vote() function. The changes could be implemented as follows:
function vote(uint256 id) public {
...
	uint256 i = id - allProposals[0].id;
	allProposals[i].votes++;
	allProposals[i].voters.push(msg.sender);
Resolution: The team has implemented the above recommendation.

Finding #7 - Governance - Low (Resolved)

Description: Both the winProposal() and emenrgencyReset() functions use a for loop to cycle through every created proposal in the contract, however there is no limit to the number of proposals the contract can have.
Risk/Impact: If the total number of proposals grows too large, the winProposal() and emenrgencyReset() functions will not be able to execute due to the execution cost of the transaction exceeding the block's gas limit.
Recommendation: The team should enforce a maximum proposal limit of 350 in the propose() function to prevent the loops in the above functions from hitting the block gas limit.
Resolution: The team has implemented the above recommendation.

Finding #8 - Governance - Low (Resolved)

Description: The deposit(), propose(), vote(), and withdraw() functions are all unnecessarily declared payable as msg.value is never used in the functions.
Risk/Impact: Any ETH accidentally provided by users is permanently locked in the contract.
Recommendation: The team should remove the payable modifiers from the deposit(), propose(), vote(), and withdraw() functions. Alternatively, the team could add a function that allows an Admin to withdraw ETH from the contract.
Resolution: The team has removed the payable modifiers from the above functions.

Finding #9 - Governance - Informational (Resolved)

Description: All logic related to the couldWithdraw local variable in the withdraw() function is redundant as couldWithdraw will always be true at the time its value is enforced in the below require statement.
function withdraw() public payable {
    Coin coin = Coin(token);

    bool couldWithdraw = false;
    require(deposits[msg.sender].withdrawn == false, "Already withdrawn, might also be proposed");

    coin.transfer(msg.sender, deposits[msg.sender].amount);

    deposits[msg.sender].withdrawn = true;
    couldWithdraw = true;
    require(couldWithdraw, "Could not withdraw, probably the id is wrong");
}
Recommendation: The team could remove all logic related to the couldWithdraw local variable from the withdraw() function for additional gas savings on each call.
Resolution: The team has implemented the above recommendation.

Contract Overview

  • Any user can initiate a deposit by specifying a number of TORA tokens that will be transferred to the contract.
  • The user must grant the contract a sufficient allowance in order for the transaction to successfully occur.
  • The specified token amount must exceed the minimum deposit value set by the team.
  • Any user that has initiated a deposit can initiate a proposal by providing a proposal message, as long as the proposal time set by the team has passed since the time of their last deposit.
  • Users are prohibited from initiating two proposals in a row. Another deposit must be made by the user to initiate another proposal.
  • Any user that currently has tokens deposited in the contract can vote on a created proposal by specifying the proposal ID.
  • The voting cool-down period set by the team must have passed for users to be able to vote again.
  • The owner can initiate a win-proposal transaction which will declare the proposal with the most votes as "passed". All other proposals are removed from the platform and the agenda item is updated by the owner.
  • If there is a tie in votes, the proposal that was initiated first will be declared as passed.
  • Any user can withdraw their full deposit amount after 2 weeks have passed since their last deposit.
  • The deployer will be assigned as an "Admin" address upon deployment.
  • Any Admin can add another address as an Admin address at any time.
  • Any Admin can reset all proposal votes to zero at any time.
  • Any Admin can update the minimum deposit amount to any value at any time.
  • Any Admin can update the voting cool-down time to any value at any time.
  • Any Admin can update the proposal time to any value at any time.
  • Any Admin can toggle between the first and second rounds of the contract at any time.
  • 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 The team can reset all proposal votes to zero at any time. 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 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

 + [Int] Coin 
    - [Ext] transfer #
    - [Ext] transferFrom #

 +  Governance 
    - [Pub]  #
    - [Pub] changeProposeTime #
       - modifiers: _onlyOwner
    - [Pub] changeVotingCooldown #
       - modifiers: _onlyOwner
    - [Pub] changeMinimumDeposit #
       - modifiers: _onlyOwner
    - [Pub] addAdmin #
       - modifiers: _onlyOwner
    - [Pub] isAdmin
    - [Pub] deposit #
    - [Pub] propose #
    - [Pub] vote #
    - [Pub] startSecondRound #
       - modifiers: _onlyOwner
    - [Pub] returnToFirstRound #
       - modifiers: _onlyOwner
    - [Pub] winProposal #
       - modifiers: _onlyOwner
    - [Pub] withdraw #
    - [Pub] getTimeLeftToVote
    - [Pub] getTimeLeftToPropose
    - [Pub] getMinimumDeposit
    - [Pub] getProposalTime
    - [Pub] getCurrentAgenda
    - [Pub] getVotingCooldown
    - [Pub] getIfProposed
    - [Pub] getIfWithdrawn
    - [Pub] getDeposit
    - [Pub] getIsSecondRound
    - [Pub] getWinners
    - [Pub] returnWithdrawableAmount
    - [Pub] emergencyReset #
       - modifiers: _onlyOwner
    - [Pub] returnAllProposals
    - [Pub] returnWinners

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.