code-423n4 / 2022-06-badger-findings

0 stars 0 forks source link

Gas Optimizations #47

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago

Function can be marked view to save gas

Contract: https://github.com/Badger-Finance/vested-aura/blob/v0.0.2/contracts/MyStrategy.sol#L396

Issue: The _getBalance and _getPricePerFullShare can be marked as view

Recommendation: Change the function as below:

function _getBalance() internal view returns (uint256) {
        return IVault(vault).balance();
    }

    function _getPricePerFullShare() internal view returns (uint256) {
        return IVault(vault).getPricePerFullShare();
    }

Use ++i instead of i++

Make use of ++i which is unchecked instead of i++ in loops. This will prevent gas on each loop run. One such example is at MyStrategy.sol#L116

GalloDaSballo commented 2 years ago

Function can be marked view to save gas

I don't believe this saves gas

CALL and STATICCALL cost 100 both

Use ++i instead of i++

Saves 5 gas per instance