Skip to content

Commit 585c52b

Browse files
committed
Added state mutability support to Signature and updated ABIManager for new constructor
1 parent 09b7419 commit 585c52b

File tree

2 files changed

+39
-11
lines changed

2 files changed

+39
-11
lines changed

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

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public class Signature {
1717
private final List<String> _outputParamTypes;
1818
private final String _fullSignature;
1919
private final String _selector;
20+
private final String _stateMutability;
2021
private Set<Statement> _entryPoints;
2122
private Set<Statement> _exitPoints;
2223
private boolean _isProtected;
@@ -31,9 +32,10 @@ public class Signature {
3132
* @param fullSignature the full signature string
3233
* @param selector the selector (first 4 bytes of the Keccak-256
3334
* hash)
35+
* @param stateMutability the state mutability of the signature
3436
*/
3537
public Signature(String name, String type, List<String> inputParamTypes, List<String> outputParamTypes,
36-
String fullSignature, String selector) {
38+
String fullSignature, String selector, String stateMutability) {
3739
this._name = name;
3840
this._type = type;
3941
this._inputParamTypes = inputParamTypes;
@@ -43,6 +45,23 @@ public Signature(String name, String type, List<String> inputParamTypes, List<St
4345
this._entryPoints = new HashSet<>();
4446
this._exitPoints = new HashSet<>();
4547
this._isProtected = false;
48+
this._stateMutability = stateMutability;
49+
}
50+
51+
/**
52+
* Constructs a Signature with the specified properties.
53+
*
54+
* @param name the name of the function or event
55+
* @param type the type (e.g., "function", "event")
56+
* @param inputParamTypes the list of input parameter types
57+
* @param outputParamTypes the list of output parameter types
58+
* @param fullSignature the full signature string
59+
* @param selector the selector (first 4 bytes of the Keccak-256
60+
* hash)
61+
*/
62+
public Signature(String name, String type, List<String> inputParamTypes, List<String> outputParamTypes,
63+
String fullSignature, String selector) {
64+
this(name, type, inputParamTypes, outputParamTypes, fullSignature, selector, "view");
4665
}
4766

4867
/**
@@ -117,6 +136,15 @@ public Set<Statement> getEntryPoints() {
117136
return _entryPoints;
118137
}
119138

139+
/**
140+
* Gets the state mutability for this signature.
141+
*
142+
* @return the state mutability
143+
*/
144+
public String getStateMutability() {
145+
return _stateMutability;
146+
}
147+
120148
/**
121149
* Sets the entry points for this signature.
122150
*
@@ -196,12 +224,13 @@ public boolean equals(Object obj) {
196224
Objects.equals(_type, other._type) &&
197225
Objects.equals(_fullSignature, other._fullSignature) &&
198226
Objects.equals(_selector, other._selector) &&
199-
_isProtected == other._isProtected;
227+
_isProtected == other._isProtected &&
228+
Objects.equals(_stateMutability, other._stateMutability);
200229
}
201230

202231
@Override
203232
public int hashCode() {
204-
return Objects.hash(_name, _type, _fullSignature, _selector, _isProtected);
233+
return Objects.hash(_name, _type, _fullSignature, _selector, _isProtected, _stateMutability);
205234
}
206235

207236
/**
@@ -244,6 +273,8 @@ public JSONObject toJson() {
244273

245274
json.put("is_protected", _isProtected);
246275

276+
json.put("state_mutability", _stateMutability);
277+
247278
return json;
248279
}
249280

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ public static Set<Signature> parseEventsFromABI(Path abi) {
7272
}
7373

7474
private static Set<Signature> parseABI(Path abi, String type) {
75-
Set<String> stateMutabilityForbidden = Set.of("view", "pure");
7675
Set<Signature> signatures = new HashSet<>();
7776
String abiJson;
7877

@@ -88,13 +87,10 @@ private static Set<Signature> parseABI(Path abi, String type) {
8887
for (int i = 0; i < abiArray.length(); i++) {
8988
JSONObject obj = abiArray.getJSONObject(i);
9089
if (obj.has("type") && obj.getString("type").equals(type)) {
91-
92-
/* We do not need to collect global variables */
93-
if (obj.has("stateMutability")
94-
&& stateMutabilityForbidden.contains(obj.getString("stateMutability")))
95-
continue;
96-
9790
String functionName = obj.getString("name");
91+
String functionStateMutability = "view"; // default
92+
if (obj.has("stateMutability"))
93+
functionStateMutability = obj.getString("stateMutability");
9894
JSONArray inputs = obj.getJSONArray("inputs");
9995
JSONArray outputs = obj.optJSONArray("outputs");
10096

@@ -122,7 +118,8 @@ private static Set<Signature> parseABI(Path abi, String type) {
122118
String fullSignature = signatureBuilder.toString();
123119
String selector = getFunctionSelector(fullSignature);
124120

125-
signatures.add(new Signature(functionName, type, paramTypes, outputTypes, fullSignature, selector));
121+
signatures.add(new Signature(functionName, type, paramTypes, outputTypes, fullSignature, selector,
122+
functionStateMutability));
126123
}
127124
}
128125
return signatures;

0 commit comments

Comments
 (0)