Nested Finance contest - 0xNazgul's results

The one-stop Defi app to build, manage and monetize your portfolio.

General Information

Platform: Code4rena

Start Date: 15/06/2022

Pot Size: $35,000 USDC

Total HM: 1

Participants: 36

Period: 3 days

Judge: Jack the Pug

Total Solo HM: 1

Id: 137

League: ETH

Nested Finance

Findings Distribution

Researcher Performance

Rank: 3/36

Findings: 2

Award: $631.81

🌟 Selected for report: 1

🚀 Solo Findings: 0

Awards

595.6211 USDC - $595.62

Labels

bug
QA (Quality Assurance)
sponsor confirmed
valid

External Links

Missing Zero-address Validation

Severity: Low Context: Withdrawer.sol#L16-L18, YearnCurveVaultOperator.sol#L31-L51

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.

Missing Time locks

Severity: Low Context: NestedFactory.sol#L121-L179, BeefyVaultStorage.sol#L34-L38

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 or incentivizer programs completed early without notice. 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, authorised owners have no time for any planned incident response.

Missing Equivalence Checks in Setters

Severity: Low Context: NestedFactory.sol#L152-L172

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.

receive() Function Should Emit An Event

Severity: Low Context: NestedFactory.sol#L88-L92, Withdrawer.sol#L16-L18

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.

Lack of Event Emission For Critical Functions

Severity: Low Context: BeefyVaultOperator.sol#L36-L67, BeefyVaultOperator.sol#L79-L108, BeefyZapBiswapLPVaultOperator.sol#L46-L77, BeefyZapBiswapLPVaultOperator.sol#L91-L121, BeefyZapUniswapLPVaultOperator.sol#L46-L77, BeefyZapUniswapLPVaultOperator.sol#L91-L121, ParaswapOperator.sol#L22-L48

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.

Unindexed Event Parameters

Severity Informational Context: MixinOperatorResolver.sol#L14, TimelockControllerEmergency.sol#L60

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: Add the indexed keyword to event parameters that should include it.

Lack of solhint To Ignore Warnings

Severity: Informational Context: OwnerProxy.sol#L21-L36, OperatorScripts.sol#L58-L60

Description: solhint is useful to help ignore warnings that aren't really issues. For example the code base has some assembly blocks which promts the warning Linter: Avoid to use inline assembly. It is acceptable only in rare cases. Adding in /* solhint-disable no-inline-assembly */ above it will ignore this warning.

Recommendation: Use solhint to ignore warnings that aren't really issues.

Spelling Errors

Severity: Informational Context: NestedFactory.sol#L51 (withdrawed => withdrawn), NestedFactory.sol#L477 (dont => do not), NestedFactory.sol#L534 (transfered => transferred), NestedFactory.sol#L639 (withdrawed => withdrawal), MixinOperatorResolver.sol#L81 (datas => data(it is already plural)), OwnableProxyDelegation.sol#L17 (setted => set), TimeLockControllerEmergency.sol#L183 (datas => data), TimeLockControllerEmergency.sol#L187 (datas => data), TimeLockControllerEmergency.sol#L224 (datas => data), TimeLockControllerEmergency.sol#L230 (datas => data), TimeLockControllerEmergency.sol#L232 (datas => data), BeefyVaultOperator.sol#L95 (WITHDRAWED => WITHDRAWAL), BeefyZapBiswapLPVaultOperator.sol#L108 (WITHDRAWED => WITHDRAWAL), BeefyZapUniswapLPVaultOperator.sol#L108 (WITHDRAWED => WITHDRAWAL), StakingLPVaultHelpers.sol#L21 (liquitiy => liquidity), StakingLPVaultHelpers.sol#L52 (liquitiy => liquidity), StakingLPVaultHelpers.sol#L85 (liquitiy => liquidity), StakingLPVaultHelpers.sol#L115 (liquitiy => liquidity)

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

Recommendation: Check all misspellings to ensure they are corrected.

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.

Too Recent of a Pragma

Severity Informational Context: All Contracts

Description: Using too recent of a pragma is risky since they are not battle tested. A rise of a bug that wasn't known on release would cause either a hack or a need to secure funds and redeploy.

Recommendation: Use a Pragma version that has been used for sometime. I would suggest 0.8.4 for the decrease of risk and still has the gas optimizations implemented.

#0 - Yashiru

2022-06-22T15:48:12Z

Lack of Event Emission For Critical Functions (Confirmed)

