Holograph contest - halden's results

Omnichain protocol for deploying, minting, & bridging NFTs between blockchains.

General Information

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

Holograph

Findings Distribution

Researcher Performance

Rank: 34/144

Findings: 1

Award: $222.25

Gas:
grade-a

🌟 Selected for report: 0

πŸš€ Solo Findings: 0

[G-01] Use custom errors isntead of revert strings to save gas

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

[G-02] require()/revert() strings longer than 32 bytes cost extra gas

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

[G-03] X > 0 is less efficient than != 0 for unsigned integers

File HolographOperator.sol: 309, 350, 363, 398, 1126

[G-03] Optimizations with assembly

[G-03.1] Use assembly for math (add, sub, mul, div)

File HolographOperator.sol: 1177

File LayerZeroModule.sol: 293

File PA1D.sol: 388, 395, 415, 438, 551, 553, 641, 643

[G-03.2] Use assembly to check for address(0)

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

[G-03] X += Y or X -= Y costs more gas than X = X + Y or X = X - Y for state variables

File HolographOperator.sol: 378, 382, 834

File HolographERC20.sol: 633, 702, 685, 686

[G-04] Using unchecked blocks to save gas

[G-04.1] Use Add unchecked {} where the operands can not underflow/overflow because of a previous check

File HolographOperator.sol: 1174

File PA1D.sol: 391

[G-04.2] Increments in for loop can be unchecked

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

[G-05] ++i costs less gas compared to i++ or i += 1 in for loops (~5 gas per iteration)

++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

[G-06] It costs more gas to initialize variables with their default value than letting the default value be applied

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

[G-07] Splitting require() statements that use && saves gas

File HolographOperator.sol: 857

File Holographer.sol: 166

File HolographERC721.sol: 263

File HolographERC721.sol: 465-466

[G-08] Empty blocks should be removed or emit something

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

[G-09] Cache storage values in memory to minimize SLOADs

cache _operatorPods.length File HolographOperator.sol: 867, 871

[G-10] Using calldata instead of memory for read-only arguments in external functions saves gas

File HolographBridge.sol: 162

File HolographOperator.sol: 240

File HolographFactory.sol: 145, 193-194

File LayerZeroModule.sol: 158

File Holographer.sol: 147

File PA1D.sol: 173, 185

File HolographERC721.sol: 238

File HolographERC20.sol: 218

File ERC721H.sol: 140

File ERC20H.sol 140

[G-11] USE ABI.ENCODEWITHSELECTOR INSTEAD OF ABI.ENCODEWITHSIGNATURE

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

[G-12] An array's length should be cached to save gas in for-loops

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

[G-13] if condition is unesesary

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

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