code-423n4 / 2022-04-pooltogether-findings

0 stars 0 forks source link

Gas Optimizations #43

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago

[S]: Suggested optimation, save a decent amount of gas without compromising readability;

[M]: Minor optimation, the amount of gas saved is minor, change when you see fit;

[N]: Non-preferred, the amount of gas saved is at cost of readability, only apply when gas saving is a top priority.

[S] Changing unnecessary storage variables to immutable can save gas

https://github.com/pooltogether/aave-v3-yield-source/blob/e63d1b0e396a5bce89f093630c282ca1c6627e44/contracts/AaveV3YieldSource.sol#L127

  IAToken public aToken;

Considering that aToken will never change, changing it to immutable variable instead of a storage variable can save gas.

[S] SafeMath is no longer needed

SafeMath is no longer needed starting with Solidity 0.8. The compiler now has built in overflow checking.

Removing SafeMath can save some gas.

[S] _tokenAddress() can be changed to immutable to save gas from unnecessary external calls

https://github.com/pooltogether/aave-v3-yield-source/blob/e63d1b0e396a5bce89f093630c282ca1c6627e44/contracts/AaveV3YieldSource.sol#L231-L235

  function supplyTokenTo(uint256 _depositAmount, address _to) external override nonReentrant {
    uint256 _shares = _tokenToShares(_depositAmount);
    require(_shares > 0, "AaveV3YS/shares-gt-zero");

    address _underlyingAssetAddress = _tokenAddress();
    ...

Since _underlyingAssetAddress will never change, it can be change to a immutable variable in the constructor() and save a decent of gas from the unnecessary external calls in every supplyTokenTo() and redeemToken() txs.

PierrickGT commented 2 years ago

Great report by this warden, he should get extra points.

[S] Changing unnecessary storage variables to immutable can save gas

Duplicate of https://github.com/code-423n4/2022-04-pooltogether-findings/issues/1

[S] SafeMath is no longer needed

Duplicate of https://github.com/code-423n4/2022-04-pooltogether-findings/issues/11

[S] _tokenAddress() can be changed to immutable to save gas from unnecessary external calls

Duplicate of https://github.com/code-423n4/2022-04-pooltogether-findings/issues/19

gititGoro commented 2 years ago

Excellent report that was clearly composed with sponsor empathy in mind.