Skip to content

Commit 284716a

Browse files
smonicaselopez
andauthored
Etherscan: Add a new check that the source code is verified (#646)
* Add a new check that the source code is verified * tests: add etherscan and sourcify tests for contract with no code --------- Co-authored-by: Emilio López <emilio.lopez@trailofbits.com>
1 parent 3cfc69b commit 284716a

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

crytic_compile/platform/etherscan.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,11 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: str) -> None:
383383
raise InvalidCompilation("Contract has no public source code: " + etherscan_url)
384384

385385
result = info["result"][0]
386+
387+
if "ABI" in result and "Contract source code not verified" in result["ABI"]:
388+
LOGGER.error("Contract has no public source code")
389+
raise InvalidCompilation("Contract has no public source code: " + etherscan_url)
390+
386391
# Assert to help mypy
387392
assert isinstance(result["SourceCode"], str)
388393
assert isinstance(result["ContractName"], str)

scripts/ci_test_etherscan.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,12 @@ fi
101101
cd ../../../
102102

103103
echo "::endgroup::"
104+
105+
# test with no verified code - should fail
106+
echo "::group::Etherscan #9"
107+
if crytic-compile 0xc3898ea7e322b3cdc92d65cfe5a34808b7338236 --compile-remove-metadata --etherscan-apikey "$ETHERSCAN_API_KEY"
108+
then
109+
echo "Etherscan #9 test failed"
110+
exit 255
111+
fi
112+
echo "::endgroup::"

scripts/ci_test_sourcify.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,15 @@ cd ../../../
9595

9696
echo "::endgroup::"
9797

98+
# Same as Etherscan #9 - test with no verified code - should fail
99+
echo "::group::Sourcify #9"
100+
if crytic-compile "sourcify-1:0xc3898ea7e322b3cdc92d65cfe5a34808b7338236"
101+
then
102+
echo "Sourcify #9 test failed"
103+
exit 255
104+
fi
105+
echo "::endgroup::"
106+
98107
# Test hex chain ID format (Sourcify-specific feature)
99108
echo "::group::Sourcify hex chain ID"
100109
if ! crytic-compile "sourcify-0x1:0x7F37f78cBD74481E593F9C737776F7113d76B315" --compile-remove-metadata

0 commit comments

Comments
 (0)