Skip to content

Commit

Permalink
Optimized the creation of contracts in buildContractsFromFile(), intr…
Browse files Browse the repository at this point in the history
…oduced test mode in analyzeContract()
  • Loading branch information
merendamattia committed Mar 3, 2025
1 parent 6a38174 commit ee16bb9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
26 changes: 9 additions & 17 deletions src/main/java/it/unipr/EVMLiSA.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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();
}
}

Expand Down Expand Up @@ -341,9 +341,6 @@ public static StatisticsObject computeStatistics(JumpSolver checker, LiSA lisa,
*/
private static StatisticsObject computeJumps(JumpSolver checker, Set<Statement> soundlySolved) {
EVMCFG cfg = checker.getComputedCFG();

log.info("### Calculating statistics ###");

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

int resolvedJumps = 0;
Expand Down Expand Up @@ -425,15 +422,7 @@ private static StatisticsObject computeJumps(JumpSolver checker, Set<Statement>
}
}

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)
Expand All @@ -442,6 +431,10 @@ private static StatisticsObject computeJumps(JumpSolver checker, Set<Statement>
.unsoundJumps(unsoundJumps)
.maybeUnsoundJumps(maybeUnsoundJumps)
.build();

log.info("### Calculating statistics ###\n{}", stats);

return stats;
}

/**
Expand Down Expand Up @@ -502,13 +495,12 @@ public static List<SmartContract> 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();

Expand Down
6 changes: 6 additions & 0 deletions src/main/java/it/unipr/analysis/contract/SmartContract.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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 {
Expand Down

0 comments on commit ee16bb9

Please sign in to comment.