Skip to content

Commit 7538013

Browse files
Apply spotless
1 parent c10a786 commit 7538013

File tree

12 files changed

+94
-83
lines changed

12 files changed

+94
-83
lines changed

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

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -150,29 +150,31 @@ public static void enableTxOriginChecker() {
150150
public static void setTestMode() {
151151
TEST_MODE = true;
152152
}
153-
153+
154154
public static boolean isInTestMode() {
155155
return TEST_MODE;
156156
}
157-
157+
158158
public static boolean isInPaperMode() {
159159
return PAPER_MODE;
160160
}
161161

162162
/**
163-
* Enables the paper mode (i.e., statistics contains jump classifications as in the reference paper).
163+
* Enables the paper mode (i.e., statistics contains jump classifications as
164+
* in the reference paper).
164165
*/
165166
public static void setPaperMode() {
166167
PAPER_MODE = true;
167168
}
168169

169170
/**
170-
* Disables the paper mode (i.e., statistics contains jump classifications as in the reference paper).
171+
* Disables the paper mode (i.e., statistics contains jump classifications
172+
* as in the reference paper).
171173
*/
172174
public static void disablePaperMode() {
173175
PAPER_MODE = false;
174176
}
175-
177+
176178
/**
177179
* Executes the analysis workflow.
178180
*
@@ -250,7 +252,7 @@ public static void analyzeSetOfContracts(Path filePath) {
250252
* Analyzes a set of smart contracts from a given file.
251253
*
252254
* @param filePath the path to the file containing contract addresses
253-
* @param shutdown whether to shut down the executor after the analysis
255+
* @param shutdown whether to shut down the executor after the analysis
254256
*/
255257
public static void analyzeSetOfContracts(Path filePath, boolean shutdown) {
256258
log.info("Building contracts.");
@@ -611,7 +613,8 @@ private static StatisticsObject<?> computeJumps(JumpSolver checker, Set<Statemen
611613
}
612614

613615
/**
614-
* Computes jump-related statistics based on the analysis results, with the same classification of the reference paper.
616+
* Computes jump-related statistics based on the analysis results, with the
617+
* same classification of the reference paper.
615618
*
616619
* @param checker the jump solver used for analysis
617620
* @param soundlySolved the set of jumps that have been soundly solved
@@ -624,11 +627,10 @@ private static StatisticsObject<?> computePaperJumps(JumpSolver checker, Set<Sta
624627

625628
int resolved = 0;
626629
int unreachable = 0;
627-
int erroneous = 0;
628-
int unknown = 0;
630+
int erroneous = 0;
631+
int unknown = 0;
629632
int topState = 0;
630633

631-
632634
if (cfg.getEntrypoints().stream().findAny().isEmpty()) {
633635
log.warn("There are no entrypoints.");
634636
return null;
@@ -637,36 +639,41 @@ private static StatisticsObject<?> computePaperJumps(JumpSolver checker, Set<Sta
637639
Statement entryPoint = cfg.getEntrypoints().stream().findAny().get();
638640

639641
// we are safe supposing that we have a single entry point
640-
for (Statement jumpNode : cfg.getAllJumps())
641-
if ((jumpNode instanceof Jump) || (jumpNode instanceof Jumpi))
642+
for (Statement jumpNode : cfg.getAllJumps())
643+
if ((jumpNode instanceof Jump) || (jumpNode instanceof Jumpi))
642644
if (cfg.getAllPushedJumps().contains(jumpNode))
643645
// stacks of pushed jumps are not stored for optimization
644646
resolved++;
645647
else if (soundlySolved.contains(jumpNode))
646-
// soundlySolved contains getMaybeUnsoundJumps() (whole value state went to top)
647-
// and getUnsoundJumps() (at least one stack has top on front)
648+
// soundlySolved contains getMaybeUnsoundJumps() (whole
649+
// value state went to top)
650+
// and getUnsoundJumps() (at least one stack has top on
651+
// front)
648652
unknown++;
649653
else if (checker.getUnsoundJumps().contains(jumpNode))
650-
// getUnsoundJumps() contains jumps where at least one top stack is top
654+
// getUnsoundJumps() contains jumps where at least one top
655+
// stack is top
651656
unknown++;
652657
else if (checker.getMaybeUnsoundJumps().contains(jumpNode)) {
653-
// getMaybeUnsoundJumps() contains jumps where the whole value state went to top
658+
// getMaybeUnsoundJumps() contains jumps where the whole
659+
// value state went to top
654660
unknown++;
655661
topState++;
656-
} else if (!cfg.reachableFrom(entryPoint, jumpNode) || checker.getUnreachableJumps().contains(jumpNode))
657-
// getUnreachableJumps() contains jumps where the whole value state went to bottom
662+
} else if (!cfg.reachableFrom(entryPoint, jumpNode) || checker.getUnreachableJumps().contains(jumpNode))
663+
// getUnreachableJumps() contains jumps where the whole
664+
// value state went to bottom
658665
unreachable++;
659666
else {
660667
Set<StackElement> topStacks = checker.getTopStackValuesPerJump(jumpNode);
661-
if (topStacks.isEmpty())
668+
if (topStacks.isEmpty())
662669
unreachable++;
663-
else if (topStacks.stream().allMatch(StackElement::isBottom))
670+
else if (topStacks.stream().allMatch(StackElement::isBottom))
664671
erroneous++;
665672
else if (topStacks.stream().anyMatch(StackElement::isTop))
666673
unknown++;
667-
else
674+
else
668675
resolved++;
669-
}
676+
}
670677

671678
PaperStatisticsObject stats = PaperStatisticsObject.newStatisticsObject()
672679
.totalOpcodes(cfg.getOpcodeCount())

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
import java.util.Arrays;
1616
import java.util.function.Predicate;
1717

18-
public class AbstractStack implements ValueDomain<AbstractStack>, BaseLattice<AbstractStack>, Comparable<AbstractStack> {
18+
public class AbstractStack
19+
implements ValueDomain<AbstractStack>, BaseLattice<AbstractStack>, Comparable<AbstractStack> {
1920

2021
/**
2122
* The stack height.

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

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

3+
import it.unive.lisa.analysis.SemanticException;
4+
import it.unive.lisa.analysis.lattices.SetLattice;
35
import java.util.Collections;
46
import java.util.Set;
57
import java.util.TreeSet;
68

7-
import it.unive.lisa.analysis.SemanticException;
8-
import it.unive.lisa.analysis.lattices.SetLattice;
9-
109
public class AbstractStackSet extends SetLattice<AbstractStackSet, AbstractStack> {
1110

1211
/**

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

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

3-
import java.io.IOException;
4-
import java.math.BigInteger;
5-
import java.util.HashSet;
6-
import java.util.Objects;
7-
import java.util.Set;
8-
import java.util.TreeSet;
9-
import java.util.function.Predicate;
10-
11-
import org.apache.commons.lang3.tuple.Pair;
12-
import org.apache.logging.log4j.LogManager;
13-
import org.apache.logging.log4j.Logger;
14-
import org.bouncycastle.jcajce.provider.digest.Keccak;
15-
import org.bouncycastle.jcajce.provider.digest.Keccak.Digest256;
16-
173
import it.unipr.cfg.EVMCFG;
184
import it.unipr.cfg.ProgramCounterLocation;
195
import it.unipr.frontend.EVMFrontend;
@@ -37,6 +23,18 @@
3723
import it.unive.lisa.symbolic.value.operator.unary.UnaryOperator;
3824
import it.unive.lisa.util.representation.StringRepresentation;
3925
import it.unive.lisa.util.representation.StructuredRepresentation;
26+
import java.io.IOException;
27+
import java.math.BigInteger;
28+
import java.util.HashSet;
29+
import java.util.Objects;
30+
import java.util.Set;
31+
import java.util.TreeSet;
32+
import java.util.function.Predicate;
33+
import org.apache.commons.lang3.tuple.Pair;
34+
import org.apache.logging.log4j.LogManager;
35+
import org.apache.logging.log4j.Logger;
36+
import org.bouncycastle.jcajce.provider.digest.Keccak;
37+
import org.bouncycastle.jcajce.provider.digest.Keccak.Digest256;
4038

4139
public class EVMAbstractState
4240
implements ValueDomain<EVMAbstractState>, BaseLattice<EVMAbstractState> {

src/main/java/it/unipr/analysis/contract/SmartContract.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -815,7 +815,7 @@ public JSONObject toJson() {
815815
BasicBlock.basicBlocksToLongArray(_basicBlocks)) : new JSONArray());
816816

817817
jsonObject.put("last_pc", this._cfg.getLastOpcodePc());
818-
818+
819819
jsonObject.put("execution_time", _executionTime);
820820

821821
return jsonObject;

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,10 @@ public Set<Statement> getExternalData() {
116116
}
117117

118118
/**
119-
* Yields the program counter of the last opcode in the CFG.
120-
* This method iterates over all basic blocks and their statements to find
121-
* the highest program counter value, which corresponds to the last instruction
122-
* in the bytecode.
119+
* Yields the program counter of the last opcode in the CFG. This method
120+
* iterates over all basic blocks and their statements to find the highest
121+
* program counter value, which corresponds to the last instruction in the
122+
* bytecode.
123123
*
124124
* @return the maximum program counter found among all statements
125125
*/
@@ -129,9 +129,9 @@ public int getLastOpcodePc() {
129129
for (BasicBlock bb : bbs) {
130130
int max = 0;
131131
for (Statement st : bb.getStatements())
132-
if (((ProgramCounterLocation) st.getLocation()).getPc() > max)
132+
if (((ProgramCounterLocation) st.getLocation()).getPc() > max)
133133
max = ((ProgramCounterLocation) st.getLocation()).getPc();
134-
if (max > maxPc)
134+
if (max > maxPc)
135135
maxPc = max;
136136
}
137137

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ public EVMCFG getComputedCFG() {
7878
/**
7979
* Yields the jumps where the whole value state is bottom (i.e., the jump is
8080
* unreachable).
81+
*
8182
* @return the set of unreachable jumps
8283
*/
8384
public Set<Statement> getUnreachableJumps() {
@@ -87,15 +88,17 @@ public Set<Statement> getUnreachableJumps() {
8788
/**
8889
* Yields the jumps where the whole value state is top (i.e., the jump is
8990
* maybe unsound).
91+
*
9092
* @return the set of maybe unsound jumps
9193
*/
9294
public Set<Statement> getMaybeUnsoundJumps() {
9395
return maybeUnsoundJumps;
9496
}
9597

9698
/**
97-
* Yields the jumps where at least one of the top stack values is top (i.e., the jump is
98-
* unsound).
99+
* Yields the jumps where at least one of the top stack values is top (i.e.,
100+
* the jump is unsound).
101+
*
99102
* @return the set of unsound jumps
100103
*/
101104
public Set<Statement> getUnsoundJumps() {
@@ -104,7 +107,8 @@ public Set<Statement> getUnsoundJumps() {
104107

105108
/**
106109
* The set of top stack values per jump. This only exists for jumps that are
107-
* not in {@link #getMaybeUnsoundJumps()} and {@link #getUnreachableJumps()}.
110+
* not in {@link #getMaybeUnsoundJumps()} and
111+
* {@link #getUnreachableJumps()}.
108112
*/
109113
public Set<StackElement> getTopStackValuesPerJump(Statement node) {
110114
return topStackValuesPerJump.get(node);

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,15 @@ public static Set<StatisticsObject<?>> readStatsFromJSON(Path filePath) {
6969

7070
if (EVMLiSA.isInPaperMode())
7171
groundTruthData.add(PaperStatisticsObject.newStatisticsObject()
72-
.address(address)
73-
.totalOpcodes(statistics.getInt("total_opcodes"))
74-
.totalJumps(statistics.getInt("total_jumps"))
75-
.totalEdges(statistics.getInt("total_edges"))
76-
.resolved(statistics.getInt("resolved_jumps"))
77-
.unreachable(statistics.getInt("unreachable_jumps"))
78-
.unknown(statistics.getInt("unknown_jumps"))
79-
.erroneous(statistics.getInt("erroneous_jumps"))
80-
.build());
72+
.address(address)
73+
.totalOpcodes(statistics.getInt("total_opcodes"))
74+
.totalJumps(statistics.getInt("total_jumps"))
75+
.totalEdges(statistics.getInt("total_edges"))
76+
.resolved(statistics.getInt("resolved_jumps"))
77+
.unreachable(statistics.getInt("unreachable_jumps"))
78+
.unknown(statistics.getInt("unknown_jumps"))
79+
.erroneous(statistics.getInt("erroneous_jumps"))
80+
.build());
8181

8282
else
8383
groundTruthData.add(StandardStatisticsObject.newStatisticsObject()

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,19 @@ private PaperStatisticsObject() {
3333
/**
3434
* Creates a new {@code PaperStatisticsObject} with specified values.
3535
*
36-
* @param address the contract address
37-
* @param totalOpcodes the total number of opcodes
38-
* @param totalJumps the total number of jumps
39-
* @param totalEdges the total number of edges
40-
* @param resolved the number of resolved jumps
41-
* @param unreachable the number of unreachable jumps
42-
* @param erroneous the number of erroneous jumps
43-
* @param unknown the number of unknown jumps
44-
* @param topState the number of unknown jumps where the whole state was top
45-
* @param json the JSON representation of the object
36+
* @param address the contract address
37+
* @param totalOpcodes the total number of opcodes
38+
* @param totalJumps the total number of jumps
39+
* @param totalEdges the total number of edges
40+
* @param resolved the number of resolved jumps
41+
* @param unreachable the number of unreachable jumps
42+
* @param erroneous the number of erroneous jumps
43+
* @param unknown the number of unknown jumps
44+
* @param topState the number of unknown jumps where the whole state was
45+
* top
46+
* @param json the JSON representation of the object
4647
*/
47-
private PaperStatisticsObject(String address, int totalOpcodes, int totalJumps, int totalEdges,
48+
private PaperStatisticsObject(String address, int totalOpcodes, int totalJumps, int totalEdges,
4849
int resolved, int unreachable, int erroneous, int unknown, int topState, JSONObject json) {
4950
super(address, totalOpcodes, totalJumps, totalEdges, json);
5051
this.resolved = resolved;
@@ -162,7 +163,6 @@ public PaperStatisticsObject unknown(int unknown) {
162163
return this;
163164
}
164165

165-
166166
/**
167167
* Sets the number of unknown jumps where the whole state was top.
168168
*

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,14 @@ private StandardStatisticsObject() {
3838
* @param totalJumps the total number of jumps
3939
* @param totalEdges the total number of edges
4040
* @param resolvedJumps the number of resolved jumps
41-
* @param definitelyUnreachableJumps the number of definitely unreachable jumps
41+
* @param definitelyUnreachableJumps the number of definitely unreachable
42+
* jumps
4243
* @param maybeUnreachableJumps the number of maybe unreachable jumps
4344
* @param unsoundJumps the number of unsound jumps
4445
* @param maybeUnsoundJumps the number of maybe unsound jumps
4546
* @param json the JSON representation of the object
4647
*/
47-
private StandardStatisticsObject(String address, int totalOpcodes, int totalJumps, int totalEdges,
48+
private StandardStatisticsObject(String address, int totalOpcodes, int totalJumps, int totalEdges,
4849
int resolvedJumps, int definitelyUnreachableJumps,
4950
int maybeUnreachableJumps, int unsoundJumps, int maybeUnsoundJumps, JSONObject json) {
5051
super(address, totalOpcodes, totalJumps, totalEdges, json);
@@ -182,7 +183,8 @@ public StandardStatisticsObject maybeUnsoundJumps(int maybeUnsoundJumps) {
182183
*/
183184
@Override
184185
public StandardStatisticsObject build() {
185-
return new StandardStatisticsObject(address, totalOpcodes, totalJumps, totalEdges, resolvedJumps, definitelyUnreachableJumps,
186+
return new StandardStatisticsObject(address, totalOpcodes, totalJumps, totalEdges, resolvedJumps,
187+
definitelyUnreachableJumps,
186188
maybeUnreachableJumps, unsoundJumps, maybeUnsoundJumps, json);
187189
}
188190

@@ -203,7 +205,8 @@ public boolean equals(Object o) {
203205

204206
@Override
205207
public int hashCode() {
206-
return super.hashCode() ^ Objects.hash(resolvedJumps, definitelyUnreachableJumps, maybeUnreachableJumps, unsoundJumps, maybeUnsoundJumps);
208+
return super.hashCode() ^ Objects.hash(resolvedJumps, definitelyUnreachableJumps, maybeUnreachableJumps,
209+
unsoundJumps, maybeUnsoundJumps);
207210
}
208211

209212
/**

0 commit comments

Comments
 (0)