Skip to content

Commit de160c4

Browse files
authored
Merge pull request #544 from shortdoom/dev-remaps
feat: automatically handle solc configuration for Etherscan Platform
2 parents 3c088df + 9c397a7 commit de160c4

File tree

3 files changed

+57
-2
lines changed

3 files changed

+57
-2
lines changed

crytic_compile/platform/etherscan.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,28 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: str) -> None:
424424
via_ir=via_ir_enabled,
425425
)
426426

427+
metadata_config = {
428+
"solc_remaps": remappings if remappings else {},
429+
"solc_solcs_select": compiler_version,
430+
"solc_args": " ".join(
431+
filter(
432+
None,
433+
[
434+
"--via-ir" if via_ir_enabled else "",
435+
"--optimize --optimize-runs " + str(optimize_runs) if optimize_runs else "",
436+
"--evm-version " + evm_version if evm_version else "",
437+
],
438+
)
439+
),
440+
}
441+
442+
with open(
443+
os.path.join(working_dir if working_dir else export_dir, "crytic_compile.config.json"),
444+
"w",
445+
encoding="utf-8",
446+
) as f:
447+
json.dump(metadata_config, f)
448+
427449
def clean(self, **_kwargs: str) -> None:
428450
pass
429451

@@ -474,7 +496,9 @@ def _convert_version(version: str) -> str:
474496
Returns:
475497
str: converted version
476498
"""
477-
return version[1 : version.find("+")]
499+
if "+" in version:
500+
return version[1 : version.find("+")]
501+
return version[1:]
478502

479503

480504
def _sanitize_remappings(

scripts/ci_test_etherscan.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,34 @@ then
9999
exit 255
100100
fi
101101
echo "::endgroup::"
102+
103+
# From crytic/crytic-compile#544
104+
echo "::group::Etherscan #8"
105+
crytic-compile 0x9AB6b21cDF116f611110b048987E58894786C244 --etherscan-apikey "$GITHUB_ETHERSCAN"
106+
107+
if [ $? -ne 0 ]
108+
then
109+
echo "Etherscan #8 test failed"
110+
exit 255
111+
fi
112+
113+
dir_name=$(find crytic-export/etherscan-contracts/ -type d -name "*0x9AB6b21cDF116f611110b048987E58894786C244*" -print -quit)
114+
cd "$dir_name" || { echo "Failed to change directory"; exit 255; }
115+
116+
if [ ! -f crytic_compile.config.json ]; then
117+
echo "crytic_compile.config.json does not exist"
118+
exit 255
119+
fi
120+
121+
# TODO: Globbing at crytic_compile.py:720 to run with '.'
122+
crytic-compile 'contracts/InterestRates/InterestRatePositionManager.f.sol' --config-file crytic_compile.config.json
123+
124+
if [ $? -ne 0 ]
125+
then
126+
echo "crytic-compile command failed"
127+
exit 255
128+
fi
129+
130+
cd ../../../
131+
132+
echo "::endgroup::"

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
description="Util to facilitate smart contracts compilation.",
1212
url="https://github.com/crytic/crytic-compile",
1313
author="Trail of Bits",
14-
version="0.3.4",
14+
version="0.3.6",
1515
packages=find_packages(),
1616
# Python 3.12.0 on Windows suffers from https://github.com/python/cpython/issues/109590
1717
# breaking some of our integrations. The issue is fixed in 3.12.1

0 commit comments

Comments
 (0)