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

0 stars 0 forks source link

Gas Optimizations #226

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago

Precompute constant hashes

Severity: Gas optimization
Context:
Description:

As listed in above context, there are several keccak256 operations performed on constant values. Instead of performing them on each invocation, these hashes should be precomputed and used directly to save gas.

Use unchecked blocks when safe to do so

Severity: Gas optimization
Context:
Description:

As listed in above context, there are several places in which math operations are executed in which we can be certain that an overflow/underflow is impossible. In these cases, we should place this logic within unchecked blocks to save gas.

Avoid recomputing logic which can be passed as parameters

Severity: Gas optimization
Context:
Description:

In Market.forceReplenish, the values deficit and replenishmentCost are computed. Despite the fact that Market.forceReplenish is the only possible caller of DBR.onForceReplenish, these values are re-computed, when they can be more efficiently passed as parameters.

Avoid revert strings greater than 32 bytes

Severity: Gas optimization
Context:
Description:

The revert string listed above in context is greater than 32 bytes long, costing additional gas on revert by requiring the management of multiple words in memory.

Can use uint256 instead of some smaller sized uints

Severity: Gas optimization
Context:
Description:

As listed above in context, occasionally there are instances of uints of <256 bits used when not necessary. Usage of smaller sized uints generally requires more gas as the values have to be converted to 256 bits to execute operations on them.

Use msg.sender directly instead of passing as param

Severity: Gas optimization
Context:

Description:

In BorrowController.borrowAllowed, msg.sender gets passed as a param when it would be more efficient to simply use msg.sender directly.

c4-judge commented 2 years ago

0xean marked the issue as grade-b