code-423n4 / 2022-09-frax-findings

2 stars 1 forks source link

Gas Optimizations #315

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago

Using assembly to optimize ETH sending

Change

        (bool success,) = payable(to).call{ value: amount }("");
        require(success, "Invalid transfer");

to

        bool success;

        assembly {
            // Transfer the ETH and store if it succeeded or not.
            success := call(gas(), to, amount, 0, 0, 0, 0)
        }

        if(!success) revert ETH_TRANSFER_FAILED();

Use unchecked { ++i; }

for (uint256 i = 0; i < numDeposits; ++i) {

Should be

for (uint256 i = 0; i < numDeposits; ) {
    ...
    unchecked { ++i; }
}

Use custom errors instead of requires

require(!depositEtherPaused, "Depositing ETH is paused");

Should be

error Paused();
...
if (depositEtherPaused) revert Paused();