subtract values in the if statement to avoid a useless operation #124
Labels
bug
Something isn't working
G (Gas Optimization)
resolved
Finding has been patched by sponsor (sponsor pls link to PR containing fix)
sponsor confirmed
Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")
Handle
OriDabush
Vulnerability details
TimeswapPair.sol - Gas Optimization
Lines 289-290 can be transferred into the if statements to avoid subtract 0 from the variables.
code before:
pool.state.reserves.asset -= tokensOut.asset;
pool.state.reserves.collateral -= tokensOut.collateral;
if (tokensOut.asset > 0) asset.safeTransfer(assetTo, tokensOut.asset);
if (tokensOut.collateral > 0) collateral.safeTransfer(collateralTo, tokensOut.collateral);
code after:
if (tokensOut.asset > 0) {
asset.safeTransfer(assetTo, tokensOut.asset);
pool.state.reserves.asset -= tokensOut.asset;
}
if (tokensOut.collateral > 0) {
collateral.safeTransfer(collateralTo, tokensOut.collateral);
pool.state.reserves.collateral -= tokensOut.collateral;
}
The text was updated successfully, but these errors were encountered: