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

0 stars 0 forks source link

Declaring unnecessary immutable variables as constant can save gas #267

Closed code423n4 closed 2 years ago

code423n4 commented 2 years ago

Handle

WatchPug

Vulnerability details

In LockeERC20, decimals is defined as an immutable variable while it's not configured as a parameter of the constructor. Thus, it can be declared as constant to save gas.

https://github.com/code-423n4/2021-11-streaming/blob/56d81204a00fc949d29ddd277169690318b36821/Streaming/src/LockeERC20.sol#L25-L25

uint8 public immutable decimals;

https://github.com/code-423n4/2021-11-streaming/blob/56d81204a00fc949d29ddd277169690318b36821/Streaming/src/LockeERC20.sol#L56-L74

    constructor(
        address depositToken,
        uint256 streamId,
        uint32 endStream
    ) {

        // locke + depositTokenName + streamId = lockeUSD Coin-1
        name = string(abi.encodePacked("locke", ERC20(depositToken).name(), ": ", toString(streamId)));
        // locke + Symbol + streamId = lockeUSDC1
        // TODO: we could have start_time+stream_duration+depositlocktime as maturity-date
        // i.e. lockeETH8-AUG-14-2022
        symbol = string(abi.encodePacked("locke", ERC20(depositToken).symbol(), toString(streamId)));
        decimals = 18;

        transferStartTime = endStream;

        INITIAL_CHAIN_ID = block.chainid;
        INITIAL_DOMAIN_SEPARATOR = computeDomainSeparator();
    }

Recommendation

Change to:

uint8 public constant decimals = 18;
0xean commented 2 years ago

dupe of #231