From From EIP 2, the Homestead difficulty adjustment algorithm is:

    block_diff = parent_diff + parent_diff // 2048 * 
      max(1 - (block_timestamp - parent_timestamp) // 10, -99) + 
      int(2**((block.number // 100000) - 2))

where // is the integer division operator, eg. 6 // 2 = 3, 7 // 2 = 3, 8 // 2 = 4.

Due to differences in the clock settings on different miner's computers, can block_timestamp be before parent_timestamp?

And if block_timestamp CANNOT be before parent_timestamp, how are differences in the clock settings on different miner's computers taken into account?


EDIT June 12 2016 I've moved the second question above into How do Ethereum mining nodes maintain a time consistent with the network?

This question was prompted by the question How does the Ethereum Homestead difficulty adjustment algorithm work?, which was prompted by the question What was the first block mined with Homestead?



Other related Q&As:

up vote 9 down vote accepted

block_timestamp CANNOT be before parent_timestamp

This is enforced by the protocol, see yellow paper:

Hs is the timestamp of block H and must fulfil the relation: (48) Hs > P(H)Hs

Also in my empirical research on Homesteads blocktimes there was not a single negative value.

As mentioned, the protocol prevents this from happening.

As for miners' clocks, the protocol can't tell what their actual clock says. A miner could simply lie, put a different timestamp in, and the protocol would be none-the-wiser. The protocol attempts to prevent this by the difficulty adjustment formula.

To quote the Yellow Paper:

This mechanism enforces a homeostasis in terms of the time between blocks; a smaller period between the last two blocks results in an increase in the difficulty level and thus additional computation required, lengthening the likely next period. Conversely, if the period is too large, the difficulty, and expected time to the next block, is reduced.

The Homestead difficulty formula change was to address the very issue of miners reporting wrong timestamps.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.