code-423n4 / 2022-06-notional-coop-findings

1 stars 1 forks source link

Gas Optimizations #231

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago

Split require to avoid using && opcode

Details: In L129-137 of wfCashLogic.sol consider changing the code

require(
            ac.hasDebt == 0x00 &&
            assets.length == 1 &&
            EncodeDecode.encodeERC1155Id(
                assets[0].currencyId,
                assets[0].maturity,
                assets[0].assetType
            ) == fCashID
        );

to the following version without the && operator:

require(ac.hasDebt == 0x00);
require(assets.length == 1);
require(EncodeDecode.encodeERC1155Id(
          assets[0].currencyId,
          assets[0].maturity,
            assets[0].assetType
        == fCashID));

Note: This optimization can became invalid if an error message is added to require. Furthermore, consider using custom errors to save gas.