diff --git a/src/main/java/it/unipr/cfg/EVMCFG.java b/src/main/java/it/unipr/cfg/EVMCFG.java index c1ebbfb81..a0d088e36 100644 --- a/src/main/java/it/unipr/cfg/EVMCFG.java +++ b/src/main/java/it/unipr/cfg/EVMCFG.java @@ -289,7 +289,7 @@ private boolean dfsSequential(Statement start, Statement target, Set Collection outgoingEdges = list.getOutgoingEdges(current); for (Edge edge : outgoingEdges) { - if (edge.getSource() instanceof Jump || edge.getSource() instanceof Jumpi) + if (edge.getSource() instanceof Jumpi || edge.getSource() instanceof Jump) continue; Statement next = edge.getDestination(); if (!visited.contains(next)) diff --git a/src/main/java/it/unipr/checker/ReentrancyChecker.java b/src/main/java/it/unipr/checker/ReentrancyChecker.java index 1b4e8d2f7..a1e6c21c0 100644 --- a/src/main/java/it/unipr/checker/ReentrancyChecker.java +++ b/src/main/java/it/unipr/checker/ReentrancyChecker.java @@ -1,10 +1,13 @@ package it.unipr.checker; +import java.util.Set; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + import it.unipr.analysis.AbstractStack; import it.unipr.analysis.EVMAbstractState; -import it.unipr.analysis.MyCache; import it.unipr.analysis.StackElement; -import it.unipr.analysis.UniqueItemCollector; import it.unipr.cfg.Call; import it.unipr.cfg.EVMCFG; import it.unipr.cfg.ProgramCounterLocation; @@ -19,21 +22,16 @@ import it.unive.lisa.checks.semantic.SemanticCheck; import it.unive.lisa.program.cfg.CFG; import it.unive.lisa.program.cfg.statement.Statement; -import java.util.Set; -import org.apache.commons.lang3.tuple.ImmutablePair; -import org.apache.commons.lang3.tuple.Pair; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; public class ReentrancyChecker implements - SemanticCheck>> { +SemanticCheck>> { private static final Logger log = LogManager.getLogger(ReentrancyChecker.class); @Override public boolean visit( CheckToolWithAnalysisResults< - SimpleAbstractState>> tool, + SimpleAbstractState>> tool, CFG graph, Statement node) { if (node instanceof Call) { @@ -44,7 +42,7 @@ public boolean visit( for (AnalyzedCFG>> result : tool.getResultOf(cfg)) { AnalysisState>> analysisResult = null; + TypeEnvironment>> analysisResult = null; try { analysisResult = result.getAnalysisStateBefore(call); @@ -84,59 +82,23 @@ private void checkForReentrancy(Call call, Statement sstore, CheckToolWithAnalys SimpleAbstractState>> tool, Set ns, EVMCFG cfg) { - Pair myPair = new ImmutablePair<>(call, sstore); - ProgramCounterLocation sstoreLoc = (ProgramCounterLocation) sstore.getLocation(); - if (MyCache.getInstance().existsStmtReachableFrom(myPair)) { - if (MyCache.getInstance().isStmtReachableFrom(myPair)) { - - for (Statement otherSstore : ns) - if (!otherSstore.equals(sstore)) - if (otherSstore.getLocation().compareTo(sstoreLoc) > 0 - && cfg.reachableFromSequentially(sstore, otherSstore)) - sstoreLoc = (ProgramCounterLocation) otherSstore.getLocation(); - - log.debug("Reentrancy attack at " - + sstoreLoc.getPc() + "at line no. " - + sstoreLoc.getSourceCodeLine() - + "coming from line " - + ((ProgramCounterLocation) call.getLocation()).getSourceCodeLine()); - String warn = "Reentrancy attack at " - + sstoreLoc.getPc(); - tool.warn(warn); - UniqueItemCollector.getInstance().add(warn); // TODO - // to - // optimize, - // temp - // solution - } - } else { - if (cfg.reachableFrom(call, sstore)) { - - for (Statement otherSstore : ns) - if (!otherSstore.equals(sstore)) - if (otherSstore.compareTo(sstore) > 0 && cfg.reachableFromSequentially(sstore, otherSstore)) - sstoreLoc = (ProgramCounterLocation) otherSstore.getLocation(); - - MyCache.getInstance().setStmtReachableFrom(myPair, true); - log.debug("Reentrancy attack at " - + sstoreLoc.getPc() + "at line no. " - + sstoreLoc.getSourceCodeLine() - + "coming from line " - + ((ProgramCounterLocation) call.getLocation()).getSourceCodeLine()); - String warn = "Reentrancy attack at " - + sstoreLoc.getPc(); - tool.warn(warn); - UniqueItemCollector.getInstance().add(warn); // TODO - // to - // optimize, - // temp - // solution - - } else { - MyCache.getInstance().setStmtReachableFrom(myPair, false); - } + + if (cfg.reachableFrom(call, sstore)) { + for (Statement otherSstore : ns) + if (!otherSstore.equals(sstore)) + if (cfg.reachableFromSequentially(sstore, otherSstore)) + sstoreLoc = (ProgramCounterLocation) otherSstore.getLocation(); + + log.debug("Reentrancy attack at " + + sstoreLoc.getPc() + "at line no. " + + sstoreLoc.getSourceCodeLine() + + "coming from line " + + ((ProgramCounterLocation) call.getLocation()).getSourceCodeLine()); + String warn = "Reentrancy attack at " + + sstoreLoc.getPc(); + tool.warn(warn); + } } - } \ No newline at end of file