Skip to content

Commit

Permalink
feat: improved FastBridgeReceiver events, expanded the integration te…
Browse files Browse the repository at this point in the history
…sts, found some testing issues

Also disabled gas reporter by default.
  • Loading branch information
jaybuidl committed Jul 16, 2022
1 parent 54119fa commit 81e6621
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 66 deletions.
10 changes: 8 additions & 2 deletions contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,15 @@ const config: HardhatUserConfig = {
relayer: {
default: 1,
},
bridger: {
default: 2,
},
challenger: {
default: 3,
},
},
gasReporter: {
enabled: process.env.REPORT_GAS !== undefined,
enabled: process.env.REPORT_GAS !== undefined ? process.env.REPORT_GAS === "true" : false,
currency: "USD",
},
verify: {
Expand All @@ -166,7 +172,7 @@ const config: HardhatUserConfig = {
},
},
docgen: {
path: './docs',
path: "./docs",
clear: true,
runOnCompile: false,
},
Expand Down
11 changes: 6 additions & 5 deletions contracts/src/bridge/FastBridgeReceiverOnEthereum.sol
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,6 @@ contract FastBridgeReceiverOnEthereum is IFastBridgeReceiver, ISafeBridgeReceive
claim.honest = true;
fastInbox[_epoch] = claim.batchMerkleRoot;
emit BatchVerified(_epoch);
} else {
// unhappy path
emit BatchNotVerified(_epoch);
}
claim.verificationAttempted = true;
}
Expand Down Expand Up @@ -194,6 +191,7 @@ contract FastBridgeReceiverOnEthereum is IFastBridgeReceiver, ISafeBridgeReceive
challenges[_epoch].honest = true;
}
}
emit BatchSafeVerified(_epoch, claims[_epoch].honest, challenges[_epoch].honest);
}

/**
Expand Down Expand Up @@ -223,7 +221,7 @@ contract FastBridgeReceiverOnEthereum is IFastBridgeReceiver, ISafeBridgeReceive
Claim storage claim = claims[_epoch];

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

uint256 amount = deposit;
Expand All @@ -232,6 +230,7 @@ contract FastBridgeReceiverOnEthereum is IFastBridgeReceiver, ISafeBridgeReceive
}

claim.depositAndRewardWithdrawn = true;
emit ClaimDepositWithdrawn(_epoch, claim.bridger);

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

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

uint256 amount = deposit;
Expand All @@ -254,6 +253,7 @@ contract FastBridgeReceiverOnEthereum is IFastBridgeReceiver, ISafeBridgeReceive
}

challenge.depositAndRewardWithdrawn = true;
emit ChallengeDepositWithdrawn(_epoch, challenge.challenger);

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

(success, ) = receiver.call(data);
// Checks-Effects-Interaction
Expand Down
7 changes: 4 additions & 3 deletions contracts/src/bridge/FastBridgeReceiverOnGnosis.sol
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,6 @@ contract FastBridgeReceiverOnGnosis is IFastBridgeReceiver, ISafeBridgeReceiver
claim.honest = true;
fastInbox[_epoch] = claim.batchMerkleRoot;
emit BatchVerified(_epoch);
} else {
// unhappy path
emit BatchNotVerified(_epoch);
}
claim.verificationAttempted = true;
}
Expand Down Expand Up @@ -192,6 +189,7 @@ contract FastBridgeReceiverOnGnosis is IFastBridgeReceiver, ISafeBridgeReceiver
challenges[_epoch].honest = true;
}
}
emit BatchSafeVerified(_epoch, claims[_epoch].honest, challenges[_epoch].honest);
}

/**
Expand Down Expand Up @@ -230,6 +228,7 @@ contract FastBridgeReceiverOnGnosis is IFastBridgeReceiver, ISafeBridgeReceiver
}

claim.depositAndRewardWithdrawn = true;
emit ClaimDepositWithdrawn(_epoch, claim.bridger);

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

challenge.depositAndRewardWithdrawn = true;
emit ChallengeDepositWithdrawn(_epoch, challenge.challenger);

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

(success, ) = receiver.call(data);
// Checks-Effects-Interaction
Expand Down
6 changes: 3 additions & 3 deletions contracts/src/bridge/FastBridgeReceiverOnPolygon.sol
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,6 @@ contract FastBridgeReceiverOnPolygon is FxBaseChildTunnel, IFastBridgeReceiver,
claim.honest = true;
fastInbox[_epoch] = claim.batchMerkleRoot;
emit BatchVerified(_epoch);
} else {
// unhappy path
emit BatchNotVerified(_epoch);
}
claim.verificationAttempted = true;
}
Expand Down Expand Up @@ -234,6 +231,7 @@ contract FastBridgeReceiverOnPolygon is FxBaseChildTunnel, IFastBridgeReceiver,
}

claim.depositAndRewardWithdrawn = true;
emit ClaimDepositWithdrawn(_epoch, claim.bridger);

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

challenge.depositAndRewardWithdrawn = true;
emit ChallengeDepositWithdrawn(_epoch, challenge.challenger);

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

(success, ) = receiver.call(data);
// Checks-Effects-Interaction
Expand Down
31 changes: 27 additions & 4 deletions contracts/src/bridge/interfaces/IFastBridgeReceiver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,45 @@ interface IFastBridgeReceiver {
event ClaimReceived(uint256 indexed _epoch, bytes32 indexed _batchMerkleRoot);

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

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

/**
* @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.
* @dev This event indicates that the batch has been received via the Safe Bridge.
* @param _epoch The epoch associated with the batch.
* @param _isBridgerHonest Whether the bridger made an honest claim.
* @param _isChallengerHonest Whether the bridger made an honest challenge.
*/
event BatchNotVerified(uint256 indexed _epoch);
event BatchSafeVerified(uint256 indexed _epoch, bool _isBridgerHonest, bool _isChallengerHonest);

/**
* @dev This event indicates that the claim deposit has been withdrawn.
* @param _epoch The epoch associated with the batch.
* @param _bridger The recipient of the claim deposit.
*/
event ClaimDepositWithdrawn(uint256 indexed _epoch, address indexed _bridger);

/**
* @dev This event indicates that the challenge deposit has been withdrawn.
* @param _epoch The epoch associated with the batch.
* @param _challenger The recipient of the challenge deposit.
*/
event ChallengeDepositWithdrawn(uint256 indexed _epoch, address indexed _challenger);

/**
* @dev This event indicates that a message has been relayed for the batch in this `_epoch`.
* @param _epoch The epoch associated with the batch.
* @param _nonce The nonce of the message that was relayed.
*/
event MessageRelayed(uint256 indexed _epoch, uint256 indexed _nonce);

// ************************************* //
// * Function Modifiers * //
Expand Down
Loading

0 comments on commit 81e6621

Please sign in to comment.