PartyDAO contest - 0xNazgul's results

A protocol for buying, using, and selling NFTs as a group.

General Information

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

PartyDAO

Findings Distribution

Researcher Performance

Rank: 24/110

Findings: 2

Award: $198.10

๐ŸŒŸ Selected for report: 0

๐Ÿš€ Solo Findings: 0

[NAZ-L1] Lack of Event Emission For Critical Functions

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.

[NAZ-L2] Unsafe Type Casting

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.

[NAZ-L3] Missing Time locks

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.

[NAZ-L4] Missing Equivalence Checks in Setters

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.

[NAZ-L5] Lack of Two-Step Process for Critical Operations

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.

[NAZ-L6] Missing Zero-address Validation

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.

[NAZ-L7] Value Range Validity

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.

[NAZ-L8] Assert Violation That Always Incorrect Control Flow Implementation

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.

[NAZ-L9] receive() Function Should Emit An Event

Severity: 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.

[NAZ-L10] Missing Events In Initialize 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.

[NAZ-N1] Function States Named Return But Doesn't Use It

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.

[NAZ-N2] Array length mismatch

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.

[NAZ-N3] Visibility Should Be Before Modifiers

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.

[NAZ-N4] Line Length

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.

[NAZ-N5] Code Contains Empty Blocks

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.

[NAZ-N6] Function && Variable Naming Convention

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.

[NAZ-N7] Code Structure Deviates From Best-Practice

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.

[NAZ-N8] Unindexed Event Parameters

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.

[NAZ-N9] Unclear Revert Messages

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.

[NAZ-N10] Spelling Errors

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.

[NAZ-N11] Missing or Incomplete NatSpec

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.

[NAZ-N12] Floating Pragma

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.

[NAZ-N13] Older Version Pragma

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

[NAZ-G1] Use of 2**256 - 1 && type(uint256).max When 2**255 Can Be Used

Context: ProposalExecutionEngine.sol#L161

Description: Infinity can also be represented via ``2255, it's hex representation is 0x8000000000000000000000000000000000000000000000000000000000000000while2256 - 1is0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff`. 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.

[NAZ-G] Use ++index instead of index++ to increment a loop counter

Context: CollectionBuyCrowdfund.sol#L62

Description: Due to reduced stack operations, using ++index saves 5 gas per iteration.

Recommendation: Use ++index to increment a loop counter.

[NAZ-G2] The Increment In For Loop Post Condition Can Be Made Unchecked

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.

[NAZ-G3] Catching The Array Length Prior To Loop

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.

[NAZ-G4] Setting The Constructor To Payable

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.

[NAZ-G5] Use of Custom Errors Instead of String

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.

[NAZ-G6] Function Ordering via Method ID

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.

[NAZ-G7] Upgrade To At Least 0.8.4

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:

  • Safemath by default from =0.8.0= (can be more gas efficient than /some/ library based safemath).
  • 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.

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