Uniswap / v2-core

🦄 🦄 Core smart contracts of Uniswap V2
https://uniswap.org/docs
GNU General Public License v3.0
2.92k stars 3.13k forks source link

Why uint32(block.timestamp % 2**32) ? #109

Closed mudgen closed 3 years ago

mudgen commented 3 years ago

The update function in UniswapV2Pair.sol has this line of code:

uint32 blockTimestamp = uint32(block.timestamp % 2**32);

In case of uint32 overflow the following return the same value:

uint32 blockTimestamp = uint32(block.timestamp % 2**32);
uint32 blockTimestamp = uint32(block.timestamp);

So why do this block.timestamp % 2**32 ?

It looks like the code is requiring the gas cost of doing a modulus operation for no reason.

Or is it done to show that overflow is okay?

moodysalem commented 3 years ago

You already reported this https://github.com/Uniswap/uniswap-v2-core/issues/96

mudgen commented 3 years ago

Oh, sorry, I didn't realize that.

Sufiyan-dev commented 2 years ago

can you explain us ??

Sufiyan-dev commented 2 years ago

can somebody explain why the value is not changing, even after block.timestamp % 2**32 ?? i know it is use for overflow but how ?

pradeepvarma22 commented 1 year ago

can somebody explain why the value is not changing, even after block.timestamp % 2**32 ?? i know it is use for overflow but how ?

This may help https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2020-September/018172.html

Sufiyan-dev commented 1 year ago

can somebody explain why the value is not changing, even after block.timestamp % 2**32 ?? i know it is use for overflow but how ?

This may help

https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2020-September/018172.html

Thanks i got it