Skip to content

Commit 6df223c

Browse files
committed
Completing work on --use_relpaths_for_solc_json (#8042)
ecb7ec74a1c2e7e1fed01f442ecc4ba7d682cf0f
1 parent 8fecb05 commit 6df223c

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

scripts/CertoraProver/certoraBuild.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1543,7 +1543,8 @@ def standard_json(self,
15431543
contract_file_posix_abs: Path,
15441544
contract_file_as_provided: str,
15451545
remappings: List[str],
1546-
compiler_collector: CompilerCollector) -> Dict[str, Any]:
1546+
compiler_collector: CompilerCollector,
1547+
compile_wd: Path) -> Dict[str, Any]:
15471548
"""
15481549
when calling solc with the standard_json api, instead of passing it flags, we pass it json to request what we
15491550
want -- currently we only use this to retrieve storage layout as this is the only way to do that,
@@ -1554,7 +1555,7 @@ def standard_json(self,
15541555
@param compiler_collector: Solidity or Vyper compiler collector
15551556
@return:
15561557
"""
1557-
solc_json_contract_key = contract_file_as_provided if self.context.use_relpaths_for_solc_json else contract_file_posix_abs
1558+
solc_json_contract_key = os.path.relpath(contract_file_as_provided, compile_wd) if self.context.use_relpaths_for_solc_json else contract_file_posix_abs
15581559
compiler_collector_lang = compiler_collector.smart_contract_lang
15591560
if compiler_collector_lang == CompilerLangSol() or compiler_collector_lang == CompilerLangYul():
15601561
sources_dict = {str(solc_json_contract_key): {
@@ -1854,7 +1855,7 @@ def collect_for_file(self,
18541855
# Standard JSON
18551856
remappings = [] if isinstance(compiler_collector, CompilerCollectorYul) else self.context.remappings
18561857
input_for_solc = self.standard_json(Path(file_abs_path), build_arg_contract_file, remappings,
1857-
compiler_collector)
1858+
compiler_collector, compile_wd)
18581859
standard_json_input = json.dumps(input_for_solc).encode("utf-8")
18591860
compiler_logger.debug(f"about to run in {compile_wd} the command: {collect_cmd}")
18601861
compiler_logger.debug(f"solc input = {json.dumps(input_for_solc, indent=4)}")
@@ -1910,7 +1911,7 @@ def collect_for_file(self,
19101911
contract_file_abs = str(Util.abs_norm_path(contract_file))
19111912

19121913
# using os.path.relpath because Path.relative_to cannot go up the directory tree (no ..)
1913-
contract_file_rel = os.path.relpath(Path(contract_file_abs), Path.cwd())
1914+
contract_file_rel = os.path.relpath(Path(contract_file_abs), compile_wd)
19141915

19151916
build_logger.debug(f"available keys: {data['contracts'].keys()}")
19161917
if contract_file_rel in data[CONTRACTS]:
@@ -2009,7 +2010,15 @@ def collect_for_file(self,
20092010
srclist = {"0": file_abs_path}
20102011
report_srclist = {"0": file_abs_path}
20112012

2012-
report_source_file = report_srclist[[idx for idx in srclist if Util.abs_posix_path(srclist[idx]) == file_abs_path][0]]
2013+
# Annoyingly, this is currently used just for... presentation?!
2014+
# We should clean up report_source_file from all places...
2015+
2016+
build_logger.debug(f"Finding report source file, abs path {file_abs_path} relative to {compile_wd}")
2017+
if self.context.use_relpaths_for_solc_json:
2018+
orig_report_source_file = Util.abs_posix_path(os.path.relpath(file_abs_path, compile_wd))
2019+
else:
2020+
orig_report_source_file = file_abs_path
2021+
report_source_file = report_srclist[[idx for idx in srclist if Util.abs_posix_path(srclist[idx]) == orig_report_source_file][0]]
20132022

20142023
# all "contracts in SDC" are the same for every primary contract of the compiled file.
20152024
# we can therefore compute those just once...
@@ -2040,8 +2049,9 @@ def collect_for_file(self,
20402049

20412050
build_logger.debug(f"finding primary contract address of {file_compiler_path}:{primary_contract} in "
20422051
f"{contracts_with_chosen_addresses}")
2052+
path_to_find = os.path.relpath(file_compiler_path, compile_wd) if self.context.use_relpaths_for_solc_json else file_compiler_path
20432053
primary_contract_address = \
2044-
self.find_contract_address_str(file_compiler_path,
2054+
self.find_contract_address_str(path_to_find,
20452055
primary_contract,
20462056
contracts_with_chosen_addresses)
20472057
build_logger.debug(f"Contracts in SDC {sdc_name}: {[contract.name for contract in contracts_in_sdc]}")
@@ -2102,6 +2112,7 @@ def build_report_srclist(self,
21022112
report_srclist = srclist
21032113
else:
21042114
report_srclist = srclist
2115+
build_logger.debug(f"Report source list={report_srclist}")
21052116
return report_srclist
21062117

21072118
def get_bytecode(self,
@@ -3014,7 +3025,7 @@ def handle_erc7201_annotations(self) -> None:
30143025
target_file = self.context.contract_to_file[target.name]
30153026
base_contracts = self.retrieve_base_contracts_list(
30163027
target_file,
3017-
Util.abs_posix_path(target_file),
3028+
target_file if self.context.use_relpaths_for_solc_json else Util.abs_posix_path(target_file),
30183029
target.name
30193030
)
30203031
extensions: Set[str] = set()
@@ -3090,19 +3101,20 @@ def handle_one_extension(storage_ext: str) -> tuple[Any, str, List[Dict[str, Any
30903101

30913102
# let's try to find the AST now
30923103
build_file_ast = None
3104+
orig_path = os.path.relpath(ext_instance.original_file, Path.cwd()) if self.context.use_relpaths_for_solc_json else ext_instance.original_file
30933105
for (k, v) in self.asts.items():
3094-
if ext_instance.original_file in v:
3106+
if orig_path in v:
30953107
build_file_ast = k
30963108
break
30973109
if build_file_ast is None:
30983110
raise RuntimeError(f"Couldn't find file for storage extension file {storage_ext}")
30993111

31003112
contract_def_node = self.get_contract_def_node_ref(
31013113
build_file_ast,
3102-
ext_instance.original_file,
3114+
orig_path,
31033115
storage_ext
31043116
)
3105-
def_node = self.asts[build_file_ast][ext_instance.original_file][contract_def_node]
3117+
def_node = self.asts[build_file_ast][orig_path][contract_def_node]
31063118
nodes = def_node.get("nodes")
31073119
if not isinstance(nodes, list):
31083120
raise RuntimeError(f"Couldn't find nodes for body of {storage_ext}")

0 commit comments

Comments
 (0)