From ee16bb9ad060f09b39297045905b1b208f4f453f Mon Sep 17 00:00:00 2001 From: 0xMere Date: Mon, 3 Mar 2025 10:35:15 +0100 Subject: [PATCH] Optimized the creation of contracts in buildContractsFromFile(), introduced test mode in analyzeContract() --- src/main/java/it/unipr/EVMLiSA.java | 26 +++++++------------ .../analysis/contract/SmartContract.java | 6 +++++ 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/main/java/it/unipr/EVMLiSA.java b/src/main/java/it/unipr/EVMLiSA.java index 16b195205..7a7fa0014 100644 --- a/src/main/java/it/unipr/EVMLiSA.java +++ b/src/main/java/it/unipr/EVMLiSA.java @@ -260,7 +260,7 @@ public static void analyzeContract(SmartContract contract) { LiSA lisa = new LiSA(conf); lisa.run(program); - log.info("Analysis ended: CFG built successfully ({})", contract.getAddress()); + log.info("Analysis ended ({})", contract.getAddress()); contract.setStatistics( computeStatistics(checker, lisa, program)); @@ -311,7 +311,7 @@ public static void analyzeContract(SmartContract contract) { .getTimestampDependencyWarnings(checker.getComputedCFG().hashCode())) .build()); contract.generateCFGWithBasicBlocks(); - contract.toFile(); // save results to file + contract.toFile(); } } @@ -341,9 +341,6 @@ public static StatisticsObject computeStatistics(JumpSolver checker, LiSA lisa, */ private static StatisticsObject computeJumps(JumpSolver checker, Set soundlySolved) { EVMCFG cfg = checker.getComputedCFG(); - - log.info("### Calculating statistics ###"); - Set unreachableJumpNodes = checker.getUnreachableJumps(); int resolvedJumps = 0; @@ -425,15 +422,7 @@ private static StatisticsObject computeJumps(JumpSolver checker, Set } } - log.info("Total opcodes: {}", cfg.getOpcodeCount()); - log.info("Total jumps: {}", cfg.getAllJumps().size()); - log.info("Resolved jumps: {}", resolvedJumps); - log.info("Definitely unreachable jumps: {}", definitelyUnreachable); - log.info("Maybe unreachable jumps: {}", maybeUnreachable); - log.info("Unsound jumps: {}", unsoundJumps); - log.info("Maybe unsound jumps: {}", maybeUnsoundJumps); - - return StatisticsObject.newStatisticsObject() + StatisticsObject stats = StatisticsObject.newStatisticsObject() .totalOpcodes(cfg.getOpcodeCount()) .totalJumps(cfg.getAllJumps().size()) .resolvedJumps(resolvedJumps) @@ -442,6 +431,10 @@ private static StatisticsObject computeJumps(JumpSolver checker, Set .unsoundJumps(unsoundJumps) .maybeUnsoundJumps(maybeUnsoundJumps) .build(); + + log.info("### Calculating statistics ###\n{}", stats); + + return stats; } /** @@ -502,13 +495,12 @@ public static List buildContractsFromFile(Path filePath) throws E try { File myObj = new File(String.valueOf(filePath)); Scanner myReader = new Scanner(myObj); + int counter = 0; while (myReader.hasNextLine()) { String address = myReader.nextLine(); contracts.add(new SmartContract(address)); - - log.info("Created contract: {}", address); - Thread.sleep(500); + log.info("Created contract ({}): {}", ++counter, address); } myReader.close(); diff --git a/src/main/java/it/unipr/analysis/contract/SmartContract.java b/src/main/java/it/unipr/analysis/contract/SmartContract.java index 8748a81f2..e7420c279 100644 --- a/src/main/java/it/unipr/analysis/contract/SmartContract.java +++ b/src/main/java/it/unipr/analysis/contract/SmartContract.java @@ -106,6 +106,7 @@ public SmartContract(String address) { // Etherscan File file = new File(String.valueOf(_bytecodeFilePath)); if (!file.exists()) { + Thread.sleep(500); // Etherscan API request limit Files.createDirectories(outputDir); this._bytecode = EVMFrontend.parseBytecodeFromEtherscan(address); // Write bytecode to file @@ -118,6 +119,8 @@ public SmartContract(String address) { } } catch (IOException e) { log.warn("Failed to load bytecode: {}", address, e); + } catch (InterruptedException e) { + log.error("Unable to parse bytecode from Etherscan: {}", address, e); } // ABI case @@ -126,6 +129,7 @@ public SmartContract(String address) { // Etherscan File file = new File(String.valueOf(_abiFilePath)); if (!file.exists()) { + Thread.sleep(500); // Etherscan API request limit Files.createDirectories(outputDir); this._abi = EVMFrontend.parseABIFromEtherscan(address); // Write ABI to file @@ -138,6 +142,8 @@ public SmartContract(String address) { } } catch (IOException e) { log.warn("Failed to load ABI: {}", address, e); + } catch (InterruptedException e) { + log.error("Unable to parse ABI from Etherscan: {}", address, e); } try {