koinos / koinos-miner

The Koinos Miner (CLI) provides a functional command line interface that allows users to mine the KOIN ERC-20 which will be used to deliver an equitable initial token distribution on the Koinos blockchain.
https://koinos.io
GNU General Public License v3.0
16 stars 15 forks source link

Calculation of words compared with the smart contract #91

Closed joticajulian closed 3 years ago

joticajulian commented 3 years ago

I'm wondering why the miner hashes the seed as H(seed, i) where i is an integer between 0 and 9, while the smart contract hashes the seed as H(seed, y) where y is part of the work calculation.

Miner: https://github.com/koinos/koinos-miner/blob/5795a608933d3588d1b18bbbd69308227fef369d/miner/main.c#L424-L434 👆 this Hash is outside the while loop that rotates the nonce (seems like it doesn't depend on the nonce).

Smart Contract: https://github.com/koinos/koinos-erc20/blob/09199ada7201ff559d40cd24fd050e02230fe3a5/contracts/KnsTokenWork.sol#L42-L55 👆 this Hash is inside the work calculation, and the result depends on the nonce.

am I missing something?

joticajulian commented 3 years ago

Now I understand it. The i is not until 9 but until 2^16, so the miner is calculating all possible hashes and taking them in memory. And during the while loop, it is just picking up 10 of them on each iteration. Clever.