Skip to content

Commit 1a8974e

Browse files
committed
fix: replaced buggy createSubcourtJurorFee()
1 parent cb59730 commit 1a8974e

File tree

3 files changed

+32
-34
lines changed

3 files changed

+32
-34
lines changed

contracts/deploy/01-foreign-gateway.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ enum ForeignChains {
1010

1111
const deployForeignGateway: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
1212
const { ethers, deployments, getNamedAccounts, getChainId, config } = hre;
13-
const { deploy } = deployments;
13+
const { deploy, execute } = deployments;
1414
const { hexZeroPad, hexlify } = ethers.utils;
1515

1616
// fallback to hardhat node signers on local network
@@ -38,17 +38,19 @@ const deployForeignGateway: DeployFunction = async (hre: HardhatRuntimeEnvironme
3838
const foreignGateway = await deploy("ForeignGatewayOnEthereum", {
3939
from: deployer,
4040
contract: "ForeignGateway",
41-
args: [
42-
deployer,
43-
veaReceiver.address,
44-
[ethers.BigNumber.from(10).pow(17)],
45-
homeGatewayAddress,
46-
homeChainIdAsBytes32,
47-
],
41+
args: [deployer, veaReceiver.address, homeGatewayAddress, homeChainIdAsBytes32],
4842
gasLimit: 4000000,
4943
log: true,
5044
});
5145

46+
await execute(
47+
"ForeignGatewayOnEthereum",
48+
{ from: deployer, log: true },
49+
"changeSubcourtJurorFee",
50+
0,
51+
ethers.BigNumber.from(10).pow(17)
52+
);
53+
5254
const metaEvidenceUri = `https://raw.githubusercontent.com/kleros/kleros-v2/master/contracts/deployments/${hre.network.name}/MetaEvidence_ArbitrableExample.json`;
5355

5456
await deploy("ArbitrableExample", {

contracts/deploy/03-vea-mock.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const HARDHAT_NETWORK = 31337;
99

1010
const deployHomeGateway: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
1111
const { ethers, deployments, getNamedAccounts } = hre;
12-
const { deploy } = deployments;
12+
const { deploy, execute } = deployments;
1313
const { hexZeroPad, hexlify } = ethers.utils;
1414

1515
// fallback to hardhat node signers on local network
@@ -31,7 +31,7 @@ const deployHomeGateway: DeployFunction = async (hre: HardhatRuntimeEnvironment)
3131
const foreignGateway = await deploy("ForeignGatewayOnEthereum", {
3232
from: deployer,
3333
contract: "ForeignGateway",
34-
args: [deployer, vea.address, [ethers.BigNumber.from(10).pow(17)], homeGatewayAddress, homeChainIdAsBytes32],
34+
args: [deployer, vea.address, homeGatewayAddress, homeChainIdAsBytes32],
3535
gasLimit: 4000000,
3636
log: true,
3737
}); // nonce+0
@@ -44,6 +44,14 @@ const deployHomeGateway: DeployFunction = async (hre: HardhatRuntimeEnvironment)
4444
log: true,
4545
}); // nonce+1
4646

47+
await execute(
48+
"ForeignGatewayOnEthereum",
49+
{ from: deployer, log: true },
50+
"changeSubcourtJurorFee",
51+
0,
52+
ethers.BigNumber.from(10).pow(17)
53+
);
54+
4755
const metaEvidenceUri = `https://raw.githubusercontent.com/kleros/kleros-v2/master/contracts/deployments/goerli/MetaEvidence_ArbitrableExample.json`;
4856

4957
await deploy("ArbitrableExample", {

contracts/src/gateway/ForeignGateway.sol

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ contract ForeignGateway is IForeignGateway {
4343
address arbitrable
4444
);
4545

46+
event ArbitrationCostModified(uint96 indexed _subcourtID, uint256 _feeForJuror);
47+
4648
// ************************************* //
4749
// * Storage * //
4850
// ************************************* //
@@ -51,7 +53,7 @@ contract ForeignGateway is IForeignGateway {
5153
uint256 public immutable override senderChainID;
5254
address public immutable override senderGateway;
5355
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.
54-
uint256[] internal feeForJuror; // feeForJuror[subcourtID]
56+
mapping(uint96 => uint256) public feeForJuror; // feeForJuror[subcourtID], it mirrors the value on KlerosCore.
5557
address public governor;
5658
IFastBridgeReceiver public fastBridgeReceiver;
5759
IFastBridgeReceiver public depreciatedFastbridge;
@@ -79,13 +81,11 @@ contract ForeignGateway is IForeignGateway {
7981
constructor(
8082
address _governor,
8183
IFastBridgeReceiver _fastBridgeReceiver,
82-
uint256[] memory _feeForJuror,
8384
address _senderGateway,
8485
uint256 _senderChainID
8586
) {
8687
governor = _governor;
8788
fastBridgeReceiver = _fastBridgeReceiver;
88-
feeForJuror = _feeForJuror;
8989
senderGateway = _senderGateway;
9090
senderChainID = _senderChainID;
9191
}
@@ -113,26 +113,17 @@ contract ForeignGateway is IForeignGateway {
113113
*/
114114
function changeSubcourtJurorFee(uint96 _subcourtID, uint256 _feeForJuror) external onlyByGovernor {
115115
feeForJuror[_subcourtID] = _feeForJuror;
116-
}
117-
118-
/**
119-
* @dev Creates the `feeForJuror` property value for a new subcourt.
120-
* @param _feeForJuror The new value for the `feeForJuror` property value.
121-
*/
122-
function createSubcourtJurorFee(uint256 _feeForJuror) external onlyByGovernor {
123-
feeForJuror.push(_feeForJuror);
116+
emit ArbitrationCostModified(_subcourtID, _feeForJuror);
124117
}
125118

126119
// ************************************* //
127120
// * State Modifiers * //
128121
// ************************************* //
129122

130-
function createDispute(uint256 _choices, bytes calldata _extraData)
131-
external
132-
payable
133-
override
134-
returns (uint256 disputeID)
135-
{
123+
function createDispute(
124+
uint256 _choices,
125+
bytes calldata _extraData
126+
) external payable override returns (uint256 disputeID) {
136127
require(msg.value >= arbitrationCost(_extraData), "Not paid enough for arbitration");
137128

138129
disputeID = localDisputeID++;
@@ -166,7 +157,6 @@ contract ForeignGateway is IForeignGateway {
166157

167158
function arbitrationCost(bytes calldata _extraData) public view override returns (uint256 cost) {
168159
(uint96 subcourtID, uint256 minJurors) = extraDataToSubcourtIDMinJurors(_extraData);
169-
170160
cost = feeForJuror[subcourtID] * minJurors;
171161
}
172162

@@ -214,19 +204,17 @@ contract ForeignGateway is IForeignGateway {
214204
// * Internal * //
215205
// ************************ //
216206

217-
function extraDataToSubcourtIDMinJurors(bytes memory _extraData)
218-
internal
219-
view
220-
returns (uint96 subcourtID, uint256 minJurors)
221-
{
207+
function extraDataToSubcourtIDMinJurors(
208+
bytes memory _extraData
209+
) internal view returns (uint96 subcourtID, uint256 minJurors) {
222210
// Note that here we ignore DisputeKitID
223211
if (_extraData.length >= 64) {
224212
assembly {
225213
// solium-disable-line security/no-inline-assembly
226214
subcourtID := mload(add(_extraData, 0x20))
227215
minJurors := mload(add(_extraData, 0x40))
228216
}
229-
if (subcourtID >= feeForJuror.length) subcourtID = 0;
217+
if (feeForJuror[subcourtID] == 0) subcourtID = 0;
230218
if (minJurors == 0) minJurors = MIN_JURORS;
231219
} else {
232220
subcourtID = 0;

0 commit comments

Comments
 (0)