Skip to content

Commit

Permalink
fix: adding back the grace period on the foreign gateway outbox chang…
Browse files Browse the repository at this point in the history
…e function
  • Loading branch information
jaybuidl committed Jun 12, 2023
1 parent 203a4cc commit a0e0ae7
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 53 deletions.
4 changes: 2 additions & 2 deletions contracts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Refresh the list of deployed contracts by running `./scripts/generateDeployments
#### Chiado

- [ArbitrableExample](https://blockscout.com/gnosis/chiado/address/0xc0fcc96BFd78e36550FCaB434A9EE1210B57225b)
- [ForeignGatewayOnGnosis](https://blockscout.com/gnosis/chiado/address/0x604E209B0f77aa85F30739987cA576B2f5d5ad5D)
- [ForeignGatewayOnGnosis](https://blockscout.com/gnosis/chiado/address/0x499AD7EAA015E97CeC65eEDC3f2Ea9D848eB8618)
- [SortitionSumTreeFactory](https://blockscout.com/gnosis/chiado/address/0xc7e3BF90299f6BD9FA7c3703837A9CAbB5743636)
- [TokenBridge](https://blockscout.com/gnosis/chiado/address/0xbb3c86f9918C3C1d83668fA84e79E876d147fFf2)
- [WETH](https://blockscout.com/gnosis/chiado/address/0x96f7C31EF5bac6710ADF201176298d61943Dde63)
Expand All @@ -32,7 +32,7 @@ Refresh the list of deployed contracts by running `./scripts/generateDeployments
- [BlockHashRNG](https://goerli.arbiscan.io/address/0x68eE49dfD9d76f3386257a3D0e0A85c0A5519bBD)
- [DisputeKitClassic](https://goerli.arbiscan.io/address/0xE28206c91Cbb71652001AeB23c6763D4E4220466)
- [DisputeResolver](https://goerli.arbiscan.io/address/0xf6356Ff189C0fBDa4A1e8dB6BF24Dc66CfBa003B)
- [HomeGatewayToGnosis](https://goerli.arbiscan.io/address/0xD2655d9768DB42F4C98A9F51653a3f77Ec4493a3)
- [HomeGatewayToGnosis](https://goerli.arbiscan.io/address/0xaAEB65dD8424ec76425FfB48bc0a057b3D6D5502)
- [KlerosCore](https://goerli.arbiscan.io/address/0x720d566572aFA2D66abD2007e5aBa95a98E9f160)
- [PolicyRegistry](https://goerli.arbiscan.io/address/0xED503aBA65B28D81444294D1eAa5d84CeFdC2C58)
- [RandomizerRNG](https://goerli.arbiscan.io/address/0xa90f7D2e35718FDE9AD96c8B6667AFcAa4BEfd4d)
Expand Down
34 changes: 17 additions & 17 deletions contracts/deployments/arbitrumGoerli/HomeGatewayToGnosis.json

Large diffs are not rendered by default.

127 changes: 97 additions & 30 deletions contracts/deployments/chiado/ForeignGatewayOnGnosis.json

Large diffs are not rendered by default.

14 changes: 12 additions & 2 deletions contracts/src/gateway/ForeignGateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,20 @@ contract ForeignGateway is IForeignGateway {
address public veaOutbox;
uint256 public immutable senderChainID;
address public override senderGateway;
address public deprecatedVeaOutbox;
uint256 public deprecatedVeaOutboxExpiration;
mapping(bytes32 => DisputeData) public disputeHashtoDisputeData;

// ************************************* //
// * Function Modifiers * //
// ************************************* //

modifier onlyFromVea(address _messageSender) {
require(veaOutbox == msg.sender, "Access not allowed: Vea Outbox only.");
require(
veaOutbox == msg.sender ||
(block.timestamp < deprecatedVeaOutboxExpiration && deprecatedVeaOutbox == msg.sender),
"Access not allowed: Vea Outbox only."
);
require(_messageSender == senderGateway, "Access not allowed: Sender Gateway only.");
_;
}
Expand Down Expand Up @@ -89,7 +95,11 @@ contract ForeignGateway is IForeignGateway {

/// @dev Changes the outbox.
/// @param _veaOutbox The address of the new outbox.
function changeVea(address _veaOutbox) external onlyByGovernor {
/// @param _gracePeriod The duration to accept messages from the deprecated bridge (if at all).
function changeVea(address _veaOutbox, uint256 _gracePeriod) external onlyByGovernor {
// grace period to relay the remaining messages which are still going through the deprecated bridge.
deprecatedVeaOutboxExpiration = block.timestamp + _gracePeriod;
deprecatedVeaOutbox = veaOutbox;
veaOutbox = _veaOutbox;
}

Expand Down
19 changes: 17 additions & 2 deletions contracts/src/gateway/ForeignGatewayOnGnosis.sol
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,20 @@ contract ForeignGatewayOnGnosis is IForeignGateway {
address public veaOutbox;
uint256 public immutable senderChainID;
address public override senderGateway;
address public deprecatedVeaOutbox;
uint256 public deprecatedVeaOutboxExpiration;
mapping(bytes32 => DisputeData) public disputeHashtoDisputeData;

// ************************************* //
// * Function Modifiers * //
// ************************************* //

modifier onlyFromVea(address _messageSender) {
require(veaOutbox == msg.sender, "Access not allowed: Fast Bridge only.");
require(
veaOutbox == msg.sender ||
(block.timestamp < deprecatedVeaOutboxExpiration && deprecatedVeaOutbox == msg.sender),
"Access not allowed: Vea Outbox only."
);
require(_messageSender == senderGateway, "Access not allowed: Sender Gateway only.");
_;
}
Expand Down Expand Up @@ -90,6 +96,16 @@ contract ForeignGatewayOnGnosis is IForeignGateway {
governor = _governor;
}

/// @dev Changes the outbox.
/// @param _veaOutbox The address of the new outbox.
/// @param _gracePeriod The duration to accept messages from the deprecated bridge (if at all).
function changeVea(address _veaOutbox, uint256 _gracePeriod) external onlyByGovernor {
// grace period to relay the remaining messages which are still going through the deprecated bridge.
deprecatedVeaOutboxExpiration = block.timestamp + _gracePeriod;
deprecatedVeaOutbox = veaOutbox;
veaOutbox = _veaOutbox;
}

/// @dev Changes the sender gateway.
/// @param _senderGateway The address of the new sender gateway.
function changeReceiverGateway(address _senderGateway) external {
Expand Down Expand Up @@ -165,7 +181,6 @@ contract ForeignGatewayOnGnosis is IForeignGateway {
uint256 _ruling,
address _relayer
) external override onlyFromVea(_messageSender) {
require(_messageSender == senderGateway, "Only the homegateway is allowed.");
DisputeData storage dispute = disputeHashtoDisputeData[_disputeHash];

require(dispute.id != 0, "Dispute does not exist");
Expand Down

0 comments on commit a0e0ae7

Please sign in to comment.