Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CompilationUnit.implementation_address when the CU is a proxy contract #452

Merged
merged 5 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions crytic_compile/compilation_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ def __init__(self, crytic_compile: "CryticCompile", unique_id: str):
compiler="N/A", version="N/A", optimized=False
)

# if the compilation unit comes from etherscan-like service and is a proxy,
# store the implementation address
self._implementation_address: Optional[str] = None

self._crytic_compile: "CryticCompile" = crytic_compile

if unique_id == ".":
Expand Down Expand Up @@ -130,6 +134,24 @@ def create_source_unit(self, filename: Filename) -> SourceUnit:
self.filenames.append(filename)
return self._source_units[filename]

@property
def implementation_address(self) -> Optional[str]:
"""Return the implementation address if the compilation unit is a proxy

Returns:
Optional[str]: Implementation address
"""
return self._implementation_address

@implementation_address.setter
def implementation_address(self, implementation: str) -> None:
"""Set the implementation address

Args:
implementation (str): Implementation address
"""
self._implementation_address = implementation

# endregion
###################################################################################
###################################################################################
Expand Down
8 changes: 8 additions & 0 deletions crytic_compile/platform/etherscan.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,14 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: str) -> None:
optimize_runs=optimize_runs,
)
compilation_unit.compiler_version.look_for_installed_version()

if "Proxy" in result and result["Proxy"] == "1":
assert "Implementation" in result
implementation = str(result["Implementation"])
if target.startswith(tuple(SUPPORTED_NETWORK)):
implementation = f"{target[:target.find(':')]}:{implementation}"
compilation_unit.implementation_address = implementation

solc_standard_json.standalone_compile(
filenames,
compilation_unit,
Expand Down