Closed code423n4 closed 2 years ago
WatchPug
https://github.com/Badger-Finance/ibbtc/blob/49c9564724a0283e6ee0293621902819cacb861a/contracts/Zap.sol#L126-L142
if (numTokens == 2) { uint[2] memory amounts; amounts[idx] = amount; pool.add_liquidity(amounts, 0); } if (numTokens == 3) { uint[3] memory amounts; amounts[idx] = amount; pool.add_liquidity(amounts, 0); } if (numTokens == 4) { uint[4] memory amounts; amounts[idx] = amount; pool.add_liquidity(amounts, 0); }
Change to else if can save gas:
else if
if (numTokens == 2) { uint[2] memory amounts; amounts[idx] = amount; pool.add_liquidity(amounts, 0); } else if (numTokens == 3) { uint[3] memory amounts; amounts[idx] = amount; pool.add_liquidity(amounts, 0); } else if (numTokens == 4) { uint[4] memory amounts; amounts[idx] = amount; pool.add_liquidity(amounts, 0); }
I would like an explanation
You're stil comparing a condition and you're still making a jump, why is else if cheaper?
duplicate of #76 which contains explanation.
Handle
WatchPug
Vulnerability details
https://github.com/Badger-Finance/ibbtc/blob/49c9564724a0283e6ee0293621902819cacb861a/contracts/Zap.sol#L126-L142
Change to
else if
can save gas: