code-423n4 / 2021-09-yaxis-findings

0 stars 0 forks source link

Consider making some constants as non-public to save gas #94

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago

Handle

hrkrshnn

Vulnerability details

Consider making some constants as non-public to save gas

Each function part of contract's external interface is part of the function dispatch, i.e., every time a contract is called, it goes through a switch statement (a set of eq ... JUMPI blocks in EVM) matching the selector of each externally available functions with the chosen function selector (the first 4 bytes of calldata).

This means that any unnecessary function that is part of contract's external interface will lead to more gas for (almost) every single function calls to the contract. There are several cases where constants were made public. This is unnecessary; the constants can simply be read from the verified contract, i.e., it is unnecessary to expose it with a public function.

Examples

./contracts/v3/Harvester.sol:24:    uint256 public constant ONE_HUNDRED_PERCENT = 10000;
./contracts/v3/Vault.sol:29:    uint256 public constant MAX = 10000;
./contracts/v3/controllers/LegacyController.sol:20:    uint256 public constant MAX = 10000;
./contracts/v3/strategies/BaseStrategy.sol:37:    uint256 public constant ONE_HUNDRED_PERCENT = 10000;
./contracts/v3/Manager.sol:26:    uint256 public constant PENDING_STRATEGIST_TIMELOCK = 7 days;
./contracts/v3/Manager.sol:27:    uint256 public constant MAX_TOKENS = 256;
GalloDaSballo commented 2 years ago

Agree with the finding, although most of the time it's nice to have these constants as public