code-423n4 / 2021-11-streaming-findings

0 stars 0 forks source link

Gas Optimization on the Public Functions #247

Closed code423n4 closed 2 years ago

code423n4 commented 2 years ago

Handle

defsec

Vulnerability details

Impact

This does not directly impact the smart contract in anyway besides cost. This is a gas optimization to reduce cost of smart contract. Calling each function, we can see that the public function uses 496 gas, while the external function uses only 261.

Proof of Concept

According to Slither Analyzer documentation (https://github.com/crytic/slither/wiki/Detector-Documentation#public-function-that-could-be-declared-external), there are functions in the contract that are never called. These functions should be declared as external in order to save gas.

Slither Detector:

external-function:

https://github.com/code-423n4/2021-11-streaming/blob/main/Streaming/src/Locke.sol#L532

https://github.com/code-423n4/2021-11-streaming/blob/main/Streaming/src/Locke.sol#L516

https://github.com/code-423n4/2021-11-streaming/blob/main/Streaming/src/Locke.sol#L500

https://github.com/code-423n4/2021-11-streaming/blob/main/Streaming/src/Locke.sol#L487

https://github.com/code-423n4/2021-11-streaming/blob/main/Streaming/src/Locke.sol#L455

https://github.com/code-423n4/2021-11-streaming/blob/main/Streaming/src/Locke.sol#L417

https://github.com/code-423n4/2021-11-streaming/blob/main/Streaming/src/Locke.sol#L377

https://github.com/code-423n4/2021-11-streaming/blob/main/Streaming/src/Locke.sol#L365

Tools Used

Slither

Recommended Mitigation Steps

  1. Get Smart Contracts from the Repository.
  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.
  5. Define public functions as an external for the gas optimization.
0xean commented 2 years ago

dupe of #260