Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bridge v3 #7

Draft
wants to merge 8 commits into
base: bridge-v2
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
25 changes: 15 additions & 10 deletions Bridge/Bridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ contract Bridge is EthTokenReciever {
require(
checkSignatures(
keccak256(
abi.encodePacked(
abi.encode(
"addToken",
address(this),
newToken,
ticker,
Expand Down Expand Up @@ -205,7 +206,7 @@ contract Bridge is EthTokenReciever {
require(
checkSignatures(
keccak256(
abi.encodePacked(
abi.encode(
"prepareMigration",
address(this),
salt,
Expand Down Expand Up @@ -245,7 +246,8 @@ contract Bridge is EthTokenReciever {
require(
checkSignatures(
keccak256(
abi.encodePacked(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Transition from encode to encodePacked is not that necessary but might be taken as it may only affect the order of the params for the statement we sign but not the signature itself
Just make sure that it works fine when passing params to recoverAddress, now it looks okay, but it will not be superfluous to double check it

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's needed to prevent signature collision

abi.encode(
"migrate",
address(this),
newContractAddress,
salt,
Expand Down Expand Up @@ -306,7 +308,8 @@ contract Bridge is EthTokenReciever {
require(
checkSignatures(
keccak256(
abi.encodePacked(
abi.encode(
"addAsset",
address(this),
name,
symbol,
Expand Down Expand Up @@ -412,9 +415,9 @@ contract Bridge is EthTokenReciever {
require(
checkSignatures(
keccak256(
abi.encodePacked(
address(this),
abi.encode(
"addPeer",
address(this),
newPeerAddress,
txHash,
_networkId
Expand Down Expand Up @@ -453,9 +456,9 @@ contract Bridge is EthTokenReciever {
require(
checkSignatures(
keccak256(
abi.encodePacked(
address(this),
abi.encode(
"removePeer",
address(this),
peerAddress,
txHash,
_networkId
Expand Down Expand Up @@ -499,7 +502,8 @@ contract Bridge is EthTokenReciever {
require(
checkSignatures(
keccak256(
abi.encodePacked(
abi.encode(
"transfer",
address(this),
tokenAddress,
amount,
Expand Down Expand Up @@ -557,7 +561,8 @@ contract Bridge is EthTokenReciever {
require(
checkSignatures(
keccak256(
abi.encodePacked(
abi.encode(
"transferOwned",
address(this),
sidechainAssetId,
amount,
Expand Down
8 changes: 8 additions & 0 deletions deploy-data/mainnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ const config: DeployConfig = {
{
"address": "0xc7D9c108D4E1dD1484D3e2568d7f74bfD763d356",
"asset_id": "0x0200080000000000000000000000000000000000000000000000000000000000"
},
{
"address": "0x5E7F20e72C21f6D0Bf0A2814FD4164176401cf8e",
"asset_id": "0x00f2f4fda40a4bf1fc3769d156fa695532eec31e265d75068524462c0b80f674"
},
{
"address": "0xC60D6662027F5797Cf873bFe80BcF048e30Fc35e",
"asset_id": "0x0200090000000000000000000000000000000000000000000000000000000000"
}
],
"erc20Addresses": [
Expand Down
18 changes: 18 additions & 0 deletions deploy-data/sepolia2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

import DeployConfig from "./config";

const config: DeployConfig = {
"xorAddress": "0x9826ecfcd937c4518e1c42b3703c7cb908b61197",
"valAddress": "0x88ee18defc56d78417b0d331e794ef75799ca6d1",
"sidechainAssets": [
],
"erc20Addresses": [
],
"peers": [
"0x981bccf6d8593dc49c22cf744a59afa5a2b23118",
"0x90dca3c91c10e802093318123ad8bb8809061765",
"0x457d710255184dbf63c019ab50f65743c6cb072f"
]
};

export default config;
20 changes: 18 additions & 2 deletions deploy/01-bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import { default as gethConfig } from "../deploy-data/geth"
import { default as rinkebyConfig } from "../deploy-data/rinkeby"
import { default as mainnetConfig } from "../deploy-data/mainnet"
import { default as sepoliaConfig } from "../deploy-data/sepolia"
import { default as sepolia2Config } from "../deploy-data/sepolia2"


module.exports = async ({
deployments,
getUnnamedAccounts,
network
network,
run
}: HardhatRuntimeEnvironment) => {
let [deployer] = await getUnnamedAccounts();

Expand All @@ -28,10 +30,14 @@ module.exports = async ({
case "sepolia":
config = sepoliaConfig;
break;
case "sepolia2":
config = sepolia2Config;
break;
case "geth":
config = gethConfig;
break;
default:
console.log("No config for network", network.name);
config = ganacheConfig;
break;
}
Expand All @@ -40,7 +46,7 @@ module.exports = async ({

let tokenAddresses = config.sidechainAssets.map((val) => val.address);
let assetIds = config.sidechainAssets.map((val) => val.asset_id);
await deployments.deploy("Bridge", {
let bridge = await deployments.deploy("Bridge", {
from: deployer,
log: true,
autoMine: true,
Expand All @@ -51,4 +57,14 @@ module.exports = async ({
'0x0000000000000000000000000000000000000000000000000000000000000000'
]
});

await run("verify:verify", {
address: bridge.address,
constructorArguments: [
config.peers,
tokenAddresses, assetIds, config.erc20Addresses,
config.valAddress, config.xorAddress,
'0x0000000000000000000000000000000000000000000000000000000000000000'
],
});
};
2 changes: 1 addition & 1 deletion gen_mainnet_config.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash -v

npx hardhat gen-config --network mainnet --contract-address 0x1485E9852ac841b52eD44D573036429504f4F602 --sora-endpoint wss://ws.alb.sora.org --peers 0x6C9E8391a0444c739e7e2edd37A2C6e3381b1cbF,0xEf22D478a53bc8BBe854ceF8bA2eb79C49A1a171 --output deploy-data/mainnet.ts
npx hardhat gen-config --network mainnet --contract-address 0x6f984c337ad5b7c2084805042ae942cef462e3ff --sora-endpoint wss://ws.mof.sora.org --peers 0x6C9E8391a0444c739e7e2edd37A2C6e3381b1cbF,0xEf22D478a53bc8BBe854ceF8bA2eb79C49A1a171,0x6219d0ba6a0bafa69cd2b1b15633a3fd864dd371 --output deploy-data/mainnet.ts
13 changes: 12 additions & 1 deletion hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { resolve } from "path";
import "solidity-coverage"

import * as gen_config from "./tasks/gen-config";
import * as send from "./tasks/send";

dotenv({ path: resolve(__dirname, ".env") });

Expand Down Expand Up @@ -57,6 +58,11 @@ const config: HardhatUserConfig = {
url: 'https://rpc.sepolia.org',
accounts: [sepoliaPrivateKey],
},
sepolia2: {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why? they are the same (sepolia and sepolia2)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To have deployment data for test and stage environment

chainId: 11155111,
url: 'https://rpc.sepolia.org',
accounts: [sepoliaPrivateKey],
},
mainnet: {
chainId: 1,
url: `https://mainnet.infura.io/v3/${infuraKey}`,
Expand Down Expand Up @@ -87,7 +93,7 @@ const config: HardhatUserConfig = {
timeout: 60000
},
etherscan: {
apiKey: etherscanKey
apiKey: etherscanKey,
}
};

Expand All @@ -97,4 +103,9 @@ task("gen-config", "Generate config file for given network")
.addParam("peers")
.addParam("output").setAction(gen_config.main);

task("send", "Generate config file for given network")
.addParam("to")
.addParam("amount")
.addParam("token", "Token address", undefined, undefined, true)
.setAction(send.main);
export default config;
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
},
"dependencies": {
"@iarna/toml": "^2.2.5",
"@nomiclabs/hardhat-etherscan": "^2.1.4",
"@nomiclabs/hardhat-etherscan": "^3.1.0",
"@openzeppelin/contracts": "^4.3.2",
"@openzeppelin/test-helpers": "https://github.com/Snowfork/openzeppelin-test-helpers.git#3f9c4b8",
"@sora-substrate/util": "^1.8.15",
Expand Down Expand Up @@ -49,4 +49,4 @@
"typescript": "^4.4.3",
"web3": "^1.3.6"
}
}
}
25 changes: 25 additions & 0 deletions scripts/verify-bridge.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { HardhatRuntimeEnvironment } from 'hardhat/types';
import DeployConfig from "../deploy-data/config";
import { default as mainnetConfig } from "../deploy-data/mainnet"

async function main() {
const hh: HardhatRuntimeEnvironment = require("hardhat");
const config = mainnetConfig;
const bridgeAddress = "0x6F984C337aD5b7C2084805042AE942cef462e3ff";
let tokenAddresses = config.sidechainAssets.map((val) => val.address);
let assetIds = config.sidechainAssets.map((val) => val.asset_id);
await hh.run("verify:verify", {
address: bridgeAddress,
constructorArguments: [
config.peers,
tokenAddresses, assetIds, config.erc20Addresses,
config.valAddress, config.xorAddress,
'0x0000000000000000000000000000000000000000000000000000000000000000'
],
});
}

main().then(() => process.exit(0)).catch((error) => {
console.error(error);
process.exit(1);
});
4 changes: 0 additions & 4 deletions tasks/gen-config.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import { log } from "console";
import { readFile } from "fs";
import { HardhatRuntimeEnvironment } from 'hardhat/types';
import DeployConfig from "../deploy-data/config";
import * as sora from "@sora-substrate/util";
import abi from "../abis/BridgeOld.abi";
import { writeFile } from "fs/promises";
import { AnyJson } from "@polkadot/types/types";
import { keccak256 } from "web3-utils";

export async function main({ contractAddress, soraEndpoint, output, peers }) {
let peersArray = (peers as string).split(",");
Expand Down
18 changes: 18 additions & 0 deletions tasks/send.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { HardhatRuntimeEnvironment } from 'hardhat/types';
import DeployConfig from "../deploy-data/config";
import * as sora from "@sora-substrate/util";
import abi from "../abis/BridgeOld.abi";
import { writeFile } from "fs/promises";
import "hardhat-deploy";

export async function main({ to, amount, token }) {
const hh: HardhatRuntimeEnvironment = require("hardhat");
let [deployer] = await hh.getUnnamedAccounts();
let res;
if (!token) {
res = await hh.deployments.execute("Bridge", { from: deployer, log: true, value: amount }, "sendEthToSidechain", to);
} else {
res = await hh.deployments.execute("Bridge", { from: deployer, log: true }, "sendERC20ToSidechain", to, amount, token);
}
console.log(res);
}
Loading