code-423n4 / 2021-12-defiprotocol-findings

0 stars 0 forks source link

`handleFees` can be implemented more efficiently #143

Closed code423n4 closed 2 years ago

code423n4 commented 2 years ago

Handle

0x0x0x

Vulnerability details

In handleFees, when timeDiff = 0 the calculations for the fee are not required. Inside last else statement can an if statement added to avoid not needed calculations. This would save gas especially, when the contract is used more than once in a single block.

So this part

} else {
            uint256 timeDiff = (block.timestamp - lastFee);

Can be replaced with the following:

} else {
            uint256 timeDiff = (block.timestamp - lastFee);
                        if (timeDiff == 0) {
                                    return;
                        }

Or alternatively all remaining calculations can be inside an if (timeDiff != 0).

0xleastwood commented 2 years ago

Duplicate of #110