code-423n4 / 2021-07-sherlock-findings

0 stars 0 forks source link

[AaveV2.sol] Function that should be declared as external to save gas #55

Closed code423n4 closed 3 years ago

code423n4 commented 3 years ago

Handle

eriksal1217

Vulnerability details

Impact

Gas Optimization - This finding does not affect the contract negatively nor does it put funds or transactions at risk for the user. Optimizes the contract to use less gas

Proof of Concept

According to the Slither Analyzer documentation (https://github.com/crytic/slither/wiki/Detector-Documentation#public-function-that-could-be-declared-external), public functions that are never called by the contract itself should be declared as external to save gas. This allows the contract to read directly from the call data. Allows for gas savings if you change a function from public to external, as in the external functions you do not have the extra logic to copy the data to memory.


Code snippet:

deposit() should be declared external:

(contracts/strategies/AaveV2.sol#75-81)


Console output (Slither Analyzer):

getUnactivatedStakersPoolBalance(IERC20) should be declared external:

getTotalUnmintedSherX(IERC20) should be declared external:

accruedDebt(bytes32,IERC20) should be declared external:

getTotalAccruedDebt(IERC20) should be declared external:

accrueSherX(IERC20) should be declared external:

accrueSherXWatsons() should be declared external:

deposit() should be declared external:

Reference: https://github.com/crytic/slither/wiki/Detector-Documentation#public-function-that-could-be-declared-external


Tools Used

Sherlock Contracts Solidity (v 0.7.4) Slither Analyzer (v 0.8.0)

Recommended Mitigation Steps

  1. Clone repository for Sherlock Smart Contracts
  2. Create a python virtual environment with a stable python version
  3. Install Slither Analyzer on the python VEM
  4. Run Slither against all contracts
Evert0x commented 3 years ago

112