Skip to content

Commit

Permalink
Add CompilationUnit.implementation_address
Browse files Browse the repository at this point in the history
  • Loading branch information
SheldonHolmgren committed Jun 15, 2023
1 parent fc58a91 commit 5b5b3ae
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
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 @@ -127,6 +131,24 @@ def create_source_unit(self, filename: Filename) -> SourceUnit:
self._source_units[filename] = source_unit
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
7 changes: 7 additions & 0 deletions crytic_compile/platform/etherscan.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,13 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: str) -> None:
)
compilation_unit.compiler_version.look_for_installed_version()

if "Proxy" in result and result["Proxy"] == "1":
assert "Implementation" in result
implementation = result["Implementation"]
if prefix is not None:
implementation = f"{prefix}:{implementation}"
compilation_unit.implementation_address = implementation

solc_standard_json.standalone_compile(filenames, compilation_unit, working_dir=working_dir)

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

0 comments on commit 5b5b3ae

Please sign in to comment.