Skip to content

Commit 8a8bd69

Browse files
committed
Merge branch 'master' into feat/subgraph
2 parents e2f04cb + 324c4d1 commit 8a8bd69

File tree

113 files changed

+4185
-9019
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

113 files changed

+4185
-9019
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,9 @@ tags
173173
.history
174174
.ionide
175175

176+
# Ignore the .DS_Store file
177+
.DS_Store
178+
176179
# Support for Project snippet scope
177180
!.vscode/*.code-snippets
178181

CONTRIBUTING.md

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
## Contribution Guidelines
2+
3+
👉 Please start by reading our guidelines here: https://kleros.gitbook.io/docs/contribution-guidelines/overview
4+
5+
## Opening an issue
6+
7+
You should usually open an issue in the following situations:
8+
9+
- Report an error you can’t solve yourself
10+
- Discuss a high-level topic or idea (for example, community, vision or policies)
11+
- Propose a new feature or other project idea
12+
13+
### Tips for communicating on issues:
14+
15+
- **If you see an open issue that you want to tackle,** comment on the issue to let people know you’re on it. That way, people are less likely to duplicate your work.
16+
- **If an issue was opened a while ago,** it’s possible that it’s being addressed somewhere else, or has already been resolved, so comment to ask for confirmation before starting work.
17+
- **If you opened an issue, but figured out the answer later on your own,** comment on the issue to let people know, then close the issue. Even documenting that outcome is a contribution to the project.
18+
19+
## Opening a pull request
20+
21+
You should usually open a pull request in the following situations:
22+
23+
- Submit trivial fixes (for example, a typo, a broken link or an obvious error).
24+
- Start work on a contribution that was already asked for, or that you’ve already discussed, in an issue.
25+
26+
A pull request doesn’t have to represent finished work. It’s usually better to open a _draft_ pull request early on, so others can watch or give feedback on your progress. Just mark it as a “WIP” (Work in Progress) in the subject line. You can always add more commits later.
27+
28+
As a contributor who is not an organization member, here’s how to submit a pull request:
29+
30+
- **Fork the repository** and clone it locally. Connect your local to the original repository by adding it as a remote. Pull in changes from this repository often so that you stay up to date so that when you submit your pull request, merge conflicts will be less likely.
31+
- **Create a branch** for your edits.
32+
- **Reference any relevant issues** or supporting documentation in your PR (for example, “Closes #37.”)
33+
- **Include screenshots of the before and after** if your changes include differences in HTML/CSS. Drag and drop the images into the body of your pull request.
34+
- **Test your changes!** Run your changes against any existing tests if they exist and create new ones when needed. Whether tests exist or not, make sure your changes don’t break the existing project.
35+
- **Contribute in the style of the project** to the best of your abilities. This may mean using indents, semi-colons or comments differently than you would in your own repository, but makes it easier for the maintainer to merge, others to understand and maintain in the future.
36+
37+
If you are an organization member, a branch can be created directly in this repository, there is no need to fork it.

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99
</p>
1010

1111
<p align="center">
12+
<a href="https://sonarcloud.io/summary/new_code?id=kleros_kleros-v2"><img src="https://sonarcloud.io/api/project_badges/measure?project=kleros_kleros-v2&metric=security_rating" alt="Security Rating"></a>
13+
<a href="https://sonarcloud.io/summary/new_code?id=kleros_kleros-v2"><img src="https://sonarcloud.io/api/project_badges/measure?project=kleros_kleros-v2&metric=alert_status" alt="Quality Gate Status"></a>
14+
<a href="https://sonarcloud.io/summary/new_code?id=kleros_kleros-v2"><img src="https://sonarcloud.io/api/project_badges/measure?project=kleros_kleros-v2&metric=bugs" alt="Bugs"></a>
15+
<a href="https://sonarcloud.io/summary/new_code?id=kleros_kleros-v2"><img src="https://sonarcloud.io/api/project_badges/measure?project=kleros_kleros-v2&metric=reliability_rating" alt="Reliability Rating"></a>
16+
<a href="https://sonarcloud.io/summary/new_code?id=kleros_kleros-v2"><img src="https://sonarcloud.io/api/project_badges/measure?project=kleros_kleros-v2&metric=sqale_rating" alt="Maintainability Rating"></a>
17+
</br>
1218
<a href="https://github.com/kleros/kleros-v2/actions/workflows/contracts-testing.yml"><img src="https://github.com/kleros/kleros-v2/actions/workflows/contracts-testing.yml/badge.svg?branch=master" alt="Unit testing"></a>
1319
<a href="https://conventionalcommits.org"><img src="https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg" alt="Conventional Commits"></a>
1420
<a href="http://commitizen.github.io/cz-cli/"><img src="https://img.shields.io/badge/commitizen-friendly-brightgreen.svg" alt="Commitizen Friendly"></a>

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

+12-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
2525

2626
const rng = await deploy("IncrementalNG", {
2727
from: deployer,
28+
args: [67193503189],
2829
log: true,
2930
});
3031

@@ -59,7 +60,17 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
5960
libraries: {
6061
SortitionSumTreeFactory: sortitionSumTreeLibrary.address,
6162
},
62-
args: [deployer, pnk, AddressZero, disputeKit.address, false, minStake, alpha, feeForJuror, 3, [0, 0, 0, 0], 3],
63+
args: [
64+
deployer,
65+
pnk,
66+
AddressZero,
67+
disputeKit.address,
68+
[120, 120], // minStakingTime, maxFreezingTime
69+
false,
70+
[minStake, alpha, feeForJuror, 3], // minStake, alpha, feeForJuror, jurorsForCourtJump
71+
[0, 0, 0, 0], // evidencePeriod, commitPeriod, votePeriod, appealPeriod
72+
3,
73+
],
6374
log: true,
6475
});
6576

contracts/deploy/01-foreign-chain.ts

+19-5
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,19 @@ const paramsByChainId = {
1515
claimDeposit: parseEther("0.1"),
1616
challengeDuration: 86400, // 1 day
1717
homeChainId: 42161,
18+
arbitrumInbox: "0x4Dbd4fc535Ac27206064B68FfCf827b0A60BAB3f",
1819
},
1920
4: {
2021
claimDeposit: parseEther("0.1"),
2122
challengeDuration: 120, // 2 min
2223
homeChainId: 421611,
24+
arbitrumInbox: "0x578BAde599406A8fE3d24Fd7f7211c0911F5B29e",
2325
},
2426
31337: {
2527
claimDeposit: parseEther("0.1"),
2628
challengeDuration: 120, // 2 min
2729
homeChainId: 31337,
30+
arbitrumInbox: "0x00",
2831
},
2932
};
3033

@@ -50,26 +53,35 @@ const deployForeignGateway: DeployFunction = async (hre: HardhatRuntimeEnvironme
5053
let nonce;
5154
if (chainId === ForeignChains.HARDHAT) {
5255
nonce = await ethers.provider.getTransactionCount(deployer);
53-
nonce += 4; // HomeGatewayToEthereum deploy tx will be the 6th after this, same network for both home/foreign.
56+
nonce += 5; // HomeGatewayToEthereum deploy tx will be the 6th after this, same network for both home/foreign.
5457
} else {
5558
const homeChainProvider = new providers.JsonRpcProvider(homeNetworks[chainId].url);
5659
nonce = await homeChainProvider.getTransactionCount(deployer);
5760
nonce += 1; // HomeGatewayToEthereum deploy tx will the third tx after this on its home network, so we add two to the current nonce.
5861
}
59-
const { claimDeposit, challengeDuration, homeChainId } = paramsByChainId[chainId];
62+
const { claimDeposit, challengeDuration, homeChainId, arbitrumInbox } = paramsByChainId[chainId];
6063
const challengeDeposit = claimDeposit;
6164
const bridgeAlpha = 5000;
6265
const homeChainIdAsBytes32 = hexZeroPad(homeChainId, 32);
6366

6467
const homeGatewayAddress = getContractAddress(deployer, nonce);
6568
console.log("calculated future HomeGatewayToEthereum address for nonce %d: %s", nonce, homeGatewayAddress);
69+
nonce -= 1;
70+
71+
const fastBridgeSenderAddress = getContractAddress(deployer, nonce);
72+
console.log("calculated future FastSender for nonce %d: %s", nonce, fastBridgeSenderAddress);
73+
74+
nonce += 5;
75+
76+
const inboxAddress = chainId === ForeignChains.HARDHAT ? getContractAddress(deployer, nonce) : arbitrumInbox;
77+
console.log("calculated future inboxAddress for nonce %d: %s", nonce, inboxAddress);
6678

6779
const fastBridgeReceiver = await deploy("FastBridgeReceiverOnEthereum", {
6880
from: deployer,
6981
args: [
7082
deployer,
71-
ethers.constants.AddressZero, // should be safeBridgeSender
72-
ethers.constants.AddressZero, // should be Arbitrum Inbox
83+
fastBridgeSenderAddress,
84+
inboxAddress,
7385
claimDeposit,
7486
challengeDeposit,
7587
challengeDuration,
@@ -87,12 +99,14 @@ const deployForeignGateway: DeployFunction = async (hre: HardhatRuntimeEnvironme
8799
homeGatewayAddress,
88100
homeChainIdAsBytes32,
89101
],
102+
gasLimit: 4000000,
90103
log: true,
91104
});
92105

93106
const metaEvidenceUri =
94107
"https://raw.githubusercontent.com/kleros/kleros-v2/master/contracts/deployments/rinkeby/MetaEvidence_ArbitrableExample.json";
95-
const arbitrable = await deploy("ArbitrableExample", {
108+
109+
await deploy("ArbitrableExample", {
96110
from: deployer,
97111
args: [foreignGateway.address, metaEvidenceUri],
98112
log: true,

contracts/deploy/02-home-chain.ts

+97-30
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { HardhatRuntimeEnvironment } from "hardhat/types";
22
import { DeployFunction } from "hardhat-deploy/types";
3-
import { Address } from "ethereumjs-util";
43
import { ethers } from "hardhat";
54

65
const HOME_CHAIN_IDS = [42161, 421611, 31337]; // ArbOne, ArbRinkeby, Hardhat
76

7+
// TODO: use deterministic deployments
8+
89
const deployHomeGateway: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
910
const { deployments, getNamedAccounts, getChainId } = hre;
1011
const { deploy, execute } = deployments;
@@ -14,35 +15,101 @@ const deployHomeGateway: DeployFunction = async (hre: HardhatRuntimeEnvironment)
1415
const deployer = (await getNamedAccounts()).deployer ?? (await hre.ethers.getSigners())[0].address;
1516
console.log("deployer: %s", deployer);
1617

17-
// The object below is not available when launching the hardhat node.
18-
// TODO: use deterministic deployments
19-
const fastBridgeReceiver =
20-
chainId === 31337
21-
? await deployments.get("FastBridgeReceiverOnEthereum")
22-
: await hre.companionNetworks.foreign.deployments.get("FastBridgeReceiverOnEthereum");
23-
const fastBridgeSender = await deploy("FastBridgeSenderToEthereum", {
24-
from: deployer,
25-
args: [deployer, fastBridgeReceiver.address, ethers.constants.AddressZero],
26-
log: true,
27-
}); // nonce+0
28-
29-
const klerosCore = await deployments.get("KlerosCore");
30-
const foreignGateway =
31-
chainId === 31337
32-
? await deployments.get("ForeignGatewayOnEthereum")
33-
: await hre.companionNetworks.foreign.deployments.get("ForeignGatewayOnEthereum");
34-
const foreignChainId = chainId === 31337 ? 31337 : Number(await hre.companionNetworks.foreign.getChainId());
35-
const homeGateway = await deploy("HomeGatewayToEthereum", {
36-
from: deployer,
37-
args: [klerosCore.address, fastBridgeSender.address, foreignGateway.address, foreignChainId],
38-
log: true,
39-
}); // nonce+1
40-
41-
const fastSender = await hre.ethers
42-
.getContractAt("FastBridgeSenderToEthereum", fastBridgeSender.address)
43-
.then((contract) => contract.fastBridgeSender());
44-
if (fastSender === ethers.constants.AddressZero) {
45-
await execute("FastBridgeSenderToEthereum", { from: deployer, log: true }, "changeFastSender", homeGateway.address);
18+
// ----------------------------------------------------------------------------------------------
19+
const hardhatDeployer = async () => {
20+
const fastBridgeReceiver = await deployments.get("FastBridgeReceiverOnEthereum");
21+
const arbSysMock = await deploy("ArbSysMock", { from: deployer, log: true });
22+
23+
const fastBridgeSender = await deploy("FastBridgeSenderToEthereumMock", {
24+
from: deployer,
25+
args: [deployer, fastBridgeReceiver.address, ethers.constants.AddressZero, arbSysMock.address],
26+
log: true,
27+
}); // nonce+0
28+
29+
const klerosCore = await deployments.get("KlerosCore");
30+
const foreignGateway = await deployments.get("ForeignGatewayOnEthereum");
31+
const foreignChainId = 31337;
32+
33+
const homeGateway = await deploy("HomeGatewayToEthereum", {
34+
from: deployer,
35+
args: [klerosCore.address, fastBridgeSender.address, foreignGateway.address, foreignChainId],
36+
gasLimit: 4000000,
37+
log: true,
38+
}); // nonce+1
39+
40+
const fastSender = await hre.ethers
41+
.getContractAt("FastBridgeSenderToEthereumMock", fastBridgeSender.address)
42+
.then((contract) => contract.fastBridgeSender());
43+
44+
if (fastSender === ethers.constants.AddressZero) {
45+
await execute(
46+
"FastBridgeSenderToEthereumMock",
47+
{
48+
from: deployer,
49+
log: true,
50+
},
51+
"changeFastSender",
52+
homeGateway.address
53+
);
54+
55+
const outbox = await deploy("OutboxMock", {
56+
from: deployer,
57+
args: [fastBridgeSender.address],
58+
log: true,
59+
});
60+
61+
const bridge = await deploy("BridgeMock", {
62+
from: deployer,
63+
args: [outbox.address],
64+
log: true,
65+
});
66+
67+
await deploy("InboxMock", {
68+
from: deployer,
69+
args: [bridge.address],
70+
log: true,
71+
});
72+
}
73+
};
74+
75+
// ----------------------------------------------------------------------------------------------
76+
const liveDeployer = async () => {
77+
const fastBridgeReceiver = await hre.companionNetworks.foreign.deployments.get("FastBridgeReceiverOnEthereum");
78+
79+
const fastBridgeSender = await deploy("FastBridgeSenderToEthereum", {
80+
from: deployer,
81+
args: [deployer, fastBridgeReceiver.address, ethers.constants.AddressZero],
82+
log: true,
83+
}); // nonce+0
84+
85+
const klerosCore = await deployments.get("KlerosCore");
86+
const foreignGateway = await hre.companionNetworks.foreign.deployments.get("ForeignGatewayOnEthereum");
87+
const foreignChainId = Number(await hre.companionNetworks.foreign.getChainId());
88+
const homeGateway = await deploy("HomeGatewayToEthereum", {
89+
from: deployer,
90+
args: [klerosCore.address, fastBridgeSender.address, foreignGateway.address, foreignChainId],
91+
log: true,
92+
}); // nonce+1
93+
94+
const fastSender = await hre.ethers
95+
.getContractAt("FastBridgeSenderToEthereum", fastBridgeSender.address)
96+
.then((contract) => contract.fastBridgeSender());
97+
98+
if (fastSender === ethers.constants.AddressZero) {
99+
await execute(
100+
"FastBridgeSenderToEthereum",
101+
{ from: deployer, log: true },
102+
"changeFastSender",
103+
homeGateway.address
104+
);
105+
}
106+
};
107+
108+
// ----------------------------------------------------------------------------------------------
109+
if (chainId === 31337) {
110+
await hardhatDeployer();
111+
} else {
112+
await liveDeployer();
46113
}
47114
};
48115

contracts/hardhat.config.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ dotenv.config();
1616

1717
const config: HardhatUserConfig = {
1818
solidity: {
19-
version: "0.8.10",
19+
version: "0.8.9",
2020
settings: {
2121
optimizer: {
2222
enabled: true,
@@ -31,6 +31,7 @@ const config: HardhatUserConfig = {
3131
hardhat: {
3232
live: false,
3333
saveDeployments: true,
34+
allowUnlimitedContractSize: true,
3435
tags: ["test", "local"],
3536
},
3637
localhost: {

contracts/package.json

+23-23
Original file line numberDiff line numberDiff line change
@@ -22,37 +22,37 @@
2222
"devDependencies": {
2323
"@nomiclabs/hardhat-ethers": "npm:[email protected]",
2424
"@nomiclabs/hardhat-waffle": "^2.0.3",
25-
"@openzeppelin/contracts": "^4.5.0",
25+
"@openzeppelin/contracts": "^4.6.0",
2626
"@tenderly/hardhat-tenderly": "^1.0.13",
27-
"@typechain/ethers-v5": "^9.0.0",
28-
"@typechain/hardhat": "^5.0.0",
29-
"@types/chai": "^4.3.0",
30-
"@types/mocha": "^9.1.0",
31-
"@types/node": "^16.11.7",
32-
"@typescript-eslint/eslint-plugin": "^5.15.0",
33-
"@typescript-eslint/parser": "^5.15.0",
27+
"@typechain/ethers-v5": "^10.0.0",
28+
"@typechain/hardhat": "^6.0.0",
29+
"@types/chai": "^4.3.1",
30+
"@types/mocha": "^9.1.1",
31+
"@types/node": "^16",
32+
"@typescript-eslint/eslint-plugin": "^5.26.0",
33+
"@typescript-eslint/parser": "^5.26.0",
3434
"chai": "^4.3.6",
3535
"chai-ethers": "^0.0.1",
36-
"dotenv": "^16.0.0",
37-
"ethereum-waffle": "^3.4.0",
36+
"dotenv": "^16.0.1",
37+
"ethereum-waffle": "^3.4.4",
3838
"ethereumjs-util": "^7.1.4",
39-
"ethers": "^5.6.1",
40-
"follow-redirects": "^1.14.9",
41-
"hardhat": "^2.9.1",
42-
"hardhat-contract-sizer": "^2.5.0",
43-
"hardhat-deploy": "^0.11.0",
39+
"ethers": "^5.6.7",
40+
"follow-redirects": "^1.15.0",
41+
"hardhat": "^2.9.6",
42+
"hardhat-contract-sizer": "^2.5.1",
43+
"hardhat-deploy": "^0.11.10",
4444
"hardhat-deploy-ethers": "^0.3.0-beta.13",
4545
"hardhat-docgen": "^1.3.0",
4646
"hardhat-gas-reporter": "^1.0.8",
47-
"hardhat-watcher": "^2.1.1",
47+
"hardhat-watcher": "^2.3.0",
4848
"json-schema": "^0.4.0",
49-
"mocha": "^9.2.0",
49+
"mocha": "^10.0.0",
5050
"npm-run-all": "^4.1.5",
51-
"shelljs": "0.8.5",
52-
"solhint": "^3.3.6",
53-
"solidity-coverage": "^0.7.17",
54-
"ts-node": "^10.4.0",
55-
"typechain": "^7.0.0",
56-
"typescript": "^4.5.5"
51+
"shelljs": "^0.8.5",
52+
"solhint": "^3.3.7",
53+
"solidity-coverage": "^0.7.21",
54+
"ts-node": "^10.8.0",
55+
"typechain": "^8.0.0",
56+
"typescript": "^4.6.4"
5757
}
5858
}

contracts/scripts/changeRng.ts

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ async function main() {
2121

2222
const rng = await deploy("IncrementalNG", {
2323
from: deployer,
24+
args: [6485021504514574],
2425
log: true,
2526
skipIfAlreadyDeployed: false, // BUG: this parameter does nothing
2627
});

0 commit comments

Comments
 (0)