code-423n4 / 2022-02-aave-lens-findings

0 stars 0 forks source link

Gas Optimizations #13

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago

Loading the array length here isn't needed as this is already the initial value, which in turn costs extra gas: LensHub.sol::541 - for (uint256 i = 0; i < vars.datas.length; ++i) { PublishingLogic.sol::400 - if (byteHandle.length == 0 || byteHandle.length > Constants.MAX_HANDLE_LENGTH) PublishingLogic.sol::403 - for (uint256 i = 0; i < byteHandle.length; ++i) { InteractionLogic.sol::46 - if (profileIds.length != followModuleDatas.length) revert Errors.ArrayMismatch(); InteractionLogic.sol::47 - for (uint256 i = 0; i < profileIds.length; ++i) {

Initializing variables that have the same default value is unnecessary and costs extra gas. FollowNFT.sol::120 - uint256 lower = 0; FollowNFT.sol::162 - uint256 lower = 0;

SHR opcode uses less gas compared to DIV opcode FollowNFT.sol::134 - uint256 center = upper - (upper - lower) / 2; FollowNFT.sol::176 - uint256 center = upper - (upper - lower) / 2;

Zer0dot commented 2 years ago

These are valid (except the 2nd point which appears to be handled by the optimizer) and are already addressed in https://github.com/aave/lens-protocol/pull/80