Open code423n4 opened 2 years ago
Issue: Require message is too long Explanation: The require revert strings referenced below can be shortened to 32 characters or fewer (as shown) to save gas
Require
require
https://github.com/code-423n4/2022-05-backd/blob/2a5664d35cde5b036074edef3c1369b984d10010/protocol/contracts/AddressProvider.sol#L296
require(!_stakerVaults.contains(token), Error.STAKER_VAULT_EXISTS);
Change the referenced error message from a staker vault already exists for the token to token already has staker vault
a staker vault already exists for the token
token already has staker vault
https://github.com/code-423n4/2022-05-backd/blob/2a5664d35cde5b036074edef3c1369b984d10010/protocol/contracts/BkdLocker.sol#L59
require(currentUInts256[_START_BOOST] == 0, Error.CONTRACT_INITIALIZED);
Change the referenced error message from contract can only be initialized once to contract already initialized
contract can only be initialized once
contract already initialized
https://github.com/code-423n4/2022-05-backd/blob/2a5664d35cde5b036074edef3c1369b984d10010/protocol/contracts/tokenomics/InflationManager.sol#L60
require(_minter != address(0), Error.INVALID_MINTER);
Change the referenced error message from the minter address of the LP token and the pool address do not match to minter and pool address mismatch
the minter address of the LP token and the pool address do not match
minter and pool address mismatch
The same error message occurs in the lines referenced below:
https://github.com/code-423n4/2022-05-backd/blob/2a5664d35cde5b036074edef3c1369b984d10010/protocol/contracts/tokenomics/Minter.sol#L72
https://github.com/code-423n4/2022-05-backd/blob/2a5664d35cde5b036074edef3c1369b984d10010/protocol/contracts/tokenomics/Minter.sol#L73
https://github.com/code-423n4/2022-05-backd/blob/2a5664d35cde5b036074edef3c1369b984d10010/protocol/contracts/tokenomics/Minter.sol#L74
Example:
require(_annualInflationDecayAmm < ScaledMath.ONE, Error.INVALID_PARAMETER_VALUE);
Change the referenced error message from invalid parameter value attempted to invalid parameter value attempt
invalid parameter value attempted
invalid parameter value attempt
https://github.com/code-423n4/2022-05-backd/blob/2a5664d35cde5b036074edef3c1369b984d10010/protocol/contracts/tokenomics/Minter.sol#L150-L153
require( issuedNonInflationSupply + amount <= nonInflationDistribution, "Maximum non-inflation amount exceeded." );
Change error message to Max non-inflation amt exceeded
Max non-inflation amt exceeded
https://github.com/code-423n4/2022-05-backd/blob/2a5664d35cde5b036074edef3c1369b984d10010/protocol/contracts/utils/Preparable.sol#L110
require(block.timestamp >= deadline, Error.DEADLINE_NOT_REACHED);
Change the referenced error message from deadline has not been reached yet to deadline not yet reached
deadline has not been reached yet
deadline not yet reached
Issue: Should use != 0 instead of > 0 in a require statement if variable is an unsigned integer (uint)
!= 0
> 0
uint
Explanation: != 0 should be used where possible since > 0 costs more gas
The same require occurs in all three lines below:
https://github.com/code-423n4/2022-05-backd/blob/2a5664d35cde5b036074edef3c1369b984d10010/protocol/contracts/BkdLocker.sol#L91
https://github.com/code-423n4/2022-05-backd/blob/2a5664d35cde5b036074edef3c1369b984d10010/protocol/contracts/tokenomics/AmmGauge.sol#L104
https://github.com/code-423n4/2022-05-backd/blob/2a5664d35cde5b036074edef3c1369b984d10010/protocol/contracts/tokenomics/AmmGauge.sol#L125
require(amount > 0, Error.INVALID_AMOUNT);
Change amount > 0 to amount != 0 in each case
amount > 0
amount != 0
https://github.com/code-423n4/2022-05-backd/blob/2a5664d35cde5b036074edef3c1369b984d10010/protocol/contracts/BkdLocker.sol#L92
require(totalLockedBoosted > 0, Error.NOT_ENOUGH_FUNDS);
Change totalLockedBoosted > 0 to totalLockedBoosted != 0
totalLockedBoosted > 0
totalLockedBoosted != 0
https://github.com/code-423n4/2022-05-backd/blob/2a5664d35cde5b036074edef3c1369b984d10010/protocol/contracts/BkdLocker.sol#L137
require(length > 0, "No entries");
Change length > 0 to length != 0
length > 0
length != 0
https://github.com/code-423n4/2022-05-backd/blob/2a5664d35cde5b036074edef3c1369b984d10010/protocol/contracts/tokenomics/KeeperGauge.sol#L140
require(totalClaimable > 0, Error.ZERO_TRANSFER_NOT_ALLOWED);
Change totalClaimable > 0 to totalClaimable != 0
totalClaimable > 0
totalClaimable != 0
https://github.com/code-423n4/2022-05-backd/blob/2a5664d35cde5b036074edef3c1369b984d10010/protocol/contracts/tokenomics/VestedEscrow.sol#L84
require(unallocatedSupply > 0, "No reward tokens in contract");
Change unallocatedSupply > 0 to unallocatedSupply != 0
unallocatedSupply > 0
unallocatedSupply != 0
Issue: Variables should not be initialized to their default values
Explanation: For example, initialization of booleans to their default value of false is unnecessary and costs gas
booleans
false
https://github.com/code-423n4/2022-05-backd/blob/2a5664d35cde5b036074edef3c1369b984d10010/protocol/contracts/tokenomics/InflationManager.sol#L412
bool keeperGaugeExists = false;
Change to bool keeperGaugeExists;
bool keeperGaugeExists;
Issue: Array length should not be looked up in every iteration of a for loop
for
Explanation: Calculating the array length costs gas
Recommendation: Read the length of the array from memory before executing the loop
https://github.com/code-423n4/2022-05-backd/blob/2a5664d35cde5b036074edef3c1369b984d10010/protocol/contracts/access/RoleManager.sol#L82
for (uint256 i; i < roles.length; i = i.uncheckedInc()) {
Recommendation:
uint256 totalRolesLength = roles.length; for (uint256 i; i < totalRolesLength; i = i.uncheckedInc()) {
Similarly for the seven for loops referenced below:
https://github.com/code-423n4/2022-05-backd/blob/2a5664d35cde5b036074edef3c1369b984d10010/protocol/contracts/RewardHandler.sol#L42
https://github.com/code-423n4/2022-05-backd/blob/2a5664d35cde5b036074edef3c1369b984d10010/protocol/contracts/StakerVault.sol#L259
https://github.com/code-423n4/2022-05-backd/blob/2a5664d35cde5b036074edef3c1369b984d10010/protocol/contracts/tokenomics/FeeBurner.sol#L56
https://github.com/code-423n4/2022-05-backd/blob/2a5664d35cde5b036074edef3c1369b984d10010/protocol/contracts/tokenomics/InflationManager.sol#L116
https://github.com/code-423n4/2022-05-backd/blob/2a5664d35cde5b036074edef3c1369b984d10010/protocol/contracts/tokenomics/VestedEscrow.sol#L94
https://github.com/code-423n4/2022-05-backd/blob/2a5664d35cde5b036074edef3c1369b984d10010/protocol/contracts/zaps/PoolMigrationZap.sol#L22
https://github.com/code-423n4/2022-05-backd/blob/2a5664d35cde5b036074edef3c1369b984d10010/protocol/contracts/zaps/PoolMigrationZap.sol#L39
6 * 6 = 36
Saves 3 gas per instance 7 * 3 = 21
3
3 per instance 8 * 3 = 24
Total Gas Saved 84
Issue:
Require
message is too long Explanation: Therequire
revert strings referenced below can be shortened to 32 characters or fewer (as shown) to save gashttps://github.com/code-423n4/2022-05-backd/blob/2a5664d35cde5b036074edef3c1369b984d10010/protocol/contracts/AddressProvider.sol#L296
Change the referenced error message from
a staker vault already exists for the token
totoken already has staker vault
https://github.com/code-423n4/2022-05-backd/blob/2a5664d35cde5b036074edef3c1369b984d10010/protocol/contracts/BkdLocker.sol#L59
Change the referenced error message from
contract can only be initialized once
tocontract already initialized
https://github.com/code-423n4/2022-05-backd/blob/2a5664d35cde5b036074edef3c1369b984d10010/protocol/contracts/tokenomics/InflationManager.sol#L60
Change the referenced error message from
the minter address of the LP token and the pool address do not match
tominter and pool address mismatch
The same error message occurs in the lines referenced below:
https://github.com/code-423n4/2022-05-backd/blob/2a5664d35cde5b036074edef3c1369b984d10010/protocol/contracts/tokenomics/Minter.sol#L72
https://github.com/code-423n4/2022-05-backd/blob/2a5664d35cde5b036074edef3c1369b984d10010/protocol/contracts/tokenomics/Minter.sol#L73
https://github.com/code-423n4/2022-05-backd/blob/2a5664d35cde5b036074edef3c1369b984d10010/protocol/contracts/tokenomics/Minter.sol#L74
Example:
Change the referenced error message from
invalid parameter value attempted
toinvalid parameter value attempt
https://github.com/code-423n4/2022-05-backd/blob/2a5664d35cde5b036074edef3c1369b984d10010/protocol/contracts/tokenomics/Minter.sol#L150-L153
Change error message to
Max non-inflation amt exceeded
https://github.com/code-423n4/2022-05-backd/blob/2a5664d35cde5b036074edef3c1369b984d10010/protocol/contracts/utils/Preparable.sol#L110
Change the referenced error message from
deadline has not been reached yet
todeadline not yet reached
Issue: Should use
!= 0
instead of> 0
in arequire
statement if variable is an unsigned integer (uint
)Explanation:
!= 0
should be used where possible since> 0
costs more gasThe same
require
occurs in all three lines below:https://github.com/code-423n4/2022-05-backd/blob/2a5664d35cde5b036074edef3c1369b984d10010/protocol/contracts/BkdLocker.sol#L91
https://github.com/code-423n4/2022-05-backd/blob/2a5664d35cde5b036074edef3c1369b984d10010/protocol/contracts/tokenomics/AmmGauge.sol#L104
https://github.com/code-423n4/2022-05-backd/blob/2a5664d35cde5b036074edef3c1369b984d10010/protocol/contracts/tokenomics/AmmGauge.sol#L125
Change
amount > 0
toamount != 0
in each casehttps://github.com/code-423n4/2022-05-backd/blob/2a5664d35cde5b036074edef3c1369b984d10010/protocol/contracts/BkdLocker.sol#L92
Change
totalLockedBoosted > 0
tototalLockedBoosted != 0
https://github.com/code-423n4/2022-05-backd/blob/2a5664d35cde5b036074edef3c1369b984d10010/protocol/contracts/BkdLocker.sol#L137
Change
length > 0
tolength != 0
https://github.com/code-423n4/2022-05-backd/blob/2a5664d35cde5b036074edef3c1369b984d10010/protocol/contracts/tokenomics/KeeperGauge.sol#L140
Change
totalClaimable > 0
tototalClaimable != 0
https://github.com/code-423n4/2022-05-backd/blob/2a5664d35cde5b036074edef3c1369b984d10010/protocol/contracts/tokenomics/VestedEscrow.sol#L84
Change
unallocatedSupply > 0
tounallocatedSupply != 0
Issue: Variables should not be initialized to their default values
Explanation: For example, initialization of
booleans
to their default value offalse
is unnecessary and costs gashttps://github.com/code-423n4/2022-05-backd/blob/2a5664d35cde5b036074edef3c1369b984d10010/protocol/contracts/tokenomics/InflationManager.sol#L412
Change to
bool keeperGaugeExists;
Issue: Array length should not be looked up in every iteration of a
for
loopExplanation: Calculating the array length costs gas
Recommendation: Read the length of the array from memory before executing the loop
https://github.com/code-423n4/2022-05-backd/blob/2a5664d35cde5b036074edef3c1369b984d10010/protocol/contracts/access/RoleManager.sol#L82
Recommendation:
Similarly for the seven
for
loops referenced below:https://github.com/code-423n4/2022-05-backd/blob/2a5664d35cde5b036074edef3c1369b984d10010/protocol/contracts/RewardHandler.sol#L42
https://github.com/code-423n4/2022-05-backd/blob/2a5664d35cde5b036074edef3c1369b984d10010/protocol/contracts/StakerVault.sol#L259
https://github.com/code-423n4/2022-05-backd/blob/2a5664d35cde5b036074edef3c1369b984d10010/protocol/contracts/tokenomics/FeeBurner.sol#L56
https://github.com/code-423n4/2022-05-backd/blob/2a5664d35cde5b036074edef3c1369b984d10010/protocol/contracts/tokenomics/InflationManager.sol#L116
https://github.com/code-423n4/2022-05-backd/blob/2a5664d35cde5b036074edef3c1369b984d10010/protocol/contracts/tokenomics/VestedEscrow.sol#L94
https://github.com/code-423n4/2022-05-backd/blob/2a5664d35cde5b036074edef3c1369b984d10010/protocol/contracts/zaps/PoolMigrationZap.sol#L22
https://github.com/code-423n4/2022-05-backd/blob/2a5664d35cde5b036074edef3c1369b984d10010/protocol/contracts/zaps/PoolMigrationZap.sol#L39