Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extend v4 difficulty algorithm (two variants) #6

Merged

Conversation

psychocrypt
Copy link
Contributor

@psychocrypt psychocrypt commented Dec 14, 2018

Correct "invalid" timestamps.

  • add algorithm v4-interp2 and v4-interp6
  • remove 99% correction

This PR is equal to #5 but v4-interp2 has lower guards fir the first last block and allow a mx change in hashrate per block by +-20%

Why should it be useful to correct the timestamps?

In the perfect blockchain world all system clocks are synced and it is not possible to set an arbitrary time stamp. In that case it will never be possible to have negative block time differences because you can not mine a block before the previous block is known. From that all timestamps are growing with the block index. v4-interp assumes that there are valid timestamps in the sequence of blocks those are used to calculate the difficulty. Valid timestamps are used as boundary condition to correct time stamps to be a sequence with increasing timestamps per block index.

description

This algorithms performs like the v4 implementation. The difference is that there is no 99% reduction to correct the difficulty and negative differences will not be set to zero.
"Invalid" time stamps will be masked and corrected later. Invalid means in the case of v4-interp that the difference between two block timestamps is negative. If so it is not clear if the new timestamp is manipulated to point to the past or if the previous is set to the future. Therefore the newer and previous timestamp are marked as invalid.
Invalid timestamps are corrected in a second step. A valid previous and a valid time stamp from a future block will be used to interpolate linearly new time stamps for all invalid blocks between this two valid blocks.

diff_algo

The figure show a sequence of block timestamps where a newer block has a time stamp before the previous block. The read blocks are marked as invalid and the timings gets corrected. For the correction the timestamp of block 1 and 4 are used.

- update v3 algorithm to the algorithm used in RYO
- rename old v3 implementation to v4 (possible next algorithm in RYO)
- update attack simulation to support v4 with the requirement that N + 1 timestamps are available
- add tiny basic functors to allow faster attack vector tests
- add plot script
- extend output
@psychocrypt
Copy link
Contributor Author

psychocrypt commented Dec 14, 2018

./timedil_harness 50 'add,720|10:10' v4 > v4.txt;./timedil_harness 50 'add,720|10:10' v4-interp2 > v4-interp2.txt;./timedil_harness 50 'add,720|10:10' v3 > v3.txt;./timedil_harness 50 'add,720|10:10' v4-interp6 > v4-interp6.txt; ../plot v3.txt v4.txt v4-interp6.txt v4-interp2.txt

zawy12/difficulty-algorithms#30

Forwarded Timestamp Attack (FTL attack)

ftl

Correct "invalid" timestamps.

- add algorithm v4-interp2 and v4-interp6
- remove 99% correction
@psychocrypt psychocrypt force-pushed the topic-v4-interpolatedAlgorithm2 branch from 14e7a29 to dfff6ca Compare December 14, 2018 20:46
@psychocrypt
Copy link
Contributor Author

./timedil_harness 100 'set,s|10:10; set|10:14:1; addScaled,-1|10:14:1' v4 > v4.txt;./timedil_harness 100 'set,s|10:10; set|10:14:1; addScaled,-1|10:14:1' v3 > v3.txt; ./timedil_harness 100 'set,s|10:10; set|10:14:1; addScaled,-1|10:14:1' v4-interp6 > v4-interp6.txt; ./timedil_harness 100 'set,s|10:10; set|10:14:1; addScaled,-1|10:14:1' v4-interp2 > v4-interp2.txt; ../plot v3.txt v4.txt v4-interp6.txt v4-interp2.txt

Reverse Timestamp Attack 5 blocks

reversetattack

@psychocrypt
Copy link
Contributor Author

./timedil_harness 100 'hrMul,2|10:10' v4 > v4.txt ;./timedil_harness 100 'hrMul,2|10:10' v4-interp2 > v4-interp2.txt;./timedil_harness 100 'hrMul,2|10:10' v4-interp6 > v4-interp6.txt;./timedil_harness 100 'hrMul,2|10:10' v3 > v3.txt; ../plot v3.txt v4.txt v4-interp6.txt v4-interp2.txt

hash rate increase by a factor 2

factor2hash

@fireice-uk fireice-uk merged commit ffea838 into fireice-uk:master Dec 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants