Skip to content

Commit

Permalink
Merge pull request #544 from shortdoom/dev-remaps
Browse files Browse the repository at this point in the history
feat: automatically handle solc configuration for Etherscan Platform
  • Loading branch information
0xalpharush authored Mar 20, 2024
2 parents 3c088df + 9c397a7 commit de160c4
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 2 deletions.
26 changes: 25 additions & 1 deletion crytic_compile/platform/etherscan.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,28 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: str) -> None:
via_ir=via_ir_enabled,
)

metadata_config = {
"solc_remaps": remappings if remappings else {},
"solc_solcs_select": compiler_version,
"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)

def clean(self, **_kwargs: str) -> None:
pass

Expand Down Expand Up @@ -474,7 +496,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[1:]


def _sanitize_remappings(
Expand Down
31 changes: 31 additions & 0 deletions scripts/ci_test_etherscan.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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=$(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"
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::"
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.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
Expand Down

0 comments on commit de160c4

Please sign in to comment.