code-423n4 / 2022-04-phuture-findings

0 stars 0 forks source link

Gas Optimizations #16

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago

Issues found

Don't Initialize Variables with Default Value

Impact

Issue Information: G001 - variables with default value

Findings:

TopNMarketCapIndex.sol::51 => uint8 weight = _i == 0
UniswapV2PathPriceOracle.sol::34 => for (uint i = 0; i < path.length - 1; i++) {
UniswapV2PathPriceOracle.sol::49 => for (uint i = 0; i < path.length - 1; i++) {

Cache Array Length Outside of Loop

Impact

Issue Information: G002 - array length outside loop

Findings:

BaseIndex.sol::78 => for (uint i; i < _assets.length; ++i) {
IndexLogic.sol::39 => for (uint i; i < assets.length(); ++i) {
IndexLogic.sol::60 => for (uint i; i < inactiveAssets.length(); ++i) {
ManagedIndex.sol::30 => for (uint i; i < _assets.length; ++i) {
ManagedIndex.sol::53 => if (data.length == 0) {
ManagedIndexReweightingLogic.sol::38 => for (uint i; i < assets.length(); ++i) {
ManagedIndexReweightingLogic.sol::50 => for (uint i; i < _updatedAssets.length; ++i) {
ManagedIndexReweightingLogic.sol::96 => for (uint i; i < _inactiveAssets.length; ++i) {
TopNMarketCapIndex.sol::48 => for (uint i; i < _assets.length; ++i) {
TopNMarketCapReweightingLogic.sol::37 => for (uint i; i < assets.length(); ++i) {
TopNMarketCapReweightingLogic.sol::104 => for (uint i; i < _inactiveAssets.length; ++i) {
TrackedIndex.sol::35 => for (uint i; i < _assets.length; ++i) {
TrackedIndexReweightingLogic.sol::37 => for (uint i; i < assets.length(); ++i) {
TrackedIndexReweightingLogic.sol::66 => for (uint i; i < assets.length(); ++i) {
UniswapV2PathPriceOracle.sol::34 => for (uint i = 0; i < path.length - 1; i++) {
UniswapV2PathPriceOracle.sol::49 => for (uint i = 0; i < path.length - 1; i++) {

Long Revert Strings

Impact

Issue Information: G007 - long (revert) strings

Findings:

TopNMarketCapIndex.sol::74 => revert("TopNMarketCapIndex: REWEIGH_FAILED");
TopNMarketCapReweightingLogic.sol::67 => require(IAccessControl(registry).hasRole(ASSET_ROLE, asset), "TopNMarketCapIndex: INVALID_ASSET");
UniswapV2PathPriceOracle.sol::25 => require(_oracles.length == _path.length - 1, "UniswapV2PathPriceOracle: ORACLES");

Prefix increments are cheaper than postfix increments

Impact

Issue Information: G009 - Prefix increments are cheaper than postfix increments

Findings:

UniswapV2PathPriceOracle.sol::34 => for (uint i = 0; i < path.length - 1; i++) {
UniswapV2PathPriceOracle.sol::49 => for (uint i = 0; i < path.length - 1; i++) {
libraries/FullMath.sol::124 => result++;