6
6
from collections import defaultdict
7
7
from typing import TYPE_CHECKING , Dict , List , Optional , Set , Tuple , Union
8
8
9
- import sha3
9
+ from Crypto . Hash import keccak
10
10
11
11
from crytic_compile .utils .naming import Filename
12
12
from crytic_compile .utils .natspec import Natspec
@@ -435,12 +435,12 @@ def _convert_libraries_names(self, libraries: Dict[str, str]) -> Dict[str, str]:
435
435
# Prior solidity 0.5
436
436
# libraries were on the format __filename:contract_name_____
437
437
# From solidity 0.5,
438
- # libraries are on the format __$kecckack (filename:contract_name)[34]$__
438
+ # libraries are on the format __$keccak (filename:contract_name)[34]$__
439
439
# https://solidity.readthedocs.io/en/v0.5.7/050-breaking-changes.html#command-line-and-json-interfaces
440
440
441
441
lib_4 = "__" + lib + "_" * (38 - len (lib ))
442
442
443
- sha3_result = sha3 . keccak_256 ( )
443
+ sha3_result = keccak . new ( digest_bits = 256 )
444
444
sha3_result .update (lib .encode ("utf-8" ))
445
445
lib_5 = "__$" + sha3_result .hexdigest ()[:34 ] + "$__"
446
446
@@ -465,12 +465,12 @@ def _convert_libraries_names(self, libraries: Dict[str, str]) -> Dict[str, str]:
465
465
lib_4 = "__" + lib_with_used_filename + "_" * (38 - len (lib_with_used_filename ))
466
466
new_names [lib_4 ] = addr
467
467
468
- sha3_result = sha3 . keccak_256 ( )
468
+ sha3_result = keccak . new ( digest_bits = 256 )
469
469
sha3_result .update (lib_with_abs_filename .encode ("utf-8" ))
470
470
lib_5 = "__$" + sha3_result .hexdigest ()[:34 ] + "$__"
471
471
new_names [lib_5 ] = addr
472
472
473
- sha3_result = sha3 . keccak_256 ( )
473
+ sha3_result = keccak . new ( digest_bits = 256 )
474
474
sha3_result .update (lib_with_used_filename .encode ("utf-8" ))
475
475
lib_5 = "__$" + sha3_result .hexdigest ()[:34 ] + "$__"
476
476
new_names [lib_5 ] = addr
@@ -529,22 +529,22 @@ def _library_name_lookup(
529
529
return name , solidity_0_4_filename
530
530
531
531
# Solidity 0.5
532
- sha3_result = sha3 . keccak_256 ( )
532
+ sha3_result = keccak . new ( digest_bits = 256 )
533
533
sha3_result .update (name .encode ("utf-8" ))
534
534
v5_name = "__$" + sha3_result .hexdigest ()[:34 ] + "$__"
535
535
536
536
if v5_name == lib_name :
537
537
return name , v5_name
538
538
539
539
# Solidity 0.5 with filename
540
- sha3_result = sha3 . keccak_256 ( )
540
+ sha3_result = keccak . new ( digest_bits = 256 )
541
541
sha3_result .update (name_with_absolute_filename .encode ("utf-8" ))
542
542
v5_name = "__$" + sha3_result .hexdigest ()[:34 ] + "$__"
543
543
544
544
if v5_name == lib_name :
545
545
return name , v5_name
546
546
547
- sha3_result = sha3 . keccak_256 ( )
547
+ sha3_result = keccak . new ( digest_bits = 256 )
548
548
sha3_result .update (name_with_used_filename .encode ("utf-8" ))
549
549
v5_name = "__$" + sha3_result .hexdigest ()[:34 ] + "$__"
550
550
@@ -656,7 +656,7 @@ def _compute_hashes(self, name: str) -> None:
656
656
sig_name = sig ["name" ]
657
657
arguments = "," .join ([x ["type" ] for x in sig ["inputs" ]])
658
658
sig = f"{ sig_name } ({ arguments } )"
659
- sha3_result = sha3 . keccak_256 ( )
659
+ sha3_result = keccak . new ( digest_bits = 256 )
660
660
sha3_result .update (sig .encode ("utf-8" ))
661
661
self ._hashes [name ][sig ] = int ("0x" + sha3_result .hexdigest ()[:8 ], 16 )
662
662
@@ -694,7 +694,7 @@ def _compute_topics_events(self, name: str) -> None:
694
694
arguments = "," .join ([x ["type" ] for x in sig ["inputs" ]])
695
695
indexes = [x .get ("indexed" , False ) for x in sig ["inputs" ]]
696
696
sig = f"{ sig_name } ({ arguments } )"
697
- sha3_result = sha3 . keccak_256 ( )
697
+ sha3_result = keccak . new ( digest_bits = 256 )
698
698
sha3_result .update (sig .encode ("utf-8" ))
699
699
700
700
self ._events [name ][sig ] = (int ("0x" + sha3_result .hexdigest ()[:8 ], 16 ), indexes )
0 commit comments