Skip to content

Commit feac4c5

Browse files
committed
Added option to show all instructions in CFG representation (#53)
1 parent 60da221 commit feac4c5

File tree

3 files changed

+45
-17
lines changed

3 files changed

+45
-17
lines changed

README.md

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -98,23 +98,24 @@ Alternatively, you can pass your API key directly using the `--etherscan-api-key
9898

9999
```
100100
Options:
101-
-a,--address <arg> Address of an Ethereum smart contract
101+
-a,--address <arg> Address of an Ethereum smart contract.
102102
--abi <arg> ABI of the bytecode to be analyzed (JSON format).
103-
--abi-path <arg> Filepath of the ABI file
104-
-b,--bytecode <arg> Bytecode to be analyzed (e.g., 0x6080...)
105-
--benchmark <arg> Filepath of the benchmark
106-
--bytecode-path <arg> Filepath of the bytecode file
107-
-c,--cores <arg> Number of cores used in benchmark
108-
--checker-all Enable all security checkers
109-
--checker-reentrancy Enable reentrancy checker
110-
--checker-timestampdependency Enable timestamp-dependency checker
111-
--checker-txorigin Enable tx-origin checker
112-
--etherscan-api-key <arg> Insert your Etherscan API key
113-
--link-unsound-jumps-to-all-jumpdest Link all unsound jumps to all jumpdest
114-
--output-directory-path <arg> Filepath of the output directory
115-
--stack-set-size <arg> Dimension of stack-set (default: 8)
116-
--stack-size <arg> Dimension of stack (default: 32)
117-
--use-live-storage Use the live storage in SLOAD
103+
--abi-path <arg> Filepath of the ABI file.
104+
-b,--bytecode <arg> Bytecode to be analyzed (e.g., 0x6080...).
105+
--benchmark <arg> Filepath of the benchmark.
106+
--bytecode-path <arg> Filepath of the bytecode file.
107+
-c,--cores <arg> Number of cores used in benchmark.
108+
--checker-all Enable all security checkers.
109+
--checker-reentrancy Enable reentrancy checker.
110+
--checker-timestampdependency Enable timestamp-dependency checker.
111+
--checker-txorigin Enable tx-origin checker.
112+
--etherscan-api-key <arg> Insert your Etherscan API key.
113+
--link-unsound-jumps-to-all-jumpdest Link all unsound jumps to all jumpdest.
114+
--output-directory-path <arg> Filepath of the output directory.
115+
--show-all-instructions-in-cfg Show all instructions in the CFG representation.
116+
--stack-set-size <arg> Dimension of stack-set (default: 8).
117+
--stack-size <arg> Dimension of stack (default: 32).
118+
--use-live-storage Use the live storage in SLOAD.
118119
```
119120

120121
## The Abstract Stack Set Domain

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,8 @@ private void setupGlobalOptions(CommandLine cmd) {
810810
EVMLiSA.setTestMode();
811811
if (cmd.hasOption("paper-stats"))
812812
EVMLiSA.setPaperMode();
813+
if (cmd.hasOption("show-all-instructions-in-cfg"))
814+
DOTFileManager.showAllInstructions();
813815
}
814816

815817
private Options getOptions() {
@@ -949,6 +951,13 @@ private Options getOptions() {
949951
.hasArg(false)
950952
.build();
951953

954+
Option showAllInstructionsInCFG = Option.builder()
955+
.longOpt("show-all-instructions-in-cfg")
956+
.desc("Show all instructions in the Control Flow Graph representation.")
957+
.required(false)
958+
.hasArg(false)
959+
.build();
960+
952961
options.addOption(addressOption);
953962
options.addOption(bytecodeOption);
954963
options.addOption(bytecodePathOption);
@@ -968,6 +977,7 @@ private Options getOptions() {
968977
options.addOption(abiOption);
969978
options.addOption(useTestModeOption);
970979
options.addOption(usePaperStats);
980+
options.addOption(showAllInstructionsInCFG);
971981

972982
return options;
973983
}

src/main/java/it/unipr/utils/DOTFileManager.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,23 @@ public class DOTFileManager {
2020
public static String blueColor = "#6FA8DC";
2121
public static String blackColor = "#000000";
2222

23+
public static boolean showAllInstructions = false;
24+
25+
/**
26+
* Sets a flag to show all instructions.
27+
*/
28+
public static void showAllInstructions() {
29+
showAllInstructions = true;
30+
}
31+
32+
/**
33+
* Generates a DOT graph from the provided basic blocks and writes it to the
34+
* specified output path. The graph includes nodes for each basic block,
35+
* edges for outgoing edges, and a legend for color interpretation.
36+
*
37+
* @param basicBlocks an array of JSON objects representing basic blocks
38+
* @param outputPath the file path where the .dot file will be written
39+
*/
2340
public static void generateDotGraph(JSONArray basicBlocks, String outputPath) {
2441
StringBuilder dotGraph = new StringBuilder();
2542
dotGraph.append("digraph CFG {\n");
@@ -36,7 +53,7 @@ public static void generateDotGraph(JSONArray basicBlocks, String outputPath) {
3653
if (block.has("label"))
3754
label.append(block.getString("label")).append("\\n- - - - - - - - - - - -\\n");
3855

39-
if (instructions.length() > 5) {
56+
if (!showAllInstructions && instructions.length() > 5) {
4057
JSONObject firstInstr = instructions.getJSONObject(0);
4158
JSONObject secondInstr = instructions.getJSONObject(1);
4259
JSONObject secondLastInstr = instructions.getJSONObject(instructions.length() - 2);

0 commit comments

Comments
 (0)