ENS contest - 0xNazgul's results

Decentralised naming for wallets, websites, & more.

General Information

Platform: Code4rena

Start Date: 12/07/2022

Pot Size: $75,000 USDC

Total HM: 16

Participants: 100

Period: 7 days

Judge: LSDan

Total Solo HM: 7

Id: 145

League: ETH

ENS

Findings Distribution

Researcher Performance

Rank: 48/100

Findings: 2

Award: $123.53

🌟 Selected for report: 0

πŸš€ Solo Findings: 0

Missing Equivalence Checks in Setters

Severity: Low Context: DNSSECImpl.sol#L58-L72, ReverseRegistrar.sol#L51-L57

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.

Commented Out Code

Severity: Informational Context: ReverseRegistrar.sol#L16

Description: There is commented code that makes the code messy and unneeded.

Recommendation: Remove the commented out code.

TODOs Left In The Code

Severity: Informational Context: DNSSECImpl.sol#L238

Description: There should never be any TODOs in the code when deploying.

Recommendation: Finish the TODOs before deploying.

Missing or Incomplete NatSpec

Severity: Informational Context: SHA1.sol, Owned.sol, DNSSEC.sol, ETHRegistrarController.sol, ERC1155Fuse.sol, Controllable.sol`

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.

Spelling Errors

Severity: Informational Context: BytesUtils.sol#L35 (codepoints => code points), RRUtils.sol#L282 (bitshifting => bit shifting), ReverseRegistrar.sol#L40 (authorised => authorized), ReverseRegistrar.sol#L46 (authorised => authorized), ReverseRegistrar.sol#L80 (authorised => authorized), ReverseRegistrar.sol#L126 (authorised => authorized), ReverseRegistrar.sol#L156 (optimised => optimized), NameWrapper.sol#L152 (Unauthorised => Unauthorized), NameWrapper.sol#L202 (authorised => authorized), NameWrapper.sol#L241 (authorised => authorized), NameWrapper.sol#L266 (authorised => authorized), NameWrapper.sol#L282 (_normaliseExpiry => _normalizeExpiry), NameWrapper.sol#L289 (authorised => authorized), NameWrapper.sol#L315 (Unauthorised => Unauthorized), NameWrapper.sol#L370 (PARENT_CANOT_CONTROL => PARENT_CANNOT_CONTROL), NameWrapper.sol#L381 (Unauthorised => Unauthorized), NameWrapper.sol#L482 (_normaliseExpiry => _normalizeExpiry), NameWrapper.sol#L518 (_getDataAndNormaliseExpiry => _getDataAndNormalizeExpiry), NameWrapper.sol#L534 (regsitry => registry), NameWrapper.sol#L554 (_getDataAndNormaliseExpiry => _getDataAndNormalizeExpiry), NameWrapper.sol#L825 (_getDataAndNormaliseExpiry => _getDataAndNormalizeExpiry), NameWrapper.sol#L842 (_normaliseExpiry => _normalizeExpiry), NameWrapper.sol#L846 (_getETH2LDDataAndNormaliseExpiry => _getETH2LDDataAndNormalizeExpiry), NameWrapper.sol#L863 (_normaliseExpiry => _normalizeExpiry), NameWrapper.sol#L867 (_normaliseExpiry => _normalizeExpiry), NameWrapper.sol#L897 (_getETH2LDDataAndNormaliseExpiry => _getETH2LDDataAndNormalizeExpiry)

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

Recommendation: Check all misspellings to ensure they are corrected.

Use of ABIEncoderV2 With 0.8+

Severity: Informational Context: DNSSECImpl.sol, DNSSEC.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: remove pragma experimental ABIEncoderV2;.

Missing SPDX License Identifier

Severity: Informational Context: IBaseRegistrar.sol

Description: This contract is missing the SPDX license Identifier before the pragma version.

Recommendation: Consider adding the SPDX license.

Missing Pragma Version

Severity: Informational Context: IBaseRegistrar.sol

Description: This contract is missing the pragma version.

Recommendation: Consider adding the pragma version.

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

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 - dmvt

2022-09-08T10:57:53Z

British English spellings should not be considered spelling errors.

Use of Custom Errors Instead of String

Context: RRUtils.sol, ETHRegistrarController.sol, ReverseRegistrar.sol, BytesUtil.sol, ERC1155Fuse.sol, Controllable.sol

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.

Use ++index instead of index++ to increment a loop counter

Context: BytesUtils.sol#L266, BytesUtils.sol#L313, DNSSECImpl.sol#L93, ETHRegistrarController.sol#L256, ERC1155Fuse.sol#L92, ERC1155Fuse.sol#L205

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

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

The Increment In For Loop Post Condition Can Be Made Unchecked

Context: BytesUtils.sol#L266, BytesUtils.sol#L313, DNSSECImpl.sol#L93, ETHRegistrarController.sol#L256, ERC1155Fuse.sol#L92, ERC1155Fuse.sol#L205

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: BytesUtils.sol#L266, DNSSECImpl.sol#L93, RRUtils.sol#L310, ETHRegistrarController.sol#L256, ERC1155Fuse.sol#L92, ERC1155Fuse.sol#L205

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.

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.

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.

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