Skip to content

Commit 81e6621

Browse files
committed
feat: improved FastBridgeReceiver events, expanded the integration tests, found some testing issues
Also disabled gas reporter by default.
1 parent 54119fa commit 81e6621

File tree

6 files changed

+122
-66
lines changed

6 files changed

+122
-66
lines changed

contracts/hardhat.config.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,15 @@ const config: HardhatUserConfig = {
141141
relayer: {
142142
default: 1,
143143
},
144+
bridger: {
145+
default: 2,
146+
},
147+
challenger: {
148+
default: 3,
149+
},
144150
},
145151
gasReporter: {
146-
enabled: process.env.REPORT_GAS !== undefined,
152+
enabled: process.env.REPORT_GAS !== undefined ? process.env.REPORT_GAS === "true" : false,
147153
currency: "USD",
148154
},
149155
verify: {
@@ -166,7 +172,7 @@ const config: HardhatUserConfig = {
166172
},
167173
},
168174
docgen: {
169-
path: './docs',
175+
path: "./docs",
170176
clear: true,
171177
runOnCompile: false,
172178
},

contracts/src/bridge/FastBridgeReceiverOnEthereum.sol

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,6 @@ contract FastBridgeReceiverOnEthereum is IFastBridgeReceiver, ISafeBridgeReceive
164164
claim.honest = true;
165165
fastInbox[_epoch] = claim.batchMerkleRoot;
166166
emit BatchVerified(_epoch);
167-
} else {
168-
// unhappy path
169-
emit BatchNotVerified(_epoch);
170167
}
171168
claim.verificationAttempted = true;
172169
}
@@ -194,6 +191,7 @@ contract FastBridgeReceiverOnEthereum is IFastBridgeReceiver, ISafeBridgeReceive
194191
challenges[_epoch].honest = true;
195192
}
196193
}
194+
emit BatchSafeVerified(_epoch, claims[_epoch].honest, challenges[_epoch].honest);
197195
}
198196

