Platform: Code4rena
Start Date: 11/08/2022
Pot Size: $40,000 USDC
Total HM: 8
Participants: 108
Period: 4 days
Judge: hickuphh3
Total Solo HM: 2
Id: 152
League: ETH
Rank: 91/108
Findings: 1
Award: $20.68
馃専 Selected for report: 0
馃殌 Solo Findings: 0
馃専 Selected for report: Dravee
Also found by: 0x040, 0x1f8b, 0xDjango, 0xHarry, 0xNazgul, 0xSmartContract, 0xbepresent, 0xkatana, Amithuddar, Aymen0909, Bnke0x0, Chom, CodingNameKiki, Deivitto, DevABDee, Diraco, ElKu, Fitraldys, Funen, IllIllI, JC, LeoS, Metatron, MiloTruck, Noah3o6, ReyAdmirado, Rohan16, Rolezn, Saw-mon_and_Natalie, Sm4rty, SpaceCake, TomJ, Tomio, Trabajo_de_mates, Waze, Yiko, __141345__, ajtra, apostle0x01, bobirichman, brgltd, bulej93, c3phas, cRat1st0s, carlitox477, d3e4, durianSausage, erictee, fatherOfBlocks, gerdusx, gogo, hakerbaya, ignacio, jag, joestakey, ladboy233, medikko, mics, newfork01, oyc_109, pfapostol, robee, rvierdiiev, sach1r0, saian, samruna, sikorico, simon135, wagmi, zeesaw, zkhorse, zuhaibmohd
20.6764 USDC - $20.68
##USING > 0 COSTS MORE GAS THAN != 0 this saves 6 gas per loop iteration instance 4 instances line 88, 130, 131 NFTDropCollection.sol line 244 MarketFees.sol
##USING >= 2 COSTS MORE GAS THAN > 1 2 instances line 130, 131 PercentSplitETH.sol
##CHEAPER FOR LOOPS - 25 TO 80 GAS PER INSTANCE You can get cheaper for loops (at least 25 gas, however can be up to 80 gas under certain conditions), by rewriting:
for (uint256 i = 0; i < orders.length; /** NOTE: Removed i++ **/ ) { // Do the thing // Unchecked pre-increment is cheapest unchecked { ++i; } }
1 instance line 198, MarketFees.sol
##<ARRAY>.LENGTH SHOULD NOT BE LOOKED UP IN EVERY LOOP OF A FOR-LOOP 4 instances line 126, 198, 484, 503 MarketFees.sol
##IT COST MORE GAS TO CHECK ADDRESS(0) != buyReferrer BEFORE buyReferrer != msg.sender && buyReferrer != seller && buyReferrer != creator BECAUSE IT IS LESS PROBABLE THAT buyReferrer == address(0) 1 instance line 522 MarketFees.sol
##USING PRIVATE RATHER THAN PUBLIC FOR CONSTANTS, SAVES GAS If needed, the value can be read from the verified contract source code. Savings are due to the compiler not having to create non-payable getter functions for deployment calldata, and not adding another entry to the method ID table -1 instance line 70 NFTDropMarketFixedPriceSale.sol
#0 - HardlyDifficult
2022-08-19T16:07:57Z
Use != 0 instead of > 0
Invalid. We tested the recommendation and got the following results:
createNFTDropCollection gas reporter results: using > 0 (current): - 319246 路 319578 路 319361 using != 0 (recommendation): - 319252 路 319584 路 319367 impact: +6 gas
SING >= 2 COSTS MORE GAS THAN > 1
Fair point, will consider a change here.
unchecked loop in
getFeesAndRecipients
getFeesAndRecipients
is a read only function not intended to be used on-chain, but as a best practice we will add unchecked there as well.
Cache Array Length Outside of Loop
May be theoretically valid, but won't fix. I tested this: gas-reporter and our gas-stories suite is reporting a small regression using this technique. It also hurts readability a bit so we wouldn't want to include it unless it was a clear win.
IT COST MORE GAS TO CHECK
Disagree. buyReferrer == address(0) is the most common scenario.
Using private rather than public for constants to saves gas.
Agree but won't fix. For ease of use and consistency we will continue to expose some constants publicly.