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

Why right-shift after generating blake2b hash? #4

Open
giulitu95 opened this issue Apr 30, 2020 · 0 comments
Open

Why right-shift after generating blake2b hash? #4

giulitu95 opened this issue Apr 30, 2020 · 0 comments

Comments

@giulitu95
Copy link

I want to adapt this algorithm in order to implement a ZCash miner. However, analysing the code I have some doubts about how XOR is computed in the various steps of the algorithm.
In function void Equihash::FillMemory(uint32_t length) hashes are generated in the following way:

for (unsigned i = 0; i < length; ++i, ++input[SEED_LENGTH + 1]) {
blake2b((uint8_t*)buf, &input, NULL, sizeof(buf), sizeof(input), 0);
uint32_t index = buf[0] >> (32 - n / (k + 1));
unsigned count = filledList[index];
if (count < LIST_LENGTH) {
for (unsigned j = 1; j < (k + 1); ++j) {
//select j-th block of n/(k+1) bits
tupleList[index][count].blocks[j - 1] = buf[j] >> (32 - n / (k + 1));
}
tupleList[index][count].reference = i;
filledList[index]++;
}
}

Why, at row 74, only the most significant n/(k + 1) bits of buf[j] are stored and why the remaining 32-n/(k+1) bits are not considered?

In function void Equihash::ResolveCollisions(bool store) tuples' blocks are XORed generating a new tupleList. Neveretheless, in this way, if I have correctly understood, in each step of the algorithm, every n/(k+1) bits are not considered sequentially.

I try to make an example:
k=9, n=200

On each step I'm interested in the next 20 bits i.e. bits from 0 to 19 on first step, 0 to 39 on second etc.
In this algorithm it seems to me that in the first step are considered bits from 0 to 19, 32 to 52 on second etc because the shift register operation cut off the bits from 20 to 31

@giulitu95 giulitu95 changed the title Implementation of a Zcash miner Why a right-shift operation is performed after generating blake2b hash? May 1, 2020
@giulitu95 giulitu95 changed the title Why a right-shift operation is performed after generating blake2b hash? Why a right-shift after generating blake2b hash? May 1, 2020
@giulitu95 giulitu95 changed the title Why a right-shift after generating blake2b hash? Why right-shift after generating blake2b hash? May 1, 2020
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

No branches or pull requests

1 participant