code-423n4 / 2022-10-inverse-findings

0 stars 0 forks source link

Gas Optimizations #538

Closed code423n4 closed 2 years ago

code423n4 commented 2 years ago

[01] Increment can be made unchecked to save gas

It can save 30-40 gas.

https://github.com/code-423n4/2022-10-inverse/blob/main/src/Market.sol#L521

[02] x += y costs more gas than x = x + y for state variables

Using the addition operator instead of plus-equals saves 113 gas.

https://github.com/code-423n4/2022-10-inverse/blob/main/src/Market.sol#L395

https://github.com/code-423n4/2022-10-inverse/blob/main/src/Market.sol#L397

https://github.com/code-423n4/2022-10-inverse/blob/main/src/Market.sol#L534-L535

[03] Cache state variable reads

Caching of a state variable replace each Gwarmaccess (100 gas) with a cheaper stack read.

https://github.com/code-423n4/2022-10-inverse/blob/main/src/Market.sol#L246

[04] Don’t compare boolean expressions to boolean literals

if ( == true) => if (), if ( == false) => if (!)

https://github.com/code-423n4/2022-10-inverse/blob/main/src/DBR.sol#L350

c4-judge commented 2 years ago

0xean marked the issue as grade-c