Nouns DAO contest - SaharAP's results

A DAO-driven NFT project on Ethereum.

General Information

Platform: Code4rena

Start Date: 22/08/2022

Pot Size: $50,000 USDC

Total HM: 4

Participants: 160

Period: 5 days

Judge: gzeon

Total Solo HM: 2

Id: 155

League: ETH

Nouns DAO

Findings Distribution

Researcher Performance

Rank: 149/160

Findings: 1

Award: $16.66

🌟 Selected for report: 0

🚀 Solo Findings: 0

1. Not to initialize uint variables to zero

Uint variable's default value is zero. So, you can save gas by just defining uint variables.

Proof of Concept

getPriorVotes() queue()

You can just define uint32 lower without initializing it to zero. Also, there are many for loops in NounsDAOLogicV2 and NounsDAOLogicV1 contracts that you can just define uint256 i without initializing it.

2. Use unchecked block if possible

Use unchecked blocks for arithmetic operations that can't underflow/overflow.

Proof of Concept

queue()

You can put ++i or i++ in for loops in an unchecked block.

3. Use !=0 instead of > 0

!= 0 is a cheaper operation compared to > 0, when dealing with uint. > 0 can be replaced with != 0 for gas optimization.

Proof of Concept

castRefundableVoteInternal() _writeQuorumParamsCheckpoint() getCurrentVotes() _moveDelegates() _moveDelegates() _moveDelegates() _writeCheckpoint()

Replace > 0 with != 0 when comparing unsigned integer variables to save gas.

4. Use custom errors instead of require() statements with revert strings.

Using custom errors can save gas instead of using string errors.

Proof of Concept

initialize() propose() tokenOfOwnerByIndex tokenByIndex

Internal functions used once can be written inline to save gas.

5. Use inline code instead of writing functions.

Proof of Concept

safe32() safe96() add96() sub96() getChainId() getChainIdInternal() queueOrRevertInternal() _refundGas()

Write safe32(), safe96(), add96(), sub96 and getChainId() functions inside their calling functions.

6. Cache an array length in a memory variable to save gas

targets.length is read multiple times, especially in loops, you should cache it in a memory variable to save gas.

Proof of Concept

propose() queue() execute() cancel() veto()

Store targets.length in a memory variable to save gas.

7. Use external visibility for uncalled public functions

Public functions that are never called from within the contracts should be declared external to save gas.

Proof of Concept

delegate()

Change delegate() function visiblity from public to external.

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