code-423n4 / 2021-12-perennial-findings

0 stars 0 forks source link

Use immutable variables can save gas #29

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago

Handle

WatchPug

Vulnerability details

https://github.com/code-423n4/2021-12-perennial/blob/fd7c38823833a51ae0c6ae3856a3d93a7309c0e4/protocol/contracts/oracle/ChainlinkOracle.sol#L20-L20

IChainlinkFeed public feed;

https://github.com/code-423n4/2021-12-perennial/blob/fd7c38823833a51ae0c6ae3856a3d93a7309c0e4/protocol/contracts/oracle/ChainlinkOracle.sol#L29-L29

uint256 private _decimalOffset;

In ChainlinkOracle.sol, feed and _decimalOffset will never change, use immutable variables instead of storage variables can save gas.

https://github.com/code-423n4/2021-12-perennial/blob/fd7c38823833a51ae0c6ae3856a3d93a7309c0e4/protocol/contracts/product/ProductProviderBase.sol#L13-L13

IOracle public oracle;

In ProductProviderBase.sol, oracle will never change, use immutable variables instead of storage variables can save gas.

GalloDaSballo commented 2 years ago

Finding is valid, for any variable that is only set once, either use a constant or immutable to save gas