Skip to content

Commit

Permalink
Merge branch 'dev' into feat(web)/cases-filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
alcercu authored Sep 12, 2023
2 parents 041c945 + f946f6e commit bfe027c
Show file tree
Hide file tree
Showing 88 changed files with 1,802 additions and 938 deletions.
79 changes: 79 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: "CodeQL Advanced"

on:
merge_group:
branches:
- master
- dev
push:
branches:
- master
- dev
pull_request:
# The branches below must be a subset of the branches above
branches:
- master
- dev
schedule:
- cron: '26 1 * * 6'

permissions:
actions: read

jobs:
codeql-advanced-analysis:
name: Analyze
runs-on: ubuntu-latest
timeout-minutes: 360
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language:
- javascript

steps:
- name: Harden Runner
uses: step-security/harden-runner@128a63446a954579617e875aaab7d2978154e969 # v2.4.0
with:
egress-policy: audit

- name: Checkout repository
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@29b1f65c5e92e24fe6b6647da1eaabe529cec70f # v2.3.3
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.

# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality


# Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@29b1f65c5e92e24fe6b6647da1eaabe529cec70f # v2.3.3

# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun

# If the Autobuild fails above, remove it and uncomment the following three lines.
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.

# - run: |
# echo "Run, Build Application using script"
# ./location_of_script_within_repo/buildscript.sh

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@29b1f65c5e92e24fe6b6647da1eaabe529cec70f # v2.3.3
with:
category: "/language:${{matrix.language}}"
19 changes: 15 additions & 4 deletions .github/workflows/contracts-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,20 @@ on:
push:
branches:
- master
- dev
paths-ignore:
- "kleros-sdk/**"
- "services/**"
- "subgraph/**"
- "web/**"
pull_request:
branches:
- "*"
paths-ignore:
- "kleros-sdk/**"
- "services/**"
- "subgraph/**"
- "web/**"

permissions: # added using https://github.com/step-security/secure-workflows
contents: read
Expand All @@ -34,14 +45,14 @@ jobs:
54.185.253.63:443
- name: Setup Node.js environment
uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c
uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d
with:
node-version: 16.x

- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9
- uses: actions/checkout@7739b9ba2efcda9dde65ad1e3c2dbe65b41dfba7

- name: Cache node modules
uses: actions/cache@67b839edb68371cc5014f6cea11c9aa77238de78
uses: actions/cache@f7ebb81a3f195b4fb88dab7c14e2f7aff52045aa
env:
cache-name: cache-node-modules
with:
Expand Down Expand Up @@ -72,7 +83,7 @@ jobs:
working-directory: contracts

- name: Upload a build artifact
uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce
uses: actions/upload-artifact@65d862660abb392b8c4a3d1195a2108db131dd05
with:
name: code-coverage-report
path: contracts/coverage
6 changes: 5 additions & 1 deletion .github/workflows/dependency-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,9 @@ jobs:
- name: 'Checkout Repository'
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3

- name: 'Dependency Review'
uses: actions/dependency-review-action@7d90b4f05fea31dde1c4a1fb3fa787e197ea93ab # v3.0.7
uses: actions/dependency-review-action@f6fff72a3217f580d5afd49a46826795305b63c7 # v3.0.8
with:
base-ref: ${{ github.event.pull_request.base.sha || 'dev' }}
head-ref: ${{ github.event.pull_request.head.sha || github.ref }}
4 changes: 2 additions & 2 deletions .github/workflows/deploy-bots.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ jobs:
with:
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs

- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9
- uses: actions/checkout@7739b9ba2efcda9dde65ad1e3c2dbe65b41dfba7
- uses: actions/setup-python@61a6322f88396a6271a6ee3565807d608ecaddd1
- uses: aws-actions/setup-sam@12a6719db503425e98edcc798b6779590a450e8f
- uses: aws-actions/configure-aws-credentials@5fd3084fc36e372ff1fff382a39b10d03659f355
- uses: aws-actions/configure-aws-credentials@131c7b6fd10c0d7f36e1e49650b241d91ee327b9
with:
aws-access-key-id: ${{ secrets.STAGING_AWS_ACCESS_KEY }}
aws-secret-access-key: ${{ secrets.STAGING_AWS_SECRET_KEY }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/scorecards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,6 @@ jobs:

# Upload the results to GitHub's code scanning dashboard.
- name: "Upload to code-scanning"
uses: github/codeql-action/upload-sarif@5b6282e01c62d02e720b81eb8a51204f527c3624 # v2.21.3
uses: github/codeql-action/upload-sarif@a09933a12a80f87b87005513f0abb1494c27a716 # v2.21.4
with:
sarif_file: results.sarif
6 changes: 3 additions & 3 deletions .github/workflows/sentry-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ jobs:
sentry.io:443
54.185.253.63:443
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9
- uses: actions/checkout@7739b9ba2efcda9dde65ad1e3c2dbe65b41dfba7

- name: Cache node modules
uses: actions/cache@67b839edb68371cc5014f6cea11c9aa77238de78
uses: actions/cache@f7ebb81a3f195b4fb88dab7c14e2f7aff52045aa
env:
cache-name: cache-node-modules
with:
Expand All @@ -45,7 +45,7 @@ jobs:
${{ runner.os }}-build-${{ secrets.CACHE_VERSION }}-${{ env.cache-name }}-
- name: Set up Node.js
uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c
uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d
with:
node-version: 16

Expand Down
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
},
"solidity-va.test.defaultUnittestTemplate": "hardhat",
"solidity-language-server.trace.server.verbosity": "message",
"typescript.tsdk": "node_modules/typescript/lib",
"eslint.packageManager": "yarn",
"prettier.useEditorConfig": true,
"prettier.configPath": "prettier-config/.prettierrc.js"
Expand Down
3 changes: 2 additions & 1 deletion contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"bot:relayer-from-chiado": "NODE_NO_WARNINGS=1 NODE_OPTIONS=--experimental-fetch hardhat run ./scripts/disputeRelayerBotFromChiado.ts",
"bot:relayer-from-goerli": "NODE_NO_WARNINGS=1 NODE_OPTIONS=--experimental-fetch hardhat run ./scripts/disputeRelayerBotFromGoerli.ts",
"bot:relayer-from-hardhat": "NODE_NO_WARNINGS=1 NODE_OPTIONS=--experimental-fetch hardhat run ./scripts/disputeRelayerBotFromHardhat.ts",
"bot:disputor": "NODE_NO_WARNINGS=1 yarn hardhat run ./scripts/disputeCreatorBot.ts",
"etherscan-verify": "hardhat etherscan-verify",
"sourcify": "hardhat sourcify --write-failing-metadata",
"size": "hardhat size-contracts --no-compile",
Expand Down Expand Up @@ -75,7 +76,7 @@
"solhint-plugin-prettier": "^0.0.5",
"solidity-coverage": "0.8.2",
"ts-node": "^10.9.1",
"typechain": "^8.2.0",
"typechain": "^8.3.1",
"typescript": "^4.9.5"
},
"dependencies": {
Expand Down
78 changes: 78 additions & 0 deletions contracts/scripts/disputeCreatorBot.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import env from "./utils/env";
import loggerFactory from "./utils/logger";
import hre = require("hardhat");
import { KlerosCore, DisputeResolver } from "../typechain-types";
import { BigNumber } from "ethers";
const { ethers } = hre;

const HEARTBEAT_URL = env.optionalNoDefault("HEARTBEAT_URL_DISPUTOR_BOT");
const loggerOptions = env.optionalNoDefault("LOGTAIL_TOKEN_DISPUTOR_BOT")
? {
transportTargetOptions: {
target: "@logtail/pino",
options: { sourceToken: env.require("LOGTAIL_TOKEN_DISPUTOR_BOT") },
level: env.optional("LOG_LEVEL", "info"),
},
level: env.optional("LOG_LEVEL", "info"), // for pino-pretty
}
: {};
const logger = loggerFactory.createLogger(loggerOptions);

export default async function main() {
logger.info("Starting up");

const core = (await ethers.getContract("KlerosCore")) as KlerosCore;
const resolver = (await ethers.getContract("DisputeResolver")) as DisputeResolver;

if (HEARTBEAT_URL) {
logger.debug("Sending heartbeat");
fetch(HEARTBEAT_URL);
} else {
logger.debug("Heartbeat not set up, skipping");
}
const extraData =
"0x" +
"0000000000000000000000000000000000000000000000000000000000000001" + // courtId 1
"000000000000000000000000000000000000000000000000000000000000000B" + // minJurors 11
"0000000000000000000000000000000000000000000000000000000000000002"; // disputeKitId 2
const templates = [
`{"title":"A reality.eth question","description":"A reality.eth question has been raised to arbitration.","question":"**Kleros Moderate:** Did the user, **degenape6** (ID: 1554345080), break the Telegram group, ***[Kleros Trading Group]()*** (ID: -1001151472172), ***[rules](https://ipfs.kleros.io/ipfs/Qme3Qbj9rKUNHUe9vj9rqCLnTVUCWKy2YfveQF8HiuWQSu/Kleros%20Moderate%20Community%20Rules.pdf)*** due to conduct related to the ***[message](https://t.me/c/1151472172/116662)*** (***[backup](https://ipfs.kleros.io/ipfs/QmVbFrZR1bcyQzZjvLyXwL9ekDxrqHERykdreRxXrw4nqg/animations_file_23.mp4)***)?","answers":[{"id":"0x01","title":"Yes","reserved":false},{"id":"0x02","title":"No","reserved":false},{"id":"0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF","title":"Answered Too Soon","reserved":true}],"policyURI":"/ipfs/QmZ5XaV2RVgBADq5qMpbuEwgCuPZdRgCeu8rhGtJWLV6yz","frontendUrl":"https://reality.eth.limo/app/#!/question/0xe78996a233895be74a66f451f1019ca9734205cc-0xe2a3bd38e3ad4e22336ac35b221bbbdd808d716209f84014c7bc3bf62f8e3b39","arbitrableChainID":"100","arbitrableAddress":"0x2e39b8f43d0870ba896f516f78f57cde773cf805","arbitratorChainID":"421613","arbitratorAddress":"0xD08Ab99480d02bf9C092828043f611BcDFEA917b","category":"Oracle","lang":"en_US","specification":"KIP99"}`,
`{"title":"Add an entry to Ledger Contract Domain Name registry v2","description":"Someone requested to add an entry to Ledger Contract Domain Name registry v2","question":"Does the entry comply with the required criteria?","answers":[{"title":"Yes, Add It","description":"Select this if you think the entry complies with the required criteria and should be added."},{"title":"No, Don't Add It","description":"Select this if you think the entry does not comply with the required criteria and should not be added."}],"policyURI":"/ipfs/QmW3nQcMW2adyqe6TujRTYkyq26PiDqcmmTjdgKiz9ynPV","frontendUrl":"https://curate.kleros.io/tcr/100/0x957a53a994860be4750810131d9c876b2f52d6e1/0xc2c1aa705632f53051f22a9f65967c0944370020a7489aba608bd0d755ca1234","arbitratorChainID":"421613","arbitratorAddress":"0x791812B0B9f2ba260B2DA432BB02Ee23BC1bB509","category":"Curation","specification":"KIP0X","lang":"en_US"}`,
`{"title":"Omen Question: News & Politics","description":"This reality dispute has been created by Omen, we advise you to read [the Omen Rules](https://cdn.kleros.link/ipfs/QmU1oZzsduGwtC7vCUQPw1QcBP6BDNDkg4t6zkowPucVcx) and consult the evidence provided in [the Market Comments](https://omen.eth.limo/#/0x95b2271039b020aba31b933039e042b60b063800).","question":"**Assuming that today is December 20th 2020, will Joe Biden win the 2020 United States presidential election?**","answers":[{"title":"Yes"},{"title":"No"}],"policyURI":"/ipfs/QmU1oZzsduGwtC7vCUQPw1QcBP6BDNDkg4t6zkowPucVcx","frontendUrl":"https://omen.eth.limo/#/0x95b2271039b020aba31b933039e042b60b063800","arbitratorChainID":"421613","arbitratorAddress":"0x791812B0B9f2ba260B2DA432BB02Ee23BC1bB509","category":"Oracle","specification":"KIP0X","lang":"en_US"}`,
`{"title":"Proof of Humanity Registration Request","description":"A request to register the specified entry to a list of provable humans.","question":"Should the request to register be accepted?","answers":[{"title":"Yes","description":"Accept the request to register the entry."},{"title":"No","description":"Deny the request."}],"policyURI":"/ipfs/QmYPf2fdSyr9BiSy6pJFUmB1oTUPwg6dhEuFqL1n4ZosgH","frontendUrl":"https://app.proofofhumanity.id/profile/0x00de4b13153673bcae2616b67bf822500d325fc3?network=mainnet","arbitratorChainID":"421613","arbitratorAddress":"0x791812B0B9f2ba260B2DA432BB02Ee23BC1bB509","category":"Curated List","specification":"KIP0X","lang":"en_US"}`,
];
const randomTemplate = templates[Math.floor(Math.random() * templates.length)];
const nbOfChoices = 2;
const cost = (await core.functions["arbitrationCost(bytes)"](extraData)).cost;
const tx = await resolver.createDisputeForTemplate(
extraData,
randomTemplate,
"disputeTemplateMapping: TODO",
nbOfChoices,
{
value: cost,
}
);

logger.info(`Dispute creation tx: ${tx.hash}`);
const blockNumber = await tx.wait().then((receipt) => receipt.blockNumber);
const disputeId = await resolver
.queryFilter(resolver.filters.DisputeRequest(), blockNumber, blockNumber)
.then((events) => BigNumber.from(events[0].args[1]));
logger.info(`Dispute created with disputeId ${disputeId.toString()}`);

logger.info("Shutting down");
await delay(2000); // Some log messages may be lost otherwise
}

const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));

