The Standard

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

Consider using a state variable for total TST instead of iterating through a loop

Summary

The computation of total TST in the getTstTotal() function involves iterating through two arrays, positions and pendingStakes. If these arrays become too large, the looping process could consume a significant amount of gas. In case it exceeds the block gas limit, it might lead to a Denial of Service (DoS) when using this function. Therefore, it would be beneficial to use a state variable to store the total TST state within the contract each time there is a change, such as in the increasePosition() and decreasePosition() functions.

Recommendations

Add a variable totalTST and update it each time there is a change in TST within the contract, for example:

uint256 private totalTST;
function increasePosition(uint256 _tstVal, uint256 _eurosVal) external {
require(_tstVal > 0 || _eurosVal > 0);
consolidatePendingStakes();
ILiquidationPoolManager(manager).distributeFees();
if (_tstVal > 0) {
IERC20(TST).safeTransferFrom(msg.sender, address(this), _tstVal);
totalTST += _tstVal; // <- AUDIT - add here
}
if (_eurosVal > 0) IERC20(EUROs).safeTransferFrom(msg.sender, address(this), _eurosVal);
pendingStakes.push(PendingStake(msg.sender, block.timestamp, _tstVal, _eurosVal));
addUniqueHolder(msg.sender);
}
function decreasePosition(uint256 _tstVal, uint256 _eurosVal) external {
consolidatePendingStakes();
ILiquidationPoolManager(manager).distributeFees();
require(_tstVal <= positions[msg.sender].TST && _eurosVal <= positions[msg.sender].EUROs, "invalid-decr-amount");
if (_tstVal > 0) {
IERC20(TST).safeTransfer(msg.sender, _tstVal);
positions[msg.sender].TST -= _tstVal;
totalTST -= _tstVal; // <- AUDIT - add here
}
if (_eurosVal > 0) {
IERC20(EUROs).safeTransfer(msg.sender, _eurosVal);
positions[msg.sender].EUROs -= _eurosVal;
}
if (empty(positions[msg.sender])) deletePosition(positions[msg.sender]);
}
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.