Skip to content

Commit

Permalink
Difficulty RFC: Clarify some ambiguities in the Zcash specification
Browse files Browse the repository at this point in the history
  • Loading branch information
teor2345 committed Nov 12, 2020
1 parent 2476c0d commit 39632e8
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions book/src/dev/rfcs/0006-contextual-difficulty.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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`.

Expand Down

0 comments on commit 39632e8

Please sign in to comment.