code-423n4 / 2022-02-tribe-turbo-findings

1 stars 0 forks source link

Gas Optimizations #63

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago

Use custom errors

Solidity ^0.8.4 allow the use of custom errors to optimize gas usage. https://blog.soliditylang.org/2021/04/21/custom-errors/

Get id before push

There is no need to subtract https://github.com/code-423n4/2022-02-tribe-turbo/blob/66f27fe51083f49f7935e3fe594ab2380b75dee8/src/TurboMaster.sol#L171

        id = safes.length;
        // Add the safe to the list of Safes.
        safes.push(safe);

Function can be set external instead of public

https://github.com/code-423n4/2022-02-tribe-turbo/blob/66f27fe51083f49f7935e3fe594ab2380b75dee8/src/TurboRouter.sol#L118

    function boost(TurboSafe safe, ERC4626 vault, uint256 feiAmount) public authenticate(address(safe)) {
GalloDaSballo commented 2 years ago

I believe the first finding is valid, and would save 3 gas Disagree with the second one, the latest solidity versions won't have extra costs unless you're converting dynamic arrays into memory

3