> 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.
Gas Comparison
> 0
is less efficient than!= 0
for unsigned integersit may seem that
> 0
is cheaper than!=
, this is only true without the optimizer enabled and outside arequire
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