Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix blobHash collision #2881

Merged
merged 1 commit into from
Sep 19, 2023
Merged

Conversation

howjmay
Copy link
Member

@howjmay howjmay commented Sep 18, 2023

No description provided.

@howjmay howjmay force-pushed the blob-collision branch 3 times, most recently from 373c479 to 47b2eac Compare September 18, 2023 16:14
@howjmay
Copy link
Member Author

howjmay commented Sep 18, 2023

The python code to generate the hash value to compare in this PR

import hashlib
import codecs

# byte string to be converted
b_string = b'\x04\x00\x00\x00'

# decoding the byte string to unicode string
u_string = codecs.decode(b_string, 'utf-8')
text = u_string+"key0"+"val0"+u_string+"key1"+"val1"
print(u_string)
hashObject = hashlib.blake2b(text.encode('utf-8'), digest_size=32)
digest = hashObject.hexdigest()

print(digest)

@howjmay howjmay force-pushed the blob-collision branch 3 times, most recently from 4ebfe58 to 84ba2d7 Compare September 19, 2023 14:02
values = append(values, v)
all = append(all, v)
all = append(all, []byte(k))
binary.LittleEndian.PutUint32(prefix[:], uint32(len(key)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should leave a comment explaining why we need this 👍

require.NoError(t, err)
require.Equal(t, resHash, h.Bytes())
})
t.Run("with escape separator", func(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this test doesn't make sense anymore

)

func TestMustGetBlobHash(t *testing.T) {
t.Run("normal", func(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should add a test that asserts the collision doesn't happen anymore, right?
so {"ab", "123"} yields a different hash than {"ab1","23"}

@howjmay howjmay force-pushed the blob-collision branch 2 times, most recently from 34d0a46 to 5d00efc Compare September 19, 2023 14:21
@howjmay howjmay merged commit 25bb40e into iotaledger:develop Sep 19, 2023
5 checks passed
@howjmay howjmay deleted the blob-collision branch September 19, 2023 15:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants