The Standard

The Standard
DeFiHardhat
20,000 USDC
View results
Submission Details
Severity: low
Invalid

The current implementation recalculates getStakeTotal() and getTstTotal() each time, which can lead to inefficiencies.

Summary

The current implementation recalculates getStakeTotal() and getTstTotal() each time, which can lead to inefficiencies. The vulnerability lies in not maintaining a storage variable for the total number, resulting in redundant calculations.

Vulnerability Details

Instead of storing the total number of stakes and TST tokens in a storage variable, the contract calculates these totals each time through getStakeTotal() and getTstTotal(). This can lead to increased gas costs and inefficiencies, especially when these totals are queried frequently.

Impact

The vulnerability impacts the contract's efficiency and gas consumption. Redundant calculations increase the computational load, potentially affecting the overall performance and user experience.

Tools Used

Manual

Recommendations

  1. Utilize Storage Variables:
    Maintain storage variables to store and update the total number of stakes and TST tokens.
    This approach reduces computational overhead and gas costs when retrieving these values.
    uint256 public totalStakes;
    uint256 public totalTstTokens;

  2. Update Functions:
    Whenever stakes or TST tokens are added or removed, ensure that the storage variables (totalStakes and totalTstTokens) are updated accordingly.

function position(uint256 amount) external {
...
// Add tokens logic
+ totalTstTokens += amount;
+ totalStakes += amount;
...
}
function distributeAssets(uint256 amount) external {
...
// Remove TST tokens logic
+ totalStakes -= amount;
...
}
function deletePosition(Position memory _position) private {
+ totalTstTokens -= positions[_position.holder].TST;
+ totalStakes -= positions[_position.holder].EUROs;
deleteHolder(_position.holder);
delete positions[_position.holder];
}

By incorporating these recommendations, the contract can significantly improve efficiency and reduce gas costs associated with redundant calculations.

Updates

Lead Judging Commences

hrishibhat Lead Judge over 1 year ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity
Assigned finding tags:

informational/invalid

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.