Foundation Drop contest - Trabajo_de_mates's results

Foundation is a web3 destination.

General Information

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

Foundation

Findings Distribution

Researcher Performance

Rank: 91/108

Findings: 1

Award: $20.68

馃専 Selected for report: 0

馃殌 Solo Findings: 0

##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.

AuditHub

A portfolio for auditors, a security profile for protocols, a hub for web3 security.

Built bymalatrax 漏 2024

Auditors

Browse

Contests

Browse

Get in touch

ContactTwitter