Skip to content

Commit 3220297

Browse files
Added reference for timestampDependency checker
1 parent 07945fa commit 3220297

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package it.unipr;
22

33
import it.unipr.analysis.*;
4+
import it.unipr.analysis.taint.TimestampDependencyAbstractDomain;
45
import it.unipr.analysis.taint.TxOriginAbstractDomain;
56
import it.unipr.cfg.*;
67
import it.unipr.checker.JumpSolver;
78
import it.unipr.checker.ReentrancyChecker;
9+
import it.unipr.checker.TimestampDependencyChecker;
810
import it.unipr.checker.TxOriginChecker;
911
import it.unipr.frontend.EVMFrontend;
1012
import it.unive.lisa.LiSA;
@@ -72,6 +74,7 @@ public class EVMLiSA {
7274
private static final boolean REGENERATE = false;
7375
private static boolean ENABLE_REENTRANCY_CHECKER = false;
7476
private static boolean ENABLE_TXORIGIN_CHECKER = false;
77+
private static boolean ENABLE_TIMESTAMPDEPENDENCY_CHECKER = false;
7578

7679
/**
7780
* Generates a control flow graph (represented as a LiSA {@code Program})
@@ -201,6 +204,7 @@ private void setupGlobalOptions(CommandLine cmd) {
201204

202205
ENABLE_REENTRANCY_CHECKER = cmd.hasOption("checker-reentrancy");
203206
ENABLE_TXORIGIN_CHECKER = cmd.hasOption("checker-txorigin");
207+
ENABLE_TIMESTAMPDEPENDENCY_CHECKER = cmd.hasOption("checker-timestampdependency");
204208

205209
try {
206210
if (cmd.hasOption("stack-size"))
@@ -544,6 +548,19 @@ void checkers(LiSAConfiguration conf, LiSA lisa, Program program, JumpSolver che
544548
jsonOptions.put("tx-origin-warning",
545549
MyCache.getInstance().getTxOriginWarnings(checker.getComputedCFG().hashCode()));
546550
}
551+
552+
if (ENABLE_TIMESTAMPDEPENDENCY_CHECKER) {
553+
// Clear existing checks and add the TimestampdependencyChecker
554+
conf.semanticChecks.clear();
555+
conf.semanticChecks.add(new TimestampDependencyChecker());
556+
conf.abstractState = new SimpleAbstractState<>(new MonolithicHeap(), new TimestampDependencyAbstractDomain(),
557+
new TypeEnvironment<>(new InferredTypes()));
558+
lisa.run(program);
559+
560+
// Store timestamp-dependency warnings in the JSON options
561+
jsonOptions.put("timestamp-dependency-warning",
562+
MyCache.getInstance().getTimestampDependencyWarnings(checker.getComputedCFG().hashCode()));
563+
}
547564
}
548565

549566
/**
@@ -1143,6 +1160,13 @@ private Options getOptions() {
11431160
.hasArg(false)
11441161
.build();
11451162

1163+
Option enableTimestampDependencyCheckerOption = Option.builder()
1164+
.longOpt("checker-timestampdependency")
1165+
.desc("Enable timestamp-dependency checker.")
1166+
.required(false)
1167+
.hasArg(false)
1168+
.build();
1169+
11461170
options.addOption(addressOption);
11471171
options.addOption(outputOption);
11481172
options.addOption(filePathOption);
@@ -1163,6 +1187,8 @@ private Options getOptions() {
11631187
options.addOption(dumpDotOption);
11641188
options.addOption(enableReentrancyCheckerOption);
11651189
options.addOption(enableTxOriginCheckerOption);
1190+
options.addOption(enableTimestampDependencyCheckerOption);
1191+
11661192

11671193
return options;
11681194
}

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public class MyCache {
1818
private final LRUMap<String, Long> _timeLostToGetStorage;
1919
private final LRUMap<Integer, Set<Object>> _reentrancyWarnings;
2020
private final LRUMap<Integer, Set<Object>> _txOriginWarnings;
21+
private final LRUMap<Integer, Set<Object>> _timestampDependencyWarnings;
2122
private final LRUMap<Integer, Boolean> _reachableFrom;
2223

2324
/**
@@ -44,6 +45,7 @@ private MyCache() {
4445
this._timeLostToGetStorage = new LRUMap<String, Long>(500);
4546
this._reentrancyWarnings = new LRUMap<Integer, Set<Object>>(1000);
4647
this._txOriginWarnings = new LRUMap<Integer, Set<Object>>(1000);
48+
this._timestampDependencyWarnings = new LRUMap<Integer, Set<Object>>(1000);
4749
this._reachableFrom = new LRUMap<Integer, Boolean>(2000);
4850
}
4951

@@ -225,4 +227,38 @@ public int getTxOriginWarnings(Integer key) {
225227
return (_txOriginWarnings.get(key) != null) ? _txOriginWarnings.get(key).size() : 0;
226228
}
227229
}
230+
231+
/**
232+
* Adds a timestamp dependency warning for the specified key. If no warnings are
233+
* associated with the key, a new set is created and the warning is added to
234+
* it. This method is thread-safe.
235+
*
236+
* @param key the key identifying the smart contract or entity for which
237+
* the warning applies
238+
* @param warning the warning object to be added
239+
*/
240+
public void addTimestampDependencyWarning(Integer key, Object warning) {
241+
synchronized (_timestampDependencyWarnings) {
242+
_timestampDependencyWarnings
243+
.computeIfAbsent(key, k -> Collections.synchronizedSet(new HashSet<>()))
244+
.add(warning);
245+
}
246+
}
247+
248+
/**
249+
* Retrieves the number of timestamp dependency warnings associated with the specified
250+
* key. If no warnings are associated with the key, the method returns 0.
251+
* This method is thread-safe.
252+
*
253+
* @param key the key identifying the smart contract or entity whose
254+
* warnings are to be retrieved
255+
*
256+
* @return the number of warnings associated with the key, or 0 if none
257+
* exist
258+
*/
259+
public int getTimestampDependencyWarnings(Integer key) {
260+
synchronized (_timestampDependencyWarnings) {
261+
return (_timestampDependencyWarnings.get(key) != null) ? _timestampDependencyWarnings.get(key).size() : 0;
262+
}
263+
}
228264
}

0 commit comments

Comments
 (0)