Nested Finance contest - UnusualTurtle'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: 28/36

Findings: 1

Award: $40.25

🌟 Selected for report: 0

🚀 Solo Findings: 0

Awards

40.2482 USDC - $40.25

Labels

bug
G (Gas Optimization)
valid

External Links

  1. Avoiding initialization of loop index can save a little gas

POC

Examples of this issue in the codebase:

https://github.com/code-423n4/2022-06-nested/blob/b253ed80f67d1bb2a04e1702f5796fd96a7c521e/contracts/NestedFactory.sol#L124

https://github.com/code-423n4/2022-06-nested/blob/b253ed80f67d1bb2a04e1702f5796fd96a7c521e/contracts/NestedFactory.sol#L315

impact

The local variable used for the loop index need not be initialized to 0 because the default value is 0. Avoiding this anti-pattern can save a few opcodes and therefore a tiny bit of gas.

  1. Using Prefix (++i) rather than postfix (i++) in increment/decrement operators in for-loops

POC

Examples of this issue in the codebase:

https://github.com/code-423n4/2022-06-nested/blob/b253ed80f67d1bb2a04e1702f5796fd96a7c521e/contracts/NestedFactory.sol#L136

https://github.com/code-423n4/2022-06-nested/blob/b253ed80f67d1bb2a04e1702f5796fd96a7c521e/contracts/NestedFactory.sol#L651

impact

using the prefix increment/decrement operators (++i/--i) cost less gas PER LOOP than the postfix increment/decrement operators (i++/i--)

  1. For-Loops: Increments can be unchecked

POC

Examples of this issue in the codebase:

https://github.com/code-423n4/2022-06-nested/blob/b253ed80f67d1bb2a04e1702f5796fd96a7c521e/contracts/NestedFactory.sol#L412

https://github.com/code-423n4/2022-06-nested/blob/b253ed80f67d1bb2a04e1702f5796fd96a7c521e/contracts/NestedFactory.sol#L256

impact

In Solidity 0.8+, there’s a default overflow check on unsigned integers. It’s possible to uncheck this in for-loops and save some gas at each iteration, but at the cost of some code readability, as this uncheck cannot be made inline.

  1. Use Custom Errors instead of Revert Strings to save Gas

POC

Examples of this issue in the codebase:

https://github.com/code-423n4/2022-06-nested/blob/b253ed80f67d1bb2a04e1702f5796fd96a7c521e/contracts/NestedFactory.sol#L250

https://github.com/code-423n4/2022-06-nested/blob/b253ed80f67d1bb2a04e1702f5796fd96a7c521e/contracts/NestedFactory.sol#L252

impact

Custom errors from Solidity 0.8.4 are cheaper than revert strings (cheaper deployment cost and runtime cost when the revert condition is met).

Custom errors are defined using the error statement, which can be used inside and outside of contracts (including interfaces and libraries).

#0 - maximebrugel

2022-06-24T14:28:20Z

4. Use Custom Errors instead of Revert Strings to save Gas (Duplicated)

#6 (see comment)

#1 - Yashiru

2022-06-24T15:47:35Z

1. Avoiding initialization of loop index can save a little gas (Duplicated)

Duplicated of #2 at For loop optimizaion

2. Using Prefix (++i) rather than postfix (i++) in increment/decrement operators in for-loops (Duplicated)

Duplicated of #2 at For loop optimizaion

3. For-Loops: Increments can be unchecked (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