Platform: Code4rena
Start Date: 05/08/2021
Pot Size: $50,000 USDC
Total HM: 9
Participants: 16
Period: 7 days
Judge: 0xean
Total Solo HM: 4
Id: 22
League: ETH
Rank: 15/16
Findings: 1
Award: $24.58
🌟 Selected for report: 0
🚀 Solo Findings: 0
24.5798 USDC - $24.58
bw
The YieldManagerAave.sol
contract made use of a number of public
variables that were set only in the constructor and would remain constant. These variables were consuming storage slots, which unnecessarily increased the deployment and runtime gas costs of the contract.
For more information regarding the immutable
keyword:
https://blog.soliditylang.org/2020/05/13/immutable-keyword/
diff --git a/contracts/contracts/YieldManagerAave.sol b/contracts/contracts/YieldManagerAave.sol index c7e23b2..042930f 100644 --- a/contracts/contracts/YieldManagerAave.sol +++ b/contracts/contracts/YieldManagerAave.sol @@ -22,20 +22,20 @@ contract YieldManagerAave is IYieldManager { ╚═════════════════════════════╝*/ /// @notice address of longShort contract - address public longShort; + address public immutable longShort; /// @notice address of treasury contract - this is the address that can claim aave incentives rewards - address public treasury; + address public immutable treasury; /// @notice The payment token the yield manager supports /// @dev DAI token - ERC20 public paymentToken; + ERC20 public immutable paymentToken; /// @notice The token representing the interest accruing payment token position from Aave /// @dev ADAI token - IERC20Upgradeable public aToken; + IERC20Upgradeable public immutable aToken; /// @notice The specific Aave lending pool contract - ILendingPool public lendingPool; + ILendingPool public immutable lendingPool; /// @notice The specific Aave incentives controller contract - IAaveIncentivesController public aaveIncentivesController; + IAaveIncentivesController public immutable aaveIncentivesController; /// @dev An aave specific referralCode that has been a depricated feature. This will be set to 0 for "no referral" at deployment uint16 referralCode; @@ -97,7 +97,7 @@ contract YieldManagerAave is IYieldManager { aaveIncentivesController = IAaveIncentivesController(_aaveIncentivesController); // Approve tokens for aave lending pool maximally. - paymentToken.approve(address(lendingPool), type(uint256).max); + ERC20(_paymentToken).approve(_lendingPool, type(uint256).max); }
By removing the public
keyword from all variables that are not required (which are only used in the unit tests), the deployment costs can be further reduced.
https://www.npmjs.com/package/hardhat-gas-reporter
Add the immutable key word to all variables that are only set during the constructor.
#0 - JasoonS
2021-08-10T12:49:03Z
Thank you. Quite a few duplicates of this.
By removing the public keyword from all variables that are not required (which are only used in the unit tests), the deployment costs can be further reduced.
Thank you, we are not concerned about deployment gas costs fortunately - convenience of having those variables public is worth more than a once off gas optimisation (on any network IMO - but on Polygon in particular).
#1 - JasoonS
2021-08-13T18:49:34Z
Closing in favour of #53