Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gas Optimizations #21

Open
code423n4 opened this issue Apr 20, 2022 · 1 comment
Open

Gas Optimizations #21

code423n4 opened this issue Apr 20, 2022 · 1 comment
Labels
bug Something isn't working G (Gas Optimization) sponsor disputed Sponsor cannot duplicate the issue, or otherwise disagrees this is an issue

Comments

@code423n4
Copy link
Contributor

Impact

As per 0.8.4 solidity version it supports new custom errors.
It spends 30 gas less when the revert condition is not met and 250 gas otherwise.
Also reduces contract size and deployment costs.

Affected code:

https://github.com/code-423n4/2022-04-phuture/blob/594459d0865fb6603ba388b53f3f01648f5bb6fb/contracts/libraries/IndexLibrary.sol#L29

require(_assetPerBaseInUQ > 0, "IndexLibrary: ORACLE");

Proof of Concept

https://blog.soliditylang.org/2021/04/21/custom-errors/

Tools Used

Recommended Mitigation Steps

Recommended code:
error IndexLibrary_Oracle();
..
if (_assetPerBaseInUQ <= 0)
{
revert IndexLibrary_Oracle();
}


Impact

As per 0.8.4 solidity version it supports new custom errors.
It spends 30 gas less when the revert condition is not met and 250 gas otherwise.
Also reduces contract size and deployment costs.

Affected code:
https://github.com/code-423n4/2022-04-phuture/blob/594459d0865fb6603ba388b53f3f01648f5bb6fb/contracts/libraries/NAV.sol#L49

require(shares > 0, "NAV: INSUFFICIENT_AMOUNT");

Proof of Concept

https://blog.soliditylang.org/2021/04/21/custom-errors/

Tools Used

Recommended Mitigation Steps

Recommended code:
error NAV_InsufficientAmount();
..
if (shares <= 0)
{
revert NAV_InsufficientAmount();
}


Impact

As per 0.8.4 solidity version it supports new custom errors.
It spends 30 gas less when the revert condition is not met and 250 gas otherwise.
Also reduces contract size and deployment costs.

Affected code:
https://github.com/code-423n4/2022-04-phuture/blob/594459d0865fb6603ba388b53f3f01648f5bb6fb/contracts/libraries/NAV.sol#L59

require(amount > 0, "NAV: INSUFFICIENT_SHARES_BURNED");

Proof of Concept

https://blog.soliditylang.org/2021/04/21/custom-errors/

Tools Used

Recommended Mitigation Steps

Recommended code:
error NAV_InsufficientSharesBurned();
..
if (amount <= 0)
{
revert NAV_InsufficientSharesBurned();
}


Impact

As per 0.8.4 solidity version it supports new custom errors.
It spends 30 gas less when the revert condition is not met and 250 gas otherwise.
Also reduces contract size and deployment costs.

Affected code:
https://github.com/code-423n4/2022-04-phuture/blob/594459d0865fb6603ba388b53f3f01648f5bb6fb/contracts/BaseIndex.sol#L29

require(IAccessControl(registry).hasRole(role, msg.sender), "GovernableIndex: FORBIDDEN");

Proof of Concept

https://blog.soliditylang.org/2021/04/21/custom-errors/

Tools Used

Recommended Mitigation Steps

Recommended code:
error GovernableIndex_Forbidden();
..
if (!IAccessControl(registry).hasRole(role, msg.sender))
{
revert GovernableIndex_Forbidden();
}


Impact

As per 0.8.4 solidity version it supports new custom errors.
It spends 30 gas less when the revert condition is not met and 250 gas otherwise.
Also reduces contract size and deployment costs.

Affected code:
https://github.com/code-423n4/2022-04-phuture/blob/594459d0865fb6603ba388b53f3f01648f5bb6fb/contracts/BaseIndex.sol#L34

require(_factory.supportsInterface(type(IIndexFactory).interfaceId), "BaseIndex: INTERFACE");

Proof of Concept

https://blog.soliditylang.org/2021/04/21/custom-errors/

Tools Used

