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
Rank: 32/96
Findings: 2
Award: $47.59
π Selected for report: 0
π Solo Findings: 0
π Selected for report: IllIllI
Also found by: 0x1f8b, 0x29A, 0x52, 0xNazgul, 0xNineDec, 0xc0ffEE, 0xf15ers, 0xkatana, BowTiedWardens, Chom, ElKu, Funen, GalloDaSballo, JC, JMukesh, JohnSmith, Lambda, Limbooo, MadWookie, MiloTruck, Nethermind, Noah3o6, Nyamcil, Picodes, PwnedNoMore, Randyyy, RoiEvenHaim, SmartSek, StErMi, Tadashi, TerrierLover, TomJ, Tomio, Treasure-Seeker, UnusualTurtle, Varun_Verma, Wayne, Waze, _Adam, apostle0x01, asutorufos, berndartmueller, c3phas, catchup, cccz, cloudjunky, codexploder, cryptphi, defsec, delfin454000, dipp, ellahi, exd0tpy, fatherOfBlocks, hansfriese, hyh, joestakey, kebabsec, kenta, masterchief, minhquanym, naps62, oyc_109, pashov, peritoflores, reassor, rfa, robee, sach1r0, saian, sashik_eth, shenwilly, simon135, slywaters, sorrynotsorry, sseefried, unforgiven, xiaoming90, ych18, zuhaibmohd, zzzitron
29.1064 USDC - $29.11
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.
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 EventSeverity: 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.
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.
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.
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.
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.
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.
π Selected for report: IllIllI
Also found by: 0v3rf10w, 0x1f8b, 0x29A, 0xKitsune, 0xNazgul, 0xf15ers, 0xkatana, 8olidity, ACai, BowTiedWardens, Chandr, Chom, ElKu, Fitraldys, Funen, IgnacioB, JC, Lambda, Limbooo, MiloTruck, Noah3o6, Nyamcil, Picodes, Randyyy, SmartSek, StErMi, TerrierLover, TomJ, Tomio, UnusualTurtle, Waze, _Adam, ajtra, c3phas, cRat1st0s, catchup, codexploder, cryptphi, defsec, delfin454000, ellahi, exd0tpy, fatherOfBlocks, hansfriese, joestakey, kebabsec, kenta, m_Rassska, minhquanym, oyc_109, pashov, reassor, rfa, robee, sach1r0, saian, sashik_eth, simon135, slywaters, ych18, ynnad, zuhaibmohd
18.4845 USDC - $18.48
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.
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.
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.
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:
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.