199197
/**
@@ -223,7 +221,7 @@ contract FastBridgeReceiverOnEthereum is IFastBridgeReceiver, ISafeBridgeReceive
223221
Claim storage claim = claims[_epoch];
224222

225223
require(claim.bridger != address(0), "Claim does not exist");
226-
require(claim.honest == true, "Claim not verified.");
224+
require(claim.honest == true, "Claim failed.");
227225
require(claim.depositAndRewardWithdrawn == false, "Claim deposit and any rewards already withdrawn.");
228226

229227
uint256 amount = deposit;
@@ -232,6 +230,7 @@ contract FastBridgeReceiverOnEthereum is IFastBridgeReceiver, ISafeBridgeReceive
232230
}
233231

234232
claim.depositAndRewardWithdrawn = true;
233+
emit ClaimDepositWithdrawn(_epoch, claim.bridger);
235234

236235
payable(claim.bridger).send(amount); // Use of send to prevent reverting fallback. User is responsibility for accepting ETH.
237236
// Checks-Effects-Interaction
@@ -245,7 +244,7 @@ contract FastBridgeReceiverOnEthereum is IFastBridgeReceiver, ISafeBridgeReceive
245244
Challenge storage challenge = challenges[_epoch];
246245

247246
require(challenge.challenger != address(0), "Challenge does not exist");
248-
require(challenge.honest == true, "Challenge not verified.");
247+
require(challenge.honest == true, "Challenge failed.");
249248
require(challenge.depositAndRewardWithdrawn == false, "Challenge deposit and rewards already withdrawn.");
250249

251250
uint256 amount = deposit;
@@ -254,6 +253,7 @@ contract FastBridgeReceiverOnEthereum is IFastBridgeReceiver, ISafeBridgeReceive
254253
}
255254

256255
challenge.depositAndRewardWithdrawn = true;
256+
emit ChallengeDepositWithdrawn(_epoch, challenge.challenger);
257257

258258
payable(challenge.challenger).send(amount); // Use of send to prevent reverting fallback. User is responsibility for accepting ETH.
259259
// Checks-Effects-Interaction
@@ -337,6 +337,7 @@ contract FastBridgeReceiverOnEthereum is IFastBridgeReceiver, ISafeBridgeReceive
337337
bytes32 replay = relayed[_epoch][index];
338338
require(((replay >> offset) & bytes32(uint256(1))) == 0, "Message already relayed");
339339
relayed[_epoch][index] = replay | bytes32(1 << offset);
340+
emit MessageRelayed(_epoch, nonce);
340341

341342
(success, ) = receiver.call(data);
342343
// Checks-Effects-Interaction

contracts/src/bridge/FastBridgeReceiverOnGnosis.sol

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,6 @@ contract FastBridgeReceiverOnGnosis is IFastBridgeReceiver, ISafeBridgeReceiver
162162
claim.honest = true;
163163
fastInbox[_epoch] = claim.batchMerkleRoot;
164164
emit BatchVerified(_epoch);
165-
} else {
166-
// unhappy path
167-
emit BatchNotVerified(_epoch);
168165
}
169166
claim.verificationAttempted = true;
170167
}
@@ -192,6 +189,7 @@ contract FastBridgeReceiverOnGnosis is IFastBridgeReceiver, ISafeBridgeReceiver
192189
challenges[_epoch].honest = true;
193190
}
194191
}
192+
emit BatchSafeVerified(_epoch, claims[_epoch].honest, challenges[_epoch].honest);
195193
}
196194

197195
/**
@@ -230,6 +228,7 @@ contract FastBridgeReceiverOnGnosis is IFastBridgeReceiver, ISafeBridgeReceiver
230228
}
231229

232230
claim.depositAndRewardWithdrawn = true;
231+
emit ClaimDepositWithdrawn(_epoch, claim.bridger);
233232

234233
payable(claim.bridger).send(amount); // Use of send to prevent reverting fallback. User is responsibility for accepting ETH.
235234
// Checks-Effects-Interaction
@@ -252,6 +251,7 @@ contract FastBridgeReceiverOnGnosis is IFastBridgeReceiver, ISafeBridgeReceiver
252251
}
253252

254253
challenge.depositAndRewardWithdrawn = true;
254+
emit ChallengeDepositWithdrawn(_epoch, challenge.challenger);
255255

256256
payable(challenge.challenger).send(amount); // Use of send to prevent reverting fallback. User is responsibility for accepting ETH.
257257
// Checks-Effects-Interaction
@@ -335,6 +335,7 @@ contract FastBridgeReceiverOnGnosis is IFastBridgeReceiver, ISafeBridgeReceiver
335335
bytes32 replay = relayed[_epoch][index];
336336
require(((replay >> offset) & bytes32(uint256(1))) == 0, "Message already relayed");
337337
relayed[_epoch][index] = replay | bytes32(1 << offset);
338+
emit MessageRelayed(_epoch, nonce);
338339

339340
(success, ) = receiver.call(data);
340341
// Checks-Effects-Interaction

contracts/src/bridge/FastBridgeReceiverOnPolygon.sol

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,6 @@ contract FastBridgeReceiverOnPolygon is FxBaseChildTunnel, IFastBridgeReceiver,
156156
claim.honest = true;
157157
fastInbox[_epoch] = claim.batchMerkleRoot;
158158
emit BatchVerified(_epoch);
159-
} else {
160-
// unhappy path
161-
emit BatchNotVerified(_epoch);
162159
}
163160
claim.verificationAttempted = true;
164161
}
@@ -234,6 +231,7 @@ contract FastBridgeReceiverOnPolygon is FxBaseChildTunnel, IFastBridgeReceiver,
234231
}
235232

236233
claim.depositAndRewardWithdrawn = true;
234+
emit ClaimDepositWithdrawn(_epoch, claim.bridger);
237235

238236
payable(claim.bridger).send(amount); // Use of send to prevent reverting fallback. User is responsibility for accepting ETH.
239237
// Checks-Effects-Interaction
@@ -256,6 +254,7 @@ contract FastBridgeReceiverOnPolygon is FxBaseChildTunnel, IFastBridgeReceiver,
256254
}
257255

258256
challenge.depositAndRewardWithdrawn = true;
257+
emit ChallengeDepositWithdrawn(_epoch, challenge.challenger);
259258

260259
payable(challenge.challenger).send(amount); // Use of send to prevent reverting fallback. User is responsibility for accepting ETH.
261260
// Checks-Effects-Interaction
@@ -339,6 +338,7 @@ contract FastBridgeReceiverOnPolygon is FxBaseChildTunnel, IFastBridgeReceiver,
339338
bytes32 replay = relayed[_epoch][index];
340339
require(((replay >> offset) & bytes32(uint256(1))) == 0, "Message already relayed");
341340
relayed[_epoch][index] = replay | bytes32(1 << offset);
341+
emit MessageRelayed(_epoch, nonce);
342342

343343
(success, ) = receiver.call(data);
344344
// Checks-Effects-Interaction

contracts/src/bridge/interfaces/IFastBridgeReceiver.sol

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,45 @@ interface IFastBridgeReceiver {
2323
event ClaimReceived(uint256 indexed _epoch, bytes32 indexed _batchMerkleRoot);
2424

2525
/**
26-
* @dev The Fast Bridge participants watch for these events to call `sendSafeFallback()` on the sending side.
26+
* @dev This event indicates that `sendSafeFallback()` should be called on the sending side.
2727
* @param _epoch The epoch associated with the challenged claim.
2828
*/
2929
event ClaimChallenged(uint256 indexed _epoch);
3030

