Gas Optimizations #117
Labels
bug
Something isn't working
G (Gas Optimization)
sponsor confirmed
Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")
GAS :
1.
Title : Its cheaper using delete
Impact :
In the removeLiquidity function if the diff value is 0, its cheaper to use delete instead setting the pos, vAsset, vUSD, dToken to zero, this can save +- 3 gas
POC :
https://github.com/code-423n4/2022-02-hubble/blob/main/contracts/AMM.sol#L243-L246
Mitigation :
Title : its cheaper to save length value to a local variable
Impact : when using a loop, its cheaper to save the length value of an array to a variable, so the loop didn't have to read the storage length in each loop, but comparing with the length that was already save in the local variable. For an array that has a length 10 it can save +- 1800 gas.
POC :
https://github.com/code-423n4/2022-02-hubble/blob/main/contracts/ClearingHouse.sol#L122
https://github.com/code-423n4/2022-02-hubble/blob/main/contracts/ClearingHouse.sol#L130
https://github.com/code-423n4/2022-02-hubble/blob/main/contracts/ClearingHouse.sol#L170
https://github.com/code-423n4/2022-02-hubble/blob/main/contracts/ClearingHouse.sol#L194
Title : its cheaper to use block.timestamp directly
Impact :
Its cheaper to use block.timestamp directly instead calling it through a _blocktimestamp() function.
POC :
https://github.com/code-423n4/2022-02-hubble/blob/main/contracts/Oracle.sol#L65
The text was updated successfully, but these errors were encountered: