Nibbl contest - 0xNazgul's results

NFT fractionalization protocol with guaranteed liquidity and price based buyout.

General Information

Platform: Code4rena

Start Date: 21/06/2022

Pot Size: $30,000 USDC

Total HM: 12

Participants: 96

Period: 3 days

Judge: HardlyDifficult

Total Solo HM: 5

Id: 140

League: ETH

Nibbl

Findings Distribution

Researcher Performance

Rank: 32/96

Findings: 2

Award: $47.59

🌟 Selected for report: 0

πŸš€ Solo Findings: 0

Lack of Event Emission For Critical Functions

Severity: Low Context: NibblVaultFactory.sol#L106-L169 (All functions in block), NibblVault.sol#L173-L204, Basket.sol#L23-L25

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: Add events to functions that change critical parameters.

Missing Zero-address Validation

Severity: Low Context: ProxyBasket.sol#L19-L21, ProxyVault.sol#L19-L21, Basket.sol#L23-L25

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: Add explicit zero-address validation on input parameters of address type.

receive() Function Should Emit An Event

Severity: Low Context: NibblVaultFactory.sol#L183, NibblVault.sol#L585, Basket.sol#L114, ProxyVault.sol#L56, ProxyBasket.sol#L56

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: Add events to the receive() functions.

Variable Naming Convention

Severity Informational Context: NibblVault.sol#L28

Description: The linked variables do not conform to the standard naming convention of Solidity whereby functions and variable names utilize the camelCase format unless variables are declared as constant in which case they utilize the UPPER_CASE format.

Recommendation: Naming conventions utilized by the linked statements are adjusted to reflect the correct type of declaration according to the Solidity style guide.

Unintuitive Modifier Name

Severity: Informational Context: NibblVault.sol#L128-L133

Description: The modifier name is either not as it describes or can be more descriptive. nonReentrant would be a better choice.

Recommendation: Change all occurrences of this modifier name to be more intuitive.

Spelling Errors

Severity: Informational Context: NibblVault.sol#L125 (reenterancy => reentrancy), NibblVault.sol#L200 (ratio/primaryReseveRatio => ratio/primaryReserveRatio), NibblVault.sol#L250 (continous => continuous), NibblVault.sol#L263 (seconday => secondary), NibblVault.sol#L270 (continous => continuous), NibblVault.sol#L282 (continous => continuous), NibblVault.sol#L359 (Continous => Continuous), NibblVault.sol#L361 (recieve => receive), NibblVault.sol#L461 (tokenholders => token holders), NibblVault.sol#L512 (airdops => airdrops), ProxyVault.sol#L26 (internall => internal), ProxyBasket.sol#L26 (internall => internal)

Description: Spelling errors in comments can cause confusion to both users and developers.

Recommendation: Check all misspellings to ensure they are corrected.

Floating Pragma

Severity: Informational Context: AccessControlMechanism.sol

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: Lock the pragma version.

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: Add in full NatSpec comments for all functions to have complete code documentation for future use.

#0 - HardlyDifficult

2022-07-03T15:12:03Z

#1 - HardlyDifficult

2022-07-03T15:20:35Z

#2 - HardlyDifficult

2022-07-04T15:04:30Z

Good suggestions. Excellent report format.

Functions Visibility Can Be Declared External

Context: NibblVaultFactory.sol#L64-L74, NibblVaultFactory.sol#L76-L78, NibblVaultFactory.sol#L80-L86, NibblVaultFactory.sol#L88-L93

Description: Several functions across multiple contracts have a public visibility and can be marked with external visibility to save gas.

Recommendation: Change the functions visibility to external to save gas.

The Increment In For Loop Post Condition Can Be Made Unchecked

Context: NibblVault.sol#L504-L509, NibblVault.sol#L523-L528, NibblVault.sol#L545-L551, Basket.sol#L43-L47, Basket.sol#L68-L75, Basket.sol#L91-L97

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; i = unchecked_inc(i)) {
    // do something that doesn't change the value of i
}

function unchecked_inc(uint i) returns (uint) {
    unchecked {
        return i + 1;
    }
}

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: The increment in the for loop post condition can be made unchecked.

Catching The Array Length Prior To Loop

Context: NibblVault.sol#L504-L509, NibblVault.sol#L523-L528, NibblVault.sol#L545-L551, Basket.sol#L43-L47, Basket.sol#L68-L75, Basket.sol#L91-L97

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.

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.

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.

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