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
Rank: 44/54
Findings: 1
Award: $8.19
🌟 Selected for report: 0
🚀 Solo Findings: 0
🌟 Selected for report: windhustler
Also found by: 0xhex, 0xta, JCK, K42, MatricksDeCoder, MrPotatoMagic, SAQ, SY_S, SovaSlava, aslanbek, d3e4, danb, hunter_w3b, lukejohn
8.1878 USDC - $8.19
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:
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_delegateMulti
function and pass it to the functions that require itthe loop in the main function has multiple optimizations which could be implemented:
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++)
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