code-423n4 / 2022-05-bunker-findings

1 stars 0 forks source link

Gas Optimizations #128

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago

Gas Comparison

> 0 is less efficient than != 0 for unsigned integers

it may seem that > 0 is cheaper than !=, this is only true without the optimizer enabled and outside a require statement. If you enable the optimizer at 10k AND you’re in a require statement, this will save gas.

soruce : https://twitter.com/gzeon/status/1485428085885640706

POC : https://github.com/bunkerfinance/bunker-protocol/blob/752126094691e7457d08fc62a6a5006df59bd2fe/contracts/Oracles/UniswapV2PriceOracle.sol#L67 https://github.com/bunkerfinance/bunker-protocol/blob/752126094691e7457d08fc62a6a5006df59bd2fe/contracts/Oracles/UniswapV2PriceOracle.sol#L91 https://github.com/bunkerfinance/bunker-protocol/blob/752126094691e7457d08fc62a6a5006df59bd2fe/contracts/Oracles/UniswapV2PriceOracle.sol#L115