From 1a8974ec6b9f56ce9d549609c1350a0b0b9b66ea Mon Sep 17 00:00:00 2001 From: jaybuidl Date: Fri, 16 Dec 2022 20:17:28 +0000 Subject: [PATCH] fix: replaced buggy createSubcourtJurorFee() --- contracts/deploy/01-foreign-gateway.ts | 18 ++++++------ contracts/deploy/03-vea-mock.ts | 12 ++++++-- contracts/src/gateway/ForeignGateway.sol | 36 ++++++++---------------- 3 files changed, 32 insertions(+), 34 deletions(-) diff --git a/contracts/deploy/01-foreign-gateway.ts b/contracts/deploy/01-foreign-gateway.ts index db9725362..cb1c9f06f 100644 --- a/contracts/deploy/01-foreign-gateway.ts +++ b/contracts/deploy/01-foreign-gateway.ts @@ -10,7 +10,7 @@ enum ForeignChains { const deployForeignGateway: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { const { ethers, deployments, getNamedAccounts, getChainId, config } = hre; - const { deploy } = deployments; + const { deploy, execute } = deployments; const { hexZeroPad, hexlify } = ethers.utils; // fallback to hardhat node signers on local network @@ -38,17 +38,19 @@ const deployForeignGateway: DeployFunction = async (hre: HardhatRuntimeEnvironme const foreignGateway = await deploy("ForeignGatewayOnEthereum", { from: deployer, contract: "ForeignGateway", - args: [ - deployer, - veaReceiver.address, - [ethers.BigNumber.from(10).pow(17)], - homeGatewayAddress, - homeChainIdAsBytes32, - ], + args: [deployer, veaReceiver.address, homeGatewayAddress, homeChainIdAsBytes32], gasLimit: 4000000, log: true, }); + await execute( + "ForeignGatewayOnEthereum", + { from: deployer, log: true }, + "changeSubcourtJurorFee", + 0, + ethers.BigNumber.from(10).pow(17) + ); + const metaEvidenceUri = `https://raw.githubusercontent.com/kleros/kleros-v2/master/contracts/deployments/${hre.network.name}/MetaEvidence_ArbitrableExample.json`; await deploy("ArbitrableExample", { diff --git a/contracts/deploy/03-vea-mock.ts b/contracts/deploy/03-vea-mock.ts index 07279dde9..557a5a9fd 100644 --- a/contracts/deploy/03-vea-mock.ts +++ b/contracts/deploy/03-vea-mock.ts @@ -9,7 +9,7 @@ const HARDHAT_NETWORK = 31337; const deployHomeGateway: DeployFunction = async (hre: HardhatRuntimeEnvironment) => { const { ethers, deployments, getNamedAccounts } = hre; - const { deploy } = deployments; + const { deploy, execute } = deployments; const { hexZeroPad, hexlify } = ethers.utils; // fallback to hardhat node signers on local network @@ -31,7 +31,7 @@ const deployHomeGateway: DeployFunction = async (hre: HardhatRuntimeEnvironment) const foreignGateway = await deploy("ForeignGatewayOnEthereum", { from: deployer, contract: "ForeignGateway", - args: [deployer, vea.address, [ethers.BigNumber.from(10).pow(17)], homeGatewayAddress, homeChainIdAsBytes32], + args: [deployer, vea.address, homeGatewayAddress, homeChainIdAsBytes32], gasLimit: 4000000, log: true, }); // nonce+0 @@ -44,6 +44,14 @@ const deployHomeGateway: DeployFunction = async (hre: HardhatRuntimeEnvironment) log: true, }); // nonce+1 + await execute( + "ForeignGatewayOnEthereum", + { from: deployer, log: true }, + "changeSubcourtJurorFee", + 0, + ethers.BigNumber.from(10).pow(17) + ); + const metaEvidenceUri = `https://raw.githubusercontent.com/kleros/kleros-v2/master/contracts/deployments/goerli/MetaEvidence_ArbitrableExample.json`; await deploy("ArbitrableExample", { diff --git a/contracts/src/gateway/ForeignGateway.sol b/contracts/src/gateway/ForeignGateway.sol index 8d0f8ac62..b4d8caf2c 100644 --- a/contracts/src/gateway/ForeignGateway.sol +++ b/contracts/src/gateway/ForeignGateway.sol @@ -43,6 +43,8 @@ contract ForeignGateway is IForeignGateway { address arbitrable ); + event ArbitrationCostModified(uint96 indexed _subcourtID, uint256 _feeForJuror); + // ************************************* // // * Storage * // // ************************************* // @@ -51,7 +53,7 @@ contract ForeignGateway is IForeignGateway { uint256 public immutable override senderChainID; address public immutable override senderGateway; 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. - uint256[] internal feeForJuror; // feeForJuror[subcourtID] + mapping(uint96 => uint256) public feeForJuror; // feeForJuror[subcourtID], it mirrors the value on KlerosCore. address public governor; IFastBridgeReceiver public fastBridgeReceiver; IFastBridgeReceiver public depreciatedFastbridge; @@ -79,13 +81,11 @@ contract ForeignGateway is IForeignGateway { constructor( address _governor, IFastBridgeReceiver _fastBridgeReceiver, - uint256[] memory _feeForJuror, address _senderGateway, uint256 _senderChainID ) { governor = _governor; fastBridgeReceiver = _fastBridgeReceiver; - feeForJuror = _feeForJuror; senderGateway = _senderGateway; senderChainID = _senderChainID; } @@ -113,26 +113,17 @@ contract ForeignGateway is IForeignGateway { */ function changeSubcourtJurorFee(uint96 _subcourtID, uint256 _feeForJuror) external onlyByGovernor { feeForJuror[_subcourtID] = _feeForJuror; - } - - /** - * @dev Creates the `feeForJuror` property value for a new subcourt. - * @param _feeForJuror The new value for the `feeForJuror` property value. - */ - function createSubcourtJurorFee(uint256 _feeForJuror) external onlyByGovernor { - feeForJuror.push(_feeForJuror); + emit ArbitrationCostModified(_subcourtID, _feeForJuror); } // ************************************* // // * State Modifiers * // // ************************************* // - function createDispute(uint256 _choices, bytes calldata _extraData) - external - payable - override - returns (uint256 disputeID) - { + function createDispute( + uint256 _choices, + bytes calldata _extraData + ) external payable override returns (uint256 disputeID) { require(msg.value >= arbitrationCost(_extraData), "Not paid enough for arbitration"); disputeID = localDisputeID++; @@ -166,7 +157,6 @@ contract ForeignGateway is IForeignGateway { function arbitrationCost(bytes calldata _extraData) public view override returns (uint256 cost) { (uint96 subcourtID, uint256 minJurors) = extraDataToSubcourtIDMinJurors(_extraData); - cost = feeForJuror[subcourtID] * minJurors; } @@ -214,11 +204,9 @@ contract ForeignGateway is IForeignGateway { // * Internal * // // ************************ // - function extraDataToSubcourtIDMinJurors(bytes memory _extraData) - internal - view - returns (uint96 subcourtID, uint256 minJurors) - { + function extraDataToSubcourtIDMinJurors( + bytes memory _extraData + ) internal view returns (uint96 subcourtID, uint256 minJurors) { // Note that here we ignore DisputeKitID if (_extraData.length >= 64) { assembly { @@ -226,7 +214,7 @@ contract ForeignGateway is IForeignGateway { subcourtID := mload(add(_extraData, 0x20)) minJurors := mload(add(_extraData, 0x40)) } - if (subcourtID >= feeForJuror.length) subcourtID = 0; + if (feeForJuror[subcourtID] == 0) subcourtID = 0; if (minJurors == 0) minJurors = MIN_JURORS; } else { subcourtID = 0;