5

I'm not sure how to write this block header digest/hash generation in another language then C(++). Is this even possible without a lot of hacking?

If so: Could a language-neutral format for the digest message be documented?

If not: This would be a very undesireable lock-in: EOS blocks will not be able to be validated on other blockchains like ethereum. Perhaps this hash function should be refined in a more language-neutral way.

Edit 1 (May 10) I found this serialiser that was written for steem data types, but obviously there's a lot of interoperability!

2
  • A better question might be: "How can I calculate the block digest?" May 8, 2018 at 23:12
  • ^ Exactly, clear documentation on this would be extremely useful.
    – wanheda
    May 8, 2018 at 23:21

1 Answer 1

7

Here's how the C++ code calculates the block digest:

  • digest_type::hash(*this) serializes the block into a binary form, then runs the binary through sha-256.
  • block.hpp#L125 identifies the order that the fields are serialized in.
  • The types of these fields is at block.hpp#L18
  • Each type has its own serialization procedure. Most of them live in libraries/fc.
  • Here's an example of how it serializes an unsigned_int. This is a 32-bit type which serializes to 1-5 bytes depending on value: raw.hpp#L210

Note: many users of the JSON RPC API have to serialize objects to binary form, so I suspect someone will create documentation of this process.

Note: the block fields may still change. I pointed to the master branch as of 2018-05-08.

3
  • Awesome, could you link to such a type serialisation procedure in libraries/fc?
    – wanheda
    May 8, 2018 at 23:19
  • @toonsevrin added May 8, 2018 at 23:28
  • Take a look at my post edit, quite a nice resource!
    – wanheda
    May 10, 2018 at 14:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.