From 579480b47740c5b63d6dda63c7e6eae8ede2217d Mon Sep 17 00:00:00 2001 From: Nikhil Parasaram Date: Wed, 20 Oct 2021 12:43:49 +0100 Subject: [PATCH] Fix issue with source mapping (#1526) * Fix issue with source mapping * Fix issues with deployedBytecode * Add typing --- mythril/solidity/soliditycontract.py | 36 ++++++++++++++++------------ 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/mythril/solidity/soliditycontract.py b/mythril/solidity/soliditycontract.py index ac054f57..8ca4ef7b 100644 --- a/mythril/solidity/soliditycontract.py +++ b/mythril/solidity/soliditycontract.py @@ -132,28 +132,34 @@ class SolidityContract(EVMContract): super().__init__(code, creation_code, name=name) + @staticmethod + def get_sources(indices_data: Dict, source_data: Dict) -> None: + """ + Get source indices mapping + """ + if "generatedSources" not in source_data: + return + sources = source_data["generatedSources"] + for source in sources: + full_contract_src_maps = SolidityContract.get_full_contract_src_maps( + source["ast"] + ) + indices_data[source["id"]] = SolidityFile( + source["name"], source["contents"], full_contract_src_maps + ) + @staticmethod def get_solc_indices(data: Dict) -> Dict: """ Returns solc file indices """ - indices = {} - has_sources = True + indices: Dict = {} for contract_data in data["contracts"].values(): for source_data in contract_data.values(): - if "generatedSources" not in source_data["evm"]["deployedBytecode"]: - has_sources = False - break - sources = source_data["evm"]["deployedBytecode"]["generatedSources"] - for source in sources: - full_contract_src_maps = SolidityContract.get_full_contract_src_maps( - source["ast"] - ) - indices[source["id"]] = SolidityFile( - source["name"], source["contents"], full_contract_src_maps - ) - if has_sources is False: - break + SolidityContract.get_sources(indices, source_data["evm"]["bytecode"]) + SolidityContract.get_sources( + indices, source_data["evm"]["deployedBytecode"] + ) for source in data["sources"].values(): full_contract_src_maps = SolidityContract.get_full_contract_src_maps( source["ast"]