Please login or register.

What are the inputs to the hash function?

I wrote an implementation of the cryptonight hash function (a purely academic exercise). Now I want to take it to the next level. I understand that hashing in reality involves a set of inputs, notably the previous block hash, some current transaction data, and a nonce. Is that correct? What is the actual raw input of the monero hash function?

I see the API has a "getblocktemplate" method which returns some of this data. The previous hash is there. Is the blob returned considered the current blob of transactions? If not, where does that come from? And in the end, how do I string this together with the prev hash and nonce to produce a new block?

Replies: 3
moneromooo posted 6 years ago Replies: 2 | Weight: 0 | Link [ - ]

For Cryptonight, the input is the "block hashing blob". This is basically the serialized block, plus the root of the merkle tree of transactions it contains and the number of transactions. I think getblocktemplate gets you pretty much that. This does not include the transactions themselves, just the root of the merkle tree consisting of hte transactions.

Reply to: moneromooo
theshoeshiner edited 6 years ago Weight: 0 | Link [ - ]

Ah okay! So if getblocktemplate returns that part of the input, you also need to attach a nonce, as that is the essence of mining. So where is that attached? Directly on the end?

Reply to: moneromooo
theshoeshiner posted 6 years ago Weight: 0 | Link [ - ]

FWIW, I figured out where the nonce belongs. Now im working on figuring out how to validate my data & hashes, and im starting by figuring out how to validate blocks from the getBlock call. Have a another thread on that one though if you have any input!

https://forum.getmonero.org/4/academic-and-technical/88610/how-to-validate-a-block-received-from-daemon-api