Skip to content

Commit

Permalink
Minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
merendamattia committed Feb 26, 2024
1 parent 9ede2e1 commit 6dea99e
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 7 deletions.
57 changes: 53 additions & 4 deletions src/main/java/it/unipr/EVMLiSA.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public class EVMLiSA {
private static SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("YYYY-MM-dd HH:mm:ss,SSS");
private int CORES;
private long startOfExecutionTime = 0;

private String init = "Smart Contract, Total Opcodes, Total Jumps, Solved Jumps, Definitely unreachable jumps, Maybe unreachable jumps, Total solved Jumps, Not solved jumps, % Total Solved, Time (millis), Notes \n";
/**
* Generates a control flow graph (represented as a LiSA {@code Program})
* from a EVM bytecode smart contract and runs the analysis on it.
Expand Down Expand Up @@ -669,7 +669,6 @@ public ArrayList<String> readSmartContractsFromFile() throws Exception {
*/
private void toFileStatistics(String stats) {
synchronized (STATISTICS_FULLPATH) {
String init = "Smart Contract, Total Opcodes, Total Jumps, Precisely solved Jumps, Sound solved Jumps, Definitely unreachable jumps, Maybe unreachable jumps, Total solved Jumps, Not solved jumps, % Total Solved, Time (millis), Thread, Notes \n";
try {
File idea = new File(STATISTICS_FULLPATH);
if (!idea.exists()) {
Expand Down Expand Up @@ -697,7 +696,6 @@ private void toFileStatistics(String stats) {
*/
private void toFileStatisticsWithZeroJumps(String stats) {
synchronized (STATISTICSZEROJUMP_FULLPATH) {
String init = "Smart Contract, Total Opcodes, Total Jumps, Precisely solved Jumps, Sound solved Jumps, Definitely unreachable jumps, Maybe unreachable jumps, Total solved Jumps, % Precisely Solved, % Total Solved, Time (millis), Thread, Notes \n";
try {
File idea = new File(STATISTICSZEROJUMP_FULLPATH);
if (!idea.exists()) {
Expand Down Expand Up @@ -725,7 +723,6 @@ private void toFileStatisticsWithZeroJumps(String stats) {
*/
private void toFileFailure(String stats) {
synchronized (FAILURE_FULLPATH) {
String init = "Smart Contract, Total Opcodes, Total Jumps, Precisely solved Jumps, Sound solved Jumps, Definitely unreachable jumps, Maybe unreachable jumps, Total solved Jumps, Not solved jumps, % Total Solved, Time (millis), Thread, Notes \n";
try {
File idea = new File(FAILURE_FULLPATH);
if (!idea.exists()) {
Expand Down Expand Up @@ -816,5 +813,57 @@ private String buildMessage(String type, String address, int smartContractsSize,
private String now() {
return DATE_FORMAT.format(System.currentTimeMillis());
}

/**
* Saves smart contracts bytecode from Etherscan.
* <p>
* This method reads a list of smart contract addresses from a file, then
* for each address, it retrieves the bytecode of the corresponding smart
* contract from Etherscan.io and saves it to a file. The method also limits
* the API requests to Etherscan.io to a maximum of 5 per second.
* </p>
*
* @throws Exception if an error occurs during the process.
*/
@SuppressWarnings("unused")
private void saveSmartContractsFromEtherscan() throws Exception {
List<String> smartContracts = readSmartContractsFromFile();

for (int i = 0; i < smartContracts.size(); i++) {
String address = smartContracts.get(i);

String BYTECODE_FULLPATH = OUTPUT_DIR + "/benchmark/" + address + "/" + address
+ ".sol";

if (i % 5 == 0) {
try {
Thread.sleep(1001); // I can do max 5 API
// request in 1 sec to
// Etherscan.io
} catch (InterruptedException e) {
e.printStackTrace();
}
}

// Directory setup and bytecode retrieval
try {
Files.createDirectories(Paths.get(OUTPUT_DIR + "/" + "benchmark/" + address));

// If the file does not exists, we will do an API request to
// Etherscan
File file = new File(BYTECODE_FULLPATH);
if (!file.exists()) {
numberOfAPIEtherscanRequest++;
if (EVMFrontend.parseContractFromEtherscan(address, BYTECODE_FULLPATH))
numberOfAPIEtherscanRequestOnSuccess++;

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

}
7 changes: 4 additions & 3 deletions src/main/java/it/unipr/analysis/MyLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,16 @@ public String toString() {
return address + divider +
opcodes + divider +
jumps + divider +
preciselyResolvedJumps + divider +
soundResolvedJumps + divider +
// preciselyResolvedJumps + divider +
// soundResolvedJumps + divider +
(soundResolvedJumps + preciselyResolvedJumps) + divider +
definitelyUnreachableJumps + divider +
maybeUnreachableJumps + divider +
totalResolvedJumps + divider +
notSolvedJumps + divider +
solvedJumpsPercent + divider +
time + divider +
currentThread + divider +
// currentThread + divider +
notes + " \n";
}
}

0 comments on commit 6dea99e

Please sign in to comment.