Skip to content

Dispute kits refactor with shared classic logic + Upgradability improvements #1805

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jan 22, 2025
2 changes: 1 addition & 1 deletion contracts/deploy/00-home-chain-arbitration-neo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
deployer,
deployer,
pnk.target,
ZeroAddress, // KlerosCore is configured later
ZeroAddress, // jurorProsecutionModule is not implemented yet
disputeKit.address,
false,
[minStake, alpha, feeForJuror, jurorsForCourtJump],
Expand Down
34 changes: 34 additions & 0 deletions contracts/deploy/upgrade-dispute-kit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { DeployFunction } from "hardhat-deploy/types";
import { deployUpgradable } from "./utils/deployUpgradable";
import { HomeChains, isSkipped } from "./utils";

const deployUpgradeDisputeKit: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
const { deployments, getNamedAccounts, getChainId } = hre;

// fallback to hardhat node signers on local network
const deployer = (await getNamedAccounts()).deployer ?? (await hre.ethers.getSigners())[0].address;
const chainId = Number(await getChainId());
console.log("upgrading on %s with deployer %s", HomeChains[chainId], deployer);

try {
console.log("upgrading DisputeKitClassicNeo...");
await deployUpgradable(deployments, "DisputeKitClassicNeo", {
contract: "DisputeKitClassic",
initializer: "initialize",
from: deployer,
// Warning: do not reinitialize everything, only the new variables
args: [],
});
} catch (err) {
console.error(err);
throw err;
}
};

deployUpgradeDisputeKit.tags = ["Upgrade", "DisputeKit"];
deployUpgradeDisputeKit.skip = async ({ network }) => {
return isSkipped(network, !HomeChains[network.config.chainId ?? 0]);
};

export default deployUpgradeDisputeKit;
31 changes: 8 additions & 23 deletions contracts/deploy/upgrade-kleros-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,21 @@ import { deployUpgradable } from "./utils/deployUpgradable";
import { HomeChains, isSkipped } from "./utils";

const deployUpgradeKlerosCore: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
const { ethers, deployments, getNamedAccounts, getChainId } = hre;
const { ZeroAddress } = hre.ethers;
const { deployments, getNamedAccounts, getChainId } = hre;

// fallback to hardhat node signers on local network
const deployer = (await getNamedAccounts()).deployer ?? (await hre.ethers.getSigners())[0].address;
const chainId = Number(await getChainId());
console.log("upgrading to %s with deployer %s", HomeChains[chainId], deployer);
console.log("upgrading on %s with deployer %s", HomeChains[chainId], deployer);

