Skip to content

Commit bfa5925

Browse files
committed
Refactoring: moved all the utility classes under the utils package
1 parent 569ab99 commit bfa5925

13 files changed

+46
-22
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import it.unipr.checker.TxOriginChecker;
99
import it.unipr.crossChainAnalysis.CrossChainAnalysis;
1010
import it.unipr.frontend.EVMFrontend;
11+
import it.unipr.utils.MyCache;
12+
import it.unipr.utils.MyLogger;
1113
import it.unive.lisa.LiSA;
1214
import it.unive.lisa.analysis.SimpleAbstractState;
1315
import it.unive.lisa.analysis.heap.MonolithicHeap;

src/main/java/it/unipr/analysis/EVMAbstractState.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import it.unipr.analysis.operator.JumpiOperator;
44
import it.unipr.cfg.EVMCFG;
55
import it.unipr.frontend.EVMFrontend;
6+
import it.unipr.utils.MyCache;
67
import it.unive.lisa.analysis.BaseLattice;
78
import it.unive.lisa.analysis.Lattice;
89
import it.unive.lisa.analysis.ScopeToken;

src/main/java/it/unipr/checker/JumpSolver.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import it.unipr.cfg.ProgramCounterLocation;
99
import it.unipr.frontend.EVMFeatures;
1010
import it.unipr.frontend.EVMTypeSystem;
11+
import it.unipr.utils.MyCache;
1112
import it.unive.lisa.AnalysisException;
1213
import it.unive.lisa.LiSA;
1314
import it.unive.lisa.analysis.AnalysisState;

src/main/java/it/unipr/checker/ReentrancyChecker.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
import it.unipr.analysis.AbstractStack;
44
import it.unipr.analysis.EVMAbstractState;
5-
import it.unipr.analysis.MyCache;
65
import it.unipr.analysis.StackElement;
76
import it.unipr.cfg.Call;
87
import it.unipr.cfg.EVMCFG;
98
import it.unipr.cfg.ProgramCounterLocation;
9+
import it.unipr.utils.MyCache;
1010
import it.unive.lisa.analysis.AnalysisState;
1111
import it.unive.lisa.analysis.AnalyzedCFG;
1212
import it.unive.lisa.analysis.SemanticException;

src/main/java/it/unipr/checker/TimestampDependencyChecker.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
package it.unipr.checker;
22

3-
import static org.reflections.Reflections.log;
4-
5-
import it.unipr.analysis.MyCache;
63
import it.unipr.analysis.taint.TaintAbstractDomain;
74
import it.unipr.analysis.taint.TaintElement;
85
import it.unipr.cfg.*;
6+
import it.unipr.utils.MyCache;
97
import it.unive.lisa.analysis.AnalysisState;
108
import it.unive.lisa.analysis.AnalyzedCFG;
119
import it.unive.lisa.analysis.SemanticException;

src/main/java/it/unipr/checker/TxOriginChecker.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package it.unipr.checker;
22

3-
import it.unipr.analysis.MyCache;
43
import it.unipr.analysis.taint.TaintAbstractDomain;
54
import it.unipr.analysis.taint.TaintElement;
65
import it.unipr.cfg.EVMCFG;
76
import it.unipr.cfg.Origin;
87
import it.unipr.cfg.ProgramCounterLocation;
8+
import it.unipr.utils.MyCache;
99
import it.unive.lisa.analysis.AnalysisState;
1010
import it.unive.lisa.analysis.AnalyzedCFG;
1111
import it.unive.lisa.analysis.SemanticException;

