Skip to content

Commit 7f74425

Browse files
committed
Added test mode functionality.
1 parent d33b026 commit 7f74425

File tree

2 files changed

+35
-34
lines changed

2 files changed

+35
-34
lines changed

src/main/java/it/unipr/EVMLiSA.java

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,10 @@ public static void setTestMode() {
149149
TEST_MODE = true;
150150
}
151151

152+
public static boolean isInTestMode() {
153+
return TEST_MODE;
154+
}
155+
152156
/**
153157
* Executes the analysis workflow.
154158
*
@@ -244,7 +248,7 @@ public static void analyzeSetOfContracts(List<SmartContract> contracts) {
244248

245249
log.info("Finished analysis of {} contracts.", contracts.size());
246250

247-
Path outputDir = OUTPUT_DIRECTORY_PATH.resolve("contracts-" + System.currentTimeMillis());
251+
Path outputDir = OUTPUT_DIRECTORY_PATH.resolve("set-of-contracts");
248252
try {
249253
Files.createDirectories(outputDir);
250254
Files.writeString(
@@ -295,12 +299,12 @@ public static void buildCFG(SmartContract contract) {
295299
contract.setExecutionTime(System.currentTimeMillis() - startTime);
296300

297301
log.info("[OUT] CFG of contract {} built.", contract.getName());
298-
302+
log.info("[IN] Computing statistics of contract {}.", contract.getName());
299303
contract.setStatistics(
300304
computeStatistics(checker, lisa, program));
301305
contract.setCFG(checker.getComputedCFG());
302306

303-
log.debug("Contract {} statistics: {}", contract.getAddress(), contract.getStatistics());
307+
log.debug("[OUT] Contract {} statistics: {}", contract.getAddress(), contract.getStatistics());
304308

305309
if (TEST_MODE)
306310
return;
@@ -674,6 +678,8 @@ private void setupGlobalOptions(CommandLine cmd) {
674678
EVMAbstractState.setUseStorageLive();
675679
if (cmd.hasOption("etherscan-api-key"))
676680
EVMFrontend.setEtherscanAPIKey(cmd.getOptionValue("etherscan-api-key"));
681+
if (cmd.hasOption("test-mode"))
682+
EVMLiSA.setTestMode();
677683
}
678684

679685
private Options getOptions() {
@@ -714,6 +720,7 @@ private Options getOptions() {
714720
.required(false)
715721
.hasArg(true)
716722
.build();
723+
717724
Option abiOption = Option.builder()
718725
.longOpt("abi")
719726
.desc("ABI of the bytecode to be analyzed (JSON format).")
@@ -798,18 +805,11 @@ private Options getOptions() {
798805
.hasArg(true)
799806
.build();
800807

801-
Option crossChainBytecodeDirectoryPathOption = Option.builder()
802-
.longOpt("bytecode-directory-path")
803-
.desc("Directory path of bytecode files.")
804-
.required(false)
805-
.hasArg(true)
806-
.build();
807-
808-
Option crossChainAbiDirectoryPathOption = Option.builder()
809-
.longOpt("abi-directory-path")
810-
.desc("Directory path of abi files.")
808+
Option useTestModeOption = Option.builder()
809+
.longOpt("test-mode")
810+
.desc("Use the test mode (i.e., do not compute functions and events).")
811811
.required(false)
812-
.hasArg(true)
812+
.hasArg(false)
813813
.build();
814814

815815
options.addOption(addressOption);
@@ -829,8 +829,7 @@ private Options getOptions() {
829829
options.addOption(outputDirectoryPathOption);
830830
options.addOption(etherscanAPIKeyOption);
831831
options.addOption(abiOption);
832-
options.addOption(crossChainBytecodeDirectoryPathOption);
833-
options.addOption(crossChainAbiDirectoryPathOption);
832+
options.addOption(useTestModeOption);
834833

835834
return options;
836835
}

src/main/java/it/unipr/analysis/contract/SmartContract.java

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package it.unipr.analysis.contract;
22

3+
import it.unipr.EVMLiSA;
34
import it.unipr.cfg.EVMCFG;
45
import it.unipr.cfg.push.Push;
56
import it.unipr.frontend.EVMFrontend;
@@ -779,9 +780,25 @@ public JSONObject toJson() {
779780
JSONObject jsonObject = new JSONObject();
780781

781782
jsonObject.put("address", _address != null ? _address : new JSONArray());
782-
jsonObject.put("bytecode", _bytecode != null ? _bytecode : new JSONArray());
783-
jsonObject.put("mnemonic_bytecode", _mnemonicBytecode != null ? _mnemonicBytecode : new JSONArray());
784-
jsonObject.put("abi", _abi != null ? _abi : new JSONArray());
783+
if (!EVMLiSA.isInTestMode()) {
784+
jsonObject.put("bytecode", _bytecode != null ? _bytecode : new JSONArray());
785+
jsonObject.put("mnemonic_bytecode", _mnemonicBytecode != null ? _mnemonicBytecode : new JSONArray());
786+
jsonObject.put("abi", _abi != null ? _abi : new JSONArray());
787+
788+
jsonObject.put("basic_blocks",
789+
_basicBlocks != null ? JSONManager.basicBlocksToJson(this) : new JSONArray());
790+
JSONArray functionsArray = new JSONArray();
791+
if (_functionsSignature != null && !_functionsSignature.isEmpty())
792+
for (Signature signature : _functionsSignature)
793+
functionsArray.put(signature.toJson());
794+
jsonObject.put("functions_signature", !functionsArray.isEmpty() ? functionsArray : new JSONArray());
795+
796+
JSONArray eventsArray = new JSONArray();
797+
if (_eventsSignature != null && !_eventsSignature.isEmpty())
798+
for (Signature signature : _eventsSignature)
799+
eventsArray.put(signature.toJson());
800+
jsonObject.put("events_signature", !eventsArray.isEmpty() ? eventsArray : new JSONArray());
801+
}
785802

786803
jsonObject.put("working_directory", _workingDirectory.toString());
787804

@@ -794,26 +811,11 @@ public JSONObject toJson() {
794811

795812
jsonObject.put("vulnerabilities", _vulnerabilities != null ? _vulnerabilities.toJson() : new JSONArray());
796813

797-
jsonObject.put("basic_blocks",
798-
_basicBlocks != null ? JSONManager.basicBlocksToJson(this) : new JSONArray());
799-
800814
jsonObject.put("basic_blocks_pc", _basicBlocks != null ? BasicBlock.basicBlocksToLongArrayToString(
801815
BasicBlock.basicBlocksToLongArray(_basicBlocks)) : new JSONArray());
802816

803817
jsonObject.put("execution_time", _executionTime);
804818

805-
JSONArray functionsArray = new JSONArray();
806-
if (_functionsSignature != null && !_functionsSignature.isEmpty())
807-
for (Signature signature : _functionsSignature)
808-
functionsArray.put(signature.toJson());
809-
jsonObject.put("functions_signature", !functionsArray.isEmpty() ? functionsArray : new JSONArray());
810-
811-
JSONArray eventsArray = new JSONArray();
812-
if (_eventsSignature != null && !_eventsSignature.isEmpty())
813-
for (Signature signature : _eventsSignature)
814-
eventsArray.put(signature.toJson());
815-
jsonObject.put("events_signature", !eventsArray.isEmpty() ? eventsArray : new JSONArray());
816-
817819
return jsonObject;
818820
}
819821

0 commit comments

Comments
 (0)