3131
/**
32-
* @dev The Fast Bridge participants watch for these events to know optimistic verification has succeeded. The messages are ready to be relayed.
32+
* @dev This events indicates that optimistic verification has succeeded. The messages are ready to be relayed.
3333
* @param _epoch The epoch associated with the batch.
3434
*/
3535
event BatchVerified(uint256 indexed _epoch);
3636

3737
/**
38-
* @dev The Fast Bridge users watch for these events to know that optimistic verification has failed. The Fast Bridge sender will fallback to the Safe Bridge.
38+
* @dev This event indicates that the batch has been received via the Safe Bridge.
3939
* @param _epoch The epoch associated with the batch.
40+
* @param _isBridgerHonest Whether the bridger made an honest claim.
41+
* @param _isChallengerHonest Whether the bridger made an honest challenge.
4042
*/
41-
event BatchNotVerified(uint256 indexed _epoch);
43+
event BatchSafeVerified(uint256 indexed _epoch, bool _isBridgerHonest, bool _isChallengerHonest);
44+
45+
/**
46+
* @dev This event indicates that the claim deposit has been withdrawn.
47+
* @param _epoch The epoch associated with the batch.
48+
* @param _bridger The recipient of the claim deposit.
49+
*/
50+
event ClaimDepositWithdrawn(uint256 indexed _epoch, address indexed _bridger);
51+
52+
/**
53+
* @dev This event indicates that the challenge deposit has been withdrawn.
54+
* @param _epoch The epoch associated with the batch.
55+
* @param _challenger The recipient of the challenge deposit.
56+
*/
57+
event ChallengeDepositWithdrawn(uint256 indexed _epoch, address indexed _challenger);
58+
59+
/**
60+
* @dev This event indicates that a message has been relayed for the batch in this `_epoch`.
61+
* @param _epoch The epoch associated with the batch.
62+
* @param _nonce The nonce of the message that was relayed.
63+
*/
64+
event MessageRelayed(uint256 indexed _epoch, uint256 indexed _nonce);
4265

4366
// ************************************* //
4467
// * Function Modifiers * //

0 commit comments

Comments
 (0)