From 03fe8463f734a116d5330a16dcc00291419c9410 Mon Sep 17 00:00:00 2001 From: jaybuidl Date: Fri, 13 Oct 2023 23:56:45 +0100 Subject: [PATCH] fix: fixed based on feedback from @unknownunknown1, bumped hardhat-deploy to pick up this merged PR https://github.com/wighawag/hardhat-deploy/pull/479 --- contracts/deploy/utils/deployUpgradable.ts | 19 ++++++++++++------- contracts/package.json | 2 +- contracts/src/arbitration/KlerosCore.sol | 11 +++++------ .../dispute-kits/DisputeKitSybilResistant.sol | 1 + .../interfaces/IDisputeTemplateRegistry.sol | 2 -- contracts/src/gateway/ForeignGateway.sol | 9 ++++++--- contracts/src/gateway/HomeGateway.sol | 11 ++++++++--- contracts/src/libraries/Constants.sol | 3 +++ contracts/src/proxy/Initializable.sol | 8 +++++++- contracts/src/proxy/UUPSProxiable.sol | 2 +- contracts/src/proxy/UUPSProxy.sol | 2 +- contracts/test/proxy/index.ts | 3 +-- yarn.lock | 10 +++++----- 13 files changed, 51 insertions(+), 32 deletions(-) diff --git a/contracts/deploy/utils/deployUpgradable.ts b/contracts/deploy/utils/deployUpgradable.ts index 2a5f4ec92..af77021ef 100644 --- a/contracts/deploy/utils/deployUpgradable.ts +++ b/contracts/deploy/utils/deployUpgradable.ts @@ -1,30 +1,35 @@ import { DeployResult, DeployOptions } from "hardhat-deploy/types"; import { HardhatRuntimeEnvironment } from "hardhat/types"; -export function deployUpgradable( +export const deployUpgradable = async ( hre: HardhatRuntimeEnvironment, contract: string, options: DeployOptions -): Promise { +): Promise => { const { deploy } = hre.deployments; const { args, ...otherOptions } = options; + // Rationale: https://github.com/kleros/kleros-v2/pull/1214#issue-1879116629 return deploy(contract, { proxy: { proxyContract: "UUPSProxy", proxyArgs: ["{implementation}", "{data}"], - checkProxyAdmin: false, - checkABIConflict: false, + checkProxyAdmin: false, // Not relevant for UUPSProxy + checkABIConflict: false, // Not relevant for UUPSProxy + upgradeFunction: { + methodName: "upgradeToAndCall", + upgradeArgs: ["{implementation}", "{data}"], + }, execute: { init: { methodName: "initialize", args: args ?? [], }, onUpgrade: { - methodName: "governor", - args: [], + methodName: "initialize", + args: args ?? [], }, }, }, ...otherOptions, }); -} +}; diff --git a/contracts/package.json b/contracts/package.json index 20fe8877f..b19dc857b 100644 --- a/contracts/package.json +++ b/contracts/package.json @@ -63,7 +63,7 @@ "graphql-request": "^6.1.0", "hardhat": "^2.15.0", "hardhat-contract-sizer": "^2.10.0", - "hardhat-deploy": "^0.11.37", + "hardhat-deploy": "^0.11.42", "hardhat-deploy-ethers": "^0.4.0-next.1", "hardhat-deploy-tenderly": "^0.2.0", "hardhat-docgen": "^1.3.0", diff --git a/contracts/src/arbitration/KlerosCore.sol b/contracts/src/arbitration/KlerosCore.sol index 3b9e12fe3..472f28614 100644 --- a/contracts/src/arbitration/KlerosCore.sol +++ b/contracts/src/arbitration/KlerosCore.sol @@ -108,7 +108,6 @@ contract KlerosCore is IArbitratorV2, UUPSProxiable, Initializable { uint256 private constant ALPHA_DIVISOR = 1e4; // The number to divide `Court.alpha` by. uint256 private constant NON_PAYABLE_AMOUNT = (2 ** 256 - 2) / 2; // An amount higher than the supply of ETH. uint256 private constant SEARCH_ITERATIONS = 10; // Number of iterations to search for suitable parent court before jumping to the top court. - IERC20 private constant NATIVE_CURRENCY = IERC20(address(0)); // The native currency, such as ETH on Arbitrum, Optimism and Ethereum L1. address public governor; // The governor of the contract. IERC20 public pinakion; // The Pinakion token contract. @@ -516,7 +515,7 @@ contract KlerosCore is IArbitratorV2, UUPSProxiable, Initializable { ) external payable override returns (uint256 disputeID) { if (msg.value < arbitrationCost(_extraData)) revert ArbitrationFeesNotEnough(); - return _createDispute(_numberOfChoices, _extraData, NATIVE_CURRENCY, msg.value); + return _createDispute(_numberOfChoices, _extraData, Constants.NATIVE_CURRENCY, msg.value); } /// @inheritdoc IArbitratorV2 @@ -553,7 +552,7 @@ contract KlerosCore is IArbitratorV2, UUPSProxiable, Initializable { Round storage round = dispute.rounds.push(); // Obtain the feeForJuror in the same currency as the _feeAmount - uint256 feeForJuror = (_feeToken == NATIVE_CURRENCY) + uint256 feeForJuror = (_feeToken == Constants.NATIVE_CURRENCY) ? court.feeForJuror : convertEthToTokenAmount(_feeToken, court.feeForJuror); round.nbVotes = _feeAmount / feeForJuror; @@ -810,7 +809,7 @@ contract KlerosCore is IArbitratorV2, UUPSProxiable, Initializable { } if (_params.repartition == _params.numberOfVotesInRound - 1 && _params.coherentCount == 0) { // No one was coherent, send the rewards to the governor. - if (round.feeToken == NATIVE_CURRENCY) { + if (round.feeToken == Constants.NATIVE_CURRENCY) { // The dispute fees were paid in ETH payable(governor).send(round.totalFeesForJurors); } else { @@ -865,7 +864,7 @@ contract KlerosCore is IArbitratorV2, UUPSProxiable, Initializable { uint256 feeReward = ((round.totalFeesForJurors / _params.coherentCount) * degreeOfCoherence) / ALPHA_DIVISOR; round.sumFeeRewardPaid += feeReward; pinakion.safeTransfer(account, pnkReward); - if (round.feeToken == NATIVE_CURRENCY) { + if (round.feeToken == Constants.NATIVE_CURRENCY) { // The dispute fees were paid in ETH payable(account).send(feeReward); } else { @@ -891,7 +890,7 @@ contract KlerosCore is IArbitratorV2, UUPSProxiable, Initializable { pinakion.safeTransfer(governor, leftoverPnkReward); } if (leftoverFeeReward != 0) { - if (round.feeToken == NATIVE_CURRENCY) { + if (round.feeToken == Constants.NATIVE_CURRENCY) { // The dispute fees were paid in ETH payable(governor).send(leftoverFeeReward); } else { diff --git a/contracts/src/arbitration/dispute-kits/DisputeKitSybilResistant.sol b/contracts/src/arbitration/dispute-kits/DisputeKitSybilResistant.sol index a0fed2592..23946ac60 100644 --- a/contracts/src/arbitration/dispute-kits/DisputeKitSybilResistant.sol +++ b/contracts/src/arbitration/dispute-kits/DisputeKitSybilResistant.sol @@ -160,6 +160,7 @@ contract DisputeKitSybilResistant is IDisputeKit, IEvidence, Initializable, UUPS /// @dev Initializer. /// @param _governor The governor's address. /// @param _core The KlerosCore arbitrator. + /// @param _poh The Proof of Humanity registry. function initialize(address _governor, KlerosCore _core, IProofOfHumanity _poh) external reinitializer(1) { governor = _governor; core = _core; diff --git a/contracts/src/arbitration/interfaces/IDisputeTemplateRegistry.sol b/contracts/src/arbitration/interfaces/IDisputeTemplateRegistry.sol index 96500ce6e..3106568ec 100644 --- a/contracts/src/arbitration/interfaces/IDisputeTemplateRegistry.sol +++ b/contracts/src/arbitration/interfaces/IDisputeTemplateRegistry.sol @@ -2,8 +2,6 @@ pragma solidity 0.8.18; -import "./IArbitratorV2.sol"; - /// @title IDisputeTemplate /// @notice Dispute Template interface. interface IDisputeTemplateRegistry { diff --git a/contracts/src/gateway/ForeignGateway.sol b/contracts/src/gateway/ForeignGateway.sol index 6e121b330..acce881b1 100644 --- a/contracts/src/gateway/ForeignGateway.sol +++ b/contracts/src/gateway/ForeignGateway.sol @@ -11,6 +11,7 @@ pragma solidity 0.8.18; import "./interfaces/IForeignGateway.sol"; import "../proxy/UUPSProxiable.sol"; import "../proxy/Initializable.sol"; +import "../libraries/Constants.sol"; /// Foreign Gateway /// Counterpart of `HomeGateway` @@ -37,7 +38,6 @@ contract ForeignGateway is IForeignGateway, UUPSProxiable, Initializable { // * Storage * // // ************************************* // - uint256 public constant DEFAULT_NB_OF_JURORS = 3; // The default number of jurors in a dispute. uint256 internal localDisputeID; // 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. mapping(uint96 => uint256) public feeForJuror; // feeForJuror[v2CourtID], it mirrors the value on KlerosCore. address public governor; @@ -78,6 +78,9 @@ contract ForeignGateway is IForeignGateway, UUPSProxiable, Initializable { /// @dev Constructs the `PolicyRegistry` contract. /// @param _governor The governor's address. + /// @param _veaOutbox The address of the VeaOutbox. + /// @param _homeChainID The chainID of the home chain. + /// @param _homeGateway The address of the home gateway. function initialize( address _governor, address _veaOutbox, @@ -263,10 +266,10 @@ contract ForeignGateway is IForeignGateway, UUPSProxiable, Initializable { minJurors := mload(add(_extraData, 0x40)) } if (feeForJuror[courtID] == 0) courtID = 0; - if (minJurors == 0) minJurors = DEFAULT_NB_OF_JURORS; + if (minJurors == 0) minJurors = Constants.DEFAULT_NB_OF_JURORS; } else { courtID = 0; - minJurors = DEFAULT_NB_OF_JURORS; + minJurors = Constants.DEFAULT_NB_OF_JURORS; } } } diff --git a/contracts/src/gateway/HomeGateway.sol b/contracts/src/gateway/HomeGateway.sol index 86ef0d58c..5c232cd29 100644 --- a/contracts/src/gateway/HomeGateway.sol +++ b/contracts/src/gateway/HomeGateway.sol @@ -11,6 +11,7 @@ pragma solidity 0.8.18; import "./interfaces/IForeignGateway.sol"; import "./interfaces/IHomeGateway.sol"; import "../libraries/SafeERC20.sol"; +import "../libraries/Constants.sol"; import "../proxy/UUPSProxiable.sol"; import "../proxy/Initializable.sol"; @@ -32,7 +33,6 @@ contract HomeGateway is IHomeGateway, UUPSProxiable, Initializable { // * Storage * // // ************************************* // - IERC20 public constant NATIVE_CURRENCY = IERC20(address(0)); // The native currency, such as ETH on Arbitrum, Optimism and Ethereum L1. address public governor; IArbitratorV2 public arbitrator; IVeaInbox public veaInbox; @@ -64,6 +64,11 @@ contract HomeGateway is IHomeGateway, UUPSProxiable, Initializable { /// @dev Constructs the `PolicyRegistry` contract. /// @param _governor The governor's address. + /// @param _arbitrator The address of the arbitrator. + /// @param _veaInbox The address of the vea inbox. + /// @param _foreignChainID The ID of the foreign chain. + /// @param _foreignGateway The address of the foreign gateway. + /// @param _feeToken The address of the fee token. function initialize( address _governor, IArbitratorV2 _arbitrator, @@ -128,7 +133,7 @@ contract HomeGateway is IHomeGateway, UUPSProxiable, Initializable { /// @inheritdoc IHomeGateway function relayCreateDispute(RelayCreateDisputeParams memory _params) external payable override { - require(feeToken == NATIVE_CURRENCY, "Fees paid in ERC20 only"); + require(feeToken == Constants.NATIVE_CURRENCY, "Fees paid in ERC20 only"); require(_params.foreignChainID == foreignChainID, "Foreign chain ID not supported"); bytes32 disputeHash = keccak256( @@ -166,7 +171,7 @@ contract HomeGateway is IHomeGateway, UUPSProxiable, Initializable { /// @inheritdoc IHomeGateway function relayCreateDispute(RelayCreateDisputeParams memory _params, uint256 _feeAmount) external { - require(feeToken != NATIVE_CURRENCY, "Fees paid in native currency only"); + require(feeToken != Constants.NATIVE_CURRENCY, "Fees paid in native currency only"); require(_params.foreignChainID == foreignChainID, "Foreign chain ID not supported"); bytes32 disputeHash = keccak256( diff --git a/contracts/src/libraries/Constants.sol b/contracts/src/libraries/Constants.sol index 72788b3ec..3f0b41409 100644 --- a/contracts/src/libraries/Constants.sol +++ b/contracts/src/libraries/Constants.sol @@ -2,6 +2,8 @@ pragma solidity 0.8.18; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; + /// @title Constants library Constants { // Courts @@ -14,4 +16,5 @@ library Constants { // Defaults uint256 public constant DEFAULT_NB_OF_JURORS = 3; // The default number of jurors in a dispute. + IERC20 public constant NATIVE_CURRENCY = IERC20(address(0)); // The native currency, such as ETH on Arbitrum, Optimism and Ethereum L1. } diff --git a/contracts/src/proxy/Initializable.sol b/contracts/src/proxy/Initializable.sol index f1fa5f1db..e9fc1eb05 100644 --- a/contracts/src/proxy/Initializable.sol +++ b/contracts/src/proxy/Initializable.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -// OpenZeppelin Contracts (last updated v4.9.0) (proxy/utils/Initializable.sol) +// OpenZeppelin Contracts (last updated v4.9.0) (proxy/utils/Initializable.sol) pragma solidity 0.8.18; @@ -43,6 +43,12 @@ pragma solidity 0.8.18; * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed: * + * ``` + * /// @custom:oz-upgrades-unsafe-allow constructor + * constructor() { + * _disableInitializers(); + * } + * ``` */ abstract contract Initializable { /** diff --git a/contracts/src/proxy/UUPSProxiable.sol b/contracts/src/proxy/UUPSProxiable.sol index fd94df7b7..ad45d3505 100644 --- a/contracts/src/proxy/UUPSProxiable.sol +++ b/contracts/src/proxy/UUPSProxiable.sol @@ -1,5 +1,5 @@ //SPDX-License-Identifier: MIT -// Adapted from +// Adapted from /** * @authors: [@malatrax] diff --git a/contracts/src/proxy/UUPSProxy.sol b/contracts/src/proxy/UUPSProxy.sol index 375c6e11c..95ea941b9 100644 --- a/contracts/src/proxy/UUPSProxy.sol +++ b/contracts/src/proxy/UUPSProxy.sol @@ -1,5 +1,5 @@ //SPDX-License-Identifier: MIT -// Adapted from +// Adapted from /** * @authors: [@malatrax] diff --git a/contracts/test/proxy/index.ts b/contracts/test/proxy/index.ts index dbb3b4c7e..f9d5cca41 100644 --- a/contracts/test/proxy/index.ts +++ b/contracts/test/proxy/index.ts @@ -1,6 +1,5 @@ import { expect } from "chai"; -import { ethers, deployments, getNamedAccounts } from "hardhat"; -const hre = require("hardhat"); +import { ethers, deployments } from "hardhat"; let deployer; let user1; diff --git a/yarn.lock b/yarn.lock index 141c94cad..aed203c19 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5290,7 +5290,7 @@ __metadata: graphql-request: ^6.1.0 hardhat: ^2.15.0 hardhat-contract-sizer: ^2.10.0 - hardhat-deploy: ^0.11.37 + hardhat-deploy: ^0.11.42 hardhat-deploy-ethers: ^0.4.0-next.1 hardhat-deploy-tenderly: ^0.2.0 hardhat-docgen: ^1.3.0 @@ -18011,9 +18011,9 @@ __metadata: languageName: node linkType: hard -"hardhat-deploy@npm:^0.11.37": - version: 0.11.37 - resolution: "hardhat-deploy@npm:0.11.37" +"hardhat-deploy@npm:^0.11.42": + version: 0.11.42 + resolution: "hardhat-deploy@npm:0.11.42" dependencies: "@ethersproject/abi": ^5.7.0 "@ethersproject/abstract-signer": ^5.7.0 @@ -18039,7 +18039,7 @@ __metadata: murmur-128: ^0.2.1 qs: ^6.9.4 zksync-web3: ^0.14.3 - checksum: c338289849f26530296be648c7bfc2d4673d0786855ed256ee9cc864f40b94125cfa36808bedfbae4f2bad7adc38def7547bbeb3b84cbfb0aeabae04de5238fd + checksum: b5ee4d9e8716a7f359be9c222942531adccb28fa5e4a8f4d9e3f33b5b2b13bd13f8aa190f8fbe50072d817b9f8731909b507cad19b692b8814c991795f5a0d73 languageName: node linkType: hard