# Request to verify calculations for blake2b please

**URL:** <https://forum.zcashcommunity.com/t/request-to-verify-calculations-for-blake2b-please/30775>\
**Category:** Community Collaborations\
**Created:** [August 11, 2018, 11:10pm UTC](https://forum.zcashcommunity.com/t/request-to-verify-calculations-for-blake2b-please/30775 "2018-08-11T23:10:52Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![lxman](https://avatars.discourse-cdn.com/v4/letter/l/f08c70/32.png) [@lxman](https://forum.zcashcommunity.com/u/lxman)\
**Post date:** [August 11, 2018, 11:10pm UTC](https://forum.zcashcommunity.com/t/request-to-verify-calculations-for-blake2b-please/30775/1 "2018-08-11T23:10:52Z")

</div>

Hello,

I have been reading over this thread:

> [@Easy to follow description of the equihash algorithm](https://forum.zcashcommunity.com/t/easy-to-follow-description-of-the-equihash-algorithm/12689/22):
>
> Hi I’m a little confuse with this header 040000007003225F30E1015EE14609B222E6036B7572963E18355688A966BB0E00000000E53B8DC142BBF69584F26B5F1D2125B79F238E77D04A37CDFAE64D3CFE9B2E730000000000000000000000000000000000000000000000000000000000000000C85BDA595DB6121C4FFFFFFF05000000000000000000000000000000000000000000000000000000 and after + 00000000 and 01000000 and 02000000 then compute blake2b(50) I received these , that are different with your result index 0 ====\> aad5e0ace4562e371912fd1b266…

and have been working on my own implementation of a miner.

I have come to the point of actually calculating the hashes for the compiled units of work received from the stratum server. I have tested my calculation engine against the “classic” rfc7693 calculation and result for “abc.” Everything checks out. I have also compiled and done a few checks against this implementation:

> **[GitHub - metadings/Blake2B.cs: BLAKE2.cs source code package - C# implementation](https://github.com/metadings/Blake2B.cs)**
>
> BLAKE2.cs source code package - C# implementation

Things check out there as well, until I get to calculating the full hash on the 144-byte work (represented by the 288-byte string). At that point things seem to diverge, and I was wondering whether someone would be willing to check my results.

As a start, I need to ask one question. Am I correct in understanding that what I am processing will be the 144 bytes once the string is converted **from** hex to a byte array (i.e. the string “04000000” would be the bytes 0x04, 0x00, 0x00, 0x00)? Or am I supposed to process the string directly converted to bytes, in which case the previous example would become 0x30, 0x34, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30? The second option wouldn’t seem likely to me as the specification calls for a 144 byte work segment, and that would produce a 288 byte segment. I just wanted to make sure, though.

Anyway, for this input:

040000007003225F30E1015EE14609B222E6036B7572963E18355688A966BB0E00000000E53B8DC142BBF69584F26B5F1D2125B79F238E77D04A37CDFAE64D3CFE9B2E730000000000000000000000000000000000000000000000000000000000000000C85BDA595DB6121C4FFFFFFF0500000000000000000000000000000000000000000000000000000000000000

I receive:

10a71c3968181c4feb7b615f2e11ca551b5d41abb2d09818a1b20d2a4e3760f9d13aed079ffe3b1bac2b69c09239b955b260

using the first method (converting to a 144-byte work chunk) or:

82b56b82381ec3efca8ce131e90320706a17f0587109e34fa84ee60d60bff3310f8125657ccdd750b1ffd3f8e9ff4397d943

parsing the string byte for byte.

Do either of these results look correct?

Thank you in advance.

---

<div class="post-metadata">

**Author:** ![mtve](https://avatars.discourse-cdn.com/v4/letter/m/f0a364/32.png) [@mtve](https://forum.zcashcommunity.com/u/mtve)\
**Post date:** [August 12, 2018, 10:29am UTC](https://forum.zcashcommunity.com/t/request-to-verify-calculations-for-blake2b-please/30775/2 "2018-08-12T10:29:50Z")

</div>

> [@lxman](#):
>
> Am I correct in understanding that what I am processing will be the 144 bytes once the string is converted **from** hex to a byte array (i.e. the string “04000000” would be the bytes 0x04, 0x00, 0x00, 0x00)?

yes, all binary manipulations are going on bytes, definitely not on “hex string read by bytes”.

> [@](#):
>
> Anyway, for this input:

sorry, not quite clear what are you doing here.

for Blake2B ZCash-style hash of that 144 bytes I get:

```
302b73bb4f258cf918ad9d9555321f5f7a9e88392a1a4b674e4c420c5ecba665b5c412edda230dc93a4fce4956bc8f8dce74

```

---

<div class="post-metadata">

**Author:** ![lxman](https://avatars.discourse-cdn.com/v4/letter/l/f08c70/32.png) [@lxman](https://forum.zcashcommunity.com/u/lxman)\
**Post date:** [August 12, 2018, 2:08pm UTC](https://forum.zcashcommunity.com/t/request-to-verify-calculations-for-blake2b-please/30775/3 "2018-08-12T14:08:45Z")

</div>

Thank you. That agrees with what is listed in the discussion that I quoted previously. Obviously there is an error in my algorithm that I will have to track down. Your verification helps me to confirm that.

---

<div class="post-metadata">

**Author:** ![mtve](https://avatars.discourse-cdn.com/v4/letter/m/f0a364/32.png) [@mtve](https://forum.zcashcommunity.com/u/mtve)\
**Post date:** [August 12, 2018, 2:41pm UTC](https://forum.zcashcommunity.com/t/request-to-verify-calculations-for-blake2b-please/30775/4 "2018-08-12T14:41:31Z")

</div>

You may find [https://blake2.net/blake2.pdf](https://blake2.net/blake2.pdf) paragraph 2.8 and [zips/protocol.pdf at main · zcash/zips · GitHub](https://github.com/zcash/zips/blob/master/protocol/protocol.pdf) paragraph 5.4.1.9 useful to get what “Zcash-style” means here for Blake2B, since RFC 7693 paragraph 2.5 does not specify these Zcash’ details.

---

<div class="post-metadata">

**Author:** ![lxman](https://avatars.discourse-cdn.com/v4/letter/l/f08c70/32.png) [@lxman](https://forum.zcashcommunity.com/u/lxman)\
**Post date:** [August 13, 2018, 3:19am UTC](https://forum.zcashcommunity.com/t/request-to-verify-calculations-for-blake2b-please/30775/5 "2018-08-13T03:19:07Z")

</div>

Thank you. I will look into those.

---

<div class="post-metadata">

**Author:** ![lxman](https://avatars.discourse-cdn.com/v4/letter/l/f08c70/32.png) [@lxman](https://forum.zcashcommunity.com/u/lxman)\
**Post date:** [August 13, 2018, 3:43am UTC](https://forum.zcashcommunity.com/t/request-to-verify-calculations-for-blake2b-please/30775/6 "2018-08-13T03:43:58Z")

</div>

If I read 2.3 of [https://blake2.net/blake2.pdf](https://blake2.net/blake2.pdf), am I to understand that I should be using both f0 **and** f1 as end indicators?

---

<div class="post-metadata">

**Author:** ![lxman](https://avatars.discourse-cdn.com/v4/letter/l/f08c70/32.png) [@lxman](https://forum.zcashcommunity.com/u/lxman)\
**Post date:** [August 13, 2018, 7:39am UTC](https://forum.zcashcommunity.com/t/request-to-verify-calculations-for-blake2b-please/30775/7 "2018-08-13T07:39:05Z")

</div>

Okay, so think I’ve answered my own question. I went digging around in the nheqminer source and it would appear that no, f1 is not needed. With the last flag, just xor 0xFFFFFFFFFFFFFFFF with v[14] and that is sufficient.
