Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions contracts/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ The format is based on [Common Changelog](https://common-changelog.org/).
### Changed

- **Breaking:** Replace `require()` with `revert()` and custom errors outside KlerosCore for consistency and smaller bytecode ([#2084](https://github.com/kleros/kleros-v2/issues/2084))
- **Breaking:** Rename the interface from `RNG` to `IRNG` ([#2054](https://github.com/kleros/kleros-v2/issues/2054))
- **Breaking:** Remove the `_block` parameter from `IRNG.requestRandomness()` and `IRNG.receiveRandomness()`, not needed for the primary VRF-based RNG ([#2054](https://github.com/kleros/kleros-v2/issues/2054))
- Make the primary VRF-based RNG fall back to `BlockhashRNG` if the VRF request is not fulfilled within a timeout ([#2054](https://github.com/kleros/kleros-v2/issues/2054))
- Authenticate the calls to the RNGs to prevent 3rd parties from depleting the Chainlink VRF subscription funds ([#2054](https://github.com/kleros/kleros-v2/issues/2054))
- Use `block.timestamp` rather than `block.number` for `BlockhashRNG` for better reliability on Arbitrum as block production is sporadic depending on network conditions. ([#2054](https://github.com/kleros/kleros-v2/issues/2054))
- Set the Hardhat Solidity version to v0.8.30 and enable the IR pipeline ([#2069](https://github.com/kleros/kleros-v2/issues/2069))
- Set the Foundry Solidity version to v0.8.30 and enable the IR pipeline ([#2073](https://github.com/kleros/kleros-v2/issues/2073))
- Widen the allowed solc version to any v0.8.x for the interfaces only ([#2083](https://github.com/kleros/kleros-v2/issues/2083))
Expand Down
31 changes: 0 additions & 31 deletions contracts/deploy/00-ethereum-pnk.ts

This file was deleted.

18 changes: 8 additions & 10 deletions contracts/deploy/00-home-chain-arbitration-neo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ import { changeCurrencyRate } from "./utils/klerosCoreHelper";
import { HomeChains, isSkipped, isDevnet, PNK, ETH } from "./utils";
import { getContractOrDeploy, getContractOrDeployUpgradable } from "./utils/getContractOrDeploy";
import { deployERC20AndFaucet, deployERC721 } from "./utils/deployTokens";
import { ChainlinkRNG, DisputeKitClassic, KlerosCoreNeo } from "../typechain-types";
import { ChainlinkRNG, DisputeKitClassic, KlerosCoreNeo, RNGWithFallback } from "../typechain-types";

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

// fallback to hardhat node signers on local network
const deployer = (await getNamedAccounts()).deployer ?? (await hre.ethers.getSigners())[0].address;
Expand Down Expand Up @@ -45,7 +44,7 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
const devnet = isDevnet(hre.network);
const minStakingTime = devnet ? 180 : 1800;
const maxFreezingTime = devnet ? 600 : 1800;
const rng = (await ethers.getContract("ChainlinkRNG")) as ChainlinkRNG;
const rngWithFallback = await ethers.getContract<RNGWithFallback>("RNGWithFallback");
const maxStakePerJuror = PNK(2_000);
const maxTotalStaked = PNK(2_000_000);
const sortitionModule = await deployUpgradable(deployments, "SortitionModuleNeo", {
Expand All @@ -55,8 +54,7 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
klerosCoreAddress,
minStakingTime,
maxFreezingTime,
rng.target,
RNG_LOOKAHEAD,
rngWithFallback.target,
maxStakePerJuror,
maxTotalStaked,
],
Expand Down Expand Up @@ -94,11 +92,11 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
await disputeKitContract.changeCore(klerosCore.address);
}

// rng.changeSortitionModule() only if necessary
const rngSortitionModule = await rng.sortitionModule();
if (rngSortitionModule !== sortitionModule.address) {
console.log(`rng.changeSortitionModule(${sortitionModule.address})`);
await rng.changeSortitionModule(sortitionModule.address);
// rngWithFallback.changeConsumer() only if necessary
const rngConsumer = await rngWithFallback.consumer();
if (rngConsumer !== sortitionModule.address) {
console.log(`rngWithFallback.changeConsumer(${sortitionModule.address})`);
await rngWithFallback.changeConsumer(sortitionModule.address);
}

const core = (await hre.ethers.getContract("KlerosCoreNeo")) as KlerosCoreNeo;
Expand Down
19 changes: 9 additions & 10 deletions contracts/deploy/00-home-chain-arbitration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ import { changeCurrencyRate } from "./utils/klerosCoreHelper";
import { HomeChains, isSkipped, isDevnet, PNK, ETH, Courts } from "./utils";
import { getContractOrDeploy, getContractOrDeployUpgradable } from "./utils/getContractOrDeploy";
import { deployERC20AndFaucet } from "./utils/deployTokens";
import { ChainlinkRNG, DisputeKitClassic, KlerosCore } from "../typechain-types";
import { ChainlinkRNG, DisputeKitClassic, KlerosCore, RNGWithFallback } from "../typechain-types";

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

// fallback to hardhat node signers on local network
const deployer = (await getNamedAccounts()).deployer ?? (await hre.ethers.getSigners())[0].address;
Expand Down Expand Up @@ -50,10 +49,10 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
const devnet = isDevnet(hre.network);
const minStakingTime = devnet ? 180 : 1800;
const maxFreezingTime = devnet ? 600 : 1800;
const rng = (await ethers.getContract("ChainlinkRNG")) as ChainlinkRNG;
const rngWithFallback = await ethers.getContract<RNGWithFallback>("RNGWithFallback");
const sortitionModule = await deployUpgradable(deployments, "SortitionModule", {
from: deployer,
args: [deployer, klerosCoreAddress, minStakingTime, maxFreezingTime, rng.target, RNG_LOOKAHEAD],
args: [deployer, klerosCoreAddress, minStakingTime, maxFreezingTime, rngWithFallback.target],
log: true,
}); // nonce (implementation), nonce+1 (proxy)

Expand All @@ -80,18 +79,18 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
}); // nonce+2 (implementation), nonce+3 (proxy)

// disputeKit.changeCore() only if necessary
const disputeKitContract = (await ethers.getContract("DisputeKitClassic")) as DisputeKitClassic;
const disputeKitContract = await ethers.getContract<DisputeKitClassic>("DisputeKitClassic");
const currentCore = await disputeKitContract.core();
if (currentCore !== klerosCore.address) {
console.log(`disputeKit.changeCore(${klerosCore.address})`);
await disputeKitContract.changeCore(klerosCore.address);
}

// rng.changeSortitionModule() only if necessary
const rngSortitionModule = await rng.sortitionModule();
if (rngSortitionModule !== sortitionModule.address) {
console.log(`rng.changeSortitionModule(${sortitionModule.address})`);
await rng.changeSortitionModule(sortitionModule.address);
// rngWithFallback.changeConsumer() only if necessary
const rngConsumer = await rngWithFallback.consumer();
if (rngConsumer !== sortitionModule.address) {
console.log(`rngWithFallback.changeConsumer(${sortitionModule.address})`);
await rngWithFallback.changeConsumer(sortitionModule.address);
}

const core = (await hre.ethers.getContract("KlerosCore")) as KlerosCore;
Expand Down
36 changes: 0 additions & 36 deletions contracts/deploy/00-home-chain-pnk-faucet.ts

This file was deleted.

4 changes: 2 additions & 2 deletions contracts/deploy/00-home-chain-resolver.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { DeployFunction } from "hardhat-deploy/types";
import { HomeChains, isSkipped } from "./utils";
import { deployUpgradable } from "./utils/deployUpgradable";
import { getContractOrDeploy } from "./utils/getContractOrDeploy";

const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
const { deployments, getNamedAccounts, getChainId } = hre;
Expand All @@ -15,7 +15,7 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
const klerosCore = await deployments.get("KlerosCore");
const disputeTemplateRegistry = await deployments.get("DisputeTemplateRegistry");

await deploy("DisputeResolver", {
await getContractOrDeploy(hre, "DisputeResolver", {
from: deployer,
args: [klerosCore.address, disputeTemplateRegistry.address],
log: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { HardhatRuntimeEnvironment } from "hardhat/types";
import { DeployFunction } from "hardhat-deploy/types";
import { HomeChains, isSkipped } from "./utils";
import { getContractOrDeploy } from "./utils/getContractOrDeploy";
import { RNGWithFallback } from "../typechain-types";

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

// fallback to hardhat node signers on local network
const deployer = (await getNamedAccounts()).deployer ?? (await hre.ethers.getSigners())[0].address;
Expand Down Expand Up @@ -57,11 +57,16 @@ const deployRng: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
const requestConfirmations = 200; // between 1 and 200 L2 blocks
const callbackGasLimit = 100000;

await deploy("ChainlinkRNG", {
const oldRng = await ethers.getContractOrNull("ChainlinkRNG");
if (!oldRng) {
console.log("Register this Chainlink consumer here: http://vrf.chain.link/");
}

const rng = await getContractOrDeploy(hre, "ChainlinkRNG", {
from: deployer,
args: [
deployer,
deployer, // The consumer is configured as the SortitionModule later
deployer, // The consumer is configured as the RNGWithFallback later
ChainlinkVRFCoordinator.target,
keyHash,
subscriptionId,
Expand All @@ -70,6 +75,26 @@ const deployRng: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
],
log: true,
});

const fallbackTimeoutSeconds = 30 * 60; // 30 minutes
await getContractOrDeploy(hre, "RNGWithFallback", {
from: deployer,
args: [
deployer,
deployer, // The consumer is configured as the SortitionModule later
fallbackTimeoutSeconds,
rng.target,
],
log: true,
});

// rng.changeConsumer() only if necessary
const rngWithFallback = await ethers.getContract<RNGWithFallback>("RNGWithFallback");
const rngConsumer = await rng.consumer();
if (rngConsumer !== rngWithFallback.target) {
console.log(`rng.changeConsumer(${rngWithFallback.target})`);
await rng.changeConsumer(rngWithFallback.target);
}
};

deployRng.tags = ["ChainlinkRNG"];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { HardhatRuntimeEnvironment } from "hardhat/types";
import { DeployFunction } from "hardhat-deploy/types";
import { HomeChains, isSkipped } from "./utils";
import { getContractOrDeploy } from "./utils/getContractOrDeploy";
import { RNGWithFallback } from "../typechain-types";

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

// fallback to hardhat node signers on local network
const deployer = (await getNamedAccounts()).deployer ?? (await hre.ethers.getSigners())[0].address;
Expand All @@ -20,11 +20,35 @@ const deployRng: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
log: true,
});

await getContractOrDeploy(hre, "RandomizerRNG", {
const rng = await getContractOrDeploy(hre, "RandomizerRNG", {
from: deployer,
args: [deployer, deployer, randomizerOracle.target], // The consumer is configured as the SortitionModule later
args: [
deployer,
deployer, // The consumer is configured as the RNGWithFallback later
randomizerOracle.target,
],
log: true,
});

const fallbackTimeoutSeconds = 30 * 60; // 30 minutes
await getContractOrDeploy(hre, "RNGWithFallback", {
from: deployer,
args: [
deployer,
deployer, // The consumer is configured as the SortitionModule later
fallbackTimeoutSeconds,
rng.target,
],
log: true,
});

// rng.changeConsumer() only if necessary
const rngWithFallback = await ethers.getContract<RNGWithFallback>("RNGWithFallback");
const rngConsumer = await rng.consumer();
if (rngConsumer !== rngWithFallback.target) {
console.log(`rng.changeConsumer(${rngWithFallback.target})`);
await rng.changeConsumer(rngWithFallback.target);
}
};

deployRng.tags = ["RandomizerRNG"];
Expand Down
47 changes: 0 additions & 47 deletions contracts/deploy/00-rng.ts

This file was deleted.

8 changes: 4 additions & 4 deletions contracts/deploy/change-sortition-module-rng.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ const task: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
sortitionModule = await ethers.getContract<SortitionModule>("SortitionModule");
}

console.log(`chainlinkRng.changeSortitionModule(${sortitionModule.target})`);
await chainlinkRng.changeSortitionModule(sortitionModule.target);
console.log(`chainlinkRng.changeConsumer(${sortitionModule.target})`);
await chainlinkRng.changeConsumer(sortitionModule.target);

console.log(`sortitionModule.changeRandomNumberGenerator(${chainlinkRng.target}, 0)`);
await sortitionModule.changeRandomNumberGenerator(chainlinkRng.target, 0);
console.log(`sortitionModule.changeRandomNumberGenerator(${chainlinkRng.target})`);
await sortitionModule.changeRandomNumberGenerator(chainlinkRng.target);
};

task.tags = ["ChangeSortitionModuleRNG"];
Expand Down
Loading
Loading