ENS - danb's results

Decentralized naming for wallets, websites, & more.

General Information

Platform: Code4rena

Start Date: 05/10/2023

Pot Size: $33,050 USDC

Total HM: 1

Participants: 54

Period: 6 days

Judge: hansfriese

Id: 294

League: ETH

ENS

Findings Distribution

Researcher Performance

Rank: 44/54

Findings: 1

Award: $8.19

Gas:
grade-b

🌟 Selected for report: 0

🚀 Solo Findings: 0

Findings Information

🌟 Selected for report: windhustler

Also found by: 0xhex, 0xta, JCK, K42, MatricksDeCoder, MrPotatoMagic, SAQ, SY_S, SovaSlava, aslanbek, d3e4, danb, hunter_w3b, lukejohn

Labels

bug
G (Gas Optimization)
grade-b
sufficient quality report
G-12

Awards

8.1878 USDC - $8.19

External Links

Optimizations

Optimizing the proxy addresses

The retrieveProxyContractAddress function is called multiple times for each of the "main loop"'s iterations. I propose 2 possible different ways to fixe for this issue:

  • Save a mapping between each delegate to the "Proxy Contact address" and change the retrieveProxyContractAddress function to return the value from the mapping if it exists, and calculate it and save it to the mapping for future lookup otherwise
  • Calculate the "Proxy Contact address" once ahead of time in the beginning of the _delegateMulti function and pass it to the functions that require it

Optimizing the loop in the main function

the loop in the main function has multiple optimizations which could be implemented:

  • The Math.max(sourcesLength, targetsLength) condition in the main loop should be calculated before it like so:
uint256 stopCondition = Math.max(sourcesLength, targetsLength) for (uint transferIndex = 0; transferIndex < stopCondition; transferIndex++)
  • Additionally, the main loop should be split into two separate loops in order to minimize the calculation of the conditions which compare the indexes to the sizes of the input arrays in the for loop like so:
uint256 stopConditionFirstLoop = Math.min(sourcesLength, targetsLength); uint256 stopConditionSecondLoop = Math.max(sourcesLength, targetsLength); uint transferIndex = 0; for (; transferIndex < stopConditionFirstLoop ; transferIndex++) { address source = transferIndex < sourcesLength ? address(uint160(sources[transferIndex])) : address(0); address target = transferIndex < targetsLength ? address(uint160(targets[transferIndex])) : address(0); uint256 amount = amounts[transferIndex]; _processDelegation(source, target, amount); } if (transferIndex < sourcesLength) { for (; transferIndex < stopConditionSecondLoop; transferIndex++) { address source = transferIndex < sourcesLength ? address(uint160(sources[transferIndex])) : address(0); uint256 amount = amounts[transferIndex]; _reimburse(source, amount); } } else if (transferIndex < targetsLength) { for (; transferIndex < stopConditionSecondLoop; transferIndex++) { address target = transferIndex < targetsLength ? address(uint160(targets[transferIndex])) : address(0); uint256 amount = amounts[transferIndex]; createProxyDelegatorAndTransfer(target, amount); } }

#0 - c4-pre-sort

2023-10-13T13:51:30Z

141345 marked the issue as sufficient quality report

#1 - c4-judge

2023-10-24T17:03:22Z

hansfriese marked the issue as grade-b

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