Skip to content

Commit

Permalink
Merge pull request #325 from crytic/dev-sync-master
Browse files Browse the repository at this point in the history
Sync master <> dev
  • Loading branch information
montyly authored Dec 16, 2022
2 parents a2c7147 + 6a85506 commit e53d03c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
20 changes: 10 additions & 10 deletions crytic_compile/compilation_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from collections import defaultdict
from typing import TYPE_CHECKING, Dict, List, Optional, Set, Tuple, Union

import sha3
from Crypto.Hash import keccak

from crytic_compile.utils.naming import Filename
from crytic_compile.utils.natspec import Natspec
Expand Down Expand Up @@ -435,12 +435,12 @@ def _convert_libraries_names(self, libraries: Dict[str, str]) -> Dict[str, str]:
# Prior solidity 0.5
# libraries were on the format __filename:contract_name_____
# From solidity 0.5,
# libraries are on the format __$kecckack(filename:contract_name)[34]$__
# libraries are on the format __$keccak(filename:contract_name)[34]$__
# https://solidity.readthedocs.io/en/v0.5.7/050-breaking-changes.html#command-line-and-json-interfaces

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

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

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

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

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

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

if v5_name == lib_name:
return name, v5_name

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

if v5_name == lib_name:
return name, v5_name

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

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

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

self._events[name][sig] = (int("0x" + sha3_result.hexdigest()[:8], 16), indexes)
Expand Down
6 changes: 6 additions & 0 deletions crytic_compile/platform/solc_standard_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,12 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: Any) -> None:
optimized=is_optimized(solc_arguments),
)

add_optimization(
self._json,
compilation_unit.compiler_version.optimized,
compilation_unit.compiler_version.optimize_runs,
)

# Add all remappings
if solc_remaps:
if isinstance(solc_remaps, str):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
version="0.2.4",
packages=find_packages(),
python_requires=">=3.8",
install_requires=["pysha3>=1.0.2"],
install_requires=["pycryptodome>=3.4.6"],
license="AGPL-3.0",
long_description=long_description,
package_data={"crytic_compile": ["py.typed"]},
Expand Down

0 comments on commit e53d03c

Please sign in to comment.