Quality assurance confirmed

#1 - obatirou

2022-06-23T08:50:40Z

Lack of solhint To Ignore Warnings (disputed)

Is not an issue for us

#2 - Yashiru

2022-06-23T09:10:19Z

Too Recent of a Pragma (Acknowledged)

It is a choice between the risks of last update stability and the risk of exposure to known vulnerabilities. We prefer to use the latest pragma.

#3 - obatirou

2022-06-23T09:17:06Z

receive() Function Should Emit An Event (disputed)

An event is already emitted with WETH (Transfer, Deposit,…)

#4 - obatirou

2022-06-23T12:50:17Z

Missing Equivalence Checks in Setters (disputed)

Not necessary

#5 - obatirou

2022-06-24T12:02:39Z

Missing Time locks (disputed)

There is a timelock, see ownership documentation in readme

#6 - obatirou

2022-06-24T14:14:19Z

Unindexed Event Parameters (Acknowledge)

Acknowledge as it costs gas

#7 - Yashiru

2022-06-24T14:18:13Z

Spelling Errors (Duplicated)

Duplicated of #45 at Typos

#8 - Yashiru

2022-06-24T14:50:53Z

Missing Zero-address Validation (Duplicated)

Duplicated of #61 at 2. Missing address(0) checks

#9 - obatirou

2022-06-24T16:04:52Z

#10 - jack-the-pug

2022-07-31T14:54:25Z

L-1: Missing Zero-address Validation

Non-critical.

L-2: Missing Time locks

Invalid.

L-3: Missing Equivalence Checks in Setters

Invalid or Non-critical. No need to make changes.

L-4: receive() Function Should Emit An Event

Seems unnecessary to me.

L-4: Lack of Event Emission For Critical Functions

Non-critical. Make changes when you see fit.

N-1: Unindexed Event Parameters

Non-critical. Make changes when you see fit.

N-2: Lack of solhint To Ignore Warnings

Non-critical.

N-3: Spelling Errors

Valid.

N-4: Missing or Incomplete NatSpec

Non-critical.

N-5: Too Recent of a Pragma

Non-critical.

Awards

36.189 USDC - $36.19

Labels

bug
G (Gas Optimization)
valid

External Links

The Increment In For Loop Post Condition Can Be Made Unchecked

Context: NestedFactory.sol#L121-L130, NestedFactory.sol#L133-L149, NestedFactory.sol#L184-L202, NestedFactory.sol#L243-L275, NestedFactory.sol#L310-L323, NestedFactory.sol#L328-L344, NestedFactory.sol#L353-L391, NestedFactory.sol#L400-L449, NestedFactory.sol#L649-L657, OperatorResolver.sol#L32-L49, OperatorResolver.sol#L52-L70, OperatorResolver.sol#L74-L78, MixinOperatorResolver.sol#L32-L48, MixinOperatorResolver.sol#L51-L70, TimelockControllerEmergency.sol#L65-L95 (For both), TimelockControllerEmergency.sol#L221-L237, TimelockControllerEmergency.sol#L312-L328, OperatorScripts.sol#L52-L86 (For both), BeefyVaultOperator.sol#L13-L23, BeefyZapBiswapLPVaultOperator.sol#L21-L32, BeefyZapUniswapLPVaultOperator.sol#L21-L32, YearnCurveVaultOperator.sol#L31-L51, CurveHelpers.sol#L79-L93

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: NestedFactory.sol#L121-L130, NestedFactory.sol#L649-L657, OperatorResolver.sol#L52-L70, OperatorResolver.sol#L74-L78, MixinOperatorResolver.sol#L32-L48, MixinOperatorResolver.sol#L51-L70, TimelockControllerEmergency.sol#L65-L95 (For both), TimelockControllerEmergency.sol#L221-L237, TimelockControllerEmergency.sol#L312-L328

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.

#0 - obatirou

2022-06-23T14:27:59Z

Function Ordering via Method ID (disputed)

It will reduce the readability of our contracts.

#1 - maximebrugel

2022-06-24T14:03:32Z

Setting The Constructor To Payable (Duplicated)

#29 (see comment)

#2 - Yashiru

2022-06-24T15:32:52Z

The Increment In For Loop Post Condition Can Be Made Unchecked (Duplicated)

Duplicated of #2 at For loop optimizaion

Catching The Array Length Prior To Loop (Duplicated)

Duplicated of #2 at For loop optimizaion

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