src/main/java/it/unipr/crossChainAnalysis/CrossChainAnalysis.java

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import it.unipr.frontend.EVMFrontend;
1111
import it.unipr.frontend.EVMTypeSystem;
1212
import it.unipr.utils.EthereumUtils;
13+
import it.unipr.utils.MyCache;
1314
import it.unive.lisa.LiSA;
1415
import it.unive.lisa.analysis.SimpleAbstractState;
1516
import it.unive.lisa.analysis.heap.MonolithicHeap;
@@ -41,16 +42,16 @@ public class CrossChainAnalysis {
4142
private final Bridge _bridge;
4243
private EVMCFG _xCFG;
4344
private List<Edge> _crossChainEdges;
44-
private final int _cores;
45-
private ExecutorService _executor;
45+
private final ExecutorService _executor;
4646

4747
public CrossChainAnalysis(Path abi, Path bytecode) {
4848
this._abiFolder = abi;
4949
this._bytecodeFolder = bytecode;
5050
this._bridge = new Bridge(abi, bytecode);
5151
this._xCFG = null;
5252
this._crossChainEdges = new ArrayList<>();
53-
this._cores = Runtime.getRuntime().availableProcessors() - 1;
53+
54+
int _cores = Runtime.getRuntime().availableProcessors() - 1;
5455
this._executor = Executors.newFixedThreadPool(_cores > 0 ? _cores : 1);
5556
}
5657

@@ -85,7 +86,11 @@ public void run() {
8586
shutdownExecutor();
8687
}
8788

88-
private void runCheckers() {
89+
/**
90+
* Executes all security checkers in parallel on the smart contracts in the
91+
* bridge.
92+
*/
93+
public void runCheckers() {
8994
List<Future<?>> futures = new ArrayList<>();
9095

9196
for (SmartContract contract : _bridge) {
@@ -113,6 +118,11 @@ private void runCheckers() {
113118
}
114119
}
115120

121+
/**
122+
* Runs the reentrancy checker on the given smart contract.
123+
*
124+
* @param contract The smart contract to analyze.
125+
*/
116126
private void runReentrancyChecker(SmartContract contract) {
117127
// Setup configuration
118128
Program program = new Program(new EVMFeatures(), new EVMTypeSystem());
@@ -126,6 +136,14 @@ private void runReentrancyChecker(SmartContract contract) {
126136
lisa.run(program);
127137
}
128138

139+
/**
140+
* Runs the event order checker on the given smart contract. This method
141+
* verifies whether events are emitted before state modifications (SSTORE
142+
* instructions). It identifies vulnerabilities where an event is emitted
143+
* without prior state changes, potentially leading to inconsistencies.
144+
*
145+
* @param contract The smart contract to analyze.
146+
*/
129147
private void runEventOrderChecker(SmartContract contract) {
130148
List<Statement> functionsEntrypoints = new ArrayList<>();
131149

src/main/java/it/unipr/analysis/MyCache.java renamed to src/main/java/it/unipr/utils/MyCache.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
package it.unipr.analysis;
1+
package it.unipr.utils;
22

3+
import it.unipr.analysis.Number;
4+
import it.unipr.analysis.StackElement;
35
import java.util.Collections;
46
import java.util.HashSet;
57
import java.util.Set;
@@ -9,12 +11,12 @@
911
/**
1012
* Singleton class implementing a cache with an LRU (Least Recently Used)
1113
* eviction policy. The cache uses a {@link LRUMap} to store key-value pairs
12-
* where the key is a {@link Pair} of {@link String} and {@link Number}, and the
13-
* value is a {@link StackElement}.
14+
* where the key is a {@link Pair} of {@link String} and
15+
* {@link it.unipr.analysis.Number}, and the value is a {@link StackElement}.
1416
*/
1517
public class MyCache {
1618
private static MyCache _instance = null;
17-
private final LRUMap<Pair<String, Number>, StackElement> _map;
19+
private final LRUMap<Pair<String, it.unipr.analysis.Number>, StackElement> _map;
1820
private final LRUMap<String, Long> _timeLostToGetStorage;
1921
private final LRUMap<Integer, Set<Object>> _reentrancyWarnings;
2022
private final LRUMap<Integer, Set<Object>> _txOriginWarnings;
@@ -41,7 +43,7 @@ public static MyCache getInstance() {
4143
* a maximum size of 500.
4244
*/
4345
private MyCache() {
44-
this._map = new LRUMap<Pair<String, Number>, StackElement>(500);
46+
this._map = new LRUMap<Pair<String, it.unipr.analysis.Number>, StackElement>(500);
4547
this._timeLostToGetStorage = new LRUMap<String, Long>(500);
4648
this._reentrancyWarnings = new LRUMap<Integer, Set<Object>>(1000);
4749
this._txOriginWarnings = new LRUMap<Integer, Set<Object>>(1000);
@@ -53,10 +55,10 @@ private MyCache() {
5355
* Puts a key-value pair into the cache.
5456
*
5557
* @param key the key, a {@link Pair} of {@link String} and
56-
* {@link Number}.
58+
* {@link it.unipr.analysis.Number}.
5759
* @param value the value, a {@link StackElement}.
5860
*/
59-
public void put(Pair<String, Number> key, StackElement value) {
61+
public void put(Pair<String, it.unipr.analysis.Number> key, StackElement value) {
6062
synchronized (_map) {
6163
_map.put(key, value);
6264
}
@@ -65,7 +67,8 @@ public void put(Pair<String, Number> key, StackElement value) {
6567
/**
6668
* Retrieves a value from the cache by its key.
6769
*
68-
* @param key the key, a {@link Pair} of {@link String} and {@link Number}.
70+
* @param key the key, a {@link Pair} of {@link String} and
71+
* {@link it.unipr.analysis.Number}.
6972
*
7073
* @return the value associated with the key, or {@code null} if the key is
7174
* not in the cache.

src/main/java/it/unipr/analysis/MyLogger.java renamed to src/main/java/it/unipr/utils/MyLogger.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package it.unipr.analysis;
1+
package it.unipr.utils;
22

33
import org.json.JSONObject;
44

src/test/java/it/unipr/analysis/cron/EVMBytecodeGroundTruth.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
import it.unipr.analysis.AbstractStack;
55
import it.unipr.analysis.AbstractStackSet;
66
import it.unipr.analysis.EVMAbstractState;
7-
import it.unipr.analysis.MyCache;
8-
import it.unipr.analysis.MyLogger;
97
import it.unipr.checker.JumpSolver;
108
import it.unipr.frontend.EVMFrontend;
9+
import it.unipr.utils.MyCache;
10+
import it.unipr.utils.MyLogger;
1111
import it.unive.lisa.LiSA;
1212
import it.unive.lisa.analysis.SimpleAbstractState;
1313
import it.unive.lisa.analysis.heap.MonolithicHeap;

0 commit comments

Comments
 (0)