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

Verify against difficulty #185

Closed
chfast opened this issue Sep 30, 2021 · 1 comment · Fixed by #195
Closed

Verify against difficulty #185

chfast opened this issue Sep 30, 2021 · 1 comment · Fixed by #195
Labels
enhancement New feature or request

Comments

@chfast
Copy link
Owner

chfast commented Sep 30, 2021

The final hash verification is

final_hash <= 2^256 / difficulty

The current verify() API takes boundary = 2^256 / difficulty instead of difficulty. The boundary is commonly used in mining for efficiency. However, for block hash verification this is not optimal because clients have to compute 2^256 / difficulty inversion for every block hash.

We propose to add additional function which takes difficulty argument directly: verify_against_difficulty().
Internally, we can perform much more efficient check:

final_hash * difficulty <= 2^256

This has been tested and the formula is also valid for difficulty 0 and 1.

We also propose to rename verify() to verify_against_boundary() to disambiguate.
And change verify_final_hash() to verify_final_hash_against_difficulty() as this function is suppose to be used for quick block hash verification.

@chfast chfast added the enhancement New feature or request label Sep 30, 2021
@AndreaLanfranchi
Copy link

I'm totally in favor of this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants