You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hardcode aToken, rewardsController, poolAddressesProviderRegistry and _decimals with their values instead of writing them during contract deployment with constructor parameters.
Custom Errors
IMPACT
Custom errors from Solidity 0.8.4 are cheaper than revert strings (cheaper deployment cost and runtime cost when the revert condition is met) while providing the same amount of information, as explained here
Custom errors are defined using the error statement
As of Solidity 0.8.0, overflow and underflow checks are performed automatically. Using the SafeMath library methods for subtractions and additions is hence superfluous and cost additional gas upon deployment and function calls
Replace the sub() call with the regular - operation
Tight Variable Packing
PROBLEM
Solidity contracts have contiguous 32 bytes (256 bits) slots used in storage.
By arranging the variables, it is possible to minimize the number of slots used within a contract's storage and therefore reduce deployment costs.
uint8 variables are each of 1 byte size (way less than 32 bytes). However, here it takes up a whole 32 bytes slot, as it is followed in storage by a uint256 variable.
By rearranging the storage variables, we can save one slot
PROOF OF CONCEPT
Instances include:
Funding.sol
AaveV3YieldSource.sol:136-145
uint8 private immutable _decimals;
/**
* @dev Aave genesis market PoolAddressesProvider's ID.
* @dev This variable could evolve in the future if we decide to support other markets.
*/
uint256 private constant ADDRESSES_PROVIDER_ID = uint256(0);
/// @dev PoolTogether's Aave Referral Code
uint16 private constant REFERRAL_CODE = uint16(188);
TOOLS USED
Manual Analysis
MITIGATION
Place REFERRAL_CODE after _decimals to save one storage slot
uint8 private immutable _decimals;
+uint16 private constant REFERRAL_CODE = uint16(188);
/**
* @dev Aave genesis market PoolAddressesProvider's ID.
* @dev This variable could evolve in the future if we decide to support other markets.
*/
uint256 private constant ADDRESSES_PROVIDER_ID = uint256(0);
The text was updated successfully, but these errors were encountered:
Gas Report
Table of Contents
Comparisons with zero for unsigned integers
IMPACT
> 0
is less gas efficient than!= 0
if you enable the optimizer at 10k AND you’re in a require statement.Detailed explanation with the opcodes here
PROOF OF CONCEPT
Instances include:
AaveV3YieldSource.sol
TOOLS USED
Manual Analysis
MITIGATION
Replace
> 0
with!= 0
Constructor parameters should be avoided when possible
IMPACT
Constructor parameters are expensive. The contract deployment will be cheaper in gas if they are hard coded instead of using constructor parameters.
PROOF OF CONCEPT
Instances include:
AaveV3YieldSource.sol
TOOLS USED
Manual Analysis
MITIGATION
Hardcode
aToken
,rewardsController
,poolAddressesProviderRegistry
and_decimals
with their values instead of writing them during contract deployment with constructor parameters.Custom Errors
IMPACT
Custom errors from Solidity 0.8.4 are cheaper than revert strings (cheaper deployment cost and runtime cost when the revert condition is met) while providing the same amount of information, as explained here
Custom errors are defined using the error statement
PROOF OF CONCEPT
Instances include:
AaveV3YieldSource.sol
TOOLS USED
Manual Analysis
MITIGATION
Replace require and revert statements with custom errors.
For instance:
Replace
with
and define the custom error in the contract
Inline functions
PROBLEM
When we define internal functions to perform computation:
When it does not affect readability, it is recommended to inline functions in order to save gas
PROOF OF CONCEPT
Instances include:
AaveV3YieldSource.sol
TOOLS USED
Manual Analysis
MITIGATION
Inline these functions where they are called:
Safemath library redundant
PROBLEM
As of Solidity 0.8.0, overflow and underflow checks are performed automatically. Using the SafeMath library methods for subtractions and additions is hence superfluous and cost additional gas upon deployment and function calls
PROOF OF CONCEPT
Instances include:
AaveV3YieldSource.sol
TOOLS USED
Manual Analysis
MITIGATION
Replace the
sub()
call with the regular-
operationTight Variable Packing
PROBLEM
Solidity contracts have contiguous 32 bytes (256 bits) slots used in storage.
By arranging the variables, it is possible to minimize the number of slots used within a contract's storage and therefore reduce deployment costs.
uint8 variables are each of 1 byte size (way less than 32 bytes). However, here it takes up a whole 32 bytes slot, as it is followed in storage by a uint256 variable.
By rearranging the storage variables, we can save one slot
PROOF OF CONCEPT
Instances include:
Funding.sol
TOOLS USED
Manual Analysis
MITIGATION
Place
REFERRAL_CODE
after_decimals
to save one storage slotThe text was updated successfully, but these errors were encountered: