@@ -175,7 +175,7 @@ def compile_solidity_sources(source_dir, json_dir):
175175 output_file = os .path .join (json_dir , f"{ os .path .splitext (filename )[0 ]} .json" )
176176
177177 # Command to compile and save the bytecode in JSON format
178- command = f"solc --combined-json bin,bin-runtime,abi --pretty-json { input_file } > { output_file } 2> /dev/null"
178+ command = f"solc --combined-json bin,bin-runtime,abi --pretty-json { input_file } > { output_file } " # 2> /dev/null
179179
180180 # Execute the compilation command
181181 try :
@@ -264,13 +264,16 @@ def extract_and_save_longest_bytecode(bytecode_dir, json_dir, is_ethersolve=Fals
264264 # Update the progress bar
265265 pbar .update (1 )
266266
267- def extract_and_save_bytecode (bytecode_dir , json_dir , is_ethersolve = False , file_index = None ):
267+ def extract_and_save_bytecode (bytecode_dir , json_dir , is_ethersolve = False , file_index = None , abi_dir = None ):
268268 """
269269 Extracts all bytecode from each .json file and saves it in the specified output directory.
270270 """
271271 # Clear and create bytecode directory
272272 clear_directory (bytecode_dir )
273273 os .makedirs (bytecode_dir , exist_ok = True )
274+ if abi_dir is not None :
275+ clear_directory (abi_dir )
276+ os .makedirs (abi_dir , exist_ok = True )
274277
275278 # List all .sol files in the source directory
276279 num_files = [f for f in os .listdir (json_dir ) if f .endswith ('.json' )]
@@ -291,12 +294,14 @@ def extract_and_save_bytecode(bytecode_dir, json_dir, is_ethersolve=False, file_
291294 data = json .load (json_file )
292295 contracts = data .get ("contracts" , {})
293296 count = 1 # Sequential counter for each bytecode in the same JSON
297+ abi = None
294298
295299 for contract_name , contract_data in contracts .items ():
296300 if (is_ethersolve ):
297301 bytecode = contract_data .get ("bin" )
298302 else :
299303 bytecode = contract_data .get ("bin-runtime" )
304+ abi = contract_data .get ("abi" )
300305
301306 if bytecode :
302307 bytecode_filename = os .path .join (
@@ -312,21 +317,57 @@ def extract_and_save_bytecode(bytecode_dir, json_dir, is_ethersolve=False, file_
312317
313318 with open (bytecode_filename , 'w' ) as bytecode_file :
314319 bytecode_file .write ("0x" + bytecode )
320+
321+ # Save ABI if available
322+ if abi and abi_dir is not None :
323+ abi_filename = os .path .join (abi_dir , f"{ file_id } _{ count } .abi.json" )
324+
325+ if isinstance (abi , str ):
326+ abi = json .loads (abi )
327+
328+ with open (abi_filename , 'w' ) as abi_file :
329+ json .dump (abi , abi_file , indent = 4 )
330+
315331 # print(f"Extracted bytecode to {bytecode_filename}")
316332 count += 1 # Increment counter for next bytecode
317333 # Update the progress bar
318334 pbar .update (1 )
319335
336+ def compile_bridge (name ):
337+ extract_solidity_versions (src_folder = f'./{ name } /source-code' ,
338+ output_csv = f'./{ name } /source-code/version.csv' )
339+
340+ compile_solidity_sources_with_different_version (source_dir = f'./{ name } /source-code' ,
341+ json_dir = f'./{ name } /json' ,
342+ version_file = f'./{ name } /source-code/version.csv' )
343+
344+ generate_file_index (folder_path = f'./{ name } /source-code' ,
345+ output_json = f'./{ name } /match-file-index.json' )
346+
347+ with open (f'./{ name } /match-file-index.json' , 'r' ) as index_file :
348+ match_file_index = json .load (index_file )
349+
350+ extract_and_save_bytecode (bytecode_dir = f'./{ name } /bytecode' ,
351+ json_dir = f'./{ name } /json' ,
352+ abi_dir = f'./{ name } /abi' ,
353+ file_index = match_file_index )
354+
355+
320356if __name__ == "__main__" :
321357 parser = argparse .ArgumentParser (description = "Compile datasets." )
322- parser .add_argument ("--solidifi" , action = "store_true" , help = "Run analysis on SolidiFI dataset" )
323- parser .add_argument ("--smartbugs" , action = "store_true" , help = "Run analysis on SmartBugs dataset" )
324- parser .add_argument ("--slise" , action = "store_true" , help = "Run analysis on SliSE dataset" )
358+ parser .add_argument ("--solidifi" , action = "store_true" , help = "Compile SolidiFI dataset" )
359+ parser .add_argument ("--smartbugs" , action = "store_true" , help = "Compile SmartBugs dataset" )
360+ parser .add_argument ("--slise" , action = "store_true" , help = "Compile SliSE dataset" )
325361 parser .add_argument ("--longest-bytecode" , action = "store_true" , help = "Save only the longest bytecode" )
326362 parser .add_argument ("--manual" , action = "store_true" , help = "Manual mode" )
363+ parser .add_argument ("--cross-chain-xguard" , action = "store_true" , help = "Compile XGuard dataset" )
327364
328365 args = parser .parse_args ()
329366
367+ if args .cross_chain_xguard :
368+ compile_bridge ('cross-chain/XGuard/QBridge' ) # QBridge
369+ compile_bridge ('cross-chain/XGuard/MeterBridge' ) # MeterBridge
370+
330371 if args .manual :
331372 # Test ThorChain Bridge
332373 extract_solidity_versions (src_folder = './cross-chain/THORChain-bridge/source-code' ,
0 commit comments