Recommended Mitigation Steps

Recommended code:
error BaseIndex_Interface();
..
if (!_factory.supportsInterface(type(IIndexFactory).interfaceId))
{
revert BaseIndex_Interface();
}


Impact

As per 0.8.4 solidity version it supports new custom errors.
It spends 30 gas less when the revert condition is not met and 250 gas otherwise.
Also reduces contract size and deployment costs.

Affected code:
https://github.com/code-423n4/2022-04-phuture/blob/594459d0865fb6603ba388b53f3f01648f5bb6fb/contracts/ChainlinkPriceOracle.sol#L51

require(_baseAggregator != address(0) && _base != address(0), "ChainlinkPriceOracle: ZERO");

Proof of Concept

https://blog.soliditylang.org/2021/04/21/custom-errors/

Tools Used

Recommended Mitigation Steps

Recommended code:
error ChainlinkPriceOracleEqualsZero();
..
if (_baseAggregator == address(0) && _base == address(0))
{
revert ChainlinkPriceOracleEqualsZero();
}


Impact

As per 0.8.4 solidity version it supports new custom errors.
It spends 30 gas less when the revert condition is not met and 250 gas otherwise.
Also reduces contract size and deployment costs.

Affected code:
https://github.com/code-423n4/2022-04-phuture/blob/594459d0865fb6603ba388b53f3f01648f5bb6fb/contracts/ChainlinkPriceOracle.sol#L61

require(registry.hasRole(ASSET_MANAGER_ROLE, msg.sender), "ChainlinkPriceOracle: FORBIDDEN");

Proof of Concept

https://blog.soliditylang.org/2021/04/21/custom-errors/

Tools Used

Recommended Mitigation Steps

