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

0 stars 0 forks source link

Gas Optimizations #13

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago

Impact

As per 0.8.4 solidity version it supports new custom errors. Custom errors are reducing 38 gas if condition is met and 22 gas otherwise. Also reduces contract size and deployment costs.

Affected code: https://github.com/pooltogether/aave-v3-yield-source/tree/e63d1b0e396a5bce89f093630c282ca1c6627e44/contracts/AaveV3YieldSource.sol#L168

Proof of Concept

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

Tools Used

Recommended Mitigation Steps

Recommended code: error RC_NotZeroAddress(); .. if(address(_aToken) == address(0)) { revert RC_NotZeroAddress(); }


Impact

As per 0.8.4 solidity version it supports new custom errors. Custom errors are reducing 38 gas if condition is met and 22 gas otherwise. Also reduces contract size and deployment costs.

Affected code: https://github.com/pooltogether/aave-v3-yield-source/tree/e63d1b0e396a5bce89f093630c282ca1c6627e44/contracts/AaveV3YieldSource.sol#L171

Proof of Concept

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

Tools Used

Recommended Mitigation Steps

Recommended code: error RC_NotZeroAddress(); .. if(address(_rewardsController) == address(0)) { revert RC_NotZeroAddress(); }


Impact

As per 0.8.4 solidity version it supports new custom errors. Custom errors are reducing 38 gas if condition is met and 22 gas otherwise. Also reduces contract size and deployment costs.

Affected code: https://github.com/pooltogether/aave-v3-yield-source/tree/e63d1b0e396a5bce89f093630c282ca1c6627e44/contracts/AaveV3YieldSource.sol#L174

Proof of Concept

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

Tools Used

Recommended Mitigation Steps

Recommended code: error RC_NotZeroAddress(); .. if(address(_poolAddressesProviderRegistry) == address(0)) { revert RC_NotZeroAddress(); }


Impact

As per 0.8.4 solidity version it supports new custom errors. Custom errors are reducing 38 gas if condition is met and 22 gas otherwise. Also reduces contract size and deployment costs.

Affected code: https://github.com/pooltogether/aave-v3-yield-source/tree/e63d1b0e396a5bce89f093630c282ca1c6627e44/contracts/AaveV3YieldSource.sol#L177

Proof of Concept

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

Tools Used

Recommended Mitigation Steps

Recommended code: error Owner_NotZeroAddress(); .. if(_owner == address(0)) { revert Owner_NotZeroAddress(); }


Impact

As per 0.8.4 solidity version it supports new custom errors. Custom errors are reducing 38 gas if condition is met and 22 gas otherwise. Also reduces contract size and deployment costs.

Affected code: https://github.com/pooltogether/aave-v3-yield-source/tree/e63d1b0e396a5bce89f093630c282ca1c6627e44/contracts/AaveV3YieldSource.sol#L179

Proof of Concept

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

Tools Used

Recommended Mitigation Steps

Recommended code: error DecimalsGtZero(); .. if(decimals_ == 0) { revert DecimalsGtZero(); }


Impact

As per 0.8.4 solidity version it supports new custom errors. Custom errors are reducing 38 gas if condition is met and 22 gas otherwise. Also reduces contract size and deployment costs.

Affected code: https://github.com/pooltogether/aave-v3-yield-source/tree/e63d1b0e396a5bce89f093630c282ca1c6627e44/contracts/AaveV3YieldSource.sol#L233

Proof of Concept

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

Tools Used

Recommended Mitigation Steps

Recommended code: error SharesGtZero(); .. if(_shares == 0) { revert SharesGtZero(); }


Impact

As per 0.8.4 solidity version it supports new custom errors. Custom errors are reducing 38 gas if condition is met and 22 gas otherwise. Also reduces contract size and deployment costs.

Affected code: https://github.com/pooltogether/aave-v3-yield-source/tree/e63d1b0e396a5bce89f093630c282ca1c6627e44/contracts/AaveV3YieldSource.sol#L276

Proof of Concept

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

Tools Used

Recommended Mitigation Steps

Recommended code: error PayeeNotZeroAddress(); .. if(_to == address(0)) { revert PayeeNotZeroAddress(); }


Impact

As per 0.8.4 solidity version it supports new custom errors. Custom errors are reducing 38 gas if condition is met and 22 gas otherwise. Also reduces contract size and deployment costs.

Affected code: https://github.com/pooltogether/aave-v3-yield-source/tree/e63d1b0e396a5bce89f093630c282ca1c6627e44/contracts/AaveV3YieldSource.sol#L337

Proof of Concept

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

Tools Used

Recommended Mitigation Steps

Recommended code: error Forbid_aToken_Transfer(); .. if(address(_token) == address(aToken)) { revert Forbid_aToken_Transfer(); }


Impact

As per 0.8.4 solidity version it supports new custom errors. Custom errors are reducing 38 gas if condition is met and 22 gas otherwise. Also reduces contract size and deployment costs.

Affected code: https://github.com/pooltogether/aave-v3-yield-source/tree/e63d1b0e396a5bce89f093630c282ca1c6627e44/contracts/AaveV3YieldSource.sol#L349

Proof of Concept

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

Tools Used

Recommended Mitigation Steps

Recommended code: error Forbid_aToken_Allowance(); .. if(_token == address(aToken)) { revert Forbid_aToken_Allowance(); }


PierrickGT commented 2 years ago

We prefer to use require on one line instead of custom errors on several lines. For this reason, I've acknowledged the issue but we won't use custom errors.