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: 24/110
Findings: 2
Award: $198.10
๐ Selected for report: 0
๐ Solo Findings: 0
๐ Selected for report: Lambda
Also found by: 0x1f8b, 0x4non, 0x52, 0x5rings, 0xDanielC, 0xNazgul, 0xSmartContract, 0xbepresent, Anth3m, Aymen0909, B2, CRYP70, CertoraInc, Ch_301, Chom, ChristianKuri, CodingNameKiki, Deivitto, Funen, JC, JansenC, Jeiwan, KIntern_NA, MasterCookie, MiloTruck, Olivierdem, PaludoX0, R2, RaymondFam, ReyAdmirado, StevenL, The_GUILD, Tomo, Trust, V_B, __141345__, asutorufos, ayeslick, bin2chen, brgltd, bulej93, c3phas, cccz, ch0bu, cryptphi, csanuragjain, d3e4, delfin454000, djxploit, erictee, fatherOfBlocks, gogo, hansfriese, indijanc, ladboy233, leosathya, lukris02, malinariy, martin, pedr02b2, pfapostol, rvierdiiev, slowmoses, smiling_heretic, tnevler, wagmi
162.669 USDC - $162.67
Severity: Low
Context: Globals.sol#L27
, Globals.sol#L59
, Globals.sol#L63
, Globals.sol#L67
, Globals.sol#L71
, Globals.sol#L75
, Globals.sol#L79
, PartyGovernanceNFT.sol#L169
Description: Several functions update critical parameters that are missing event emission. These should be performed to ensure tracking of changes of such critical parameters.
Recommendation: Consider adding events to functions that change critical parameters.
Severity Low
Context: Globals.sol#L44
Description: Downcasting from uint256/int256 in Solidity does not revert on overflow. This can easily result in undesired exploitation or bugs.
Recommendation: Consider using SafeCast library from OpenZeppelin.
Severity: Low
Context: Globals.sol#L27
, PartyGovernanceNFT.sol#L169
Description: When critical parameters of systems need to be changed, it is required to broadcast the change via event emission and recommended to enforce the changes after a time-delay. This is to allow system users to be aware of such critical changes and give them an opportunity to exit or adjust their engagement with the system accordingly. None of the onlyOwner functions that change critical protocol addresses/parameters have a timelock for a time-delayed change to alert: (1) users and give them a chance to engage/exit protocol if they are not agreeable to the changes (2) team in case of compromised owner(s) and give them a chance to perform incident response.
Recommendation: Users may be surprised when critical parameters are changed. Furthermore, it can erode users' trust since they canโt be sure the protocol rules wonโt be changed later on. Compromised owner keys may be used to change protocol addresses/parameters to benefit attackers. Without a time-delay, authorized owners have no time for any planned incident response.
Severity: Low
Context: Globals.sol#L27
, Globals.sol#L59
, Globals.sol#L63
, Globals.sol#L71
, Globals.sol#L75
, Globals.sol#L79
Description: Setter functions are missing checks to validate if the new value being set is the same as the current value already set in the contract. Such checks will showcase mismatches between on-chain and off-chain states.
Recommendation: This may hinder detecting discrepancies between on-chain and off-chain states leading to flawed assumptions of on-chain state and protocol behavior.
Severity Low
Context: Globals.sol#L27
, PartyGovernanceNFT.sol#L169
Description: This function transfers the ownership of the contract in a single step. There is no way to reverse a one-step transfer of ownership to an address without an owner. This would not be the case if ownership were transferred through a two-step process in which an owner proposed a transfer and the prospective recipient accepted it.
Recommendation: Consider using a two-step process for ownership transfers.
Severity: Low
Context: Proxy.sol#L17
, Proxy.sol#L26
, PartyFactory.sol#L22
, FractionalizeProposal.sol#L35
, CrowdfundFactory.sol#L25
, CrowdfundNFT.sol#L34
, PartyGovernanceNFT.sol#L44
, PartyGovernanceNFT.sol#L62
,ListOnZoraProposal.sol#L70
, BuyCrowdfundBase.sol#L78
, BuyCrowdfundBase.sol#L80-L82
, BuyCrowdfund.sol#L87
, CollectionBuyCrowdfund.sol#L101
, ProposalExecutionEngine.sol#L83
, TokenDistributor.sol#L93
, Globals.sol#L23
, Globals.sol#L27
, Globals.sol#L67
, Globals.sol#L79
Description: Lack of zero-address validation on address parameters may lead to transaction reverts, waste gas, require resubmission of transactions and may even force contract redeployments in certain cases within the protocol.
Recommendation: Consider adding explicit zero-address validation on input parameters of address type.
Severity Low
Context: BuyCrowdfundBase.sol#L73-L74
, BuyCrowdfundBase.sol#L79
Description: These functions doesn't have any checks to ensure that the variables being set is within some kind of value range.
Recommendation: Each variable input parameter updated should have it's own value range checks to ensure their validity.
Severity: Low
Context: ReadOnlyDelegateCall.sol#L30
, FractionalizeProposal.sol#L67
, CrowdfundNFT.sol#L166
, PartyGovernanceNFT.sol#L179
, ListOnZoraProposal.sol#L120
, ProposalExecutionEngine.sol#L142
, TokenDistributor.sol#L385
, TokenDistributor.sol#L411
, ListOnOpenseaProposal.sol#L221
, ListOnOpenseaProposal.sol#L302
, PartyGovernance.sol#L504
Description: The Solidity assert() function is meant to assert invariants. Properly functioning code should never reach a failing assert statement. A reachable assertion can mean one of two things:
1). A bug exists in the contract that allows it to enter an invalid state; 2). The assert statement is used incorrectly, e.g. to validate inputs.
Recommendation: Consider whether the condition checked in the assert() is actually an invariant. If not, replace the assert() statement with a require() statement. If the exception is indeed caused by unexpected behaviour of the code, fix the underlying bug(s) that allow the assertion to be violated.
receive()
Function Should Emit An EventSeverity: Low
Context: Party.sol#L47
, AuctionCrowdfund.sol#L144
Description:
Consider emitting an event inside this function with msg.sender
and msg.value
as the parameters. This would make it easier to track incoming ether transfers.
Recommendation:
Consider adding events to the receive()
functions.
Severity: Low
Context: BuyCrowdfundBase.sol#L70
, CrowdfundNFT.sol#L39
, AuctionCrowdfund.sol#L110
, ProposalExecutionEngine.sol#L99
, ProposalStorage.sol#L33
, BuyCrowdfund.sol#L68
, CollectionBuyCrowdfund.sol#L83
Description: None of the initialize functions emit emit init-specific events. They all however have the initializer modifier (from Initializable) so that they can be called only once. Off-chain monitoring of calls to these critical functions is not possible.
Recommendation: It is recommended to emit events in your initialization functions.
Severity Informational
Context: ProposalStorage.sol#L24
, AuctionCrowdfund.sol#L287
, ProposalExecutionEngine.sol#L110
, PartyGovernance.sol#L385
Description: The linked function(s) have a named return that is not used. Using both named returns and a return statement isn't necessary.
Recommendation: Removing one of those can improve code clarity.
Severity: Informational
Context: PartyFactory.sol#L29-L30
, TokenDistributor.sol#L225
, TokenDistributor.sol#L236
Description: These fail to perform input validation on arrays to verify the lengths match. A mismatch could lead to an exception or undefined behavior.
Recommendation: Perform input validation on the arrays to verify that the lengths match.
Severity: Informational
Context: TokenDistributor.sol#L307
, TokenDistributor.sol#L321
, TokenDistributor.sol#L327
Description: Visibility keyword should be before the list of modifiers as per best practice.
Recommendation: Consider moving the visibility keyword before the list of modifiers.
Severity: Informational
Context: CrowdfundFactory.sol#L18
, ProposalExecutionEngine.sol#L73
, Crowdfund.sol#L78
Description: Max line length must be no more than 120 but many lines are extended past this length.
Recommendation: Consider cutting down the line length below 120.
Severity: Informational
Context: Party.sol#L28
, Party.sol#L47
, BuyCrowdfund.sol#L62
, CollectionBuyCrowdfund.sol#L77
, CrowdfundNFT.sol#L52
, CrowdfundNFT.sol#L59
, CrowdfundNFT.sol#L66
, CrowdfundNFT.sol#L73
, CrowdfundNFT.sol#L80
, AuctionCrowdfund.sol#L104
, AuctionCrowdfund.sol#L144
, BuyCrowdfundBase.sol#L67
Description: It's best practice that when there is an empty block, to add a comment in the block explaining why it's empty.
Recommendation:
Consider adding /* Comment on why */
to the empty blocks.
Severity Informational
Context: Proxy.sol#L12
, PartyFactory.sol#L18
, ProposalStorage.sol#L18-L19
, FractionalizeProposal.sol#L31
, CrowdfundFactory.sol#L22
, CrowdfundNFT.sol#L17
, PartyGovernanceNFT.sol#L24
, ListOnZoraProposal.sol#L58
, ListOnZoraProposal.sol#L61
, ListOnZoraProposal.sol#L64
, ListOnZoraProposal.sol#L67
, ProposalExecutionEngine.sol#L77
, TokenDistributor.sol#L55
, TokenDistributor.sol#L59
, Implementation.sol#L9
, ListOnOpenseaProposal.sol#L100
, ListOnOpenseaProposal.sol#L102
, ListOnOpenseaProposal.sol#L105
, Crowdfund.sol#L87
, PartyGovernance.sol#L189-L190
, PartyGovernance.sol#L194
, LibProposal.sol#L7
Description:
The linked variables do not conform to the standard naming convention of Solidity whereby functions and variable names(local and state) utilize the mixedCase
format unless variables are declared as constant
in which case they utilize the UPPER_CASE_WITH_UNDERSCORES
format. Private variables and functions should lead with an _underscore
.
Recommendation: Consider naming conventions utilized by the linked statements are adjusted to reflect the correct type of declaration according to the Solidity style guide.
Severity: Informational
Context: ProposalStorage.sol#L29
, FractionalizeProposal.sol#L31
, CrowdfundFactory.sol#L22
, AuctionCrowdfund.sol#L144
Description: The best-practice layout for a contract should follow the following order: state variables, events, modifiers, constructor and functions. Function ordering helps readers identify which functions they can call and find constructor and fallback functions easier. Functions should be grouped according to their visibility and ordered as: constructor, receive function (if exists), fallback function (if exists), external, public, internal, private. Functions should then further be ordered with view functions coming after the non-view labeled ones.
Recommendation: Consider adopting recommended best-practice for code structure and layout.
Severity Informational
Context: CrowdfundFactory.sol#L16-L18
, ListOnZoraProposal.sol#L53
, ArbitraryCallsProposal.sol#L35
, BuyCrowdfundBase.sol#L52
, ListOnOpenseaProposal.sol#L63-L82
, Crowdfund.sol#L82-L83
, PartyGovernance.sol#L151-L162
Description: Parameters of certain events are expected to be indexed so that theyโre included in the blockโs bloom filter for faster access. Failure to do so might confuse off-chain tooling looking for such indexed events.
Recommendation: Consider adding the indexed keyword to event parameters that should include it.
Severity Informational
Context: ReadOnlyDelegateCall.sol#L20
, ProposalExecutionEngine.sol#L246-L247
Description: Some revert messages are unclear which can lead to confusion. Unclear revert messages may cause misunderstandings on reverted transactions.
Recommendation: Consider making revert messages more clear.
Severity: Informational
Context: BuyCrowdfundBase.sol#L31 (receieves => receives)
, Crowdfund.sol#L46 (recipeint => recipient)
Description: Spelling errors in comments can cause confusion to both users and developers.
Recommendation: Consider checking all misspellings to ensure they are corrected.
Severity: Informational
Context: All Contracts
Description: Some functions are missing @notice/@dev NatSpec comments for the function, @param for all/some of their parameters and @return for return values. Given that NatSpec is an important part of code documentation, this affects code comprehension, auditability and usability.
Recommendation: Consider adding in full NatSpec comments for all functions to have complete code documentation for future use.
Severity: Informational
Context: All Contracts
Description: Contracts should be deployed with the same compiler version and flags that they have been tested with thoroughly. Locking the pragma helps to ensure that contracts do not accidentally get deployed using, for example, an outdated compiler version that might introduce bugs that affect the contract system negatively.
Recommendation: Consider locking the pragma version.
Severity: Informational
Context: All Contracts
Description: Using very old versions of Solidity prevents benefits of bug fixes and newer security checks. Using the latest versions might make contracts susceptible to undiscovered compiler bugs.
Recommendation: Consider using the most recent version.
#0 - HardlyDifficult
2022-10-04T09:48:43Z
๐ 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.4285 USDC - $35.43
2**256 - 1 && type(uint256).max
When 2**255
Can Be UsedContext: ProposalExecutionEngine.sol#L161
Description:
Infinity can also be represented via ``2255, it's hex representation is
0x8000000000000000000000000000000000000000000000000000000000000000while
2256 - 1is
0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff`. Then main difference is and where the gas savings come from is, zeros are cheaper than non-zero values in hex representation.
Recommendation:
Use 2**255
instead of 2**256 - 1
to save gas on deployment.
++index
instead of index++
to increment a loop counterContext: CollectionBuyCrowdfund.sol#L62
Description:
Due to reduced stack operations, using ++index
saves 5 gas per iteration.
Recommendation:
Use ++index
to increment a loop counter.
Context: CollectionBuyCrowdfund.sol#L62
, ArbitraryCallsProposal.sol#L52
, ArbitraryCallsProposal.sol#L61
, ArbitraryCallsProposal.sol#L78
, TokenDistributor.sol#L230
, TokenDistributor.sol#L239
, Crowdfund.sol#L180
, Crowdfund.sol#L242
, Crowdfund.sol#L300
, Crowdfund.sol#L348
, PartyGovernance.sol#L306
, ListOnOpenseaProposal.sol#L291
, LibProposal.sol#L14
, LibProposal.sol#L32
Description:
(This is only relevant if you are using the default solidity checked arithmetic). i++
involves checked arithmetic, which is not required. This is because the value of i
is always strictly less than length <= 2**256 - 1. Therefore, the theoretical maximum value of i
to enter the for-loop body is 2**256 - 2
. This means that the i++
in the for loop can never overflow. Regardless, the overflow checks are performed by the compiler.
Unfortunately, the Solidity optimizer is not smart enough to detect this and remove the checks. One can manually do this by:
for (uint i = 0; i < length; ) { // do something that doesn't change the value of i unchecked { ++i; } }
Note that itโs important that the call to unchecked_inc
is inlined. This is only possible for solidity versions starting from 0.8.2
.
Recommendation: Consider doing the increment in the for loop post condition in an unchecked block.
Context: CollectionBuyCrowdfund.sol#L62
, ArbitraryCallsProposal.sol#L52
, ArbitraryCallsProposal.sol#L61
, ArbitraryCallsProposal.sol#L78
, TokenDistributor.sol#L230
, TokenDistributor.sol#L239
, Crowdfund.sol#L180
, Crowdfund.sol#L300
, PartyGovernance.sol#L306
, ListOnOpenseaProposal.sol#L291
, LibProposal.sol#L14
, LibProposal.sol#L32
Description: One can save gas by caching the array length (in stack) and using that set variable in the loop. Replace state variable reads and writes within loops with local variable reads and writes. This is done by assigning state variable values to new local variables, reading and/or writing the local variables in a loop, then after the loop assigning any changed local variables to their equivalent state variables.
Recommendation:
Simply do something like so before the for loop: uint length = variable.length
. Then add length
in place of variable.length
in the for loop.
Context: All Contracts
Description:
You can cut out 10 opcodes in the creation-time EVM bytecode if you declare a constructor payable. Making the constructor payable eliminates the need for an initial check of msg.value == 0
and saves 21 gas on deployment with no security risks.
Recommendation: Set the constructor to payable.
Context: All Contracts
Description: To save some gas the use of custom errors leads to cheaper deploy time cost and run time cost. The run time cost is only relevant when the revert condition is met.
Recommendation: Use Custom Errors instead of strings.
Context: All Contracts
Description:
Contracts most called functions could simply save gas by function ordering via Method ID. Calling a function at runtime will be cheaper if the function is positioned earlier in the order (has a relatively lower Method ID) because 22 gas are added to the cost of a function for every position that came before it. The caller can save on gas if you prioritize most called functions. One could use This tool
to help find alternative function names with lower Method IDs while keeping the original name intact.
Recommendation:
Find a lower method ID name for the most called functions for example mostCalled()
vs. mostCalled_41q()
is cheaper by 44 gas.
Context: All Contracts
Description: Using newer compiler versions and the optimizer gives gas optimizations and additional safety checks for free!
The advantages of versions =0.8.*= over =<0.8.0= are:
Low level inliner
from =0.8.2=, leads to cheaper runtime gas.
Especially relevant when the contract has small functions. For
example, OpenZeppelin libraries typically have a lot of small
helper functions and if they are not inlined, they cost an
additional 20 to 40 gas because of 2 extra =jump= instructions and
additional stack operations needed for function calls.Optimizer improvements in packed structs
: Before =0.8.3=, storing
packed structs, in some cases used an additional storage read
operation. After EIP-2929
, if the slot was already cold, this
means unnecessary stack operations and extra deploy time costs.
However, if the slot was already warm, this means additional cost
of =100= gas alongside the same unnecessary stack operations and
extra deploy time costs.Custom errors
from =0.8.4=, leads to cheaper deploy time cost and
run time cost. Note: the run time cost is only relevant when the
revert condition is met. In short, replace revert strings by
custom errors.Recommendation: Upgrade to at least 0.8.4 for the additional benefits.