Recommended code:
error ChainlinkPriceOracle_Forbidden();
..
if (!registry.hasRole(ASSET_MANAGER_ROLE, msg.sender)
{
revert ChainlinkPriceOracle_Forbidden();
}


Impact

As per 0.8.4 solidity version it supports new custom errors.
It spends 30 gas less when the revert condition is not met and 250 gas otherwise.
Also reduces contract size and deployment costs.

Affected code:
https://github.com/code-423n4/2022-04-phuture/blob/594459d0865fb6603ba388b53f3f01648f5bb6fb/contracts/ChainlinkPriceOracle.sol#L62

require(_asset != address(0), "ChainlinkPriceOracle: ZERO");

Proof of Concept

https://blog.soliditylang.org/2021/04/21/custom-errors/

Tools Used

Recommended Mitigation Steps

Recommended code:
error ChainlinkPriceOracle_Zero();
..
if (_asset == address(0))
{
revert ChainlinkPriceOracle_Zero();
}


Impact

As per 0.8.4 solidity version it supports new custom errors.
It spends 30 gas less when the revert condition is not met and 250 gas otherwise.
Also reduces contract size and deployment costs.

Affected code:
https://github.com/code-423n4/2022-04-phuture/blob/594459d0865fb6603ba388b53f3f01648f5bb6fb/contracts/ChainlinkPriceOracle.sol#L86

require(basePrice > 0 && quotePrice > 0, "ChainlinkPriceOracle: NEGATIVE");

Proof of Concept

https://blog.soliditylang.org/2021/04/21/custom-errors/

Tools Used

Recommended Mitigation Steps

Recommended code:
error ChainlinkPriceOracle_Negative();
..
if (!(basePrice > 0 && quotePrice > 0))
{
revert ChainlinkPriceOracle_Negative();
}


Impact

As per 0.8.4 solidity version it supports new custom errors.
It spends 30 gas less when the revert condition is not met and 250 gas otherwise.
Also reduces contract size and deployment costs.

Affected code:
https://github.com/code-423n4/2022-04-phuture/blob/594459d0865fb6603ba388b53f3f01648f5bb6fb/contracts/IndexLogic.sol#L40

require(IAccessControl(registry).hasRole(ASSET_ROLE, assets.at(i)), "Index: INVALID_ASSET");

Proof of Concept

https://blog.soliditylang.org/2021/04/21/custom-errors/

Tools Used

Recommended Mitigation Steps

Recommended code:
error Index_InvalidAsset();
..
if (!IAccessControl(registry).hasRole(ASSET_ROLE, assets.at(i)))
{
revert Index_InvalidAsset();
}


Impact

As per 0.8.4 solidity version it supports new custom errors.
It spends 30 gas less when the revert condition is not met and 250 gas otherwise.
Also reduces contract size and deployment costs.

Affected code:
https://github.com/code-423n4/2022-04-phuture/blob/594459d0865fb6603ba388b53f3f01648f5bb6fb/contracts/IndexLogic.sol#L76

require(lastAssetBalanceInBase > 0, "Index: INSUFFICIENT_AMOUNT");

Proof of Concept

https://blog.soliditylang.org/2021/04/21/custom-errors/

Tools Used

Recommended Mitigation Steps

Recommended code:
error Index_InsufficientAmount();
..
if (lastAssetBalanceInBase <= 0)
{
revert Index_InsufficientAmount();
}


Impact

As per 0.8.4 solidity version it supports new custom errors.
It spends 30 gas less when the revert condition is not met and 250 gas otherwise.
Also reduces contract size and deployment costs.

Affected code:
https://github.com/code-423n4/2022-04-phuture/blob/594459d0865fb6603ba388b53f3f01648f5bb6fb/contracts/IndexLogic.sol#L98

require(value > 0, "Index: INSUFFICIENT_AMOUNT");

Proof of Concept

https://blog.soliditylang.org/2021/04/21/custom-errors/

Tools Used

Recommended Mitigation Steps

Recommended code:
error Index_InsufficientAmount();
..
if (value <= 0)
{
revert Index_InsufficientAmount();
}


Impact

As per 0.8.4 solidity version it supports new custom errors.
It spends 30 gas less when the revert condition is not met and 250 gas otherwise.
Also reduces contract size and deployment costs.

Affected code:
https://github.com/code-423n4/2022-04-phuture/blob/594459d0865fb6603ba388b53f3f01648f5bb6fb/contracts/ManagedIndex.sol#L28

require(msg.sender == factory, "ManagedIndex: FORBIDDEN");

Proof of Concept

https://blog.soliditylang.org/2021/04/21/custom-errors/

Tools Used

Recommended Mitigation Steps

Recommended code:
error ManagedIndex_Forbidden();
..
if (msg.sender != factory)
{
revert ManagedIndex_Forbidden();
}


Impact

As per 0.8.4 solidity version it supports new custom errors.
It spends 30 gas less when the revert condition is not met and 250 gas otherwise.
Also reduces contract size and deployment costs.

Affected code:
https://github.com/code-423n4/2022-04-phuture/blob/594459d0865fb6603ba388b53f3f01648f5bb6fb/contracts/ManagedIndex.sol#L44-L48

require(
IAccessControl(registry).hasRole(INDEX_MANAGER_ROLE, msg.sender) ||
IAccessControl(registry).hasRole(REWEIGHT_INDEX_ROLE, msg.sender),
"ManagedIndex: FORBIDDEN"
);

Proof of Concept

https://blog.soliditylang.org/2021/04/21/custom-errors/

Tools Used

Recommended Mitigation Steps

Recommended code:
error ManagedIndex_Forbidden();
..
if (!(IAccessControl(registry).hasRole(INDEX_MANAGER_ROLE, msg.sender) ||
IAccessControl(registry).hasRole(REWEIGHT_INDEX_ROLE, msg.sender)))
{
revert ManagedIndex_Forbidden();
}


Impact

As per 0.8.4 solidity version it supports new custom errors.
It spends 30 gas less when the revert condition is not met and 250 gas otherwise.
Also reduces contract size and deployment costs.

Affected code:
https://github.com/code-423n4/2022-04-phuture/blob/594459d0865fb6603ba388b53f3f01648f5bb6fb/contracts/ManagedIndexReweightingLogic.sol#L29-L34

require(
_updatedAssets.length > 1 &&
_updatedWeights.length == _updatedAssets.length &&
_updatedAssets.length <= IIndexRegistry(registry).maxComponents(),
"ManagedIndex: INVALID"
);

Proof of Concept

https://blog.soliditylang.org/2021/04/21/custom-errors/

Tools Used

Recommended Mitigation Steps

Recommended code:
error ManagedIndex_Invalid();
..
if (!(_updatedAssets.length > 1 &&
_updatedWeights.length == _updatedAssets.length &&
_updatedAssets.length <= IIndexRegistry(registry).maxComponents()))
{
revert ManagedIndex_Invalid();
}


Impact

As per 0.8.4 solidity version it supports new custom errors.
It spends 30 gas less when the revert condition is not met and 250 gas otherwise.
Also reduces contract size and deployment costs.

Affected code:
https://github.com/code-423n4/2022-04-phuture/blob/594459d0865fb6603ba388b53f3f01648f5bb6fb/contracts/ManagedIndexReweightingLogic.sol#L52

require(asset != address(0), "ManagedIndex: ZERO");

Proof of Concept

https://blog.soliditylang.org/2021/04/21/custom-errors/

Tools Used

Recommended Mitigation Steps

Recommended code:
error ManagedIndex_Zero();
..
if (asset == address(0))
{
revert ManagedIndex_Zero();
}


Impact

As per 0.8.4 solidity version it supports new custom errors.
It spends 30 gas less when the revert condition is not met and 250 gas otherwise.
Also reduces contract size and deployment costs.

Affected code:
https://github.com/code-423n4/2022-04-phuture/blob/594459d0865fb6603ba388b53f3f01648f5bb6fb/contracts/ManagedIndexReweightingLogic.sol#L58

require(_updatedAssets[i - 1] < asset, "ManagedIndex: SORT");

Proof of Concept

https://blog.soliditylang.org/2021/04/21/custom-errors/

Tools Used

Recommended Mitigation Steps

Recommended code:
error ManagedIndex_Sort();
..
if (_updatedAssets[i - 1] >= asset)
{
revert ManagedIndex_Sort();
}


Impact

As per 0.8.4 solidity version it supports new custom errors.
It spends 30 gas less when the revert condition is not met and 250 gas otherwise.
Also reduces contract size and deployment costs.

Affected code:
https://github.com/code-423n4/2022-04-phuture/blob/594459d0865fb6603ba388b53f3f01648f5bb6fb/contracts/ManagedIndexReweightingLogic.sol#L62

require(IAccessControl(registry).hasRole(ASSET_ROLE, asset), "ManagedIndex: INVALID_ASSET");

Proof of Concept

https://blog.soliditylang.org/2021/04/21/custom-errors/

Tools Used

Recommended Mitigation Steps

Recommended code:
error ManagedIndex_InvalidAsset();
..
if (!IAccessControl(registry).hasRole(ASSET_ROLE, asset))
{
revert ManagedIndex_InvalidAsset();
}


Impact

As per 0.8.4 solidity version it supports new custom errors.
It spends 30 gas less when the revert condition is not met and 250 gas otherwise.
Also reduces contract size and deployment costs.

Affected code:
https://github.com/code-423n4/2022-04-phuture/blob/594459d0865fb6603ba388b53f3f01648f5bb6fb/contracts/ManagedIndexReweightingLogic.sol#L85

require(assets.remove(asset), "ManagedIndex: INVALID");

Proof of Concept

https://blog.soliditylang.org/2021/04/21/custom-errors/

Tools Used

Recommended Mitigation Steps

Recommended code:
error ManagedIndex_Invalid();
..
if (!assets.remove(asset))
{
revert ManagedIndex_Invalid();
}


Impact

As per 0.8.4 solidity version it supports new custom errors.
It spends 30 gas less when the revert condition is not met and 250 gas otherwise.
Also reduces contract size and deployment costs.

Affected code:
https://github.com/code-423n4/2022-04-phuture/blob/594459d0865fb6603ba388b53f3f01648f5bb6fb/contracts/PhuturePriceOracle.sol#L38

require(IAccessControl(registry).hasRole(_role, msg.sender), "PhuturePriceOracle: FORBIDDEN");

Proof of Concept

https://blog.soliditylang.org/2021/04/21/custom-errors/

Tools Used

Recommended Mitigation Steps

Recommended code:
error PhuturePriceOracle_Forbidden();
..
if (!IAccessControl(registry).hasRole(_role, msg.sender))
{
revert PhuturePriceOracle_Forbidden();
}


Impact

As per 0.8.4 solidity version it supports new custom errors.
It spends 30 gas less when the revert condition is not met and 250 gas otherwise.
Also reduces contract size and deployment costs.

Affected code:
https://github.com/code-423n4/2022-04-phuture/blob/594459d0865fb6603ba388b53f3f01648f5bb6fb/contracts/PhuturePriceOracle.sol#L46

require(_registry.supportsAllInterfaces(interfaceIds), "PhuturePriceOracle: INTERFACE");

Proof of Concept

https://blog.soliditylang.org/2021/04/21/custom-errors/

Tools Used

Recommended Mitigation Steps

Recommended code:
error PhuturePriceOracle_Interface();
..
if (!_registry.supportsAllInterfaces(interfaceIds))
{
revert PhuturePriceOracle_Interface();
}


Impact

As per 0.8.4 solidity version it supports new custom errors.
It spends 30 gas less when the revert condition is not met and 250 gas otherwise.
Also reduces contract size and deployment costs.

Affected code:
https://github.com/code-423n4/2022-04-phuture/blob/594459d0865fb6603ba388b53f3f01648f5bb6fb/contracts/PhuturePriceOracle.sol#L47

require(_base != address(0), "PhuturePriceOracle: ZERO");

Proof of Concept

https://blog.soliditylang.org/2021/04/21/custom-errors/

Tools Used

Recommended Mitigation Steps

Recommended code:
error PhuturePriceOracle_Zero();
..
if (_base == address(0))
{
revert PhuturePriceOracle_Zero();
}


Impact

As per 0.8.4 solidity version it supports new custom errors.
It spends 30 gas less when the revert condition is not met and 250 gas otherwise.
Also reduces contract size and deployment costs.

Affected code:
https://github.com/code-423n4/2022-04-phuture/blob/594459d0865fb6603ba388b53f3f01648f5bb6fb/contracts/PhuturePriceOracle.sol#L56

require(_oracle.supportsInterface(type(IPriceOracle).interfaceId), "PhuturePriceOracle: INTERFACE");

Proof of Concept

https://blog.soliditylang.org/2021/04/21/custom-errors/

Tools Used

Recommended Mitigation Steps

Recommended code:
error PhuturePriceOracle_Interface();
..
if (!_oracle.supportsInterface(type(IPriceOracle).interfaceId))
{
revert PhuturePriceOracle_Interface();
}


Impact

As per 0.8.4 solidity version it supports new custom errors.
It spends 30 gas less when the revert condition is not met and 250 gas otherwise.
Also reduces contract size and deployment costs.

Affected code:
https://github.com/code-423n4/2022-04-phuture/blob/594459d0865fb6603ba388b53f3f01648f5bb6fb/contracts/PhuturePriceOracle.sol#L63

require(priceOracleOf[_asset] != address(0), "PhuturePriceOracle: UNSET");

Proof of Concept

https://blog.soliditylang.org/2021/04/21/custom-errors/

Tools Used

Recommended Mitigation Steps

Recommended code:
error PhuturePriceOracle_Unset();
..
if (priceOracleOf[_asset] == address(0))
{
revert PhuturePriceOracle_Unset();
}


Impact

As per 0.8.4 solidity version it supports new custom errors.
It spends 30 gas less when the revert condition is not met and 250 gas otherwise.
Also reduces contract size and deployment costs.

Affected code:
https://github.com/code-423n4/2022-04-phuture/blob/594459d0865fb6603ba388b53f3f01648f5bb6fb/contracts/PhuturePriceOracle.sol#L83

require(priceOracleOf[_asset] != address(0), "PhuturePriceOracle: UNSET");

Proof of Concept

https://blog.soliditylang.org/2021/04/21/custom-errors/

Tools Used

Recommended Mitigation Steps

Recommended code:
error PhuturePriceOracle_Unset();
..
if (priceOracleOf[_asset] == address(0))
{
revert PhuturePriceOracle_Unset();
}


Impact

As per 0.8.4 solidity version it supports new custom errors.
It spends 30 gas less when the revert condition is not met and 250 gas otherwise.
Also reduces contract size and deployment costs.

Affected code:
https://github.com/code-423n4/2022-04-phuture/blob/594459d0865fb6603ba388b53f3f01648f5bb6fb/contracts/PhuturePriceOracle.sol#L93

require(priceOracleOf[_asset] != address(0), "PhuturePriceOracle: UNSET");

Proof of Concept

https://blog.soliditylang.org/2021/04/21/custom-errors/

Tools Used

Recommended Mitigation Steps

Recommended code:
error PhuturePriceOracle_Unset();
..
if (priceOracleOf[_asset] == address(0))
{
revert PhuturePriceOracle_Unset();
}


Impact

As per 0.8.4 solidity version it supports new custom errors.
It spends 30 gas less when the revert condition is not met and 250 gas otherwise.
Also reduces contract size and deployment costs.

Affected code:
https://github.com/code-423n4/2022-04-phuture/blob/594459d0865fb6603ba388b53f3f01648f5bb6fb/contracts/TopNMarketCapIndex.sol#L45

require(msg.sender == factory, "TopNMarketCapIndex: FORBIDDEN");

Proof of Concept

https://blog.soliditylang.org/2021/04/21/custom-errors/

Tools Used

Recommended Mitigation Steps

Recommended code:
error TopNMarketCapIndex_Forbidden();
..
if (msg.sender != factory)
{
revert TopNMarketCapIndex_Forbidden();
}


Impact

As per 0.8.4 solidity version it supports new custom errors.
It spends 30 gas less when the revert condition is not met and 250 gas otherwise.
Also reduces contract size and deployment costs.

Affected code:
https://github.com/code-423n4/2022-04-phuture/blob/594459d0865fb6603ba388b53f3f01648f5bb6fb/contracts/TopNMarketCapIndex.sol#L55

require(asset != address(0), "TopNMarketCapIndex: ZERO");

Proof of Concept

https://blog.soliditylang.org/2021/04/21/custom-errors/

Tools Used

Recommended Mitigation Steps

Recommended code:
error TopNMarketCapIndex_Zero();
..
if (asset == address(0))
{
revert TopNMarketCapIndex_Zero();
}


Impact

As per 0.8.4 solidity version it supports new custom errors.
It spends 30 gas less when the revert condition is not met and 250 gas otherwise.
Also reduces contract size and deployment costs.

Affected code:
https://github.com/code-423n4/2022-04-phuture/blob/594459d0865fb6603ba388b53f3f01648f5bb6fb/contracts/TopNMarketCapReweightingLogic.sol#L67

require(IAccessControl(registry).hasRole(ASSET_ROLE, asset), "TopNMarketCapIndex: INVALID_ASSET");

Proof of Concept

https://blog.soliditylang.org/2021/04/21/custom-errors/

Tools Used

Recommended Mitigation Steps

Recommended code:
error TopNMarketCapIndex_InvalidAsset();
..
if (!IAccessControl(registry).hasRole(ASSET_ROLE, asset))
{
revert TopNMarketCapIndex_InvalidAsset();
}


Impact

As per 0.8.4 solidity version it supports new custom errors.
It spends 30 gas less when the revert condition is not met and 250 gas otherwise.
Also reduces contract size and deployment costs.

Affected code:
https://github.com/code-423n4/2022-04-phuture/blob/594459d0865fb6603ba388b53f3f01648f5bb6fb/contracts/TrackedIndex.sol#L30

require(msg.sender == factory, "TrackedIndex: FORBIDDEN");

Proof of Concept

https://blog.soliditylang.org/2021/04/21/custom-errors/

Tools Used

Recommended Mitigation Steps

Recommended code:
error TrackedIndex_Forbidden();
..
if (msg.sender != factory)
{
revert TrackedIndex_Forbidden();
}


Impact

As per 0.8.4 solidity version it supports new custom errors.
It spends 30 gas less when the revert condition is not met and 250 gas otherwise.
Also reduces contract size and deployment costs.

Affected code:
https://github.com/code-423n4/2022-04-phuture/blob/594459d0865fb6603ba388b53f3f01648f5bb6fb/contracts/TrackedIndexReweightingLogic.sol#L38

require(IAccessControl(registry).hasRole(ASSET_ROLE, assets.at(i)), "TrackedIndex: INVALID_ASSET");

Proof of Concept

https://blog.soliditylang.org/2021/04/21/custom-errors/

Tools Used

Recommended Mitigation Steps

Recommended code:
error TrackedIndex_InvalidAsset();
..
if (!IAccessControl(registry).hasRole(ASSET_ROLE, assets.at(i))
{
revert TrackedIndex_InvalidAsset();
}


Impact

As per 0.8.4 solidity version it supports new custom errors.
It spends 30 gas less when the revert condition is not met and 250 gas otherwise.
Also reduces contract size and deployment costs.

Affected code:
https://github.com/code-423n4/2022-04-phuture/blob/594459d0865fb6603ba388b53f3f01648f5bb6fb/contracts/UniswapV2PathPriceOracle.sol#L24

require(_path.length >= 2, "UniswapV2PathPriceOracle: PATH");

Proof of Concept

https://blog.soliditylang.org/2021/04/21/custom-errors/

Tools Used

Recommended Mitigation Steps

Recommended code:
error UniswapV2PathPriceOracle_Path();
..
if (_path.length < 2)
{
revert UniswapV2PathPriceOracle_Path();
}


Impact

As per 0.8.4 solidity version it supports new custom errors.
It spends 30 gas less when the revert condition is not met and 250 gas otherwise.
Also reduces contract size and deployment costs.

Affected code:
https://github.com/code-423n4/2022-04-phuture/blob/594459d0865fb6603ba388b53f3f01648f5bb6fb/contracts/UniswapV2PathPriceOracle.sol#L25

require(_oracles.length == _path.length - 1, "UniswapV2PathPriceOracle: ORACLES");

Proof of Concept

https://blog.soliditylang.org/2021/04/21/custom-errors/

Tools Used

Recommended Mitigation Steps

Recommended code:
error UniswapV2PathPriceOracle_Oracles();
..
if (_oracles.length != _path.length - 1)
{
revert UniswapV2PathPriceOracle_Oracles();
}


Impact

As per 0.8.4 solidity version it supports new custom errors.
It spends 30 gas less when the revert condition is not met and 250 gas otherwise.
Also reduces contract size and deployment costs.

Affected code:
https://github.com/code-423n4/2022-04-phuture/blob/594459d0865fb6603ba388b53f3f01648f5bb6fb/contracts/UniswapV2PriceOracle.sol#L46

require(reserve0 != 0 && reserve1 != 0, "UniswapV2PriceOracle: RESERVES");

Proof of Concept

https://blog.soliditylang.org/2021/04/21/custom-errors/

Tools Used

Recommended Mitigation Steps

Recommended code:
error UniswapV2PriceOracle_Reserves();
..
if (reserve0 == 0 && reserve1 == 0)
{
revert UniswapV2PriceOracle_Reserves();
}


Impact

As per 0.8.4 solidity version it supports new custom errors.
It spends 30 gas less when the revert condition is not met and 250 gas otherwise.
Also reduces contract size and deployment costs.

Affected code:
https://github.com/code-423n4/2022-04-phuture/blob/594459d0865fb6603ba388b53f3f01648f5bb6fb/contracts/UniswapV2PriceOracle.sol#L83

require(_asset == asset1, "UniswapV2PriceOracle: UNKNOWN");

Proof of Concept

https://blog.soliditylang.org/2021/04/21/custom-errors/

Tools Used

Recommended Mitigation Steps

Recommended code:
error UniswapV2PriceOracle_Unknown();
..
if (_asset != asset1)
{
revert UniswapV2PriceOracle_Unknown();
}


Impact

As per 0.8.4 solidity version it supports new custom errors.
It spends 30 gas less when the revert condition is not met and 250 gas otherwise.
Also reduces contract size and deployment costs.

Affected code:
https://github.com/code-423n4/2022-04-phuture/blob/594459d0865fb6603ba388b53f3f01648f5bb6fb/contracts/vToken.sol#L46

require(IAccessControl(registry).hasRole(_role, msg.sender), "vToken: FORBIDDEN");

Proof of Concept

https://blog.soliditylang.org/2021/04/21/custom-errors/

Tools Used

Recommended Mitigation Steps

Recommended code:
error vToken_Forbidden();
..
if (!IAccessControl(registry).hasRole(_role, msg.sender))
{
revert vToken_Forbidden();
}


Impact

As per 0.8.4 solidity version it supports new custom errors.
It spends 30 gas less when the revert condition is not met and 250 gas otherwise.
Also reduces contract size and deployment costs.

Affected code:
https://github.com/code-423n4/2022-04-phuture/blob/594459d0865fb6603ba388b53f3f01648f5bb6fb/contracts/vToken.sol#L59

require(_registry.supportsAllInterfaces(interfaceIds), "vToken: INTERFACE");

Proof of Concept

https://blog.soliditylang.org/2021/04/21/custom-errors/

Tools Used

Recommended Mitigation Steps

Recommended code:
error vToken_Interface();
..
if (!_registry.supportsAllInterfaces(interfaceIds))
{
revert vToken_Interface();
}


Impact

As per 0.8.4 solidity version it supports new custom errors.
It spends 30 gas less when the revert condition is not met and 250 gas otherwise.
Also reduces contract size and deployment costs.

Affected code:
https://github.com/code-423n4/2022-04-phuture/blob/594459d0865fb6603ba388b53f3f01648f5bb6fb/contracts/vToken.sol#L60

require(_asset != address(0), "vToken: ZERO");

Proof of Concept

https://blog.soliditylang.org/2021/04/21/custom-errors/

Tools Used

Recommended Mitigation Steps

Recommended code:
error vToken_Zero();
..
if (_asset == address(0))
{
revert vToken_Zero();
}


Impact

As per 0.8.4 solidity version it supports new custom errors.
It spends 30 gas less when the revert condition is not met and 250 gas otherwise.
Also reduces contract size and deployment costs.

Affected code:
https://github.com/code-423n4/2022-04-phuture/blob/594459d0865fb6603ba388b53f3f01648f5bb6fb/contracts/vToken.sol#L71

require(msg.sender == IIndexRegistry(registry).orderer(), "vToken: FORBIDDEN");

Proof of Concept

https://blog.soliditylang.org/2021/04/21/custom-errors/

Tools Used

Recommended Mitigation Steps

Recommended code:
error vToken_Forbidden();
..
if (!msg.sender == IIndexRegistry(registry).orderer())
{
revert vToken_Forbidden();
}

@code423n4 code423n4 added bug Something isn't working G (Gas Optimization) labels Apr 20, 2022
code423n4 added a commit that referenced this issue Apr 20, 2022
@jn-lp jn-lp added the sponsor disputed Sponsor cannot duplicate the issue, or otherwise disagrees this is an issue label May 3, 2022
@jn-lp jn-lp closed this as completed May 3, 2022
@itsmetechjay itsmetechjay reopened this May 13, 2022
@moose-code
Copy link
Collaborator

For readability warden should consider not copying and pasting same sentence 10 times.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working G (Gas Optimization) sponsor disputed Sponsor cannot duplicate the issue, or otherwise disagrees this is an issue
Projects
None yet
Development

No branches or pull requests

4 participants