Platform: Code4rena
Start Date: 09/07/2021
Pot Size: $25,000 USDC
Total HM: 7
Participants: 10
Period: 3 days
Judge: ghoulsol
Total Solo HM: 2
Id: 19
League: ETH
Rank: 9/10
Findings: 2
Award: $29.52
馃専 Selected for report: 0
馃殌 Solo Findings: 0
馃専 Selected for report: hrkrshnn
Also found by: GalloDaSballo, cmichel, gpersoon, shw
29.5216 USDC - $29.52
GalloDaSballo
Instead of creating a new array,
uint256[] memory updated = new uint256[](newLength);
and then looping
You can iterate in place, saving gas
Example code, and tests in repo link given below
Provide direct links to all referenced code in GitHub. Add screenshots, logs, or any other relevant proof that illustrates the concept.
I rewrote the function as such:
function remove(address user, uint256 preparedBlock) public { uint256 index = 99999999999999999999; uint256[] storage list = activeTransactionBlocks[user]; uint256 length = list.length; for(uint256 x; x < length; x++){ if(list[x] == preparedBlock){ index = x; } } if(index != 99999999999999999999) { list[index] = list[list.length - 1]; list.pop(); } }
Current Version: Min 16635 路 Max 64060 路 Avg 35224
New Version: Min 16652 路 Max 50306 路 Avg 28333
You can run the repo with demo code here: https://github.com/GalloDaSballo/connext-gas
Also see "SO example on deleting element from array" https://ethereum.stackexchange.com/a/98484
#0 - LayneHaber
2021-07-13T17:21:13Z
#60