Skip to content

Commit c9c27e2

Browse files
authored
Merge pull request #452 from SheldonHolmgren/implementation_address
Add CompilationUnit.implementation_address when the CU is a proxy contract
2 parents ee04ee3 + 8c24df2 commit c9c27e2

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

crytic_compile/compilation_unit.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ def __init__(self, crytic_compile: "CryticCompile", unique_id: str):
4646
compiler="N/A", version="N/A", optimized=False
4747
)
4848

49+
# if the compilation unit comes from etherscan-like service and is a proxy,
50+
# store the implementation address
51+
self._implementation_address: Optional[str] = None
52+
4953
self._crytic_compile: "CryticCompile" = crytic_compile
5054

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

137+
@property
138+
def implementation_address(self) -> Optional[str]:
139+
"""Return the implementation address if the compilation unit is a proxy
140+
141+
Returns:
142+
Optional[str]: Implementation address
143+
"""
144+
return self._implementation_address
145+
146+
@implementation_address.setter
147+
def implementation_address(self, implementation: str) -> None:
148+
"""Set the implementation address
149+
150+
Args:
151+
implementation (str): Implementation address
152+
"""
153+
self._implementation_address = implementation
154+
133155
# endregion
134156
###################################################################################
135157
###################################################################################

crytic_compile/platform/etherscan.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,14 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: str) -> None:
401401
optimize_runs=optimize_runs,
402402
)
403403
compilation_unit.compiler_version.look_for_installed_version()
404+
405+
if "Proxy" in result and result["Proxy"] == "1":
406+
assert "Implementation" in result
407+
implementation = str(result["Implementation"])
408+
if target.startswith(tuple(SUPPORTED_NETWORK)):
409+
implementation = f"{target[:target.find(':')]}:{implementation}"
410+
compilation_unit.implementation_address = implementation
411+
404412
solc_standard_json.standalone_compile(
405413
filenames,
406414
compilation_unit,

0 commit comments

Comments
 (0)