Skip to content

Commit 92f1c42

Browse files
committed
fix: minor, switched to another rng temporarily
1 parent 19cf159 commit 92f1c42

File tree

7 files changed

+161
-27
lines changed

7 files changed

+161
-27
lines changed

contracts/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ Refresh the list of deployed contracts by running `./scripts/generateDeployments
6767

6868
- [PNK](https://goerli.arbiscan.io/token/0x3483FA1b87792cd5BE4100822C4eCEC8D3E531ee)
6969
- [ArbitrableExample](https://goerli.arbiscan.io/address/0x5d96ede4D4Dd4c245d6879A4D790fF0AB1F476cC)
70+
- [BlockHashRNG](https://goerli.arbiscan.io/address/0xCea37c9A838831F6B4eE3BffbDC21b945113AD0C)
7071
- [DAI](https://goerli.arbiscan.io/address/0xB755843e26F2cD1c6A46659cEBb67CcFAE0f2EeE)
7172
- [DAIFaucet](https://goerli.arbiscan.io/address/0xCEBF1e0A5921767dd97b999ed14801A3770afAfd)
7273
- [DisputeKitClassic: proxy](https://goerli.arbiscan.io/address/0x6394A70cADD1376FdE5C38bA331761256DDd03E2), [implementation](https://goerli.arbiscan.io/address/0x9755b94c2c8AB04dDc7d102A6F8c974f538481fb)

contracts/deploy/00-home-chain-arbitration.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { DeployFunction } from "hardhat-deploy/types";
33
import { BigNumber } from "ethers";
44
import getContractAddress from "./utils/getContractAddress";
55
import { deployUpgradable } from "./utils/deployUpgradable";
6-
import { HomeChains, isSkipped } from "./utils";
6+
import { HomeChains, isSkipped, isDevnet } from "./utils";
77

88
const pnkByChain = new Map<HomeChains, string>([
99
[HomeChains.ARBITRUM_ONE, "0x330bD769382cFc6d50175903434CCC8D206DCAE5"],
@@ -69,17 +69,12 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
6969
klerosCoreAddress = getContractAddress(deployer, nonce + 3); // deployed on the 4th tx (nonce+3): SortitionModule Impl tx, SortitionModule Proxy tx, KlerosCore Impl tx, KlerosCore Proxy tx
7070
console.log("calculated future KlerosCore address for nonce %d: %s", nonce + 3, klerosCoreAddress);
7171
}
72-
72+
const devnet = isDevnet(hre.network);
73+
const minStakingTime = devnet ? 180 : 1800;
74+
const maxFreezingTime = devnet ? 600 : 1800;
7375
const sortitionModule = await deployUpgradable(hre, "SortitionModule", {
7476
from: deployer,
75-
args: [
76-
deployer,
77-
klerosCoreAddress,
78-
1800, // minStakingTime
79-
1800, // maxFreezingTime
80-
rng.address,
81-
RNG_LOOKAHEAD,
82-
],
77+
args: [deployer, klerosCoreAddress, minStakingTime, maxFreezingTime, rng.address, RNG_LOOKAHEAD],
8378
log: true,
8479
}); // nonce (implementation), nonce+1 (proxy)
8580

contracts/deploy/00-rng.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@ import { HardhatRuntimeEnvironment } from "hardhat/types";
22
import { DeployFunction } from "hardhat-deploy/types";
33
import { SortitionModule, RandomizerRNG } from "../typechain-types";
44
import { HomeChains, isSkipped } from "./utils";
5+
import { deployUpgradable } from "./utils/deployUpgradable";
56

67
const pnkByChain = new Map<HomeChains, string>([
78
[HomeChains.ARBITRUM_ONE, "0x330bD769382cFc6d50175903434CCC8D206DCAE5"],
89
[HomeChains.ARBITRUM_GOERLI, "0x3483FA1b87792cd5BE4100822C4eCEC8D3E531ee"],
910
]);
1011

1112
const randomizerByChain = new Map<HomeChains, string>([
12-
[HomeChains.ARBITRUM_ONE, "0x00"],
13-
[HomeChains.ARBITRUM_GOERLI, "0x57F7a8aA8291A04B325F3f0d2c4d03353d3Ef25f"],
13+
[HomeChains.ARBITRUM_ONE, "0x5b8bB80f2d72D0C85caB8fB169e8170A05C94bAF"],
14+
[HomeChains.ARBITRUM_GOERLI, "0x923096Da90a3b60eb7E12723fA2E1547BA9236Bc"],
1415
]);
1516

1617
const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
@@ -47,9 +48,10 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
4748
}
4849

4950
const randomizer = randomizerByChain.get(Number(await getChainId())) ?? AddressZero;
50-
const rng = await deploy("RandomizerRNG", {
51+
await deployUpgradable(hre, "RandomizerRNG", { from: deployer, args: [randomizer, deployer], log: true });
52+
const rng = await deploy("BlockHashRNG", {
5153
from: deployer,
52-
args: [randomizer, deployer],
54+
args: [],
5355
log: true,
5456
});
5557

contracts/deploy/utils/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ export enum Courts {
2525
GENERAL = 1,
2626
}
2727

28+
export const isDevnet = (network: Network) => network.name.endsWith("Devnet");
29+
2830
export const isSkipped = async (network: Network, skip: boolean) => {
2931
if (skip) {
3032
console.error(`Error: incompatible network ${network.name} for this deployment script`);
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
{
2+
"address": "0xCea37c9A838831F6B4eE3BffbDC21b945113AD0C",
3+
"abi": [
4+
{
5+
"inputs": [
6+
{
7+
"internalType": "uint256",
8+
"name": "",
9+
"type": "uint256"
10+
}
11+
],
12+
"name": "randomNumbers",
13+
"outputs": [
14+
{
15+
"internalType": "uint256",
16+
"name": "",
17+
"type": "uint256"
18+
}
19+
],
20+
"stateMutability": "view",
21+
"type": "function"
22+
},
23+
{
24+
"inputs": [
25+
{
26+
"internalType": "uint256",
27+
"name": "_block",
28+
"type": "uint256"
29+
}
30+
],
31+
"name": "receiveRandomness",
32+
"outputs": [
33+
{
34+
"internalType": "uint256",
35+
"name": "randomNumber",
36+
"type": "uint256"
37+
}
38+
],
39+
"stateMutability": "nonpayable",
40+
"type": "function"
41+
},
42+
{
43+
"inputs": [
44+
{
45+
"internalType": "uint256",
46+
"name": "_block",
47+
"type": "uint256"
48+
}
49+
],
50+
"name": "requestRandomness",
51+
"outputs": [],
52+
"stateMutability": "nonpayable",
53+
"type": "function"
54+
}
55+
],
56+
"transactionHash": "0x2fe708909f7af98d318c248b2229bfef4e65c67bf067b7e2d4414a12515a78b9",
57+
"receipt": {
58+
"to": null,
59+
"from": "0xF50E77f2A2B6138D16c6c7511562E5C33c4B15A3",
60+
"contractAddress": "0xCea37c9A838831F6B4eE3BffbDC21b945113AD0C",
61+
"transactionIndex": 1,
62+
"gasUsed": "131155",
63+
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
64+
"blockHash": "0x4b0fd3aabf2668022d0df7bdc17463205474b86fad947eaccf7eafa694fca724",
65+
"transactionHash": "0x2fe708909f7af98d318c248b2229bfef4e65c67bf067b7e2d4414a12515a78b9",
66+
"logs": [],
67+
"blockNumber": 47071848,
68+
"cumulativeGasUsed": "131155",
69+
"status": 1,
70+
"byzantium": true
71+
},
72+
"args": [],
73+
"numDeployments": 1,
74+
"solcInputHash": "59b40cda2fa06bf780452318a34d868f",
75+
"metadata": "{\"compiler\":{\"version\":\"0.8.18+commit.87f61d96\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"name\":\"randomNumbers\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"_block\",\"type\":\"uint256\"}],\"name\":\"receiveRandomness\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"randomNumber\",\"type\":\"uint256\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"_block\",\"type\":\"uint256\"}],\"name\":\"requestRandomness\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}],\"devdoc\":{\"author\":\"Cl\\u00e9ment Lesaege - <clement@lesaege.com>\",\"details\":\"Random Number Generator returning the blockhash with a fallback behaviour. In case no one called it within the 256 blocks, it returns the previous blockhash. This contract must be used when returning 0 is a worse failure mode than returning another blockhash. Allows saving the random number for use in the future. It allows the contract to still access the blockhash even after 256 blocks.\",\"kind\":\"dev\",\"methods\":{\"receiveRandomness(uint256)\":{\"details\":\"Return the random number. If it has not been saved and is still computable compute it.\",\"params\":{\"_block\":\"Block the random number is linked to.\"},\"returns\":{\"randomNumber\":\"The random number or 0 if it is not ready or has not been requested.\"}},\"requestRandomness(uint256)\":{\"details\":\"Request a random number.\",\"params\":{\"_block\":\"Block the random number is linked to.\"}}},\"title\":\"Random Number Generator using blockhash with fallback.\",\"version\":1},\"userdoc\":{\"kind\":\"user\",\"methods\":{},\"version\":1}},\"settings\":{\"compilationTarget\":{\"src/rng/BlockhashRNG.sol\":\"BlockHashRNG\"},\"evmVersion\":\"paris\",\"libraries\":{},\"metadata\":{\"bytecodeHash\":\"ipfs\",\"useLiteralContent\":true},\"optimizer\":{\"enabled\":true,\"runs\":100},\"remappings\":[]},\"sources\":{\"src/rng/BlockhashRNG.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n\\npragma solidity 0.8.18;\\n\\nimport \\\"./RNG.sol\\\";\\n\\n/// @title Random Number Generator using blockhash with fallback.\\n/// @author Cl\\u00e9ment Lesaege - <clement@lesaege.com>\\n/// @dev\\n/// Random Number Generator returning the blockhash with a fallback behaviour.\\n/// In case no one called it within the 256 blocks, it returns the previous blockhash.\\n/// This contract must be used when returning 0 is a worse failure mode than returning another blockhash.\\n/// Allows saving the random number for use in the future. It allows the contract to still access the blockhash even after 256 blocks.\\ncontract BlockHashRNG is RNG {\\n mapping(uint256 => uint256) public randomNumbers; // randomNumbers[block] is the random number for this block, 0 otherwise.\\n\\n /// @dev Request a random number.\\n /// @param _block Block the random number is linked to.\\n function requestRandomness(uint256 _block) external override {\\n // nop\\n }\\n\\n /// @dev Return the random number. If it has not been saved and is still computable compute it.\\n /// @param _block Block the random number is linked to.\\n /// @return randomNumber The random number or 0 if it is not ready or has not been requested.\\n function receiveRandomness(uint256 _block) external override returns (uint256 randomNumber) {\\n randomNumber = randomNumbers[_block];\\n if (randomNumber != 0) {\\n return randomNumber;\\n }\\n\\n if (_block < block.number) {\\n // The random number is not already set and can be.\\n if (blockhash(_block) != 0x0) {\\n // Normal case.\\n randomNumber = uint256(blockhash(_block));\\n } else {\\n // The contract was not called in time. Fallback to returning previous blockhash.\\n randomNumber = uint256(blockhash(block.number - 1));\\n }\\n }\\n randomNumbers[_block] = randomNumber;\\n }\\n}\\n\",\"keccak256\":\"0xbec8950b4a908f498273fb7c678f66ffbe08433009d5161545de9a3369eae1ea\",\"license\":\"MIT\"},\"src/rng/RNG.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\n\\npragma solidity 0.8.18;\\n\\ninterface RNG {\\n /// @dev Request a random number.\\n /// @param _block Block linked to the request.\\n function requestRandomness(uint256 _block) external;\\n\\n /// @dev Receive the random number.\\n /// @param _block Block the random number is linked to.\\n /// @return randomNumber Random Number. If the number is not ready or has not been required 0 instead.\\n function receiveRandomness(uint256 _block) external returns (uint256 randomNumber);\\n}\\n\",\"keccak256\":\"0x5afe7121f49aebe72218df356bd91b66c2171b9ad15e7945a15a091784291a43\",\"license\":\"MIT\"}},\"version\":1}",
76+
"bytecode": "0x608060405234801561001057600080fd5b50610169806100206000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c806313cf9054146100465780635257cd901461006b5780637363ae1f1461008b575b600080fd5b6100596100543660046100f3565b61009e565b60405190815260200160405180910390f35b6100596100793660046100f3565b60006020819052908152604090205481565b61009c6100993660046100f3565b50565b005b60008181526020819052604090205480156100b857919050565b438210156100de578140156100cf575080406100de565b6100da60014361010c565b4090505b60009182526020829052604090912081905590565b60006020828403121561010557600080fd5b5035919050565b8181038181111561012d57634e487b7160e01b600052601160045260246000fd5b9291505056fea2646970667358221220d8343029f3281984aa61880b071de45f3d714f660c2a6c1973b488429c50c84e64736f6c63430008120033",
77+
"deployedBytecode": "0x608060405234801561001057600080fd5b50600436106100415760003560e01c806313cf9054146100465780635257cd901461006b5780637363ae1f1461008b575b600080fd5b6100596100543660046100f3565b61009e565b60405190815260200160405180910390f35b6100596100793660046100f3565b60006020819052908152604090205481565b61009c6100993660046100f3565b50565b005b60008181526020819052604090205480156100b857919050565b438210156100de578140156100cf575080406100de565b6100da60014361010c565b4090505b60009182526020829052604090912081905590565b60006020828403121561010557600080fd5b5035919050565b8181038181111561012d57634e487b7160e01b600052601160045260246000fd5b9291505056fea2646970667358221220d8343029f3281984aa61880b071de45f3d714f660c2a6c1973b488429c50c84e64736f6c63430008120033",
78+
"devdoc": {
79+
"author": "Clément Lesaege - <clement@lesaege.com>",
80+
"details": "Random Number Generator returning the blockhash with a fallback behaviour. In case no one called it within the 256 blocks, it returns the previous blockhash. This contract must be used when returning 0 is a worse failure mode than returning another blockhash. Allows saving the random number for use in the future. It allows the contract to still access the blockhash even after 256 blocks.",
81+
"kind": "dev",
82+
"methods": {
83+
"receiveRandomness(uint256)": {
84+
"details": "Return the random number. If it has not been saved and is still computable compute it.",
85+
"params": {
86+
"_block": "Block the random number is linked to."
87+
},
88+
"returns": {
89+
"randomNumber": "The random number or 0 if it is not ready or has not been requested."
90+
}
91+
},
92+
"requestRandomness(uint256)": {
93+
"details": "Request a random number.",
94+
"params": {
95+
"_block": "Block the random number is linked to."
96+
}
97+
}
98+
},
99+
"title": "Random Number Generator using blockhash with fallback.",
100+
"version": 1
101+
},
102+
"userdoc": {
103+
"kind": "user",
104+
"methods": {},
105+
"version": 1
106+
},
107+
"storageLayout": {
108+
"storage": [
109+
{
110+
"astId": 22380,
111+
"contract": "src/rng/BlockhashRNG.sol:BlockHashRNG",
112+
"label": "randomNumbers",
113+
"offset": 0,
114+
"slot": "0",
115+
"type": "t_mapping(t_uint256,t_uint256)"
116+
}
117+
],
118+
"types": {
119+
"t_mapping(t_uint256,t_uint256)": {
120+
"encoding": "mapping",
121+
"key": "t_uint256",
122+
"label": "mapping(uint256 => uint256)",
123+
"numberOfBytes": "32",
124+
"value": "t_uint256"
125+
},
126+
"t_uint256": {
127+
"encoding": "inplace",
128+
"label": "uint256",
129+
"numberOfBytes": "32"
130+
}
131+
}
132+
}
133+
}

contracts/scripts/keeperBot.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,7 @@ const getDisputesWithContributionsNotYetWithdrawn = async (): Promise<Dispute[]>
146146
};
147147

148148
const handleError = (e: any) => {
149-
if (typeof e === "string") {
150-
logger.error(e, "Failure");
151-
} else if (e instanceof Error) {
152-
logger.error(e, "Failure");
153-
}
149+
logger.error(e, "Failure");
154150
};
155151

156152
const isRngReady = async () => {
@@ -172,7 +168,8 @@ const passPhase = async () => {
172168
try {
173169
await sortition.callStatic.passPhase();
174170
} catch (e) {
175-
logger.info(`passPhase: not ready yet because of ${(e as CustomError).reason}`);
171+
const error = e as CustomError;
172+
logger.info(`passPhase: not ready yet because of ${error?.reason ?? error?.errorName ?? error?.code}`);
176173
return success;
177174
}
178175
const before = await sortition.phase();
@@ -196,7 +193,12 @@ const passPeriod = async (dispute: { id: string }) => {
196193
try {
197194
await core.callStatic.passPeriod(dispute.id);
198195
} catch (e) {
199-
logger.info(`passPeriod: not ready yet for dispute ${dispute.id} because of error ${(e as CustomError).errorName}`);
196+
const error = e as CustomError;
197+
logger.info(
198+
`passPeriod: not ready yet for dispute ${dispute.id} because of error ${
199+
error?.reason ?? error?.errorName ?? error?.code
200+
}`
201+
);
200202
return success;
201203
}
202204
const before = (await core.disputes(dispute.id)).period;
@@ -478,7 +480,6 @@ async function main() {
478480
logger.info(`Dispute #${dispute.id}, round #${dispute.currentRoundIndex}, ${dispute.period} period`);
479481
}
480482
logger.info(`Disputes needing more jurors: ${disputesWithoutJurors.map((dispute) => dispute.id)}`);
481-
482483
if ((await hasMinStakingTimePassed()) && disputesWithoutJurors.length > 0) {
483484
// ----------------------------------------------- //
484485
// DRAWING ATTEMPT //

yarn.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5371,7 +5371,7 @@ __metadata:
53715371
"@kleros/kleros-v2-eslint-config": "workspace:^"
53725372
"@kleros/kleros-v2-prettier-config": "workspace:^"
53735373
"@kleros/kleros-v2-tsconfig": "workspace:^"
5374-
"@kleros/ui-components-library": ^2.6.2
5374+
"@kleros/ui-components-library": ^2.6.3
53755375
"@netlify/functions": ^1.6.0
53765376
"@parcel/transformer-svg-react": 2.8.3
53775377
"@parcel/watcher": ~2.2.0
@@ -5429,9 +5429,9 @@ __metadata:
54295429
languageName: unknown
54305430
linkType: soft
54315431

5432-
"@kleros/ui-components-library@npm:^2.6.2":
5433-
version: 2.6.2
5434-
resolution: "@kleros/ui-components-library@npm:2.6.2"
5432+
"@kleros/ui-components-library@npm:^2.6.3":
5433+
version: 2.6.3
5434+
resolution: "@kleros/ui-components-library@npm:2.6.3"
54355435
dependencies:
54365436
"@datepicker-react/hooks": ^2.8.4
54375437
"@swc/helpers": ^0.3.2
@@ -5448,7 +5448,7 @@ __metadata:
54485448
react-dom: ^18.0.0
54495449
react-is: ^18.0.0
54505450
styled-components: ^5.3.3
5451-
checksum: 499478dcacb825569d56f752de90954c58a737525a677b87645e330294ccd1f3d58bbc7b78b4cfb3bab8c0326eabc8f24fbad59c8db810e214791dbe8d4ea476
5451+
checksum: 090e9e137283b22adad531f9f0917b5cb9d56f165647e579031dc20856913b45955539cb42b89b4392fadf7ef956b3a3b9468d3441d76a0328f2a774431f6002
54525452
languageName: node
54535453
linkType: hard
54545454

0 commit comments

Comments
 (0)