Platform: Code4rena
Start Date: 12/09/2022
Pot Size: $75,000 USDC
Total HM: 19
Participants: 110
Period: 7 days
Judge: HardlyDifficult
Total Solo HM: 9
Id: 160
League: ETH
Rank: 100/110
Findings: 1
Award: $35.35
🌟 Selected for report: 0
🚀 Solo Findings: 0
🌟 Selected for report: CertoraInc
Also found by: 0x1f8b, 0x4non, 0x5rings, 0x85102, 0xNazgul, 0xSmartContract, 0xkatana, Amithuddar, Aymen0909, B2, Bnke0x0, CRYP70, Chom, ChristianKuri, CodingNameKiki, Deivitto, Diraco, Fitraldys, Funen, IgnacioB, JAGADESH, JC, Lambda, LeoS, Matin, Metatron, MiloTruck, Noah3o6, Ocean_Sky, Olivierdem, PaludoX0, RaymondFam, ReyAdmirado, Rohan16, Rolezn, Saintcode_, Sm4rty, SnowMan, StevenL, Tomio, Tomo, V_B, Waze, __141345__, ajtra, asutorufos, aysha, brgltd, bulej93, c3phas, ch0bu, d3e4, delfin454000, dharma09, djxploit, erictee, fatherOfBlocks, francoHacker, gianganhnguyen, gogo, got_targ, ignacio, jag, karanctf, ladboy233, leosathya, lukris02, m_Rassska, malinariy, martin, natzuu, pashov, peanuts, peiw, pfapostol, prasantgupta52, robee, simon135, slowmoses, sryysryy, tnevler
35.3477 USDC - $35.35
If a variable is not set/initialized, it is assumed to have the default value (0, false, 0x0 etc depending on the data type). Explicitly initializing it with its default value is an anti-pattern and wastes gas.
Instances include:
ArbitraryCallsProposal.sol#L52 ArbitraryCallsProposal.sol#L61 ArbitraryCallsProposal.sol#L78
TokenDistributor.sol#L230 TokenDistributor.sol#L239
ListOnOpenseaProposal.sol#L291
Crowdfund.sol#L180 Crowdfund.sol#L242 Crowdfund.sol#L300 Crowdfund.sol#L348
PartyGovernance.sol#L306
the equivalent of (a && b)
is !(!a || !b)
Even with the 10k Optimizer enabled, OR
conditions cost less than their equivalent AND
conditions.
Compare in Remix this example contract’s 2 diffs (or any test contract of your choice, as experimentation always shows the same results).
pragma solidity 0.8.13; contract Test { bool isOpen; bool channelPreviouslyOpen; function boolTest() external view returns (uint) { - if (isOpen && !channelPreviouslyOpen) { + if (!(!isOpen || channelPreviouslyOpen)) { return 1; - } else if (!isOpen && channelPreviouslyOpen) { + } else if (!(isOpen || !channelPreviouslyOpen)) { return 2; } } function setBools(bool _isOpen, bool _channelPreviouslyOpen) external { isOpen = _isOpen; channelPreviouslyOpen= _channelPreviouslyOpen; } }
effectively saving 12 gas.
ListOnZoraProposal.sol#L96 ListOnZoraProposal.sol#L98 ListOnZoraProposal.sol#L103 ListOnOpenseaProposal.sol#L204 ListOnOpenseaProposal.sol#L206
Use !(minDuration == 0 || !data.duration < minDuration)
instead of (minDuration != 0 && data.duration < minDuration)
Use !(lc == CrowdfundLifecycle.Active || lc == CrowdfundLifecycle.Expired)
instead of (lc != CrowdfundLifecycle.Active && lc != CrowdfundLifecycle.Expired)
Use !(maximumPrice_ == 0 || !callValue > maximumPrice_)
instead of (maximumPrice_ != 0 && callValue > maximumPrice_)
ListOnOpenseaProposal.sol#L140
Use !(isUnanimous || !LibProposal.isTokenIdPrecious(data.token,data.tokenId,params.preciousTokens,params.preciousTokenIds)
instead of (!isUnanimous &&LibProposal.isTokenIdPrecious(data.token,data.tokenId,params.preciousTokens,params.preciousTokenIds)
Use !(snap.intrinsicVotingPower != 0 || snap.delegatedVotingPower != 0)
instead of (snap.intrinsicVotingPower == 0 && snap.delegatedVotingPower == 0)
Use !(msg.sender == partyDao || isHost[msg.sender])
instead of (msg.sender != partyDao && !isHost[msg.sender])
All instances:
PartyGovernance.sol#L577 PartyGovernance.sol#L600 PartyGovernance.sol#L624 PartyGovernance.sol#L674 PartyGovernance.sol#L856 PartyGovernance.sol#L934 LibProposal.sol#L33