/ EIPS / eip-100.md
eip-100.md
 1  ---
 2  eip: 100
 3  title: Change difficulty adjustment to target mean block time including uncles
 4  author: Vitalik Buterin (@vbuterin)
 5  type: Standards Track
 6  category: Core
 7  status: Final
 8  created: 2016-04-28
 9  ---
10  
11  ### Specification
12  
13  Currently, the formula to compute the difficulty of a block includes the following logic:
14  
15  ``` python
16  adj_factor = max(1 - ((timestamp - parent.timestamp) // 10), -99)
17  child_diff = int(max(parent.difficulty + (parent.difficulty // BLOCK_DIFF_FACTOR) * adj_factor, min(parent.difficulty, MIN_DIFF)))
18  ...
19  ```
20  
21  If `block.number >= BYZANTIUM_FORK_BLKNUM`, we change the first line to the following:
22  
23  ``` python
24  adj_factor = max((2 if len(parent.uncles) else 1) - ((timestamp - parent.timestamp) // 9), -99)
25  ```
26  ### Rationale
27  
28  This new formula ensures that the difficulty adjustment algorithm targets a constant average rate of blocks produced including uncles, and so ensures a highly predictable issuance rate that cannot be manipulated upward by manipulating the uncle rate. A formula that accounts for the exact number of included uncles:
29  ``` python
30  adj_factor = max(1 + len(parent.uncles) - ((timestamp - parent.timestamp) // 9), -99)
31  ```
32  can be fairly easily seen to be (to within a tolerance of ~3/4194304) mathematically equivalent to assuming that a block with `k` uncles is equivalent to a sequence of `k+1` blocks that all appear with the exact same timestamp, and this is likely the simplest possible way to accomplish the desired effect. But since the exact formula depends on the full block and not just the header, we are instead using an approximate formula that accomplishes almost the same effect but has the benefit that it depends only on the block header (as you can check the uncle hash against the blank hash).
33  
34  Changing the denominator from 10 to 9 ensures that the block time remains roughly the same (in fact, it should decrease by ~3% given the current uncle rate of 7%).
35  
36  ### References
37  
38  1. EIP 100 issue and discussion: https://github.com/ethereum/EIPs/issues/100
39  2. https://bitslog.wordpress.com/2016/04/28/uncle-mining-an-ethereum-consensus-protocol-flaw/