code-423n4 / 2022-03-volt-findings

0 stars 0 forks source link

Gas Optimizations #104

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago
  1. Unnecessary Zero Check

https://github.com/code-423n4/2022-03-volt/blob/f1210bf3151095e4d371c9e9d7682d9031860bbd/contracts/peg/NonCustodialPSM.sol#L292

amountFeiToTransfer doesnt need to be checked if was zero

Tool Used

Visual Studio Code, Manual Review

Reccomendation Mitigation

Remove it

  1. Betterway to use SafeERC20 function for gas saving

https://github.com/code-423n4/2022-03-volt/blob/main/contracts/pcv/PCVDeposit.sol this implementation can be used for another gas opt

Impact

Expensive gas

POC

https://docs.openzeppelin.com/contracts/3.x/api/token/erc20#SafeERC20

Tool Used

Manual Review

Reccomendation Mitigation Steps

by do not declaring using SafeERC20 for IERC20; and used safeTransfer and safeTransferFrom.

  1. change multiple if into if-elseif logic for saving more gas

https://github.com/code-423n4/2022-03-volt/blob/f1210bf3151095e4d371c9e9d7682d9031860bbd/contracts/peg/NonCustodialPSM.sol#L292-L298 This implementation can be using for saving more gas.

Tool used

Visual Studio Code, Manual Review

Recommended Mitigation Step

        if (amountFeiToTransfer != 0) {
            IERC20(volt()).safeTransfer(to, amountFeiToTransfer);
        }

        if (amountFeiToMint != 0) {
            rateLimitedMinter.mintVolt(to, amountFeiToMint);
        }

change to else if to save gas :

        if (amountFeiToTransfer != 0) {
            IERC20(volt()).safeTransfer(to, amountFeiToTransfer);
        } else if (amountFeiToMint != 0) {
            rateLimitedMinter.mintVolt(to, amountFeiToMint);
        }
  1. Unnecessary Constructor can be removed

https://github.com/code-423n4/2022-03-volt/blob/f1210bf3151095e4d371c9e9d7682d9031860bbd/contracts/refs/CoreRef.sol#L27

since this was no-op, removed this can be saving more gas.

Impact

Expensive gas

Tool used

Remix

Recommended Mitigation

Remove Constructor

  1. Public Function to External for saving gas

This functions could be set external to saving more gas gas

Impact

Expensive Gas

POC

https://github.com/code-423n4/2022-03-volt/blob/f1210bf3151095e4d371c9e9d7682d9031860bbd/contracts/core/Permissions.sol#L187 https://github.com/code-423n4/2022-03-volt/blob/f1210bf3151095e4d371c9e9d7682d9031860bbd/contracts/core/Permissions.sol#L202