main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
})
.finally(() => {
logger.flush();
});
58 changes: 42 additions & 16 deletions contracts/scripts/keeperBot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import hre = require("hardhat");
const { ethers } = hre;
const MAX_DRAW_ITERATIONS = 30;
const MAX_EXECUTE_ITERATIONS = 20;
const MAX_DELAYED_STAKES_ITERATIONS = 50;
const WAIT_FOR_RNG_DURATION = 5 * 1000; // 5 seconds
const ITERATIONS_COOLDOWN_PERIOD = 20 * 1000; // 20 seconds
const HIGH_GAS_LIMIT = { gasLimit: 50000000 }; // 50M gas
const ITERATIONS_COOLDOWN_PERIOD = 10 * 1000; // 10 seconds
const HIGH_GAS_LIMIT = { gasLimit: 50_000_000 }; // 50M gas
const HEARTBEAT_URL = env.optionalNoDefault("HEARTBEAT_URL_KEEPER_BOT");
const SUBGRAPH_URL = env.require("SUBGRAPH_URL");
const MAX_JURORS_PER_DISPUTE = 1000; // Skip disputes with more than this number of jurors
Expand Down Expand Up @@ -219,7 +220,7 @@ const drawJurors = async (dispute: { id: string; currentRoundIndex: string }, it
try {
await core.callStatic.draw(dispute.id, iterations, HIGH_GAS_LIMIT);
} catch (e) {
logger.info(`Draw: will fail for ${dispute.id}, skipping`);
logger.error(`Draw: will fail for ${dispute.id}, skipping`);
return success;
}
try {
Expand All @@ -241,7 +242,7 @@ const executeRepartitions = async (dispute: { id: string; currentRoundIndex: str
try {
await core.callStatic.execute(dispute.id, dispute.currentRoundIndex, iterations, HIGH_GAS_LIMIT);
} catch (e) {
logger.info(`Execute: will fail for ${dispute.id}, skipping`);
logger.error(`Execute: will fail for ${dispute.id}, skipping`);
return success;
}
try {
Expand All @@ -260,7 +261,7 @@ const executeRuling = async (dispute: { id: string }) => {
try {
await core.callStatic.executeRuling(dispute.id);
} catch (e) {
logger.info(`ExecuteRuling: will fail for ${dispute.id}, skipping`);
logger.error(`ExecuteRuling: will fail for ${dispute.id}, skipping`);
return success;
}
try {
Expand Down Expand Up @@ -290,7 +291,7 @@ const withdrawAppealContribution = async (
contribution.choice
);
} catch (e) {
logger.info(
logger.warn(
`WithdrawFeesAndRewards: will fail for dispute #${disputeId}, round #${roundId}, choice ${contribution.choice} and beneficiary ${contribution.contributor.id}, skipping`
);
return success;
Expand Down Expand Up @@ -323,6 +324,40 @@ const withdrawAppealContribution = async (
return success;
};

const executeDelayedStakes = async () => {
const { sortition } = await getContracts();

// delayedStakes = 1 + delayedStakeWriteIndex - delayedStakeReadIndex
const delayedStakesRemaining = BigNumber.from(1)
.add(await sortition.delayedStakeWriteIndex())
.sub(await sortition.delayedStakeReadIndex());

const delayedStakes = delayedStakesRemaining.lt(MAX_DELAYED_STAKES_ITERATIONS)
? delayedStakesRemaining
: BigNumber.from(MAX_DELAYED_STAKES_ITERATIONS);

if (delayedStakes.eq(0)) {
logger.info("No delayed stakes to execute");
return true;
}
logger.info(`Executing ${delayedStakes} delayed stakes, ${delayedStakesRemaining} remaining`);
let success = false;
try {
await sortition.callStatic.executeDelayedStakes(delayedStakes);
} catch (e) {
logger.error(`executeDelayedStakes: will fail because of ${JSON.stringify(e)}`);
return success;
}
try {
const gas = (await sortition.estimateGas.executeDelayedStakes(delayedStakes)).mul(150).div(100); // 50% extra gas
const tx = await (await sortition.executeDelayedStakes(delayedStakes, { gasLimit: gas })).wait();
logger.info(`executeDelayedStakes txID: ${tx?.transactionHash}`);
} catch (e) {
handleError(e);
}
return success;
};

const getMissingJurors = async (dispute: { id: string; currentRoundIndex: string }) => {
const { core } = await getContracts();
const { nbVotes, drawnJurors } = await core.getRoundInfo(dispute.id, dispute.currentRoundIndex);
Expand Down Expand Up @@ -594,18 +629,9 @@ async function main() {
// ----------------------------------------------- //
// EXECUTE DELAYED STAKES //
// ----------------------------------------------- //
// delayedStakes = 1 + delayedStakeWriteIndex - delayedStakeReadIndex
const delayedStakes = BigNumber.from(1)
.add(await sortition.delayedStakeWriteIndex())
.sub(await sortition.delayedStakeReadIndex());

if (await isPhaseStaking()) {
if (delayedStakes.gt(0)) {
logger.info("Executing delayed stakes");
await sortition.executeDelayedStakes(delayedStakes);
} else {
logger.info("No delayed stakes to execute");
}
await executeDelayedStakes();
}

await sendHeartbeat();
Expand Down
Loading

0 comments on commit bfe027c

Please sign in to comment.