Platform: Code4rena
Start Date: 26/09/2022
Pot Size: $50,000 USDC
Total HM: 13
Participants: 113
Period: 5 days
Judge: 0xean
Total Solo HM: 6
Id: 166
League: ETH
Rank: 68/113
Findings: 1
Award: $52.04
🌟 Selected for report: 0
🚀 Solo Findings: 0
🌟 Selected for report: 0xNazgul
Also found by: 0x1f8b, 0x52, 0xDecorativePineapple, 0xSmartContract, 0xmatt, Aeros, Aymen0909, Bnke0x0, Chom, CodingNameKiki, Deivitto, DimitarDimitrov, IllIllI, JC, Jeiwan, Lambda, Matin, Migue, Mukund, Ocean_Sky, Olivierdem, RaymondFam, RockingMiles, Rolezn, Ruhum, Satyam_Sharma, Shinchan, Tomo, Trabajo_de_mates, V_B, Waze, __141345__, a12jmx, ajtra, asutorufos, aysha, brgltd, bulej93, carrotsmuggler, catchup, cccz, chrisdior4, cryptonue, cryptphi, d3e4, defsec, delfin454000, durianSausage, erictee, fatherOfBlocks, gogo, kaden, karanctf, ladboy233, lukris02, mahdikarimi, martin, mics, natzuu, oyc_109, p_crypt0, pedr02b2, rbserver, reassor, rotcivegaf, rvierdiiev, sikorico, slowmoses, sorrynotsorry, tnevler, trustindistrust
52.0364 USDC - $52.04
In AlgebraPool.sol, there is an excessive compulsion to check for fee reductions.
The initial if statement:
if (amount0 | amount1 != 0) { position.fees0 = positionFees0 - amount0; position.fees1 = positionFees1 - amount1; } if (amount0 > 0) { TransferHelper.safeTransfer(token0, recipient, amount0); } if (amount1 > 0) { TransferHelper.safeTransfer(token1, recipient, amount1); }
Can become:
if (amount0 > 0) { position.fees0 = positionFees0 - amount0; TransferHelper.safeTransfer(token0, recipient, amount0); } if (amount1 > 0) { position.fees1 = positionFees1 - amount1; TransferHelper.safeTransfer(token0, recipient, amount0); }
This is both more simple to read and more effiicient since it deals with one less if statement.
The bitwise |
check in the first if statement is redundant, since it's essentially saying:
if amount0, or amount1, contains anything which isn't 0x000000 then update fees.
Getting rid of this check would not impact the function of the code, since the amounts are checked to be above zero straight after.
#0 - vladyan18
2022-10-04T16:33:07Z
Please note that fees are packed in single storage slot