code-423n4 / 2022-03-prepo-findings

0 stars 0 forks source link

Gas Optimizations #111

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago
  1. The default of uint is already 0

Proof of Concept: https://github.com/code-423n4/2022-03-prepo/blob/main/contracts/core/Collateral.sol#L81

Recommended Mitigation Steps: considered remove 0 value can save gas

========================================================================

  1. More efficient gas usage by removing && operator

Proof of Concept: https://github.com/code-423n4/2022-03-prepo/blob/main/contracts/core/DepositHook.sol#L31

Recommended Mitigation Steps: Example:

require( _accountAccessController.isAccountAllowed(_sender),"Account not allowed to deposit");
require( !_accountAccessController.isAccountBlocked(_sender),"Account not allowed to deposit");
``

========================================================================

3. Can save gas usage by using only `<` or `>` operator 

Proof of Concept:
https://github.com/code-423n4/2022-03-prepo/blob/main/contracts/core/PrePOMarket.sol#L185
https://github.com/code-423n4/2022-03-prepo/blob/main/contracts/core/PrePOMarket.sol#L189

Recommended Mitigation Steps:
Example:

require( _newFinalLongPrice > _floorLongPrice, "Price cannot be below floor" );


========================================================================

4. unused code

Proof of Concept:
https://github.com/code-423n4/2022-03-prepo/blob/main/contracts/core/AccountAccessController.sol#L15

Recommended Mitigation Steps:
remove it

========================================================================

5. using `unchecked` can save gas

Proof of Concept:
https://github.com/code-423n4/2022-03-prepo/blob/main/contracts/core/Collateral.sol#L70
https://github.com/code-423n4/2022-03-prepo/blob/main/contracts/core/Collateral.sol#L166

Recommended Mitigation Steps:
add `unchecked`

========================================================================

6. considered using `uint128` can save gas

Proof of Concept:
https://github.com/code-423n4/2022-03-prepo/blob/main/contracts/core/interfaces/ICollateral.sol#L20

Recommended Mitigation Steps:

struct WithdrawalRequest { uint128 amount; uint128 blockNumber; }



========================================================================
ramenforbreakfast commented 2 years ago

duplicate of #5 and #18