Skip to content

Commit 1cd7d05

Browse files
First look at TimestampDependencyChecker
1 parent 75a20d7 commit 1cd7d05

File tree

2 files changed

+46
-3
lines changed

2 files changed

+46
-3
lines changed

src/main/java/it/unipr/cfg/EVMCFG.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public class EVMCFG extends CFG {
4141
public Set<Statement> jumpNodes;
4242
public Set<Statement> pushedJumps;
4343
public Set<Statement> sstores;
44+
public Set<Statement> sha3s;
4445

4546
public EVMCFG(CodeMemberDescriptor descriptor, Collection<Statement> entrypoints,
4647
NodeList<CFG, Statement, Edge> list) {
@@ -54,7 +55,7 @@ public EVMCFG(CodeMemberDescriptor cfgDesc) {
5455
/**
5556
* Returns a set of all the SSTORE statements in the CFG. SSTORE
5657
*
57-
* @return a set of all the JUMPDEST statements in the CFG
58+
* @return a set of all the SSTORE statements in the CFG
5859
*/
5960
public Set<Statement> getAllSstore() {
6061
if (sstores == null) {
@@ -72,6 +73,28 @@ public Set<Statement> getAllSstore() {
7273

7374
return sstores;
7475
}
76+
77+
/**
78+
* Returns a set of all the SHA3 statements in the CFG. SHA3
79+
*
80+
* @return a set of all the SHA3 statements in the CFG
81+
*/
82+
public Set<Statement> getAllSha3() {
83+
if (sha3s == null) {
84+
NodeList<CFG, Statement, Edge> cfgNodeList = this.getNodeList();
85+
Set<Statement> sha3s = new HashSet<>();
86+
87+
for (Statement statement : cfgNodeList.getNodes()) {
88+
if (statement instanceof Sha3) {
89+
sha3s.add(statement);
90+
}
91+
}
92+
93+
return this.sha3s = sha3s;
94+
}
95+
96+
return sha3s;
97+
}
7598

7699
/**
77100
* Returns a set of all the JUMPDEST statements in the CFG.
@@ -321,5 +344,4 @@ private boolean dfsSequential(Statement start, Statement target, Set<Statement>
321344

322345
return false;
323346
}
324-
325347
}

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

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

3+
import java.util.Set;
4+
35
import it.unipr.analysis.taint.TaintAbstractDomain;
6+
import it.unipr.cfg.Balance;
7+
import it.unipr.cfg.Blockhash;
8+
import it.unipr.cfg.Difficulty;
9+
import it.unipr.cfg.EVMCFG;
10+
import it.unipr.cfg.Timestamp;
411
import it.unive.lisa.analysis.SimpleAbstractState;
512
import it.unive.lisa.analysis.heap.MonolithicHeap;
613
import it.unive.lisa.analysis.nonrelational.value.TypeEnvironment;
@@ -26,7 +33,21 @@ public boolean visit(
2633
CheckToolWithAnalysisResults<
2734
SimpleAbstractState<MonolithicHeap, TaintAbstractDomain, TypeEnvironment<InferredTypes>>> tool,
2835
CFG graph, Statement node) {
29-
// TODO Auto-generated method stub
36+
37+
if (node instanceof Timestamp || node instanceof Blockhash || node instanceof Difficulty || node instanceof Balance) {
38+
EVMCFG cfg = ((EVMCFG) graph);
39+
Set<Statement> nsh = cfg.getAllSha3();
40+
Set<Statement> ns = cfg.getAllSstore();
41+
// The function cfg.getAllJumps() returns all jumps, whether being jump or jumpi
42+
// if you want to separete the jumps, a different function need to be done
43+
Set<Statement> nj = cfg.getAllJumps();
44+
45+
46+
}
47+
48+
49+
50+
3051
return SemanticCheck.super.visit(tool, graph, node);
3152
}
3253

0 commit comments

Comments
 (0)