DeFiFoundrySolidity
16,653 OP
View results
Submission Details
Severity: low
Invalid

[Gas] Can save gas on failing claimAndSwap if we move require statement first

Summary

Can save gas on failing claimAndSwap if we move require statement first

Vulnerability Details

The original function claimAndSwapchecks the _minOut and _amountClaim but only after claiming. In case when incorrect parameters was supplied, we can save on around 50k gas.

The original function test shows usage of 80235 gas in case of failure

function test_expectRevertClaimAndSwap() public {
uint256 _amountClaim = 10 ether;
uint256 _minOut = 1 wei;
uint256 _routeNumber = 0;
vm.expectRevert();
vm.prank(keeper);
// Gas: 80235
strategy.claimAndSwap(_amountClaim, _minOut, _routeNumber);
}

If we move the require statement and run the test again

function test_expectRevertClaimAndSwap_optimized() public {
uint256 _amountClaim = 10 ether;
uint256 _minOut = 1 wei;
uint256 _routeNumber = 0;
vm.expectRevert();
vm.prank(keeper);
// Gas: 30234
strategy.claimAndSwap_optimized(_amountClaim, _minOut, _routeNumber);
}

Impact

Gas / Low

Tools Used

Manual Review

Recommendations

Move the following line before claiming

require(_minOut > _amountClaim, "minOut too low")
Updates

Appeal created

inallhonesty Lead Judge 10 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity
inallhonesty Lead Judge 10 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Support

FAQs

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