|
1 | 1 | ---
|
2 | 2 | sidebar_position: 3
|
3 | 3 | ---
|
4 |
| -# Difficulty Adjusting Algorithm |
5 | 4 |
|
| 5 | +# Difficulty Adjusting Algorithm |
| 6 | + |
| 7 | +How to adjust the difficulty target to ensure an average block generation time of 10 minutes. |
| 8 | + |
| 9 | +## What is a Difficulty Adjustment Algorithm? |
| 10 | + |
| 11 | +A difficulty adjustment algorithm adjusts the difficulty target based on the speed of past block production to ensure |
| 12 | +that new blocks are generated at an average time of 10 minutes. This algorithm is an important component of the |
| 13 | +blockchain network, controlling the block production speed, regulating the issuance rate of new coins, and ensuring the |
| 14 | +security and stability of the blockchain. |
| 15 | + |
| 16 | +The following explains Bitcoin's difficulty adjustment algorithm and the ASERT-DAA algorithm used in the MVC network. |
| 17 | + |
| 18 | +## Bitcoin's Difficulty Adjustment Algorithm |
| 19 | + |
| 20 | +Bitcoin adjusts its difficulty every 2016 blocks (approximately every two weeks). Here are the detailed steps of |
| 21 | +Bitcoin's difficulty adjustment algorithm: |
| 22 | + |
| 23 | +**Calculate Actual Time Taken** |
| 24 | + |
| 25 | +The actual time taken is the total time taken to generate the last 2016 blocks: |
| 26 | + |
| 27 | +$$ |
| 28 | +\text{Actual Time} = \text{Time of the Last Block} - \text{Time of the First Block} |
| 29 | +$$ |
| 30 | + |
| 31 | +**Calculate Target Time** |
| 32 | + |
| 33 | +The target time is the expected time to generate 2016 blocks: |
| 34 | + |
| 35 | +$$ |
| 36 | +\text{Target Time} = 2016 \times 10 \, \text{minutes} |
| 37 | +$$ |
| 38 | + |
| 39 | +$$ |
| 40 | +\text{Target Time} = 2016 \times 600 \, \text{seconds} |
| 41 | +$$ |
| 42 | + |
| 43 | +$$ |
| 44 | +\text{Target Time} = 1209600 \, \text{seconds} |
| 45 | +$$ |
| 46 | + |
| 47 | +**Calculate New Difficulty Target** |
| 48 | + |
| 49 | +The new difficulty target is adjusted based on the ratio of actual time to target time: |
| 50 | + |
| 51 | +$$ |
| 52 | +\text{New Difficulty Target} = \text{Old Difficulty Target} \times \left( \frac{\text{Actual Time}}{\text{Target Time}} |
| 53 | +\right) |
| 54 | +$$ |
| 55 | + |
| 56 | +**Limit Adjustment Range** |
| 57 | + |
| 58 | +To avoid drastic fluctuations in the difficulty target, the Bitcoin protocol limits the adjustment range to no more than |
| 59 | +four times or less than one-quarter of the previous difficulty: |
| 60 | + |
| 61 | +$$ |
| 62 | +\text{New Difficulty Target} = \min\left(\text{Old Difficulty Target} \times 4, \max\left(\frac{\text{Old Difficulty |
| 63 | +Target}}{4}, \text{New Difficulty Target}\right)\right) |
| 64 | +$$ |
| 65 | + |
| 66 | +The drawback of this method is that the adjustment speed is slow. For a mature and stable blockchain network like |
| 67 | +Bitcoin, this adjustment speed is acceptable. However, for emerging blockchain networks, price fluctuations may lead to |
| 68 | +significant changes in computing power, seriously affecting block production speed. |
| 69 | + |
| 70 | +When BCH (Bitcoin Cash) first forked from Bitcoin, it faced block production difficulties due to computing power |
| 71 | +fluctuations. BCH initially adopted the EDA (Emergency Difficulty Adjustment) algorithm to adjust the difficulty in a |
| 72 | +shorter time, ensuring block production speed. However, the EDA algorithm had some issues and was vulnerable to attacks. |
| 73 | +Therefore, BCH later adopted the ASERT-DAA algorithm, which performed well in the BCH network. Consequently, the MVC |
| 74 | +network also adopted the ASERT-DAA algorithm. |
| 75 | + |
| 76 | +## ASERT-DAA Algorithm |
| 77 | + |
| 78 | +The [ASERT-DAA](https://github.com/bitcoincashorg/bitcoincash.org/blob/master/spec/2020-11-15-asert.md) algorithm is a |
| 79 | +difficulty adjustment algorithm used in the BCH network. It is a dynamic difficulty adjustment algorithm based on |
| 80 | +computing power that can adjust the difficulty in a short time to ensure an average block production time of 10 minutes. |
| 81 | + |
| 82 | +The Automatic Difficulty Adjustment by Smoothly Updating and Real-Time Targeting (Asert) algorithm was introduced in the |
| 83 | +November 15, 2020, upgrade of Bitcoin Cash. Here are the features and calculation steps of the Asert difficulty |
| 84 | +adjustment algorithm: |
| 85 | + |
| 86 | +### Features of the Asert Difficulty Adjustment Algorithm |
| 87 | + |
| 88 | +1. **Continuous Adjustment**: |
| 89 | + The Asert algorithm employs a continuous difficulty adjustment mechanism instead of adjusting every 2016 blocks. This |
| 90 | + allows it to more promptly reflect changes in computing power and maintain a more stable block production time. |
| 91 | + |
| 92 | +2. **Time Parameterization**: |
| 93 | + Asert adjusts difficulty directly based on the difference between actual and target block production times, making |
| 94 | + the adjustments more flexible and precise. |
| 95 | + |
| 96 | +3. **Exponential Smoothing**: |
| 97 | + The Asert algorithm uses exponential smoothing to avoid drastic fluctuations in the difficulty target, ensuring |
| 98 | + smooth transitions and stability. |
| 99 | + |
| 100 | +### Asert Difficulty Adjustment Formula |
| 101 | + |
| 102 | +The core formula of the Asert algorithm is as follows: |
| 103 | + |
| 104 | +$$ |
| 105 | +D_{next} = D_{prior} \times 2^{\left( \frac{t_{actual} - t_{expected}}{T} \right) / \tau} |
| 106 | +$$ |
| 107 | + |
| 108 | +Where: |
| 109 | + |
| 110 | +- $ D_{next}$ is the difficulty target for the next block. |
| 111 | +- $ D_{prior}$ is the current block's difficulty target. |
| 112 | +- $ t_{actual}$ is the difference in timestamps between the current block and the last adjusted block. |
| 113 | +- $ t_{expected}$ is the target block time interval multiplied by the number of blocks. |
| 114 | +- $ T$ is the target block time, usually 600 seconds (10 minutes). |
| 115 | +- $ \tau$ is a time constant used for smoothing adjustments, typically 172800 seconds (2 days). |
| 116 | + |
| 117 | +### Calculation Steps |
| 118 | + |
| 119 | +1. **Calculate Time Difference**: |
| 120 | + Calculate the difference in timestamps between the current block and the last adjusted block, i.e., $ t_{actual}$. |
| 121 | + |
| 122 | +2. **Calculate Target Time Difference**: |
| 123 | + Calculate the target time difference based on the expected block time interval and the actual number of blocks, |
| 124 | + i.e., $ t_{expected}$. |
| 125 | + |
| 126 | +3. **Calculate Difficulty Adjustment Factor**: |
| 127 | + Use the formula to calculate the difficulty adjustment factor: |
| 128 | + |
| 129 | + $$ |
| 130 | + \text{Adjustment Factor} = 2^{\left( \frac{t_{actual} - t_{expected}}{T} \right) / \tau} |
| 131 | + $$ |
| 132 | + |
| 133 | +4. **Calculate Next Block's Difficulty Target**: |
| 134 | + Calculate the next block's difficulty target using the adjustment factor: |
| 135 | + |
| 136 | + $$ |
| 137 | + D_{next} = D_{prior} \times \text{Adjustment Factor} |
| 138 | + $$ |
| 139 | + |
| 140 | +### Example |
| 141 | + |
| 142 | +Suppose the current block's difficulty target $ D_{prior} $ is 100000, the actual time difference $ t_{actual}$ is 1200 |
| 143 | +seconds, the target time difference $ t_{expected}$ is 600 seconds, the target block time $ T$ is 600 seconds, and the |
| 144 | +time constant $ \tau$ is 172800 seconds. |
| 145 | + |
| 146 | +1. **Calculate Time Difference**: |
| 147 | + |
| 148 | + $$ |
| 149 | + t_{actual} = 1200 |
| 150 | + $$ |
| 151 | + $$ |
| 152 | + t_{expected} = 600 |
| 153 | + $$ |
| 154 | + |
| 155 | +2. **Calculate Adjustment Factor**: |
| 156 | + |
| 157 | + $$ |
| 158 | + \text{Adjustment Factor} = 2^{\left( \frac{1200 - 600}{600} \right) / 172800} |
| 159 | + $$ |
| 160 | + $$ |
| 161 | + \text{Adjustment Factor} = 2^{\left( \frac{600}{600} \right) / 172800} |
| 162 | + $$ |
| 163 | + $$ |
| 164 | + \text{Adjustment Factor} = 2^{1 / 172800} |
| 165 | + $$ |
| 166 | + |
| 167 | +3. **Calculate New Difficulty Target**: |
| 168 | + |
| 169 | + $$ |
| 170 | + D_{next} = 100000 \times 2^{1 / 172800} |
| 171 | + $$ |
| 172 | + |
| 173 | +This calculation enables the MVC network to more smoothly adjust the difficulty, addressing computing power fluctuations |
| 174 | +and ensuring network stability and reliability. |
0 commit comments