Open sujithsomraaj opened 7 months ago
I dont fully understand the recommendation. This is changing the logic of the code, not a pure gas optimization. We have three cases:
And we wanted to treat all these three cases separately. So are you suggesting to remove the "currentAllowance" variable to save gas here? Cause your code also removes the branch for case 1 and that would result in a waste of gas since we set allowance to 0 although it is 0 already.
Please comment
Ok this is quite tricky. Cuz the above will safe if there is enough approval. But if there is not enough approval, then it'll be costlier. But the non-appoval case is rare, as we set it to max.
I see your point
How about this one instead?
if (currentAllowance < fromAmount) {
// check if is non-zero
if (currentAllowance != 0) sendingAsset.safeApprove(approveTo, 0);
sendingAsset.safeApprove(approveTo, type(uint256).max);
}
This should be ideal, I guess. efficient in both cases.
Awesome....will go forward with this. With closing this last issue we can consider this audit done.
Appreciate your support and professionalism. Thanks, Sujith.
Context: GenericSwapFacet.sol#L275
Description: The function
_depositAndSwapERC20
approves theswapData.approveTo
address if there is not enough allowance (or) allowance is zero. However the function can be simplified to save some gas.Recommendation: Consider simplifying the logic to save approximately 36 GAS.
LI.FI:
Researcher: