Skip to content

Commit a73c7d5

Browse files
committed
Added check in getCrossChainEdges to prevent event-function links in the same contract.
1 parent 5cec316 commit a73c7d5

File tree

2 files changed

+49
-22
lines changed

2 files changed

+49
-22
lines changed

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -846,6 +846,24 @@ public boolean toFile() {
846846
return true;
847847
}
848848

849+
@Override
850+
public boolean equals(Object o) {
851+
if (o == null)
852+
return false;
853+
if (!(o instanceof SmartContract))
854+
return false;
855+
if (this == o)
856+
return true;
857+
SmartContract contract = (SmartContract) o;
858+
return _bytecode.equals(contract._bytecode)
859+
&& _cfg.equals(contract._cfg);
860+
}
861+
862+
@Override
863+
public int hashCode() {
864+
return 13 * _bytecode.hashCode() + 17 * _cfg.hashCode();
865+
}
866+
849867
/**
850868
* Extracts the filename without extension from a given Path.
851869
*

src/main/java/it/unipr/crosschain/xEVMLiSA.java

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -94,27 +94,36 @@ public static Set<Edge> getCrossChainEdgesUsingEventsAndFunctionsEntrypoint(Brid
9494
log.debug("Events in bridge: {}.", bridge.getEvents().size());
9595
log.debug("Log statement in bridge: {}.", bridge.getXCFG().getAllLogX().size());
9696

97-
for (Signature event : bridge.getEvents()) {
98-
for (Signature function : bridge.getFunctions()) {
99-
100-
if (xEVMLiSA.defaultPolicy(event, function)) {
101-
functionsUsed.add(function.getFullSignature());
102-
eventUsed.add(event.getFullSignature());
103-
104-
crossChainEdges.addAll(
105-
addCrossChainEdges(event.getExitPoints(), function.getEntryPoints()));
106-
107-
MyCache.getInstance().addMapEventsFunctions(event, function);
108-
109-
// Debug print
110-
for (Statement e : event.getExitPoints()) {
111-
for (Statement f : function.getEntryPoints()) {
112-
log.debug(
113-
"Cross-chain edge added: event {} (name: {}, selector: {}, line: {}) -> function {} (name: {}, selector: {}, line: {}).",
114-
e, event.getFullSignature(), event.getSelector(),
115-
((ProgramCounterLocation) e.getLocation()).getSourceCodeLine(),
116-
f, function.getFullSignature(), function.getSelector(),
117-
((ProgramCounterLocation) f.getLocation()).getSourceCodeLine());
97+
for (SmartContract contractSource : bridge.getSmartContracts()) {
98+
for (SmartContract contractDestination : bridge.getSmartContracts()) {
99+
if (contractSource.equals(contractDestination))
100+
continue; // Avoid auto-link
101+
102+
for (Signature event : contractSource.getEventsSignature()) {
103+
for (Signature function : contractDestination.getFunctionsSignature()) {
104+
105+
if (xEVMLiSA.defaultPolicy(event, function)) {
106+
functionsUsed.add(function.getFullSignature());
107+
eventUsed.add(event.getFullSignature());
108+
109+
crossChainEdges.addAll(
110+
addCrossChainEdges(event.getExitPoints(), function.getEntryPoints()));
111+
112+
MyCache.getInstance().addMapEventsFunctions(event, function);
113+
114+
// Debug print
115+
for (Statement e : event.getExitPoints()) {
116+
for (Statement f : function.getEntryPoints()) {
117+
log.debug(
118+
"Cross-chain edge added: from contract {} with event {} (name: {}, selector: {}, line: {}) to contract {} with function {} (name: {}, selector: {}, line: {}).",
119+
contractSource.getName(),
120+
e, event.getFullSignature(), event.getSelector(),
121+
((ProgramCounterLocation) e.getLocation()).getSourceCodeLine(),
122+
contractDestination.getName(),
123+
f, function.getFullSignature(), function.getSelector(),
124+
((ProgramCounterLocation) f.getLocation()).getSourceCodeLine());
125+
}
126+
}
118127
}
119128
}
120129
}
@@ -131,7 +140,7 @@ public static Set<Edge> getCrossChainEdgesUsingEventsAndFunctionsEntrypoint(Brid
131140
}
132141

133142
/**
134-
* Checks if the default policy is to match events and functions by name.
143+
* Matches events and functions by name.
135144
*
136145
* @param event The event signature to compare with the function's name.
137146
* @param function The function signature whose name will be compared with

0 commit comments

Comments
 (0)