Skip to content

Commit ea93f66

Browse files
authored
Merge pull request HathorNetwork#1378 from HathorNetwork/feat/nano-sha256-storage
feat(nano): change internal storage hashing to sha256
2 parents 7707b6c + 2f65827 commit ea93f66

3 files changed

Lines changed: 5 additions & 5 deletions

File tree

‎hathor/nanocontracts/storage/contract_storage.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class AttrKey(TrieKey):
5454
key: bytes
5555

5656
def __bytes__(self) -> bytes:
57-
return _Tag.ATTR.value + hashlib.sha1(self.key).digest()
57+
return _Tag.ATTR.value + hashlib.sha256(self.key).digest()
5858

5959

6060
@dataclass(frozen=True, slots=True)
@@ -127,7 +127,7 @@ class MetadataKey(TrieKey):
127127
key: bytes
128128

129129
def __bytes__(self) -> bytes:
130-
return _Tag.METADATA.value + hashlib.sha1(self.key).digest()
130+
return _Tag.METADATA.value + hashlib.sha256(self.key).digest()
131131

132132

133133
_BLUEPRINT_ID_KEY = b'blueprint_id'

‎hathor/nanocontracts/storage/patricia_trie.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def calculate_id(self) -> NodeId:
6969
7070
This method assumes that all children already have their ids calculated.
7171
"""
72-
h = hashlib.sha1()
72+
h = hashlib.sha256()
7373
h.update(self.key)
7474
if self.content is not None:
7575
h.update(self.content)

‎tests/nanocontracts/test_patricia_trie.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def test_random_data(self) -> None:
151151
data = {}
152152
for v_int in range(20_000):
153153
v = str(v_int).encode('ascii')
154-
k = hashlib.sha1(v).digest()
154+
k = hashlib.sha256(v).digest()
155155
data[k] = v
156156
trie.update(k, v)
157157

@@ -175,7 +175,7 @@ def test_commit(self) -> None:
175175
data = {}
176176
for v_int in range(20_000):
177177
v = str(v_int).encode('ascii')
178-
k = hashlib.sha1(v).digest()
178+
k = hashlib.sha256(v).digest()
179179
data[k] = v
180180
trie.update(k, v)
181181
trie.commit()

0 commit comments

Comments
 (0)