From 35bbe5438f223ca41f12bad1ec267368bb45f7bc Mon Sep 17 00:00:00 2001 From: alpharush <0xalpharush@protonmail.com> Date: Tue, 17 Oct 2023 09:15:48 -0500 Subject: [PATCH 1/9] prepare 0.3.5 release --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index fe021686..52a11c35 100644 --- a/setup.py +++ b/setup.py @@ -11,7 +11,7 @@ description="Util to facilitate smart contracts compilation.", url="https://github.com/crytic/crytic-compile", author="Trail of Bits", - version="0.3.4", + version="0.3.5", packages=find_packages(), python_requires=">=3.8", install_requires=["pycryptodome>=3.4.6", "cbor2", "solc-select>=v1.0.4", "toml>=0.10.2"], From bf781b1262cc2c86c54aecb14347ceab5ad5eb8a Mon Sep 17 00:00:00 2001 From: alpharush <0xalpharush@protonmail.com> Date: Tue, 16 Jan 2024 11:07:14 -0600 Subject: [PATCH 2/9] 0.3.6 release --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index dc088210..d3e0cfc2 100644 --- a/setup.py +++ b/setup.py @@ -11,7 +11,7 @@ description="Util to facilitate smart contracts compilation.", url="https://github.com/crytic/crytic-compile", author="Trail of Bits", - version="0.3.5", + version="0.3.6", packages=find_packages(), # Python 3.12.0 on Windows suffers from https://github.com/python/cpython/issues/109590 # breaking some of our integrations. The issue is fixed in 3.12.1 From 1e5deb2e06e2d606444b30767af421c9f4a2d55e Mon Sep 17 00:00:00 2001 From: shortdoom Date: Thu, 25 Jan 2024 23:26:46 +0100 Subject: [PATCH 3/9] feat: PoC of auto-generating solc-remaps file --- crytic_compile/platform/etherscan.py | 45 ++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/crytic_compile/platform/etherscan.py b/crytic_compile/platform/etherscan.py index a8f54b43..d0305f64 100644 --- a/crytic_compile/platform/etherscan.py +++ b/crytic_compile/platform/etherscan.py @@ -424,6 +424,51 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: str) -> None: via_ir=via_ir_enabled, ) + # Process filenames in target compilationUnit to build solc_remaps.txt + remaps = self.solc_remaps_generator(compilation_unit) + + # Convert to string to use with crytic-compile Target.sol --solc-remaps $(cat solc_remaps.txt) + remaps_str = ",".join(remaps) + with open(os.path.join(working_dir, "solc_remaps.txt"), "w") as f: + f.write(f'"{remaps_str}"') + + def solc_remaps_generator(self, compilationTarget: CompilationUnit) -> List[str]: + """Generate remapings for --solc-remaps argument. Uses absolute paths. + + Args: + compilationTarget (CompilationUnit): current compilation target + + Returns: + List[str]: List of remappings deduced from filenames and compilationUnit.source_units + """ + solc_remaps = [] + processed_remaps = set() # Avoid duplicates + source_units = compilationTarget.source_units + for filename, source_unit in source_units.items(): + short_name = filename.short + if short_name.startswith("@"): + remap_name = short_name.split("/", 1)[0] + + # Skip if this remap_name has already been processed + if remap_name in processed_remaps: + continue + + remap_path = filename.absolute + + # Extract the path up to and including the remap_name directory + remap_index = remap_path.find(remap_name + "/") + if remap_index != -1: + remap_path = remap_path[: remap_index + len(remap_name)] + + print(f"{remap_name}={remap_path}") + + solc_remaps.append(f"{remap_name}={remap_path}") + + # Mark this remap_name as processed + processed_remaps.add(remap_name) + + return solc_remaps + def clean(self, **_kwargs: str) -> None: pass From b5f0d628106d92b95789d207e6d2714b9ca30b5d Mon Sep 17 00:00:00 2001 From: shortdoom Date: Sun, 28 Jan 2024 21:52:34 +0100 Subject: [PATCH 4/9] feat: auto-generate crytic_compile.config.json --- crytic_compile/platform/etherscan.py | 59 +++++++--------------------- 1 file changed, 14 insertions(+), 45 deletions(-) diff --git a/crytic_compile/platform/etherscan.py b/crytic_compile/platform/etherscan.py index d0305f64..23bb0a7d 100644 --- a/crytic_compile/platform/etherscan.py +++ b/crytic_compile/platform/etherscan.py @@ -423,51 +423,20 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: str) -> None: evm_version=evm_version, via_ir=via_ir_enabled, ) - - # Process filenames in target compilationUnit to build solc_remaps.txt - remaps = self.solc_remaps_generator(compilation_unit) - - # Convert to string to use with crytic-compile Target.sol --solc-remaps $(cat solc_remaps.txt) - remaps_str = ",".join(remaps) - with open(os.path.join(working_dir, "solc_remaps.txt"), "w") as f: - f.write(f'"{remaps_str}"') - - def solc_remaps_generator(self, compilationTarget: CompilationUnit) -> List[str]: - """Generate remapings for --solc-remaps argument. Uses absolute paths. - - Args: - compilationTarget (CompilationUnit): current compilation target - - Returns: - List[str]: List of remappings deduced from filenames and compilationUnit.source_units - """ - solc_remaps = [] - processed_remaps = set() # Avoid duplicates - source_units = compilationTarget.source_units - for filename, source_unit in source_units.items(): - short_name = filename.short - if short_name.startswith("@"): - remap_name = short_name.split("/", 1)[0] - - # Skip if this remap_name has already been processed - if remap_name in processed_remaps: - continue - - remap_path = filename.absolute - - # Extract the path up to and including the remap_name directory - remap_index = remap_path.find(remap_name + "/") - if remap_index != -1: - remap_path = remap_path[: remap_index + len(remap_name)] - - print(f"{remap_name}={remap_path}") - - solc_remaps.append(f"{remap_name}={remap_path}") - - # Mark this remap_name as processed - processed_remaps.add(remap_name) - - return solc_remaps + + metadata_config = { + "solc_remaps": remappings if remappings else {}, + "solc_solcs_select": compiler_version, + "solc_args": ("--via-ir" if via_ir_enabled else "") + + ("--optimize --optimize-runs " + str(optimize_runs) if optimize_runs else "") + + ("--evm-version " + evm_version if evm_version else ""), + } + + with open( + os.path.join(working_dir if working_dir else export_dir, "crytic_compile.config.json"), + "w", + ) as f: + json.dump(metadata_config, f) def clean(self, **_kwargs: str) -> None: pass From d47b73aee5b559c78bfd76343f0c854a68be3145 Mon Sep 17 00:00:00 2001 From: shortdoom Date: Thu, 1 Feb 2024 22:37:05 +0100 Subject: [PATCH 5/9] test: ci_test_etherscan.sh, chore: lint/refactor --- crytic_compile/platform/etherscan.py | 16 ++++++++++---- scripts/ci_test_etherscan.sh | 31 ++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/crytic_compile/platform/etherscan.py b/crytic_compile/platform/etherscan.py index 23bb0a7d..004600e1 100644 --- a/crytic_compile/platform/etherscan.py +++ b/crytic_compile/platform/etherscan.py @@ -423,18 +423,26 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: str) -> None: evm_version=evm_version, via_ir=via_ir_enabled, ) - + metadata_config = { "solc_remaps": remappings if remappings else {}, "solc_solcs_select": compiler_version, - "solc_args": ("--via-ir" if via_ir_enabled else "") - + ("--optimize --optimize-runs " + str(optimize_runs) if optimize_runs else "") - + ("--evm-version " + evm_version if evm_version else ""), + "solc_args": " ".join( + filter( + None, + [ + "--via-ir" if via_ir_enabled else "", + "--optimize --optimize-runs " + str(optimize_runs) if optimize_runs else "", + "--evm-version " + evm_version if evm_version else "", + ], + ) + ), } with open( os.path.join(working_dir if working_dir else export_dir, "crytic_compile.config.json"), "w", + encoding="utf-8", ) as f: json.dump(metadata_config, f) diff --git a/scripts/ci_test_etherscan.sh b/scripts/ci_test_etherscan.sh index 7adcef2c..5da40197 100755 --- a/scripts/ci_test_etherscan.sh +++ b/scripts/ci_test_etherscan.sh @@ -99,3 +99,34 @@ then exit 255 fi echo "::endgroup::" + +# From crytic/crytic-compile#544 +echo "::group::Etherscan #8" +crytic-compile 0x9AB6b21cDF116f611110b048987E58894786C244 --etherscan-apikey "$GITHUB_ETHERSCAN" + +if [ $? -ne 0 ] +then + echo "Etherscan #8 test failed" + exit 255 +fi + +dir_name=$(ls crytic-export/etherscan-contracts/ | grep 0x9AB6b21cDF116f611110b048987E58894786C244) +cd crytic-export/etherscan-contracts/$dir_name + +if [ ! -f crytic_compile.config.json ]; then + echo "crytic_compile.config.json does not exist" + exit 255 +fi + +# TODO: Globbing at crytic_compile.py:720 to run with '.' +crytic-compile 'contracts/InterestRates/InterestRatePositionManager.f.sol' --config-file crytic_compile.config.json + +if [ $? -ne 0 ] +then + echo "crytic-compile command failed" + exit 255 +fi + +cd ../../../ + +echo "::endgroup::" \ No newline at end of file From 6bdc8e3d470c1386135e7f21886cf26e19778f7d Mon Sep 17 00:00:00 2001 From: shortdoom Date: Thu, 1 Feb 2024 23:12:25 +0100 Subject: [PATCH 6/9] chore: satisfy super-linter --- scripts/ci_test_etherscan.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/ci_test_etherscan.sh b/scripts/ci_test_etherscan.sh index 5da40197..d4ddc5a9 100755 --- a/scripts/ci_test_etherscan.sh +++ b/scripts/ci_test_etherscan.sh @@ -110,8 +110,8 @@ then exit 255 fi -dir_name=$(ls crytic-export/etherscan-contracts/ | grep 0x9AB6b21cDF116f611110b048987E58894786C244) -cd crytic-export/etherscan-contracts/$dir_name +dir_name=$(find crytic-export/etherscan-contracts/ -type d -name "*0x9AB6b21cDF116f611110b048987E58894786C244*" -print -quit) +cd "$dir_name" || { echo "Failed to change directory"; exit 255; } if [ ! -f crytic_compile.config.json ]; then echo "crytic_compile.config.json does not exist" From cf981c7018fafa3ee89e6604f4afa6109adbb8b6 Mon Sep 17 00:00:00 2001 From: Gustavo Grieco <31542053+ggrieco-tob@users.noreply.github.com> Date: Wed, 7 Feb 2024 13:30:20 +0100 Subject: [PATCH 7/9] Improve handling of "version" string from Etherscan --- crytic_compile/platform/etherscan.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crytic_compile/platform/etherscan.py b/crytic_compile/platform/etherscan.py index a8f54b43..ddb1bb07 100644 --- a/crytic_compile/platform/etherscan.py +++ b/crytic_compile/platform/etherscan.py @@ -474,7 +474,9 @@ def _convert_version(version: str) -> str: Returns: str: converted version """ - return version[1 : version.find("+")] + if "+" in version: + return version[1 : version.find("+")] + return version def _sanitize_remappings( From 1bc8da8cef922ef52cc3e71f16b3567675e3da56 Mon Sep 17 00:00:00 2001 From: Gustavo Grieco <31542053+ggrieco-tob@users.noreply.github.com> Date: Wed, 7 Feb 2024 13:51:23 +0100 Subject: [PATCH 8/9] Update etherscan.py --- crytic_compile/platform/etherscan.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crytic_compile/platform/etherscan.py b/crytic_compile/platform/etherscan.py index ddb1bb07..b16f4b5a 100644 --- a/crytic_compile/platform/etherscan.py +++ b/crytic_compile/platform/etherscan.py @@ -476,7 +476,7 @@ def _convert_version(version: str) -> str: """ if "+" in version: return version[1 : version.find("+")] - return version + return version[1 : ] def _sanitize_remappings( From ad9bf301e5bf12f241fed5fe0cedfda704c2fab2 Mon Sep 17 00:00:00 2001 From: Gustavo Grieco <31542053+ggrieco-tob@users.noreply.github.com> Date: Wed, 7 Feb 2024 14:09:22 +0100 Subject: [PATCH 9/9] fixed lint --- crytic_compile/platform/etherscan.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crytic_compile/platform/etherscan.py b/crytic_compile/platform/etherscan.py index b16f4b5a..da53c0aa 100644 --- a/crytic_compile/platform/etherscan.py +++ b/crytic_compile/platform/etherscan.py @@ -476,7 +476,7 @@ def _convert_version(version: str) -> str: """ if "+" in version: return version[1 : version.find("+")] - return version[1 : ] + return version[1:] def _sanitize_remappings(