Skip to content

Commit

Permalink
Merge pull request #81 from kleros/feat/challenge-path-4-with-merkle-…
Browse files Browse the repository at this point in the history
…root

Feat/challenge path 4 with merkle root
  • Loading branch information
jaybuidl committed Jul 27, 2022
2 parents 1d6d825 + 45c123d commit 6a5ba1d
Show file tree
Hide file tree
Showing 70 changed files with 4,313 additions and 667 deletions.
32 changes: 16 additions & 16 deletions contracts/deploy/01-foreign-chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,23 @@ enum ForeignChains {
}
const paramsByChainId = {
1: {
claimDeposit: parseEther("0.1"),
challengeDuration: 86400, // 1 day
deposit: parseEther("0.1"),
epochPeriod: 86400, // 24 hours
challengePeriod: 14400, // 4 hours
homeChainId: 42161,
arbitrumInbox: "0x4Dbd4fc535Ac27206064B68FfCf827b0A60BAB3f",
},
4: {
claimDeposit: parseEther("0.1"),
challengeDuration: 120, // 2 min
deposit: parseEther("0.1"),
epochPeriod: 86400, // 24 hours
challengePeriod: 14400, // 4 hours
homeChainId: 421611,
arbitrumInbox: "0x578BAde599406A8fE3d24Fd7f7211c0911F5B29e",
},
31337: {
claimDeposit: parseEther("0.1"),
challengeDuration: 120, // 2 min
deposit: parseEther("0.1"),
epochPeriod: 86400, // 24 hours
challengePeriod: 14400, // 4 hours
homeChainId: 31337,
arbitrumInbox: "0x00",
},
Expand Down Expand Up @@ -59,9 +62,7 @@ const deployForeignGateway: DeployFunction = async (hre: HardhatRuntimeEnvironme
nonce = await homeChainProvider.getTransactionCount(deployer);
nonce += 1; // HomeGatewayToEthereum deploy tx will the third tx after this on its home network, so we add two to the current nonce.
}
const { claimDeposit, challengeDuration, homeChainId, arbitrumInbox } = paramsByChainId[chainId];
const challengeDeposit = claimDeposit;
const bridgeAlpha = 5000;
const { deposit, epochPeriod, challengePeriod, homeChainId, arbitrumInbox } = paramsByChainId[chainId];
const homeChainIdAsBytes32 = hexZeroPad(homeChainId, 32);

const homeGatewayAddress = getContractAddress(deployer, nonce);
Expand All @@ -71,27 +72,26 @@ const deployForeignGateway: DeployFunction = async (hre: HardhatRuntimeEnvironme
const fastBridgeSenderAddress = getContractAddress(deployer, nonce);
console.log("calculated future FastSender for nonce %d: %s", nonce, fastBridgeSenderAddress);

nonce += 5;
nonce += 4;

const inboxAddress = chainId === ForeignChains.HARDHAT ? getContractAddress(deployer, nonce) : arbitrumInbox;
console.log("calculated future inboxAddress for nonce %d: %s", nonce, inboxAddress);

const fastBridgeReceiver = await deploy("FastBridgeReceiverOnEthereum", {
from: deployer,
args: [
deployer,
deposit,
epochPeriod,
challengePeriod,
fastBridgeSenderAddress,
inboxAddress,
claimDeposit,
challengeDeposit,
challengeDuration,
bridgeAlpha,
inboxAddress
],
log: true,
});

const foreignGateway = await deploy("ForeignGatewayOnEthereum", {
from: deployer,
contract: "ForeignGateway",
args: [
deployer,
fastBridgeReceiver.address,
Expand Down
78 changes: 27 additions & 51 deletions contracts/deploy/02-home-chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { DeployFunction } from "hardhat-deploy/types";
import { ethers } from "hardhat";

const HOME_CHAIN_IDS = [42161, 421611, 31337]; // ArbOne, ArbRinkeby, Hardhat
const epochPeriod = 86400; // 24 hours

// TODO: use deterministic deployments

Expand All @@ -22,7 +23,8 @@ const deployHomeGateway: DeployFunction = async (hre: HardhatRuntimeEnvironment)

const fastBridgeSender = await deploy("FastBridgeSenderToEthereumMock", {
from: deployer,
args: [deployer, fastBridgeReceiver.address, ethers.constants.AddressZero, arbSysMock.address],
contract: "FastBridgeSenderMock",
args: [epochPeriod, fastBridgeReceiver.address, arbSysMock.address],
log: true,
}); // nonce+0

Expand All @@ -32,44 +34,29 @@ const deployHomeGateway: DeployFunction = async (hre: HardhatRuntimeEnvironment)

const homeGateway = await deploy("HomeGatewayToEthereum", {
from: deployer,
args: [klerosCore.address, fastBridgeSender.address, foreignGateway.address, foreignChainId],
contract: "HomeGateway",
args: [deployer, klerosCore.address, fastBridgeSender.address, foreignGateway.address, foreignChainId],
gasLimit: 4000000,
log: true,
}); // nonce+1

const fastSender = await hre.ethers
.getContractAt("FastBridgeSenderToEthereumMock", fastBridgeSender.address)
.then((contract) => contract.fastBridgeSender());

if (fastSender === ethers.constants.AddressZero) {
await execute(
"FastBridgeSenderToEthereumMock",
{
from: deployer,
log: true,
},
"changeFastSender",
homeGateway.address
);

const outbox = await deploy("OutboxMock", {
from: deployer,
args: [fastBridgeSender.address],
log: true,
});

const bridge = await deploy("BridgeMock", {
from: deployer,
args: [outbox.address],
log: true,
});

await deploy("InboxMock", {
from: deployer,
args: [bridge.address],
log: true,
});
}
const outbox = await deploy("OutboxMock", {
from: deployer,
args: [fastBridgeSender.address],
log: true,
});

const bridge = await deploy("BridgeMock", {
from: deployer,
args: [outbox.address],
log: true,
});

await deploy("InboxMock", {
from: deployer,
args: [bridge.address],
log: true,
});
};

// ----------------------------------------------------------------------------------------------
Expand All @@ -78,7 +65,8 @@ const deployHomeGateway: DeployFunction = async (hre: HardhatRuntimeEnvironment)

const fastBridgeSender = await deploy("FastBridgeSenderToEthereum", {
from: deployer,
args: [deployer, fastBridgeReceiver.address, ethers.constants.AddressZero],
contract: "FastBridgeSender",
args: [epochPeriod, fastBridgeReceiver.address],
log: true,
}); // nonce+0

Expand All @@ -87,22 +75,10 @@ const deployHomeGateway: DeployFunction = async (hre: HardhatRuntimeEnvironment)
const foreignChainId = Number(await hre.companionNetworks.foreign.getChainId());
const homeGateway = await deploy("HomeGatewayToEthereum", {
from: deployer,
args: [klerosCore.address, fastBridgeSender.address, foreignGateway.address, foreignChainId],
contract: "HomeGateway",
args: [deployer, klerosCore.address, fastBridgeSender.address, foreignGateway.address, foreignChainId],
log: true,
}); // nonce+1

const fastSender = await hre.ethers
.getContractAt("FastBridgeSenderToEthereum", fastBridgeSender.address)
.then((contract) => contract.fastBridgeSender());

if (fastSender === ethers.constants.AddressZero) {
await execute(
"FastBridgeSenderToEthereum",
{ from: deployer, log: true },
"changeFastSender",
homeGateway.address
);
}
}); // nonce+
};

// ----------------------------------------------------------------------------------------------
Expand Down
10 changes: 8 additions & 2 deletions contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,15 @@ const config: HardhatUserConfig = {
relayer: {
default: 1,
},
bridger: {
default: 2,
},
challenger: {
default: 3,
},
},
gasReporter: {
enabled: process.env.REPORT_GAS !== undefined,
enabled: process.env.REPORT_GAS !== undefined ? process.env.REPORT_GAS === "true" : false,
currency: "USD",
},
verify: {
Expand All @@ -166,7 +172,7 @@ const config: HardhatUserConfig = {
},
},
docgen: {
path: './docs',
path: "./docs",
clear: true,
runOnCompile: false,
},
Expand Down
Loading

0 comments on commit 6a5ba1d

Please sign in to comment.