0

As a general task i am trying to reverse engineer the production of a Block. With the help of EOSJS i was able to make a transaction from scratch and i can de/serialize it and sign it and so on. Now i have the issue with creating the Transaction_mroot(same with action_mroot). There is no functionality for that in EOSJS, i guess because thats not a normal use-case for a non-block producer. I need to do it in js though and i wasn't able to build eos.cpp for debugging information.

From what i know, the Transaction-receipts are hashed into the merkletree. For the example i used Block 73223910 from Jungle2, if you are looking into this (maybe use Block 3450221 from Jungle3 if you want those have only 2 tx for the start)

first Transaction receipt:

"receipt": {
  "status": "executed",
  "cpu_usage_us": 157,
  "net_usage_words": 17,
  "trx": [
    1,{
      "signatures": ["SIG_K1_K7LEzJhRVWGrveneRppA85UUC1WiBDLtDiY83FoHjPmmnQFtBg8i8ZqHfQ3nmmvV4eYNbT8SUNsevbM92PN7LNh49DhJ8u"],
      "compression": "none",
      "packed_context_free_data": "",
      "packed_trx": "4625335eee4c2c091c3e000000000100a6823403ea3055000000572d3ccdcd0110b2838846acb85a00000000a8ed32322910b2838846acb85aa0965a576da790ba684c000000000000044a554e474c4500087472616e7366657200"
    }
  ]
} 

second receipt:

"receipt": {
  "status": "executed",
  "cpu_usage_us": 170,
  "net_usage_words": 54,
  "trx": [
    1,{
      "signatures": ["SIG_K1_KBiBYUZQnnkizjbWtJRJPBqjhvSXy5do51rhyZH8WxG1UNDenWzmNwTy2SdRsGiE4aUhs3eL1JPFzBBm3nfVScC9HbXCLw"
      ],
      "compression": "none",
      "packed_context_free_data": "",
      "packed_trx": "4f18335e954d1b36a40f000000000190b1cad39986326d00000000a86cd4450190b1cad39986326d00000000a8ed3232ce0290b1cad39986326d4f28e9aa8ce8af81e5af86e992a5293a313963323433396438313135626536616335326465393164373836623966656662613265343139346566616435393730326235383532663335396432656464621828e6b8b8e6888fe5908de7a7b0293ae9be99e8998ee696971128e688bfe997b44944293a3131303030362228e5bc80e5a78be697b6e997b4293a323032302d30312d33312030313a35333a33312228e7bb93e69d9fe697b6e997b4293a323032302d30312d33312030313a35333a35312b440400000000002228e5bd93e5b180e5b180e58fb7293a313232323934303931383436323832383238383a28e5bd93e5b180e5bc80e7898ce7bb93e69e9c293ae9be99efbc9a28e6a285e88ab132292a2a2a262a2a2ae8998eefbc9a28e7baa2e6a1834a291628e6b8b8e6888fe7bb93e69e9c293ae8998ee8b5a220827996f76f01000000"
    }
  ]
}

So following the transaction protocol you now have to convert the Data to how it is saved. example tx 1:

receipt1 = {
status: "00", //case executed = "00" uint8
cpu_usage_us: "0000009D" // uint32_t without "0x" prefix?
net_usage_us: "17" // stays the same? unsigned int
trx: [
1, //is this the keytype maybe? not sure here
{ signatures: "" //here i think it must be something like sig.toBinary to make base58
compression: "00" //none should be "00"
packed_context_free_data: "00" //this is probably some serializefunction again that makes "00" out of nothing
packed_trx: "4625335eee4c2c091c3e000000000100a6823403ea3055000000572d3ccdcd0110b2838846acb85a00000000a8ed32322910b2838846acb85aa0965a576da790ba684c000000000000044a554e474c4500087472616e7366657200" //this stays the same? of Buffer to utf8
} 

someone told me that i'd also need a packed_transactio_prefix but i didn't find anything in this regard.

let merklehashes = []

Now we create the Merkle leaves:

let prunable1 = ecc.sha256(signatures + context_free_data)
let digest1 = ecc.sha256(compression + packed_transaction + prunable)
let merklehashes[0] = ecc.sha256(status + cpu_usage_us + net_usage_words + digest)

do the same for secon receipt and make merklehash[1]

then there is must be some bitmanipulation for canonical left and right in eosio/chain/merkle.cpp I assume we have to change the first bit of merklehashes[0] to 0 and merklehashes[1] to 1

in the end ecc.sha256(merklehashes[0] + merklehashes[1]) should result in the transaction_mroot == "cc4f15a6e348381e6e8ca6760599a4716a2fa7aa6989331f0ab0e8648c06fb5b"

I would really appreciate if someone could provide me some help with that. This is somewhat of a make or break for my Thesis. I already tried so much and lost a lot of time.

Thanks for your time

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.