Blur Exchange contest - 0xNazgul's results

An NFT exchange for the Blur marketplace.

General Information

Platform: Code4rena

Start Date: 05/10/2022

Pot Size: $50,000 USDC

Total HM: 2

Participants: 80

Period: 5 days

Judge: GalloDaSballo

Id: 168

League: ETH

Blur Exchange

Findings Distribution

Researcher Performance

Rank: 55/80

Findings: 2

Award: $83.13

🌟 Selected for report: 0

🚀 Solo Findings: 0

Awards

50.4817 USDC - $50.48

Labels

bug
QA (Quality Assurance)

External Links

[NAZ-L1] Value Range Validity for Setters

Severity Low Context: BlurExchange.sol#L246

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-L2] Missing Equivalence Checks in Setters

Severity: Low Context: ExecutionDelegate.sol#L36, ExecutionDelegate.sol#L45, BlurExchange.sol#L215, BlurExchange.sol#L224, BlurExchange.sol#L233, BlurExchange.sol#L242

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-L3] Missing Zero-address Validation

Severity: Low Context: ExecutionDelegate.sol#L36, ExecutionDelegate.sol#L45

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-L4] Lack of Event Emission For Critical Functions

Severity: Low Context: ExecutionDelegate.sol#L36, ExecutionDelegate.sol#L45

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-L5] Missing Events In Initialize Functions

Severity: Low Context: BlurExchange.sol#L95

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] Visibility Should Be Before Modifiers

Severity: Informational Context: ExecutionDelegate.sol#L36, ExecutionDelegate.sol#L45, ExecutionDelegate.sol#L75, ExecutionDelegate.sol#L90, ExecutionDelegate.sol#L106, ExecutionDelegate.sol#L121

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-N2] Function && Variable Naming Convention

Severity Informational Context: BlurExchange.sol#L57-L58, MerkleVerifier.sol#L17, MerkleVerifier.sol#L33, MerkleVerifier.sol#L17

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-N3] Code Structure Deviates From Best-Practice

Severity: Informational Context: ExecutionDelegate.sol#L21, EIP712.sol#L112, BlurExchange.sol#L35

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-N4] Line Length

Severity: Informational Context: EIP712.sol#L24, EIP712.sol#L27, BlurExchange.sol#L124, BlurExchange.sol#L205, BlurExchange.sol#L388, BlurExchange.sol#L425, BlurExchange.sol#L429

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] Missing Visibility

Severity: Informational Context: ReentrancyGuarded.sol#L10 (Can be private), EIP712.sol#L33, EIP712.sol#L37

Description: There is missing visibility on some state variables that are default to public. It's best practice to explicityl mark visibility of state variables and can save gas depending on the marking.

Recommendation: Consider explicitly marking visibility of state.

[NAZ-N6] Code Contains Empty Blocks

Severity: Informational Context: BlurExchange.sol#L53

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-N7] Unclear Revert Messages

Severity Informational Context: BlurExchange.sol#L134, BlurExchange.sol#L183

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-N8] Use Underscores for Number Literals

Severity: Informational Context: BlurExchange.sol#L59

Description: There are multiple occasions where certain numbers have been hardcoded, either in variables or in the code itself. Large numbers can become hard to read.

Recommendation: Consider using underscores for number literals to improve its readability.

[NAZ-N9] Use of ABIEncoderV2 With 0.8+

Severity: Informational Context: ExecutionDelegate.sol, BlurExchange.sol

Description: ABIEncoderV2 is being stated in a solidity version 0.8+ which is not needed since ABIEncoderV2 is activated by default 0.8+.

Recommendation: Consider removing pragma experimental ABIEncoderV2;.

[NAZ-N10] 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-N11] 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 - GalloDaSballo

2022-10-22T20:30:26Z

[NAZ-L1] Value Range Validity for Setters & [NAZ-L3] Missing Zero-address Validation

L

[NAZ-L2] Missing Equivalence Checks in Setters

NC

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

<img width="310" alt="Screenshot 2022-10-22 at 22 25 00" src="https://user-images.githubusercontent.com/13383782/197361031-22781d83-4d35-4304-afa3-fd15dcaabfb3.png">

[NAZ-L5] Missing Events In Initialize Functions

NC

[NAZ-N1] Visibility Should Be Before Modifiers

NC

[NAZ-N2] Function && Variable Naming Convention

R for the internal / Public functions, disagree for name as they want to use it for a function

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

NC

[NAZ-N4] Line Length

NC

[NAZ-N5] Missing Visibility

NC

[NAZ-N6] Code Contains Empty Blocks

Disputed as they have it for compatibility

[NAZ-N7] Unclear Revert Messages

NC

[NAZ-N8] Use Underscores for Number Literals

NC

[NAZ-N9] Use of ABIEncoderV2 With 0.8+

NC

[NAZ-N10] Missing or Incomplete NatSpec

NC

[NAZ-N11] Older Version Pragma

NC

#1 - GalloDaSballo

2022-10-22T20:30:55Z

1L 1R 11NC

Awards

32.6464 USDC - $32.65

Labels

bug
G (Gas Optimization)

External Links

[NAZ-G1] Use uint Instead of bool for reentrancyLock

Context: ReentrancyGuarded.sol

Description: Use of a bool for setting reentrancy to "lock" and "unlocked" costs more gas than using a uint.

Recommendation: Consider implementing a similar ReentrancyGuard to solmates'

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

Context: PolicyManager.sol#L77, EIP712.sol#L77, BlurExchange.sol#L199, BlurExchange.sol#L476, MerkleVerifier.sol#L38

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

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

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

Context: PolicyManager.sol#L77, EIP712.sol#L77, BlurExchange.sol#L199, BlurExchange.sol#L476, MerkleVerifier.sol#L38

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;
    }
}

Recommendation: Consider doing the increment in the for loop post condition in an unchecked block.

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

Context: EIP712.sol#L77, BlurExchange.sol#L199, BlurExchange.sol#L476, MerkleVerifier.sol#L38

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-G5] 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-G6] 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-G7] 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.

#0 - GalloDaSballo

2022-10-26T21:25:47Z

5k lock 150 rest

5150

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