Difficulty Adjustment
Zilliqa has a dynamic difficulty level adjustment mechanism. The goal of this mechanism is to adjust the difficulty level according to the number of PoW submissions received.
When the network receives a low number of PoW submissions, the mechanism will reduce the difficulty so that more nodes can join and maintain the network. On the other hand, when the network receives a high number of PoW submissions, the mechanism will increase the difficulty level, making it harder for Sybil attacks to be executed.
Adjustment Procedure
- When we bootstrap the system, every node reads the initial difficulty level
from
constants.xml
. After that, the nodes will update the difficulty level at the first transaction epoch of each DS epoch - At the beginning of each DS epoch, every DS node receives PoW submissions and
records them. When the DS leader proposes the next DS block, it calls
CalculateNewDifficulty()
andCalculateNewDSDifficulty()
to calculate the new difficulty levels. These difficulty levels are placed in them_dsDifficulty
andm_difficulty
fields in the DS block. Finally, the DS leader announces the DS block to start the consensus - The DS backup nodes receive the announcement, and calculate the new
difficulty by similarly calling
CalculateNewDifficulty()
andCalculateNewDSDifficulty()
then comparing the results with those proposed by the DS leader - Once the DS committee completes consensus over the DS block containing the new difficulty level, the committee broadcasts the block to the shards. The shard nodes accept the new difficulty and use it to do PoW for the next DS epoch
- New nodes that are not part of the network can get the latest difficulty from the lookup nodes by retrieving the latest DS block
Adjustment Formula and Parameters
There are 4 parameters in constants.xml
that are used to calculate the
difficulty:
POW_CHANGE_TO_ADJ_DIFF
POW_CHANGE_TO_ADJ_DS_DIFF
EXPECTED_SHARD_NODE_NUM
NUM_DS_ELECTION
Additionally, there are two dynamic parameters that are used to calculate the difficulty:
- The number of shard PoW submissions
- The number of DS PoW submissions
The basic formulas used to calculate the new difficulty are: