@@ -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 --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 :
@@ -189,13 +189,16 @@ def compile_solidity_sources(source_dir, json_dir):
189189
190190 print (f"Compiled successfully { count_success } /{ count_success + count_failure } files." )
191191
192- def extract_and_save_longest_bytecode (bytecode_dir , json_dir , is_ethersolve = False , file_index = None ):
192+ def extract_and_save_longest_bytecode (bytecode_dir , json_dir , is_ethersolve = False , file_index = None , abi_dir = None ):
193193 """
194194 Extracts the longest bytecode based on file size from each .json file and saves it in the specified output directory.
195195 """
196196 # Clear and create bytecode directory
197197 clear_directory (bytecode_dir )
198198 os .makedirs (bytecode_dir , exist_ok = True )
199+ if abi_dir is not None :
200+ clear_directory (abi_dir )
201+ os .makedirs (abi_dir , exist_ok = True )
199202
200203 # List all .json files in the source directory
201204 num_files = [f for f in os .listdir (json_dir ) if f .endswith ('.json' )]
@@ -219,6 +222,7 @@ def extract_and_save_longest_bytecode(bytecode_dir, json_dir, is_ethersolve=Fals
219222 longest_bytecode = None
220223 longest_contract_name = None
221224 max_bytecode_length = 0 # Variable to store the maximum file size
225+ abi = None
222226
223227 # Find the contract with the longest bytecode
224228 for contract_name , contract_data in contracts .items ():
@@ -233,23 +237,26 @@ def extract_and_save_longest_bytecode(bytecode_dir, json_dir, is_ethersolve=Fals
233237 max_bytecode_length = bytecode_length
234238 longest_bytecode = bytecode
235239 longest_contract_name = contract_name
240+ abi = contract_data .get ("abi" )
236241
237242 # Save the longest bytecode, if it exists
238243 if longest_bytecode :
239- bytecode_filename = os .path .join (
240- bytecode_dir , f"{ os .path .splitext (json_filename )[0 ]} .bytecode"
241- )
242-
244+ base_filename = os .path .splitext (json_filename )[0 ]
245+
243246 if file_index is not None :
244- file_id = file_index .get (os .path .splitext (json_filename )[0 ]) # Match string name to integer
245- # Add a sequential number to the filename
246- bytecode_filename = os .path .join (
247- bytecode_dir , f"{ file_id } .bytecode"
248- )
249-
247+ file_id = file_index .get (base_filename ) # Match string name to integer
248+ base_filename = str (file_id ) if file_id is not None else base_filename
249+
250+ bytecode_filename = os .path .join (bytecode_dir , f"{ base_filename } .bytecode" )
251+
250252 with open (bytecode_filename , 'w' ) as bytecode_file :
251253 bytecode_file .write ("0x" + longest_bytecode )
252- # print(f"Extracted longest bytecode from {longest_contract_name} to {bytecode_filename}")
254+
255+ # Save ABI if available
256+ if abi and abi_dir is not None :
257+ abi_filename = os .path .join (abi_dir , f"{ base_filename } .abi.json" )
258+ with open (abi_filename , 'w' ) as abi_file :
259+ json .dump (json .loads (abi ), abi_file , indent = 4 )
253260 # Update the progress bar
254261 pbar .update (1 )
255262
@@ -326,12 +333,15 @@ def extract_and_save_bytecode(bytecode_dir, json_dir, is_ethersolve=False, file_
326333 if args .longest_bytecode :
327334 # EVMLiSA
328335 extract_and_save_longest_bytecode ('./vanilla-solidifi/bytecode/evmlisa' ,
329- './vanilla-solidifi/json' )
336+ './vanilla-solidifi/json' ,
337+ abi_dir = './vanilla-solidifi/abi/evmlisa' )
330338 extract_and_save_longest_bytecode ('./reentrancy-solidifi/bytecode/evmlisa' ,
331- './reentrancy-solidifi/json' )
339+ './reentrancy-solidifi/json' ,
340+ abi_dir = './reentrancy-solidifi/abi/evmlisa' )
332341 # TX-ORIGIN
333342 extract_and_save_longest_bytecode ('./tx-origin-solidifi/bytecode/evmlisa' ,
334- './tx-origin-solidifi/json' )
343+ './tx-origin-solidifi/json' ,
344+ abi_dir = './tx-origin-solidifi/abi/evmlisa' )
335345
336346 # EtherSolve
337347 extract_and_save_longest_bytecode ('./vanilla-solidifi/bytecode/ethersolve' ,
0 commit comments