@@ -35,18 +35,53 @@ public class Bridge implements Iterable<SmartContract> {
3535 /** Detected vulnerabilities in the bridge. */
3636 private VulnerabilitiesObject _vulnerabilities ;
3737
38+ /**
39+ * Creates a new Bridge instance with only a name.
40+ *
41+ * @param name the name of the bridge
42+ */
3843 public Bridge (String name ) {
3944 this (null , null , null , name );
4045 }
4146
47+ /**
48+ * Creates a new Bridge instance with bytecode and ABI directories, and
49+ * policy path. The bridge name will be auto-generated with a timestamp.
50+ *
51+ * @param bytecodeDirectoryPath path to the directory containing bytecode
52+ * files
53+ * @param abiDirectoryPath path to the directory containing ABI files
54+ * @param policyPath path to the policy JSON file
55+ */
4256 public Bridge (Path bytecodeDirectoryPath , Path abiDirectoryPath , Path policyPath ) {
4357 this (bytecodeDirectoryPath , abiDirectoryPath , policyPath , "unknown_bridge_" + System .currentTimeMillis ());
4458 }
4559
60+ /**
61+ * Creates a new Bridge instance with bytecode and ABI directories. No
62+ * policy will be loaded and the bridge name will be auto-generated.
63+ *
64+ * @param bytecodeDirectoryPath path to the directory containing bytecode
65+ * files
66+ * @param abiDirectoryPath path to the directory containing ABI files
67+ */
4668 public Bridge (Path bytecodeDirectoryPath , Path abiDirectoryPath ) {
4769 this (bytecodeDirectoryPath , abiDirectoryPath , null , "unknown_bridge_" + System .currentTimeMillis ());
4870 }
4971
72+ /**
73+ * Creates a new Bridge instance with all specified parameters. This is the
74+ * main constructor that initializes the bridge with smart contracts from
75+ * the provided bytecode and ABI directories, loads the policy if specified,
76+ * and assigns the given name.
77+ *
78+ * @param bytecodeDirectoryPath path to the directory containing bytecode
79+ * files
80+ * @param abiDirectoryPath path to the directory containing ABI files
81+ * @param policyPath path to the policy JSON file, or null if no
82+ * policy should be loaded
83+ * @param name the name to assign to this bridge
84+ */
5085 public Bridge (Path bytecodeDirectoryPath , Path abiDirectoryPath , Path policyPath , String name ) {
5186 this .name = name ;
5287 this .contracts = new ArrayList <>();
@@ -71,50 +106,99 @@ public Bridge(Path bytecodeDirectoryPath, Path abiDirectoryPath, Path policyPath
71106
72107 }
73108
109+ /**
110+ * Gets the name of the bridge.
111+ *
112+ * @return the name of the bridge
113+ */
74114 public String getName () {
75115 return name ;
76116 }
77117
118+ /**
119+ * Gets the list of smart contracts in this bridge.
120+ *
121+ * @return a list of SmartContract objects
122+ */
78123 public List <SmartContract > getSmartContracts () {
79124 return contracts ;
80125 }
81126
127+ /**
128+ * Gets all function signatures from all contracts in this bridge.
129+ *
130+ * @return a list of function signatures
131+ */
82132 public List <Signature > getFunctions () {
83133 List <Signature > functions = new ArrayList <>();
84134 for (SmartContract contract : contracts )
85135 functions .addAll (contract .getFunctionsSignature ());
86136 return functions ;
87137 }
88138
139+ /**
140+ * Gets all event signatures from all contracts in this bridge.
141+ *
142+ * @return a list of event signatures
143+ */
89144 public List <Signature > getEvents () {
90145 List <Signature > events = new ArrayList <>();
91146 for (SmartContract contract : contracts )
92147 events .addAll (contract .getEventsSignature ());
93148 return events ;
94149 }
95150
151+ /**
152+ * Gets the cross-chain control flow graph (xCFG) of this bridge.
153+ *
154+ * @return the EVMCFG representing the cross-chain control flow graph
155+ */
96156 public EVMCFG getXCFG () {
97157 return xCFG ;
98158 }
99159
160+ /**
161+ * Gets the cross-chain policy containing event-function pairs.
162+ *
163+ * @return a list of event-function pairs
164+ */
100165 public List <Pair <String , String >> getPolicy () {
101166 return policy ;
102167 }
103168
169+ /**
170+ * Checks if an event has an associated function in the policy.
171+ *
172+ * @param event the name of the event to check
173+ *
174+ * @return true if the event has an associated function, false otherwise
175+ */
104176 public boolean hasEventFunctionMapping (String event ) {
105177 for (Pair <String , String > pair : policy )
106178 if (pair .getLeft ().equals (event ))
107179 return true ;
108180 return false ;
109181 }
110182
183+ /**
184+ * Gets the function name associated with an event from the policy.
185+ *
186+ * @param event the name of the event
187+ *
188+ * @return the associated function name, or null if not found
189+ */
111190 public String getFunctionForEvent (String event ) {
112191 for (Pair <String , String > pair : policy )
113192 if (pair .getLeft ().equals (event ))
114193 return pair .getRight ();
115194 return null ;
116195 }
117196
197+ /**
198+ * Adds multiple cross-chain edges to the xCFG.
199+ *
200+ * @param edges a set of edges to be added
201+ */
118202 public void addEdges (Set <Edge > edges ) {
119203 for (Edge edge : edges )
120204 addEdge (edge );
@@ -141,6 +225,11 @@ public Bridge setVulnerabilities(VulnerabilitiesObject vulnerabilities) {
141225 return this ;
142226 }
143227
228+ /**
229+ * Adds a single cross-chain edge to the xCFG.
230+ *
231+ * @param edge the edge to be added
232+ */
144233 public void addEdge (Edge edge ) {
145234 xCFG .addEdge (edge );
146235 }
@@ -176,6 +265,13 @@ public EVMCFG buildPartialXCFG() {
176265 return xCFG ;
177266 }
178267
268+ /**
269+ * Loads the cross-chain policy from a JSON file and populates the policy
270+ * list. The JSON file should contain an array named "policy" with
271+ * event-function pairs.
272+ *
273+ * @param policyPath the path to the policy JSON file
274+ */
179275 private void loadPolicy (Path policyPath ) {
180276 try {
181277 log .info ("Loading policy from: {}" , policyPath );
@@ -286,6 +382,11 @@ public String toString() {
286382 return toJson ().toString (4 );
287383 }
288384
385+ /**
386+ * Returns an iterator over the smart contracts in this bridge.
387+ *
388+ * @return an Iterator over SmartContract objects
389+ */
289390 @ Override
290391 public Iterator <SmartContract > iterator () {
291392 return contracts .iterator ();
0 commit comments