ain icon indicating copy to clipboard operation
ain copied to clipboard

block.timestamp is not strictly ascending

Open kuegi opened this issue 8 months ago • 2 comments

Summary

On EVM, many protocols rely on block.timestamp to be strictly ascending (it must always be true that block(n).timestamp > block(n-1).timestamp ) On defichain, the native blocks (which define also the EVM timestamp) are not always fulfilling this which leads to problems in protocolls like UniSwapV2

f.e. see the calculation of cumulativePrice in UniswapV2 : https://github.com/Uniswap/v2-core/blob/ee547b17853e71ed4e0101ccfd52e70d5acded58/contracts/UniswapV2Pair.sol#L77-L81

(if swaps happen on blocks with negative time delta, the cumulative assumes that they are MAX_UINT112 apart and increases massively. But next check in any oracle shows a positive (small) delta between last check and current timestamp which messes up any calculation)

This is already affecting live protocolls. Currently seahorse cause the cumulative price in JAV-DFI pool triggered the issue at least once and is completely off now.

kuegi avatar Jun 07 '24 06:06 kuegi