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

Inconsistency between yellow paper and Ethash wiki #517

Closed
pgebal opened this issue Jan 31, 2018 · 7 comments
Closed

Inconsistency between yellow paper and Ethash wiki #517

pgebal opened this issue Jan 31, 2018 · 7 comments
Labels

Comments

@pgebal
Copy link

pgebal commented Jan 31, 2018

Hi,
Please take a look at eq. 230 in yellow paper and Ethash wiki implementation of get_cache_size function. If the function was implemented as in yellow paper we would have sz -= HASH_BYTES instead of sz -= 2 * HASH_BYTES. ethereumj and pyethereum implementations follow Ethash wiki. Which version is correct? Should I follow Ethash wiki or yellow paper when implementing Ethash?

@pirapira
Copy link
Member

I'll compare both with implementations.

@pirapira
Copy link
Member

Wait, the formula in YP doesn't even terminate.

pirapira added a commit to pirapira/yellowpaper that referenced this issue Jan 31, 2018
See ethereum#517

This has to be ported to all protocol versions.
@pirapira
Copy link
Member

@pgebal does this look good? #519

@pirapira
Copy link
Member

pirapira commented Feb 1, 2018

@pgebal I realized something. Whichever definition you choose, they result in the same cache size, because no even number is prime.

@pirapira pirapira closed this as completed Feb 1, 2018
@pirapira
Copy link
Member

pirapira commented Feb 5, 2018

Whenever (sz / HASH_BYTES) is an odd number at least three, the loop

    while not isprime(sz / HASH_BYTES):
        sz -= HASH_BYTES

runs even times. Say 119-> 118 (even, not a prime) -> 117 -> 116 (even, not a prime) -> 115.

So, the loop can be optimized, merging every two steps, into

    while not isprime(sz / HASH_BYTES):
        sz -= 2 * HASH_BYTES

@pgebal
Copy link
Author

pgebal commented Feb 5, 2018

You are right. Thank you.

@pirapira
Copy link
Member

pirapira commented Feb 5, 2018

I keep my pull requests open. Different formulations are confusing. Thank you for pointing them out.

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

No branches or pull requests

2 participants