Platform: Code4rena
Start Date: 18/10/2022
Pot Size: $75,000 USDC
Total HM: 27
Participants: 144
Period: 7 days
Judge: gzeon
Total Solo HM: 13
Id: 170
League: ETH
Rank: 34/144
Findings: 1
Award: $222.25
π Selected for report: 0
π Solo Findings: 0
π Selected for report: oyc_109
Also found by: 0x040, 0x1f8b, 0x5rings, 0xNazgul, 0xSmartContract, 0xZaharina, 0xsam, 0xzh, 2997ms, Amithuddar, Aymen0909, B2, Bnke0x0, Deivitto, Diana, Dinesh11G, Franfran, JC, JrNet, Jujic, KingNFT, KoKo, Mathieu, Metatron, Mukund, Olivierdem, PaludoX0, Pheonix, Picodes, RaymondFam, RedOneN, ReyAdmirado, Rolezn, Saintcode_, Satyam_Sharma, Shinchan, Tagir2003, Tomio, Waze, Yiko, __141345__, adriro, ajtra, aysha, ballx, beardofginger, bobirichman, brgltd, bulej93, catchup, catwhiskeys, cdahlheimer, ch0bu, chaduke, chrisdior4, cryptostellar5, cylzxje, d3e4, delfin454000, dharma09, djxploit, durianSausage, emrekocak, erictee, exolorkistis, fatherOfBlocks, gianganhnguyen, gogo, halden, hxzy, i_got_hacked, iepathos, karanctf, leosathya, lucacez, lukris02, lyncurion, m_Rassska, martin, mcwildy, mics, nicobevi, peanuts, peiw, rbserver, ret2basic, rotcivegaf, ryshaw, sakman, sakshamguruji, saneryee, sikorico, skyle, svskaushik, tnevler, vv7, w0Lfrum, zishansami
222.2506 USDC - $222.25
File Holograph.sol: 165
File HolographOperator.sol: 241, 309, 350, 354, 368, 415, 446, 485, 591, 595, 728, 739, 756, 829, 839, 857, 863, 881, 889, 903, 911, 915, 932
File HolographFactory.sol: 144,220,228,254
File LayerZeroModule.sol: 159, 235
File Holographer.sol: 148, 166
File PA1D.sol: 159, 174, 190, 390, 411, 416, 435, 439, 460, 472, 477
File HolographERC721.sol: 212, 224, 239, 258, 263, 323, 370-371, 388, 404, 408, 419-421, 458, 469, 484, 513, 622, 639, 689, 700, 729, 757, 762, 815-818, 869-870, 906
File HolographERC20.sol: 192, 204, 219, 241, 349,365, 387, 400, 427, 445, 450, 469, 482, 505, 529, 539, 599, 620-621, 627, 629, 645, 684, 695-696, 698,
File ERC721H.sol: 117, 123, 125, 147
File ERC20H.sol: 117, 123,125, 147
File Holograph.sol: 165
File HolographOperator.sol: 241, 309, 350, 354, 368, 368, 446, 485, 591, 595, 728, 739, 739, 756,829, 839, 857, 863, 881, 889, 903, 911, 915, 932
File HolographFactory.sol: 144,220,228,254
File LayerZeroModule.sol: 159, 235
File Holographer.sol: 148, 166
File PA1D.sol: 159, 174, 190, 390, 411, 416, 435, 439, 460, 472, 477
File HolographERC721.sol: 212, 224, 239, 258, 263, 323, 370-371, 388, 404, 408, 419-421, 458, 469, 484, 513, 622, 639, 689, 700, 729, 757, 762, 764, 815-818, 869-870, 906
File HolographERC20.sol: 192, 204, 219, 241, 349,365, 387, 400, 427, 445, 450, 452, 469, 482, 505, 529, 539, 599, 620-621, 627, 629, 645, 653, 661, 665
File ERC721H.sol: 117, 123, 125, 147
File ERC20H.sol: 117, 123,125, 147
File HolographOperator.sol: 309, 350, 363, 398, 1126
File HolographOperator.sol: 1177
File LayerZeroModule.sol: 293
File PA1D.sol: 388, 395, 415, 438, 551, 553, 641, 643
File HolographOperator.sol: 333
File PA1D.sol: 550, 560, 571, 593, 607, 627, 640, 657, 669
File HolographERC721.sol: 419, 639, 657, 689, 816, 870, 895
File HolographERC20.sol: 620-621, 627, 684, 695-696
File HolographOperator.sol: 378, 382, 834
File HolographERC20.sol: 633, 702, 685, 686
File HolographOperator.sol: 1174
File PA1D.sol: 391
The majority of Solidity for loops increment a uint256 variable that starts at 0. These increment operations never need to be checked for over/underflow because the variable will never reach the max number of uint256 (will run out of gas long before that happens). The default over/underflow check wastes gas in every iteration of virtually every for loop . eg.
File HolographOperator.sol: 781, 871
File PA1D.sol: 307, 323, 340, 356, 394, 414, 432, 437, 454, 474
File HolographERC721.sol: 357, 716
File HolographERC20.sol: 564
++i costs less gas compared to i++ or i += 1 for unsigned integer, as pre-increment is cheaper
File HolographOperator.sol: 781
File PA1D.sol: 307, 323, 340, 356, 394, 414, 432, 437, 454, 474
File HolographERC721.sol: 357, 716
File HolographERC20.sol: 564
If a variable is not set/initialized, it is assumed to have the default value (0 for uint, false for bool, address(0) for address...). Explicitly initializing it with its default value is an anti-pattern and wastes gas. Consider removing explicit initializations for default values.
File HolographOperator.sol: 781
File PA1D.sol: 307, 323, 340, 356, 394, 414, 432, 437, 454, 474
File HolographERC721.sol: 357, 716
File HolographERC20.sol: 564
File HolographOperator.sol: 857
File Holographer.sol: 166
File HolographERC721.sol: 263
File HolographERC721.sol: 465-466
Empty receive()/fallback()
payable functions that are not used, can be removed to save deployment gas. The code should be refactored such that they no longer exist, or the block should do something useful, such as emitting an event or reverting.
File HolographOperator.sol: 1209
File Holographer.sol: 223
File HolographERC721.sol: 962
File HolographERC20.sol: 251
File ERC721H.sol 212
File ERC20H.sol 212
cache _operatorPods.length
File HolographOperator.sol: 867, 871
File HolographBridge.sol: 162
File HolographOperator.sol: 240
File HolographFactory.sol: 145, 193-194
File LayerZeroModule.sol: 158
File Holographer.sol: 147
File HolographERC721.sol: 238
File HolographERC20.sol: 218
File ERC721H.sol: 140
File ERC20H.sol 140
abi.encodeWithSelector is much cheaper than abi.encodeWithSignature because it doesnβt require to compute the selector from the string.
File Holographer.sol: 164
File HolographERC721.sol: 260
Reading array length at each iteration of the loop takes 6 gas (3 for mload and 3 to place memory_offset) in the stack.
File PA1D.sol: 432, 437, 454, 474
File HolographERC721.sol: 357
File HolographERC20.sol: 564
It does not need from if condition here. With removing of body of if condition will save some deployment gas
File HolographERC721.sol: 1003
File HolographERC20.sol: 755, 288-294,
Recommended: return (_eventConfig >> uint256(_eventName)) & uint256(1) == 1;
PoC
pragma solidity 0.8.7; contract HolographWorst { function sum1(uint256 param) public returns (bool) { ++param; return param == 1 ? true : false; } }
pragma solidity 0.8.7; contract HolographBest { function sum1(uint256 param) public returns (bool) { ++param; return param == 1; } }
HolographWorst deployment: 176669 gas HolographWorst transaction: 25230 gas HolographBest deployment: 173219 gas HolographBest transaction: 25210 gas