Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
merendamattia committed Oct 7, 2024
1 parent bd035d2 commit 1adea7a
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 40 deletions.
78 changes: 38 additions & 40 deletions src/main/java/it/unipr/EVMLiSA.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public void go(String[] args) throws Exception {
try {
cmd = parser.parse(options, args);
} catch (ParseException e) {
System.err.println(e.getMessage());
log.error(e.getMessage());
formatter.printHelp("help", options);

System.exit(1);
Expand Down Expand Up @@ -205,7 +205,7 @@ public void go(String[] args) throws Exception {
AbstractStackSet.setStackSetSize(Integer.parseInt(stackSetSize));

} catch (NumberFormatException e) {
System.out.println("Size must be an integer");
log.error("Size must be an integer");
formatter.printHelp("help", options);

System.exit(1);
Expand Down Expand Up @@ -246,7 +246,7 @@ public void go(String[] args) throws Exception {
try {
runBenchmark(jsonOptions);
} catch (FileNotFoundException e) {
System.err.println("File " + benchmark + " not found.");
log.error("File " + benchmark + " not found.");
}
return;
}
Expand Down Expand Up @@ -308,19 +308,20 @@ else if (dumpAnalysis.equals("html"))
// Print the results
finish = System.currentTimeMillis();

String msg = EVMLiSA.dumpStatistics(checker)
.address(addressSC)
.time(finish - start)
.timeLostToGetStorage(MyCache.getInstance().getTimeLostToGetStorage(addressSC))
.buildJson(jsonOptions)
.build()
.toString();
MyLogger result = EVMLiSA.dumpStatistics(checker)
.address(addressSC)
.time(finish - start)
.timeLostToGetStorage(MyCache.getInstance().getTimeLostToGetStorage(addressSC))
.buildJson(jsonOptions)
.build();

if (dumpStatistics) {
toFile(STATISTICS_FULLPATH, msg);
System.out.println("Statistics successfully written in " + STATISTICS_FULLPATH);
toFile(STATISTICS_FULLPATH, result.toString());
log.info("Statistics successfully written in " + STATISTICS_FULLPATH);
}

System.err.println(result.getJson());

} catch (Throwable e) {
finish = System.currentTimeMillis();

Expand All @@ -332,11 +333,11 @@ else if (dumpAnalysis.equals("html"))
.buildJson(jsonOptions)
.build().toString();

System.err.println(msg);
log.error(msg);

if (dumpStatistics) {
toFile(FAILURE_FULLPATH, msg);
System.out.println("Failures successfully written in " + FAILURE_FULLPATH);
log.info("Failures successfully written in " + FAILURE_FULLPATH);
}
}
}
Expand Down Expand Up @@ -455,7 +456,7 @@ public void run() {
smartContractsTerminatedSuccesfully.size(), analysesTerminated,
analysesFailed, threadsStarted);

System.out.println(msg);
log.info(msg);
toFile(LOGS_FULLPATH, msg);

mutex.notifyAll();
Expand All @@ -472,14 +473,14 @@ public void run() {
.notes("failure: " + e + " - details: " + e.getMessage())
.build().toString();

System.err.println(msg);
log.error(msg);
toFile(FAILURE_FULLPATH, msg);

msg = buildMessage("FAILURE", address, smartContracts.size(),
smartContractsTerminatedSuccesfully.size(), analysesTerminated,
analysesFailed, threadsStarted);

System.out.println(msg);
log.info(msg);
toFile(LOGS_FULLPATH, msg);

mutex.notifyAll();
Expand Down Expand Up @@ -533,7 +534,7 @@ public void run() {
msg += "Heap Max size: " + new Converter().getSize(Runtime.getRuntime().maxMemory()) + "\n";
msg += "\n"; // Blank line

System.out.println(msg);
log.info(msg);
toFile(LOGS_FULLPATH, msg);

guardia.wait(timeToWait);
Expand Down Expand Up @@ -561,13 +562,13 @@ public void run() {
"successfully: " + smartContractsTerminatedSuccesfully.size() + ", " +
"failed: " + (smartContracts.size() - smartContractsTerminatedSuccesfully.size()) + " \n";

System.out.println(msg);
log.info(msg);
toFile(LOGS_FULLPATH, msg);

System.out.println("Statistics successfully written in " + STATISTICS_FULLPATH);
System.out.println("Logs successfully written in " + LOGS_FULLPATH);
System.out.println("Statistics with zero jumps successfully written in " + STATISTICSZEROJUMP_FULLPATH);
System.out.println("Failures successfully written in " + FAILURE_FULLPATH);
log.info("Statistics successfully written in " + STATISTICS_FULLPATH);
log.info("Logs successfully written in " + LOGS_FULLPATH);
log.info("Statistics with zero jumps successfully written in " + STATISTICSZEROJUMP_FULLPATH);
log.info("Failures successfully written in " + FAILURE_FULLPATH);
}

/**
Expand All @@ -583,7 +584,7 @@ public void run() {
public static MyLogger dumpStatistics(JumpSolver checker) {
EVMCFG cfg = checker.getComputedCFG();

System.err.println("### Calculating statistics ###");
log.info("### Calculating statistics ###");

Set<Statement> unreachableJumpNodes = checker.getUnreachableJumps();

Expand Down Expand Up @@ -642,22 +643,19 @@ else if (!reachableFrom) {
resolvedJumps++;
} else {
unsoundJumps++;
System.err.println(jumpNode + " not solved");
System.err.println("getTopStackValuesPerJump: " + topStackValuesPerJump);
log.error(jumpNode + " not solved");
log.error("getTopStackValuesPerJump: " + topStackValuesPerJump);
}
}
}

System.err.println();
System.err.println("##############");
System.err.println("Total opcodes: " + cfg.getOpcodeCount());
System.err.println("Total jumps: " + cfg.getAllJumps().size());
System.err.println("Resolved jumps: " + resolvedJumps);
System.err.println("Definitely unreachable jumps: " + definitelyUnreachable);
System.err.println("Maybe unreachable jumps: " + maybeUnreachable);
System.err.println("Unsound jumps: " + unsoundJumps);
System.err.println("Maybe unsound jumps: " + maybeUnsoundJumps);
System.err.println("##############");
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 MyLogger.newLogger()
.opcodes(cfg.getOpcodeCount())
Expand Down Expand Up @@ -733,7 +731,7 @@ public static ArrayList<String> readSmartContractsFromFile(String SMARTCONTRACTS
myReader.close();

} catch (FileNotFoundException e) {
System.err.println("[ERROR] " + SMARTCONTRACTS_FULLPATH + " not found");
log.error(SMARTCONTRACTS_FULLPATH + " not found");
throw e;
}

Expand Down Expand Up @@ -763,7 +761,7 @@ public static void toFile(String FILE_PATH, String stats) {
}

} catch (IOException e) {
System.err.println("An error occurred in " + FILE_PATH);
log.error("An error occurred in " + FILE_PATH);
}
}
}
Expand Down Expand Up @@ -859,15 +857,15 @@ private void saveSmartContractsFromEtherscan() throws Exception {
if (EVMFrontend.parseContractFromEtherscan(address, BYTECODE_FULLPATH))
numberOfAPIEtherscanRequestOnSuccess++;

System.out.printf("Downloading %s, remaining: %s \n", address,
log.info("Downloading {}, remaining: {}", address,
(smartContracts.size() - numberOfAPIEtherscanRequest));
}
} catch (Exception e) {
continue;
}
}

System.out.printf("Downloaded %s smart contract \n", numberOfAPIEtherscanRequestOnSuccess);
log.info("Downloaded {} smart contract", numberOfAPIEtherscanRequestOnSuccess);
}

public static class Converter {
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/it/unipr/analysis/MyLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,11 @@ public int jumpSize() {
return jumps;
}

public String getJson(){
return json.toString(4);
}


@Override
public String toString() {
return address + divider +
Expand Down

0 comments on commit 1adea7a

Please sign in to comment.