Omniscia AmpleSense Audit

Distribute Code Style Findings

Distribute Code Style Findings

DIS-01C: Inefficient Code Implementation

TypeSeverityLocation
Gas OptimizationInformationalDistribute.sol:L61, L66, L68, L80, L83, L84

Description:

The code implementation of the contract contains a lot of repetitive reads as well as ineffectual safe arithmetics, such as evaluating the amount unstaked is strictly less than or equal to the current stakes of the user via a require check and proceeding to also perform a sub operation.

Example:

contracts/Distribute.sol
72/**
73 @dev unstakes a certain amounts, if unstaking is currently not possible the function MUST revert
74 @param account From whom
75 @param amount Amount to remove from the stake
76*/
77function unstakeFrom(address payable account, uint256 amount) public onlyOwner {
78 require(account != address(0), "Distribute: Invalid account");
79 require(amount > 0, "Distribute: Amount must be greater than zero");
80 require(amount <= _stakes[account], "Distribute: Dont have enough staked");
81 uint256 to_reward = _getReward(account, amount);
82 _total_staked = _total_staked.sub(amount);
83 _stakes[account] = _stakes[account].sub(amount);
84 if(_stakes[account] == 0) {
85 investor_count--;
86 }
87
88 if(to_reward == 0) return;
89 //take into account dust error during payment too
90 if(address(reward_token) != address(0)) {
91 reward_token.safeTransfer(account, to_reward);
92 }
93 else {
94 account.transfer(to_reward);
95 }
96}

Recommendation:

We strongly recommend the codebase to be optimized by using in-memory variables and generally polishing the logical branches it executes to simplify it and lower its gas cost significantly.

Alleviation:

The usage of SafeMath was replaced in the codebase with raw arithmetics thereby optimizing to a certain extent.

DIS-02C: Inexistent Variable Visibility Specifier

TypeSeverityLocation
Code StyleInformationalDistribute.sol:L26

Description:

The linked variable has no visibility specifier explicitly set.

Example:

contracts/Distribute.sol
26uint256 constant INITIAL_BOND_VALUE = 1000000;

Recommendation:

We advise one to be set so to avoid potential compilation discrepancies in the future as the current behaviour is for the compiler to assign one automatically.

Alleviation:

The public visibility specifier was properly introduced for the linked variable.

DIS-03C: Variable Mutability Specifiers

TypeSeverityLocation
Gas OptimizationInformationalDistribute.sol:L24, L40

Description:

The linked variables are assigned to only once during the contract's constructor.

Example:

contracts/Distribute.sol
42/**
43 @dev Initialize the contract
44 @param decimals Number of decimals of the reward token
45 @param _reward_token The token used for rewards. Set to 0 for ETH
46*/
47constructor(uint256 decimals, IERC20 _reward_token) Ownable() {
48 reward_token = _reward_token;
49 PRECISION = 10**decimals;
50}

Recommendation:

We advise them to be set as immutable greatly optimizing their read access gas cost.

Alleviation:

Both linked variables have been properly set as immutable optimizing the codebase.