Every reading from storage costs about 100 gas while every reading from memory costs only 3 gas. If state variable referred more than once within a function then it is cheaper to cached it in local memory (100 gas) and then read it from memory wnen it is neaded (3 gas) rather than read state variable from storage everytime (100 gas).
Report
Gas Optimizations
[G-01]: Place subtractions where the operands can't underflow in unchecked {} block
Context:
Description:
Some gas can be saved by using an unchecked {} block if an underflow isn't possible because of a previous require() or if-statement.
[G-02]: If internal function called only once it can be inlined to save gas
Context:
[G-03]: Catch a value inside a mapping/array in local memory
Context:
https://github.com/code-423n4/2022-10-inverse/blob/main/src/Market.sol#L246
https://github.com/code-423n4/2022-10-inverse/blob/main/src/DBR.sol#L123-L124
https://github.com/code-423n4/2022-10-inverse/blob/main/src/DBR.sol#L136-L137
https://github.com/code-423n4/2022-10-inverse/blob/main/src/DBR.sol#L286-L287
https://github.com/code-423n4/2022-10-inverse/blob/main/src/Oracle.sol#L80-L86
https://github.com/code-423n4/2022-10-inverse/blob/main/src/Oracle.sol#L114-L120
Recommendation:
Example how to fix. Change:
to:
[G-04]: Catch state variable in local memory and not re-read it from storage
Context:
https://github.com/code-423n4/2022-10-inverse/blob/main/src/Market.sol#L359-L360
https://github.com/code-423n4/2022-10-inverse/blob/main/src/Market.sol#L376-L377
https://github.com/code-423n4/2022-10-inverse/blob/main/src/Market.sol#L605-L606
https://github.com/code-423n4/2022-10-inverse/blob/main/src/Oracle.sol#L67-L68
Description:
Every reading from storage costs about 100 gas while every reading from memory costs only 3 gas. If state variable referred more than once within a function then it is cheaper to cached it in local memory (100 gas) and then read it from memory wnen it is neaded (3 gas) rather than read state variable from storage everytime (100 gas).
Recommendation:
Example how to fix. Change:
to:
[G-05]: No need to catch state variable in local memory if it only use once
Context:
Recommendation:
Read the state variable from storage.