# Data ordering for the Double SHA-256 function for Equihash

**URL:** <https://forum.zcashcommunity.com/t/data-ordering-for-the-double-sha-256-function-for-equihash/39686>\
**Category:** Mining\
**Created:** [July 28, 2021, 4:43pm UTC](https://forum.zcashcommunity.com/t/data-ordering-for-the-double-sha-256-function-for-equihash/39686 "2021-07-28T16:43:12Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Reed](https://avatars.discourse-cdn.com/v4/letter/r/9de0a6/32.png) [@Reed](https://forum.zcashcommunity.com/u/Reed)\
**Post date:** [July 28, 2021, 4:43pm UTC](https://forum.zcashcommunity.com/t/data-ordering-for-the-double-sha-256-function-for-equihash/39686/1 "2021-07-28T16:43:12Z")

</div>

Hey everyone,

I’m developing a miner for the Equihash algorithm and I’m having some trouble finding out the ordering of the data I should send to the final double SHA-256 function. From what I read from [here](https://forum.zcashcommunity.com/t/easy-to-follow-description-of-the-equihash-algorithm/12689), I understand that I should send the Block Header (140 bytes) + SolutionSize (3 bytes) + Solution (1344 bytes), but I have no idea about the endianness of those fields or the order I’m supposed to send them.  
Do you guys have some examples that I could check out against? I’ve been using [this block header](https://gist.github.com/mtve/f35c090f4d93e4e71b74a6544fa5255f) as example up until now but I’m stuck in this last function.

Thanks!

---

<div class="post-metadata">

**Author:** ![extrapo](https://sea2.discourse-cdn.com/zcash/user_avatar/forum.zcashcommunity.com/extrapo/32/17568_2.png) [@extrapo](https://forum.zcashcommunity.com/u/extrapo)\
**Post date:** [July 29, 2021, 12:37pm UTC](https://forum.zcashcommunity.com/t/data-ordering-for-the-double-sha-256-function-for-equihash/39686/2 "2021-07-29T12:37:07Z")

</div>

Reading some other implementarions for this algorithm might clarify you,

> 139 repository results  
> [Repository search results · GitHub](https://github.com/search?q=Equihash)

---

<div class="post-metadata">

**Author:** ![Reed](https://avatars.discourse-cdn.com/v4/letter/r/9de0a6/32.png) [@Reed](https://forum.zcashcommunity.com/u/Reed)\
**Post date:** [July 29, 2021, 12:56pm UTC](https://forum.zcashcommunity.com/t/data-ordering-for-the-double-sha-256-function-for-equihash/39686/3 "2021-07-29T12:56:09Z")

</div>

Thank you, I’ll take a look!

---

<div class="post-metadata">

**Author:** ![android13](https://avatars.discourse-cdn.com/v4/letter/a/ac8455/32.png) [@android13](https://forum.zcashcommunity.com/u/android13)\
**Post date:** [August 10, 2021, 7:14pm UTC](https://forum.zcashcommunity.com/t/data-ordering-for-the-double-sha-256-function-for-equihash/39686/4 "2021-08-10T19:14:42Z")

</div>

Can you give any details on your miner? I’d be interested to hear any info you’d like to share. I personally found this one to be very good to study:

> **[GitHub - mbevand/silentarmy: Zcash miner optimized for AMD & Nvidia GPUs](https://github.com/mbevand/silentarmy)**
>
> Zcash miner optimized for AMD & Nvidia GPUs. Contribute to mbevand/silentarmy development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![Reed](https://avatars.discourse-cdn.com/v4/letter/r/9de0a6/32.png) [@Reed](https://forum.zcashcommunity.com/u/Reed)\
**Post date:** [August 11, 2021, 7:19am UTC](https://forum.zcashcommunity.com/t/data-ordering-for-the-double-sha-256-function-for-equihash/39686/5 "2021-08-11T07:19:02Z")

</div>

It’s a pretty standard Equihash(200,9) solver. I generate the Blake hashes using the block header I’ve linked, then distribute them into buckets and look for collisions on the first 20 bits in each bucket, repeat until the last round, where I look for collisions on the remaining 40it.  
I’ve got the right solution, but a bunch of other solutions too, so I need to look into why I’m getting more than one when this block header is supposed to give out only one.  
There’s a caveat though, I’m planning to deploy this code to an FPGA to see what can I get.  
Thanks for the link, I’ll be looking into it. Feel free to ask more questions if you wish 😃

---

<div class="post-metadata">

**Author:** ![Reed](https://avatars.discourse-cdn.com/v4/letter/r/9de0a6/32.png) [@Reed](https://forum.zcashcommunity.com/u/Reed)\
**Post date:** [August 12, 2021, 6:56am UTC](https://forum.zcashcommunity.com/t/data-ordering-for-the-double-sha-256-function-for-equihash/39686/6 "2021-08-12T06:56:54Z")

</div>

Just a question, in the solutions [here](https://github.com/mbevand/silentarmy/blob/master/testing/sols-100), the value of Soln: 0x0 (for example) is the BlockHeader we should send to the Equihash function, right? And each header can have more than one solution, correct?

---

<div class="post-metadata">

**Author:** ![android13](https://avatars.discourse-cdn.com/v4/letter/a/ac8455/32.png) [@android13](https://forum.zcashcommunity.com/u/android13)\
**Post date:** [August 13, 2021, 6:43pm UTC](https://forum.zcashcommunity.com/t/data-ordering-for-the-double-sha-256-function-for-equihash/39686/7 "2021-08-13T18:43:08Z")

</div>

I think those are the hex representation of the 512 solutions (in this case “solution” is the 512 blake2 hashes that xor to 0), these are added to the block header and hashed with sha256, and if the difficult is matched, it’s a solution for the block. Some one please correct if that’s wrong!

---

<div class="post-metadata">

**Author:** ![Reed](https://avatars.discourse-cdn.com/v4/letter/r/9de0a6/32.png) [@Reed](https://forum.zcashcommunity.com/u/Reed)\
**Post date:** [August 16, 2021, 7:04am UTC](https://forum.zcashcommunity.com/t/data-ordering-for-the-double-sha-256-function-for-equihash/39686/8 "2021-08-16T07:04:14Z")

</div>

Yep, you’re right. Before adding them to the BlockHeader to be hashes, you’ll need to encode them from 32 bits to 21. I tested my implementation with some of those headers and got good results, however it generates way too many duplicated solutions, I’m looking into that now.
