Skip to content

Commit e53d03c

Browse files
authored
Merge pull request #325 from crytic/dev-sync-master
Sync master <> dev
2 parents a2c7147 + 6a85506 commit e53d03c

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

crytic_compile/compilation_unit.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from collections import defaultdict
77
from typing import TYPE_CHECKING, Dict, List, Optional, Set, Tuple, Union
88

9-
import sha3
9+
from Crypto.Hash import keccak
1010

1111
from crytic_compile.utils.naming import Filename
1212
from crytic_compile.utils.natspec import Natspec
@@ -435,12 +435,12 @@ def _convert_libraries_names(self, libraries: Dict[str, str]) -> Dict[str, str]:
435435
# Prior solidity 0.5
436436
# libraries were on the format __filename:contract_name_____
437437
# 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]$__
439439
# https://solidity.readthedocs.io/en/v0.5.7/050-breaking-changes.html#command-line-and-json-interfaces
440440

441441
lib_4 = "__" + lib + "_" * (38 - len(lib))
442442

443-
sha3_result = sha3.keccak_256()
443+
sha3_result = keccak.new(digest_bits=256)
444444
sha3_result.update(lib.encode("utf-8"))
445445
lib_5 = "__$" + sha3_result.hexdigest()[:34] + "$__"
446446

@@ -465,12 +465,12 @@ def _convert_libraries_names(self, libraries: Dict[str, str]) -> Dict[str, str]:
465465
lib_4 = "__" + lib_with_used_filename + "_" * (38 - len(lib_with_used_filename))
466466
new_names[lib_4] = addr
467467

468-
sha3_result = sha3.keccak_256()
468+
sha3_result = keccak.new(digest_bits=256)
469469
sha3_result.update(lib_with_abs_filename.encode("utf-8"))
470470
lib_5 = "__$" + sha3_result.hexdigest()[:34] + "$__"
471471
new_names[lib_5] = addr
472472

473-
sha3_result = sha3.keccak_256()
473+
sha3_result = keccak.new(digest_bits=256)
474474
sha3_result.update(lib_with_used_filename.encode("utf-8"))
475475
lib_5 = "__$" + sha3_result.hexdigest()[:34] + "$__"
476476
new_names[lib_5] = addr
@@ -529,22 +529,22 @@ def _library_name_lookup(
529529
return name, solidity_0_4_filename
530530

531531
# Solidity 0.5
532-
sha3_result = sha3.keccak_256()
532+
sha3_result = keccak.new(digest_bits=256)
533533
sha3_result.update(name.encode("utf-8"))
534534
v5_name = "__$" + sha3_result.hexdigest()[:34] + "$__"
535535

536536
if v5_name == lib_name:
537537
return name, v5_name
538538

539539
# Solidity 0.5 with filename
540-
sha3_result = sha3.keccak_256()
540+
sha3_result = keccak.new(digest_bits=256)
541541
sha3_result.update(name_with_absolute_filename.encode("utf-8"))
542542
v5_name = "__$" + sha3_result.hexdigest()[:34] + "$__"
543543

544544
if v5_name == lib_name:
545545
return name, v5_name
546546

547-
sha3_result = sha3.keccak_256()
547+
sha3_result = keccak.new(digest_bits=256)
548548
sha3_result.update(name_with_used_filename.encode("utf-8"))
549549
v5_name = "__$" + sha3_result.hexdigest()[:34] + "$__"
550550

@@ -656,7 +656,7 @@ def _compute_hashes(self, name: str) -> None:
656656
sig_name = sig["name"]
657657
arguments = ",".join([x["type"] for x in sig["inputs"]])
658658
sig = f"{sig_name}({arguments})"
659-
sha3_result = sha3.keccak_256()
659+
sha3_result = keccak.new(digest_bits=256)
660660
sha3_result.update(sig.encode("utf-8"))
661661
self._hashes[name][sig] = int("0x" + sha3_result.hexdigest()[:8], 16)
662662

@@ -694,7 +694,7 @@ def _compute_topics_events(self, name: str) -> None:
694694
arguments = ",".join([x["type"] for x in sig["inputs"]])
695695
indexes = [x.get("indexed", False) for x in sig["inputs"]]
696696
sig = f"{sig_name}({arguments})"
697-
sha3_result = sha3.keccak_256()
697+
sha3_result = keccak.new(digest_bits=256)
698698
sha3_result.update(sig.encode("utf-8"))
699699

700700
self._events[name][sig] = (int("0x" + sha3_result.hexdigest()[:8], 16), indexes)

crytic_compile/platform/solc_standard_json.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,12 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: Any) -> None:
409409
optimized=is_optimized(solc_arguments),
410410
)
411411

412+
add_optimization(
413+
self._json,
414+
compilation_unit.compiler_version.optimized,
415+
compilation_unit.compiler_version.optimize_runs,
416+
)
417+
412418
# Add all remappings
413419
if solc_remaps:
414420
if isinstance(solc_remaps, str):

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
version="0.2.4",
1515
packages=find_packages(),
1616
python_requires=">=3.8",
17-
install_requires=["pysha3>=1.0.2"],
17+
install_requires=["pycryptodome>=3.4.6"],
1818
license="AGPL-3.0",
1919
long_description=long_description,
2020
package_data={"crytic_compile": ["py.typed"]},

0 commit comments

Comments
 (0)