Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
737c5fe
governance minimization and bug fixes
shotaronowhere Apr 12, 2022
36c9b70
chore: merge the merkle library
shotaronowhere May 10, 2022
b5ec6e0
Merge remote-tracking branch 'origin/feat/merkle-library' into challe…
shotaronowhere May 10, 2022
cdf3a83
feat: unhappy path with merkle tree
shotaronowhere May 15, 2022
7430258
feat: immutable chainIDs increase gas efficiency
shotaronowhere May 15, 2022
dabbc53
feat: updated tests
shotaronowhere May 15, 2022
6b545f1
chore: test typos
shotaronowhere May 15, 2022
160827d
chore: whitespace formatting
shotaronowhere May 15, 2022
3dbec74
chore: remove comment
shotaronowhere May 15, 2022
7116174
chore: remove testing value
shotaronowhere May 15, 2022
927f896
style: remove testing comments
shotaronowhere May 15, 2022
f8c1a4f
test: adapt deployment scripts
shotaronowhere May 16, 2022
d622a55
test: deploy central arbitrator for adhoc tests
shotaronowhere May 18, 2022
77ce88e
style: lint fix
shotaronowhere May 18, 2022
55a2c50
fix: override view funciton
shotaronowhere May 18, 2022
b56f372
style: fix code lint
shotaronowhere May 18, 2022
49da2a4
feat: merkle tree refactoring
shotaronowhere May 20, 2022
eecd405
feat: refactoring and gas optimization
shotaronowhere May 20, 2022
502692b
feat: fix chainID constructor
shotaronowhere May 20, 2022
5a879bf
feat: gnosis chain support
shotaronowhere May 20, 2022
07f7c2f
feat: refactoring and gc fallback fix
shotaronowhere May 23, 2022
6babe57
feat: refactoring safe router into new contract
shotaronowhere May 24, 2022
e0c80e0
feat: refactoring
shotaronowhere May 27, 2022
f5b677a
feat: update tests
shotaronowhere May 27, 2022
61df188
feat: deploy script
shotaronowhere May 27, 2022
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
6 changes: 6 additions & 0 deletions contracts/deploy/00-home-chain-arbitration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ const deployArbitration: DeployFunction = async (hre: HardhatRuntimeEnvironment)
).address
);
}
const centralizedArbitrator = await deploy("CentralizedArbitrator", {
from: deployer,
args: [0, 0, 0],
log: true,
});

const pnk = pnkByChain.get(Number(await getChainId())) ?? AddressZero;
const minStake = BigNumber.from(10).pow(20).mul(2);
const alpha = 10000;
Expand Down
51 changes: 32 additions & 19 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, // 1 day
homeChainId: 42161,
arbitrumInbox: "0x4Dbd4fc535Ac27206064B68FfCf827b0A60BAB3f",
},
4: {
claimDeposit: parseEther("0.1"),
challengeDuration: 120, // 2 min
deposit: parseEther("0.1"),
epochPeriod: 86400, // 1 day
homeChainId: 421611,
arbitrumInbox: "0x578BAde599406A8fE3d24Fd7f7211c0911F5B29e",
},
31337: {
claimDeposit: parseEther("0.1"),
challengeDuration: 120, // 2 min
deposit: parseEther("0.1"),
epochPeriod: 86400, // 1 day
homeChainId: 31337,
},
arbitrumInbox: "0x00",
}
};

