Skip to content

Commit 7055eb6

Browse files
committed
refactor: fixed some confusing names between sender/receiver and home/foreign gateways
1 parent 5b1ce6a commit 7055eb6

10 files changed

+126
-62
lines changed

contracts/deploy/01-foreign-gateway-on-ethereum.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const deployForeignGateway: DeployFunction = async (hre: HardhatRuntimeEnvironme
3939
const foreignGateway = await deploy("ForeignGatewayOnEthereum", {
4040
from: deployer,
4141
contract: "ForeignGateway",
42-
args: [deployer, veaOutbox.address, homeGatewayAddress, homeChainIdAsBytes32],
42+
args: [deployer, veaOutbox.address, homeChainIdAsBytes32, homeGatewayAddress],
4343
gasLimit: 4000000,
4444
log: true,
4545
});

contracts/deploy/01-foreign-gateway-on-gnosis.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ const deployForeignGateway: DeployFunction = async (hre: HardhatRuntimeEnvironme
6868
await deploy("ForeignGatewayOnGnosis", {
6969
from: deployer,
7070
contract: "ForeignGatewayOnGnosis",
71-
args: [deployer, veaOutbox.address, homeGatewayAddress, homeChainIdAsBytes32, wethAddress],
71+
args: [deployer, veaOutbox.address, homeChainIdAsBytes32, homeGatewayAddress, wethAddress],
7272
log: true,
7373
maxFeePerGas: ONE_GWEI,
7474
maxPriorityFeePerGas: ONE_GWEI,

contracts/deploy/02-home-gateway-to-ethereum.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const deployHomeGateway: DeployFunction = async (hre: HardhatRuntimeEnvironment)
2929
await deploy("HomeGatewayToEthereum", {
3030
from: deployer,
3131
contract: "HomeGateway",
32-
args: [deployer, klerosCore.address, veaInbox.address, foreignGateway.address, foreignChainId],
32+
args: [deployer, klerosCore.address, veaInbox.address, foreignChainId, foreignGateway.address],
3333
log: true,
3434
}); // nonce+0
3535
};

contracts/deploy/02-home-gateway-to-gnosis.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const deployHomeGateway: DeployFunction = async (hre: HardhatRuntimeEnvironment)
2828
await deploy("HomeGatewayToGnosis", {
2929
from: deployer,
3030
contract: "HomeGateway",
31-
args: [deployer, klerosCore.address, veaInbox.address, foreignGateway.address, foreignChainId],
31+
args: [deployer, klerosCore.address, veaInbox.address, foreignChainId, foreignGateway.address],
3232
log: true,
3333
}); // nonce+0
3434
};

contracts/deploy/03-vea-mock.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ const deployHomeGateway: DeployFunction = async (hre: HardhatRuntimeEnvironment)
3131
const foreignGateway = await deploy("ForeignGatewayOnEthereum", {
3232
from: deployer,
3333
contract: "ForeignGateway",
34-
args: [deployer, vea.address, homeGatewayAddress, homeChainIdAsBytes32],
34+
args: [deployer, vea.address, homeChainIdAsBytes32, homeGatewayAddress],
3535
gasLimit: 4000000,
3636
log: true,
3737
}); // nonce+0
3838

3939
await deploy("HomeGatewayToEthereum", {
4040
from: deployer,
4141
contract: "HomeGateway",
42-
args: [deployer, klerosCore.address, vea.address, foreignGateway.address, HARDHAT_NETWORK],
42+
args: [deployer, klerosCore.address, vea.address, HARDHAT_NETWORK, foreignGateway.address],
4343
gasLimit: 4000000,
4444
log: true,
4545
}); // nonce+1

contracts/src/gateway/ForeignGateway.sol

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ contract ForeignGateway is IForeignGateway {
5050
mapping(uint96 => uint256) public feeForJuror; // feeForJuror[courtID], it mirrors the value on KlerosCore.
5151
address public governor;
5252
address public veaOutbox;
53-
uint256 public immutable senderChainID;
54-
address public override senderGateway;
53+
uint256 public immutable override homeChainID;
54+
address public override homeGateway;
5555
address public deprecatedVeaOutbox;
5656
uint256 public deprecatedVeaOutboxExpiration;
5757
mapping(bytes32 => DisputeData) public disputeHashtoDisputeData;
@@ -66,7 +66,7 @@ contract ForeignGateway is IForeignGateway {
6666
(block.timestamp < deprecatedVeaOutboxExpiration && deprecatedVeaOutbox == msg.sender),
6767
"Access not allowed: Vea Outbox only."
6868
);
69-
require(_messageSender == senderGateway, "Access not allowed: Sender Gateway only.");
69+
require(_messageSender == homeGateway, "Access not allowed: HomeGateway only.");
7070
_;
7171
}
7272

@@ -75,11 +75,15 @@ contract ForeignGateway is IForeignGateway {
7575
_;
7676
}
7777

78-
constructor(address _governor, address _veaOutbox, address _senderGateway, uint256 _senderChainID) {
78+
// ************************************* //
79+
// * Constructor * //
80+
// ************************************* //
81+
82+
constructor(address _governor, address _veaOutbox, uint256 _homeChainID, address _homeGateway) {
7983
governor = _governor;
8084
veaOutbox = _veaOutbox;
81-
senderGateway = _senderGateway;
82-
senderChainID = _senderChainID;
85+
homeChainID = _homeChainID;
86+
homeGateway = _homeGateway;
8387
}
8488

8589
// ************************************* //
@@ -103,11 +107,11 @@ contract ForeignGateway is IForeignGateway {
103107
veaOutbox = _veaOutbox;
104108
}
105109

106-
/// @dev Changes the sender gateway.
107-
/// @param _senderGateway The address of the new sender gateway.
108-
function changeReceiverGateway(address _senderGateway) external {
110+
/// @dev Changes the home gateway.
111+
/// @param _homeGateway The address of the new home gateway.
112+
function changeHomeGateway(address _homeGateway) external {
109113
require(governor == msg.sender, "Access not allowed: Governor only.");
110-
senderGateway = _senderGateway;
114+
homeGateway = _homeGateway;
111115
}
112116

113117
/// @dev Changes the `feeForJuror` property value of a specified court.
@@ -122,6 +126,7 @@ contract ForeignGateway is IForeignGateway {
122126
// * State Modifiers * //
123127
// ************************************* //
124128

129+
/// @inheritdoc IArbitrator
125130
function createDispute(
126131
uint256 _choices,
127132
bytes calldata _extraData
@@ -165,12 +170,13 @@ contract ForeignGateway is IForeignGateway {
165170
revert("Not supported yet");
166171
}
167172

173+
/// @inheritdoc IArbitrator
168174
function arbitrationCost(bytes calldata _extraData) public view override returns (uint256 cost) {
169175
(uint96 courtID, uint256 minJurors) = extraDataToCourtIDMinJurors(_extraData);
170176
cost = feeForJuror[courtID] * minJurors;
171177
}
172178

173-
/// Relay the rule call from the home gateway to the arbitrable.
179+
/// @inheritdoc IForeignGateway
174180
function relayRule(
175181
address _messageSender,
176182
bytes32 _disputeHash,
@@ -189,6 +195,7 @@ contract ForeignGateway is IForeignGateway {
189195
arbitrable.rule(dispute.id, _ruling);
190196
}
191197

198+
/// @inheritdoc IForeignGateway
192199
function withdrawFees(bytes32 _disputeHash) external override {
193200
DisputeData storage dispute = disputeHashtoDisputeData[_disputeHash];
194201
require(dispute.id != 0, "Dispute does not exist");
@@ -203,10 +210,21 @@ contract ForeignGateway is IForeignGateway {
203210
// * Public Views * //
204211
// ************************************* //
205212

213+
/// @inheritdoc IForeignGateway
206214
function disputeHashToForeignID(bytes32 _disputeHash) external view override returns (uint256) {
207215
return disputeHashtoDisputeData[_disputeHash].id;
208216
}
209217

218+
/// @inheritdoc IReceiverGateway
219+
function senderGateway() external view returns (address) {
220+
return homeGateway;
221+
}
222+
223+
/// @inheritdoc IForeignGateway
224+
function feeToken() external view returns (IERC20) {
225+
revert("Not supported yet");
226+
}
227+
210228
// ************************ //
211229
// * Internal * //
212230
// ************************ //

contracts/src/gateway/ForeignGatewayOnGnosis.sol

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ pragma solidity 0.8.18;
1010

1111
import "../arbitration/IArbitrable.sol";
1212
import "./interfaces/IForeignGateway.sol";
13-
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
1413

1514
/// Foreign Gateway
1615
/// Counterpart of `HomeGateway`
@@ -47,16 +46,16 @@ contract ForeignGatewayOnGnosis is IForeignGateway {
4746
// ************************************* //
4847

4948
uint256 public constant DEFAULT_NB_OF_JURORS = 3; // The default number of jurors in a dispute.
50-
IERC20 public immutable weth; // WETH token on xDai.
5149
uint256 internal localDisputeID = 1; // The disputeID must start from 1 as the KlerosV1 proxy governor depends on this implementation. We now also depend on localDisputeID not ever being zero.
5250
mapping(uint96 => uint256) public feeForJuror; // feeForJuror[courtID], it mirrors the value on KlerosCore.
5351
address public governor;
5452
address public veaOutbox;
55-
uint256 public immutable senderChainID;
56-
address public override senderGateway;
53+
uint256 public immutable override homeChainID;
54+
address public override homeGateway;
5755
address public deprecatedVeaOutbox;
5856
uint256 public deprecatedVeaOutboxExpiration;
5957
mapping(bytes32 => DisputeData) public disputeHashtoDisputeData;
58+
IERC20 public immutable weth; // WETH token on xDai.
6059

6160
// ************************************* //
6261
// * Function Modifiers * //
@@ -68,7 +67,7 @@ contract ForeignGatewayOnGnosis is IForeignGateway {
6867
(block.timestamp < deprecatedVeaOutboxExpiration && deprecatedVeaOutbox == msg.sender),
6968
"Access not allowed: Vea Outbox only."
7069
);
71-
require(_messageSender == senderGateway, "Access not allowed: Sender Gateway only.");
70+
require(_messageSender == homeGateway, "Access not allowed: HomeGateway only.");
7271
_;
7372
}
7473

@@ -77,11 +76,15 @@ contract ForeignGatewayOnGnosis is IForeignGateway {
7776
_;
7877
}
7978

80-
constructor(address _governor, address _veaOutbox, address _senderGateway, uint256 _senderChainID, IERC20 _weth) {
79+
// ************************************* //
80+
// * Constructor * //
81+
// ************************************* //
82+
83+
constructor(address _governor, address _veaOutbox, uint256 _homeChainID, address _homeGateway, IERC20 _weth) {
8184
governor = _governor;
8285
veaOutbox = _veaOutbox;
83-
senderGateway = _senderGateway;
84-
senderChainID = _senderChainID;
86+
homeChainID = _homeChainID;
87+
homeGateway = _homeGateway;
8588
weth = _weth;
8689
}
8790

@@ -106,11 +109,11 @@ contract ForeignGatewayOnGnosis is IForeignGateway {
106109
veaOutbox = _veaOutbox;
107110
}
108111

109-
/// @dev Changes the sender gateway.
110-
/// @param _senderGateway The address of the new sender gateway.
111-
function changeReceiverGateway(address _senderGateway) external {
112+
/// @dev Changes the home gateway.
113+
/// @param _homeGateway The address of the new home gateway.
114+
function changeHomeGateway(address _homeGateway) external {
112115
require(governor == msg.sender, "Access not allowed: Governor only.");
113-
senderGateway = _senderGateway;
116+
homeGateway = _homeGateway;
114117
}
115118

116119
/// @dev Changes the `feeForJuror` property value of a specified court.
@@ -125,6 +128,7 @@ contract ForeignGatewayOnGnosis is IForeignGateway {
125128
// * State Modifiers * //
126129
// ************************************* //
127130

131+
/// @inheritdoc IArbitrator
128132
function createDispute(
129133
uint256 /*_choices*/,
130134
bytes calldata /*_extraData*/
@@ -174,7 +178,7 @@ contract ForeignGatewayOnGnosis is IForeignGateway {
174178
cost = feeForJuror[courtID] * minJurors;
175179
}
176180

177-
/// Relay the rule call from the home gateway to the arbitrable.
181+
/// @inheritdoc IForeignGateway
178182
function relayRule(
179183
address _messageSender,
180184
bytes32 _disputeHash,
@@ -193,6 +197,7 @@ contract ForeignGatewayOnGnosis is IForeignGateway {
193197
arbitrable.rule(dispute.id, _ruling);
194198
}
195199

200+
/// @inheritdoc IForeignGateway
196201
function withdrawFees(bytes32 _disputeHash) external override {
197202
DisputeData storage dispute = disputeHashtoDisputeData[_disputeHash];
198203
require(dispute.id != 0, "Dispute does not exist");
@@ -207,10 +212,21 @@ contract ForeignGatewayOnGnosis is IForeignGateway {
207212
// * Public Views * //
208213
// ************************************* //
209214

215+
/// @inheritdoc IForeignGateway
210216
function disputeHashToForeignID(bytes32 _disputeHash) external view override returns (uint256) {
211217
return disputeHashtoDisputeData[_disputeHash].id;
212218
}
213219

220+
/// @inheritdoc IReceiverGateway
221+
function senderGateway() external view returns (address) {
222+
return homeGateway;
223+
}
224+
225+
/// @inheritdoc IForeignGateway
226+
function feeToken() external view returns (IERC20) {
227+
return weth;
228+
}
229+
214230
// ************************ //
215231
// * Internal * //
216232
// ************************ //

contracts/src/gateway/HomeGateway.sol

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,28 @@ contract HomeGateway is IHomeGateway {
3131
address public governor;
3232
IArbitrator public arbitrator;
3333
IVeaInbox public veaInbox;
34-
address public override receiverGateway;
35-
uint256 public immutable receiverChainID;
34+
uint256 public immutable override foreignChainID;
35+
address public override foreignGateway;
3636
mapping(uint256 => bytes32) public disputeIDtoHash;
3737
mapping(bytes32 => uint256) public disputeHashtoID;
3838
mapping(bytes32 => RelayedData) public disputeHashtoRelayedData;
3939

40+
// ************************************* //
41+
// * Constructor * //
42+
// ************************************* //
43+
4044
constructor(
4145
address _governor,
4246
IArbitrator _arbitrator,
4347
IVeaInbox _veaInbox,
44-
address _receiverGateway,
45-
uint256 _receiverChainID
48+
uint256 _foreignChainID,
49+
address _foreignGateway
4650
) {
4751
governor = _governor;
4852
arbitrator = _arbitrator;
4953
veaInbox = _veaInbox;
50-
receiverGateway = _receiverGateway;
51-
receiverChainID = _receiverChainID;
54+
foreignChainID = _foreignChainID;
55+
foreignGateway = _foreignGateway;
5256

5357
emit MetaEvidence(0, "BRIDGE");
5458
}
@@ -78,24 +82,18 @@ contract HomeGateway is IHomeGateway {
7882
veaInbox = _veaInbox;
7983
}
8084

81-
/// @dev Changes the receiver gateway.
82-
/// @param _receiverGateway The address of the new receiver gateway.
83-
function changeReceiverGateway(address _receiverGateway) external {
85+
/// @dev Changes the foreign gateway.
86+
/// @param _foreignGateway The address of the new foreign gateway.
87+
function changeForeignGateway(address _foreignGateway) external {
8488
require(governor == msg.sender, "Access not allowed: Governor only.");
85-
receiverGateway = _receiverGateway;
89+
foreignGateway = _foreignGateway;
8690
}
8791

8892
// ************************************* //
8993
// * State Modifiers * //
9094
// ************************************* //
9195

92-
/// @dev Provide the same parameters as on the foreignChain while creating a dispute. Providing incorrect parameters will create a different hash than on the foreignChain and will not affect the actual dispute/arbitrable's ruling.
93-
/// @param _foreignChainID foreignChainId
94-
/// @param _foreignBlockHash foreignBlockHash
95-
/// @param _foreignDisputeID foreignDisputeID
96-
/// @param _choices number of ruling choices
97-
/// @param _extraData extraData
98-
/// @param _arbitrable arbitrable
96+
/// @inheritdoc IHomeGateway
9997
function relayCreateDispute(
10098
uint256 _foreignChainID,
10199
bytes32 _foreignBlockHash,
@@ -115,6 +113,8 @@ contract HomeGateway is IHomeGateway {
115113
_arbitrable
116114
)
117115
);
116+
require(_foreignChainID == foreignChainID, "Foreign chain ID not supported");
117+
118118
RelayedData storage relayedData = disputeHashtoRelayedData[disputeHash];
119119
require(relayedData.relayer == address(0), "Dispute already relayed");
120120

@@ -130,10 +130,7 @@ contract HomeGateway is IHomeGateway {
130130
emit Dispute(arbitrator, disputeID, 0, 0);
131131
}
132132

133-
/// @dev Give a ruling for a dispute. Must be called by the arbitrator.
134-
/// The purpose of this function is to ensure that the address calling it has the right to rule on the contract.
135-
/// @param _disputeID ID of the dispute in the Arbitrator contract.
136-
/// @param _ruling Ruling given by the arbitrator. Note that 0 is reserved for "Not able/wanting to make a decision".
133+
/// @inheritdoc IArbitrable
137134
function rule(uint256 _disputeID, uint256 _ruling) external override {
138135
require(msg.sender == address(arbitrator), "Only Arbitrator");
139136

@@ -144,12 +141,20 @@ contract HomeGateway is IHomeGateway {
144141
// because Vea takes care of inserting it for security reasons.
145142
bytes4 methodSelector = IForeignGateway.relayRule.selector;
146143
bytes memory data = abi.encode(disputeHash, _ruling, relayedData.relayer);
147-
veaInbox.sendMessage(receiverGateway, methodSelector, data);
144+
veaInbox.sendMessage(foreignGateway, methodSelector, data);
148145
}
149146

150-
/// @dev Looks up the local home disputeID for a disputeHash. For cross-chain Evidence standard.
151-
/// @param _disputeHash dispute hash
147+
// ************************************* //
148+
// * Public Views * //
149+
// ************************************* //
150+
151+
/// @inheritdoc IHomeGateway
152152
function disputeHashToHomeID(bytes32 _disputeHash) external view override returns (uint256) {
153153
return disputeHashtoID[_disputeHash];
154154
}
155+
156+
/// @inheritdoc ISenderGateway
157+
function receiverGateway() external view override returns (address) {
158+
return foreignGateway;
159+
}
155160
}

0 commit comments

Comments
 (0)