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

1 stars 0 forks source link

Gas Optimizations #224

Closed code423n4 closed 2 years ago

code423n4 commented 2 years ago

Use Custom Errors instead of requires with reason strings

The contracts use a number of require() calls with error reason strings. In total there are 57 calls including 34 in InfinityExchange and 9 in InfinityStaker.

Gas can be saved by changing these to use Custom Errors. In particular deployment gas is saved as the strings are replaced by just 4 bytes for the error signature.

As described in the Solidity blog:

require(condition, "error message") should be translated to if (!condition) revert CustomError().

Duplicated function _getCurrentPrice

This function is defined in InfinityOrderBookComplication AND InfinityExchange.

It could be moved to a deployed library and linked into each of these contracts to save on deployment gas.

It would also improve code quality to write some tests against this function directly. Currently it is indirectly tested through other functions.

Unused function InfinityToken._burn can be removed

Removing this will save deployment gas. It's internal and not called.

liu-zhipeng commented 2 years ago

Referring to another project. InfinityToken

0xleastwood commented 2 years ago

RIP gas report