how to compute metahash

how to compute metahash

by Ran Liao -
Number of replies: 4

Hi,

I have trouble computing the metahash to pass the first test case. My current implementation follows the Listing 1 in the handout but it doesn't work. I was wondering whether you can help me to clarify it.

To be precisely, suppose there're 3 chunks in a file. The hex coded hash of them are:

chunk1: h1 = 9834876dcfb05cb167a5c24953eba58c4ac89b1adf57f28f2f9d09af107ee8f0
chunk2: h2 = 3e744b9dc39389baf0c5a0660589b8402f3dbb49b89b3e75f2c9355852a3c677
chunk3: h3 = 2e7d2c03a9507ae265ecf5b5356885a53393a2029d241394997265a1a25aefc6

Suppose the separator is '\n'. Will the metahash be "hex(sha256(h1\nh2\nh3))" ?

Best,
Ran
In reply to Ran Liao

Re: how to compute metahash

by Guanyu Zhang -
Hi,

I have the same issue here:
My chunkhashs are precisely:
"9834876dcfb05cb167a5c24953eba58c4ac89b1adf57f28f2f9d09af107ee8f0",
"3e744b9dc39389baf0c5a0660589b8402f3dbb49b89b3e75f2c9355852a3c677",
"2e7d2c03a9507ae265ecf5b5356885a53393a2029d241394997265a1a25aefc6",
And I used \n as separator but the metahash calculated is not 5a00fc30e073b095a6266136552a3da1d4622d0fdaa057f0b3135aa803321e1c

Best,
Guanyu
In reply to Guanyu Zhang

Re: how to compute metahash

by Yuchen Qian -
I think one of the possible ambiguity you might both encountered here is that
h1, h2, h3 are already hex encoded. Can you try a simple example to first
decode the hex string in the test case and see if produces the expected
metahash?

The metahash expression is correct.
In reply to Yuchen Qian

Re: how to compute metahash

by Ran Liao -
SHA256 hash will output a 32-bytes array as result. So the hash of chunks are:

chunk1 : [152 52 135 109 207 176 92 177 103 165 194 73 83 235 165 140 74 200 155 26 223 87 242 143 47 157 9 175 16 126 232 240]
chunk2 : [62 116 75 157 195 147 137 186 240 197 160 102 5 137 184 64 47 61 187 73 184 155 62 117 242 201 53 88 82 163 198 119]
chunk3 : [46 125 44 3 169 80 122 226 101 236 245 181 53 104 133 165 51 147 162 2 157 36 19 148 153 114 101 161 162 90 239 198]

I concatenate these 3 arrays directly without any separators to obtain a 96-bytes array. Then I put it into SHA256 and hex encode the result.

This time the metahash matches what test case expects. Is this intended? Because it's quite different from what you suggest. Or the test case somehow is incorrect?
In reply to Ran Liao

Re: how to compute metahash

by Haoqian Zhang -
Please see the announcement here: https://moodlearchive.epfl.ch/2021-2022/mod/forum/discuss.php?d=66237