const deployForeignGateway: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
Expand All @@ -50,49 +53,59 @@ const deployForeignGateway: DeployFunction = async (hre: HardhatRuntimeEnvironme
let nonce;
if (chainId === ForeignChains.HARDHAT) {
nonce = await ethers.provider.getTransactionCount(deployer);
nonce += 4; // HomeGatewayToEthereum deploy tx will be the 6th after this, same network for both home/foreign.
nonce += 5; // HomeGatewayToEthereum deploy tx will be the 6th after this, same network for both home/foreign.
} else {
const homeChainProvider = new providers.JsonRpcProvider(homeNetworks[chainId].url);
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 } = paramsByChainId[chainId];
const challengeDeposit = claimDeposit;
const bridgeAlpha = 5000;
const { deposit, epochPeriod, homeChainId, arbitrumInbox } = paramsByChainId[chainId];
const homeChainIdAsBytes32 = hexZeroPad(homeChainId, 32);

const homeGatewayAddress = getContractAddress(deployer, nonce);
console.log("calculated future HomeGatewayToEthereum address for nonce %d: %s", nonce, homeGatewayAddress);
nonce -= 1;

const fastBridgeSenderAddress = getContractAddress(deployer, nonce);
console.log("calculated future FastSender for nonce %d: %s", nonce, fastBridgeSenderAddress);

nonce += 5;

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

const genesis = 1652709415 // sample genesis time

const fastBridgeReceiver = await deploy("FastBridgeReceiverOnEthereum", {
from: deployer,
args: [
deployer,
ethers.constants.AddressZero, // should be safeBridgeSender
ethers.constants.AddressZero, // should be Arbitrum Inbox
claimDeposit,
challengeDeposit,
challengeDuration,
bridgeAlpha,
deposit,
epochPeriod,
genesis,
inboxAddress,
fastBridgeSenderAddress,
],
log: true,
});

const foreignGateway = await deploy("ForeignGatewayOnEthereum", {
from: deployer,
contract: "ForeignGateway",
args: [
deployer,
fastBridgeReceiver.address,
[ethers.BigNumber.from(10).pow(17)],
homeGatewayAddress,
homeChainIdAsBytes32,
],
gasLimit: 4000000,
log: true,
});

const metaEvidenceUri =
"https://raw.githubusercontent.com/kleros/kleros-v2/master/contracts/deployments/rinkeby/MetaEvidence_ArbitrableExample.json";
const arbitrable = await deploy("ArbitrableExample", {

await deploy("ArbitrableExample", {
from: deployer,
args: [foreignGateway.address, metaEvidenceUri],
log: true,
Expand Down
132 changes: 102 additions & 30 deletions contracts/deploy/02-home-chain.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { DeployFunction } from "hardhat-deploy/types";
import { Address } from "ethereumjs-util";
import { ethers } from "hardhat";

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

// TODO: use deterministic deployments

const deployHomeGateway: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
const { deployments, getNamedAccounts, getChainId } = hre;
const { deploy, execute } = deployments;
Expand All @@ -14,35 +15,106 @@ const deployHomeGateway: DeployFunction = async (hre: HardhatRuntimeEnvironment)
const deployer = (await getNamedAccounts()).deployer ?? (await hre.ethers.getSigners())[0].address;
console.log("deployer: %s", deployer);

// The object below is not available when launching the hardhat node.
// TODO: use deterministic deployments
const fastBridgeReceiver =
chainId === 31337
? await deployments.get("FastBridgeReceiverOnEthereum")
: await hre.companionNetworks.foreign.deployments.get("FastBridgeReceiverOnEthereum");
const fastBridgeSender = await deploy("FastBridgeSenderToEthereum", {
from: deployer,
args: [deployer, fastBridgeReceiver.address, ethers.constants.AddressZero],
log: true,
}); // nonce+0

const klerosCore = await deployments.get("KlerosCore");
const foreignGateway =
chainId === 31337
? await deployments.get("ForeignGatewayOnEthereum")
: await hre.companionNetworks.foreign.deployments.get("ForeignGatewayOnEthereum");
const foreignChainId = chainId === 31337 ? 31337 : Number(await hre.companionNetworks.foreign.getChainId());
const homeGateway = await deploy("HomeGatewayToEthereum", {
from: deployer,
args: [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);
// ----------------------------------------------------------------------------------------------
const hardhatDeployer = async () => {
const fastBridgeReceiver = await deployments.get("FastBridgeReceiverOnEthereum");
const arbSysMock = await deploy("ArbSysMock", { from: deployer, log: true });
const epochPeriod = 86400; // 1 day
const genesis = 1652709415 // sample genesis time

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

const klerosCore = await deployments.get("KlerosCore");
const foreignGateway = await deployments.get("ForeignGatewayOnEthereum");
let foreignChainId = 1;
if (chainId === 31337){
foreignChainId = 31337;
} else if (chainId === 421611){
foreignChainId = 4;
}
const homeGatewayToEthereum = await deploy("HomeGatewayToEthereum", {
from: deployer,
contract: "HomeGateway",
args: [deployer, klerosCore.address, fastBridgeSender.address, foreignGateway.address, foreignChainId],
gasLimit: 4000000,
log: true,
}); // nonce+1
foreignChainId = 100;
if (chainId === 31337){
foreignChainId = 31337;
}
const homeGatewayToGnosis = await deploy("HomeGatewayToGnosis", {
from: deployer,
contract: "HomeGateway",
args: [deployer, klerosCore.address, fastBridgeSender.address, foreignGateway.address, foreignChainId],
gasLimit: 4000000,
log: true,
}); // nonce+1


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 liveDeployer = async () => {
const fastBridgeReceiver = await hre.companionNetworks.foreign.deployments.get("FastBridgeReceiverOnEthereum");

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

const klerosCore = await deployments.get("KlerosCore");
const foreignGateway = await hre.companionNetworks.foreign.deployments.get("ForeignGatewayOnEthereum");
const foreignChainId = Number(await hre.companionNetworks.foreign.getChainId());
const homeGateway = await deploy("HomeGatewayToEthereum", {
from: deployer,
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
);
}
};

// ----------------------------------------------------------------------------------------------
if (chainId === 31337) {
await hardhatDeployer();
} else {
await liveDeployer();
}
};

Expand Down
108 changes: 108 additions & 0 deletions contracts/deploy/04-foreign-chain-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import { parseEther } from "ethers/lib/utils";
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { DeployFunction } from "hardhat-deploy/types";
import { ethers } from "hardhat";
import getContractAddress from "../deploy-helpers/getContractAddress";

enum ForeignChains {
ETHEREUM_RINKEBY = 4,
HARDHAT = 31337,
}
const deployForeignGateway: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
const { deployments, getNamedAccounts, getChainId, config } = hre;
const { deploy } = deployments;
const { hexZeroPad } = hre.ethers.utils;

const deployer = (await getNamedAccounts()).deployer;
const chainId = Number(await getChainId());
console.log("deploying to chainId %s with deployer %s", chainId, deployer);

const deposit = parseEther("0.1")
const epochPeriod = 120 // 2 min
const homeChainId = 421611 // arbitrum testnet
const arbInbox = "0x578BAde599406A8fE3d24Fd7f7211c0911F5B29e" // https://developer.offchainlabs.com/docs/useful_addresses
const genesis = 1652709415 // sample genesis time

// TODO: use deterministic deployments
let nonce = await ethers.provider.getTransactionCount(deployer)+7;

const fastBridgeSenderToEthereumAddress = getContractAddress(deployer, nonce );
console.log("calculated future fastBridgeSenderToEthereum address for nonce %d: %s", nonce, fastBridgeSenderToEthereumAddress);
const fastBridgeSenderToGnosisAddress = getContractAddress(deployer, nonce + 1);
console.log("calculated future fastBridgeSenderToGnosis address for nonce %d: %s", nonce + 1, fastBridgeSenderToGnosisAddress);
const homeGatewayOnEthereumAddress = getContractAddress(deployer, nonce + 2);
console.log("calculated future HomeGatewayOnEthereum address for nonce %d: %s", nonce + 2, homeGatewayOnEthereumAddress);
const homeGatewayOnGnosisAddress = getContractAddress(deployer, nonce + 3);
console.log("calculated future HomeGatewayOnGnosis address for nonce %d: %s", nonce + 3, homeGatewayOnGnosisAddress);
const fastBridgeReceiverOnEthereum = await deploy("FastBridgeReceiverOnEthereum", {
from: deployer,
args: [
deposit,
epochPeriod,
genesis,
arbInbox, // should be Arbitrum Inbox
fastBridgeSenderToEthereumAddress,
],
log: true,
});

const ForeignGatewayOnEthereum = await deploy("ForeignGatewayMockOnEthereum", {
from: deployer,
contract: "ForeignGatewayMock",
args: [
fastBridgeReceiverOnEthereum.address,
homeGatewayOnEthereumAddress,
homeChainId
],
log: true,
});

const mockAMB = await deploy("MockAMB", {
from: deployer,
log: true,
}); // nonce+0

nonce = await ethers.provider.getTransactionCount(deployer) + 1;
const fastBridgeReceiverOnGnosisChainAddress = getContractAddress(deployer, nonce);
console.log("calculated future HomeGatewayOnEthereum address for nonce %d: %s", nonce, homeGatewayOnEthereumAddress);

const safeBridgeRouter = await deploy("SafeBridgeRouter", {
from: deployer,
args: [
arbInbox,
mockAMB.address,
fastBridgeSenderToGnosisAddress,
fastBridgeReceiverOnGnosisChainAddress
],
log: true,
}); // nonce+0

const fastBridgeReceiverOnGnosisChain = await deploy("FastBridgeReceiverOnGnosis", {
from: deployer,
args: [
deposit,
epochPeriod,
genesis,
mockAMB.address, // should be Arbitrum Inbox
safeBridgeRouter.address,
],
log: true,
});

const ForeignGatewayOnGnosis = await deploy("ForeignGatewayMockOnGnosis", {
from: deployer,
contract: "ForeignGatewayMock",
args: [
fastBridgeReceiverOnGnosisChain.address,
homeGatewayOnGnosisAddress,
homeChainId
],
log: true,
});
};
deployForeignGateway.tags = ["BridgeTest"];
deployForeignGateway.skip = async ({ getChainId }) => {
const chainId = Number(await getChainId());
return !ForeignChains[chainId];
};
export default deployForeignGateway;
Loading