code-423n4 / 2021-10-covalent-findings

0 stars 0 forks source link

Change unchanged storage variables to constants can save gas #54

Closed code423n4 closed 3 years ago

code423n4 commented 3 years ago

Handle

WatchPug

Vulnerability details

Some storage variables include divider, validatorCoolDown, delegatorCoolDown, maxCapMultiplier, allocatedTokensPerEpoch, globalExchangeRate and CQT are only set once in initialize() and never changed.

Changing them to constant can save gas.

Recommendation

Consider changing to constant and using all caps for the names.

uint256 constant DIVIDER = 10**18; // 18 decimals
uint128 constant VALIDATOR_COOL_DOWN = 180*6646; // ~ 6 months
uint128 constant DELEGATOR_COOL_DOWN = 28*6646; // ~ 28 days
uint128 constant MAX_CAP_MULTIPLIER = 10;
uint128 constant ALLOCATED_TOKENS_PER_EPOCH = 1*10**18; // should never be 0
uint128 constant GLOBAL_EXCHANGE_RATE = 10**18; // 1 to 1
IERC20 CQT = IERC20(0xD417144312DbF50465b1C641d016962017Ef6240);
kitti-katy commented 3 years ago

DIVIDER should be set to constant and there is a duplicate #27

These are changeable, (either in setters or potentially in future upgrade)

uint128 constant DELEGATOR_COOL_DOWN = 28*6646; // ~ 28 days
uint128 constant MAX_CAP_MULTIPLIER = 10;
uint128 constant ALLOCATED_TOKENS_PER_EPOCH = 1*10**18; // should never be 0
uint128 constant GLOBAL_EXCHANGE_RATE = 10**18; // 1 to 1
GalloDaSballo commented 3 years ago

Duplicate of #27