From 39632e82832c7d746240c639c354f0d8c37c24bd Mon Sep 17 00:00:00 2001 From: teor Date: Thu, 12 Nov 2020 18:39:05 +1000 Subject: [PATCH] Difficulty RFC: Clarify some ambiguities in the Zcash specification --- .../dev/rfcs/0006-contextual-difficulty.md | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/book/src/dev/rfcs/0006-contextual-difficulty.md b/book/src/dev/rfcs/0006-contextual-difficulty.md index 23b2caa6455..919223ca925 100644 --- a/book/src/dev/rfcs/0006-contextual-difficulty.md +++ b/book/src/dev/rfcs/0006-contextual-difficulty.md @@ -114,11 +114,13 @@ that there will be at least 28 blocks in any relevant chain on mainnet and testnet. Difficulty threshold calculations are performed using unsigned 256-bit integers. -Time calculations are performed using unsigned 32-bit integers. +In the Zcash specification, time values are 32-bit integers. But the difficulty +adjustment calculations include time subtractions which could overflow an +unsigned type, so they are performed using signed 64-bit integers in `zcashd`. -TODO: - - check how zcashd implements signed median time differences - - open a ticket to update the Zcash spec +Zebra is free to implement its calculations in any way that produces equivalent +results. Using `u256` difficulty and `i64` times will allow us to write simple +Rust code which produces the correct results. ## State service interface changes [state-service-interface]: #state-service-interface @@ -177,10 +179,13 @@ chain. Zcash uses block difficulty thresholds in its difficulty adjustment calculations. (Block hashes are not used for difficulty adjustment.) -TODO: - - check if zcashd truncates the MeanTarget before dividing by - AveragingWindowTimespan (as well as after the division), and - - open a ticket to update the Zcash spec +Note that `zcashd` truncates the `MeanTarget` after the mean calculation, and +after dividing by `AveragingWindowTimespan`, but only one of these truncations +is reflected in the Zcash specification. + +See [ZIP PR 418] for details. + +[ZIP PR 418]: https://github.com/zcash/zips/pull/418 #### Median timespan [median-timespan]: #median-timespan @@ -197,8 +202,6 @@ Calculated using the difference of the median timespans for: but this terminology is confusing, because it is a difference of medians, rather than any "actual" elapsed time.) -TODO: open a Zcash spec clarification ticket - The median timespan is damped by the `PoWDampingFactor`, and bounded by `PoWMaxAdjustDown` and `PoWMaxAdjustUp`.