try {
const pnk = await deployments.get("PNK");
const disputeKit = await deployments.get("DisputeKitClassic");
const minStake = 2n * 10n ** 20n;
const alpha = 10000;
const feeForJuror = 10n * 17n;
const sortitionModule = await deployments.get("SortitionModule");

console.log("upgrading the KlerosCore...");
await deployUpgradable(deployments, "KlerosCore", {
console.log("upgrading KlerosCoreNeo...");
await deployUpgradable(deployments, "KlerosCoreNeo", {
newImplementation: "KlerosCoreNeo",
initializer: "initialize",
from: deployer,
args: [
deployer,
pnk,
ZeroAddress,
disputeKit.address,
false,
[minStake, alpha, feeForJuror, 256], // minStake, alpha, feeForJuror, jurorsForCourtJump
[0, 0, 0, 10], // evidencePeriod, commitPeriod, votePeriod, appealPeriod
ethers.toBeHex(5), // Extra data for sortition module will return the default value of K
sortitionModule.address,
],
// Warning: do not reinitialize everything, only the new variables
args: [],
});
} catch (err) {
console.error(err);
Expand Down
23 changes: 7 additions & 16 deletions contracts/deploy/upgrade-sortition-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,20 @@ import { HomeChains, isSkipped } from "./utils";

const deployUpgradeSortitionModule: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
const { deployments, getNamedAccounts, getChainId } = hre;
const RNG_LOOKAHEAD = 20;

// fallback to hardhat node signers on local network
const deployer = (await getNamedAccounts()).deployer ?? (await hre.ethers.getSigners())[0].address;
const chainId = Number(await getChainId());
console.log("upgrading to %s with deployer %s", HomeChains[chainId], deployer);
console.log("upgrading on %s with deployer %s", HomeChains[chainId], deployer);

try {
const rng = await deployments.get("RandomizerRNG");
const klerosCore = await deployments.get("KlerosCore");
const klerosCoreAddress = klerosCore.address;

console.log("upgrading the SortitionModule...");
await deployUpgradable(deployments, "SortitionModule", {
console.log("upgrading SortitionModuleNeo...");
await deployUpgradable(deployments, "SortitionModuleNeo", {
newImplementation: "SortitionModuleNeo",
initializer: "initialize",
from: deployer,
args: [
deployer,
klerosCoreAddress,
1800, // minStakingTime
1800, // maxFreezingTime
rng.address,
RNG_LOOKAHEAD,
],
// Warning: do not reinitialize everything, only the new variables
args: [],
});
} catch (err) {
console.error(err);
Expand Down
6 changes: 3 additions & 3 deletions contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ const config: HardhatUserConfig = {
// Home chain ---------------------------------------------------------------------------------
arbitrumSepolia: {
chainId: 421614,
url: process.env.ARBITRUM_SEPOLIA_RPC ?? "https://sepolia-rollup.arbitrum.io/rpc",
url: process.env.ARBITRUM_SEPOLIA_RPC ?? `https://arbitrum-sepolia.infura.io/v3/${process.env.INFURA_API_KEY}`,
accounts:
(process.env.ARB_GOERLI_PRIVATE_KEY_WALLET_1 && [
process.env.ARB_GOERLI_PRIVATE_KEY_WALLET_1 as string,
Expand All @@ -121,7 +121,7 @@ const config: HardhatUserConfig = {
},
arbitrumSepoliaDevnet: {
chainId: 421614,
url: process.env.ARBITRUM_SEPOLIA_RPC ?? "https://sepolia-rollup.arbitrum.io/rpc",
url: process.env.ARBITRUM_SEPOLIA_RPC ?? `https://arbitrum-sepolia.infura.io/v3/${process.env.INFURA_API_KEY}`,
accounts:
(process.env.ARB_GOERLI_PRIVATE_KEY_WALLET_1 && [
process.env.ARB_GOERLI_PRIVATE_KEY_WALLET_1 as string,
Expand All @@ -147,7 +147,7 @@ const config: HardhatUserConfig = {
},
arbitrum: {
chainId: 42161,
url: "https://arb1.arbitrum.io/rpc",
url: process.env.ARBITRUM_RPC ?? `https://arbitrum-mainnet.infura.io/v3/${process.env.INFURA_API_KEY}`,
accounts: process.env.PRIVATE_KEY !== undefined ? [process.env.PRIVATE_KEY] : [],
live: true,
saveDeployments: true,
Expand Down
14 changes: 8 additions & 6 deletions contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"start-local": "hardhat node --tags Arbitration,HomeArbitrable --hostname 0.0.0.0",
"deploy": "hardhat deploy",
"deploy-local": "hardhat deploy --tags Arbitration,HomeArbitrable --network localhost",
"validate-upgrades": "openzeppelin-upgrades-core validate --exclude 'src/proxy/mock/**/*.sol' --exclude 'src/test/**/*.sol' artifacts/build-info",
"simulate": "hardhat simulate:all",
"simulate-local": "hardhat simulate:all --network localhost",
"viem:generate-devnet": "NODE_NO_WARNINGS=1 wagmi generate -c wagmi.config.devnet.ts",
Expand Down Expand Up @@ -69,6 +70,7 @@
"@nomicfoundation/hardhat-chai-matchers": "^2.0.8",
"@nomicfoundation/hardhat-ethers": "^3.0.8",
"@nomiclabs/hardhat-solhint": "^4.0.1",
"@openzeppelin/upgrades-core": "^1.41.0",
"@typechain/ethers-v6": "^0.5.1",
"@typechain/hardhat": "^9.1.0",
"@types/chai": "^4.3.20",
Expand All @@ -80,23 +82,23 @@
"dotenv": "^16.4.5",
"eslint": "^9.15.0",
"ethereumjs-util": "^7.1.5",
"ethers": "^6.13.4",
"ethers": "^6.13.5",
"graphql": "^16.9.0",
"graphql-request": "^7.1.2",
"hardhat": "2.22.16",
"hardhat": "2.22.18",
"hardhat-contract-sizer": "^2.10.0",
"hardhat-deploy": "^0.14.0",
"hardhat-deploy-ethers": "^0.4.2",
"hardhat-deploy-tenderly": "^0.2.0",
"hardhat-deploy-tenderly": "^0.2.1",
"hardhat-docgen": "^1.3.0",
"hardhat-gas-reporter": "^2.2.1",
"hardhat-gas-reporter": "^2.2.2",
"hardhat-tracer": "^3.1.0",
"hardhat-watcher": "^2.5.0",
"node-fetch": "^3.3.2",
"pino": "^8.21.0",
"pino-pretty": "^10.3.1",
"prettier": "^3.3.3",
"prettier-plugin-solidity": "^1.4.1",
"prettier-plugin-solidity": "^1.4.2",
"shelljs": "^0.8.5",
"solhint-plugin-prettier": "^0.1.0",
"solidity-coverage": "^0.8.13",
Expand All @@ -107,7 +109,7 @@
"dependencies": {
"@chainlink/contracts": "^1.3.0",
"@kleros/vea-contracts": "^0.4.0",
"@openzeppelin/contracts": "^5.1.0",
"@openzeppelin/contracts": "^5.2.0",
"viem": "^2.21.48"
}
}
4 changes: 3 additions & 1 deletion contracts/src/arbitration/DisputeTemplateRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import "./interfaces/IDisputeTemplateRegistry.sol";
/// @title Dispute Template Registry
/// @dev A contract to maintain a registry of dispute templates.
contract DisputeTemplateRegistry is IDisputeTemplateRegistry, UUPSProxiable, Initializable {
string public constant override version = "0.8.0";

// ************************************* //
// * Storage * //
// ************************************* //
Expand All @@ -31,7 +33,7 @@ contract DisputeTemplateRegistry is IDisputeTemplateRegistry, UUPSProxiable, Ini
// * Constructor * //
// ************************************* //

/// @dev Constructor, initializing the implementation to reduce attack surface.
/// @custom:oz-upgrades-unsafe-allow constructor
constructor() {
_disableInitializers();
}
Expand Down
12 changes: 6 additions & 6 deletions contracts/src/arbitration/KlerosCore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@

pragma solidity 0.8.24;

import "./KlerosCoreBase.sol";
import {UUPSProxiable} from "../proxy/UUPSProxiable.sol";
import {Initializable} from "../proxy/Initializable.sol";
import {KlerosCoreBase, IDisputeKit, ISortitionModule, IERC20} from "./KlerosCoreBase.sol";

/// @title KlerosCore
/// Core arbitrator contract for Kleros v2.
/// Note that this contract trusts the PNK token, the dispute kit and the sortition module contracts.
contract KlerosCore is KlerosCoreBase, UUPSProxiable, Initializable {
contract KlerosCore is KlerosCoreBase {
string public constant override version = "0.8.0";

// ************************************* //
// * Constructor * //
// ************************************* //

/// @dev Constructor, initializing the implementation to reduce attack surface.
/// @custom:oz-upgrades-unsafe-allow constructor
constructor() {
_disableInitializers();
}
Expand Down Expand Up @@ -48,7 +48,7 @@ contract KlerosCore is KlerosCoreBase, UUPSProxiable, Initializable {
bytes memory _sortitionExtraData,
ISortitionModule _sortitionModuleAddress
) external reinitializer(1) {
_initialize(
__KlerosCoreBase_initialize(
_governor,
_guardian,
_pinakion,
Expand Down
8 changes: 5 additions & 3 deletions contracts/src/arbitration/KlerosCoreBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ pragma solidity 0.8.24;
import {IArbitrableV2, IArbitratorV2} from "./interfaces/IArbitratorV2.sol";
import {IDisputeKit} from "./interfaces/IDisputeKit.sol";
import {ISortitionModule} from "./interfaces/ISortitionModule.sol";
import {Initializable} from "../proxy/Initializable.sol";
import {UUPSProxiable} from "../proxy/UUPSProxiable.sol";
import {SafeERC20, IERC20} from "../libraries/SafeERC20.sol";
import "../libraries/Constants.sol";

/// @title KlerosCoreBase
/// Core arbitrator contract for Kleros v2.
/// Note that this contract trusts the PNK token, the dispute kit and the sortition module contracts.
abstract contract KlerosCoreBase is IArbitratorV2 {
abstract contract KlerosCoreBase is IArbitratorV2, Initializable, UUPSProxiable {
using SafeERC20 for IERC20;

// ************************************* //
Expand Down Expand Up @@ -193,7 +195,7 @@ abstract contract KlerosCoreBase is IArbitratorV2 {
// * Constructor * //
// ************************************* //

function _initialize(
function __KlerosCoreBase_initialize(
address _governor,
address _guardian,
IERC20 _pinakion,
Expand All @@ -204,7 +206,7 @@ abstract contract KlerosCoreBase is IArbitratorV2 {
uint256[4] memory _timesPerPeriod,
bytes memory _sortitionExtraData,
ISortitionModule _sortitionModuleAddress
) internal {
) internal onlyInitializing {
governor = _governor;
guardian = _guardian;
pinakion = _pinakion;
Expand Down
12 changes: 6 additions & 6 deletions contracts/src/arbitration/KlerosCoreNeo.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@

pragma solidity 0.8.24;

import "./KlerosCoreBase.sol";
import {UUPSProxiable} from "../proxy/UUPSProxiable.sol";
import {Initializable} from "../proxy/Initializable.sol";
import {KlerosCoreBase, IDisputeKit, ISortitionModule, IERC20, OnError, StakingResult} from "./KlerosCoreBase.sol";
import "@openzeppelin/contracts/token/ERC721/IERC721.sol";

/// @title KlerosCoreNeo
/// Core arbitrator contract for Kleros v2.
/// Note that this contract trusts the PNK token, the dispute kit and the sortition module contracts.
contract KlerosCoreNeo is KlerosCoreBase, UUPSProxiable, Initializable {
contract KlerosCoreNeo is KlerosCoreBase {
string public constant override version = "0.8.0";

// ************************************* //
// * Storage * //
// ************************************* //
Expand All @@ -28,7 +28,7 @@ contract KlerosCoreNeo is KlerosCoreBase, UUPSProxiable, Initializable {
// * Constructor * //
// ************************************* //

/// @dev Constructor, initializing the implementation to reduce attack surface.
/// @custom:oz-upgrades-unsafe-allow constructor
constructor() {
_disableInitializers();
}
Expand Down Expand Up @@ -58,7 +58,7 @@ contract KlerosCoreNeo is KlerosCoreBase, UUPSProxiable, Initializable {
ISortitionModule _sortitionModuleAddress,
IERC721 _jurorNft
) external reinitializer(2) {
super._initialize(
__KlerosCoreBase_initialize(
_governor,
_guardian,
_pinakion,
Expand Down
4 changes: 3 additions & 1 deletion contracts/src/arbitration/PolicyRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import "../proxy/Initializable.sol";
/// @title PolicyRegistry
/// @dev A contract to maintain a policy for each court.
contract PolicyRegistry is UUPSProxiable, Initializable {
string public constant override version = "0.8.0";

// ************************************* //
// * Events * //
// ************************************* //
Expand Down Expand Up @@ -38,7 +40,7 @@ contract PolicyRegistry is UUPSProxiable, Initializable {
// * Constructor * //
// ************************************* //

/// @dev Constructor, initializing the implementation to reduce attack surface.
/// @custom:oz-upgrades-unsafe-allow constructor
constructor() {
_disableInitializers();
}
Expand Down
12 changes: 6 additions & 6 deletions contracts/src/arbitration/SortitionModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@

pragma solidity 0.8.24;

import "./SortitionModuleBase.sol";
import "../proxy/UUPSProxiable.sol";
import "../proxy/Initializable.sol";
import {SortitionModuleBase, KlerosCore, RNG} from "./SortitionModuleBase.sol";

/// @title SortitionModule
/// @dev A factory of trees that keeps track of staked values for sortition.
contract SortitionModule is SortitionModuleBase, UUPSProxiable, Initializable {
contract SortitionModule is SortitionModuleBase {
string public constant override version = "0.8.0";

// ************************************* //
// * Constructor * //
// ************************************* //

/// @dev Constructor, initializing the implementation to reduce attack surface.
/// @custom:oz-upgrades-unsafe-allow constructor
constructor() {
_disableInitializers();
}
Expand All @@ -41,7 +41,7 @@ contract SortitionModule is SortitionModuleBase, UUPSProxiable, Initializable {
RNG _rng,
uint256 _rngLookahead
) external reinitializer(1) {
super._initialize(_governor, _core, _minStakingTime, _maxDrawingTime, _rng, _rngLookahead);
__SortitionModuleBase_initialize(_governor, _core, _minStakingTime, _maxDrawingTime, _rng, _rngLookahead);
}

// ************************************* //
Expand Down
Loading
Loading